@copilotkitnext/runtime 0.0.1 → 0.0.3
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 -22
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-test.log +34 -33
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/runner/in-memory.ts +26 -20
- package/README-RUNNERS.md +0 -78
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkitnext/runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Server-side runtime package for CopilotKit2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"ioredis": "^5.7.0",
|
|
36
36
|
"kysely": "^0.28.5",
|
|
37
37
|
"rxjs": "7.8.1",
|
|
38
|
-
"@copilotkitnext/shared": "0.0.
|
|
38
|
+
"@copilotkitnext/shared": "0.0.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"better-sqlite3": "^12.2.0",
|
package/src/runner/in-memory.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type AgentRunnerStopRequest,
|
|
7
7
|
} from "./agent-runner";
|
|
8
8
|
import { Observable, ReplaySubject } from "rxjs";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
10
|
BaseEvent,
|
|
11
11
|
Message,
|
|
12
12
|
EventType,
|
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
ToolCallStartEvent,
|
|
17
17
|
ToolCallArgsEvent,
|
|
18
18
|
ToolCallEndEvent,
|
|
19
|
-
ToolCallResultEvent
|
|
19
|
+
ToolCallResultEvent,
|
|
20
|
+
MessagesSnapshotEvent,
|
|
20
21
|
} from "@ag-ui/client";
|
|
21
22
|
import { compactEvents } from "./event-compaction";
|
|
22
23
|
|
|
@@ -42,7 +43,7 @@ class InMemoryEventStore {
|
|
|
42
43
|
|
|
43
44
|
/** Current run ID */
|
|
44
45
|
currentRunId: string | null = null;
|
|
45
|
-
|
|
46
|
+
|
|
46
47
|
/** Historic completed runs */
|
|
47
48
|
historicRuns: HistoricRun[] = [];
|
|
48
49
|
}
|
|
@@ -137,12 +138,12 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
137
138
|
// Track seen message IDs and current run events for this run
|
|
138
139
|
const seenMessageIds = new Set<string>();
|
|
139
140
|
const currentRunEvents: BaseEvent[] = [];
|
|
140
|
-
|
|
141
|
+
|
|
141
142
|
// Get all previously seen message IDs from historic runs
|
|
142
143
|
const historicMessageIds = new Set<string>();
|
|
143
144
|
for (const run of store.historicRuns) {
|
|
144
145
|
for (const event of run.events) {
|
|
145
|
-
if (
|
|
146
|
+
if ("messageId" in event && typeof event.messageId === "string") {
|
|
146
147
|
historicMessageIds.add(event.messageId);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
@@ -163,7 +164,7 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
163
164
|
// Get parent run ID for chaining
|
|
164
165
|
const lastRun = store.historicRuns[store.historicRuns.length - 1];
|
|
165
166
|
const parentRunId = lastRun?.runId ?? null;
|
|
166
|
-
|
|
167
|
+
|
|
167
168
|
try {
|
|
168
169
|
await request.agent.runAgent(request.input, {
|
|
169
170
|
onEvent: ({ event }) => {
|
|
@@ -184,14 +185,14 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
184
185
|
if (!seenMessageIds.has(message.id)) {
|
|
185
186
|
seenMessageIds.add(message.id);
|
|
186
187
|
const events = this.convertMessageToEvents(message);
|
|
187
|
-
|
|
188
|
+
|
|
188
189
|
// Check if this message is NEW (not in historic runs)
|
|
189
190
|
const isNewMessage = !historicMessageIds.has(message.id);
|
|
190
|
-
|
|
191
|
+
|
|
191
192
|
for (const event of events) {
|
|
192
193
|
// Always emit to stream for context
|
|
193
194
|
nextSubject.next(event);
|
|
194
|
-
|
|
195
|
+
|
|
195
196
|
// Store if this is a NEW message for this run
|
|
196
197
|
if (isNewMessage) {
|
|
197
198
|
currentRunEvents.push(event);
|
|
@@ -202,11 +203,12 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
202
203
|
}
|
|
203
204
|
},
|
|
204
205
|
});
|
|
205
|
-
|
|
206
|
+
|
|
206
207
|
// Store the completed run in memory with ONLY its events
|
|
207
208
|
if (store.currentRunId) {
|
|
208
209
|
// Compact the events before storing (like SQLite does)
|
|
209
210
|
const compactedEvents = compactEvents(currentRunEvents);
|
|
211
|
+
|
|
210
212
|
store.historicRuns.push({
|
|
211
213
|
threadId: request.threadId,
|
|
212
214
|
runId: store.currentRunId,
|
|
@@ -215,7 +217,7 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
215
217
|
createdAt: Date.now(),
|
|
216
218
|
});
|
|
217
219
|
}
|
|
218
|
-
|
|
220
|
+
|
|
219
221
|
// Complete the run
|
|
220
222
|
store.isRunning = false;
|
|
221
223
|
store.currentRunId = null;
|
|
@@ -234,7 +236,7 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
234
236
|
createdAt: Date.now(),
|
|
235
237
|
});
|
|
236
238
|
}
|
|
237
|
-
|
|
239
|
+
|
|
238
240
|
// Complete the run
|
|
239
241
|
store.isRunning = false;
|
|
240
242
|
store.currentRunId = null;
|
|
@@ -276,37 +278,41 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
276
278
|
for (const run of store.historicRuns) {
|
|
277
279
|
allHistoricEvents.push(...run.events);
|
|
278
280
|
}
|
|
279
|
-
|
|
281
|
+
|
|
280
282
|
// Apply compaction to all historic events together (like SQLite)
|
|
281
283
|
const compactedEvents = compactEvents(allHistoricEvents);
|
|
282
|
-
|
|
284
|
+
|
|
283
285
|
// Emit compacted events and track message IDs
|
|
284
286
|
const emittedMessageIds = new Set<string>();
|
|
285
287
|
for (const event of compactedEvents) {
|
|
286
288
|
connectionSubject.next(event);
|
|
287
|
-
if (
|
|
289
|
+
if ("messageId" in event && typeof event.messageId === "string") {
|
|
288
290
|
emittedMessageIds.add(event.messageId);
|
|
289
291
|
}
|
|
290
292
|
}
|
|
291
|
-
|
|
293
|
+
|
|
292
294
|
// Bridge active run to connection if exists
|
|
293
295
|
if (store.subject && store.isRunning) {
|
|
294
296
|
store.subject.subscribe({
|
|
295
297
|
next: (event) => {
|
|
296
298
|
// Skip message events that we've already emitted from historic
|
|
297
|
-
if (
|
|
299
|
+
if (
|
|
300
|
+
"messageId" in event &&
|
|
301
|
+
typeof event.messageId === "string" &&
|
|
302
|
+
emittedMessageIds.has(event.messageId)
|
|
303
|
+
) {
|
|
298
304
|
return;
|
|
299
305
|
}
|
|
300
306
|
connectionSubject.next(event);
|
|
301
307
|
},
|
|
302
308
|
complete: () => connectionSubject.complete(),
|
|
303
|
-
error: (err) => connectionSubject.error(err)
|
|
309
|
+
error: (err) => connectionSubject.error(err),
|
|
304
310
|
});
|
|
305
311
|
} else {
|
|
306
312
|
// No active run, complete after historic events
|
|
307
313
|
connectionSubject.complete();
|
|
308
314
|
}
|
|
309
|
-
|
|
315
|
+
|
|
310
316
|
return connectionSubject.asObservable();
|
|
311
317
|
}
|
|
312
318
|
|
|
@@ -319,4 +325,4 @@ export class InMemoryAgentRunner extends AgentRunner {
|
|
|
319
325
|
stop(_request: AgentRunnerStopRequest): Promise<boolean | undefined> {
|
|
320
326
|
throw new Error("Method not implemented.");
|
|
321
327
|
}
|
|
322
|
-
}
|
|
328
|
+
}
|
package/README-RUNNERS.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Agent Runners
|
|
2
|
-
|
|
3
|
-
CopilotKit Runtime provides two agent runners for different use cases:
|
|
4
|
-
|
|
5
|
-
## InMemoryAgentRunner (Default)
|
|
6
|
-
|
|
7
|
-
The default runner that stores all data in memory. Perfect for development and applications that don't need persistence.
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import { CopilotRuntime, InMemoryAgentRunner } from "@copilotkitnext/runtime";
|
|
11
|
-
|
|
12
|
-
// Default - uses InMemoryAgentRunner automatically
|
|
13
|
-
const runtime = new CopilotRuntime({
|
|
14
|
-
agents: myAgents,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Or explicitly
|
|
18
|
-
const runtime = new CopilotRuntime({
|
|
19
|
-
agents: myAgents,
|
|
20
|
-
runner: new InMemoryAgentRunner(),
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
**Features:**
|
|
25
|
-
|
|
26
|
-
- No external dependencies
|
|
27
|
-
- Fast performance
|
|
28
|
-
- Data is lost when process restarts
|
|
29
|
-
- Perfect for development and stateless applications
|
|
30
|
-
|
|
31
|
-
## SqliteAgentRunner
|
|
32
|
-
|
|
33
|
-
Provides persistent storage using SQLite. Ideal for applications that need to preserve conversation history across restarts.
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
import { CopilotRuntime, SqliteAgentRunner } from "@copilotkitnext/runtime";
|
|
37
|
-
|
|
38
|
-
const runtime = new CopilotRuntime({
|
|
39
|
-
agents: myAgents,
|
|
40
|
-
runner: new SqliteAgentRunner("./data/copilot.db"),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Or use in-memory SQLite (data persists during runtime only)
|
|
44
|
-
const runtime = new CopilotRuntime({
|
|
45
|
-
agents: myAgents,
|
|
46
|
-
runner: new SqliteAgentRunner(":memory:"),
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
**Features:**
|
|
51
|
-
|
|
52
|
-
- Persistent storage across restarts
|
|
53
|
-
- Maintains conversation history
|
|
54
|
-
- Parent-child run relationships
|
|
55
|
-
- Event compaction for historic runs
|
|
56
|
-
|
|
57
|
-
**Requirements:**
|
|
58
|
-
|
|
59
|
-
- Requires `better-sqlite3` to be installed:
|
|
60
|
-
```bash
|
|
61
|
-
npm install better-sqlite3
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Choosing the Right Runner
|
|
65
|
-
|
|
66
|
-
- **Use InMemoryAgentRunner when:**
|
|
67
|
-
- Building prototypes or demos
|
|
68
|
-
- Running in serverless environments
|
|
69
|
-
- You don't need conversation history
|
|
70
|
-
- You want zero external dependencies
|
|
71
|
-
|
|
72
|
-
- **Use SqliteAgentRunner when:**
|
|
73
|
-
- You need persistent conversation history
|
|
74
|
-
- Building production applications
|
|
75
|
-
- You want to analyze historic conversations
|
|
76
|
-
- Running on a traditional server
|
|
77
|
-
|
|
78
|
-
Both runners implement the same `AgentRunner` interface, so you can switch between them without changing your application code.
|