Make every question blocking and drop inbox priority
This commit is contained in:
+7
-20
@@ -11,17 +11,6 @@ import (
|
||||
"g.fc.run/misc/byre/internal/api"
|
||||
)
|
||||
|
||||
var priorities = []api.InboxItemPriority{api.Blocked, api.Gate, api.ReviewPriority, api.Fyi}
|
||||
|
||||
func priorityRank(p api.InboxItemPriority) int {
|
||||
for i, q := range priorities {
|
||||
if q == p {
|
||||
return i
|
||||
}
|
||||
}
|
||||
panic("unknown inbox priority " + string(p))
|
||||
}
|
||||
|
||||
func DeliverableResponse(t api.InboxResponseType) bool {
|
||||
switch t {
|
||||
case api.Option, api.Other:
|
||||
@@ -38,10 +27,10 @@ func (s *Store) CreateInboxItem(ctx context.Context, item api.InboxItem) error {
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO inbox_items (id, project_id, task_id, agent_session_id, thread_id, kind, priority, blocking, payload, state, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, item.Id, item.ProjectId, item.TaskId, item.AgentSessionId, item.ThreadId, string(item.Kind), priorityRank(item.Priority),
|
||||
item.Blocking, string(payload), string(item.State), formatTime(item.CreatedAt))
|
||||
INSERT INTO inbox_items (id, project_id, task_id, agent_session_id, thread_id, kind, payload, state, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, item.Id, item.ProjectId, item.TaskId, item.AgentSessionId, item.ThreadId, string(item.Kind),
|
||||
string(payload), string(item.State), formatTime(item.CreatedAt))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -218,7 +207,7 @@ func (s *Store) AwaitingHuman(ctx context.Context, sessionID string) (int, error
|
||||
n := 0
|
||||
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 = ?
|
||||
WHERE i.agent_session_id = ? AND i.kind = ? 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.Question), string(api.Open),
|
||||
string(api.Option), string(api.Other)).Scan(&n)
|
||||
@@ -293,7 +282,6 @@ type querier interface {
|
||||
func getItem(ctx context.Context, q querier, id string) (api.InboxItem, error) {
|
||||
item := api.InboxItem{}
|
||||
kind := ""
|
||||
priority := 0
|
||||
payload := ""
|
||||
state := ""
|
||||
createdAt := ""
|
||||
@@ -301,17 +289,16 @@ func getItem(ctx context.Context, q querier, id string) (api.InboxItem, error) {
|
||||
resolvedAt := sql.NullString{}
|
||||
|
||||
err := q.QueryRowContext(ctx, `
|
||||
SELECT id, project_id, task_id, agent_session_id, thread_id, kind, priority, blocking, payload, state,
|
||||
SELECT id, project_id, task_id, agent_session_id, thread_id, kind, payload, state,
|
||||
created_at, resolved_by, resolved_at
|
||||
FROM inbox_items WHERE id = ?
|
||||
`, id).Scan(&item.Id, &item.ProjectId, &item.TaskId, &item.AgentSessionId, &item.ThreadId, &kind, &priority, &item.Blocking,
|
||||
`, id).Scan(&item.Id, &item.ProjectId, &item.TaskId, &item.AgentSessionId, &item.ThreadId, &kind,
|
||||
&payload, &state, &createdAt, &resolvedBy, &resolvedAt)
|
||||
if err != nil {
|
||||
return item, err
|
||||
}
|
||||
|
||||
item.Kind = api.InboxItemKind(kind)
|
||||
item.Priority = priorities[priority]
|
||||
item.State = api.InboxState(state)
|
||||
err = json.Unmarshal([]byte(payload), &item.Payload)
|
||||
if err != nil {
|
||||
|
||||
@@ -374,6 +374,45 @@ UPDATE users SET focus = json_set(focus,
|
||||
'$.tab', CASE json_extract(focus, '$.tab') WHEN 'preview' THEN 'transcript' ELSE json_extract(focus, '$.tab') END,
|
||||
'$.tabs', json((SELECT json_group_array(value) FROM json_each(users.focus, '$.tabs') WHERE value != 'preview')));
|
||||
UPDATE users SET focus = json_set(focus, '$.tabs', json('["transcript"]')) WHERE json_array_length(focus, '$.tabs') = 0;
|
||||
`}, {"drop-inbox-priority", `
|
||||
CREATE TABLE inbox_items_next (
|
||||
id TEXT PRIMARY KEY,
|
||||
project_id TEXT NOT NULL REFERENCES projects(id),
|
||||
task_id TEXT NOT NULL REFERENCES tasks(id),
|
||||
agent_session_id TEXT NOT NULL REFERENCES agent_sessions(id),
|
||||
thread_id TEXT NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
priority INTEGER NOT NULL DEFAULT 0,
|
||||
blocking INTEGER NOT NULL DEFAULT 1,
|
||||
payload TEXT NOT NULL,
|
||||
state TEXT NOT NULL,
|
||||
snoozed_until TEXT,
|
||||
created_at TEXT NOT NULL,
|
||||
resolved_by TEXT REFERENCES users(login),
|
||||
resolved_at TEXT
|
||||
);
|
||||
INSERT INTO inbox_items_next SELECT id, project_id, task_id, agent_session_id, thread_id, kind, priority, blocking, payload, state, snoozed_until, created_at, resolved_by, resolved_at FROM inbox_items;
|
||||
DROP TABLE inbox_items;
|
||||
ALTER TABLE inbox_items_next RENAME TO inbox_items;
|
||||
CREATE INDEX inbox_items_open ON inbox_items(state, created_at);
|
||||
CREATE INDEX inbox_items_session ON inbox_items(agent_session_id, state);
|
||||
|
||||
CREATE TABLE users_next (
|
||||
login TEXT PRIMARY KEY,
|
||||
display_name TEXT NOT NULL,
|
||||
git_name TEXT NOT NULL DEFAULT '',
|
||||
git_email TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL,
|
||||
notification_prefs TEXT NOT NULL DEFAULT '{"questions":true,"reports":false,"errors":false,"rate_limits":false}',
|
||||
focus TEXT NOT NULL DEFAULT '{"tabs":["transcript"],"tab":"transcript"}'
|
||||
);
|
||||
INSERT INTO users_next (login, display_name, git_name, git_email, created_at, notification_prefs, focus)
|
||||
SELECT login, display_name, git_name, git_email, created_at,
|
||||
json_remove(json_set(notification_prefs, '$.questions', json(CASE WHEN json_extract(notification_prefs, '$.blocking_questions') THEN 'true' ELSE 'false' END)), '$.blocking_questions'),
|
||||
focus
|
||||
FROM users;
|
||||
DROP TABLE users;
|
||||
ALTER TABLE users_next RENAME TO users;
|
||||
`}}
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user