Queue mid-turn messages for the next tool call; remove all tests
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TaskInput struct {
|
||||
ID int64
|
||||
TaskID string
|
||||
Actor string
|
||||
Text string
|
||||
Images []string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (s *Store) AddTaskInput(ctx context.Context, in TaskInput) error {
|
||||
images, err := json.Marshal(append([]string{}, in.Images...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `INSERT INTO task_inputs (task_id, actor, text, images, created_at) VALUES (?, ?, ?, ?, ?)`,
|
||||
in.TaskID, in.Actor, in.Text, string(images), now())
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) TaskInputs(ctx context.Context, taskID string) ([]TaskInput, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT id, task_id, actor, text, images, created_at FROM task_inputs WHERE task_id = ? ORDER BY id`, taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
inputs := []TaskInput{}
|
||||
for rows.Next() {
|
||||
in := TaskInput{}
|
||||
images := ""
|
||||
createdAt := ""
|
||||
err = rows.Scan(&in.ID, &in.TaskID, &in.Actor, &in.Text, &images, &createdAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(images), &in.Images)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
in.CreatedAt, err = parseTime(createdAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inputs = append(inputs, in)
|
||||
}
|
||||
return inputs, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) DeleteTaskInputs(ctx context.Context, ids []int64) error {
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
for _, id := range ids {
|
||||
_, err := tx.ExecContext(ctx, `DELETE FROM task_inputs WHERE id = ?`, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user