Render Markdown, add ask_human context, simplify inbox responses, group inbox by task

This commit is contained in:
Ian Gulliver
2026-10-14 10:37:04 -07:00
parent e9fd7de556
commit ca2644374d
25 changed files with 950 additions and 283 deletions
+7 -7
View File
@@ -24,7 +24,7 @@ func priorityRank(p api.InboxItemPriority) int {
func DeliverableResponse(t api.InboxResponseType) bool {
switch t {
case api.InboxResponseTypeOption, api.InboxResponseTypeFreeForm, api.InboxResponseTypeRedirect, api.InboxResponseTypeQuestion:
case api.Option, api.Other:
return true
}
return false
@@ -116,7 +116,7 @@ func (s *Store) ListInbox(ctx context.Context, f InboxFilter) ([]api.InboxItem,
args = append(args, now())
}
rows, err := s.db.QueryContext(ctx, `SELECT id FROM inbox_items WHERE `+strings.Join(where, " AND ")+` ORDER BY priority, created_at`, args...)
rows, err := s.db.QueryContext(ctx, `SELECT id FROM inbox_items WHERE `+strings.Join(where, " AND ")+` ORDER BY created_at`, args...)
if err != nil {
return nil, err
}
@@ -195,9 +195,9 @@ func (s *Store) AwaitingHuman(ctx context.Context, sessionID string) (int, error
err := s.db.QueryRowContext(ctx, `
SELECT COUNT(*) FROM inbox_items i
WHERE i.agent_session_id = ? AND i.kind = ? AND i.blocking AND i.state = ?
AND NOT EXISTS (SELECT 1 FROM inbox_responses r WHERE r.item_id = i.id AND r.type IN (?, ?, ?, ?))
`, sessionID, string(api.InboxItemKindQuestion), string(api.Open),
string(api.InboxResponseTypeOption), string(api.InboxResponseTypeFreeForm), string(api.InboxResponseTypeRedirect), string(api.InboxResponseTypeQuestion)).Scan(&n)
AND NOT EXISTS (SELECT 1 FROM inbox_responses r WHERE r.item_id = i.id AND r.type IN (?, ?))
`, sessionID, string(api.Question), string(api.Open),
string(api.Option), string(api.Other)).Scan(&n)
return n, err
}
@@ -209,9 +209,9 @@ type Pending struct {
func (s *Store) Undelivered(ctx context.Context, sessionID string) ([]Pending, error) {
rows, err := s.db.QueryContext(ctx, `
SELECT r.id, r.item_id FROM inbox_responses r JOIN inbox_items i ON i.id = r.item_id
WHERE i.agent_session_id = ? AND r.delivered_at IS NULL AND r.type IN (?, ?, ?, ?)
WHERE i.agent_session_id = ? AND r.delivered_at IS NULL AND r.type IN (?, ?)
ORDER BY r.created_at
`, sessionID, string(api.InboxResponseTypeOption), string(api.InboxResponseTypeFreeForm), string(api.InboxResponseTypeRedirect), string(api.InboxResponseTypeQuestion))
`, sessionID, string(api.Option), string(api.Other))
if err != nil {
return nil, err
}
+3
View File
@@ -122,6 +122,9 @@ CREATE TABLE turn_queue (
text TEXT NOT NULL,
created_at TEXT NOT NULL
);
`, `
UPDATE inbox_responses SET type = 'other' WHERE type IN ('free_form', 'redirect', 'question');
UPDATE inbox_items SET state = 'answered' WHERE state = 'redirected';
`}
type Store struct {