@copilotkitnext/sqlite-runner 0.0.15
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/.turbo/turbo-build.log +23 -0
- package/LICENSE +11 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +325 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +293 -0
- package/dist/index.mjs.map +1 -0
- package/eslint.config.mjs +3 -0
- package/package.json +54 -0
- package/src/__tests__/sqlite-runner.e2e.test.ts +765 -0
- package/src/__tests__/sqlite-runner.test.ts +226 -0
- package/src/index.ts +1 -0
- package/src/sqlite-runner.ts +419 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +11 -0
- package/vitest.config.mjs +15 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @copilotkitnext/sqlite-runner@0.0.14 build /Users/mme/Projects/CopilotKit2/main/packages/sqlite-runner
|
|
4
|
+
> tsup
|
|
5
|
+
|
|
6
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
7
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
+
[34mCLI[39m tsup v8.5.0
|
|
9
|
+
[34mCLI[39m Using tsup config: /Users/mme/Projects/CopilotKit2/main/packages/sqlite-runner/tsup.config.ts
|
|
10
|
+
[34mCLI[39m Target: es2022
|
|
11
|
+
[34mCLI[39m Cleaning output folder
|
|
12
|
+
[34mCJS[39m Build start
|
|
13
|
+
[34mESM[39m Build start
|
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.26 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m18.80 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 11ms
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m9.50 KB[39m
|
|
18
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m18.71 KB[39m
|
|
19
|
+
[32mESM[39m ⚡️ Build success in 11ms
|
|
20
|
+
DTS Build start
|
|
21
|
+
DTS ⚡️ Build success in 1162ms
|
|
22
|
+
DTS dist/index.d.ts 1010.00 B
|
|
23
|
+
DTS dist/index.d.mts 1010.00 B
|
package/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Note: This license does not apply to the whole project. Individual packages may contain their own licenses.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright 2025 Tawkit Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AgentRunner, AgentRunnerRunRequest, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerStopRequest } from '@copilotkitnext/runtime';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { BaseEvent } from '@ag-ui/client';
|
|
4
|
+
|
|
5
|
+
interface SqliteAgentRunnerOptions {
|
|
6
|
+
dbPath?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class SqliteAgentRunner extends AgentRunner {
|
|
9
|
+
private db;
|
|
10
|
+
constructor(options?: SqliteAgentRunnerOptions);
|
|
11
|
+
private initializeSchema;
|
|
12
|
+
private storeRun;
|
|
13
|
+
private getHistoricRuns;
|
|
14
|
+
private getLatestRunId;
|
|
15
|
+
private setRunState;
|
|
16
|
+
private getRunState;
|
|
17
|
+
run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
|
|
18
|
+
connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
|
|
19
|
+
isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
|
|
20
|
+
stop(_request: AgentRunnerStopRequest): Promise<boolean | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Close the database connection (for cleanup)
|
|
23
|
+
*/
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { SqliteAgentRunner, type SqliteAgentRunnerOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AgentRunner, AgentRunnerRunRequest, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerStopRequest } from '@copilotkitnext/runtime';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { BaseEvent } from '@ag-ui/client';
|
|
4
|
+
|
|
5
|
+
interface SqliteAgentRunnerOptions {
|
|
6
|
+
dbPath?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class SqliteAgentRunner extends AgentRunner {
|
|
9
|
+
private db;
|
|
10
|
+
constructor(options?: SqliteAgentRunnerOptions);
|
|
11
|
+
private initializeSchema;
|
|
12
|
+
private storeRun;
|
|
13
|
+
private getHistoricRuns;
|
|
14
|
+
private getLatestRunId;
|
|
15
|
+
private setRunState;
|
|
16
|
+
private getRunState;
|
|
17
|
+
run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
|
|
18
|
+
connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
|
|
19
|
+
isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
|
|
20
|
+
stop(_request: AgentRunnerStopRequest): Promise<boolean | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Close the database connection (for cleanup)
|
|
23
|
+
*/
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { SqliteAgentRunner, type SqliteAgentRunnerOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
SqliteAgentRunner: () => SqliteAgentRunner
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/sqlite-runner.ts
|
|
38
|
+
var import_runtime = require("@copilotkitnext/runtime");
|
|
39
|
+
var import_rxjs = require("rxjs");
|
|
40
|
+
var import_client = require("@ag-ui/client");
|
|
41
|
+
var import_better_sqlite3 = __toESM(require("better-sqlite3"));
|
|
42
|
+
var SCHEMA_VERSION = 1;
|
|
43
|
+
var ACTIVE_CONNECTIONS = /* @__PURE__ */ new Map();
|
|
44
|
+
var SqliteAgentRunner = class extends import_runtime.AgentRunner {
|
|
45
|
+
db;
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
super();
|
|
48
|
+
const dbPath = options.dbPath ?? ":memory:";
|
|
49
|
+
if (!import_better_sqlite3.default) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"better-sqlite3 is required for SqliteAgentRunner but was not found.\nPlease install it in your project:\n npm install better-sqlite3\n or\n pnpm add better-sqlite3\n or\n yarn add better-sqlite3\n\nIf you don't need persistence, use InMemoryAgentRunner instead."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
this.db = new import_better_sqlite3.default(dbPath);
|
|
55
|
+
this.initializeSchema();
|
|
56
|
+
}
|
|
57
|
+
initializeSchema() {
|
|
58
|
+
this.db.exec(`
|
|
59
|
+
CREATE TABLE IF NOT EXISTS agent_runs (
|
|
60
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
61
|
+
thread_id TEXT NOT NULL,
|
|
62
|
+
run_id TEXT NOT NULL UNIQUE,
|
|
63
|
+
parent_run_id TEXT,
|
|
64
|
+
events TEXT NOT NULL,
|
|
65
|
+
input TEXT NOT NULL,
|
|
66
|
+
created_at INTEGER NOT NULL,
|
|
67
|
+
version INTEGER NOT NULL
|
|
68
|
+
)
|
|
69
|
+
`);
|
|
70
|
+
this.db.exec(`
|
|
71
|
+
CREATE TABLE IF NOT EXISTS run_state (
|
|
72
|
+
thread_id TEXT PRIMARY KEY,
|
|
73
|
+
is_running INTEGER DEFAULT 0,
|
|
74
|
+
current_run_id TEXT,
|
|
75
|
+
updated_at INTEGER NOT NULL
|
|
76
|
+
)
|
|
77
|
+
`);
|
|
78
|
+
this.db.exec(`
|
|
79
|
+
CREATE INDEX IF NOT EXISTS idx_thread_id ON agent_runs(thread_id);
|
|
80
|
+
CREATE INDEX IF NOT EXISTS idx_parent_run_id ON agent_runs(parent_run_id);
|
|
81
|
+
`);
|
|
82
|
+
this.db.exec(`
|
|
83
|
+
CREATE TABLE IF NOT EXISTS schema_version (
|
|
84
|
+
version INTEGER PRIMARY KEY,
|
|
85
|
+
applied_at INTEGER NOT NULL
|
|
86
|
+
)
|
|
87
|
+
`);
|
|
88
|
+
const currentVersion = this.db.prepare("SELECT version FROM schema_version ORDER BY version DESC LIMIT 1").get();
|
|
89
|
+
if (!currentVersion || currentVersion.version < SCHEMA_VERSION) {
|
|
90
|
+
this.db.prepare("INSERT OR REPLACE INTO schema_version (version, applied_at) VALUES (?, ?)").run(SCHEMA_VERSION, Date.now());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
storeRun(threadId, runId, events, input, parentRunId) {
|
|
94
|
+
const compactedEvents = (0, import_client.compactEvents)(events);
|
|
95
|
+
const stmt = this.db.prepare(`
|
|
96
|
+
INSERT INTO agent_runs (thread_id, run_id, parent_run_id, events, input, created_at, version)
|
|
97
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
98
|
+
`);
|
|
99
|
+
stmt.run(
|
|
100
|
+
threadId,
|
|
101
|
+
runId,
|
|
102
|
+
parentRunId ?? null,
|
|
103
|
+
JSON.stringify(compactedEvents),
|
|
104
|
+
// Store only this run's compacted events
|
|
105
|
+
JSON.stringify(input),
|
|
106
|
+
Date.now(),
|
|
107
|
+
SCHEMA_VERSION
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
getHistoricRuns(threadId) {
|
|
111
|
+
const stmt = this.db.prepare(`
|
|
112
|
+
WITH RECURSIVE run_chain AS (
|
|
113
|
+
-- Base case: find the root runs (those without parent)
|
|
114
|
+
SELECT * FROM agent_runs
|
|
115
|
+
WHERE thread_id = ? AND parent_run_id IS NULL
|
|
116
|
+
|
|
117
|
+
UNION ALL
|
|
118
|
+
|
|
119
|
+
-- Recursive case: find children of current level
|
|
120
|
+
SELECT ar.* FROM agent_runs ar
|
|
121
|
+
INNER JOIN run_chain rc ON ar.parent_run_id = rc.run_id
|
|
122
|
+
WHERE ar.thread_id = ?
|
|
123
|
+
)
|
|
124
|
+
SELECT * FROM run_chain
|
|
125
|
+
ORDER BY created_at ASC
|
|
126
|
+
`);
|
|
127
|
+
const rows = stmt.all(threadId, threadId);
|
|
128
|
+
return rows.map((row) => ({
|
|
129
|
+
id: row.id,
|
|
130
|
+
thread_id: row.thread_id,
|
|
131
|
+
run_id: row.run_id,
|
|
132
|
+
parent_run_id: row.parent_run_id,
|
|
133
|
+
events: JSON.parse(row.events),
|
|
134
|
+
input: JSON.parse(row.input),
|
|
135
|
+
created_at: row.created_at,
|
|
136
|
+
version: row.version
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
getLatestRunId(threadId) {
|
|
140
|
+
const stmt = this.db.prepare(`
|
|
141
|
+
SELECT run_id FROM agent_runs
|
|
142
|
+
WHERE thread_id = ?
|
|
143
|
+
ORDER BY created_at DESC
|
|
144
|
+
LIMIT 1
|
|
145
|
+
`);
|
|
146
|
+
const result = stmt.get(threadId);
|
|
147
|
+
return result?.run_id ?? null;
|
|
148
|
+
}
|
|
149
|
+
setRunState(threadId, isRunning, runId) {
|
|
150
|
+
const stmt = this.db.prepare(`
|
|
151
|
+
INSERT OR REPLACE INTO run_state (thread_id, is_running, current_run_id, updated_at)
|
|
152
|
+
VALUES (?, ?, ?, ?)
|
|
153
|
+
`);
|
|
154
|
+
stmt.run(threadId, isRunning ? 1 : 0, runId ?? null, Date.now());
|
|
155
|
+
}
|
|
156
|
+
getRunState(threadId) {
|
|
157
|
+
const stmt = this.db.prepare(`
|
|
158
|
+
SELECT is_running, current_run_id FROM run_state WHERE thread_id = ?
|
|
159
|
+
`);
|
|
160
|
+
const result = stmt.get(threadId);
|
|
161
|
+
return {
|
|
162
|
+
isRunning: result?.is_running === 1,
|
|
163
|
+
currentRunId: result?.current_run_id ?? null
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
run(request) {
|
|
167
|
+
const runState = this.getRunState(request.threadId);
|
|
168
|
+
if (runState.isRunning) {
|
|
169
|
+
throw new Error("Thread already running");
|
|
170
|
+
}
|
|
171
|
+
this.setRunState(request.threadId, true, request.input.runId);
|
|
172
|
+
const seenMessageIds = /* @__PURE__ */ new Set();
|
|
173
|
+
const currentRunEvents = [];
|
|
174
|
+
const historicRuns = this.getHistoricRuns(request.threadId);
|
|
175
|
+
const historicMessageIds = /* @__PURE__ */ new Set();
|
|
176
|
+
for (const run of historicRuns) {
|
|
177
|
+
for (const event of run.events) {
|
|
178
|
+
if ("messageId" in event && typeof event.messageId === "string") {
|
|
179
|
+
historicMessageIds.add(event.messageId);
|
|
180
|
+
}
|
|
181
|
+
if (event.type === import_client.EventType.RUN_STARTED) {
|
|
182
|
+
const runStarted = event;
|
|
183
|
+
const messages = runStarted.input?.messages ?? [];
|
|
184
|
+
for (const message of messages) {
|
|
185
|
+
historicMessageIds.add(message.id);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const nextSubject = new import_rxjs.ReplaySubject(Infinity);
|
|
191
|
+
const prevSubject = ACTIVE_CONNECTIONS.get(request.threadId);
|
|
192
|
+
ACTIVE_CONNECTIONS.set(request.threadId, nextSubject);
|
|
193
|
+
const runSubject = new import_rxjs.ReplaySubject(Infinity);
|
|
194
|
+
const runAgent = async () => {
|
|
195
|
+
const parentRunId = this.getLatestRunId(request.threadId);
|
|
196
|
+
try {
|
|
197
|
+
await request.agent.runAgent(request.input, {
|
|
198
|
+
onEvent: ({ event }) => {
|
|
199
|
+
let processedEvent = event;
|
|
200
|
+
if (event.type === import_client.EventType.RUN_STARTED) {
|
|
201
|
+
const runStartedEvent = event;
|
|
202
|
+
if (!runStartedEvent.input) {
|
|
203
|
+
const sanitizedMessages = request.input.messages ? request.input.messages.filter(
|
|
204
|
+
(message) => !historicMessageIds.has(message.id)
|
|
205
|
+
) : void 0;
|
|
206
|
+
const updatedInput = {
|
|
207
|
+
...request.input,
|
|
208
|
+
...sanitizedMessages !== void 0 ? { messages: sanitizedMessages } : {}
|
|
209
|
+
};
|
|
210
|
+
processedEvent = {
|
|
211
|
+
...runStartedEvent,
|
|
212
|
+
input: updatedInput
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
runSubject.next(processedEvent);
|
|
217
|
+
nextSubject.next(processedEvent);
|
|
218
|
+
currentRunEvents.push(processedEvent);
|
|
219
|
+
},
|
|
220
|
+
onNewMessage: ({ message }) => {
|
|
221
|
+
if (!seenMessageIds.has(message.id)) {
|
|
222
|
+
seenMessageIds.add(message.id);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
onRunStartedEvent: () => {
|
|
226
|
+
if (request.input.messages) {
|
|
227
|
+
for (const message of request.input.messages) {
|
|
228
|
+
if (!seenMessageIds.has(message.id)) {
|
|
229
|
+
seenMessageIds.add(message.id);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
this.storeRun(
|
|
236
|
+
request.threadId,
|
|
237
|
+
request.input.runId,
|
|
238
|
+
currentRunEvents,
|
|
239
|
+
request.input,
|
|
240
|
+
parentRunId
|
|
241
|
+
);
|
|
242
|
+
this.setRunState(request.threadId, false);
|
|
243
|
+
runSubject.complete();
|
|
244
|
+
nextSubject.complete();
|
|
245
|
+
} catch {
|
|
246
|
+
if (currentRunEvents.length > 0) {
|
|
247
|
+
this.storeRun(
|
|
248
|
+
request.threadId,
|
|
249
|
+
request.input.runId,
|
|
250
|
+
currentRunEvents,
|
|
251
|
+
request.input,
|
|
252
|
+
parentRunId
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
this.setRunState(request.threadId, false);
|
|
256
|
+
runSubject.complete();
|
|
257
|
+
nextSubject.complete();
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
if (prevSubject) {
|
|
261
|
+
prevSubject.subscribe({
|
|
262
|
+
next: (e) => nextSubject.next(e),
|
|
263
|
+
error: (err) => nextSubject.error(err),
|
|
264
|
+
complete: () => {
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
runAgent();
|
|
269
|
+
return runSubject.asObservable();
|
|
270
|
+
}
|
|
271
|
+
connect(request) {
|
|
272
|
+
const connectionSubject = new import_rxjs.ReplaySubject(Infinity);
|
|
273
|
+
const historicRuns = this.getHistoricRuns(request.threadId);
|
|
274
|
+
const allHistoricEvents = [];
|
|
275
|
+
for (const run of historicRuns) {
|
|
276
|
+
allHistoricEvents.push(...run.events);
|
|
277
|
+
}
|
|
278
|
+
const compactedEvents = (0, import_client.compactEvents)(allHistoricEvents);
|
|
279
|
+
const emittedMessageIds = /* @__PURE__ */ new Set();
|
|
280
|
+
for (const event of compactedEvents) {
|
|
281
|
+
connectionSubject.next(event);
|
|
282
|
+
if ("messageId" in event && typeof event.messageId === "string") {
|
|
283
|
+
emittedMessageIds.add(event.messageId);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const activeSubject = ACTIVE_CONNECTIONS.get(request.threadId);
|
|
287
|
+
const runState = this.getRunState(request.threadId);
|
|
288
|
+
if (activeSubject && runState.isRunning) {
|
|
289
|
+
activeSubject.subscribe({
|
|
290
|
+
next: (event) => {
|
|
291
|
+
if ("messageId" in event && typeof event.messageId === "string" && emittedMessageIds.has(event.messageId)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
connectionSubject.next(event);
|
|
295
|
+
},
|
|
296
|
+
complete: () => connectionSubject.complete(),
|
|
297
|
+
error: (err) => connectionSubject.error(err)
|
|
298
|
+
});
|
|
299
|
+
} else {
|
|
300
|
+
connectionSubject.complete();
|
|
301
|
+
}
|
|
302
|
+
return connectionSubject.asObservable();
|
|
303
|
+
}
|
|
304
|
+
isRunning(request) {
|
|
305
|
+
const runState = this.getRunState(request.threadId);
|
|
306
|
+
return Promise.resolve(runState.isRunning);
|
|
307
|
+
}
|
|
308
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
309
|
+
stop(_request) {
|
|
310
|
+
throw new Error("Method not implemented.");
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Close the database connection (for cleanup)
|
|
314
|
+
*/
|
|
315
|
+
close() {
|
|
316
|
+
if (this.db) {
|
|
317
|
+
this.db.close();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
322
|
+
0 && (module.exports = {
|
|
323
|
+
SqliteAgentRunner
|
|
324
|
+
});
|
|
325
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sqlite-runner.ts"],"sourcesContent":["export * from \"./sqlite-runner\";\n","import {\n AgentRunner,\n type AgentRunnerConnectRequest,\n type AgentRunnerIsRunningRequest,\n type AgentRunnerRunRequest,\n type AgentRunnerStopRequest,\n} from \"@copilotkitnext/runtime\";\nimport { Observable, ReplaySubject } from \"rxjs\";\nimport {\n BaseEvent,\n RunAgentInput,\n EventType,\n RunStartedEvent,\n compactEvents,\n} from \"@ag-ui/client\";\nimport Database from \"better-sqlite3\";\n\nconst SCHEMA_VERSION = 1;\n\ninterface AgentRunRecord {\n id: number;\n thread_id: string;\n run_id: string;\n parent_run_id: string | null;\n events: BaseEvent[];\n input: RunAgentInput;\n created_at: number;\n version: number;\n}\n\nexport interface SqliteAgentRunnerOptions {\n dbPath?: string;\n}\n\n// Active connections for streaming events\n// This is the only in-memory state we need - just for active streaming\nconst ACTIVE_CONNECTIONS = new Map<string, ReplaySubject<BaseEvent>>();\n\nexport class SqliteAgentRunner extends AgentRunner {\n private db: any;\n\n constructor(options: SqliteAgentRunnerOptions = {}) {\n super();\n const dbPath = options.dbPath ?? \":memory:\";\n \n if (!Database) {\n throw new Error(\n 'better-sqlite3 is required for SqliteAgentRunner but was not found.\\n' +\n 'Please install it in your project:\\n' +\n ' npm install better-sqlite3\\n' +\n ' or\\n' +\n ' pnpm add better-sqlite3\\n' +\n ' or\\n' +\n ' yarn add better-sqlite3\\n\\n' +\n 'If you don\\'t need persistence, use InMemoryAgentRunner instead.'\n );\n }\n \n this.db = new Database(dbPath);\n this.initializeSchema();\n }\n\n private initializeSchema(): void {\n // Create the agent_runs table\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS agent_runs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n thread_id TEXT NOT NULL,\n run_id TEXT NOT NULL UNIQUE,\n parent_run_id TEXT,\n events TEXT NOT NULL,\n input TEXT NOT NULL,\n created_at INTEGER NOT NULL,\n version INTEGER NOT NULL\n )\n `);\n\n // Create run_state table to track active runs\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS run_state (\n thread_id TEXT PRIMARY KEY,\n is_running INTEGER DEFAULT 0,\n current_run_id TEXT,\n updated_at INTEGER NOT NULL\n )\n `);\n\n // Create indexes for efficient queries\n this.db.exec(`\n CREATE INDEX IF NOT EXISTS idx_thread_id ON agent_runs(thread_id);\n CREATE INDEX IF NOT EXISTS idx_parent_run_id ON agent_runs(parent_run_id);\n `);\n\n // Create schema version table\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS schema_version (\n version INTEGER PRIMARY KEY,\n applied_at INTEGER NOT NULL\n )\n `);\n\n // Check and set schema version\n const currentVersion = this.db\n .prepare(\"SELECT version FROM schema_version ORDER BY version DESC LIMIT 1\")\n .get() as { version: number } | undefined;\n\n if (!currentVersion || currentVersion.version < SCHEMA_VERSION) {\n this.db\n .prepare(\"INSERT OR REPLACE INTO schema_version (version, applied_at) VALUES (?, ?)\")\n .run(SCHEMA_VERSION, Date.now());\n }\n }\n\n private storeRun(\n threadId: string,\n runId: string,\n events: BaseEvent[],\n input: RunAgentInput,\n parentRunId?: string | null\n ): void {\n // Compact ONLY the events from this run\n const compactedEvents = compactEvents(events);\n \n const stmt = this.db.prepare(`\n INSERT INTO agent_runs (thread_id, run_id, parent_run_id, events, input, created_at, version)\n VALUES (?, ?, ?, ?, ?, ?, ?)\n `);\n\n stmt.run(\n threadId,\n runId,\n parentRunId ?? null,\n JSON.stringify(compactedEvents), // Store only this run's compacted events\n JSON.stringify(input),\n Date.now(),\n SCHEMA_VERSION\n );\n }\n\n private getHistoricRuns(threadId: string): AgentRunRecord[] {\n const stmt = this.db.prepare(`\n WITH RECURSIVE run_chain AS (\n -- Base case: find the root runs (those without parent)\n SELECT * FROM agent_runs \n WHERE thread_id = ? AND parent_run_id IS NULL\n \n UNION ALL\n \n -- Recursive case: find children of current level\n SELECT ar.* FROM agent_runs ar\n INNER JOIN run_chain rc ON ar.parent_run_id = rc.run_id\n WHERE ar.thread_id = ?\n )\n SELECT * FROM run_chain\n ORDER BY created_at ASC\n `);\n\n const rows = stmt.all(threadId, threadId) as any[];\n \n return rows.map(row => ({\n id: row.id,\n thread_id: row.thread_id,\n run_id: row.run_id,\n parent_run_id: row.parent_run_id,\n events: JSON.parse(row.events),\n input: JSON.parse(row.input),\n created_at: row.created_at,\n version: row.version\n }));\n }\n\n private getLatestRunId(threadId: string): string | null {\n const stmt = this.db.prepare(`\n SELECT run_id FROM agent_runs \n WHERE thread_id = ? \n ORDER BY created_at DESC \n LIMIT 1\n `);\n\n const result = stmt.get(threadId) as { run_id: string } | undefined;\n return result?.run_id ?? null;\n }\n\n private setRunState(threadId: string, isRunning: boolean, runId?: string): void {\n const stmt = this.db.prepare(`\n INSERT OR REPLACE INTO run_state (thread_id, is_running, current_run_id, updated_at)\n VALUES (?, ?, ?, ?)\n `);\n stmt.run(threadId, isRunning ? 1 : 0, runId ?? null, Date.now());\n }\n\n private getRunState(threadId: string): { isRunning: boolean; currentRunId: string | null } {\n const stmt = this.db.prepare(`\n SELECT is_running, current_run_id FROM run_state WHERE thread_id = ?\n `);\n const result = stmt.get(threadId) as { is_running: number; current_run_id: string | null } | undefined;\n \n return {\n isRunning: result?.is_running === 1,\n currentRunId: result?.current_run_id ?? null\n };\n }\n\n run(request: AgentRunnerRunRequest): Observable<BaseEvent> {\n // Check if thread is already running in database\n const runState = this.getRunState(request.threadId);\n if (runState.isRunning) {\n throw new Error(\"Thread already running\");\n }\n\n // Mark thread as running in database\n this.setRunState(request.threadId, true, request.input.runId);\n\n // Track seen message IDs and current run events in memory for this run\n const seenMessageIds = new Set<string>();\n const currentRunEvents: BaseEvent[] = [];\n \n // Get all previously seen message IDs from historic runs\n const historicRuns = this.getHistoricRuns(request.threadId);\n const historicMessageIds = new Set<string>();\n for (const run of historicRuns) {\n for (const event of run.events) {\n if ('messageId' in event && typeof event.messageId === 'string') {\n historicMessageIds.add(event.messageId);\n }\n if (event.type === EventType.RUN_STARTED) {\n const runStarted = event as RunStartedEvent;\n const messages = runStarted.input?.messages ?? [];\n for (const message of messages) {\n historicMessageIds.add(message.id);\n }\n }\n }\n }\n\n // Get or create subject for this thread's connections\n const nextSubject = new ReplaySubject<BaseEvent>(Infinity);\n const prevSubject = ACTIVE_CONNECTIONS.get(request.threadId);\n \n // Update the active connection for this thread\n ACTIVE_CONNECTIONS.set(request.threadId, nextSubject);\n\n // Create a subject for run() return value\n const runSubject = new ReplaySubject<BaseEvent>(Infinity);\n\n // Helper function to run the agent and handle errors\n const runAgent = async () => {\n // Get parent run ID for chaining\n const parentRunId = this.getLatestRunId(request.threadId);\n \n try {\n await request.agent.runAgent(request.input, {\n onEvent: ({ event }) => {\n let processedEvent: BaseEvent = event;\n if (event.type === EventType.RUN_STARTED) {\n const runStartedEvent = event as RunStartedEvent;\n if (!runStartedEvent.input) {\n const sanitizedMessages = request.input.messages\n ? request.input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n )\n : undefined;\n const updatedInput = {\n ...request.input,\n ...(sanitizedMessages !== undefined\n ? { messages: sanitizedMessages }\n : {}),\n };\n processedEvent = {\n ...runStartedEvent,\n input: updatedInput,\n } as RunStartedEvent;\n }\n }\n\n runSubject.next(processedEvent); // For run() return - only agent events\n nextSubject.next(processedEvent); // For connect() / store - all events\n currentRunEvents.push(processedEvent); // Accumulate for database storage\n },\n onNewMessage: ({ message }) => {\n // Called for each new message\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n },\n onRunStartedEvent: () => {\n // Mark input messages as seen without emitting duplicates\n if (request.input.messages) {\n for (const message of request.input.messages) {\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n }\n }\n },\n });\n \n // Store the run in database\n this.storeRun(\n request.threadId,\n request.input.runId,\n currentRunEvents,\n request.input,\n parentRunId\n );\n \n // Mark run as complete in database\n this.setRunState(request.threadId, false);\n \n // Complete the subjects\n runSubject.complete();\n nextSubject.complete();\n } catch {\n // Store the run even if it failed (partial events)\n if (currentRunEvents.length > 0) {\n this.storeRun(\n request.threadId,\n request.input.runId,\n currentRunEvents,\n request.input,\n parentRunId\n );\n }\n \n // Mark run as complete in database\n this.setRunState(request.threadId, false);\n \n // Don't emit error to the subject, just complete it\n // This allows subscribers to get events emitted before the error\n runSubject.complete();\n nextSubject.complete();\n }\n };\n\n // Bridge previous events if they exist\n if (prevSubject) {\n prevSubject.subscribe({\n next: (e) => nextSubject.next(e),\n error: (err) => nextSubject.error(err),\n complete: () => {\n // Don't complete nextSubject here - it needs to stay open for new events\n },\n });\n }\n\n // Start the agent execution immediately (not lazily)\n runAgent();\n\n // Return the run subject (only agent events, no injected messages)\n return runSubject.asObservable();\n }\n\n connect(request: AgentRunnerConnectRequest): Observable<BaseEvent> {\n const connectionSubject = new ReplaySubject<BaseEvent>(Infinity);\n\n // Load historic runs from database\n const historicRuns = this.getHistoricRuns(request.threadId);\n \n // Collect all historic events from database\n const allHistoricEvents: BaseEvent[] = [];\n for (const run of historicRuns) {\n allHistoricEvents.push(...run.events);\n }\n \n // Compact all events together before emitting\n const compactedEvents = compactEvents(allHistoricEvents);\n \n // Emit compacted events and track message IDs\n const emittedMessageIds = new Set<string>();\n for (const event of compactedEvents) {\n connectionSubject.next(event);\n if ('messageId' in event && typeof event.messageId === 'string') {\n emittedMessageIds.add(event.messageId);\n }\n }\n \n // Bridge active run to connection if exists\n const activeSubject = ACTIVE_CONNECTIONS.get(request.threadId);\n const runState = this.getRunState(request.threadId);\n \n if (activeSubject && runState.isRunning) {\n activeSubject.subscribe({\n next: (event) => {\n // Skip message events that we've already emitted from historic\n if ('messageId' in event && typeof event.messageId === 'string' && emittedMessageIds.has(event.messageId)) {\n return;\n }\n connectionSubject.next(event);\n },\n complete: () => connectionSubject.complete(),\n error: (err) => connectionSubject.error(err)\n });\n } else {\n // No active run, complete after historic events\n connectionSubject.complete();\n }\n \n return connectionSubject.asObservable();\n }\n\n isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean> {\n const runState = this.getRunState(request.threadId);\n return Promise.resolve(runState.isRunning);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n stop(_request: AgentRunnerStopRequest): Promise<boolean | undefined> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Close the database connection (for cleanup)\n */\n close(): void {\n if (this.db) {\n this.db.close();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;A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