@clinebot/core 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/account/cline-account-service.d.ts +34 -0
- package/dist/account/index.d.ts +3 -0
- package/dist/account/rpc.d.ts +38 -0
- package/dist/account/types.d.ts +74 -0
- package/dist/agents/agent-config-loader.d.ts +18 -0
- package/dist/agents/agent-config-parser.d.ts +25 -0
- package/dist/agents/hooks-config-loader.d.ts +23 -0
- package/dist/agents/index.d.ts +11 -0
- package/dist/agents/plugin-config-loader.d.ts +22 -0
- package/dist/agents/plugin-loader.d.ts +9 -0
- package/dist/agents/plugin-sandbox.d.ts +12 -0
- package/dist/agents/unified-config-file-watcher.d.ts +77 -0
- package/dist/agents/user-instruction-config-loader.d.ts +63 -0
- package/dist/auth/client.d.ts +11 -0
- package/dist/auth/cline.d.ts +41 -0
- package/dist/auth/codex.d.ts +39 -0
- package/dist/auth/oca.d.ts +22 -0
- package/dist/auth/server.d.ts +22 -0
- package/dist/auth/types.d.ts +72 -0
- package/dist/auth/utils.d.ts +32 -0
- package/dist/chat/chat-schema.d.ts +145 -0
- package/dist/default-tools/constants.d.ts +23 -0
- package/dist/default-tools/definitions.d.ts +96 -0
- package/dist/default-tools/executors/apply-patch-parser.d.ts +68 -0
- package/dist/default-tools/executors/apply-patch.d.ts +26 -0
- package/dist/default-tools/executors/bash.d.ts +49 -0
- package/dist/default-tools/executors/editor.d.ts +31 -0
- package/dist/default-tools/executors/file-read.d.ts +40 -0
- package/dist/default-tools/executors/index.d.ts +44 -0
- package/dist/default-tools/executors/search.d.ts +50 -0
- package/dist/default-tools/executors/web-fetch.d.ts +58 -0
- package/dist/default-tools/index.d.ts +57 -0
- package/dist/default-tools/presets.d.ts +124 -0
- package/dist/default-tools/schemas.d.ts +121 -0
- package/dist/default-tools/types.d.ts +237 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +220 -0
- package/dist/input/file-indexer.d.ts +5 -0
- package/dist/input/index.d.ts +4 -0
- package/dist/input/mention-enricher.d.ts +12 -0
- package/dist/mcp/config-loader.d.ts +15 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/manager.d.ts +24 -0
- package/dist/mcp/types.d.ts +66 -0
- package/dist/runtime/hook-file-hooks.d.ts +18 -0
- package/dist/runtime/rules.d.ts +5 -0
- package/dist/runtime/runtime-builder.d.ts +5 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts +19 -0
- package/dist/runtime/session-runtime.d.ts +36 -0
- package/dist/runtime/tool-approval.d.ts +9 -0
- package/dist/runtime/workflows.d.ts +13 -0
- package/dist/server/index.d.ts +47 -0
- package/dist/server/index.js +641 -0
- package/dist/session/default-session-manager.d.ts +77 -0
- package/dist/session/rpc-session-service.d.ts +12 -0
- package/dist/session/runtime-oauth-token-manager.d.ts +28 -0
- package/dist/session/session-artifacts.d.ts +19 -0
- package/dist/session/session-graph.d.ts +15 -0
- package/dist/session/session-host.d.ts +21 -0
- package/dist/session/session-manager.d.ts +50 -0
- package/dist/session/session-manifest.d.ts +30 -0
- package/dist/session/session-service.d.ts +113 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts +30 -0
- package/dist/session/unified-session-persistence-service.d.ts +93 -0
- package/dist/session/workspace-manager.d.ts +28 -0
- package/dist/session/workspace-manifest.d.ts +25 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts +13 -0
- package/dist/storage/provider-settings-manager.d.ts +20 -0
- package/dist/storage/sqlite-session-store.d.ts +29 -0
- package/dist/storage/sqlite-team-store.d.ts +31 -0
- package/dist/storage/team-store.d.ts +2 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/projections.d.ts +8 -0
- package/dist/types/common.d.ts +10 -0
- package/dist/types/config.d.ts +37 -0
- package/dist/types/events.d.ts +54 -0
- package/dist/types/provider-settings.d.ts +20 -0
- package/dist/types/sessions.d.ts +9 -0
- package/dist/types/storage.d.ts +37 -0
- package/dist/types/workspace.d.ts +7 -0
- package/dist/types.d.ts +26 -0
- package/package.json +63 -0
- package/src/account/cline-account-service.test.ts +101 -0
- package/src/account/cline-account-service.ts +267 -0
- package/src/account/index.ts +20 -0
- package/src/account/rpc.test.ts +62 -0
- package/src/account/rpc.ts +172 -0
- package/src/account/types.ts +80 -0
- package/src/agents/agent-config-loader.test.ts +234 -0
- package/src/agents/agent-config-loader.ts +107 -0
- package/src/agents/agent-config-parser.ts +191 -0
- package/src/agents/hooks-config-loader.ts +97 -0
- package/src/agents/index.ts +84 -0
- package/src/agents/plugin-config-loader.test.ts +91 -0
- package/src/agents/plugin-config-loader.ts +160 -0
- package/src/agents/plugin-loader.test.ts +102 -0
- package/src/agents/plugin-loader.ts +105 -0
- package/src/agents/plugin-sandbox.test.ts +120 -0
- package/src/agents/plugin-sandbox.ts +471 -0
- package/src/agents/unified-config-file-watcher.test.ts +196 -0
- package/src/agents/unified-config-file-watcher.ts +483 -0
- package/src/agents/user-instruction-config-loader.test.ts +158 -0
- package/src/agents/user-instruction-config-loader.ts +438 -0
- package/src/auth/client.test.ts +40 -0
- package/src/auth/client.ts +25 -0
- package/src/auth/cline.test.ts +130 -0
- package/src/auth/cline.ts +414 -0
- package/src/auth/codex.test.ts +170 -0
- package/src/auth/codex.ts +466 -0
- package/src/auth/oca.test.ts +215 -0
- package/src/auth/oca.ts +546 -0
- package/src/auth/server.ts +216 -0
- package/src/auth/types.ts +78 -0
- package/src/auth/utils.test.ts +128 -0
- package/src/auth/utils.ts +247 -0
- package/src/chat/chat-schema.ts +82 -0
- package/src/default-tools/constants.ts +35 -0
- package/src/default-tools/definitions.test.ts +233 -0
- package/src/default-tools/definitions.ts +632 -0
- package/src/default-tools/executors/apply-patch-parser.ts +520 -0
- package/src/default-tools/executors/apply-patch.ts +359 -0
- package/src/default-tools/executors/bash.ts +205 -0
- package/src/default-tools/executors/editor.ts +231 -0
- package/src/default-tools/executors/file-read.test.ts +25 -0
- package/src/default-tools/executors/file-read.ts +94 -0
- package/src/default-tools/executors/index.ts +75 -0
- package/src/default-tools/executors/search.ts +278 -0
- package/src/default-tools/executors/web-fetch.ts +259 -0
- package/src/default-tools/index.ts +161 -0
- package/src/default-tools/presets.test.ts +63 -0
- package/src/default-tools/presets.ts +168 -0
- package/src/default-tools/schemas.ts +228 -0
- package/src/default-tools/types.ts +324 -0
- package/src/index.ts +119 -0
- package/src/input/file-indexer.d.ts +11 -0
- package/src/input/file-indexer.test.ts +87 -0
- package/src/input/file-indexer.ts +280 -0
- package/src/input/index.ts +7 -0
- package/src/input/mention-enricher.test.ts +82 -0
- package/src/input/mention-enricher.ts +119 -0
- package/src/mcp/config-loader.test.ts +238 -0
- package/src/mcp/config-loader.ts +219 -0
- package/src/mcp/index.ts +26 -0
- package/src/mcp/manager.test.ts +106 -0
- package/src/mcp/manager.ts +262 -0
- package/src/mcp/types.ts +88 -0
- package/src/runtime/hook-file-hooks.test.ts +106 -0
- package/src/runtime/hook-file-hooks.ts +736 -0
- package/src/runtime/index.ts +27 -0
- package/src/runtime/rules.ts +34 -0
- package/src/runtime/runtime-builder.team-persistence.test.ts +203 -0
- package/src/runtime/runtime-builder.test.ts +215 -0
- package/src/runtime/runtime-builder.ts +515 -0
- package/src/runtime/runtime-parity.test.ts +132 -0
- package/src/runtime/sandbox/subprocess-sandbox.ts +207 -0
- package/src/runtime/session-runtime.ts +44 -0
- package/src/runtime/tool-approval.ts +104 -0
- package/src/runtime/workflows.test.ts +119 -0
- package/src/runtime/workflows.ts +54 -0
- package/src/server/index.ts +282 -0
- package/src/session/default-session-manager.e2e.test.ts +354 -0
- package/src/session/default-session-manager.test.ts +816 -0
- package/src/session/default-session-manager.ts +1286 -0
- package/src/session/index.ts +37 -0
- package/src/session/rpc-session-service.ts +189 -0
- package/src/session/runtime-oauth-token-manager.test.ts +137 -0
- package/src/session/runtime-oauth-token-manager.ts +265 -0
- package/src/session/session-artifacts.ts +106 -0
- package/src/session/session-graph.ts +90 -0
- package/src/session/session-host.ts +190 -0
- package/src/session/session-manager.ts +56 -0
- package/src/session/session-manifest.ts +29 -0
- package/src/session/session-service.team-persistence.test.ts +48 -0
- package/src/session/session-service.ts +610 -0
- package/src/session/sqlite-rpc-session-backend.ts +303 -0
- package/src/session/unified-session-persistence-service.ts +781 -0
- package/src/session/workspace-manager.ts +98 -0
- package/src/session/workspace-manifest.ts +100 -0
- package/src/storage/artifact-store.ts +1 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/provider-settings-legacy-migration.test.ts +175 -0
- package/src/storage/provider-settings-legacy-migration.ts +637 -0
- package/src/storage/provider-settings-manager.test.ts +111 -0
- package/src/storage/provider-settings-manager.ts +129 -0
- package/src/storage/session-store.ts +1 -0
- package/src/storage/sqlite-session-store.ts +270 -0
- package/src/storage/sqlite-team-store.ts +443 -0
- package/src/storage/team-store.ts +5 -0
- package/src/team/index.ts +4 -0
- package/src/team/projections.ts +285 -0
- package/src/types/common.ts +14 -0
- package/src/types/config.ts +64 -0
- package/src/types/events.ts +46 -0
- package/src/types/index.ts +24 -0
- package/src/types/provider-settings.ts +43 -0
- package/src/types/sessions.ts +16 -0
- package/src/types/storage.ts +64 -0
- package/src/types/workspace.ts +7 -0
- package/src/types.ts +127 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RpcSessionBackend,
|
|
3
|
+
RpcSessionRow,
|
|
4
|
+
RpcSessionStatus,
|
|
5
|
+
RpcSessionUpdateInput,
|
|
6
|
+
RpcSpawnQueueItem,
|
|
7
|
+
} from "@clinebot/rpc";
|
|
8
|
+
import {
|
|
9
|
+
asBool,
|
|
10
|
+
asOptionalString,
|
|
11
|
+
asString,
|
|
12
|
+
nowIso,
|
|
13
|
+
toBoolInt,
|
|
14
|
+
} from "@clinebot/shared/db";
|
|
15
|
+
import { SqliteSessionStore } from "../storage/sqlite-session-store";
|
|
16
|
+
|
|
17
|
+
export interface SqliteRpcSessionBackendOptions {
|
|
18
|
+
sessionsDir?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class SqliteRpcSessionBackend implements RpcSessionBackend {
|
|
22
|
+
private readonly store: SqliteSessionStore;
|
|
23
|
+
|
|
24
|
+
constructor(options: SqliteRpcSessionBackendOptions = {}) {
|
|
25
|
+
this.store = new SqliteSessionStore({ sessionsDir: options.sessionsDir });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public init(): void {
|
|
29
|
+
this.store.init();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public upsertSession(row: RpcSessionRow): void {
|
|
33
|
+
this.store.run(
|
|
34
|
+
`INSERT OR REPLACE INTO sessions (
|
|
35
|
+
session_id, source, pid, started_at, ended_at, exit_code, status, status_lock, interactive,
|
|
36
|
+
provider, model, cwd, workspace_root, team_name, enable_tools, enable_spawn, enable_teams,
|
|
37
|
+
parent_session_id, parent_agent_id, agent_id, conversation_id, is_subagent, prompt,
|
|
38
|
+
metadata_json, transcript_path, hook_path, messages_path, updated_at
|
|
39
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
40
|
+
[
|
|
41
|
+
row.sessionId,
|
|
42
|
+
row.source,
|
|
43
|
+
row.pid,
|
|
44
|
+
row.startedAt,
|
|
45
|
+
row.endedAt ?? null,
|
|
46
|
+
row.exitCode ?? null,
|
|
47
|
+
row.status,
|
|
48
|
+
row.statusLock,
|
|
49
|
+
toBoolInt(row.interactive),
|
|
50
|
+
row.provider,
|
|
51
|
+
row.model,
|
|
52
|
+
row.cwd,
|
|
53
|
+
row.workspaceRoot,
|
|
54
|
+
row.teamName ?? null,
|
|
55
|
+
toBoolInt(row.enableTools),
|
|
56
|
+
toBoolInt(row.enableSpawn),
|
|
57
|
+
toBoolInt(row.enableTeams),
|
|
58
|
+
row.parentSessionId ?? null,
|
|
59
|
+
row.parentAgentId ?? null,
|
|
60
|
+
row.agentId ?? null,
|
|
61
|
+
row.conversationId ?? null,
|
|
62
|
+
toBoolInt(row.isSubagent),
|
|
63
|
+
row.prompt ?? null,
|
|
64
|
+
row.metadata ? JSON.stringify(row.metadata) : null,
|
|
65
|
+
row.transcriptPath,
|
|
66
|
+
row.hookPath,
|
|
67
|
+
row.messagesPath ?? null,
|
|
68
|
+
row.updatedAt || nowIso(),
|
|
69
|
+
],
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getSession(sessionId: string): RpcSessionRow | undefined {
|
|
74
|
+
const row = this.store.queryOne<Record<string, unknown>>(
|
|
75
|
+
`SELECT session_id, source, pid, started_at, ended_at, exit_code, status, status_lock, interactive,
|
|
76
|
+
provider, model, cwd, workspace_root, team_name, enable_tools, enable_spawn, enable_teams,
|
|
77
|
+
parent_session_id, parent_agent_id, agent_id, conversation_id, is_subagent, prompt,
|
|
78
|
+
metadata_json, transcript_path, hook_path, messages_path, updated_at
|
|
79
|
+
FROM sessions WHERE session_id = ?`,
|
|
80
|
+
[sessionId],
|
|
81
|
+
);
|
|
82
|
+
if (!row) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
sessionId: asString(row.session_id),
|
|
87
|
+
source: asString(row.source),
|
|
88
|
+
pid: Number(row.pid ?? 0),
|
|
89
|
+
startedAt: asString(row.started_at),
|
|
90
|
+
endedAt: (row.ended_at as string | null | undefined) ?? null,
|
|
91
|
+
exitCode: (row.exit_code as number | null | undefined) ?? null,
|
|
92
|
+
status: asString(row.status) as RpcSessionStatus,
|
|
93
|
+
statusLock: Number(row.status_lock ?? 0),
|
|
94
|
+
interactive: asBool(row.interactive),
|
|
95
|
+
provider: asString(row.provider),
|
|
96
|
+
model: asString(row.model),
|
|
97
|
+
cwd: asString(row.cwd),
|
|
98
|
+
workspaceRoot: asString(row.workspace_root),
|
|
99
|
+
teamName: asOptionalString(row.team_name),
|
|
100
|
+
enableTools: asBool(row.enable_tools),
|
|
101
|
+
enableSpawn: asBool(row.enable_spawn),
|
|
102
|
+
enableTeams: asBool(row.enable_teams),
|
|
103
|
+
parentSessionId: asOptionalString(row.parent_session_id),
|
|
104
|
+
parentAgentId: asOptionalString(row.parent_agent_id),
|
|
105
|
+
agentId: asOptionalString(row.agent_id),
|
|
106
|
+
conversationId: asOptionalString(row.conversation_id),
|
|
107
|
+
isSubagent: asBool(row.is_subagent),
|
|
108
|
+
prompt: asOptionalString(row.prompt),
|
|
109
|
+
metadata: (() => {
|
|
110
|
+
const raw = asOptionalString(row.metadata_json);
|
|
111
|
+
if (!raw) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
116
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
117
|
+
return parsed as Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
} catch {
|
|
120
|
+
// Ignore malformed metadata payloads.
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
})(),
|
|
124
|
+
transcriptPath: asString(row.transcript_path),
|
|
125
|
+
hookPath: asString(row.hook_path),
|
|
126
|
+
messagesPath: asOptionalString(row.messages_path),
|
|
127
|
+
updatedAt: asString(row.updated_at) || nowIso(),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public listSessions(options: {
|
|
132
|
+
limit: number;
|
|
133
|
+
parentSessionId?: string;
|
|
134
|
+
status?: string;
|
|
135
|
+
}): RpcSessionRow[] {
|
|
136
|
+
const where: string[] = [];
|
|
137
|
+
const params: unknown[] = [];
|
|
138
|
+
if (options.parentSessionId) {
|
|
139
|
+
where.push("parent_session_id = ?");
|
|
140
|
+
params.push(options.parentSessionId);
|
|
141
|
+
}
|
|
142
|
+
if (options.status) {
|
|
143
|
+
where.push("status = ?");
|
|
144
|
+
params.push(options.status);
|
|
145
|
+
}
|
|
146
|
+
const whereClause = where.length > 0 ? `WHERE ${where.join(" AND ")}` : "";
|
|
147
|
+
const limit = Math.max(1, Math.floor(options.limit));
|
|
148
|
+
const rows = this.store.queryAll<{ session_id?: string }>(
|
|
149
|
+
`SELECT session_id FROM sessions ${whereClause} ORDER BY started_at DESC LIMIT ?`,
|
|
150
|
+
[...params, limit],
|
|
151
|
+
);
|
|
152
|
+
const out: RpcSessionRow[] = [];
|
|
153
|
+
for (const row of rows) {
|
|
154
|
+
if (!row.session_id) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const item = this.getSession(row.session_id);
|
|
158
|
+
if (item) {
|
|
159
|
+
out.push(item);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public updateSession(input: RpcSessionUpdateInput): {
|
|
166
|
+
updated: boolean;
|
|
167
|
+
statusLock: number;
|
|
168
|
+
} {
|
|
169
|
+
const existing = this.getSession(input.sessionId);
|
|
170
|
+
if (!existing) {
|
|
171
|
+
return { updated: false, statusLock: 0 };
|
|
172
|
+
}
|
|
173
|
+
if (
|
|
174
|
+
typeof input.expectedStatusLock === "number" &&
|
|
175
|
+
existing.statusLock !== input.expectedStatusLock
|
|
176
|
+
) {
|
|
177
|
+
return { updated: false, statusLock: existing.statusLock };
|
|
178
|
+
}
|
|
179
|
+
const nextLock = existing.statusLock + 1;
|
|
180
|
+
const nextStatus = input.setRunning
|
|
181
|
+
? "running"
|
|
182
|
+
: (input.status ?? existing.status);
|
|
183
|
+
const nextEndedAt =
|
|
184
|
+
input.setRunning === true
|
|
185
|
+
? null
|
|
186
|
+
: input.endedAt !== undefined
|
|
187
|
+
? input.endedAt
|
|
188
|
+
: (existing.endedAt ?? null);
|
|
189
|
+
const nextExitCode =
|
|
190
|
+
input.setRunning === true
|
|
191
|
+
? null
|
|
192
|
+
: input.exitCode !== undefined
|
|
193
|
+
? input.exitCode
|
|
194
|
+
: (existing.exitCode ?? null);
|
|
195
|
+
const nextPrompt =
|
|
196
|
+
input.prompt !== undefined
|
|
197
|
+
? (input.prompt ?? undefined)
|
|
198
|
+
: existing.prompt;
|
|
199
|
+
const nextMetadata =
|
|
200
|
+
input.metadata !== undefined
|
|
201
|
+
? (input.metadata ?? undefined)
|
|
202
|
+
: existing.metadata;
|
|
203
|
+
|
|
204
|
+
this.store.run(
|
|
205
|
+
`UPDATE sessions
|
|
206
|
+
SET status = ?, ended_at = ?, exit_code = ?, prompt = ?, metadata_json = ?,
|
|
207
|
+
parent_session_id = ?, parent_agent_id = ?, agent_id = ?, conversation_id = ?,
|
|
208
|
+
status_lock = ?, updated_at = ?
|
|
209
|
+
WHERE session_id = ?`,
|
|
210
|
+
[
|
|
211
|
+
nextStatus,
|
|
212
|
+
nextEndedAt,
|
|
213
|
+
nextExitCode,
|
|
214
|
+
nextPrompt ?? null,
|
|
215
|
+
nextMetadata ? JSON.stringify(nextMetadata) : null,
|
|
216
|
+
input.parentSessionId !== undefined
|
|
217
|
+
? (input.parentSessionId ?? null)
|
|
218
|
+
: (existing.parentSessionId ?? null),
|
|
219
|
+
input.parentAgentId !== undefined
|
|
220
|
+
? (input.parentAgentId ?? null)
|
|
221
|
+
: (existing.parentAgentId ?? null),
|
|
222
|
+
input.agentId !== undefined
|
|
223
|
+
? (input.agentId ?? null)
|
|
224
|
+
: (existing.agentId ?? null),
|
|
225
|
+
input.conversationId !== undefined
|
|
226
|
+
? (input.conversationId ?? null)
|
|
227
|
+
: (existing.conversationId ?? null),
|
|
228
|
+
nextLock,
|
|
229
|
+
nowIso(),
|
|
230
|
+
input.sessionId,
|
|
231
|
+
],
|
|
232
|
+
);
|
|
233
|
+
return { updated: true, statusLock: nextLock };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public deleteSession(sessionId: string): boolean {
|
|
237
|
+
const changes =
|
|
238
|
+
this.store.run("DELETE FROM sessions WHERE session_id = ?", [sessionId])
|
|
239
|
+
.changes ?? 0;
|
|
240
|
+
return changes > 0;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public deleteSessionsByParent(parentSessionId: string): void {
|
|
244
|
+
this.store.run("DELETE FROM sessions WHERE parent_session_id = ?", [
|
|
245
|
+
parentSessionId,
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
public enqueueSpawnRequest(input: {
|
|
250
|
+
rootSessionId: string;
|
|
251
|
+
parentAgentId: string;
|
|
252
|
+
task?: string;
|
|
253
|
+
systemPrompt?: string;
|
|
254
|
+
}): void {
|
|
255
|
+
this.store.run(
|
|
256
|
+
`INSERT INTO subagent_spawn_queue (root_session_id, parent_agent_id, task, system_prompt, created_at, consumed_at)
|
|
257
|
+
VALUES (?, ?, ?, ?, ?, NULL)`,
|
|
258
|
+
[
|
|
259
|
+
input.rootSessionId,
|
|
260
|
+
input.parentAgentId,
|
|
261
|
+
input.task ?? null,
|
|
262
|
+
input.systemPrompt ?? null,
|
|
263
|
+
nowIso(),
|
|
264
|
+
],
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public claimSpawnRequest(
|
|
269
|
+
rootSessionId: string,
|
|
270
|
+
parentAgentId: string,
|
|
271
|
+
): RpcSpawnQueueItem | undefined {
|
|
272
|
+
const row = this.store.queryOne<Record<string, unknown>>(
|
|
273
|
+
`SELECT id, root_session_id, parent_agent_id, task, system_prompt, created_at, consumed_at
|
|
274
|
+
FROM subagent_spawn_queue
|
|
275
|
+
WHERE root_session_id = ? AND parent_agent_id = ? AND consumed_at IS NULL
|
|
276
|
+
ORDER BY id ASC LIMIT 1`,
|
|
277
|
+
[rootSessionId, parentAgentId],
|
|
278
|
+
);
|
|
279
|
+
if (!row || typeof row.id !== "number") {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const consumedAt = nowIso();
|
|
283
|
+
this.store.run(
|
|
284
|
+
"UPDATE subagent_spawn_queue SET consumed_at = ? WHERE id = ?",
|
|
285
|
+
[consumedAt, row.id],
|
|
286
|
+
);
|
|
287
|
+
return {
|
|
288
|
+
id: row.id,
|
|
289
|
+
rootSessionId: asString(row.root_session_id),
|
|
290
|
+
parentAgentId: asString(row.parent_agent_id),
|
|
291
|
+
task: asOptionalString(row.task),
|
|
292
|
+
systemPrompt: asOptionalString(row.system_prompt),
|
|
293
|
+
createdAt: asString(row.created_at),
|
|
294
|
+
consumedAt,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function createSqliteRpcSessionBackend(
|
|
300
|
+
options: SqliteRpcSessionBackendOptions = {},
|
|
301
|
+
): RpcSessionBackend {
|
|
302
|
+
return new SqliteRpcSessionBackend(options);
|
|
303
|
+
}
|