@copilotkit/runtime 1.8.5-next.2 → 1.8.5-next.4
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 +14 -0
- package/dist/{chunk-PJX3FQOX.mjs → chunk-574FKWP5.mjs} +2 -2
- package/dist/{chunk-FZJAYGIR.mjs → chunk-DNI7KA7Y.mjs} +2 -2
- package/dist/{chunk-A7E5UM7B.mjs → chunk-GGXHVDCG.mjs} +2 -2
- package/dist/{chunk-A4MGCX6X.mjs → chunk-PKO7BUPS.mjs} +186 -14
- package/dist/chunk-PKO7BUPS.mjs.map +1 -0
- package/dist/chunk-Q6JA6YY3.mjs +1 -0
- package/dist/{chunk-7VNWCLG4.mjs → chunk-WQZQTGHT.mjs} +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.js +4042 -3862
- 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 +7 -7
- package/dist/lib/index.js +3890 -3710
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +10 -6
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +1 -1
- 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 +3 -3
- package/dist/lib/integrations/nest/index.js +1 -1
- 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 +3 -3
- package/dist/lib/integrations/node-express/index.js +1 -1
- 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 +3 -3
- package/dist/lib/integrations/node-http/index.js +1 -1
- 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-86ec42e7.d.ts} +130 -45
- package/package.json +2 -2
- package/src/lib/index.ts +2 -1
- package/src/lib/runtime/copilot-runtime.ts +218 -11
- package/src/lib/runtime/mcp-tools-utils.ts +117 -0
- package/src/lib/runtime/remote-lg-action.ts +24 -2
- package/dist/chunk-A4MGCX6X.mjs.map +0 -1
- package/dist/chunk-PTC5JN3P.mjs +0 -1
- /package/dist/{chunk-PJX3FQOX.mjs.map → chunk-574FKWP5.mjs.map} +0 -0
- /package/dist/{chunk-FZJAYGIR.mjs.map → chunk-DNI7KA7Y.mjs.map} +0 -0
- /package/dist/{chunk-A7E5UM7B.mjs.map → chunk-GGXHVDCG.mjs.map} +0 -0
- /package/dist/{chunk-PTC5JN3P.mjs.map → chunk-Q6JA6YY3.mjs.map} +0 -0
- /package/dist/{chunk-7VNWCLG4.mjs.map → chunk-WQZQTGHT.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @copilotkit/runtime
|
|
2
2
|
|
|
3
|
+
## 1.8.5-next.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 76d9ef9: - fix: handle langgraph client specific errors when running lgc stream
|
|
8
|
+
- @copilotkit/shared@1.8.5-next.4
|
|
9
|
+
|
|
10
|
+
## 1.8.5-next.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 77a7457: - feat: Add Model Context Protocol (MCP) support
|
|
15
|
+
- @copilotkit/shared@1.8.5-next.3
|
|
16
|
+
|
|
3
17
|
## 1.8.5-next.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PKO7BUPS.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-574FKWP5.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
|
getCommonConfig,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PKO7BUPS.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-GGXHVDCG.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.5-next.
|
|
42
|
+
version: "1.8.5-next.4",
|
|
43
43
|
sideEffects: false,
|
|
44
44
|
main: "./dist/index.js",
|
|
45
45
|
module: "./dist/index.mjs",
|
|
@@ -1687,7 +1687,7 @@ import { Client as LangGraphClient } from "@langchain/langgraph-sdk";
|
|
|
1687
1687
|
import { createHash } from "crypto";
|
|
1688
1688
|
import { isValidUUID, randomUUID } from "@copilotkit/shared";
|
|
1689
1689
|
import { parse as parsePartialJson } from "partial-json";
|
|
1690
|
-
import { parseJson } from "@copilotkit/shared";
|
|
1690
|
+
import { parseJson, CopilotKitMisuseError } from "@copilotkit/shared";
|
|
1691
1691
|
import { RemoveMessage } from "@langchain/core/messages";
|
|
1692
1692
|
var activeInterruptEvent = false;
|
|
1693
1693
|
async function execute(args) {
|
|
@@ -1697,6 +1697,23 @@ async function execute(args) {
|
|
|
1697
1697
|
await streamEvents(controller, args);
|
|
1698
1698
|
controller.close();
|
|
1699
1699
|
} catch (err) {
|
|
1700
|
+
const cause = err == null ? void 0 : err.cause;
|
|
1701
|
+
const errorCode = (cause == null ? void 0 : cause.code) || (err == null ? void 0 : err.code);
|
|
1702
|
+
if (errorCode === "ECONNREFUSED") {
|
|
1703
|
+
throw new CopilotKitMisuseError({
|
|
1704
|
+
message: `
|
|
1705
|
+
The LangGraph client could not connect to the graph. Please further check previous logs, which includes further details.
|
|
1706
|
+
|
|
1707
|
+
See more: https://docs.copilotkit.ai/troubleshooting/common-issues`
|
|
1708
|
+
});
|
|
1709
|
+
} else {
|
|
1710
|
+
throw new CopilotKitMisuseError({
|
|
1711
|
+
message: `
|
|
1712
|
+
The LangGraph client threw unhandled error ${err}.
|
|
1713
|
+
|
|
1714
|
+
See more: https://docs.copilotkit.ai/troubleshooting/common-issues`
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1700
1717
|
}
|
|
1701
1718
|
}
|
|
1702
1719
|
});
|
|
@@ -2674,7 +2691,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2674
2691
|
import { createHash as createHash3 } from "crypto";
|
|
2675
2692
|
|
|
2676
2693
|
// 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";
|
|
2694
|
+
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
2695
|
|
|
2679
2696
|
// src/service-adapters/conversion.ts
|
|
2680
2697
|
import { plainToInstance } from "class-transformer";
|
|
@@ -2729,6 +2746,62 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
|
2729
2746
|
// src/lib/runtime/copilot-runtime.ts
|
|
2730
2747
|
import { from } from "rxjs";
|
|
2731
2748
|
import { Client as LangGraphClient2 } from "@langchain/langgraph-sdk";
|
|
2749
|
+
|
|
2750
|
+
// src/lib/runtime/mcp-tools-utils.ts
|
|
2751
|
+
function extractParametersFromSchema(toolSchema) {
|
|
2752
|
+
var _a, _b;
|
|
2753
|
+
const parameters = [];
|
|
2754
|
+
const properties = (_a = toolSchema == null ? void 0 : toolSchema.parameters) == null ? void 0 : _a.properties;
|
|
2755
|
+
const requiredParams = new Set(((_b = toolSchema == null ? void 0 : toolSchema.parameters) == null ? void 0 : _b.required) || []);
|
|
2756
|
+
if (!properties) {
|
|
2757
|
+
return parameters;
|
|
2758
|
+
}
|
|
2759
|
+
for (const paramName in properties) {
|
|
2760
|
+
if (Object.prototype.hasOwnProperty.call(properties, paramName)) {
|
|
2761
|
+
const paramDef = properties[paramName];
|
|
2762
|
+
parameters.push({
|
|
2763
|
+
name: paramName,
|
|
2764
|
+
// Infer type, default to string. MCP schemas might have more complex types.
|
|
2765
|
+
// This might need refinement based on common MCP schema practices.
|
|
2766
|
+
type: paramDef.type || "string",
|
|
2767
|
+
description: paramDef.description,
|
|
2768
|
+
required: requiredParams.has(paramName)
|
|
2769
|
+
});
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
return parameters;
|
|
2773
|
+
}
|
|
2774
|
+
__name(extractParametersFromSchema, "extractParametersFromSchema");
|
|
2775
|
+
function convertMCPToolsToActions(mcpTools, mcpEndpoint) {
|
|
2776
|
+
const actions = [];
|
|
2777
|
+
for (const [toolName, tool] of Object.entries(mcpTools)) {
|
|
2778
|
+
const parameters = extractParametersFromSchema(tool.schema);
|
|
2779
|
+
const handler = /* @__PURE__ */ __name(async (params) => {
|
|
2780
|
+
try {
|
|
2781
|
+
const result = await tool.execute({
|
|
2782
|
+
params
|
|
2783
|
+
});
|
|
2784
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
2785
|
+
} catch (error) {
|
|
2786
|
+
console.error(`Error executing MCP tool '${toolName}' from endpoint ${mcpEndpoint}:`, error);
|
|
2787
|
+
throw new Error(`Execution failed for MCP tool '${toolName}': ${error instanceof Error ? error.message : String(error)}`);
|
|
2788
|
+
}
|
|
2789
|
+
}, "handler");
|
|
2790
|
+
actions.push({
|
|
2791
|
+
name: toolName,
|
|
2792
|
+
description: tool.description || `MCP tool: ${toolName} (from ${mcpEndpoint})`,
|
|
2793
|
+
parameters,
|
|
2794
|
+
handler,
|
|
2795
|
+
// Add metadata for easier identification/debugging
|
|
2796
|
+
_isMCPTool: true,
|
|
2797
|
+
_mcpEndpoint: mcpEndpoint
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
return actions;
|
|
2801
|
+
}
|
|
2802
|
+
__name(convertMCPToolsToActions, "convertMCPToolsToActions");
|
|
2803
|
+
|
|
2804
|
+
// src/lib/runtime/copilot-runtime.ts
|
|
2732
2805
|
var CopilotRuntime = class {
|
|
2733
2806
|
actions;
|
|
2734
2807
|
remoteEndpointDefinitions;
|
|
@@ -2738,8 +2811,15 @@ var CopilotRuntime = class {
|
|
|
2738
2811
|
delegateAgentProcessingToServiceAdapter;
|
|
2739
2812
|
observability;
|
|
2740
2813
|
availableAgents;
|
|
2814
|
+
// +++ MCP Properties +++
|
|
2815
|
+
mcpEndpointsConfig;
|
|
2816
|
+
mcpActionCache = /* @__PURE__ */ new Map();
|
|
2817
|
+
// --- MCP Properties ---
|
|
2818
|
+
// +++ MCP Client Factory +++
|
|
2819
|
+
createMCPClientImpl;
|
|
2820
|
+
// --- MCP Client Factory ---
|
|
2741
2821
|
constructor(params) {
|
|
2742
|
-
var _a, _b;
|
|
2822
|
+
var _a, _b, _c, _d;
|
|
2743
2823
|
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
2824
|
console.warn("Actions set in runtime instance will not be available for the agent");
|
|
2745
2825
|
}
|
|
@@ -2754,7 +2834,59 @@ var CopilotRuntime = class {
|
|
|
2754
2834
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
2755
2835
|
this.delegateAgentProcessingToServiceAdapter = (params == null ? void 0 : params.delegateAgentProcessingToServiceAdapter) || false;
|
|
2756
2836
|
this.observability = params == null ? void 0 : params.observability_c;
|
|
2837
|
+
this.mcpEndpointsConfig = params == null ? void 0 : params.mcpEndpoints;
|
|
2838
|
+
this.createMCPClientImpl = params == null ? void 0 : params.createMCPClient;
|
|
2839
|
+
if (this.mcpEndpointsConfig && this.mcpEndpointsConfig.length > 0 && !this.createMCPClientImpl) {
|
|
2840
|
+
throw new CopilotKitMisuseError2({
|
|
2841
|
+
message: "MCP Integration Error: `mcpEndpoints` were provided, but the `createMCPClient` function was not passed to the CopilotRuntime constructor. Please provide an implementation for `createMCPClient`."
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
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))) {
|
|
2845
|
+
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.");
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
// +++ MCP Instruction Injection Method +++
|
|
2849
|
+
injectMCPToolInstructions(messages, currentActions) {
|
|
2850
|
+
const mcpActionsForRequest = currentActions.filter((action) => action._isMCPTool);
|
|
2851
|
+
if (!mcpActionsForRequest || mcpActionsForRequest.length === 0) {
|
|
2852
|
+
return messages;
|
|
2853
|
+
}
|
|
2854
|
+
const mcpToolInstructions = mcpActionsForRequest.map((action) => {
|
|
2855
|
+
const paramsString = action.parameters && action.parameters.length > 0 ? ` Parameters: ${action.parameters.map((p) => `${p.name}${p.required ? "*" : ""}(${p.type})`).join(", ")}` : "";
|
|
2856
|
+
return `- ${action.name}:${paramsString} ${action.description || ""}`;
|
|
2857
|
+
}).join("\n");
|
|
2858
|
+
if (!mcpToolInstructions) {
|
|
2859
|
+
return messages;
|
|
2860
|
+
}
|
|
2861
|
+
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.";
|
|
2862
|
+
const systemMessageIndex = messages.findIndex((msg) => {
|
|
2863
|
+
var _a;
|
|
2864
|
+
return ((_a = msg.textMessage) == null ? void 0 : _a.role) === "system";
|
|
2865
|
+
});
|
|
2866
|
+
const newMessages = [
|
|
2867
|
+
...messages
|
|
2868
|
+
];
|
|
2869
|
+
if (systemMessageIndex !== -1) {
|
|
2870
|
+
const existingMsg = newMessages[systemMessageIndex];
|
|
2871
|
+
if (existingMsg.textMessage) {
|
|
2872
|
+
existingMsg.textMessage.content = (existingMsg.textMessage.content ? existingMsg.textMessage.content + "\n\n" : "") + instructions;
|
|
2873
|
+
}
|
|
2874
|
+
} else {
|
|
2875
|
+
newMessages.unshift({
|
|
2876
|
+
id: randomId2(),
|
|
2877
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2878
|
+
textMessage: {
|
|
2879
|
+
role: MessageRole.system,
|
|
2880
|
+
content: instructions
|
|
2881
|
+
},
|
|
2882
|
+
actionExecutionMessage: void 0,
|
|
2883
|
+
resultMessage: void 0,
|
|
2884
|
+
agentStateMessage: void 0
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2887
|
+
return newMessages;
|
|
2757
2888
|
}
|
|
2889
|
+
// --- MCP Instruction Injection Method ---
|
|
2758
2890
|
async processRuntimeRequest(request) {
|
|
2759
2891
|
var _a, _b, _c, _d, _e;
|
|
2760
2892
|
const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, url, extensions, agentSession, agentStates, publicApiKey } = request;
|
|
@@ -2766,15 +2898,16 @@ var CopilotRuntime = class {
|
|
|
2766
2898
|
return await this.processAgentRequest(request);
|
|
2767
2899
|
}
|
|
2768
2900
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
2769
|
-
throw new
|
|
2901
|
+
throw new CopilotKitMisuseError2({
|
|
2770
2902
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
2771
2903
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
2772
2904
|
please use an LLM adapter instead.`
|
|
2773
2905
|
});
|
|
2774
2906
|
}
|
|
2775
|
-
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2776
|
-
const inputMessages = convertGqlInputToMessages(messages);
|
|
2777
2907
|
const serverSideActions = await this.getServerSideActions(request);
|
|
2908
|
+
const filteredRawMessages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2909
|
+
const messagesWithInjectedInstructions = this.injectMCPToolInstructions(filteredRawMessages, serverSideActions);
|
|
2910
|
+
const inputMessages = convertGqlInputToMessages(messagesWithInjectedInstructions);
|
|
2778
2911
|
if (((_a = this.observability) == null ? void 0 : _a.enabled) && publicApiKey) {
|
|
2779
2912
|
try {
|
|
2780
2913
|
const requestData = {
|
|
@@ -2955,7 +3088,7 @@ please use an LLM adapter instead.`
|
|
|
2955
3088
|
});
|
|
2956
3089
|
}
|
|
2957
3090
|
} catch (e) {
|
|
2958
|
-
throw new
|
|
3091
|
+
throw new CopilotKitMisuseError2({
|
|
2959
3092
|
message: `
|
|
2960
3093
|
Failed to find or contact remote endpoint at url ${endpoint.deploymentUrl}.
|
|
2961
3094
|
Make sure the API is running and that it's indeed a LangGraph platform url.
|
|
@@ -3301,7 +3434,8 @@ please use an LLM adapter instead.`
|
|
|
3301
3434
|
}
|
|
3302
3435
|
}
|
|
3303
3436
|
async getServerSideActions(request) {
|
|
3304
|
-
|
|
3437
|
+
var _a;
|
|
3438
|
+
const { graphqlContext, messages: rawMessages, agentStates, url } = request;
|
|
3305
3439
|
const inputMessages = convertGqlInputToMessages(rawMessages);
|
|
3306
3440
|
const langserveFunctions = [];
|
|
3307
3441
|
for (const chainPromise of this.langserve) {
|
|
@@ -3327,10 +3461,46 @@ please use an LLM adapter instead.`
|
|
|
3327
3461
|
properties: graphqlContext.properties,
|
|
3328
3462
|
url
|
|
3329
3463
|
}) : this.actions;
|
|
3464
|
+
const requestSpecificMCPActions = [];
|
|
3465
|
+
if (this.createMCPClientImpl) {
|
|
3466
|
+
const baseEndpoints = this.mcpEndpointsConfig || [];
|
|
3467
|
+
const requestEndpoints = ((_a = graphqlContext.properties) == null ? void 0 : _a.mcpEndpoints) || [];
|
|
3468
|
+
const effectiveEndpointsMap = /* @__PURE__ */ new Map();
|
|
3469
|
+
[
|
|
3470
|
+
...baseEndpoints,
|
|
3471
|
+
...requestEndpoints
|
|
3472
|
+
].forEach((ep) => {
|
|
3473
|
+
if (ep && ep.endpoint) {
|
|
3474
|
+
effectiveEndpointsMap.set(ep.endpoint, ep);
|
|
3475
|
+
}
|
|
3476
|
+
});
|
|
3477
|
+
const effectiveEndpoints = Array.from(effectiveEndpointsMap.values());
|
|
3478
|
+
for (const config of effectiveEndpoints) {
|
|
3479
|
+
const endpointUrl = config.endpoint;
|
|
3480
|
+
let actionsForEndpoint = this.mcpActionCache.get(endpointUrl);
|
|
3481
|
+
if (!actionsForEndpoint) {
|
|
3482
|
+
let client = null;
|
|
3483
|
+
try {
|
|
3484
|
+
console.log(`MCP: Cache miss. Fetching tools for endpoint: ${endpointUrl}`);
|
|
3485
|
+
client = await this.createMCPClientImpl(config);
|
|
3486
|
+
const tools = await client.tools();
|
|
3487
|
+
actionsForEndpoint = convertMCPToolsToActions(tools, endpointUrl);
|
|
3488
|
+
this.mcpActionCache.set(endpointUrl, actionsForEndpoint);
|
|
3489
|
+
console.log(`MCP: Fetched and cached ${actionsForEndpoint.length} tools for ${endpointUrl}`);
|
|
3490
|
+
} catch (error) {
|
|
3491
|
+
console.error(`MCP: Failed to fetch tools from endpoint ${endpointUrl}. Skipping. Error:`, error);
|
|
3492
|
+
actionsForEndpoint = [];
|
|
3493
|
+
this.mcpActionCache.set(endpointUrl, actionsForEndpoint);
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
requestSpecificMCPActions.push(...actionsForEndpoint || []);
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3330
3499
|
return [
|
|
3331
3500
|
...configuredActions,
|
|
3332
3501
|
...langserveFunctions,
|
|
3333
|
-
...remoteActions
|
|
3502
|
+
...remoteActions,
|
|
3503
|
+
...requestSpecificMCPActions
|
|
3334
3504
|
];
|
|
3335
3505
|
}
|
|
3336
3506
|
// Add helper method to detect provider
|
|
@@ -4588,13 +4758,15 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4588
4758
|
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
4589
4759
|
|
|
4590
4760
|
export {
|
|
4591
|
-
|
|
4592
|
-
|
|
4761
|
+
extractParametersFromSchema,
|
|
4762
|
+
convertMCPToolsToActions,
|
|
4593
4763
|
CopilotRuntime,
|
|
4594
4764
|
flattenToolCallsNoDuplicates,
|
|
4595
4765
|
copilotKitEndpoint,
|
|
4596
4766
|
langGraphPlatformEndpoint,
|
|
4597
4767
|
resolveEndpointType,
|
|
4768
|
+
getRuntimeInstanceTelemetryInfo,
|
|
4769
|
+
telemetry_client_default,
|
|
4598
4770
|
createLogger,
|
|
4599
4771
|
addCustomHeaderPlugin,
|
|
4600
4772
|
createContext,
|
|
@@ -4602,4 +4774,4 @@ export {
|
|
|
4602
4774
|
getCommonConfig,
|
|
4603
4775
|
copilotRuntimeNodeHttpEndpoint
|
|
4604
4776
|
};
|
|
4605
|
-
//# sourceMappingURL=chunk-
|
|
4777
|
+
//# sourceMappingURL=chunk-PKO7BUPS.mjs.map
|