feat: expose scripts to review and add approval side chat

This commit is contained in:
ji ruo committed 2026-10-12 11:06:38 +08:00
1 parent ee413324c8
commit 9b0d1bdb3c
18 files changed
+935 -217

No files matched your search

+9 -1
View File
@@ -1237,17 +1237,25 @@ CREATE TABLE IF NOT EXISTS side_question_sessions (
task_id BIGINT REFERENCES tasks(id) ON DELETE CASCADE,
exploration_id BIGINT REFERENCES explorations(id) ON DELETE CASCADE,
intent_id BIGINT REFERENCES exploration_nodes(id) ON DELETE CASCADE,
approval_id BIGINT REFERENCES intercept_pending(id) ON DELETE CASCADE,
run_id BIGINT NOT NULL,
version BIGINT NOT NULL,
snapshot JSONB NOT NULL,
generation BIGINT NOT NULL DEFAULT 0,
CHECK ((conversation_id IS NOT NULL AND task_id IS NULL AND exploration_id IS NULL AND intent_id IS NULL)
CHECK (approval_id IS NOT NULL OR
(conversation_id IS NOT NULL AND task_id IS NULL AND exploration_id IS NULL AND intent_id IS NULL)
OR (conversation_id IS NULL AND task_id IS NOT NULL AND exploration_id IS NOT NULL))
);
ALTER TABLE side_question_sessions ADD COLUMN IF NOT EXISTS approval_id BIGINT REFERENCES intercept_pending(id) ON DELETE CASCADE;
ALTER TABLE side_question_sessions DROP CONSTRAINT IF EXISTS side_question_sessions_check;
ALTER TABLE side_question_sessions ADD CONSTRAINT side_question_sessions_check CHECK (approval_id IS NOT NULL OR
(conversation_id IS NOT NULL AND task_id IS NULL AND exploration_id IS NULL AND intent_id IS NULL)
OR (conversation_id IS NULL AND task_id IS NOT NULL AND exploration_id IS NOT NULL));
CREATE INDEX IF NOT EXISTS idx_side_sessions_conv ON side_question_sessions(conversation_id);
CREATE INDEX IF NOT EXISTS idx_side_sessions_task ON side_question_sessions(task_id);
CREATE INDEX IF NOT EXISTS idx_side_sessions_exp ON side_question_sessions(exploration_id);
CREATE INDEX IF NOT EXISTS idx_side_sessions_intent ON side_question_sessions(intent_id);
CREATE INDEX IF NOT EXISTS idx_side_sessions_approval ON side_question_sessions(approval_id);
CREATE TABLE IF NOT EXISTS side_question_requests (
id TEXT PRIMARY KEY,
+6 -4
View File
@@ -19,7 +19,9 @@ var ErrSideParentGone = errors.New("旁路父会话已删除或归档")
func lockSideParent(ctx context.Context, tx *sql.Tx, p sidequestion.Parent) error {
var id int64
var err error
if p.ConversationID > 0 {
if p.ApprovalID > 0 {
err = tx.QueryRowContext(ctx, `SELECT id FROM intercept_pending WHERE id=$1 FOR SHARE`, p.ApprovalID).Scan(&id)
} else if p.ConversationID > 0 {
err = tx.QueryRowContext(ctx, `SELECT id FROM conversations WHERE id=$1 FOR SHARE`, p.ConversationID).Scan(&id)
} else {
err = tx.QueryRowContext(ctx, `SELECT id FROM tasks WHERE id=$1 AND exploration_id=$2 AND deleted_at IS NULL AND archived_at IS NULL FOR SHARE`, p.TaskID, p.ExplorationID).Scan(&id)
@@ -53,10 +55,10 @@ func (d *DB) SaveSideSnapshot(ctx context.Context, s sidequestion.Snapshot) erro
if err = lockSideParent(ctx, tx, s.Parent); err != nil {
return err
}
_, err = tx.ExecContext(ctx, `INSERT INTO side_question_sessions(session_key,conversation_id,task_id,exploration_id,intent_id,run_id,version,snapshot)
VALUES($1,$2,$3,$4,$5,$6,$7,$8) ON CONFLICT(session_key) DO UPDATE SET run_id=EXCLUDED.run_id,version=EXCLUDED.version,snapshot=EXCLUDED.snapshot
_, err = tx.ExecContext(ctx, `INSERT INTO side_question_sessions(session_key,conversation_id,task_id,exploration_id,intent_id,approval_id,run_id,version,snapshot)
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9) ON CONFLICT(session_key) DO UPDATE SET run_id=EXCLUDED.run_id,version=EXCLUDED.version,snapshot=EXCLUDED.snapshot
WHERE (side_question_sessions.run_id,side_question_sessions.version)<(EXCLUDED.run_id,EXCLUDED.version)`,
s.Parent.Key(), nullableSideID(s.Parent.ConversationID), nullableSideID(s.Parent.TaskID), nullableSideID(s.Parent.ExplorationID), nullableSideID(s.Parent.IntentID), s.RunID, s.Version, string(jsonbClean(b)))
s.Parent.Key(), nullableSideID(s.Parent.ConversationID), nullableSideID(s.Parent.TaskID), nullableSideID(s.Parent.ExplorationID), nullableSideID(s.Parent.IntentID), nullableSideID(s.Parent.ApprovalID), s.RunID, s.Version, string(jsonbClean(b)))
if err != nil {
return err
}