@copilotkit/agentcore-runner 1.82.0 → 2.0.0-rc.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/dist/agentcore-runner.cjs +2 -2
- package/dist/agentcore-runner.cjs.map +1 -1
- package/dist/agentcore-runner.d.cts +1 -1
- package/dist/agentcore-runner.d.cts.map +1 -1
- package/dist/agentcore-runner.d.mts +1 -1
- package/dist/agentcore-runner.d.mts.map +1 -1
- package/dist/agentcore-runner.mjs +1 -1
- package/dist/agentcore-runner.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/agentcore-runner.e2e.test.ts +10 -11
- package/src/__tests__/agentcore-runner.test.ts +3 -2
- package/src/agentcore-runner.ts +10 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let node_crypto = require("node:crypto");
|
|
2
2
|
let _ag_ui_client = require("@ag-ui/client");
|
|
3
|
-
let
|
|
3
|
+
let _copilotkit_runtime = require("@copilotkit/runtime");
|
|
4
4
|
let rxjs = require("rxjs");
|
|
5
5
|
|
|
6
6
|
//#region src/agentcore-runner.ts
|
|
@@ -17,7 +17,7 @@ let rxjs = require("rxjs");
|
|
|
17
17
|
* CopilotKit needs those to reconcile its message state, so we synthesise
|
|
18
18
|
* empty results for each past tool call before the snapshot.
|
|
19
19
|
*/
|
|
20
|
-
var AgentCoreRunner = class extends
|
|
20
|
+
var AgentCoreRunner = class extends _copilotkit_runtime.InMemoryAgentRunner {
|
|
21
21
|
knownThreadIds = /* @__PURE__ */ new Set();
|
|
22
22
|
run(request) {
|
|
23
23
|
if (request.threadId) this.knownThreadIds.add(request.threadId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentcore-runner.cjs","names":["InMemoryAgentRunner","EventType"],"sources":["../src/agentcore-runner.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport {\n
|
|
1
|
+
{"version":3,"file":"agentcore-runner.cjs","names":["InMemoryAgentRunner","EventType"],"sources":["../src/agentcore-runner.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { EventType } from \"@ag-ui/client\";\nimport type {\n BaseEvent,\n Message,\n MessagesSnapshotEvent,\n ToolCall,\n ToolCallResultEvent,\n} from \"@ag-ui/client\";\nimport { InMemoryAgentRunner } from \"@copilotkit/runtime\";\nimport type { Observable } from \"rxjs\";\nimport { concatMap, of } from \"rxjs\";\n\n/**\n * AgentCore stores conversation history server-side via AgentCoreMemorySaver /\n * AgentCoreMemorySessionManager. When CopilotKit reconnects to an existing\n * thread (e.g. page refresh), two issues arise that this runner fixes:\n *\n * 1. Unknown threads — CopilotKit may call `connect()` for a thread that has\n * never had a `run()` (first load). The base runner would error; we emit an\n * empty snapshot instead so the UI initialises cleanly.\n * 2. Missing tool-call results — AgentCore's replayed history contains assistant\n * messages with tool calls but no corresponding TOOL_CALL_RESULT events.\n * CopilotKit needs those to reconcile its message state, so we synthesise\n * empty results for each past tool call before the snapshot.\n */\nexport class AgentCoreRunner extends InMemoryAgentRunner {\n private readonly knownThreadIds = new Set<string>();\n\n override run(request: Parameters<InMemoryAgentRunner[\"run\"]>[0]) {\n if (request.threadId) this.knownThreadIds.add(request.threadId);\n return super.run(request);\n }\n\n override connect(request: Parameters<InMemoryAgentRunner[\"connect\"]>[0]) {\n if (!request.threadId || !this.knownThreadIds.has(request.threadId)) {\n const threadId = request.threadId ?? randomUUID();\n const runId = randomUUID();\n return of(\n { type: EventType.RUN_STARTED, threadId, runId },\n { type: EventType.MESSAGES_SNAPSHOT, messages: [] },\n { type: EventType.RUN_FINISHED, threadId, runId },\n ) as Observable<BaseEvent>;\n }\n\n return super.connect(request).pipe(\n concatMap((event: BaseEvent) => {\n if (event.type !== EventType.MESSAGES_SNAPSHOT) return of(event);\n const snapshot = event as MessagesSnapshotEvent;\n const replayedResults: ToolCallResultEvent[] =\n snapshot.messages.flatMap((message: Message) => {\n if (message.role !== \"assistant\" || !message.toolCalls?.length)\n return [];\n return message.toolCalls.map<ToolCallResultEvent>(\n (toolCall: ToolCall) => ({\n type: EventType.TOOL_CALL_RESULT,\n toolCallId: toolCall.id,\n messageId: `${toolCall.id}-result`,\n content: \"\",\n role: \"tool\",\n }),\n );\n });\n return of(...replayedResults, snapshot) as Observable<BaseEvent>;\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,IAAa,kBAAb,cAAqCA,wCAAoB;CACvD,AAAiB,iCAAiB,IAAI,KAAa;CAEnD,AAAS,IAAI,SAAoD;AAC/D,MAAI,QAAQ,SAAU,MAAK,eAAe,IAAI,QAAQ,SAAS;AAC/D,SAAO,MAAM,IAAI,QAAQ;;CAG3B,AAAS,QAAQ,SAAwD;AACvE,MAAI,CAAC,QAAQ,YAAY,CAAC,KAAK,eAAe,IAAI,QAAQ,SAAS,EAAE;GACnE,MAAM,WAAW,QAAQ,yCAAwB;GACjD,MAAM,qCAAoB;AAC1B,uBACE;IAAE,MAAMC,wBAAU;IAAa;IAAU;IAAO,EAChD;IAAE,MAAMA,wBAAU;IAAmB,UAAU,EAAE;IAAE,EACnD;IAAE,MAAMA,wBAAU;IAAc;IAAU;IAAO,CAClD;;AAGH,SAAO,MAAM,QAAQ,QAAQ,CAAC,0BACjB,UAAqB;AAC9B,OAAI,MAAM,SAASA,wBAAU,kBAAmB,qBAAU,MAAM;GAChE,MAAM,WAAW;AAejB,uBAAU,GAbR,SAAS,SAAS,SAAS,YAAqB;AAC9C,QAAI,QAAQ,SAAS,eAAe,CAAC,QAAQ,WAAW,OACtD,QAAO,EAAE;AACX,WAAO,QAAQ,UAAU,KACtB,cAAwB;KACvB,MAAMA,wBAAU;KAChB,YAAY,SAAS;KACrB,WAAW,GAAG,SAAS,GAAG;KAC1B,SAAS;KACT,MAAM;KACP,EACF;KACD,EAC0B,SAAS;IACvC,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentcore-runner.d.cts","names":[],"sources":["../src/agentcore-runner.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"agentcore-runner.d.cts","names":[],"sources":["../src/agentcore-runner.ts"],"mappings":";;;;;;;AA0BA;;;;;;;;;;;cAAa,eAAA,SAAwB,mBAAA;EAAA,iBAClB,cAAA;EAER,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,mBAAA,cAA8B,UAAA,CAAA,SAAA;EAKtD,OAAA,CAAQ,OAAA,EAAS,UAAA,CAAW,mBAAA,kBAAkC,UAAA,CAAA,SAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentcore-runner.d.mts","names":[],"sources":["../src/agentcore-runner.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"agentcore-runner.d.mts","names":[],"sources":["../src/agentcore-runner.ts"],"mappings":";;;;;;;AA0BA;;;;;;;;;;;cAAa,eAAA,SAAwB,mBAAA;EAAA,iBAClB,cAAA;EAER,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,mBAAA,cAA8B,UAAA,CAAA,SAAA;EAKtD,OAAA,CAAQ,OAAA,EAAS,UAAA,CAAW,mBAAA,kBAAkC,UAAA,CAAA,SAAA;AAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { EventType } from "@ag-ui/client";
|
|
3
|
-
import { InMemoryAgentRunner } from "@copilotkit/runtime
|
|
3
|
+
import { InMemoryAgentRunner } from "@copilotkit/runtime";
|
|
4
4
|
import { concatMap, of } from "rxjs";
|
|
5
5
|
|
|
6
6
|
//#region src/agentcore-runner.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentcore-runner.mjs","names":[],"sources":["../src/agentcore-runner.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport {\n
|
|
1
|
+
{"version":3,"file":"agentcore-runner.mjs","names":[],"sources":["../src/agentcore-runner.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { EventType } from \"@ag-ui/client\";\nimport type {\n BaseEvent,\n Message,\n MessagesSnapshotEvent,\n ToolCall,\n ToolCallResultEvent,\n} from \"@ag-ui/client\";\nimport { InMemoryAgentRunner } from \"@copilotkit/runtime\";\nimport type { Observable } from \"rxjs\";\nimport { concatMap, of } from \"rxjs\";\n\n/**\n * AgentCore stores conversation history server-side via AgentCoreMemorySaver /\n * AgentCoreMemorySessionManager. When CopilotKit reconnects to an existing\n * thread (e.g. page refresh), two issues arise that this runner fixes:\n *\n * 1. Unknown threads — CopilotKit may call `connect()` for a thread that has\n * never had a `run()` (first load). The base runner would error; we emit an\n * empty snapshot instead so the UI initialises cleanly.\n * 2. Missing tool-call results — AgentCore's replayed history contains assistant\n * messages with tool calls but no corresponding TOOL_CALL_RESULT events.\n * CopilotKit needs those to reconcile its message state, so we synthesise\n * empty results for each past tool call before the snapshot.\n */\nexport class AgentCoreRunner extends InMemoryAgentRunner {\n private readonly knownThreadIds = new Set<string>();\n\n override run(request: Parameters<InMemoryAgentRunner[\"run\"]>[0]) {\n if (request.threadId) this.knownThreadIds.add(request.threadId);\n return super.run(request);\n }\n\n override connect(request: Parameters<InMemoryAgentRunner[\"connect\"]>[0]) {\n if (!request.threadId || !this.knownThreadIds.has(request.threadId)) {\n const threadId = request.threadId ?? randomUUID();\n const runId = randomUUID();\n return of(\n { type: EventType.RUN_STARTED, threadId, runId },\n { type: EventType.MESSAGES_SNAPSHOT, messages: [] },\n { type: EventType.RUN_FINISHED, threadId, runId },\n ) as Observable<BaseEvent>;\n }\n\n return super.connect(request).pipe(\n concatMap((event: BaseEvent) => {\n if (event.type !== EventType.MESSAGES_SNAPSHOT) return of(event);\n const snapshot = event as MessagesSnapshotEvent;\n const replayedResults: ToolCallResultEvent[] =\n snapshot.messages.flatMap((message: Message) => {\n if (message.role !== \"assistant\" || !message.toolCalls?.length)\n return [];\n return message.toolCalls.map<ToolCallResultEvent>(\n (toolCall: ToolCall) => ({\n type: EventType.TOOL_CALL_RESULT,\n toolCallId: toolCall.id,\n messageId: `${toolCall.id}-result`,\n content: \"\",\n role: \"tool\",\n }),\n );\n });\n return of(...replayedResults, snapshot) as Observable<BaseEvent>;\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,IAAa,kBAAb,cAAqC,oBAAoB;CACvD,AAAiB,iCAAiB,IAAI,KAAa;CAEnD,AAAS,IAAI,SAAoD;AAC/D,MAAI,QAAQ,SAAU,MAAK,eAAe,IAAI,QAAQ,SAAS;AAC/D,SAAO,MAAM,IAAI,QAAQ;;CAG3B,AAAS,QAAQ,SAAwD;AACvE,MAAI,CAAC,QAAQ,YAAY,CAAC,KAAK,eAAe,IAAI,QAAQ,SAAS,EAAE;GACnE,MAAM,WAAW,QAAQ,YAAY,YAAY;GACjD,MAAM,QAAQ,YAAY;AAC1B,UAAO,GACL;IAAE,MAAM,UAAU;IAAa;IAAU;IAAO,EAChD;IAAE,MAAM,UAAU;IAAmB,UAAU,EAAE;IAAE,EACnD;IAAE,MAAM,UAAU;IAAc;IAAU;IAAO,CAClD;;AAGH,SAAO,MAAM,QAAQ,QAAQ,CAAC,KAC5B,WAAW,UAAqB;AAC9B,OAAI,MAAM,SAAS,UAAU,kBAAmB,QAAO,GAAG,MAAM;GAChE,MAAM,WAAW;AAejB,UAAO,GAAG,GAbR,SAAS,SAAS,SAAS,YAAqB;AAC9C,QAAI,QAAQ,SAAS,eAAe,CAAC,QAAQ,WAAW,OACtD,QAAO,EAAE;AACX,WAAO,QAAQ,UAAU,KACtB,cAAwB;KACvB,MAAM,UAAU;KAChB,YAAY,SAAS;KACrB,WAAW,GAAG,SAAS,GAAG;KAC1B,SAAS;KACT,MAAM;KACP,EACF;KACD,EAC0B,SAAS;IACvC,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/agentcore-runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
4
4
|
"description": "AWS Bedrock AgentCore-compatible agent runner for CopilotKit2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ag-ui/client": "1.0.2",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"@copilotkit/runtime": "2.0.0-rc.0",
|
|
27
|
+
"rxjs": "7.8.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.15.3",
|
|
@@ -13,21 +13,20 @@
|
|
|
13
13
|
import { describe, it, expect } from "vitest";
|
|
14
14
|
import { EMPTY, firstValueFrom } from "rxjs";
|
|
15
15
|
import { toArray } from "rxjs/operators";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type ToolCallResultEvent,
|
|
16
|
+
import { AbstractAgent, EventType } from "@ag-ui/client";
|
|
17
|
+
import type {
|
|
18
|
+
BaseEvent,
|
|
19
|
+
Message,
|
|
20
|
+
MessagesSnapshotEvent,
|
|
21
|
+
RunAgentInput,
|
|
22
|
+
RunFinishedEvent,
|
|
23
|
+
RunStartedEvent,
|
|
24
|
+
ToolCallResultEvent,
|
|
26
25
|
} from "@ag-ui/client";
|
|
27
26
|
import type {
|
|
28
27
|
AgentRunnerConnectRequest,
|
|
29
28
|
AgentRunnerRunRequest,
|
|
30
|
-
} from "@copilotkit/runtime
|
|
29
|
+
} from "@copilotkit/runtime";
|
|
31
30
|
import { AgentCoreRunner } from "..";
|
|
32
31
|
|
|
33
32
|
// ---------------------------------------------------------------------------
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { firstValueFrom } from "rxjs";
|
|
3
3
|
import { toArray } from "rxjs/operators";
|
|
4
|
-
import { EventType
|
|
5
|
-
import type {
|
|
4
|
+
import { EventType } from "@ag-ui/client";
|
|
5
|
+
import type { MessagesSnapshotEvent } from "@ag-ui/client";
|
|
6
|
+
import type { AgentRunnerConnectRequest } from "@copilotkit/runtime";
|
|
6
7
|
import { AgentCoreRunner } from "..";
|
|
7
8
|
|
|
8
9
|
describe("AgentCoreRunner.connect()", () => {
|
package/src/agentcore-runner.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { EventType } from "@ag-ui/client";
|
|
3
|
+
import type {
|
|
4
|
+
BaseEvent,
|
|
5
|
+
Message,
|
|
6
|
+
MessagesSnapshotEvent,
|
|
7
|
+
ToolCall,
|
|
8
|
+
ToolCallResultEvent,
|
|
9
9
|
} from "@ag-ui/client";
|
|
10
|
-
import { InMemoryAgentRunner } from "@copilotkit/runtime
|
|
11
|
-
import {
|
|
10
|
+
import { InMemoryAgentRunner } from "@copilotkit/runtime";
|
|
11
|
+
import type { Observable } from "rxjs";
|
|
12
|
+
import { concatMap, of } from "rxjs";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* AgentCore stores conversation history server-side via AgentCoreMemorySaver /
|