@copilotkitnext/core 1.53.1-next.2 → 1.54.0-next.3

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/dist/index.umd.js CHANGED
@@ -972,7 +972,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
972
972
  if (tool === null || tool === void 0 ? void 0 : tool.handler) {
973
973
  let parsedArgs;
974
974
  try {
975
- parsedArgs = JSON.parse(toolCall.function.arguments);
975
+ parsedArgs = ensureObjectArgs(JSON.parse(toolCall.function.arguments), toolCall.function.name);
976
976
  } catch (error) {
977
977
  const parseError = error instanceof Error ? error : new Error(String(error));
978
978
  errorMessage = parseError.message;
@@ -1060,7 +1060,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1060
1060
  if (wildcardTool === null || wildcardTool === void 0 ? void 0 : wildcardTool.handler) {
1061
1061
  let parsedArgs;
1062
1062
  try {
1063
- parsedArgs = JSON.parse(toolCall.function.arguments);
1063
+ parsedArgs = ensureObjectArgs(JSON.parse(toolCall.function.arguments), toolCall.function.name);
1064
1064
  } catch (error) {
1065
1065
  const parseError = error instanceof Error ? error : new Error(String(error));
1066
1066
  errorMessage = parseError.message;
@@ -1199,7 +1199,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1199
1199
  */
1200
1200
  function createToolSchema(tool) {
1201
1201
  if (!tool.parameters) return { ...EMPTY_TOOL_SCHEMA };
1202
- const rawSchema = (0, zod_to_json_schema.zodToJsonSchema)(tool.parameters, { $refStrategy: "none" });
1202
+ const rawSchema = (0, _copilotkitnext_shared.schemaToJsonSchema)(tool.parameters, { zodToJsonSchema: zod_to_json_schema.zodToJsonSchema });
1203
1203
  if (!rawSchema || typeof rawSchema !== "object") return { ...EMPTY_TOOL_SCHEMA };
1204
1204
  const { $schema, ...schema } = rawSchema;
1205
1205
  if (typeof schema.type !== "string") schema.type = "object";
@@ -1217,6 +1217,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1217
1217
  if (record.additionalProperties !== void 0) delete record.additionalProperties;
1218
1218
  for (const value of Object.values(record)) stripAdditionalProperties(value);
1219
1219
  }
1220
+ /**
1221
+ * Ensures parsed tool arguments are a plain object.
1222
+ * Throws for non-object values so the caller's catch block can emit
1223
+ * a structured TOOL_ARGUMENT_PARSE_FAILED error.
1224
+ *
1225
+ * @internal Exported for testing only.
1226
+ */
1227
+ function ensureObjectArgs(parsed, toolName) {
1228
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return parsed;
1229
+ throw new Error(`Tool arguments for ${toolName} parsed to non-object (${typeof parsed})`);
1230
+ }
1220
1231
 
1221
1232
  //#endregion
1222
1233
  //#region src/core/state-manager.ts
@@ -2018,5 +2029,6 @@ exports.StateManager = StateManager;
2018
2029
  exports.SuggestionEngine = SuggestionEngine;
2019
2030
  exports.ToolCallStatus = ToolCallStatus;
2020
2031
  exports.completePartialMarkdown = completePartialMarkdown;
2032
+ exports.ensureObjectArgs = ensureObjectArgs;
2021
2033
  });
2022
2034
  //# sourceMappingURL=index.umd.js.map