Switch to prefixed IDs and tell agents which Mac a message came from
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"g.fc.run/ai/byre/internal/ids"
|
||||
)
|
||||
|
||||
type TaskInput struct {
|
||||
@@ -16,6 +18,7 @@ type TaskInput struct {
|
||||
Text string
|
||||
Images []string
|
||||
SendID string
|
||||
Client string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
@@ -25,15 +28,15 @@ func (s *Store) AddTaskInput(ctx context.Context, in TaskInput, projectID, sessi
|
||||
return err
|
||||
}
|
||||
if in.SendID == "" {
|
||||
in.SendID = NewID()
|
||||
in.SendID = ids.New(ids.Send)
|
||||
}
|
||||
payload := map[string]any{"text": in.Text, "send_id": in.SendID}
|
||||
if len(in.Images) > 0 {
|
||||
payload["images"] = in.Images
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
res, err := tx.ExecContext(ctx, `INSERT INTO task_inputs (task_id, member, actor, text, images, send_id, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
in.TaskID, in.Member, in.Actor, in.Text, string(images), in.SendID, now())
|
||||
res, err := tx.ExecContext(ctx, `INSERT INTO task_inputs (task_id, member, actor, text, images, send_id, client_id, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
in.TaskID, in.Member, in.Actor, in.Text, string(images), in.SendID, in.Client, now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -82,7 +85,7 @@ func (s *Store) WithdrawTaskInput(ctx context.Context, taskID string, id int64,
|
||||
}
|
||||
|
||||
func (s *Store) TaskInputs(ctx context.Context, taskID, member string) ([]TaskInput, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT id, task_id, member, actor, text, images, send_id, created_at FROM task_inputs WHERE task_id = ? AND member = ? ORDER BY id`, taskID, member)
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT id, task_id, member, actor, text, images, send_id, client_id, created_at FROM task_inputs WHERE task_id = ? AND member = ? ORDER BY id`, taskID, member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -93,7 +96,7 @@ func (s *Store) TaskInputs(ctx context.Context, taskID, member string) ([]TaskIn
|
||||
in := TaskInput{}
|
||||
images := ""
|
||||
createdAt := ""
|
||||
err = rows.Scan(&in.ID, &in.TaskID, &in.Member, &in.Actor, &in.Text, &images, &in.SendID, &createdAt)
|
||||
err = rows.Scan(&in.ID, &in.TaskID, &in.Member, &in.Actor, &in.Text, &images, &in.SendID, &in.Client, &createdAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -117,8 +120,8 @@ func (s *Store) RestoreTaskInputs(ctx context.Context, inputs []TaskInput) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO task_inputs (id, task_id, member, actor, text, images, send_id, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
in.ID, in.TaskID, in.Member, in.Actor, in.Text, string(images), in.SendID, formatTime(in.CreatedAt))
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO task_inputs (id, task_id, member, actor, text, images, send_id, client_id, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
in.ID, in.TaskID, in.Member, in.Actor, in.Text, string(images), in.SendID, in.Client, formatTime(in.CreatedAt))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user