You've already forked agentic-coding-workflow
bugfix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
-- name: ListAgentKindConfigFiles :many
|
||||
SELECT id, agent_kind_id, rel_path, encrypted_content, updated_by, created_at, updated_at
|
||||
SELECT id, agent_kind_id, rel_path, encrypted_content, updated_by, created_at, updated_at, key_version
|
||||
FROM acp_agent_kind_config_files
|
||||
WHERE agent_kind_id = $1
|
||||
ORDER BY rel_path ASC;
|
||||
@@ -12,7 +12,7 @@ ON CONFLICT (agent_kind_id, rel_path) DO UPDATE
|
||||
SET encrypted_content = EXCLUDED.encrypted_content,
|
||||
updated_by = EXCLUDED.updated_by,
|
||||
updated_at = now()
|
||||
RETURNING id, agent_kind_id, rel_path, encrypted_content, updated_by, created_at, updated_at;
|
||||
RETURNING id, agent_kind_id, rel_path, encrypted_content, updated_by, created_at, updated_at, key_version;
|
||||
|
||||
-- name: DeleteAgentKindConfigFile :execrows
|
||||
DELETE FROM acp_agent_kind_config_files
|
||||
|
||||
@@ -1,50 +1,61 @@
|
||||
-- name: CreateAgentKind :one
|
||||
INSERT INTO acp_agent_kinds (
|
||||
id, name, display_name, description, binary_path, args, encrypted_env, enabled, created_by, tool_allowlist, client_type, encrypted_mcp_servers
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
||||
id, name, display_name, description, binary_path, args, encrypted_env, enabled, created_by, tool_allowlist, client_type, encrypted_mcp_servers,
|
||||
model_id, max_cost_usd, max_tokens, max_wall_clock_seconds
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
|
||||
RETURNING id, name, display_name, description, binary_path, args, encrypted_env,
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers;
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
|
||||
model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version;
|
||||
|
||||
-- name: GetAgentKindByID :one
|
||||
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
|
||||
model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
|
||||
FROM acp_agent_kinds
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: GetAgentKindByName :one
|
||||
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
|
||||
model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
|
||||
FROM acp_agent_kinds
|
||||
WHERE name = $1;
|
||||
|
||||
-- name: ListAgentKinds :many
|
||||
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
|
||||
model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
|
||||
FROM acp_agent_kinds
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: ListEnabledAgentKinds :many
|
||||
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
|
||||
model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
|
||||
FROM acp_agent_kinds
|
||||
WHERE enabled = TRUE
|
||||
ORDER BY name ASC;
|
||||
|
||||
-- name: UpdateAgentKind :one
|
||||
UPDATE acp_agent_kinds
|
||||
SET display_name = $2,
|
||||
description = $3,
|
||||
binary_path = $4,
|
||||
args = $5,
|
||||
encrypted_env = $6,
|
||||
enabled = $7,
|
||||
tool_allowlist = $8,
|
||||
client_type = $9,
|
||||
encrypted_mcp_servers = $10,
|
||||
updated_at = now()
|
||||
SET display_name = $2,
|
||||
description = $3,
|
||||
binary_path = $4,
|
||||
args = $5,
|
||||
encrypted_env = $6,
|
||||
enabled = $7,
|
||||
tool_allowlist = $8,
|
||||
client_type = $9,
|
||||
encrypted_mcp_servers = $10,
|
||||
model_id = $11,
|
||||
max_cost_usd = $12,
|
||||
max_tokens = $13,
|
||||
max_wall_clock_seconds = $14,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, name, display_name, description, binary_path, args, encrypted_env,
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers;
|
||||
enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
|
||||
model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version;
|
||||
|
||||
-- name: DeleteAgentKind :exec
|
||||
DELETE FROM acp_agent_kinds WHERE id = $1;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
-- dashboard.sql: run-history dashboard 读模型(只读聚合)。
|
||||
-- - SessionTimeline: 单会话的 RPC 事件按 (direction, rpc_kind, method) 分桶,
|
||||
-- 给出条数 + 首/末时间戳,用于会话时间线概览。
|
||||
-- - SessionRollup: 在 owner/admin scope + 可选 project/requirement 过滤下,
|
||||
-- 统计会话总数、成功率(exited 视为成功)、总成本、平均时长。
|
||||
-- - SessionsByDay: 按天的 总数 / 成功 / 失败 / 成本 时间序列。
|
||||
-- scope 约定(与 ListSessionsByUser/ListAllSessions 一致):
|
||||
-- $1 user_id 为 NULL 时不按用户过滤(admin 全量),非 NULL 时仅该用户。
|
||||
|
||||
-- name: SessionTimeline :many
|
||||
-- 单会话事件时间线:按 method/kind 分桶聚合(条数 + 首末时间)。
|
||||
SELECT direction,
|
||||
rpc_kind,
|
||||
COALESCE(method, '') AS method,
|
||||
COUNT(*)::bigint AS event_count,
|
||||
MIN(created_at)::timestamptz AS first_at,
|
||||
MAX(created_at)::timestamptz AS last_at
|
||||
FROM acp_events
|
||||
WHERE session_id = $1
|
||||
GROUP BY direction, rpc_kind, COALESCE(method, '')
|
||||
ORDER BY first_at ASC;
|
||||
|
||||
-- name: SessionRollup :one
|
||||
-- owner/admin scope + 可选 project/requirement + 时间窗内的会话汇总。
|
||||
-- success = status='exited';avg_duration_seconds 仅统计已结束(ended_at 非空)会话。
|
||||
SELECT
|
||||
COUNT(*)::bigint AS total,
|
||||
COUNT(*) FILTER (WHERE status = 'exited')::bigint AS succeeded,
|
||||
COUNT(*) FILTER (WHERE status = 'crashed')::bigint AS crashed,
|
||||
COUNT(*) FILTER (WHERE status IN ('starting','running'))::bigint AS active,
|
||||
COALESCE(SUM(cost_usd), 0)::numeric AS total_cost_usd,
|
||||
COALESCE(SUM(tokens_total), 0)::bigint AS total_tokens,
|
||||
COALESCE(
|
||||
AVG(EXTRACT(EPOCH FROM (ended_at - started_at)))
|
||||
FILTER (WHERE ended_at IS NOT NULL),
|
||||
0)::float8 AS avg_duration_seconds
|
||||
FROM acp_sessions
|
||||
WHERE ($1::uuid IS NULL OR user_id = $1)
|
||||
AND ($2::uuid IS NULL OR project_id = $2)
|
||||
AND ($3::uuid IS NULL OR requirement_id = $3)
|
||||
AND started_at >= $4
|
||||
AND started_at < $5;
|
||||
|
||||
-- name: SessionsByDay :many
|
||||
-- 按天的会话时间序列(总数 / 成功 / 失败 / 成本),同 SessionRollup 的 scope。
|
||||
SELECT
|
||||
date_trunc('day', started_at)::timestamptz AS day,
|
||||
COUNT(*)::bigint AS total,
|
||||
COUNT(*) FILTER (WHERE status = 'exited')::bigint AS succeeded,
|
||||
COUNT(*) FILTER (WHERE status = 'crashed')::bigint AS crashed,
|
||||
COALESCE(SUM(cost_usd), 0)::numeric AS total_cost_usd
|
||||
FROM acp_sessions
|
||||
WHERE ($1::uuid IS NULL OR user_id = $1)
|
||||
AND ($2::uuid IS NULL OR project_id = $2)
|
||||
AND ($3::uuid IS NULL OR requirement_id = $3)
|
||||
AND started_at >= $4
|
||||
AND started_at < $5
|
||||
GROUP BY day
|
||||
ORDER BY day ASC;
|
||||
@@ -0,0 +1,9 @@
|
||||
-- name: InsertSessionUsage :one
|
||||
-- 写一条 per-turn 用量账目。source_event_id 非空时按唯一索引去重(同一事件
|
||||
-- 重复 Observe 不会重复入账);返回受影响行数判定是否实际插入。
|
||||
INSERT INTO acp_session_usage (
|
||||
session_id, user_id, project_id, agent_kind_id, model_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, cost_usd, source_event_id
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
ON CONFLICT (source_event_id) WHERE source_event_id IS NOT NULL DO NOTHING
|
||||
RETURNING id;
|
||||
@@ -1,26 +1,75 @@
|
||||
-- name: InsertSession :one
|
||||
INSERT INTO acp_sessions (
|
||||
id, workspace_id, project_id, agent_kind_id, user_id,
|
||||
issue_id, requirement_id, branch, cwd_path, is_main_worktree, status
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
issue_id, requirement_id, branch, cwd_path, is_main_worktree, status,
|
||||
orchestrator_step_id,
|
||||
budget_max_cost_usd, budget_max_tokens, budget_max_wall_clock_seconds
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
|
||||
RETURNING id, workspace_id, project_id, agent_kind_id, user_id,
|
||||
issue_id, requirement_id, agent_session_id,
|
||||
branch, cwd_path, is_main_worktree, status,
|
||||
pid, exit_code, last_error, started_at, ended_at;
|
||||
pid, exit_code, last_error, started_at, ended_at, last_stop_reason,
|
||||
orchestrator_step_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, total_cost_usd,
|
||||
last_activity_at, budget_max_cost_usd, budget_max_tokens,
|
||||
budget_max_wall_clock_seconds, terminated_reason, sandbox_mode,
|
||||
cost_usd, tokens_total;
|
||||
|
||||
-- name: GetSessionByID :one
|
||||
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
||||
issue_id, requirement_id, agent_session_id,
|
||||
branch, cwd_path, is_main_worktree, status,
|
||||
pid, exit_code, last_error, started_at, ended_at
|
||||
pid, exit_code, last_error, started_at, ended_at, last_stop_reason,
|
||||
orchestrator_step_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, total_cost_usd,
|
||||
last_activity_at, budget_max_cost_usd, budget_max_tokens,
|
||||
budget_max_wall_clock_seconds, terminated_reason, sandbox_mode,
|
||||
cost_usd, tokens_total
|
||||
FROM acp_sessions
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: GetSessionByStepID :one
|
||||
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
||||
issue_id, requirement_id, agent_session_id,
|
||||
branch, cwd_path, is_main_worktree, status,
|
||||
pid, exit_code, last_error, started_at, ended_at, last_stop_reason,
|
||||
orchestrator_step_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, total_cost_usd,
|
||||
last_activity_at, budget_max_cost_usd, budget_max_tokens,
|
||||
budget_max_wall_clock_seconds, terminated_reason, sandbox_mode,
|
||||
cost_usd, tokens_total
|
||||
FROM acp_sessions
|
||||
WHERE orchestrator_step_id = $1
|
||||
ORDER BY started_at DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- name: GetCrashedSessionForResume :one
|
||||
-- 返回某 step 最近一次处于可恢复终态(crashed/exited)的 session。
|
||||
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
||||
issue_id, requirement_id, agent_session_id,
|
||||
branch, cwd_path, is_main_worktree, status,
|
||||
pid, exit_code, last_error, started_at, ended_at, last_stop_reason,
|
||||
orchestrator_step_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, total_cost_usd,
|
||||
last_activity_at, budget_max_cost_usd, budget_max_tokens,
|
||||
budget_max_wall_clock_seconds, terminated_reason, sandbox_mode,
|
||||
cost_usd, tokens_total
|
||||
FROM acp_sessions
|
||||
WHERE orchestrator_step_id = $1
|
||||
AND status IN ('crashed','exited')
|
||||
ORDER BY started_at DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- name: ListSessionsByUser :many
|
||||
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
||||
issue_id, requirement_id, agent_session_id,
|
||||
branch, cwd_path, is_main_worktree, status,
|
||||
pid, exit_code, last_error, started_at, ended_at
|
||||
pid, exit_code, last_error, started_at, ended_at, last_stop_reason,
|
||||
orchestrator_step_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, total_cost_usd,
|
||||
last_activity_at, budget_max_cost_usd, budget_max_tokens,
|
||||
budget_max_wall_clock_seconds, terminated_reason, sandbox_mode,
|
||||
cost_usd, tokens_total
|
||||
FROM acp_sessions
|
||||
WHERE user_id = $1
|
||||
AND ($2::uuid IS NULL OR requirement_id = $2)
|
||||
@@ -30,7 +79,12 @@ ORDER BY started_at DESC;
|
||||
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
||||
issue_id, requirement_id, agent_session_id,
|
||||
branch, cwd_path, is_main_worktree, status,
|
||||
pid, exit_code, last_error, started_at, ended_at
|
||||
pid, exit_code, last_error, started_at, ended_at, last_stop_reason,
|
||||
orchestrator_step_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, total_cost_usd,
|
||||
last_activity_at, budget_max_cost_usd, budget_max_tokens,
|
||||
budget_max_wall_clock_seconds, terminated_reason, sandbox_mode,
|
||||
cost_usd, tokens_total
|
||||
FROM acp_sessions
|
||||
WHERE ($1::uuid IS NULL OR requirement_id = $1)
|
||||
ORDER BY started_at DESC;
|
||||
@@ -40,6 +94,17 @@ UPDATE acp_sessions
|
||||
SET status = 'running', agent_session_id = $2, pid = $3
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: UpdateSessionLastStopReason :exec
|
||||
UPDATE acp_sessions
|
||||
SET last_stop_reason = $2
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: UpdateSessionSandboxMode :exec
|
||||
-- 记录本 session 运行所用的沙箱模式(审计/取证)。
|
||||
UPDATE acp_sessions
|
||||
SET sandbox_mode = $2
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: UpdateSessionFinished :exec
|
||||
UPDATE acp_sessions
|
||||
SET status = $2, exit_code = $3, last_error = $4, ended_at = now()
|
||||
@@ -50,6 +115,20 @@ UPDATE acp_sessions
|
||||
SET status = 'crashed', last_error = $2, ended_at = now()
|
||||
WHERE id = $1 AND status IN ('starting', 'running');
|
||||
|
||||
-- name: ResetSessionForResume :exec
|
||||
-- 把崩溃/退出的 session 复用为新一轮:回到 starting、清空上次运行时字段。
|
||||
-- 编排器 resume 在重新 Spawn 前调用,使同一行 session 在同 cwd/worktree 上复用。
|
||||
UPDATE acp_sessions
|
||||
SET status = 'starting',
|
||||
agent_session_id = NULL,
|
||||
pid = NULL,
|
||||
exit_code = NULL,
|
||||
last_error = NULL,
|
||||
ended_at = NULL,
|
||||
terminated_reason = NULL,
|
||||
last_activity_at = now()
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: CountActiveSessions :one
|
||||
SELECT COUNT(*) FROM acp_sessions WHERE status IN ('starting', 'running');
|
||||
|
||||
@@ -72,3 +151,88 @@ WHERE id = $1 AND active_main_session_id = $2;
|
||||
-- name: AcquireMainWorktree :execrows
|
||||
UPDATE workspaces SET active_main_session_id = $1
|
||||
WHERE id = $2 AND active_main_session_id IS NULL;
|
||||
|
||||
-- name: AddSessionUsageTotals :one
|
||||
-- 单 round-trip 累加 session 运行时 token/cost 总量并刷新 last_activity_at,
|
||||
-- 返回累加后的权威总量供预算判定。
|
||||
-- 同时把 dashboard rollup 列(cost_usd / tokens_total)与运行时累加器对齐,
|
||||
-- 使 run-history dashboard 在会话进行中及退出后都能读到 agent 上报的成本。
|
||||
UPDATE acp_sessions
|
||||
SET prompt_tokens = prompt_tokens + $2,
|
||||
completion_tokens = completion_tokens + $3,
|
||||
thinking_tokens = thinking_tokens + $4,
|
||||
total_cost_usd = total_cost_usd + $5,
|
||||
cost_usd = cost_usd + $5,
|
||||
tokens_total = tokens_total + $2 + $3 + $4,
|
||||
last_activity_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING prompt_tokens, completion_tokens, thinking_tokens, total_cost_usd;
|
||||
|
||||
-- name: SumProjectCostUSD :one
|
||||
-- 某 project 自 since 起的 ACP 累计花费(per-project 软预算)。
|
||||
SELECT COALESCE(SUM(cost_usd), 0)::numeric AS cost_usd
|
||||
FROM acp_session_usage
|
||||
WHERE project_id = $1 AND created_at >= $2;
|
||||
|
||||
-- name: MarkSessionTerminatedReason :exec
|
||||
-- 写入终止原因;已有非空 terminated_reason 时不覆盖(reaper / budget 互斥保护)。
|
||||
UPDATE acp_sessions
|
||||
SET terminated_reason = $2
|
||||
WHERE id = $1 AND terminated_reason IS NULL;
|
||||
|
||||
-- name: ListSessionsForReaper :many
|
||||
-- 返回应被回收的活跃 session:
|
||||
-- 超过自身 wall-clock 上限(budget_max_wall_clock_seconds 非空且 started_at 过早),或
|
||||
-- 超过全局 wall-clock 上限($1::timestamptz = now - 全局上限),或
|
||||
-- 空闲超时(last_activity_at < $2::timestamptz)。
|
||||
SELECT id, user_id, started_at, last_activity_at, budget_max_wall_clock_seconds
|
||||
FROM acp_sessions
|
||||
WHERE status IN ('starting','running')
|
||||
AND (
|
||||
(budget_max_wall_clock_seconds IS NOT NULL
|
||||
AND started_at < now() - make_interval(secs => budget_max_wall_clock_seconds))
|
||||
OR ($1::timestamptz IS NOT NULL AND started_at < $1::timestamptz)
|
||||
OR last_activity_at < $2::timestamptz
|
||||
);
|
||||
|
||||
-- name: SummarizeAcpUsageByUser :many
|
||||
SELECT user_id,
|
||||
SUM(prompt_tokens)::bigint AS prompt_tokens,
|
||||
SUM(completion_tokens)::bigint AS completion_tokens,
|
||||
SUM(thinking_tokens)::bigint AS thinking_tokens,
|
||||
SUM(cost_usd)::numeric AS cost_usd
|
||||
FROM acp_session_usage
|
||||
WHERE created_at >= $1 AND created_at < $2
|
||||
GROUP BY user_id
|
||||
ORDER BY cost_usd DESC;
|
||||
|
||||
-- name: SummarizeAcpUsageByModel :many
|
||||
SELECT model_id,
|
||||
SUM(prompt_tokens)::bigint AS prompt_tokens,
|
||||
SUM(completion_tokens)::bigint AS completion_tokens,
|
||||
SUM(thinking_tokens)::bigint AS thinking_tokens,
|
||||
SUM(cost_usd)::numeric AS cost_usd
|
||||
FROM acp_session_usage
|
||||
WHERE created_at >= $1 AND created_at < $2
|
||||
GROUP BY model_id
|
||||
ORDER BY cost_usd DESC;
|
||||
|
||||
-- name: SummarizeAcpUsageByDay :many
|
||||
SELECT date_trunc('day', created_at)::timestamptz AS day,
|
||||
SUM(prompt_tokens)::bigint AS prompt_tokens,
|
||||
SUM(completion_tokens)::bigint AS completion_tokens,
|
||||
SUM(thinking_tokens)::bigint AS thinking_tokens,
|
||||
SUM(cost_usd)::numeric AS cost_usd
|
||||
FROM acp_session_usage
|
||||
WHERE created_at >= $1 AND created_at < $2
|
||||
GROUP BY day
|
||||
ORDER BY day;
|
||||
|
||||
-- name: ListSessionUsageBySession :many
|
||||
SELECT id, session_id, user_id, project_id, agent_kind_id, model_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, cost_usd,
|
||||
source_event_id, created_at
|
||||
FROM acp_session_usage
|
||||
WHERE session_id = $1
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
-- name: InsertTurn :one
|
||||
INSERT INTO acp_turns (
|
||||
session_id, turn_index, prompt_request_id, status
|
||||
) VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, session_id, turn_index, prompt_request_id, status,
|
||||
stop_reason, update_count, started_at, completed_at;
|
||||
|
||||
-- name: MarkTurnCompleted :exec
|
||||
UPDATE acp_turns
|
||||
SET status = 'completed', stop_reason = $3, update_count = $4, completed_at = now()
|
||||
WHERE session_id = $1 AND turn_index = $2 AND status = 'in_progress';
|
||||
|
||||
-- name: MarkTurnAborted :exec
|
||||
UPDATE acp_turns
|
||||
SET status = 'aborted', completed_at = now()
|
||||
WHERE session_id = $1 AND turn_index = $2 AND status = 'in_progress';
|
||||
|
||||
-- name: IncrementTurnUpdateCount :exec
|
||||
UPDATE acp_turns
|
||||
SET update_count = update_count + 1
|
||||
WHERE session_id = $1 AND turn_index = $2 AND status = 'in_progress';
|
||||
|
||||
-- name: GetLatestTurnBySession :one
|
||||
SELECT id, session_id, turn_index, prompt_request_id, status,
|
||||
stop_reason, update_count, started_at, completed_at
|
||||
FROM acp_turns
|
||||
WHERE session_id = $1
|
||||
ORDER BY turn_index DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- name: ListTurnsBySession :many
|
||||
SELECT id, session_id, turn_index, prompt_request_id, status,
|
||||
stop_reason, update_count, started_at, completed_at
|
||||
FROM acp_turns
|
||||
WHERE session_id = $1
|
||||
ORDER BY turn_index ASC;
|
||||
|
||||
-- name: PurgeTurnsBefore :execrows
|
||||
DELETE FROM acp_turns WHERE started_at < $1;
|
||||
Reference in New Issue
Block a user