@copilotkit/runtime 1.8.7 → 1.8.8-next.1

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-TOZ7TDZQ.mjs → chunk-3UU33HF6.mjs} +2 -2
  3. package/dist/{chunk-D453SZIW.mjs → chunk-HBCCZQBE.mjs} +29 -19
  4. package/dist/chunk-HBCCZQBE.mjs.map +1 -0
  5. package/dist/{chunk-ZD6BIBVB.mjs → chunk-O4WMMGSX.mjs} +2 -2
  6. package/dist/{chunk-S2W2IABM.mjs → chunk-QF6GPOZV.mjs} +2 -2
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +28 -18
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +4 -4
  11. package/dist/lib/index.d.ts +1 -1
  12. package/dist/lib/index.js +28 -18
  13. package/dist/lib/index.js.map +1 -1
  14. package/dist/lib/index.mjs +4 -4
  15. package/dist/lib/integrations/index.d.ts +2 -2
  16. package/dist/lib/integrations/index.js +1 -1
  17. package/dist/lib/integrations/index.js.map +1 -1
  18. package/dist/lib/integrations/index.mjs +4 -4
  19. package/dist/lib/integrations/nest/index.d.ts +1 -1
  20. package/dist/lib/integrations/nest/index.js +1 -1
  21. package/dist/lib/integrations/nest/index.js.map +1 -1
  22. package/dist/lib/integrations/nest/index.mjs +2 -2
  23. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  24. package/dist/lib/integrations/node-express/index.js +1 -1
  25. package/dist/lib/integrations/node-express/index.js.map +1 -1
  26. package/dist/lib/integrations/node-express/index.mjs +2 -2
  27. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  28. package/dist/lib/integrations/node-http/index.js +1 -1
  29. package/dist/lib/integrations/node-http/index.js.map +1 -1
  30. package/dist/lib/integrations/node-http/index.mjs +1 -1
  31. package/dist/{shared-350db43f.d.ts → shared-32a46e93.d.ts} +7 -6
  32. package/package.json +2 -2
  33. package/src/lib/runtime/copilot-runtime.ts +34 -24
  34. package/src/lib/runtime/mcp-tools-utils.ts +16 -5
  35. package/dist/chunk-D453SZIW.mjs.map +0 -1
  36. /package/dist/{chunk-TOZ7TDZQ.mjs.map → chunk-3UU33HF6.mjs.map} +0 -0
  37. /package/dist/{chunk-ZD6BIBVB.mjs.map → chunk-O4WMMGSX.mjs.map} +0 -0
  38. /package/dist/{chunk-S2W2IABM.mjs.map → chunk-QF6GPOZV.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  config,
4
4
  copilotRuntimeNextJSAppRouterEndpoint,
5
5
  copilotRuntimeNextJSPagesRouterEndpoint
6
- } from "./chunk-S2W2IABM.mjs";
6
+ } from "./chunk-QF6GPOZV.mjs";
7
7
  import {
8
8
  copilotRuntimeNestEndpoint
9
- } from "./chunk-ZD6BIBVB.mjs";
9
+ } from "./chunk-O4WMMGSX.mjs";
10
10
  import {
11
11
  copilotRuntimeNodeExpressEndpoint
12
- } from "./chunk-TOZ7TDZQ.mjs";
12
+ } from "./chunk-3UU33HF6.mjs";
13
13
  import {
14
14
  CopilotRuntime,
15
15
  addCustomHeaderPlugin,
@@ -24,7 +24,7 @@ import {
24
24
  getCommonConfig,
25
25
  langGraphPlatformEndpoint,
26
26
  resolveEndpointType
27
- } from "./chunk-D453SZIW.mjs";
27
+ } from "./chunk-HBCCZQBE.mjs";
28
28
  import {
29
29
  AnthropicAdapter,
30
30
  EmptyAdapter,
@@ -1,5 +1,5 @@
1
1
  export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-53d3fa48.js';
2
- export { e as CommonConfig, C as CopilotRequestContextProperties, k as CopilotRuntime, j as CopilotRuntimeConstructorParams, f as CopilotRuntimeLogger, i as CopilotRuntimeRequest, b as CreateCopilotRuntimeServerOptions, G as GraphQLContext, L as LogLevel, o as MCPClient, p as MCPEndpointConfig, M as MCPTool, a as addCustomHeaderPlugin, d as buildSchema, s as convertMCPToolsToActions, m as copilotKitEndpoint, c as createContext, h as createLogger, q as extractParametersFromSchema, l as flattenToolCallsNoDuplicates, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from '../shared-350db43f.js';
2
+ export { e as CommonConfig, C as CopilotRequestContextProperties, k as CopilotRuntime, j as CopilotRuntimeConstructorParams, f as CopilotRuntimeLogger, i as CopilotRuntimeRequest, b as CreateCopilotRuntimeServerOptions, G as GraphQLContext, L as LogLevel, o as MCPClient, p as MCPEndpointConfig, M as MCPTool, a as addCustomHeaderPlugin, d as buildSchema, s as convertMCPToolsToActions, m as copilotKitEndpoint, c as createContext, h as createLogger, q as extractParametersFromSchema, l as flattenToolCallsNoDuplicates, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from '../shared-32a46e93.js';
3
3
  export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint } from './integrations/index.js';
4
4
  export { copilotRuntimeNodeHttpEndpoint } from './integrations/node-http/index.js';
5
5
  export { copilotRuntimeNodeExpressEndpoint } from './integrations/node-express/index.js';
package/dist/lib/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.8.7",
47
+ version: "1.8.8-next.1",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -4377,11 +4377,13 @@ var import_rxjs2 = require("rxjs");
4377
4377
  var import_langgraph_sdk2 = require("@langchain/langgraph-sdk");
4378
4378
 
4379
4379
  // src/lib/runtime/mcp-tools-utils.ts
4380
- function extractParametersFromSchema(toolSchema) {
4381
- var _a, _b;
4380
+ function extractParametersFromSchema(toolOrSchema) {
4381
+ var _a;
4382
4382
  const parameters = [];
4383
- const properties = (_a = toolSchema == null ? void 0 : toolSchema.parameters) == null ? void 0 : _a.properties;
4384
- const requiredParams = new Set(((_b = toolSchema == null ? void 0 : toolSchema.parameters) == null ? void 0 : _b.required) || []);
4383
+ const schema = "schema" in (toolOrSchema || {}) ? toolOrSchema.schema : toolOrSchema;
4384
+ const toolParameters = (schema == null ? void 0 : schema.parameters) || ((_a = schema == null ? void 0 : schema.parameters) == null ? void 0 : _a.jsonSchema);
4385
+ const properties = toolParameters == null ? void 0 : toolParameters.properties;
4386
+ const requiredParams = new Set((toolParameters == null ? void 0 : toolParameters.required) || []);
4385
4387
  if (!properties) {
4386
4388
  return parameters;
4387
4389
  }
@@ -4404,7 +4406,7 @@ __name(extractParametersFromSchema, "extractParametersFromSchema");
4404
4406
  function convertMCPToolsToActions(mcpTools, mcpEndpoint) {
4405
4407
  const actions = [];
4406
4408
  for (const [toolName, tool] of Object.entries(mcpTools)) {
4407
- const parameters = extractParametersFromSchema(tool.schema);
4409
+ const parameters = extractParametersFromSchema(tool);
4408
4410
  const handler = /* @__PURE__ */ __name(async (params) => {
4409
4411
  try {
4410
4412
  const result = await tool.execute({
@@ -4442,7 +4444,7 @@ var CopilotRuntime = class {
4442
4444
  observability;
4443
4445
  availableAgents;
4444
4446
  // +++ MCP Properties +++
4445
- mcpEndpointsConfig;
4447
+ mcpServersConfig;
4446
4448
  mcpActionCache = /* @__PURE__ */ new Map();
4447
4449
  // --- MCP Properties ---
4448
4450
  // +++ MCP Client Factory +++
@@ -4465,14 +4467,14 @@ var CopilotRuntime = class {
4465
4467
  this.delegateAgentProcessingToServiceAdapter = (params == null ? void 0 : params.delegateAgentProcessingToServiceAdapter) || false;
4466
4468
  this.observability = params == null ? void 0 : params.observability_c;
4467
4469
  this.agents = (params == null ? void 0 : params.agents) ?? {};
4468
- this.mcpEndpointsConfig = params == null ? void 0 : params.mcpEndpoints;
4470
+ this.mcpServersConfig = params == null ? void 0 : params.mcpServers;
4469
4471
  this.createMCPClientImpl = params == null ? void 0 : params.createMCPClient;
4470
- if (this.mcpEndpointsConfig && this.mcpEndpointsConfig.length > 0 && !this.createMCPClientImpl) {
4472
+ if (this.mcpServersConfig && this.mcpServersConfig.length > 0 && !this.createMCPClientImpl) {
4471
4473
  throw new import_shared18.CopilotKitMisuseError({
4472
- message: "MCP Integration Error: `mcpEndpoints` were provided, but the `createMCPClient` function was not passed to the CopilotRuntime constructor. Please provide an implementation for `createMCPClient`."
4474
+ message: "MCP Integration Error: `mcpServers` were provided, but the `createMCPClient` function was not passed to the CopilotRuntime constructor. Please provide an implementation for `createMCPClient`."
4473
4475
  });
4474
4476
  }
4475
- 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))) {
4477
+ 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.mcpServersConfig) == null ? void 0 : _d.length))) {
4476
4478
  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.");
4477
4479
  }
4478
4480
  }
@@ -4482,7 +4484,11 @@ var CopilotRuntime = class {
4482
4484
  if (!mcpActionsForRequest || mcpActionsForRequest.length === 0) {
4483
4485
  return messages;
4484
4486
  }
4485
- const mcpToolInstructions = mcpActionsForRequest.map((action) => {
4487
+ const uniqueMcpTools = /* @__PURE__ */ new Map();
4488
+ mcpActionsForRequest.forEach((action) => {
4489
+ uniqueMcpTools.set(action.name, action);
4490
+ });
4491
+ const mcpToolInstructions = Array.from(uniqueMcpTools.values()).map((action) => {
4486
4492
  const paramsString = action.parameters && action.parameters.length > 0 ? ` Parameters: ${action.parameters.map((p) => `${p.name}${p.required ? "*" : ""}(${p.type})`).join(", ")}` : "";
4487
4493
  return `- ${action.name}:${paramsString} ${action.description || ""}`;
4488
4494
  }).join("\n");
@@ -5065,7 +5071,7 @@ please use an LLM adapter instead.`
5065
5071
  }
5066
5072
  }
5067
5073
  async getServerSideActions(request) {
5068
- var _a;
5074
+ var _a, _b;
5069
5075
  const { graphqlContext, messages: rawMessages, agentStates, url } = request;
5070
5076
  const inputMessages = convertGqlInputToMessages(rawMessages);
5071
5077
  const langserveFunctions = [];
@@ -5095,11 +5101,17 @@ please use an LLM adapter instead.`
5095
5101
  }) : this.actions;
5096
5102
  const requestSpecificMCPActions = [];
5097
5103
  if (this.createMCPClientImpl) {
5098
- const baseEndpoints = this.mcpEndpointsConfig || [];
5099
- const requestEndpoints = ((_a = graphqlContext.properties) == null ? void 0 : _a.mcpEndpoints) || [];
5104
+ const baseEndpoints = this.mcpServersConfig || [];
5105
+ const requestEndpoints = ((_a = graphqlContext.properties) == null ? void 0 : _a.mcpServers) || ((_b = graphqlContext.properties) == null ? void 0 : _b.mcpEndpoints) || [];
5100
5106
  const effectiveEndpointsMap = /* @__PURE__ */ new Map();
5101
5107
  [
5102
- ...baseEndpoints,
5108
+ ...baseEndpoints
5109
+ ].forEach((ep) => {
5110
+ if (ep && ep.endpoint) {
5111
+ effectiveEndpointsMap.set(ep.endpoint, ep);
5112
+ }
5113
+ });
5114
+ [
5103
5115
  ...requestEndpoints
5104
5116
  ].forEach((ep) => {
5105
5117
  if (ep && ep.endpoint) {
@@ -5113,12 +5125,10 @@ please use an LLM adapter instead.`
5113
5125
  if (!actionsForEndpoint) {
5114
5126
  let client = null;
5115
5127
  try {
5116
- console.log(`MCP: Cache miss. Fetching tools for endpoint: ${endpointUrl}`);
5117
5128
  client = await this.createMCPClientImpl(config2);
5118
5129
  const tools = await client.tools();
5119
5130
  actionsForEndpoint = convertMCPToolsToActions(tools, endpointUrl);
5120
5131
  this.mcpActionCache.set(endpointUrl, actionsForEndpoint);
5121
- console.log(`MCP: Fetched and cached ${actionsForEndpoint.length} tools for ${endpointUrl}`);
5122
5132
  } catch (error) {
5123
5133
  console.error(`MCP: Failed to fetch tools from endpoint ${endpointUrl}. Skipping. Error:`, error);
5124
5134
  actionsForEndpoint = [];