Answer a question again by forking at its answer's snapshot
This commit is contained in:
+54
-24
@@ -32,6 +32,31 @@ func (s *Store) CreateInboxItem(ctx context.Context, item api.InboxItem) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) CreateAnsweredItem(ctx context.Context, item api.InboxItem, resp api.InboxResponse) error {
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
payload, err := json.Marshal(item.Payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO inbox_items (id, project_id, task_id, agent_session_id, thread_id, payload, state, created_at, resolved_by, resolved_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, item.Id, item.ProjectId, item.TaskId, item.AgentSessionId, item.ThreadId,
|
||||
string(payload), string(api.Answered), formatTime(item.CreatedAt), resp.User, now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = insertResponse(ctx, tx, resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return emitItem(ctx, tx, emit, "inbox.created", item.Id, resp.User)
|
||||
})
|
||||
}
|
||||
|
||||
const agentActor = "agent"
|
||||
|
||||
func (s *Store) GetInboxItem(ctx context.Context, id string) (api.InboxItem, error) {
|
||||
@@ -120,30 +145,7 @@ func (s *Store) Respond(ctx context.Context, actor string, resolutions []Resolut
|
||||
return fmt.Errorf("%w: %s", ErrNotOpen, resp.ItemId)
|
||||
}
|
||||
|
||||
attachments, err := json.Marshal(resp.Attachments)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
images, err := json.Marshal(resp.Images)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var options *string
|
||||
if resp.Options != nil {
|
||||
b, err := json.Marshal(*resp.Options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := string(b)
|
||||
options = &s
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO inbox_responses (id, item_id, user_login, type, options, text, images, attachments, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, resp.Id, resp.ItemId, resp.User, string(resp.Type), options, resp.Text, string(images), string(attachments), formatTime(resp.CreatedAt))
|
||||
err = insertResponse(ctx, tx, resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -157,6 +159,34 @@ func (s *Store) Respond(ctx context.Context, actor string, resolutions []Resolut
|
||||
})
|
||||
}
|
||||
|
||||
func insertResponse(ctx context.Context, tx *sql.Tx, resp api.InboxResponse) error {
|
||||
attachments, err := json.Marshal(resp.Attachments)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
images, err := json.Marshal(resp.Images)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var options *string
|
||||
if resp.Options != nil {
|
||||
b, err := json.Marshal(*resp.Options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := string(b)
|
||||
options = &s
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO inbox_responses (id, item_id, user_login, type, options, text, images, attachments, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, resp.Id, resp.ItemId, resp.User, string(resp.Type), options, resp.Text, string(images), string(attachments), formatTime(resp.CreatedAt))
|
||||
return err
|
||||
}
|
||||
|
||||
var ErrNotOpen = errors.New("inbox item is not open")
|
||||
|
||||
func (s *Store) WithdrawItem(ctx context.Context, id string) error {
|
||||
|
||||
Reference in New Issue
Block a user