mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
b3a39ad93d
* refactor: replace persistent subagents with ephemeral spawn tool (#subagent) - Drop subagents table, remove all persistent subagent infrastructure - Add 'subagent' session type with parent_session_id on bot_sessions - Rewrite subagent tool as single 'spawn' tool with parallel execution - Create system_subagent.md prompt, add _subagent.md include for chat - Limit subagent tools to file, exec, web_search, web_fetch only - Merge subagent token usage into parent chat session in reporting - Remove frontend subagent management page, update chat UI for spawn - Fix UTF-8 truncation in session title, fix query not passed to agent * refactor: remove history message page
81 lines
2.1 KiB
SQL
81 lines
2.1 KiB
SQL
-- name: CreateSession :one
|
|
INSERT INTO bot_sessions (
|
|
bot_id, route_id, channel_type, type, title, metadata, parent_session_id
|
|
)
|
|
VALUES (
|
|
sqlc.arg(bot_id),
|
|
sqlc.narg(route_id)::uuid,
|
|
sqlc.narg(channel_type)::text,
|
|
sqlc.arg(type),
|
|
sqlc.arg(title),
|
|
sqlc.arg(metadata),
|
|
sqlc.narg(parent_session_id)::uuid
|
|
)
|
|
RETURNING *;
|
|
|
|
-- name: GetSessionByID :one
|
|
SELECT *
|
|
FROM bot_sessions
|
|
WHERE id = $1
|
|
AND deleted_at IS NULL;
|
|
|
|
-- name: ListSessionsByBot :many
|
|
SELECT
|
|
s.id, s.bot_id, s.route_id, s.channel_type, s.type, s.title, s.metadata,
|
|
s.created_at, s.updated_at, s.deleted_at,
|
|
r.metadata AS route_metadata,
|
|
r.conversation_type AS route_conversation_type
|
|
FROM bot_sessions s
|
|
LEFT JOIN bot_channel_routes r ON r.id = s.route_id
|
|
WHERE s.bot_id = sqlc.arg(bot_id)
|
|
AND s.deleted_at IS NULL
|
|
ORDER BY s.updated_at DESC;
|
|
|
|
-- name: ListSessionsByRoute :many
|
|
SELECT *
|
|
FROM bot_sessions
|
|
WHERE route_id = sqlc.arg(route_id)
|
|
AND deleted_at IS NULL
|
|
ORDER BY updated_at DESC;
|
|
|
|
-- name: UpdateSessionTitle :one
|
|
UPDATE bot_sessions
|
|
SET title = sqlc.arg(title), updated_at = now()
|
|
WHERE id = sqlc.arg(id) AND deleted_at IS NULL
|
|
RETURNING *;
|
|
|
|
-- name: UpdateSessionMetadata :one
|
|
UPDATE bot_sessions
|
|
SET metadata = sqlc.arg(metadata), updated_at = now()
|
|
WHERE id = sqlc.arg(id) AND deleted_at IS NULL
|
|
RETURNING *;
|
|
|
|
-- name: SoftDeleteSession :exec
|
|
UPDATE bot_sessions
|
|
SET deleted_at = now(), updated_at = now()
|
|
WHERE id = sqlc.arg(id) AND deleted_at IS NULL;
|
|
|
|
-- name: TouchSession :exec
|
|
UPDATE bot_sessions
|
|
SET updated_at = now()
|
|
WHERE id = sqlc.arg(id) AND deleted_at IS NULL;
|
|
|
|
-- name: GetActiveSessionForRoute :one
|
|
SELECT s.*
|
|
FROM bot_sessions s
|
|
JOIN bot_channel_routes r ON r.active_session_id = s.id
|
|
WHERE r.id = sqlc.arg(route_id)
|
|
AND s.deleted_at IS NULL;
|
|
|
|
-- name: ListSubagentSessionsByParent :many
|
|
SELECT *
|
|
FROM bot_sessions
|
|
WHERE parent_session_id = sqlc.arg(parent_session_id)
|
|
AND deleted_at IS NULL
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: SoftDeleteSessionsByBot :exec
|
|
UPDATE bot_sessions
|
|
SET deleted_at = now(), updated_at = now()
|
|
WHERE bot_id = sqlc.arg(bot_id) AND deleted_at IS NULL;
|