@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @copilotkit/runtime
2
2
 
3
+ ## 1.9.2-next.23
4
+
5
+ ### Patch Changes
6
+
7
+ - fc6b653: - Fix extract toolParameters in extractParametersFromSchema
8
+ - Ensures consistency in how parameters are passed to the execute function across the codebase.
9
+ - fc6b653: - Fix extract toolParameters in extractParametersFromSchema
10
+ - Fixed generateMcpToolInstructions to properly extract parameters from schema.parameters.properties
11
+ - fix: enhance MCP schema support for complex types and remove duplicate headers
12
+ - fc6b653: - Fix extract toolParameters in extractParametersFromSchema
13
+ - @copilotkit/shared@1.9.2-next.23
14
+
15
+ ## 1.9.2-next.22
16
+
17
+ ### Patch Changes
18
+
19
+ - @copilotkit/shared@1.9.2-next.22
20
+
3
21
  ## 1.9.2-next.21
4
22
 
5
23
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LangGraphEventTypes
3
- } from "./chunk-IBYPYIVX.mjs";
3
+ } from "./chunk-FIA5HRU2.mjs";
4
4
  import {
5
5
  __name
6
6
  } from "./chunk-FHD4JECV.mjs";
@@ -155,4 +155,4 @@ export {
155
155
  CustomEventNames,
156
156
  LangGraphAgent
157
157
  };
158
- //# sourceMappingURL=chunk-UPC6N4MV.mjs.map
158
+ //# sourceMappingURL=chunk-C6PCDSTD.mjs.map
@@ -40,7 +40,7 @@ var require_package = __commonJS({
40
40
  publishConfig: {
41
41
  access: "public"
42
42
  },
43
- version: "1.9.2-next.21",
43
+ version: "1.9.2-next.23",
44
44
  sideEffects: false,
45
45
  main: "./dist/index.js",
46
46
  module: "./dist/index.mjs",
@@ -2632,7 +2632,7 @@ function extractParametersFromSchema(toolOrSchema) {
2632
2632
  var _a;
2633
2633
  const parameters = [];
2634
2634
  const schema = "schema" in (toolOrSchema || {}) ? toolOrSchema.schema : toolOrSchema;
2635
- const toolParameters = (schema == null ? void 0 : schema.parameters) || ((_a = schema == null ? void 0 : schema.parameters) == null ? void 0 : _a.jsonSchema);
2635
+ const toolParameters = ((_a = schema == null ? void 0 : schema.parameters) == null ? void 0 : _a.jsonSchema) || (schema == null ? void 0 : schema.parameters);
2636
2636
  const properties = toolParameters == null ? void 0 : toolParameters.properties;
2637
2637
  const requiredParams = new Set((toolParameters == null ? void 0 : toolParameters.required) || []);
2638
2638
  if (!properties) {
@@ -2641,12 +2641,29 @@ function extractParametersFromSchema(toolOrSchema) {
2641
2641
  for (const paramName in properties) {
2642
2642
  if (Object.prototype.hasOwnProperty.call(properties, paramName)) {
2643
2643
  const paramDef = properties[paramName];
2644
+ let type = paramDef.type || "string";
2645
+ let description = paramDef.description || "";
2646
+ if (type === "array" && paramDef.items) {
2647
+ const itemType = paramDef.items.type || "object";
2648
+ if (itemType === "object" && paramDef.items.properties) {
2649
+ const itemProperties = Object.keys(paramDef.items.properties).join(", ");
2650
+ description = description + (description ? " " : "") + `Array of objects with properties: ${itemProperties}`;
2651
+ } else {
2652
+ type = `array<${itemType}>`;
2653
+ }
2654
+ }
2655
+ if (paramDef.enum && Array.isArray(paramDef.enum)) {
2656
+ const enumValues = paramDef.enum.join(" | ");
2657
+ description = description + (description ? " " : "") + `Allowed values: ${enumValues}`;
2658
+ }
2659
+ if (type === "object" && paramDef.properties) {
2660
+ const objectProperties = Object.keys(paramDef.properties).join(", ");
2661
+ description = description + (description ? " " : "") + `Object with properties: ${objectProperties}`;
2662
+ }
2644
2663
  parameters.push({
2645
2664
  name: paramName,
2646
- // Infer type, default to string. MCP schemas might have more complex types.
2647
- // This might need refinement based on common MCP schema practices.
2648
- type: paramDef.type || "string",
2649
- description: paramDef.description,
2665
+ type,
2666
+ description,
2650
2667
  required: requiredParams.has(paramName)
2651
2668
  });
2652
2669
  }
@@ -2660,9 +2677,7 @@ function convertMCPToolsToActions(mcpTools, mcpEndpoint) {
2660
2677
  const parameters = extractParametersFromSchema(tool);
2661
2678
  const handler = /* @__PURE__ */ __name(async (params) => {
2662
2679
  try {
2663
- const result = await tool.execute({
2664
- params
2665
- });
2680
+ const result = await tool.execute(params);
2666
2681
  return typeof result === "string" ? result : JSON.stringify(result);
2667
2682
  } catch (error) {
2668
2683
  console.error(`Error executing MCP tool '${toolName}' from endpoint ${mcpEndpoint}:`, error);
@@ -2688,17 +2703,38 @@ function generateMcpToolInstructions(toolsMap) {
2688
2703
  }
2689
2704
  const toolEntries = Object.entries(toolsMap);
2690
2705
  const toolsDoc = toolEntries.map(([name, tool]) => {
2706
+ var _a;
2691
2707
  let paramsDoc = " No parameters required";
2692
2708
  try {
2693
2709
  if (tool.schema && typeof tool.schema === "object") {
2694
2710
  const schema = tool.schema;
2695
- if (schema.properties) {
2696
- const requiredParams = schema.required || [];
2697
- const paramsList = Object.entries(schema.properties).map(([paramName, propSchema]) => {
2711
+ const toolParameters = ((_a = schema.parameters) == null ? void 0 : _a.jsonSchema) || schema.parameters;
2712
+ const properties = (toolParameters == null ? void 0 : toolParameters.properties) || schema.properties;
2713
+ const requiredParams = (toolParameters == null ? void 0 : toolParameters.required) || schema.required || [];
2714
+ if (properties) {
2715
+ const paramsList = Object.entries(properties).map(([paramName, propSchema]) => {
2698
2716
  const propDetails = propSchema;
2699
2717
  const requiredMark = requiredParams.includes(paramName) ? "*" : "";
2700
- const typeInfo = propDetails.type || "any";
2701
- const description = propDetails.description ? ` - ${propDetails.description}` : "";
2718
+ let typeInfo = propDetails.type || "any";
2719
+ let description = propDetails.description ? ` - ${propDetails.description}` : "";
2720
+ if (typeInfo === "array" && propDetails.items) {
2721
+ const itemType = propDetails.items.type || "object";
2722
+ if (itemType === "object" && propDetails.items.properties) {
2723
+ const itemProps = Object.keys(propDetails.items.properties).join(", ");
2724
+ typeInfo = `array<object>`;
2725
+ description = description + (description ? " " : " - ") + `Array of objects with properties: ${itemProps}`;
2726
+ } else {
2727
+ typeInfo = `array<${itemType}>`;
2728
+ }
2729
+ }
2730
+ if (propDetails.enum && Array.isArray(propDetails.enum)) {
2731
+ const enumValues = propDetails.enum.join(" | ");
2732
+ description = description + (description ? " " : " - ") + `Allowed values: ${enumValues}`;
2733
+ }
2734
+ if (typeInfo === "object" && propDetails.properties) {
2735
+ const objectProps = Object.keys(propDetails.properties).join(", ");
2736
+ description = description + (description ? " " : " - ") + `Object with properties: ${objectProps}`;
2737
+ }
2702
2738
  return ` - ${paramName}${requiredMark} (${typeInfo})${description}`;
2703
2739
  });
2704
2740
  if (paramsList.length > 0) {
@@ -2719,8 +2755,11 @@ ${toolsDoc}
2719
2755
  When using these tools:
2720
2756
  1. Only provide valid parameters according to their type requirements
2721
2757
  2. Required parameters are marked with *
2722
- 3. Format API calls correctly with the expected parameter structure
2723
- 4. Always check tool responses to determine your next action`;
2758
+ 3. For array parameters, provide data in the correct array format
2759
+ 4. For object parameters, include all required nested properties
2760
+ 5. For enum parameters, use only the allowed values listed
2761
+ 6. Format API calls correctly with the expected parameter structure
2762
+ 7. Always check tool responses to determine your next action`;
2724
2763
  }
2725
2764
  __name(generateMcpToolInstructions, "generateMcpToolInstructions");
2726
2765
 
@@ -2807,7 +2846,7 @@ var CopilotRuntime = class {
2807
2846
  if (!mcpToolInstructions) {
2808
2847
  return messages;
2809
2848
  }
2810
- 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.";
2849
+ const instructions = mcpToolInstructions + "\nUse them when appropriate to fulfill the user's request.";
2811
2850
  const systemMessageIndex = messages.findIndex((msg) => {
2812
2851
  var _a;
2813
2852
  return ((_a = msg.textMessage) == null ? void 0 : _a.role) === "system";
@@ -5824,4 +5863,4 @@ export {
5824
5863
  getCommonConfig,
5825
5864
  copilotRuntimeNodeHttpEndpoint
5826
5865
  };
5827
- //# sourceMappingURL=chunk-IBYPYIVX.mjs.map
5866
+ //# sourceMappingURL=chunk-FIA5HRU2.mjs.map