@copilotkit/runtime 0.0.0-fix-interrupt-issues-20250409144731 → 0.0.0-main-20250416144141
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/CHANGELOG.md +111 -3
- package/dist/{chunk-VUTLFZ6R.mjs → chunk-3KFMOJC6.mjs} +2 -2
- package/dist/{chunk-XPNNDFCN.mjs → chunk-D4R6RNSD.mjs} +2 -2
- package/dist/{chunk-FZJAYGIR.mjs → chunk-DNI7KA7Y.mjs} +2 -2
- package/dist/{chunk-7MWJJP4Z.mjs → chunk-H2VC34X7.mjs} +308 -16
- package/dist/chunk-H2VC34X7.mjs.map +1 -0
- package/dist/{chunk-MNZKCJK5.mjs → chunk-NKMMHPPX.mjs} +2 -2
- package/dist/chunk-Q6JA6YY3.mjs +1 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.js +4155 -3855
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +8 -7
- package/dist/lib/index.js +4014 -3714
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +10 -6
- package/dist/lib/integrations/index.d.ts +5 -4
- package/dist/lib/integrations/index.js +15 -10
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +4 -3
- package/dist/lib/integrations/nest/index.js +15 -10
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +4 -3
- package/dist/lib/integrations/node-express/index.js +15 -10
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +4 -3
- package/dist/lib/integrations/node-http/index.js +15 -10
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.mjs +1 -1
- package/dist/{copilot-runtime-9347bd66.d.ts → shared-93687488.d.ts} +133 -45
- package/package.json +6 -2
- package/src/lib/index.ts +2 -1
- package/src/lib/runtime/agentwire-action.ts +123 -0
- package/src/lib/runtime/copilot-runtime.ts +226 -11
- package/src/lib/runtime/mcp-tools-utils.ts +117 -0
- package/src/lib/runtime/remote-action-constructors.ts +2 -7
- package/src/lib/runtime/remote-actions.ts +25 -1
- package/src/lib/runtime/remote-lg-action.ts +24 -2
- package/dist/chunk-7MWJJP4Z.mjs.map +0 -1
- package/dist/chunk-PTC5JN3P.mjs +0 -1
- /package/dist/{chunk-VUTLFZ6R.mjs.map → chunk-3KFMOJC6.mjs.map} +0 -0
- /package/dist/{chunk-XPNNDFCN.mjs.map → chunk-D4R6RNSD.mjs.map} +0 -0
- /package/dist/{chunk-FZJAYGIR.mjs.map → chunk-DNI7KA7Y.mjs.map} +0 -0
- /package/dist/{chunk-MNZKCJK5.mjs.map → chunk-NKMMHPPX.mjs.map} +0 -0
- /package/dist/{chunk-PTC5JN3P.mjs.map → chunk-Q6JA6YY3.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,122 @@
|
|
|
1
1
|
# @copilotkit/runtime
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-main-20250416144141
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- 7a04bd1: - fix: fix how results are communicated back on interrupt
|
|
8
8
|
- fix: do not allow followup for interrupt actions
|
|
9
9
|
- chore: improve TS docs for interrupt
|
|
10
|
+
- @copilotkit/shared@0.0.0-main-20250416144141
|
|
11
|
+
|
|
12
|
+
## 1.8.6-next.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 7a04bd1: - fix: fix how results are communicated back on interrupt
|
|
17
|
+
- fix: do not allow followup for interrupt actions
|
|
18
|
+
- chore: improve TS docs for interrupt
|
|
19
|
+
- @copilotkit/shared@1.8.6-next.0
|
|
20
|
+
|
|
21
|
+
## 1.8.5
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- c0d3261: - full AWP support
|
|
26
|
+
|
|
27
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
28
|
+
|
|
29
|
+
- refactor: address linter issues with the new pages
|
|
30
|
+
|
|
31
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
32
|
+
|
|
33
|
+
- Merge branch 'mme/acp' into mme/mastra
|
|
34
|
+
- add sse example
|
|
35
|
+
- Create small-turkeys-agree.md
|
|
36
|
+
- upgrade AWP
|
|
37
|
+
- Merge branch 'mme/mastra' of github.com:CopilotKit/CopilotKit into mme/mastra
|
|
38
|
+
- make agents a dict
|
|
39
|
+
- update docs
|
|
40
|
+
- send tools
|
|
41
|
+
- update to latest packages
|
|
42
|
+
- fix problem where state sync are preventing tool calls
|
|
43
|
+
- set possibly undefined toolCalls to an empty array
|
|
44
|
+
- fix missing tool call ids
|
|
45
|
+
|
|
46
|
+
- 77a7457: - feat: Add Model Context Protocol (MCP) support
|
|
47
|
+
- 76d9ef9: - fix: handle langgraph client specific errors when running lgc stream
|
|
48
|
+
- c0d3261: - add AWP support
|
|
49
|
+
|
|
50
|
+
- make it work
|
|
51
|
+
- update docs
|
|
52
|
+
- refactor: move UI files to be normal NextJS pages and update generation
|
|
53
|
+
|
|
54
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
55
|
+
|
|
56
|
+
- refactor: address linter issues with the new pages
|
|
57
|
+
|
|
58
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
59
|
+
|
|
60
|
+
- Merge branch 'mme/acp' into mme/mastra
|
|
61
|
+
- add sse example
|
|
62
|
+
|
|
10
63
|
- d0e8a1e: - fix: fix duplicate messages on regenerate
|
|
11
|
-
- @copilotkit/shared@
|
|
64
|
+
- @copilotkit/shared@1.8.5
|
|
65
|
+
|
|
66
|
+
## 1.8.5-next.5
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- c0d3261: - full AWP support
|
|
71
|
+
|
|
72
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
73
|
+
|
|
74
|
+
- refactor: address linter issues with the new pages
|
|
75
|
+
|
|
76
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
77
|
+
|
|
78
|
+
- Merge branch 'mme/acp' into mme/mastra
|
|
79
|
+
- add sse example
|
|
80
|
+
- Create small-turkeys-agree.md
|
|
81
|
+
- upgrade AWP
|
|
82
|
+
- Merge branch 'mme/mastra' of github.com:CopilotKit/CopilotKit into mme/mastra
|
|
83
|
+
- make agents a dict
|
|
84
|
+
- update docs
|
|
85
|
+
- send tools
|
|
86
|
+
- update to latest packages
|
|
87
|
+
- fix problem where state sync are preventing tool calls
|
|
88
|
+
- set possibly undefined toolCalls to an empty array
|
|
89
|
+
- fix missing tool call ids
|
|
90
|
+
|
|
91
|
+
- c0d3261: - add AWP support
|
|
92
|
+
|
|
93
|
+
- make it work
|
|
94
|
+
- update docs
|
|
95
|
+
- refactor: move UI files to be normal NextJS pages and update generation
|
|
96
|
+
|
|
97
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
98
|
+
|
|
99
|
+
- refactor: address linter issues with the new pages
|
|
100
|
+
|
|
101
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
102
|
+
|
|
103
|
+
- Merge branch 'mme/acp' into mme/mastra
|
|
104
|
+
- add sse example
|
|
105
|
+
- @copilotkit/shared@1.8.5-next.5
|
|
106
|
+
|
|
107
|
+
## 1.8.5-next.4
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- 76d9ef9: - fix: handle langgraph client specific errors when running lgc stream
|
|
112
|
+
- @copilotkit/shared@1.8.5-next.4
|
|
113
|
+
|
|
114
|
+
## 1.8.5-next.3
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- 77a7457: - feat: Add Model Context Protocol (MCP) support
|
|
119
|
+
- @copilotkit/shared@1.8.5-next.3
|
|
12
120
|
|
|
13
121
|
## 1.8.5-next.2
|
|
14
122
|
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-H2VC34X7.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNodeExpressEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-3KFMOJC6.mjs.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getCommonConfig,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-H2VC34X7.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -77,4 +77,4 @@ export {
|
|
|
77
77
|
config,
|
|
78
78
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
79
79
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-D4R6RNSD.mjs.map
|
|
@@ -1439,7 +1439,6 @@ __name(EmptyAdapter, "EmptyAdapter");
|
|
|
1439
1439
|
var ExperimentalEmptyAdapter = EmptyAdapter;
|
|
1440
1440
|
|
|
1441
1441
|
export {
|
|
1442
|
-
RemoteChain,
|
|
1443
1442
|
OpenAIAdapter,
|
|
1444
1443
|
streamLangChainResponse,
|
|
1445
1444
|
LangChainAdapter,
|
|
@@ -1447,9 +1446,10 @@ export {
|
|
|
1447
1446
|
OpenAIAssistantAdapter,
|
|
1448
1447
|
UnifyAdapter,
|
|
1449
1448
|
GroqAdapter,
|
|
1449
|
+
RemoteChain,
|
|
1450
1450
|
AnthropicAdapter,
|
|
1451
1451
|
ExperimentalOllamaAdapter,
|
|
1452
1452
|
EmptyAdapter,
|
|
1453
1453
|
ExperimentalEmptyAdapter
|
|
1454
1454
|
};
|
|
1455
|
-
//# sourceMappingURL=chunk-
|
|
1455
|
+
//# sourceMappingURL=chunk-DNI7KA7Y.mjs.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
EmptyAdapter,
|
|
3
3
|
RemoteChain,
|
|
4
4
|
streamLangChainResponse
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-DNI7KA7Y.mjs";
|
|
6
6
|
import {
|
|
7
7
|
GuardrailsValidationFailureResponse,
|
|
8
8
|
MessageStreamInterruptedResponse,
|
|
@@ -39,7 +39,7 @@ var require_package = __commonJS({
|
|
|
39
39
|
publishConfig: {
|
|
40
40
|
access: "public"
|
|
41
41
|
},
|
|
42
|
-
version: "1.8.
|
|
42
|
+
version: "1.8.6-next.0",
|
|
43
43
|
sideEffects: false,
|
|
44
44
|
main: "./dist/index.js",
|
|
45
45
|
module: "./dist/index.mjs",
|
|
@@ -76,6 +76,10 @@ var require_package = __commonJS({
|
|
|
76
76
|
"zod-to-json-schema": "^3.23.5"
|
|
77
77
|
},
|
|
78
78
|
dependencies: {
|
|
79
|
+
"@agentwire/client": "0.0.26",
|
|
80
|
+
"@agentwire/proto": "0.0.26",
|
|
81
|
+
"@agentwire/core": "0.0.26",
|
|
82
|
+
"@agentwire/encoder": "0.0.26",
|
|
79
83
|
"@anthropic-ai/sdk": "^0.27.3",
|
|
80
84
|
"@copilotkit/shared": "workspace:*",
|
|
81
85
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
@@ -1410,6 +1414,9 @@ import { of, concat, scan as scan2, concatMap, ReplaySubject as ReplaySubject2,
|
|
|
1410
1414
|
// src/lib/telemetry-client.ts
|
|
1411
1415
|
import { TelemetryClient } from "@copilotkit/shared";
|
|
1412
1416
|
|
|
1417
|
+
// src/lib/runtime/remote-actions.ts
|
|
1418
|
+
import { CopilotKitErrorCode } from "@copilotkit/shared";
|
|
1419
|
+
|
|
1413
1420
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1414
1421
|
import { createHash as createHash2 } from "crypto";
|
|
1415
1422
|
|
|
@@ -1687,7 +1694,7 @@ import { Client as LangGraphClient } from "@langchain/langgraph-sdk";
|
|
|
1687
1694
|
import { createHash } from "crypto";
|
|
1688
1695
|
import { isValidUUID, randomUUID } from "@copilotkit/shared";
|
|
1689
1696
|
import { parse as parsePartialJson } from "partial-json";
|
|
1690
|
-
import { parseJson } from "@copilotkit/shared";
|
|
1697
|
+
import { parseJson, CopilotKitMisuseError } from "@copilotkit/shared";
|
|
1691
1698
|
import { RemoveMessage } from "@langchain/core/messages";
|
|
1692
1699
|
var activeInterruptEvent = false;
|
|
1693
1700
|
async function execute(args) {
|
|
@@ -1697,6 +1704,23 @@ async function execute(args) {
|
|
|
1697
1704
|
await streamEvents(controller, args);
|
|
1698
1705
|
controller.close();
|
|
1699
1706
|
} catch (err) {
|
|
1707
|
+
const cause = err == null ? void 0 : err.cause;
|
|
1708
|
+
const errorCode = (cause == null ? void 0 : cause.code) || (err == null ? void 0 : err.code);
|
|
1709
|
+
if (errorCode === "ECONNREFUSED") {
|
|
1710
|
+
throw new CopilotKitMisuseError({
|
|
1711
|
+
message: `
|
|
1712
|
+
The LangGraph client could not connect to the graph. Please further check previous logs, which includes further details.
|
|
1713
|
+
|
|
1714
|
+
See more: https://docs.copilotkit.ai/troubleshooting/common-issues`
|
|
1715
|
+
});
|
|
1716
|
+
} else {
|
|
1717
|
+
throw new CopilotKitMisuseError({
|
|
1718
|
+
message: `
|
|
1719
|
+
The LangGraph client threw unhandled error ${err}.
|
|
1720
|
+
|
|
1721
|
+
See more: https://docs.copilotkit.ai/troubleshooting/common-issues`
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1700
1724
|
}
|
|
1701
1725
|
}
|
|
1702
1726
|
});
|
|
@@ -2562,6 +2586,100 @@ __name(createHeaders, "createHeaders");
|
|
|
2562
2586
|
|
|
2563
2587
|
// src/lib/runtime/remote-actions.ts
|
|
2564
2588
|
import { CopilotKitLowLevelError as CopilotKitLowLevelError2, ResolvedCopilotKitError as ResolvedCopilotKitError2, CopilotKitError as CopilotKitError2 } from "@copilotkit/shared";
|
|
2589
|
+
|
|
2590
|
+
// src/lib/runtime/agentwire-action.ts
|
|
2591
|
+
import { parseJson as parseJson3 } from "@copilotkit/shared";
|
|
2592
|
+
function constructAgentWireRemoteAction({ logger: logger2, messages, agentStates, agent }) {
|
|
2593
|
+
const action = {
|
|
2594
|
+
name: agent.agentId,
|
|
2595
|
+
description: agent.description,
|
|
2596
|
+
parameters: [],
|
|
2597
|
+
handler: async (_args) => {
|
|
2598
|
+
},
|
|
2599
|
+
remoteAgentHandler: async ({ actionInputsWithoutAgents, threadId }) => {
|
|
2600
|
+
logger2.debug({
|
|
2601
|
+
actionName: agent.agentId
|
|
2602
|
+
}, "Executing remote agent");
|
|
2603
|
+
const agentWireMessages = convertMessagesToAgentWire(messages);
|
|
2604
|
+
agent.messages = agentWireMessages;
|
|
2605
|
+
agent.threadId = threadId;
|
|
2606
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2607
|
+
agentExecution: true,
|
|
2608
|
+
type: "self-hosted",
|
|
2609
|
+
agentsAmount: 1
|
|
2610
|
+
});
|
|
2611
|
+
let state = {};
|
|
2612
|
+
if (agentStates) {
|
|
2613
|
+
const jsonState = agentStates.find((state2) => state2.agentName === agent.agentId);
|
|
2614
|
+
if (jsonState) {
|
|
2615
|
+
state = parseJson3(jsonState.state, {});
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
agent.state = state;
|
|
2619
|
+
const tools = actionInputsWithoutAgents.map((input) => {
|
|
2620
|
+
return {
|
|
2621
|
+
name: input.name,
|
|
2622
|
+
description: input.description,
|
|
2623
|
+
parameters: JSON.parse(input.jsonSchema)
|
|
2624
|
+
};
|
|
2625
|
+
});
|
|
2626
|
+
return agent.legacy_to_be_removed_runAgentBridged({
|
|
2627
|
+
tools
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
return [
|
|
2632
|
+
action
|
|
2633
|
+
];
|
|
2634
|
+
}
|
|
2635
|
+
__name(constructAgentWireRemoteAction, "constructAgentWireRemoteAction");
|
|
2636
|
+
function convertMessagesToAgentWire(messages) {
|
|
2637
|
+
const result = [];
|
|
2638
|
+
for (const message of messages) {
|
|
2639
|
+
if (message.isTextMessage()) {
|
|
2640
|
+
result.push({
|
|
2641
|
+
id: message.id,
|
|
2642
|
+
role: message.role,
|
|
2643
|
+
content: message.content
|
|
2644
|
+
});
|
|
2645
|
+
} else if (message.isActionExecutionMessage()) {
|
|
2646
|
+
const toolCall = {
|
|
2647
|
+
id: message.id,
|
|
2648
|
+
type: "function",
|
|
2649
|
+
function: {
|
|
2650
|
+
name: message.name,
|
|
2651
|
+
arguments: JSON.stringify(message.arguments)
|
|
2652
|
+
}
|
|
2653
|
+
};
|
|
2654
|
+
if (message.parentMessageId && result.some((m) => m.id === message.parentMessageId)) {
|
|
2655
|
+
const parentMessage = result.find((m) => m.id === message.parentMessageId);
|
|
2656
|
+
if (parentMessage.toolCalls === void 0) {
|
|
2657
|
+
parentMessage.toolCalls = [];
|
|
2658
|
+
}
|
|
2659
|
+
parentMessage.toolCalls.push(toolCall);
|
|
2660
|
+
} else {
|
|
2661
|
+
result.push({
|
|
2662
|
+
id: message.parentMessageId ?? message.id,
|
|
2663
|
+
role: "assistant",
|
|
2664
|
+
toolCalls: [
|
|
2665
|
+
toolCall
|
|
2666
|
+
]
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
} else if (message.isResultMessage()) {
|
|
2670
|
+
result.push({
|
|
2671
|
+
id: message.id,
|
|
2672
|
+
role: "tool",
|
|
2673
|
+
content: message.result,
|
|
2674
|
+
toolCallId: message.actionExecutionId
|
|
2675
|
+
});
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
return result;
|
|
2679
|
+
}
|
|
2680
|
+
__name(convertMessagesToAgentWire, "convertMessagesToAgentWire");
|
|
2681
|
+
|
|
2682
|
+
// src/lib/runtime/remote-actions.ts
|
|
2565
2683
|
var EndpointType;
|
|
2566
2684
|
(function(EndpointType2) {
|
|
2567
2685
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -2617,7 +2735,7 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2617
2735
|
}
|
|
2618
2736
|
}
|
|
2619
2737
|
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
2620
|
-
async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
|
|
2738
|
+
async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl, agents }) {
|
|
2621
2739
|
const logger2 = graphqlContext.logger.child({
|
|
2622
2740
|
component: "remote-actions.fetchRemoteActions"
|
|
2623
2741
|
});
|
|
@@ -2666,6 +2784,22 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
|
|
|
2666
2784
|
agentStates
|
|
2667
2785
|
});
|
|
2668
2786
|
}));
|
|
2787
|
+
for (const [key, agent] of Object.entries(agents)) {
|
|
2788
|
+
if (agent.agentId !== void 0 && agent.agentId !== key) {
|
|
2789
|
+
throw new CopilotKitError2({
|
|
2790
|
+
message: `Agent ${key} has agentId ${agent.agentId} which does not match the key ${key}`,
|
|
2791
|
+
code: CopilotKitErrorCode.UNKNOWN
|
|
2792
|
+
});
|
|
2793
|
+
} else if (agent.agentId === void 0) {
|
|
2794
|
+
agent.agentId = key;
|
|
2795
|
+
}
|
|
2796
|
+
result.push(constructAgentWireRemoteAction({
|
|
2797
|
+
logger: logger2,
|
|
2798
|
+
messages,
|
|
2799
|
+
agentStates,
|
|
2800
|
+
agent
|
|
2801
|
+
}));
|
|
2802
|
+
}
|
|
2669
2803
|
return result.flat();
|
|
2670
2804
|
}
|
|
2671
2805
|
__name(setupRemoteActions, "setupRemoteActions");
|
|
@@ -2674,7 +2808,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2674
2808
|
import { createHash as createHash3 } from "crypto";
|
|
2675
2809
|
|
|
2676
2810
|
// src/lib/runtime/copilot-runtime.ts
|
|
2677
|
-
import { actionParametersToJsonSchema, ResolvedCopilotKitError as ResolvedCopilotKitError3, CopilotKitApiDiscoveryError as CopilotKitApiDiscoveryError2, randomId as randomId2, CopilotKitError as CopilotKitError3, CopilotKitLowLevelError as CopilotKitLowLevelError3, CopilotKitAgentDiscoveryError, CopilotKitMisuseError } from "@copilotkit/shared";
|
|
2811
|
+
import { actionParametersToJsonSchema, ResolvedCopilotKitError as ResolvedCopilotKitError3, CopilotKitApiDiscoveryError as CopilotKitApiDiscoveryError2, randomId as randomId2, CopilotKitError as CopilotKitError3, CopilotKitLowLevelError as CopilotKitLowLevelError3, CopilotKitAgentDiscoveryError, CopilotKitMisuseError as CopilotKitMisuseError2 } from "@copilotkit/shared";
|
|
2678
2812
|
|
|
2679
2813
|
// src/service-adapters/conversion.ts
|
|
2680
2814
|
import { plainToInstance } from "class-transformer";
|
|
@@ -2729,8 +2863,65 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
|
2729
2863
|
// src/lib/runtime/copilot-runtime.ts
|
|
2730
2864
|
import { from } from "rxjs";
|
|
2731
2865
|
import { Client as LangGraphClient2 } from "@langchain/langgraph-sdk";
|
|
2866
|
+
|
|
2867
|
+
// src/lib/runtime/mcp-tools-utils.ts
|
|
2868
|
+
function extractParametersFromSchema(toolSchema) {
|
|
2869
|
+
var _a, _b;
|
|
2870
|
+
const parameters = [];
|
|
2871
|
+
const properties = (_a = toolSchema == null ? void 0 : toolSchema.parameters) == null ? void 0 : _a.properties;
|
|
2872
|
+
const requiredParams = new Set(((_b = toolSchema == null ? void 0 : toolSchema.parameters) == null ? void 0 : _b.required) || []);
|
|
2873
|
+
if (!properties) {
|
|
2874
|
+
return parameters;
|
|
2875
|
+
}
|
|
2876
|
+
for (const paramName in properties) {
|
|
2877
|
+
if (Object.prototype.hasOwnProperty.call(properties, paramName)) {
|
|
2878
|
+
const paramDef = properties[paramName];
|
|
2879
|
+
parameters.push({
|
|
2880
|
+
name: paramName,
|
|
2881
|
+
// Infer type, default to string. MCP schemas might have more complex types.
|
|
2882
|
+
// This might need refinement based on common MCP schema practices.
|
|
2883
|
+
type: paramDef.type || "string",
|
|
2884
|
+
description: paramDef.description,
|
|
2885
|
+
required: requiredParams.has(paramName)
|
|
2886
|
+
});
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
return parameters;
|
|
2890
|
+
}
|
|
2891
|
+
__name(extractParametersFromSchema, "extractParametersFromSchema");
|
|
2892
|
+
function convertMCPToolsToActions(mcpTools, mcpEndpoint) {
|
|
2893
|
+
const actions = [];
|
|
2894
|
+
for (const [toolName, tool] of Object.entries(mcpTools)) {
|
|
2895
|
+
const parameters = extractParametersFromSchema(tool.schema);
|
|
2896
|
+
const handler = /* @__PURE__ */ __name(async (params) => {
|
|
2897
|
+
try {
|
|
2898
|
+
const result = await tool.execute({
|
|
2899
|
+
params
|
|
2900
|
+
});
|
|
2901
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
2902
|
+
} catch (error) {
|
|
2903
|
+
console.error(`Error executing MCP tool '${toolName}' from endpoint ${mcpEndpoint}:`, error);
|
|
2904
|
+
throw new Error(`Execution failed for MCP tool '${toolName}': ${error instanceof Error ? error.message : String(error)}`);
|
|
2905
|
+
}
|
|
2906
|
+
}, "handler");
|
|
2907
|
+
actions.push({
|
|
2908
|
+
name: toolName,
|
|
2909
|
+
description: tool.description || `MCP tool: ${toolName} (from ${mcpEndpoint})`,
|
|
2910
|
+
parameters,
|
|
2911
|
+
handler,
|
|
2912
|
+
// Add metadata for easier identification/debugging
|
|
2913
|
+
_isMCPTool: true,
|
|
2914
|
+
_mcpEndpoint: mcpEndpoint
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
return actions;
|
|
2918
|
+
}
|
|
2919
|
+
__name(convertMCPToolsToActions, "convertMCPToolsToActions");
|
|
2920
|
+
|
|
2921
|
+
// src/lib/runtime/copilot-runtime.ts
|
|
2732
2922
|
var CopilotRuntime = class {
|
|
2733
2923
|
actions;
|
|
2924
|
+
agents;
|
|
2734
2925
|
remoteEndpointDefinitions;
|
|
2735
2926
|
langserve = [];
|
|
2736
2927
|
onBeforeRequest;
|
|
@@ -2738,8 +2929,15 @@ var CopilotRuntime = class {
|
|
|
2738
2929
|
delegateAgentProcessingToServiceAdapter;
|
|
2739
2930
|
observability;
|
|
2740
2931
|
availableAgents;
|
|
2932
|
+
// +++ MCP Properties +++
|
|
2933
|
+
mcpEndpointsConfig;
|
|
2934
|
+
mcpActionCache = /* @__PURE__ */ new Map();
|
|
2935
|
+
// --- MCP Properties ---
|
|
2936
|
+
// +++ MCP Client Factory +++
|
|
2937
|
+
createMCPClientImpl;
|
|
2938
|
+
// --- MCP Client Factory ---
|
|
2741
2939
|
constructor(params) {
|
|
2742
|
-
var _a, _b;
|
|
2940
|
+
var _a, _b, _c, _d;
|
|
2743
2941
|
if ((params == null ? void 0 : params.actions) && (params == null ? void 0 : params.remoteEndpoints) && (params == null ? void 0 : params.remoteEndpoints.some((e) => e.type === EndpointType.LangGraphPlatform))) {
|
|
2744
2942
|
console.warn("Actions set in runtime instance will not be available for the agent");
|
|
2745
2943
|
}
|
|
@@ -2754,7 +2952,60 @@ var CopilotRuntime = class {
|
|
|
2754
2952
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
2755
2953
|
this.delegateAgentProcessingToServiceAdapter = (params == null ? void 0 : params.delegateAgentProcessingToServiceAdapter) || false;
|
|
2756
2954
|
this.observability = params == null ? void 0 : params.observability_c;
|
|
2955
|
+
this.agents = (params == null ? void 0 : params.agents) ?? {};
|
|
2956
|
+
this.mcpEndpointsConfig = params == null ? void 0 : params.mcpEndpoints;
|
|
2957
|
+
this.createMCPClientImpl = params == null ? void 0 : params.createMCPClient;
|
|
2958
|
+
if (this.mcpEndpointsConfig && this.mcpEndpointsConfig.length > 0 && !this.createMCPClientImpl) {
|
|
2959
|
+
throw new CopilotKitMisuseError2({
|
|
2960
|
+
message: "MCP Integration Error: `mcpEndpoints` were provided, but the `createMCPClient` function was not passed to the CopilotRuntime constructor. Please provide an implementation for `createMCPClient`."
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
if ((params == null ? void 0 : params.actions) && (((_c = params == null ? void 0 : params.remoteEndpoints) == null ? void 0 : _c.some((e) => e.type === EndpointType.LangGraphPlatform)) || ((_d = this.mcpEndpointsConfig) == null ? void 0 : _d.length))) {
|
|
2964
|
+
console.warn("Local 'actions' defined in CopilotRuntime might not be available to remote agents (LangGraph, MCP). Consider defining actions closer to the agent implementation if needed.");
|
|
2965
|
+
}
|
|
2757
2966
|
}
|
|
2967
|
+
// +++ MCP Instruction Injection Method +++
|
|
2968
|
+
injectMCPToolInstructions(messages, currentActions) {
|
|
2969
|
+
const mcpActionsForRequest = currentActions.filter((action) => action._isMCPTool);
|
|
2970
|
+
if (!mcpActionsForRequest || mcpActionsForRequest.length === 0) {
|
|
2971
|
+
return messages;
|
|
2972
|
+
}
|
|
2973
|
+
const mcpToolInstructions = mcpActionsForRequest.map((action) => {
|
|
2974
|
+
const paramsString = action.parameters && action.parameters.length > 0 ? ` Parameters: ${action.parameters.map((p) => `${p.name}${p.required ? "*" : ""}(${p.type})`).join(", ")}` : "";
|
|
2975
|
+
return `- ${action.name}:${paramsString} ${action.description || ""}`;
|
|
2976
|
+
}).join("\n");
|
|
2977
|
+
if (!mcpToolInstructions) {
|
|
2978
|
+
return messages;
|
|
2979
|
+
}
|
|
2980
|
+
const instructions = "You have access to the following tools provided by external Model Context Protocol (MCP) servers:\n" + mcpToolInstructions + "\nUse them when appropriate to fulfill the user's request.";
|
|
2981
|
+
const systemMessageIndex = messages.findIndex((msg) => {
|
|
2982
|
+
var _a;
|
|
2983
|
+
return ((_a = msg.textMessage) == null ? void 0 : _a.role) === "system";
|
|
2984
|
+
});
|
|
2985
|
+
const newMessages = [
|
|
2986
|
+
...messages
|
|
2987
|
+
];
|
|
2988
|
+
if (systemMessageIndex !== -1) {
|
|
2989
|
+
const existingMsg = newMessages[systemMessageIndex];
|
|
2990
|
+
if (existingMsg.textMessage) {
|
|
2991
|
+
existingMsg.textMessage.content = (existingMsg.textMessage.content ? existingMsg.textMessage.content + "\n\n" : "") + instructions;
|
|
2992
|
+
}
|
|
2993
|
+
} else {
|
|
2994
|
+
newMessages.unshift({
|
|
2995
|
+
id: randomId2(),
|
|
2996
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2997
|
+
textMessage: {
|
|
2998
|
+
role: MessageRole.system,
|
|
2999
|
+
content: instructions
|
|
3000
|
+
},
|
|
3001
|
+
actionExecutionMessage: void 0,
|
|
3002
|
+
resultMessage: void 0,
|
|
3003
|
+
agentStateMessage: void 0
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
return newMessages;
|
|
3007
|
+
}
|
|
3008
|
+
// --- MCP Instruction Injection Method ---
|
|
2758
3009
|
async processRuntimeRequest(request) {
|
|
2759
3010
|
var _a, _b, _c, _d, _e;
|
|
2760
3011
|
const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, url, extensions, agentSession, agentStates, publicApiKey } = request;
|
|
@@ -2766,15 +3017,16 @@ var CopilotRuntime = class {
|
|
|
2766
3017
|
return await this.processAgentRequest(request);
|
|
2767
3018
|
}
|
|
2768
3019
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
2769
|
-
throw new
|
|
3020
|
+
throw new CopilotKitMisuseError2({
|
|
2770
3021
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
2771
3022
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
2772
3023
|
please use an LLM adapter instead.`
|
|
2773
3024
|
});
|
|
2774
3025
|
}
|
|
2775
|
-
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2776
|
-
const inputMessages = convertGqlInputToMessages(messages);
|
|
2777
3026
|
const serverSideActions = await this.getServerSideActions(request);
|
|
3027
|
+
const filteredRawMessages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
3028
|
+
const messagesWithInjectedInstructions = this.injectMCPToolInstructions(filteredRawMessages, serverSideActions);
|
|
3029
|
+
const inputMessages = convertGqlInputToMessages(messagesWithInjectedInstructions);
|
|
2778
3030
|
if (((_a = this.observability) == null ? void 0 : _a.enabled) && publicApiKey) {
|
|
2779
3031
|
try {
|
|
2780
3032
|
const requestData = {
|
|
@@ -2955,7 +3207,7 @@ please use an LLM adapter instead.`
|
|
|
2955
3207
|
});
|
|
2956
3208
|
}
|
|
2957
3209
|
} catch (e) {
|
|
2958
|
-
throw new
|
|
3210
|
+
throw new CopilotKitMisuseError2({
|
|
2959
3211
|
message: `
|
|
2960
3212
|
Failed to find or contact remote endpoint at url ${endpoint.deploymentUrl}.
|
|
2961
3213
|
Make sure the API is running and that it's indeed a LangGraph platform url.
|
|
@@ -3301,7 +3553,8 @@ please use an LLM adapter instead.`
|
|
|
3301
3553
|
}
|
|
3302
3554
|
}
|
|
3303
3555
|
async getServerSideActions(request) {
|
|
3304
|
-
|
|
3556
|
+
var _a;
|
|
3557
|
+
const { graphqlContext, messages: rawMessages, agentStates, url } = request;
|
|
3305
3558
|
const inputMessages = convertGqlInputToMessages(rawMessages);
|
|
3306
3559
|
const langserveFunctions = [];
|
|
3307
3560
|
for (const chainPromise of this.langserve) {
|
|
@@ -3321,16 +3574,53 @@ please use an LLM adapter instead.`
|
|
|
3321
3574
|
graphqlContext,
|
|
3322
3575
|
messages: inputMessages,
|
|
3323
3576
|
agentStates,
|
|
3324
|
-
frontendUrl: url
|
|
3577
|
+
frontendUrl: url,
|
|
3578
|
+
agents: this.agents
|
|
3325
3579
|
});
|
|
3326
3580
|
const configuredActions = typeof this.actions === "function" ? this.actions({
|
|
3327
3581
|
properties: graphqlContext.properties,
|
|
3328
3582
|
url
|
|
3329
3583
|
}) : this.actions;
|
|
3584
|
+
const requestSpecificMCPActions = [];
|
|
3585
|
+
if (this.createMCPClientImpl) {
|
|
3586
|
+
const baseEndpoints = this.mcpEndpointsConfig || [];
|
|
3587
|
+
const requestEndpoints = ((_a = graphqlContext.properties) == null ? void 0 : _a.mcpEndpoints) || [];
|
|
3588
|
+
const effectiveEndpointsMap = /* @__PURE__ */ new Map();
|
|
3589
|
+
[
|
|
3590
|
+
...baseEndpoints,
|
|
3591
|
+
...requestEndpoints
|
|
3592
|
+
].forEach((ep) => {
|
|
3593
|
+
if (ep && ep.endpoint) {
|
|
3594
|
+
effectiveEndpointsMap.set(ep.endpoint, ep);
|
|
3595
|
+
}
|
|
3596
|
+
});
|
|
3597
|
+
const effectiveEndpoints = Array.from(effectiveEndpointsMap.values());
|
|
3598
|
+
for (const config of effectiveEndpoints) {
|
|
3599
|
+
const endpointUrl = config.endpoint;
|
|
3600
|
+
let actionsForEndpoint = this.mcpActionCache.get(endpointUrl);
|
|
3601
|
+
if (!actionsForEndpoint) {
|
|
3602
|
+
let client = null;
|
|
3603
|
+
try {
|
|
3604
|
+
console.log(`MCP: Cache miss. Fetching tools for endpoint: ${endpointUrl}`);
|
|
3605
|
+
client = await this.createMCPClientImpl(config);
|
|
3606
|
+
const tools = await client.tools();
|
|
3607
|
+
actionsForEndpoint = convertMCPToolsToActions(tools, endpointUrl);
|
|
3608
|
+
this.mcpActionCache.set(endpointUrl, actionsForEndpoint);
|
|
3609
|
+
console.log(`MCP: Fetched and cached ${actionsForEndpoint.length} tools for ${endpointUrl}`);
|
|
3610
|
+
} catch (error) {
|
|
3611
|
+
console.error(`MCP: Failed to fetch tools from endpoint ${endpointUrl}. Skipping. Error:`, error);
|
|
3612
|
+
actionsForEndpoint = [];
|
|
3613
|
+
this.mcpActionCache.set(endpointUrl, actionsForEndpoint);
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
requestSpecificMCPActions.push(...actionsForEndpoint || []);
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3330
3619
|
return [
|
|
3331
3620
|
...configuredActions,
|
|
3332
3621
|
...langserveFunctions,
|
|
3333
|
-
...remoteActions
|
|
3622
|
+
...remoteActions,
|
|
3623
|
+
...requestSpecificMCPActions
|
|
3334
3624
|
];
|
|
3335
3625
|
}
|
|
3336
3626
|
// Add helper method to detect provider
|
|
@@ -4588,13 +4878,15 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4588
4878
|
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
4589
4879
|
|
|
4590
4880
|
export {
|
|
4591
|
-
|
|
4592
|
-
|
|
4881
|
+
extractParametersFromSchema,
|
|
4882
|
+
convertMCPToolsToActions,
|
|
4593
4883
|
CopilotRuntime,
|
|
4594
4884
|
flattenToolCallsNoDuplicates,
|
|
4595
4885
|
copilotKitEndpoint,
|
|
4596
4886
|
langGraphPlatformEndpoint,
|
|
4597
4887
|
resolveEndpointType,
|
|
4888
|
+
getRuntimeInstanceTelemetryInfo,
|
|
4889
|
+
telemetry_client_default,
|
|
4598
4890
|
createLogger,
|
|
4599
4891
|
addCustomHeaderPlugin,
|
|
4600
4892
|
createContext,
|
|
@@ -4602,4 +4894,4 @@ export {
|
|
|
4602
4894
|
getCommonConfig,
|
|
4603
4895
|
copilotRuntimeNodeHttpEndpoint
|
|
4604
4896
|
};
|
|
4605
|
-
//# sourceMappingURL=chunk-
|
|
4897
|
+
//# sourceMappingURL=chunk-H2VC34X7.mjs.map
|