@tambo-ai/react 0.66.0 → 0.66.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.
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,aAAa,EACb,eAAe,EACf,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAYrC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAOvE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,EAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GACjC,WAAW,GAAG,SAAS,CAYzB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,SAAS,GAAG,uBAAuB,GACxC,IAAI,IAAI,SAAS,CAEnB;AA0DD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,2BAA2B,GACtC,MAAM,SAAS,GAAG,uBAAuB,KACxC,aAAa,EAmDf,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,aAAa,EACb,eAAe,EACf,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAYrC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAOvE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,EAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GACjC,WAAW,GAAG,SAAS,CAYzB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,SAAS,GAAG,uBAAuB,GACxC,IAAI,IAAI,SAAS,CAEnB;AAsDD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,2BAA2B,GACtC,MAAM,SAAS,GAAG,uBAAuB,KACxC,aAAa,EAmDf,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,CAAC"}
@@ -85,9 +85,6 @@ function hasInputSchema(tool) {
85
85
  * @returns The input schema (Standard Schema or JSON Schema), or undefined if not toolSchema
86
86
  */
87
87
  function getArgsFromToolSchema(tool) {
88
- if (!("toolSchema" in tool) || !tool.toolSchema) {
89
- return undefined;
90
- }
91
88
  if ((0, json_schema_1.looksLikeJSONSchema)(tool.toolSchema)) {
92
89
  return tool.toolSchema;
93
90
  }
@@ -163,19 +160,19 @@ const getParametersFromToolSchema = (tool) => {
163
160
  return [];
164
161
  }
165
162
  // Convert to JSON Schema if needed
166
- // For toolSchema, the args are typically a Zod tuple from z.function().args(...)
167
- // We use direct Zod conversion to ensure proper tuple handling
168
163
  let jsonSchema;
169
- if ((0, json_schema_1.looksLikeJSONSchema)(argsSchema)) {
170
- jsonSchema = argsSchema;
171
- }
172
- else if ((0, zod_1.isZodSchema)(argsSchema)) {
173
- // Use direct Zod conversion for more reliable tuple handling
164
+ // zod 3 and 4 are both compatible with StandardSchema
165
+ if ((0, zod_1.isZodSchema)(argsSchema)) {
174
166
  jsonSchema = (0, zod_1.handleZodSchemaToJson)(argsSchema);
175
167
  }
176
168
  else if ((0, standard_schema_1.isStandardSchema)(argsSchema)) {
169
+ // uses @standard-community/standard-json for conversion
177
170
  jsonSchema = schemaToJsonSchema(argsSchema);
178
171
  }
172
+ else if ((0, json_schema_1.looksLikeJSONSchema)(argsSchema)) {
173
+ // already JSON Schema
174
+ jsonSchema = argsSchema;
175
+ }
179
176
  else {
180
177
  console.warn("Unknown toolSchema args type, returning empty parameters");
181
178
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AA2CH,gDAOC;AAQD,wDAeC;AAOD,wCAIC;AAlFD,qEAA6E;AAS7E,+CAIuB;AACvB,uDAAqD;AACrD,+BAA+E;AAE/E,uDAAuD;AACvD,IAAA,0BAAU,EAAC,KAAK,EAAE,2BAAqB,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,kBAAkB,CAAC,MAAuB;IACxD,uCAAuC;IACvC,IAAI,CAAC,IAAA,kCAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,4BAAY,CAAC,IAAI,CAAC,MAAM,CAAgB,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,MAA0C,EAC1C,OAAkC;IAElC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAC5B,IAAyC;IAEzC,OAAO,aAAa,IAAI,IAAI,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;A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AAI,IAAA,+BAAiB,EAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,IAAA,qCAAuB,EAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC7D,OAAO,gCAAgC,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IAED,4EAA4E;IAC5E,OAAO,gCAAgC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC;AArDW,QAAA,2BAA2B,+BAqDtC","sourcesContent":["/**\n * Schema utilities for working with Standard Schema, Zod, and JSON Schema.\n *\n * This module provides a unified interface for handling different schema types\n * used in Tambo components and tools. It uses Standard Schema (https://standardschema.dev/)\n * as the primary interface, which is implemented by Zod and other validation libraries.\n *\n * JSON Schema conversion is handled by `@standard-community/standard-json`, with:\n * - Zod 4: Uses Zod's native toJSONSchema\n * - Zod 3: Requires optional peer dependency 'zod-to-json-schema'\n * - Other vendors: Handled by standard-json's built-in converters\n * @module schema\n */\n\nimport { loadVendor, toJsonSchema } from \"@standard-community/standard-json\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport {\n ParameterSpec,\n SupportedSchema,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n getJsonSchemaTupleItems,\n isJsonSchemaTuple,\n looksLikeJSONSchema,\n} from \"./json-schema\";\nimport { isStandardSchema } from \"./standard-schema\";\nimport { getZodFunctionArgs, handleZodSchemaToJson, isZodSchema } from \"./zod\";\n\n// Register the Zod vendor converter with standard-json\nloadVendor(\"zod\", handleZodSchemaToJson);\n\n/**\n * Converts a schema (Standard Schema or JSON Schema) to a JSON Schema object.\n *\n * If the schema is already a JSON Schema, it is returned as-is.\n * For Standard Schema validators (Zod, Valibot, ArkType, etc.), uses\n * `@standard-community/standard-json` for conversion.\n * @param schema - The schema to convert\n * @returns The JSON Schema representation\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * // Convert a Zod schema\n * const zodSchema = z.object({ name: z.string() });\n * const jsonSchema = schemaToJsonSchema(zodSchema);\n *\n * // Pass through a JSON Schema\n * const existingJsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * schemaToJsonSchema(existingJsonSchema); // returns the same object\n * ```\n */\nexport function schemaToJsonSchema(schema: SupportedSchema): JSONSchema7 {\n // Already a JSON Schema - return as-is\n if (!isStandardSchema(schema)) {\n return schema;\n }\n\n return toJsonSchema.sync(schema) as JSONSchema7;\n}\n\n/**\n * Safely converts a schema to JSON Schema, returning undefined for invalid inputs.\n * @param schema - The schema to convert (may be undefined)\n * @param onError - Optional callback invoked on conversion error\n * @returns The JSON Schema representation, or undefined if conversion fails\n */\nexport function safeSchemaToJsonSchema(\n schema: SupportedSchema | undefined | null,\n onError?: (error: unknown) => void,\n): JSONSchema7 | undefined {\n if (!schema) {\n return undefined;\n }\n\n try {\n return schemaToJsonSchema(schema);\n } catch (error) {\n console.error(\"Error converting schema to JSON Schema:\", error);\n onError?.(error);\n return undefined;\n }\n}\n\n/**\n * Checks if a tool uses the new inputSchema interface (vs deprecated toolSchema).\n * @param tool - The Tambo tool to check\n * @returns True if the tool uses inputSchema\n */\nexport function hasInputSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): tool is TamboTool {\n return \"inputSchema\" in tool && tool.inputSchema != null;\n}\n\n/**\n * Retrieves the input schema for a Tambo tool using the deprecated toolSchema.\n * For toolSchema, this extracts the args from the Zod function schema.\n * @param tool - The Tambo tool (potentially with toolSchema)\n * @returns The input schema (Standard Schema or JSON Schema), or undefined if not toolSchema\n */\nfunction getArgsFromToolSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): StandardSchemaV1 | JSONSchema7 | undefined {\n if (!(\"toolSchema\" in tool) || !tool.toolSchema) {\n return undefined;\n }\n\n if (looksLikeJSONSchema(tool.toolSchema)) {\n return tool.toolSchema;\n }\n\n return getZodFunctionArgs(tool.toolSchema);\n}\n\n/**\n * Extracts parameter specifications from JSON Schema tuple items.\n * Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).\n * This is library-agnostic - works with Zod, Valibot, ArkType, etc.\n * @param tupleItems - The array of JSON Schema items\n * @returns An array of parameter specifications\n */\nfunction extractParamsFromJsonSchemaTuple(\n tupleItems: JSONSchema7[],\n): ParameterSpec[] {\n return tupleItems.map((item, index) => ({\n name: `param${index + 1}`,\n type: typeof item.type === \"string\" ? item.type : \"object\",\n description: item.description ?? \"\",\n isRequired: true, // tuple items are positional\n schema: item,\n }));\n}\n\n/**\n * Creates a single parameter spec from an input schema.\n * Used for the new inputSchema interface where the schema represents\n * the shape of the single object argument to the tool function.\n * @param schema - The input schema (JSON Schema)\n * @returns A single parameter specification\n */\nfunction createInputParameter(schema: JSONSchema7): ParameterSpec {\n return {\n name: \"input\",\n type: typeof schema.type === \"string\" ? schema.type : \"object\",\n description: schema.description ?? \"\",\n isRequired: true,\n schema,\n };\n}\n\n/**\n * Extracts parameter specifications from a tool schema.\n *\n * For tools with **inputSchema** (new interface):\n * - Returns a single parameter named \"input\" representing the object schema\n * - The inputSchema defines the shape of the single object argument\n *\n * For tools with **toolSchema** (deprecated):\n * - Extracts positional parameters from tuple/function args\n * - Returns params named \"param1\", \"param2\", etc.\n * @param tool - The tool containing the schema\n * @returns An array of parameter specifications\n */\nexport const getParametersFromToolSchema = (\n tool: TamboTool | TamboToolWithToolSchema,\n): ParameterSpec[] => {\n // New interface: inputSchema represents the single object argument\n if (hasInputSchema(tool)) {\n const schema = tool.inputSchema;\n\n // Convert to JSON Schema if needed\n let jsonSchema: JSONSchema7;\n if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else if (isStandardSchema(schema)) {\n jsonSchema = schemaToJsonSchema(schema);\n } else {\n console.warn(\"Unknown inputSchema type, returning empty parameters\");\n return [];\n }\n\n return [createInputParameter(jsonSchema)];\n }\n\n // Deprecated interface: toolSchema with positional tuple args\n const argsSchema = getArgsFromToolSchema(tool);\n\n if (!argsSchema) {\n console.warn(\"No toolSchema found, returning empty parameters\");\n return [];\n }\n\n // Convert to JSON Schema if needed\n // For toolSchema, the args are typically a Zod tuple from z.function().args(...)\n // We use direct Zod conversion to ensure proper tuple handling\n let jsonSchema: JSONSchema7;\n if (looksLikeJSONSchema(argsSchema)) {\n jsonSchema = argsSchema;\n } else if (isZodSchema(argsSchema)) {\n // Use direct Zod conversion for more reliable tuple handling\n jsonSchema = handleZodSchemaToJson(argsSchema) as JSONSchema7;\n } else if (isStandardSchema(argsSchema)) {\n jsonSchema = schemaToJsonSchema(argsSchema);\n } else {\n console.warn(\"Unknown toolSchema args type, returning empty parameters\");\n return [];\n }\n\n // Extract tuple items for positional params\n if (isJsonSchemaTuple(jsonSchema)) {\n const tupleItems = getJsonSchemaTupleItems(jsonSchema) ?? [];\n return extractParamsFromJsonSchemaTuple(tupleItems);\n }\n\n // Fallback: wrap as single param (shouldn't normally happen for toolSchema)\n return extractParamsFromJsonSchemaTuple([jsonSchema]);\n};\n\nexport type { SupportedSchema };\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AA2CH,gDAOC;AAQD,wDAeC;AAOD,wCAIC;AAlFD,qEAA6E;AAS7E,+CAIuB;AACvB,uDAAqD;AACrD,+BAA+E;AAE/E,uDAAuD;AACvD,IAAA,0BAAU,EAAC,KAAK,EAAE,2BAAqB,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,kBAAkB,CAAC,MAAuB;IACxD,uCAAuC;IACvC,IAAI,CAAC,IAAA,kCAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,4BAAY,CAAC,IAAI,CAAC,MAAM,CAAgB,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,MAA0C,EAC1C,OAAkC;IAElC,IAAI,CAAC,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CAAC,EAAE,CAAC;QACxC,wDAAwD;QACxD,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;SAAM,IAAI,IAAA,iCAAmB,EAAC,UAAU,CAAC,EAAE,CAAC;QAC3C,sBAAsB;QACtB,UAAU,GAAG,UAAU,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,0DAA0D,CAAC,CAAC;QACzE,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,4CAA4C;IAC5C,IAAI,IAAA,+BAAiB,EAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,IAAA,qCAAuB,EAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC7D,OAAO,gCAAgC,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IAED,4EAA4E;IAC5E,OAAO,gCAAgC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC;AArDW,QAAA,2BAA2B,+BAqDtC","sourcesContent":["/**\n * Schema utilities for working with Standard Schema, Zod, and JSON Schema.\n *\n * This module provides a unified interface for handling different schema types\n * used in Tambo components and tools. It uses Standard Schema (https://standardschema.dev/)\n * as the primary interface, which is implemented by Zod and other validation libraries.\n *\n * JSON Schema conversion is handled by `@standard-community/standard-json`, with:\n * - Zod 4: Uses Zod's native toJSONSchema\n * - Zod 3: Requires optional peer dependency 'zod-to-json-schema'\n * - Other vendors: Handled by standard-json's built-in converters\n * @module schema\n */\n\nimport { loadVendor, toJsonSchema } from \"@standard-community/standard-json\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport {\n ParameterSpec,\n SupportedSchema,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n getJsonSchemaTupleItems,\n isJsonSchemaTuple,\n looksLikeJSONSchema,\n} from \"./json-schema\";\nimport { isStandardSchema } from \"./standard-schema\";\nimport { getZodFunctionArgs, handleZodSchemaToJson, isZodSchema } from \"./zod\";\n\n// Register the Zod vendor converter with standard-json\nloadVendor(\"zod\", handleZodSchemaToJson);\n\n/**\n * Converts a schema (Standard Schema or JSON Schema) to a JSON Schema object.\n *\n * If the schema is already a JSON Schema, it is returned as-is.\n * For Standard Schema validators (Zod, Valibot, ArkType, etc.), uses\n * `@standard-community/standard-json` for conversion.\n * @param schema - The schema to convert\n * @returns The JSON Schema representation\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * // Convert a Zod schema\n * const zodSchema = z.object({ name: z.string() });\n * const jsonSchema = schemaToJsonSchema(zodSchema);\n *\n * // Pass through a JSON Schema\n * const existingJsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * schemaToJsonSchema(existingJsonSchema); // returns the same object\n * ```\n */\nexport function schemaToJsonSchema(schema: SupportedSchema): JSONSchema7 {\n // Already a JSON Schema - return as-is\n if (!isStandardSchema(schema)) {\n return schema;\n }\n\n return toJsonSchema.sync(schema) as JSONSchema7;\n}\n\n/**\n * Safely converts a schema to JSON Schema, returning undefined for invalid inputs.\n * @param schema - The schema to convert (may be undefined)\n * @param onError - Optional callback invoked on conversion error\n * @returns The JSON Schema representation, or undefined if conversion fails\n */\nexport function safeSchemaToJsonSchema(\n schema: SupportedSchema | undefined | null,\n onError?: (error: unknown) => void,\n): JSONSchema7 | undefined {\n if (!schema) {\n return undefined;\n }\n\n try {\n return schemaToJsonSchema(schema);\n } catch (error) {\n console.error(\"Error converting schema to JSON Schema:\", error);\n onError?.(error);\n return undefined;\n }\n}\n\n/**\n * Checks if a tool uses the new inputSchema interface (vs deprecated toolSchema).\n * @param tool - The Tambo tool to check\n * @returns True if the tool uses inputSchema\n */\nexport function hasInputSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): tool is TamboTool {\n return \"inputSchema\" in tool && tool.inputSchema != null;\n}\n\n/**\n * Retrieves the input schema for a Tambo tool using the deprecated toolSchema.\n * For toolSchema, this extracts the args from the Zod function schema.\n * @param tool - The Tambo tool (potentially with toolSchema)\n * @returns The input schema (Standard Schema or JSON Schema), or undefined if not toolSchema\n */\nfunction getArgsFromToolSchema(\n tool: TamboToolWithToolSchema,\n): StandardSchemaV1 | JSONSchema7 | undefined {\n if (looksLikeJSONSchema(tool.toolSchema)) {\n return tool.toolSchema;\n }\n\n return getZodFunctionArgs(tool.toolSchema);\n}\n\n/**\n * Extracts parameter specifications from JSON Schema tuple items.\n * Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).\n * This is library-agnostic - works with Zod, Valibot, ArkType, etc.\n * @param tupleItems - The array of JSON Schema items\n * @returns An array of parameter specifications\n */\nfunction extractParamsFromJsonSchemaTuple(\n tupleItems: JSONSchema7[],\n): ParameterSpec[] {\n return tupleItems.map((item, index) => ({\n name: `param${index + 1}`,\n type: typeof item.type === \"string\" ? item.type : \"object\",\n description: item.description ?? \"\",\n isRequired: true, // tuple items are positional\n schema: item,\n }));\n}\n\n/**\n * Creates a single parameter spec from an input schema.\n * Used for the new inputSchema interface where the schema represents\n * the shape of the single object argument to the tool function.\n * @param schema - The input schema (JSON Schema)\n * @returns A single parameter specification\n */\nfunction createInputParameter(schema: JSONSchema7): ParameterSpec {\n return {\n name: \"input\",\n type: typeof schema.type === \"string\" ? schema.type : \"object\",\n description: schema.description ?? \"\",\n isRequired: true,\n schema,\n };\n}\n\n/**\n * Extracts parameter specifications from a tool schema.\n *\n * For tools with **inputSchema** (new interface):\n * - Returns a single parameter named \"input\" representing the object schema\n * - The inputSchema defines the shape of the single object argument\n *\n * For tools with **toolSchema** (deprecated):\n * - Extracts positional parameters from tuple/function args\n * - Returns params named \"param1\", \"param2\", etc.\n * @param tool - The tool containing the schema\n * @returns An array of parameter specifications\n */\nexport const getParametersFromToolSchema = (\n tool: TamboTool | TamboToolWithToolSchema,\n): ParameterSpec[] => {\n // New interface: inputSchema represents the single object argument\n if (hasInputSchema(tool)) {\n const schema = tool.inputSchema;\n\n // Convert to JSON Schema if needed\n let jsonSchema: JSONSchema7;\n if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else if (isStandardSchema(schema)) {\n jsonSchema = schemaToJsonSchema(schema);\n } else {\n console.warn(\"Unknown inputSchema type, returning empty parameters\");\n return [];\n }\n\n return [createInputParameter(jsonSchema)];\n }\n\n // Deprecated interface: toolSchema with positional tuple args\n const argsSchema = getArgsFromToolSchema(tool);\n\n if (!argsSchema) {\n console.warn(\"No toolSchema found, returning empty parameters\");\n return [];\n }\n\n // Convert to JSON Schema if needed\n let jsonSchema: JSONSchema7;\n // zod 3 and 4 are both compatible with StandardSchema\n if (isZodSchema(argsSchema)) {\n jsonSchema = handleZodSchemaToJson(argsSchema);\n } else if (isStandardSchema(argsSchema)) {\n // uses @standard-community/standard-json for conversion\n jsonSchema = schemaToJsonSchema(argsSchema);\n } else if (looksLikeJSONSchema(argsSchema)) {\n // already JSON Schema\n jsonSchema = argsSchema;\n } else {\n console.warn(\"Unknown toolSchema args type, returning empty parameters\");\n return [];\n }\n\n // Extract tuple items for positional params\n if (isJsonSchemaTuple(jsonSchema)) {\n const tupleItems = getJsonSchemaTupleItems(jsonSchema) ?? [];\n return extractParamsFromJsonSchemaTuple(tupleItems);\n }\n\n // Fallback: wrap as single param (shouldn't normally happen for toolSchema)\n return extractParamsFromJsonSchemaTuple([jsonSchema]);\n};\n\nexport type { SupportedSchema };\n"]}
@@ -15,11 +15,11 @@ export declare function isZod4FunctionSchema(schema: unknown): schema is $ZodFun
15
15
  */
16
16
  export declare function isZodFunctionSchema(schema: unknown): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> | $ZodFunction<import("zod/v4/core").$ZodFunctionArgs, import("zod/v4/core").$ZodFunctionOut>;
17
17
  /**
18
- * Extracts the args schema from a Zod 3 function schema.
19
- * @param schema - The Zod 3 function schema
20
- * @returns The args schema, or undefined if not a Zod 3 function schema
18
+ * Extracts the args schema from a Zod function schema.
19
+ * @param schema - The Zod function schema
20
+ * @returns The args schema, or undefined if not a Zod function schema
21
21
  */
22
- export declare function getZodFunctionArgs(schema: unknown): any;
22
+ export declare function getZodFunctionArgs(schema: unknown): import("zod/v4/core").$ZodFunctionArgs | ZodTuple<ZodTupleItems, any>;
23
23
  /**
24
24
  * Extracts the return schema from a Zod 3 or Zod 4 function schema.
25
25
  * @param schema - The Zod function schema
@@ -1 +1 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,OAAO,EACP,UAAU,EACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,QAAQ,EAET,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAMjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAO5E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,iKAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,OAWjD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAWpD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAkBpD;AAaD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE/D;AAUD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,QAAQ,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,GACd,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAEnE"}
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,OAAO,EACP,UAAU,EACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,QAAQ,EAET,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAMjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAoB5E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,iKAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,yEAWjD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAWpD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAkBpD;AAaD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE/D;AAUD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,QAAQ,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,GACd,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAEnE"}
@@ -27,8 +27,20 @@ function isZod4FunctionSchema(schema) {
27
27
  if (!isZod4Schema(schema)) {
28
28
  return false;
29
29
  }
30
- // @ts-expect-error -- Error in Zod types for v3 vs v4
31
- return "def" in schema && schema._zod.def.type === "function";
30
+ // $ZodFunctions in zod 4.0 most certainly do have .def.type === "function"
31
+ // but the type definitions do not reflect this because $ZodFunction does not
32
+ // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include
33
+ // the types for 4.1 yet (and might not ever).
34
+ // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48
35
+ if ("def" in schema && typeof schema.def !== "object" && schema.def) {
36
+ if (schema.def?.type === "function") {
37
+ return true;
38
+ }
39
+ }
40
+ // We're casting as string here because zod 4.0 types don't include "function"
41
+ // literal in the union for `_zod.def.type`. The optional chaining is because
42
+ // _zod does not exist on zod 4 objects from zod 3.
43
+ return schema._zod?.def?.type === "function";
32
44
  }
33
45
  /**
34
46
  * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).
@@ -39,17 +51,17 @@ function isZodFunctionSchema(schema) {
39
51
  return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);
40
52
  }
41
53
  /**
42
- * Extracts the args schema from a Zod 3 function schema.
43
- * @param schema - The Zod 3 function schema
44
- * @returns The args schema, or undefined if not a Zod 3 function schema
54
+ * Extracts the args schema from a Zod function schema.
55
+ * @param schema - The Zod function schema
56
+ * @returns The args schema, or undefined if not a Zod function schema
45
57
  */
46
58
  function getZodFunctionArgs(schema) {
47
59
  if (isZod3FunctionSchema(schema)) {
48
60
  return schema._def.args;
49
61
  }
50
62
  if (isZod4FunctionSchema(schema)) {
51
- // @ts-expect-error -- Error in Zod types for v3 vs v4
52
- return schema._zod.def.input;
63
+ // @ts-expect-error -- Error in Zod types for v3 vs v4.0
64
+ return schema?.def?.input ?? schema._zod?.def?.input;
53
65
  }
54
66
  throw new Error("Unable to determine parameters from zod function schema");
55
67
  }
@@ -75,7 +87,7 @@ function getZodFunctionReturns(schema) {
75
87
  * @returns The JSON Schema representation
76
88
  */
77
89
  function handleZodSchemaToJson(schema) {
78
- // Detect Zod 4 by checking for def.type
90
+ // If Zod4 schema detected, use the toJSONSchema function from "zod/v4/core"
79
91
  if (isZod4Schema(schema))
80
92
  return (0, core_1.toJSONSchema)(schema);
81
93
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":";;AAiBA,oDAQC;AAKD,oDAOC;AAOD,kDAEC;AAOD,gDAWC;AAOD,sDAWC;AAQD,sDAkBC;AAkBD,oCAEC;AAeD,oCAEC;AAOD,kCAIC;AArJD,sCAIqB;AACrB,uDAAqC;AAErC;;GAEG;AACH,SAAgB,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,UAAU,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,MAAe;IAClD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,sDAAsD;IACtD,OAAO,KAAK,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,MAAe;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,MAAe;IAChD,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;QACjC,sDAAsD;QACtD,OAAO,MAAM,CAAC,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C;KACzB,CAAC;CACH,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAgB,YAAY,CAAC,MAAe;IAC1C,OAAO,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;AAClD,CAAC;AAED,MAAM,cAAc,GAAG,oBAAC,CAAC,MAAM,CAAC;IAC9B,GAAG,EAAE,oBAAC,CAAC,MAAM,EAAE;IACf,IAAI,EAAE,oBAAC,CAAC,WAAW,CAAC;QAClB,GAAG,EAAE,oBAAC,CAAC,WAAW,CAAC,EAAE,CAAC;KACvB,CAAC;IACF,WAAW,EAAE,oBAAC,CAAC,WAAW,CAAC,EAAE,CAAC;CAC/B,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAgB,YAAY,CAAC,MAAe;IAC1C,OAAO,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CACzB,MAAe;IAEf,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\nimport { z } from \"zodInternalAlias\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZod3Schema(schema)) {\n return false;\n }\n\n return \"typeName\" in schema._def && schema._def.typeName === \"ZodFunction\";\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return \"def\" in schema && schema._zod.def.type === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod 3 function schema.\n * @param schema - The Zod 3 function schema\n * @returns The args schema, or undefined if not a Zod 3 function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // Detect Zod 4 by checking for def.type\n if (isZod4Schema(schema)) return zod4ToJSONSchema(schema);\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema);\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n// Zod 3 schemas have _def with typeName and ~standard with vendor \"zod\"\n// Use looseObject to allow any _def shape (different for each type)\nconst zod3SchemaType = z.object({\n _def: z.looseObject({\n typeName: z.string().optional(),\n }),\n \"~standard\": z.looseObject({\n vendor: z.literal(\"zod\"),\n }),\n});\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return zod3SchemaType.safeParse(schema).success;\n}\n\nconst zod4SchemaType = z.object({\n def: z.object(),\n _zod: z.looseObject({\n def: z.looseObject({}),\n }),\n \"~standard\": z.looseObject({}),\n});\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return zod4SchemaType.safeParse(schema).success;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(\n schema: unknown,\n): ReturnType<typeof isZod3Schema> | ReturnType<typeof isZod4Schema> {\n return isZod3Schema(schema) || isZod4Schema(schema);\n}\n"]}
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":";;AAiBA,oDAQC;AAKD,oDAoBC;AAOD,kDAEC;AAOD,gDAWC;AAOD,sDAWC;AAQD,sDAkBC;AAkBD,oCAEC;AAeD,oCAEC;AAOD,kCAIC;AAlKD,sCAIqB;AACrB,uDAAqC;AAErC;;GAEG;AACH,SAAgB,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,UAAU,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CAAC;AAC7E,CAAC;AAED;;G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AAI,EAAE,oBAAC,CAAC,WAAW,CAAC;QAClB,GAAG,EAAE,oBAAC,CAAC,WAAW,CAAC,EAAE,CAAC;KACvB,CAAC;IACF,WAAW,EAAE,oBAAC,CAAC,WAAW,CAAC,EAAE,CAAC;CAC/B,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAgB,YAAY,CAAC,MAAe;IAC1C,OAAO,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CACzB,MAAe;IAEf,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\nimport { z } from \"zodInternalAlias\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZod3Schema(schema)) {\n return false;\n }\n\n return \"typeName\" in schema._def && schema._def.typeName === \"ZodFunction\";\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema)) return zod4ToJSONSchema(schema);\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema);\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n// Zod 3 schemas have _def with typeName and ~standard with vendor \"zod\"\n// Use looseObject to allow any _def shape (different for each type)\nconst zod3SchemaType = z.object({\n _def: z.looseObject({\n typeName: z.string().optional(),\n }),\n \"~standard\": z.looseObject({\n vendor: z.literal(\"zod\"),\n }),\n});\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return zod3SchemaType.safeParse(schema).success;\n}\n\nconst zod4SchemaType = z.object({\n def: z.object(),\n _zod: z.looseObject({\n def: z.looseObject({}),\n }),\n \"~standard\": z.looseObject({}),\n});\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return zod4SchemaType.safeParse(schema).success;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(\n schema: unknown,\n): ReturnType<typeof isZod3Schema> | ReturnType<typeof isZod4Schema> {\n return isZod3Schema(schema) || isZod4Schema(schema);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,aAAa,EACb,eAAe,EACf,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAYrC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,WA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function hasInputSchema(tool) {
79
79
  * @returns The input schema (Standard Schema or JSON Schema), or undefined if not toolSchema
80
80
  */
81
81
  function getArgsFromToolSchema(tool) {
82
- if (!("toolSchema" in tool) || !tool.toolSchema) {
83
- return undefined;
84
- }
85
82
  if (looksLikeJSONSchema(tool.toolSchema)) {
86
83
  return tool.toolSchema;
87
84
  }
@@ -157,19 +154,19 @@ export const getParametersFromToolSchema = (tool) => {
157
154
  return [];
158
155
  }
159
156
  // Convert to JSON Schema if needed
160
- // For toolSchema, the args are typically a Zod tuple from z.function().args(...)
161
- // We use direct Zod conversion to ensure proper tuple handling
162
157
  let jsonSchema;
163
- if (looksLikeJSONSchema(argsSchema)) {
164
- jsonSchema = argsSchema;
165
- }
166
- else if (isZodSchema(argsSchema)) {
167
- // Use direct Zod conversion for more reliable tuple handling
158
+ // zod 3 and 4 are both compatible with StandardSchema
159
+ if (isZodSchema(argsSchema)) {
168
160
  jsonSchema = handleZodSchemaToJson(argsSchema);
169
161
  }
170
162
  else if (isStandardSchema(argsSchema)) {
163
+ // uses @standard-community/standard-json for conversion
171
164
  jsonSchema = schemaToJsonSchema(argsSchema);
172
165
  }
166
+ else if (looksLikeJSONSchema(argsSchema)) {
167
+ // already JSON Schema
168
+ jsonSchema = argsSchema;
169
+ }
173
170
  else {
174
171
  console.warn("Unknown toolSchema args type, returning empty parameters");
175
172
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAS7E,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AA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;YACrE,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,8DAA8D;IAC9D,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAE/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QAChE,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,mCAAmC;IACnC,iFAAiF;IACjF,+DAA+D;IAC/D,IAAI,UAAuB,CAAC;IAC5B,IAAI,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC;QACpC,UAAU,GAAG,UAAU,CAAC;IAC1B,CAAC;SAAM,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,6DAA6D;QAC7D,UAAU,GAAG,qBAAqB,CAAC,UAAU,CAAgB,CAAC;IAChE,CAAC;SAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;QACxC,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,0DAA0D,CAAC,CAAC;QACzE,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,4CAA4C;IAC5C,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,uBAAuB,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC7D,OAAO,gCAAgC,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IAED,4EAA4E;IAC5E,OAAO,gCAAgC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC","sourcesContent":["/**\n * Schema utilities for working with Standard Schema, Zod, and JSON Schema.\n *\n * This module provides a unified interface for handling different schema types\n * used in Tambo components and tools. It uses Standard Schema (https://standardschema.dev/)\n * as the primary interface, which is implemented by Zod and other validation libraries.\n *\n * JSON Schema conversion is handled by `@standard-community/standard-json`, with:\n * - Zod 4: Uses Zod's native toJSONSchema\n * - Zod 3: Requires optional peer dependency 'zod-to-json-schema'\n * - Other vendors: Handled by standard-json's built-in converters\n * @module schema\n */\n\nimport { loadVendor, toJsonSchema } from \"@standard-community/standard-json\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport {\n ParameterSpec,\n SupportedSchema,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n getJsonSchemaTupleItems,\n isJsonSchemaTuple,\n looksLikeJSONSchema,\n} from \"./json-schema\";\nimport { isStandardSchema } from \"./standard-schema\";\nimport { getZodFunctionArgs, handleZodSchemaToJson, isZodSchema } from \"./zod\";\n\n// Register the Zod vendor converter with standard-json\nloadVendor(\"zod\", handleZodSchemaToJson);\n\n/**\n * Converts a schema (Standard Schema or JSON Schema) to a JSON Schema object.\n *\n * If the schema is already a JSON Schema, it is returned as-is.\n * For Standard Schema validators (Zod, Valibot, ArkType, etc.), uses\n * `@standard-community/standard-json` for conversion.\n * @param schema - The schema to convert\n * @returns The JSON Schema representation\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * // Convert a Zod schema\n * const zodSchema = z.object({ name: z.string() });\n * const jsonSchema = schemaToJsonSchema(zodSchema);\n *\n * // Pass through a JSON Schema\n * const existingJsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * schemaToJsonSchema(existingJsonSchema); // returns the same object\n * ```\n */\nexport function schemaToJsonSchema(schema: SupportedSchema): JSONSchema7 {\n // Already a JSON Schema - return as-is\n if (!isStandardSchema(schema)) {\n return schema;\n }\n\n return toJsonSchema.sync(schema) as JSONSchema7;\n}\n\n/**\n * Safely converts a schema to JSON Schema, returning undefined for invalid inputs.\n * @param schema - The schema to convert (may be undefined)\n * @param onError - Optional callback invoked on conversion error\n * @returns The JSON Schema representation, or undefined if conversion fails\n */\nexport function safeSchemaToJsonSchema(\n schema: SupportedSchema | undefined | null,\n onError?: (error: unknown) => void,\n): JSONSchema7 | undefined {\n if (!schema) {\n return undefined;\n }\n\n try {\n return schemaToJsonSchema(schema);\n } catch (error) {\n console.error(\"Error converting schema to JSON Schema:\", error);\n onError?.(error);\n return undefined;\n }\n}\n\n/**\n * Checks if a tool uses the new inputSchema interface (vs deprecated toolSchema).\n * @param tool - The Tambo tool to check\n * @returns True if the tool uses inputSchema\n */\nexport function hasInputSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): tool is TamboTool {\n return \"inputSchema\" in tool && tool.inputSchema != null;\n}\n\n/**\n * Retrieves the input schema for a Tambo tool using the deprecated toolSchema.\n * For toolSchema, this extracts the args from the Zod function schema.\n * @param tool - The Tambo tool (potentially with toolSchema)\n * @returns The input schema (Standard Schema or JSON Schema), or undefined if not toolSchema\n */\nfunction getArgsFromToolSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): StandardSchemaV1 | JSONSchema7 | undefined {\n if (!(\"toolSchema\" in tool) || !tool.toolSchema) {\n return undefined;\n }\n\n if (looksLikeJSONSchema(tool.toolSchema)) {\n return tool.toolSchema;\n }\n\n return getZodFunctionArgs(tool.toolSchema);\n}\n\n/**\n * Extracts parameter specifications from JSON Schema tuple items.\n * Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).\n * This is library-agnostic - works with Zod, Valibot, ArkType, etc.\n * @param tupleItems - The array of JSON Schema items\n * @returns An array of parameter specifications\n */\nfunction extractParamsFromJsonSchemaTuple(\n tupleItems: JSONSchema7[],\n): ParameterSpec[] {\n return tupleItems.map((item, index) => ({\n name: `param${index + 1}`,\n type: typeof item.type === \"string\" ? item.type : \"object\",\n description: item.description ?? \"\",\n isRequired: true, // tuple items are positional\n schema: item,\n }));\n}\n\n/**\n * Creates a single parameter spec from an input schema.\n * Used for the new inputSchema interface where the schema represents\n * the shape of the single object argument to the tool function.\n * @param schema - The input schema (JSON Schema)\n * @returns A single parameter specification\n */\nfunction createInputParameter(schema: JSONSchema7): ParameterSpec {\n return {\n name: \"input\",\n type: typeof schema.type === \"string\" ? schema.type : \"object\",\n description: schema.description ?? \"\",\n isRequired: true,\n schema,\n };\n}\n\n/**\n * Extracts parameter specifications from a tool schema.\n *\n * For tools with **inputSchema** (new interface):\n * - Returns a single parameter named \"input\" representing the object schema\n * - The inputSchema defines the shape of the single object argument\n *\n * For tools with **toolSchema** (deprecated):\n * - Extracts positional parameters from tuple/function args\n * - Returns params named \"param1\", \"param2\", etc.\n * @param tool - The tool containing the schema\n * @returns An array of parameter specifications\n */\nexport const getParametersFromToolSchema = (\n tool: TamboTool | TamboToolWithToolSchema,\n): ParameterSpec[] => {\n // New interface: inputSchema represents the single object argument\n if (hasInputSchema(tool)) {\n const schema = tool.inputSchema;\n\n // Convert to JSON Schema if needed\n let jsonSchema: JSONSchema7;\n if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else if (isStandardSchema(schema)) {\n jsonSchema = schemaToJsonSchema(schema);\n } else {\n console.warn(\"Unknown inputSchema type, returning empty parameters\");\n return [];\n }\n\n return [createInputParameter(jsonSchema)];\n }\n\n // Deprecated interface: toolSchema with positional tuple args\n const argsSchema = getArgsFromToolSchema(tool);\n\n if (!argsSchema) {\n console.warn(\"No toolSchema found, returning empty parameters\");\n return [];\n }\n\n // Convert to JSON Schema if needed\n // For toolSchema, the args are typically a Zod tuple from z.function().args(...)\n // We use direct Zod conversion to ensure proper tuple handling\n let jsonSchema: JSONSchema7;\n if (looksLikeJSONSchema(argsSchema)) {\n jsonSchema = argsSchema;\n } else if (isZodSchema(argsSchema)) {\n // Use direct Zod conversion for more reliable tuple handling\n jsonSchema = handleZodSchemaToJson(argsSchema) as JSONSchema7;\n } else if (isStandardSchema(argsSchema)) {\n jsonSchema = schemaToJsonSchema(argsSchema);\n } else {\n console.warn(\"Unknown toolSchema args type, returning empty parameters\");\n return [];\n }\n\n // Extract tuple items for positional params\n if (isJsonSchemaTuple(jsonSchema)) {\n const tupleItems = getJsonSchemaTupleItems(jsonSchema) ?? [];\n return extractParamsFromJsonSchemaTuple(tupleItems);\n }\n\n // Fallback: wrap as single param (shouldn't normally happen for toolSchema)\n return extractParamsFromJsonSchemaTuple([jsonSchema]);\n};\n\nexport type { SupportedSchema };\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAS7E,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE/E,uDAAuD;AACvD,UAAU,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAuB;IACxD,uCAAuC;IACvC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAgB,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAA0C,EAC1C,OAAkC;IAElC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACjB,OAAO,SAAS,CAAC;I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A4C;IAC5C,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,uBAAuB,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC7D,OAAO,gCAAgC,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IAED,4EAA4E;IAC5E,OAAO,gCAAgC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC","sourcesContent":["/**\n * Schema utilities for working with Standard Schema, Zod, and JSON Schema.\n *\n * This module provides a unified interface for handling different schema types\n * used in Tambo components and tools. It uses Standard Schema (https://standardschema.dev/)\n * as the primary interface, which is implemented by Zod and other validation libraries.\n *\n * JSON Schema conversion is handled by `@standard-community/standard-json`, with:\n * - Zod 4: Uses Zod's native toJSONSchema\n * - Zod 3: Requires optional peer dependency 'zod-to-json-schema'\n * - Other vendors: Handled by standard-json's built-in converters\n * @module schema\n */\n\nimport { loadVendor, toJsonSchema } from \"@standard-community/standard-json\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport {\n ParameterSpec,\n SupportedSchema,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n getJsonSchemaTupleItems,\n isJsonSchemaTuple,\n looksLikeJSONSchema,\n} from \"./json-schema\";\nimport { isStandardSchema } from \"./standard-schema\";\nimport { getZodFunctionArgs, handleZodSchemaToJson, isZodSchema } from \"./zod\";\n\n// Register the Zod vendor converter with standard-json\nloadVendor(\"zod\", handleZodSchemaToJson);\n\n/**\n * Converts a schema (Standard Schema or JSON Schema) to a JSON Schema object.\n *\n * If the schema is already a JSON Schema, it is returned as-is.\n * For Standard Schema validators (Zod, Valibot, ArkType, etc.), uses\n * `@standard-community/standard-json` for conversion.\n * @param schema - The schema to convert\n * @returns The JSON Schema representation\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * // Convert a Zod schema\n * const zodSchema = z.object({ name: z.string() });\n * const jsonSchema = schemaToJsonSchema(zodSchema);\n *\n * // Pass through a JSON Schema\n * const existingJsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * schemaToJsonSchema(existingJsonSchema); // returns the same object\n * ```\n */\nexport function schemaToJsonSchema(schema: SupportedSchema): JSONSchema7 {\n // Already a JSON Schema - return as-is\n if (!isStandardSchema(schema)) {\n return schema;\n }\n\n return toJsonSchema.sync(schema) as JSONSchema7;\n}\n\n/**\n * Safely converts a schema to JSON Schema, returning undefined for invalid inputs.\n * @param schema - The schema to convert (may be undefined)\n * @param onError - Optional callback invoked on conversion error\n * @returns The JSON Schema representation, or undefined if conversion fails\n */\nexport function safeSchemaToJsonSchema(\n schema: SupportedSchema | undefined | null,\n onError?: (error: unknown) => void,\n): JSONSchema7 | undefined {\n if (!schema) {\n return undefined;\n }\n\n try {\n return schemaToJsonSchema(schema);\n } catch (error) {\n console.error(\"Error converting schema to JSON Schema:\", error);\n onError?.(error);\n return undefined;\n }\n}\n\n/**\n * Checks if a tool uses the new inputSchema interface (vs deprecated toolSchema).\n * @param tool - The Tambo tool to check\n * @returns True if the tool uses inputSchema\n */\nexport function hasInputSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): tool is TamboTool {\n return \"inputSchema\" in tool && tool.inputSchema != null;\n}\n\n/**\n * Retrieves the input schema for a Tambo tool using the deprecated toolSchema.\n * For toolSchema, this extracts the args from the Zod function schema.\n * @param tool - The Tambo tool (potentially with toolSchema)\n * @returns The input schema (Standard Schema or JSON Schema), or undefined if not toolSchema\n */\nfunction getArgsFromToolSchema(\n tool: TamboToolWithToolSchema,\n): StandardSchemaV1 | JSONSchema7 | undefined {\n if (looksLikeJSONSchema(tool.toolSchema)) {\n return tool.toolSchema;\n }\n\n return getZodFunctionArgs(tool.toolSchema);\n}\n\n/**\n * Extracts parameter specifications from JSON Schema tuple items.\n * Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).\n * This is library-agnostic - works with Zod, Valibot, ArkType, etc.\n * @param tupleItems - The array of JSON Schema items\n * @returns An array of parameter specifications\n */\nfunction extractParamsFromJsonSchemaTuple(\n tupleItems: JSONSchema7[],\n): ParameterSpec[] {\n return tupleItems.map((item, index) => ({\n name: `param${index + 1}`,\n type: typeof item.type === \"string\" ? item.type : \"object\",\n description: item.description ?? \"\",\n isRequired: true, // tuple items are positional\n schema: item,\n }));\n}\n\n/**\n * Creates a single parameter spec from an input schema.\n * Used for the new inputSchema interface where the schema represents\n * the shape of the single object argument to the tool function.\n * @param schema - The input schema (JSON Schema)\n * @returns A single parameter specification\n */\nfunction createInputParameter(schema: JSONSchema7): ParameterSpec {\n return {\n name: \"input\",\n type: typeof schema.type === \"string\" ? schema.type : \"object\",\n description: schema.description ?? \"\",\n isRequired: true,\n schema,\n };\n}\n\n/**\n * Extracts parameter specifications from a tool schema.\n *\n * For tools with **inputSchema** (new interface):\n * - Returns a single parameter named \"input\" representing the object schema\n * - The inputSchema defines the shape of the single object argument\n *\n * For tools with **toolSchema** (deprecated):\n * - Extracts positional parameters from tuple/function args\n * - Returns params named \"param1\", \"param2\", etc.\n * @param tool - The tool containing the schema\n * @returns An array of parameter specifications\n */\nexport const getParametersFromToolSchema = (\n tool: TamboTool | TamboToolWithToolSchema,\n): ParameterSpec[] => {\n // New interface: inputSchema represents the single object argument\n if (hasInputSchema(tool)) {\n const schema = tool.inputSchema;\n\n // Convert to JSON Schema if needed\n let jsonSchema: JSONSchema7;\n if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else if (isStandardSchema(schema)) {\n jsonSchema = schemaToJsonSchema(schema);\n } else {\n console.warn(\"Unknown inputSchema type, returning empty parameters\");\n return [];\n }\n\n return [createInputParameter(jsonSchema)];\n }\n\n // Deprecated interface: toolSchema with positional tuple args\n const argsSchema = getArgsFromToolSchema(tool);\n\n if (!argsSchema) {\n console.warn(\"No toolSchema found, returning empty parameters\");\n return [];\n }\n\n // Convert to JSON Schema if needed\n let jsonSchema: JSONSchema7;\n // zod 3 and 4 are both compatible with StandardSchema\n if (isZodSchema(argsSchema)) {\n jsonSchema = handleZodSchemaToJson(argsSchema);\n } else if (isStandardSchema(argsSchema)) {\n // uses @standard-community/standard-json for conversion\n jsonSchema = schemaToJsonSchema(argsSchema);\n } else if (looksLikeJSONSchema(argsSchema)) {\n // already JSON Schema\n jsonSchema = argsSchema;\n } else {\n console.warn(\"Unknown toolSchema args type, returning empty parameters\");\n return [];\n }\n\n // Extract tuple items for positional params\n if (isJsonSchemaTuple(jsonSchema)) {\n const tupleItems = getJsonSchemaTupleItems(jsonSchema) ?? [];\n return extractParamsFromJsonSchemaTuple(tupleItems);\n }\n\n // Fallback: wrap as single param (shouldn't normally happen for toolSchema)\n return extractParamsFromJsonSchemaTuple([jsonSchema]);\n};\n\nexport type { SupportedSchema };\n"]}
@@ -15,11 +15,11 @@ export declare function isZod4FunctionSchema(schema: unknown): schema is $ZodFun
15
15
  */
16
16
  export declare function isZodFunctionSchema(schema: unknown): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> | $ZodFunction<import("zod/v4/core").$ZodFunctionArgs, import("zod/v4/core").$ZodFunctionOut>;
17
17
  /**
18
- * Extracts the args schema from a Zod 3 function schema.
19
- * @param schema - The Zod 3 function schema
20
- * @returns The args schema, or undefined if not a Zod 3 function schema
18
+ * Extracts the args schema from a Zod function schema.
19
+ * @param schema - The Zod function schema
20
+ * @returns The args schema, or undefined if not a Zod function schema
21
21
  */
22
- export declare function getZodFunctionArgs(schema: unknown): any;
22
+ export declare function getZodFunctionArgs(schema: unknown): import("zod/v4/core").$ZodFunctionArgs | ZodTuple<ZodTupleItems, any>;
23
23
  /**
24
24
  * Extracts the return schema from a Zod 3 or Zod 4 function schema.
25
25
  * @param schema - The Zod function schema
@@ -1 +1 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,OAAO,EACP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C,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAMjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAoB5E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,iKAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,yEAWjD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAWpD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAkBpD;AAaD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE/D;AAUD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,QAAQ,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,GACd,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAEnE"}
package/esm/schema/zod.js CHANGED
@@ -16,8 +16,20 @@ export function isZod4FunctionSchema(schema) {
16
16
  if (!isZod4Schema(schema)) {
17
17
  return false;
18
18
  }
19
- // @ts-expect-error -- Error in Zod types for v3 vs v4
20
- return "def" in schema && schema._zod.def.type === "function";
19
+ // $ZodFunctions in zod 4.0 most certainly do have .def.type === "function"
20
+ // but the type definitions do not reflect this because $ZodFunction does not
21
+ // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include
22
+ // the types for 4.1 yet (and might not ever).
23
+ // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48
24
+ if ("def" in schema && typeof schema.def !== "object" && schema.def) {
25
+ if (schema.def?.type === "function") {
26
+ return true;
27
+ }
28
+ }
29
+ // We're casting as string here because zod 4.0 types don't include "function"
30
+ // literal in the union for `_zod.def.type`. The optional chaining is because
31
+ // _zod does not exist on zod 4 objects from zod 3.
32
+ return schema._zod?.def?.type === "function";
21
33
  }
22
34
  /**
23
35
  * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).
@@ -28,17 +40,17 @@ export function isZodFunctionSchema(schema) {
28
40
  return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);
29
41
  }
30
42
  /**
31
- * Extracts the args schema from a Zod 3 function schema.
32
- * @param schema - The Zod 3 function schema
33
- * @returns The args schema, or undefined if not a Zod 3 function schema
43
+ * Extracts the args schema from a Zod function schema.
44
+ * @param schema - The Zod function schema
45
+ * @returns The args schema, or undefined if not a Zod function schema
34
46
  */
35
47
  export function getZodFunctionArgs(schema) {
36
48
  if (isZod3FunctionSchema(schema)) {
37
49
  return schema._def.args;
38
50
  }
39
51
  if (isZod4FunctionSchema(schema)) {
40
- // @ts-expect-error -- Error in Zod types for v3 vs v4
41
- return schema._zod.def.input;
52
+ // @ts-expect-error -- Error in Zod types for v3 vs v4.0
53
+ return schema?.def?.input ?? schema._zod?.def?.input;
42
54
  }
43
55
  throw new Error("Unable to determine parameters from zod function schema");
44
56
  }
@@ -64,7 +76,7 @@ export function getZodFunctionReturns(schema) {
64
76
  * @returns The JSON Schema representation
65
77
  */
66
78
  export function handleZodSchemaToJson(schema) {
67
- // Detect Zod 4 by checking for def.type
79
+ // If Zod4 schema detected, use the toJSONSchema function from "zod/v4/core"
68
80
  if (isZod4Schema(schema))
69
81
  return zod4ToJSONSchema(schema);
70
82
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,YAAY,IAAI,gBAAgB,GACjC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU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ACF,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC;CAC/B,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAe;IAC1C,OAAO,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,MAAe;IAEf,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\nimport { z } from \"zodInternalAlias\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZod3Schema(schema)) {\n return false;\n }\n\n return \"typeName\" in schema._def && schema._def.typeName === \"ZodFunction\";\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return \"def\" in schema && schema._zod.def.type === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod 3 function schema.\n * @param schema - The Zod 3 function schema\n * @returns The args schema, or undefined if not a Zod 3 function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // Detect Zod 4 by checking for def.type\n if (isZod4Schema(schema)) return zod4ToJSONSchema(schema);\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema);\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n// Zod 3 schemas have _def with typeName and ~standard with vendor \"zod\"\n// Use looseObject to allow any _def shape (different for each type)\nconst zod3SchemaType = z.object({\n _def: z.looseObject({\n typeName: z.string().optional(),\n }),\n \"~standard\": z.looseObject({\n vendor: z.literal(\"zod\"),\n }),\n});\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return zod3SchemaType.safeParse(schema).success;\n}\n\nconst zod4SchemaType = z.object({\n def: z.object(),\n _zod: z.looseObject({\n def: z.looseObject({}),\n }),\n \"~standard\": z.looseObject({}),\n});\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return zod4SchemaType.safeParse(schema).success;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(\n schema: unknown,\n): ReturnType<typeof isZod3Schema> | ReturnType<typeof isZod4Schema> {\n return isZod3Schema(schema) || isZod4Schema(schema);\n}\n"]}
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,YAAY,IAAI,gBAAgB,GACjC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,UAAU,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAe;IAClD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,8CAA8C;IAC9C,gIAAgI;IAChI,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACpE,IAAK,MAAM,CAAC,GAAwB,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;YAC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C,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\nimport { z } from \"zodInternalAlias\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZod3Schema(schema)) {\n return false;\n }\n\n return \"typeName\" in schema._def && schema._def.typeName === \"ZodFunction\";\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema)) return zod4ToJSONSchema(schema);\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema);\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n// Zod 3 schemas have _def with typeName and ~standard with vendor \"zod\"\n// Use looseObject to allow any _def shape (different for each type)\nconst zod3SchemaType = z.object({\n _def: z.looseObject({\n typeName: z.string().optional(),\n }),\n \"~standard\": z.looseObject({\n vendor: z.literal(\"zod\"),\n }),\n});\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return zod3SchemaType.safeParse(schema).success;\n}\n\nconst zod4SchemaType = z.object({\n def: z.object(),\n _zod: z.looseObject({\n def: z.looseObject({}),\n }),\n \"~standard\": z.looseObject({}),\n});\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return zod4SchemaType.safeParse(schema).success;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(\n schema: unknown,\n): ReturnType<typeof isZod3Schema> | ReturnType<typeof isZod4Schema> {\n return isZod3Schema(schema) || isZod4Schema(schema);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tambo-ai/react",
3
- "version": "0.66.0",
3
+ "version": "0.66.1",
4
4
  "description": "React client package for Tambo AI",
5
5
  "repository": {
6
6
  "type": "git",