@copilotkit/runtime 1.9.2-next.21 → 1.9.2-next.23

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 (41) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-UPC6N4MV.mjs → chunk-C6PCDSTD.mjs} +2 -2
  3. package/dist/{chunk-IBYPYIVX.mjs → chunk-FIA5HRU2.mjs} +57 -18
  4. package/dist/chunk-FIA5HRU2.mjs.map +1 -0
  5. package/dist/{chunk-IXK4UOV6.mjs → chunk-HZW6X63M.mjs} +2 -2
  6. package/dist/{chunk-P3HORCYJ.mjs → chunk-LYXJJDV3.mjs} +2 -2
  7. package/dist/{chunk-47L6Z7PJ.mjs → chunk-ZQUGWRVU.mjs} +2 -2
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +56 -17
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +5 -5
  12. package/dist/lib/index.d.ts +1 -1
  13. package/dist/lib/index.js +56 -17
  14. package/dist/lib/index.js.map +1 -1
  15. package/dist/lib/index.mjs +5 -5
  16. package/dist/lib/integrations/index.d.ts +2 -2
  17. package/dist/lib/integrations/index.js +1 -1
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +4 -4
  20. package/dist/lib/integrations/nest/index.d.ts +1 -1
  21. package/dist/lib/integrations/nest/index.js +1 -1
  22. package/dist/lib/integrations/nest/index.js.map +1 -1
  23. package/dist/lib/integrations/nest/index.mjs +2 -2
  24. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  25. package/dist/lib/integrations/node-express/index.js +1 -1
  26. package/dist/lib/integrations/node-express/index.js.map +1 -1
  27. package/dist/lib/integrations/node-express/index.mjs +2 -2
  28. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  29. package/dist/lib/integrations/node-http/index.js +1 -1
  30. package/dist/lib/integrations/node-http/index.js.map +1 -1
  31. package/dist/lib/integrations/node-http/index.mjs +1 -1
  32. package/dist/{shared-41d4988d.d.ts → shared-6b6dbf8b.d.ts} +1 -3
  33. package/package.json +2 -2
  34. package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +464 -0
  35. package/src/lib/runtime/copilot-runtime.ts +1 -3
  36. package/src/lib/runtime/mcp-tools-utils.ts +84 -18
  37. package/dist/chunk-IBYPYIVX.mjs.map +0 -1
  38. /package/dist/{chunk-UPC6N4MV.mjs.map → chunk-C6PCDSTD.mjs.map} +0 -0
  39. /package/dist/{chunk-IXK4UOV6.mjs.map → chunk-HZW6X63M.mjs.map} +0 -0
  40. /package/dist/{chunk-P3HORCYJ.mjs.map → chunk-LYXJJDV3.mjs.map} +0 -0
  41. /package/dist/{chunk-47L6Z7PJ.mjs.map → chunk-ZQUGWRVU.mjs.map} +0 -0
@@ -2,7 +2,7 @@ import {
2
2
  getCommonConfig,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-IBYPYIVX.mjs";
5
+ } from "./chunk-FIA5HRU2.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-IXK4UOV6.mjs.map
80
+ //# sourceMappingURL=chunk-HZW6X63M.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-IBYPYIVX.mjs";
5
+ } from "./chunk-FIA5HRU2.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -22,4 +22,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
22
22
  export {
23
23
  copilotRuntimeNestEndpoint
24
24
  };
25
- //# sourceMappingURL=chunk-P3HORCYJ.mjs.map
25
+ //# sourceMappingURL=chunk-LYXJJDV3.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-IBYPYIVX.mjs";
5
+ } from "./chunk-FIA5HRU2.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-47L6Z7PJ.mjs.map
25
+ //# sourceMappingURL=chunk-ZQUGWRVU.mjs.map
package/dist/index.d.ts CHANGED
@@ -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-098f97f6.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, t as generateMcpToolInstructions, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from './shared-41d4988d.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, t as generateMcpToolInstructions, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from './shared-6b6dbf8b.js';
3
3
  export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint } from './lib/integrations/index.js';
4
4
  export { copilotRuntimeNodeHttpEndpoint } from './lib/integrations/node-http/index.js';
5
5
  export { copilotRuntimeNodeExpressEndpoint } from './lib/integrations/node-express/index.js';
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.9.2-next.21",
47
+ version: "1.9.2-next.23",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -4603,7 +4603,7 @@ function extractParametersFromSchema(toolOrSchema) {
4603
4603
  var _a;
4604
4604
  const parameters = [];
4605
4605
  const schema = "schema" in (toolOrSchema || {}) ? toolOrSchema.schema : toolOrSchema;
4606
- const toolParameters = (schema == null ? void 0 : schema.parameters) || ((_a = schema == null ? void 0 : schema.parameters) == null ? void 0 : _a.jsonSchema);
4606
+ const toolParameters = ((_a = schema == null ? void 0 : schema.parameters) == null ? void 0 : _a.jsonSchema) || (schema == null ? void 0 : schema.parameters);
4607
4607
  const properties = toolParameters == null ? void 0 : toolParameters.properties;
4608
4608
  const requiredParams = new Set((toolParameters == null ? void 0 : toolParameters.required) || []);
4609
4609
  if (!properties) {
@@ -4612,12 +4612,29 @@ function extractParametersFromSchema(toolOrSchema) {
4612
4612
  for (const paramName in properties) {
4613
4613
  if (Object.prototype.hasOwnProperty.call(properties, paramName)) {
4614
4614
  const paramDef = properties[paramName];
4615
+ let type = paramDef.type || "string";
4616
+ let description = paramDef.description || "";
4617
+ if (type === "array" && paramDef.items) {
4618
+ const itemType = paramDef.items.type || "object";
4619
+ if (itemType === "object" && paramDef.items.properties) {
4620
+ const itemProperties = Object.keys(paramDef.items.properties).join(", ");
4621
+ description = description + (description ? " " : "") + `Array of objects with properties: ${itemProperties}`;
4622
+ } else {
4623
+ type = `array<${itemType}>`;
4624
+ }
4625
+ }
4626
+ if (paramDef.enum && Array.isArray(paramDef.enum)) {
4627
+ const enumValues = paramDef.enum.join(" | ");
4628
+ description = description + (description ? " " : "") + `Allowed values: ${enumValues}`;
4629
+ }
4630
+ if (type === "object" && paramDef.properties) {
4631
+ const objectProperties = Object.keys(paramDef.properties).join(", ");
4632
+ description = description + (description ? " " : "") + `Object with properties: ${objectProperties}`;
4633
+ }
4615
4634
  parameters.push({
4616
4635
  name: paramName,
4617
- // Infer type, default to string. MCP schemas might have more complex types.
4618
- // This might need refinement based on common MCP schema practices.
4619
- type: paramDef.type || "string",
4620
- description: paramDef.description,
4636
+ type,
4637
+ description,
4621
4638
  required: requiredParams.has(paramName)
4622
4639
  });
4623
4640
  }
@@ -4631,9 +4648,7 @@ function convertMCPToolsToActions(mcpTools, mcpEndpoint) {
4631
4648
  const parameters = extractParametersFromSchema(tool);
4632
4649
  const handler = /* @__PURE__ */ __name(async (params) => {
4633
4650
  try {
4634
- const result = await tool.execute({
4635
- params
4636
- });
4651
+ const result = await tool.execute(params);
4637
4652
  return typeof result === "string" ? result : JSON.stringify(result);
4638
4653
  } catch (error) {
4639
4654
  console.error(`Error executing MCP tool '${toolName}' from endpoint ${mcpEndpoint}:`, error);
@@ -4659,17 +4674,38 @@ function generateMcpToolInstructions(toolsMap) {
4659
4674
  }
4660
4675
  const toolEntries = Object.entries(toolsMap);
4661
4676
  const toolsDoc = toolEntries.map(([name, tool]) => {
4677
+ var _a;
4662
4678
  let paramsDoc = " No parameters required";
4663
4679
  try {
4664
4680
  if (tool.schema && typeof tool.schema === "object") {
4665
4681
  const schema = tool.schema;
4666
- if (schema.properties) {
4667
- const requiredParams = schema.required || [];
4668
- const paramsList = Object.entries(schema.properties).map(([paramName, propSchema]) => {
4682
+ const toolParameters = ((_a = schema.parameters) == null ? void 0 : _a.jsonSchema) || schema.parameters;
4683
+ const properties = (toolParameters == null ? void 0 : toolParameters.properties) || schema.properties;
4684
+ const requiredParams = (toolParameters == null ? void 0 : toolParameters.required) || schema.required || [];
4685
+ if (properties) {
4686
+ const paramsList = Object.entries(properties).map(([paramName, propSchema]) => {
4669
4687
  const propDetails = propSchema;
4670
4688
  const requiredMark = requiredParams.includes(paramName) ? "*" : "";
4671
- const typeInfo = propDetails.type || "any";
4672
- const description = propDetails.description ? ` - ${propDetails.description}` : "";
4689
+ let typeInfo = propDetails.type || "any";
4690
+ let description = propDetails.description ? ` - ${propDetails.description}` : "";
4691
+ if (typeInfo === "array" && propDetails.items) {
4692
+ const itemType = propDetails.items.type || "object";
4693
+ if (itemType === "object" && propDetails.items.properties) {
4694
+ const itemProps = Object.keys(propDetails.items.properties).join(", ");
4695
+ typeInfo = `array<object>`;
4696
+ description = description + (description ? " " : " - ") + `Array of objects with properties: ${itemProps}`;
4697
+ } else {
4698
+ typeInfo = `array<${itemType}>`;
4699
+ }
4700
+ }
4701
+ if (propDetails.enum && Array.isArray(propDetails.enum)) {
4702
+ const enumValues = propDetails.enum.join(" | ");
4703
+ description = description + (description ? " " : " - ") + `Allowed values: ${enumValues}`;
4704
+ }
4705
+ if (typeInfo === "object" && propDetails.properties) {
4706
+ const objectProps = Object.keys(propDetails.properties).join(", ");
4707
+ description = description + (description ? " " : " - ") + `Object with properties: ${objectProps}`;
4708
+ }
4673
4709
  return ` - ${paramName}${requiredMark} (${typeInfo})${description}`;
4674
4710
  });
4675
4711
  if (paramsList.length > 0) {
@@ -4690,8 +4726,11 @@ ${toolsDoc}
4690
4726
  When using these tools:
4691
4727
  1. Only provide valid parameters according to their type requirements
4692
4728
  2. Required parameters are marked with *
4693
- 3. Format API calls correctly with the expected parameter structure
4694
- 4. Always check tool responses to determine your next action`;
4729
+ 3. For array parameters, provide data in the correct array format
4730
+ 4. For object parameters, include all required nested properties
4731
+ 5. For enum parameters, use only the allowed values listed
4732
+ 6. Format API calls correctly with the expected parameter structure
4733
+ 7. Always check tool responses to determine your next action`;
4695
4734
  }
4696
4735
  __name(generateMcpToolInstructions, "generateMcpToolInstructions");
4697
4736
 
@@ -4778,7 +4817,7 @@ var CopilotRuntime = class {
4778
4817
  if (!mcpToolInstructions) {
4779
4818
  return messages;
4780
4819
  }
4781
- 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.";
4820
+ const instructions = mcpToolInstructions + "\nUse them when appropriate to fulfill the user's request.";
4782
4821
  const systemMessageIndex = messages.findIndex((msg) => {
4783
4822
  var _a;
4784
4823
  return ((_a = msg.textMessage) == null ? void 0 : _a.role) === "system";