@langchain/core 0.3.57 → 0.3.58

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 (42) hide show
  1. package/dist/language_models/base.d.ts +14 -7
  2. package/dist/language_models/chat_models.cjs +5 -5
  3. package/dist/language_models/chat_models.d.ts +9 -3
  4. package/dist/language_models/chat_models.js +5 -5
  5. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +1 -1
  6. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +3 -2
  7. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +19 -5
  8. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +3 -2
  9. package/dist/output_parsers/structured.cjs +8 -7
  10. package/dist/output_parsers/structured.d.ts +10 -9
  11. package/dist/output_parsers/structured.js +6 -5
  12. package/dist/runnables/base.cjs +11 -12
  13. package/dist/runnables/base.d.ts +9 -9
  14. package/dist/runnables/base.js +8 -9
  15. package/dist/runnables/graph.cjs +2 -2
  16. package/dist/runnables/graph.js +2 -2
  17. package/dist/runnables/types.d.ts +2 -2
  18. package/dist/tools/index.cjs +9 -11
  19. package/dist/tools/index.d.ts +11 -8
  20. package/dist/tools/index.js +7 -9
  21. package/dist/tools/types.cjs +2 -2
  22. package/dist/tools/types.d.ts +11 -13
  23. package/dist/tools/types.js +2 -2
  24. package/dist/utils/env.cjs +1 -3
  25. package/dist/utils/env.js +1 -3
  26. package/dist/utils/function_calling.cjs +4 -6
  27. package/dist/utils/function_calling.d.ts +4 -6
  28. package/dist/utils/function_calling.js +4 -6
  29. package/dist/utils/json_schema.cjs +6 -2
  30. package/dist/utils/json_schema.d.ts +3 -2
  31. package/dist/utils/json_schema.js +6 -2
  32. package/dist/utils/testing/index.d.ts +8 -7
  33. package/dist/utils/types/index.cjs +1 -1
  34. package/dist/utils/types/index.d.ts +1 -1
  35. package/dist/utils/types/index.js +1 -1
  36. package/dist/utils/types/zod.cjs +424 -0
  37. package/dist/utils/types/zod.d.ts +173 -0
  38. package/dist/utils/types/zod.js +404 -0
  39. package/package.json +2 -2
  40. package/dist/utils/types/is_zod_schema.cjs +0 -38
  41. package/dist/utils/types/is_zod_schema.d.ts +0 -8
  42. package/dist/utils/types/is_zod_schema.js +0 -34
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Graph = void 0;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
5
4
  const uuid_1 = require("uuid");
6
5
  const utils_js_1 = require("./utils.cjs");
7
6
  const graph_mermaid_js_1 = require("./graph_mermaid.cjs");
7
+ const json_schema_js_1 = require("../utils/json_schema.cjs");
8
8
  function nodeDataStr(id, data) {
9
9
  if (id !== undefined && !(0, uuid_1.validate)(id)) {
10
10
  return id;
@@ -39,7 +39,7 @@ function nodeDataJson(node) {
39
39
  else {
40
40
  return {
41
41
  type: "schema",
42
- data: { ...(0, zod_to_json_schema_1.zodToJsonSchema)(node.data.schema), title: node.data.name },
42
+ data: { ...(0, json_schema_js_1.toJsonSchema)(node.data.schema), title: node.data.name },
43
43
  };
44
44
  }
45
45
  }
@@ -1,7 +1,7 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { v4 as uuidv4, validate as isUuid } from "uuid";
3
2
  import { isRunnableInterface } from "./utils.js";
4
3
  import { drawMermaid, drawMermaidPng } from "./graph_mermaid.js";
4
+ import { toJsonSchema } from "../utils/json_schema.js";
5
5
  function nodeDataStr(id, data) {
6
6
  if (id !== undefined && !isUuid(id)) {
7
7
  return id;
@@ -36,7 +36,7 @@ function nodeDataJson(node) {
36
36
  else {
37
37
  return {
38
38
  type: "schema",
39
- data: { ...zodToJsonSchema(node.data.schema), title: node.data.name },
39
+ data: { ...toJsonSchema(node.data.schema), title: node.data.name },
40
40
  };
41
41
  }
42
42
  }
@@ -1,7 +1,7 @@
1
- import type { z } from "zod";
2
1
  import type { SerializableInterface } from "../load/serializable.js";
3
2
  import type { BaseCallbackConfig } from "../callbacks/manager.js";
4
3
  import type { IterableReadableStreamInterface } from "../types/_internal.js";
4
+ import { InteropZodType } from "../utils/types/zod.js";
5
5
  export type RunnableBatchOptions = {
6
6
  /** @deprecated Pass in via the standard runnable config object instead */
7
7
  maxConcurrency?: number;
@@ -9,7 +9,7 @@ export type RunnableBatchOptions = {
9
9
  };
10
10
  export type RunnableIOSchema = {
11
11
  name?: string;
12
- schema: z.ZodType;
12
+ schema: InteropZodType;
13
13
  };
14
14
  /**
15
15
  * Base interface implemented by all runnables.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tool = exports.BaseToolkit = exports.DynamicStructuredTool = exports.DynamicTool = exports.Tool = exports.StructuredTool = exports.ToolInputParsingException = exports.isStructuredToolParams = exports.isStructuredTool = exports.isRunnableToolLike = exports.isLangChainTool = void 0;
4
- const zod_1 = require("zod");
4
+ const v3_1 = require("zod/v3");
5
5
  const json_schema_1 = require("@cfworker/json-schema");
6
6
  const manager_js_1 = require("../callbacks/manager.cjs");
7
7
  const base_js_1 = require("../language_models/base.cjs");
@@ -10,7 +10,7 @@ const tool_js_1 = require("../messages/tool.cjs");
10
10
  const index_js_1 = require("../singletons/index.cjs");
11
11
  const utils_js_1 = require("./utils.cjs");
12
12
  Object.defineProperty(exports, "ToolInputParsingException", { enumerable: true, get: function () { return utils_js_1.ToolInputParsingException; } });
13
- const is_zod_schema_js_1 = require("../utils/types/is_zod_schema.cjs");
13
+ const zod_js_1 = require("../utils/types/zod.cjs");
14
14
  const json_schema_js_1 = require("../utils/json_schema.cjs");
15
15
  var types_js_1 = require("./types.cjs");
16
16
  Object.defineProperty(exports, "isLangChainTool", { enumerable: true, get: function () { return types_js_1.isLangChainTool; } });
@@ -102,10 +102,10 @@ class StructuredTool extends base_js_1.BaseLangChain {
102
102
  // If arg is a ToolCall, use its args; otherwise, use arg directly.
103
103
  const inputForValidation = (0, utils_js_1._isToolCall)(arg) ? arg.args : arg;
104
104
  let parsed; // This will hold the successfully parsed input of the expected output type.
105
- if ((0, is_zod_schema_js_1.isZodSchema)(this.schema)) {
105
+ if ((0, zod_js_1.isInteropZodSchema)(this.schema)) {
106
106
  try {
107
107
  // Validate the inputForValidation - TS needs help here as it can't exclude ToolCall based on the check
108
- parsed = await this.schema.parseAsync(inputForValidation);
108
+ parsed = await (0, zod_js_1.interopParseAsync)(this.schema, inputForValidation);
109
109
  }
110
110
  catch (e) {
111
111
  let message = `Received tool input did not match expected schema`;
@@ -190,8 +190,8 @@ class Tool extends StructuredTool {
190
190
  enumerable: true,
191
191
  configurable: true,
192
192
  writable: true,
193
- value: zod_1.z
194
- .object({ input: zod_1.z.string().optional() })
193
+ value: v3_1.z
194
+ .object({ input: v3_1.z.string().optional() })
195
195
  .transform((obj) => obj.input)
196
196
  });
197
197
  }
@@ -342,12 +342,10 @@ class BaseToolkit {
342
342
  }
343
343
  exports.BaseToolkit = BaseToolkit;
344
344
  function tool(func, fields) {
345
- const isShapelessZodSchema = fields.schema &&
346
- (0, is_zod_schema_js_1.isZodSchema)(fields.schema) &&
347
- (!("shape" in fields.schema) || !fields.schema.shape);
345
+ const isSimpleStringSchema = (0, zod_js_1.isSimpleStringZodSchema)(fields.schema);
348
346
  const isStringJSONSchema = (0, json_schema_js_1.validatesOnlyStrings)(fields.schema);
349
- // If the schema is not provided, or it's a shapeless schema (e.g. a ZodString), create a DynamicTool
350
- if (!fields.schema || isShapelessZodSchema || isStringJSONSchema) {
347
+ // If the schema is not provided, or it's a simple string schema, create a DynamicTool
348
+ if (!fields.schema || isSimpleStringSchema || isStringJSONSchema) {
351
349
  return new DynamicTool({
352
350
  ...fields,
353
351
  description: fields.description ??
@@ -1,11 +1,12 @@
1
- import { z } from "zod";
1
+ import { z } from "zod/v3";
2
2
  import { CallbackManagerForToolRun } from "../callbacks/manager.js";
3
3
  import { BaseLangChain } from "../language_models/base.js";
4
4
  import { type RunnableConfig } from "../runnables/config.js";
5
5
  import type { RunnableFunc } from "../runnables/base.js";
6
6
  import { ToolCall, ToolMessage } from "../messages/tool.js";
7
7
  import { ToolInputParsingException } from "./utils.js";
8
- import type { StructuredToolCallInput, ToolInputSchemaBase, ToolReturnType, ResponseFormat, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolParams, ToolRunnableConfig, StructuredToolInterface, DynamicToolInput, DynamicStructuredToolInput, ZodObjectAny, StringInputToolSchema, ToolInterface, ToolOutputType } from "./types.js";
8
+ import { type InferInteropZodInput, type InferInteropZodOutput, type ZodStringV3, type ZodStringV4, type ZodObjectV3, type ZodObjectV4 } from "../utils/types/zod.js";
9
+ import type { StructuredToolCallInput, ToolInputSchemaBase, ToolReturnType, ResponseFormat, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolParams, ToolRunnableConfig, StructuredToolInterface, DynamicToolInput, DynamicStructuredToolInput, StringInputToolSchema, ToolInterface, ToolOutputType } from "./types.js";
9
10
  import { type JSONSchema } from "../utils/json_schema.js";
10
11
  export type { BaseDynamicToolInput, ContentAndArtifact, DynamicToolInput, DynamicStructuredToolInput, ResponseFormat, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInterface, ToolParams, ToolReturnType, ToolRunnableConfig, ToolInputSchemaBase as ToolSchemaBase, } from "./types.js";
11
12
  export { isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams, } from "./types.js";
@@ -13,7 +14,7 @@ export { ToolInputParsingException };
13
14
  /**
14
15
  * Base class for Tools that accept input of any shape defined by a Zod schema.
15
16
  */
16
- export declare abstract class StructuredTool<SchemaT extends ToolInputSchemaBase = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseLangChain<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
17
+ export declare abstract class StructuredTool<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseLangChain<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
17
18
  abstract name: string;
18
19
  abstract description: string;
19
20
  abstract schema: SchemaT;
@@ -111,7 +112,7 @@ export declare class DynamicTool<ToolOutputT = ToolOutputType> extends Tool<Tool
111
112
  * Schema can be passed as Zod or JSON schema. The tool will not validate
112
113
  * input if JSON schema is passed.
113
114
  */
114
- export declare class DynamicStructuredTool<SchemaT extends ToolInputSchemaBase = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT> {
115
+ export declare class DynamicStructuredTool<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT> {
115
116
  static lc_name(): string;
116
117
  name: string;
117
118
  description: string;
@@ -141,7 +142,7 @@ export declare abstract class BaseToolkit {
141
142
  * Both schema types will be validated.
142
143
  * @template {ToolInputSchemaBase} RunInput The input schema for the tool.
143
144
  */
144
- interface ToolWrapperParams<RunInput extends ToolInputSchemaBase | undefined = ToolInputSchemaBase | undefined> extends ToolParams {
145
+ interface ToolWrapperParams<RunInput = ToolInputSchemaBase | undefined> extends ToolParams {
145
146
  /**
146
147
  * The name of the tool. If using with an LLM, this
147
148
  * will be passed as the tool name.
@@ -189,10 +190,12 @@ interface ToolWrapperParams<RunInput extends ToolInputSchemaBase | undefined = T
189
190
  * @param {ToolWrapperParams<SchemaT>} fields - An object containing the following properties:
190
191
  * @param {string} fields.name The name of the tool.
191
192
  * @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`.
192
- * @param {ZodObjectAny | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema.
193
+ * @param {z.AnyZodObject | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema.
193
194
  *
194
195
  * @returns {DynamicStructuredTool<SchemaT>} A new StructuredTool instance.
195
196
  */
196
- export declare function tool<SchemaT extends z.ZodString, ToolOutputT = ToolOutputType>(func: RunnableFunc<SchemaT extends z.ZodString ? z.output<SchemaT> : string, ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams<SchemaT>): DynamicTool<ToolOutputT>;
197
- export declare function tool<SchemaT extends ZodObjectAny, SchemaOutputT = z.output<SchemaT>, SchemaInputT = z.input<SchemaT>, ToolOutputT = ToolOutputType>(func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams<SchemaT>): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;
197
+ export declare function tool<SchemaT extends ZodStringV3, ToolOutputT = ToolOutputType>(func: RunnableFunc<InferInteropZodOutput<SchemaT>, ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams<SchemaT>): DynamicTool<ToolOutputT>;
198
+ export declare function tool<SchemaT extends ZodStringV4, ToolOutputT = ToolOutputType>(func: RunnableFunc<InferInteropZodOutput<SchemaT>, ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams<SchemaT>): DynamicTool<ToolOutputT>;
199
+ export declare function tool<SchemaT extends ZodObjectV3, SchemaOutputT = InferInteropZodOutput<SchemaT>, SchemaInputT = InferInteropZodInput<SchemaT>, ToolOutputT = ToolOutputType>(func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams<SchemaT>): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;
200
+ export declare function tool<SchemaT extends ZodObjectV4, SchemaOutputT = InferInteropZodOutput<SchemaT>, SchemaInputT = InferInteropZodInput<SchemaT>, ToolOutputT = ToolOutputType>(func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams<SchemaT>): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;
198
201
  export declare function tool<SchemaT extends JSONSchema, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType>(func: RunnableFunc<Parameters<DynamicStructuredToolInput<SchemaT>["func"]>[0], ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams<SchemaT>): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { z } from "zod/v3";
2
2
  import { validate, } from "@cfworker/json-schema";
3
3
  import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
4
4
  import { BaseLangChain } from "../language_models/base.js";
@@ -6,7 +6,7 @@ import { ensureConfig, patchConfig, pickRunnableConfigKeys, } from "../runnables
6
6
  import { isDirectToolOutput, ToolMessage } from "../messages/tool.js";
7
7
  import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js";
8
8
  import { _configHasToolCallId, _isToolCall, ToolInputParsingException, } from "./utils.js";
9
- import { isZodSchema } from "../utils/types/is_zod_schema.js";
9
+ import { interopParseAsync, isSimpleStringZodSchema, isInteropZodSchema, } from "../utils/types/zod.js";
10
10
  import { validatesOnlyStrings } from "../utils/json_schema.js";
11
11
  export { isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams, } from "./types.js";
12
12
  export { ToolInputParsingException };
@@ -95,10 +95,10 @@ export class StructuredTool extends BaseLangChain {
95
95
  // If arg is a ToolCall, use its args; otherwise, use arg directly.
96
96
  const inputForValidation = _isToolCall(arg) ? arg.args : arg;
97
97
  let parsed; // This will hold the successfully parsed input of the expected output type.
98
- if (isZodSchema(this.schema)) {
98
+ if (isInteropZodSchema(this.schema)) {
99
99
  try {
100
100
  // Validate the inputForValidation - TS needs help here as it can't exclude ToolCall based on the check
101
- parsed = await this.schema.parseAsync(inputForValidation);
101
+ parsed = await interopParseAsync(this.schema, inputForValidation);
102
102
  }
103
103
  catch (e) {
104
104
  let message = `Received tool input did not match expected schema`;
@@ -330,12 +330,10 @@ export class BaseToolkit {
330
330
  }
331
331
  }
332
332
  export function tool(func, fields) {
333
- const isShapelessZodSchema = fields.schema &&
334
- isZodSchema(fields.schema) &&
335
- (!("shape" in fields.schema) || !fields.schema.shape);
333
+ const isSimpleStringSchema = isSimpleStringZodSchema(fields.schema);
336
334
  const isStringJSONSchema = validatesOnlyStrings(fields.schema);
337
- // If the schema is not provided, or it's a shapeless schema (e.g. a ZodString), create a DynamicTool
338
- if (!fields.schema || isShapelessZodSchema || isStringJSONSchema) {
335
+ // If the schema is not provided, or it's a simple string schema, create a DynamicTool
336
+ if (!fields.schema || isSimpleStringSchema || isStringJSONSchema) {
339
337
  return new DynamicTool({
340
338
  ...fields,
341
339
  description: fields.description ??
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLangChainTool = exports.isStructuredToolParams = exports.isRunnableToolLike = exports.isStructuredTool = void 0;
4
4
  const base_js_1 = require("../runnables/base.cjs");
5
- const is_zod_schema_js_1 = require("../utils/types/is_zod_schema.cjs");
5
+ const zod_js_1 = require("../utils/types/zod.cjs");
6
6
  /**
7
7
  * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.
8
8
  *
@@ -40,7 +40,7 @@ function isStructuredToolParams(tool) {
40
40
  "name" in tool &&
41
41
  "schema" in tool &&
42
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- ((0, is_zod_schema_js_1.isZodSchema)(tool.schema) ||
43
+ ((0, zod_js_1.isInteropZodSchema)(tool.schema) ||
44
44
  (tool.schema != null &&
45
45
  typeof tool.schema === "object" &&
46
46
  "type" in tool.schema &&
@@ -1,15 +1,15 @@
1
- import { z } from "zod";
1
+ import type { z as z3 } from "zod/v3";
2
2
  import { CallbackManagerForToolRun } from "../callbacks/manager.js";
3
3
  import type { BaseLangChainParams, ToolDefinition } from "../language_models/base.js";
4
4
  import type { RunnableConfig } from "../runnables/config.js";
5
5
  import { RunnableToolLike, type RunnableInterface } from "../runnables/base.js";
6
6
  import { type DirectToolOutput, type ToolCall, type ToolMessage } from "../messages/tool.js";
7
7
  import type { MessageContent } from "../messages/base.js";
8
+ import { type InferInteropZodInput, type InferInteropZodOutput, type InteropZodType } from "../utils/types/zod.js";
8
9
  import { JSONSchema } from "../utils/json_schema.js";
9
10
  export type ResponseFormat = "content" | "content_and_artifact" | string;
10
11
  export type ToolOutputType = any;
11
12
  export type ContentAndArtifact = [MessageContent, any];
12
- export type ZodObjectAny = z.ZodObject<any, any, any, any>;
13
13
  /**
14
14
  * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.
15
15
  * - If the input is a ToolCall, it returns a ToolMessage
@@ -33,7 +33,7 @@ export type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToo
33
33
  * Base type that establishes the types of input schemas that can be used for LangChain tool
34
34
  * definitions.
35
35
  */
36
- export type ToolInputSchemaBase = z.ZodAny | JSONSchema;
36
+ export type ToolInputSchemaBase = z3.ZodTypeAny | JSONSchema;
37
37
  /**
38
38
  * Parameters for the Tool classes.
39
39
  */
@@ -80,7 +80,7 @@ export interface StructuredToolParams extends Pick<StructuredToolInterface, "nam
80
80
  * applying any transforms defined in your schema. If there are no transforms, the input and output
81
81
  * types will be the same.
82
82
  */
83
- export type ToolInputSchemaOutputType<T extends ToolInputSchemaBase> = T extends z.ZodSchema ? z.output<T> : T extends JSONSchema ? unknown : never;
83
+ export type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JSONSchema ? unknown : never;
84
84
  /**
85
85
  * Utility type that resolves the input type of a tool input schema.
86
86
  *
@@ -92,14 +92,14 @@ export type ToolInputSchemaOutputType<T extends ToolInputSchemaBase> = T extends
92
92
  * applying any transforms defined in your schema. If there are no transforms, the input and output
93
93
  * types will be the same.
94
94
  */
95
- export type ToolInputSchemaInputType<T extends ToolInputSchemaBase> = T extends z.ZodSchema ? z.input<T> : T extends JSONSchema ? unknown : never;
95
+ export type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JSONSchema ? unknown : never;
96
96
  /**
97
97
  * Defines the type that will be passed into a tool handler function as a result of a tool call.
98
98
  *
99
99
  * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
100
100
  * @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
101
101
  */
102
- export type StructuredToolCallInput<SchemaT extends ToolInputSchemaBase = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;
102
+ export type StructuredToolCallInput<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;
103
103
  /**
104
104
  * An input schema type for tools that accept a single string input.
105
105
  *
@@ -109,9 +109,7 @@ export type StructuredToolCallInput<SchemaT extends ToolInputSchemaBase = ToolIn
109
109
  * This is primarily used for creating simple string-based tools where the LLM
110
110
  * only needs to provide a single text value as input to the tool.
111
111
  */
112
- export type StringInputToolSchema = z.ZodEffects<z.ZodObject<{
113
- input: z.ZodOptional<z.ZodString>;
114
- }, "strip", z.ZodTypeAny, any, any>, any, any>;
112
+ export type StringInputToolSchema = z3.ZodType<string | undefined, z3.ZodTypeDef, any>;
115
113
  /**
116
114
  * Defines the type for input to a tool's call method.
117
115
  *
@@ -124,7 +122,7 @@ export type StringInputToolSchema = z.ZodEffects<z.ZodObject<{
124
122
  *
125
123
  * @param SchemaT - The schema type for the tool input, defaults to StringInputToolSchema
126
124
  */
127
- export type ToolCallInput<SchemaT extends ToolInputSchemaBase = StringInputToolSchema> = StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;
125
+ export type ToolCallInput<SchemaT = StringInputToolSchema> = StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;
128
126
  /**
129
127
  * Interface that defines the shape of a LangChain structured tool.
130
128
  *
@@ -134,7 +132,7 @@ export type ToolCallInput<SchemaT extends ToolInputSchemaBase = StringInputToolS
134
132
  * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
135
133
  * @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
136
134
  */
137
- export interface StructuredToolInterface<SchemaT extends ToolInputSchemaBase = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {
135
+ export interface StructuredToolInterface<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {
138
136
  lc_namespace: string[];
139
137
  /**
140
138
  * A Zod schema representing the parameters of the tool.
@@ -183,7 +181,7 @@ export interface StructuredToolInterface<SchemaT extends ToolInputSchemaBase = T
183
181
  * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
184
182
  * @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
185
183
  */
186
- export interface ToolInterface<SchemaT extends StringInputToolSchema = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
184
+ export interface ToolInterface<SchemaT = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
187
185
  /**
188
186
  * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
189
187
  *
@@ -222,7 +220,7 @@ export interface DynamicToolInput<ToolOutputT = ToolOutputType> extends BaseDyna
222
220
  * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
223
221
  * @param SchemaOutputT - The TypeScript type representing the result of applying the schema to the tool arguments. Useful for type checking tool handler functions when using JSONSchema.
224
222
  */
225
- export interface DynamicStructuredToolInput<SchemaT extends ToolInputSchemaBase = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {
223
+ export interface DynamicStructuredToolInput<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {
226
224
  /**
227
225
  * Tool handler function - the function that will be called when the tool is invoked.
228
226
  *
@@ -1,5 +1,5 @@
1
1
  import { Runnable, } from "../runnables/base.js";
2
- import { isZodSchema } from "../utils/types/is_zod_schema.js";
2
+ import { isInteropZodSchema, } from "../utils/types/zod.js";
3
3
  /**
4
4
  * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.
5
5
  *
@@ -35,7 +35,7 @@ export function isStructuredToolParams(tool) {
35
35
  "name" in tool &&
36
36
  "schema" in tool &&
37
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- (isZodSchema(tool.schema) ||
38
+ (isInteropZodSchema(tool.schema) ||
39
39
  (tool.schema != null &&
40
40
  typeof tool.schema === "object" &&
41
41
  "type" in tool.schema &&
@@ -8,9 +8,7 @@ const isWebWorker = () => typeof globalThis === "object" &&
8
8
  globalThis.constructor.name === "DedicatedWorkerGlobalScope";
9
9
  exports.isWebWorker = isWebWorker;
10
10
  const isJsDom = () => (typeof window !== "undefined" && window.name === "nodejs") ||
11
- (typeof navigator !== "undefined" &&
12
- (navigator.userAgent.includes("Node.js") ||
13
- navigator.userAgent.includes("jsdom")));
11
+ (typeof navigator !== "undefined" && navigator.userAgent.includes("jsdom"));
14
12
  exports.isJsDom = isJsDom;
15
13
  // Supabase Edge Function provides a `Deno` global object
16
14
  // without `version` property
package/dist/utils/env.js CHANGED
@@ -3,9 +3,7 @@ export const isWebWorker = () => typeof globalThis === "object" &&
3
3
  globalThis.constructor &&
4
4
  globalThis.constructor.name === "DedicatedWorkerGlobalScope";
5
5
  export const isJsDom = () => (typeof window !== "undefined" && window.name === "nodejs") ||
6
- (typeof navigator !== "undefined" &&
7
- (navigator.userAgent.includes("Node.js") ||
8
- navigator.userAgent.includes("jsdom")));
6
+ (typeof navigator !== "undefined" && navigator.userAgent.includes("jsdom"));
9
7
  // Supabase Edge Function provides a `Deno` global object
10
8
  // without `version` property
11
9
  export const isDeno = () => typeof Deno !== "undefined";
@@ -13,9 +13,8 @@ Object.defineProperty(exports, "isLangChainTool", { enumerable: true, get: funct
13
13
  /**
14
14
  * Formats a `StructuredTool` or `RunnableToolLike` instance into a format
15
15
  * that is compatible with OpenAI function calling. If `StructuredTool` or
16
- * `RunnableToolLike` has a zod schema, it uses the `zodToJsonSchema`
17
- * function to convert the schema of the `StructuredTool` or `RunnableToolLike`
18
- * into a JSON schema, which is then used as the parameters for the OpenAI function.
16
+ * `RunnableToolLike` has a zod schema, the output will be converted into a
17
+ * JSON schema, which is then used as the parameters for the OpenAI tool.
19
18
  *
20
19
  * @param {StructuredToolInterface | RunnableToolLike} tool The tool to convert to an OpenAI function.
21
20
  * @returns {FunctionDefinition} The inputted tool in OpenAI function format.
@@ -35,9 +34,8 @@ exports.convertToOpenAIFunction = convertToOpenAIFunction;
35
34
  /**
36
35
  * Formats a `StructuredTool` or `RunnableToolLike` instance into a
37
36
  * format that is compatible with OpenAI tool calling. If `StructuredTool` or
38
- * `RunnableToolLike` has a zod schema, it uses the `zodToJsonSchema`
39
- * function to convert the schema of the `StructuredTool` or `RunnableToolLike`
40
- * into a JSON schema, which is then used as the parameters for the OpenAI tool.
37
+ * `RunnableToolLike` has a zod schema, the output will be converted into a
38
+ * JSON schema, which is then used as the parameters for the OpenAI tool.
41
39
  *
42
40
  * @param {StructuredToolInterface | Record<string, any> | RunnableToolLike} tool The tool to convert to an OpenAI tool.
43
41
  * @returns {ToolDefinition} The inputted tool in OpenAI tool format.
@@ -5,9 +5,8 @@ export { isStructuredTool, isStructuredToolParams, isRunnableToolLike, isLangCha
5
5
  /**
6
6
  * Formats a `StructuredTool` or `RunnableToolLike` instance into a format
7
7
  * that is compatible with OpenAI function calling. If `StructuredTool` or
8
- * `RunnableToolLike` has a zod schema, it uses the `zodToJsonSchema`
9
- * function to convert the schema of the `StructuredTool` or `RunnableToolLike`
10
- * into a JSON schema, which is then used as the parameters for the OpenAI function.
8
+ * `RunnableToolLike` has a zod schema, the output will be converted into a
9
+ * JSON schema, which is then used as the parameters for the OpenAI tool.
11
10
  *
12
11
  * @param {StructuredToolInterface | RunnableToolLike} tool The tool to convert to an OpenAI function.
13
12
  * @returns {FunctionDefinition} The inputted tool in OpenAI function format.
@@ -22,9 +21,8 @@ export declare function convertToOpenAIFunction(tool: StructuredToolInterface |
22
21
  /**
23
22
  * Formats a `StructuredTool` or `RunnableToolLike` instance into a
24
23
  * format that is compatible with OpenAI tool calling. If `StructuredTool` or
25
- * `RunnableToolLike` has a zod schema, it uses the `zodToJsonSchema`
26
- * function to convert the schema of the `StructuredTool` or `RunnableToolLike`
27
- * into a JSON schema, which is then used as the parameters for the OpenAI tool.
24
+ * `RunnableToolLike` has a zod schema, the output will be converted into a
25
+ * JSON schema, which is then used as the parameters for the OpenAI tool.
28
26
  *
29
27
  * @param {StructuredToolInterface | Record<string, any> | RunnableToolLike} tool The tool to convert to an OpenAI tool.
30
28
  * @returns {ToolDefinition} The inputted tool in OpenAI tool format.
@@ -6,9 +6,8 @@ export { isStructuredTool, isStructuredToolParams, isRunnableToolLike, isLangCha
6
6
  /**
7
7
  * Formats a `StructuredTool` or `RunnableToolLike` instance into a format
8
8
  * that is compatible with OpenAI function calling. If `StructuredTool` or
9
- * `RunnableToolLike` has a zod schema, it uses the `zodToJsonSchema`
10
- * function to convert the schema of the `StructuredTool` or `RunnableToolLike`
11
- * into a JSON schema, which is then used as the parameters for the OpenAI function.
9
+ * `RunnableToolLike` has a zod schema, the output will be converted into a
10
+ * JSON schema, which is then used as the parameters for the OpenAI tool.
12
11
  *
13
12
  * @param {StructuredToolInterface | RunnableToolLike} tool The tool to convert to an OpenAI function.
14
13
  * @returns {FunctionDefinition} The inputted tool in OpenAI function format.
@@ -27,9 +26,8 @@ export function convertToOpenAIFunction(tool, fields) {
27
26
  /**
28
27
  * Formats a `StructuredTool` or `RunnableToolLike` instance into a
29
28
  * format that is compatible with OpenAI tool calling. If `StructuredTool` or
30
- * `RunnableToolLike` has a zod schema, it uses the `zodToJsonSchema`
31
- * function to convert the schema of the `StructuredTool` or `RunnableToolLike`
32
- * into a JSON schema, which is then used as the parameters for the OpenAI tool.
29
+ * `RunnableToolLike` has a zod schema, the output will be converted into a
30
+ * JSON schema, which is then used as the parameters for the OpenAI tool.
33
31
  *
34
32
  * @param {StructuredToolInterface | Record<string, any> | RunnableToolLike} tool The tool to convert to an OpenAI tool.
35
33
  * @returns {ToolDefinition} The inputted tool in OpenAI tool format.
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatesOnlyStrings = exports.toJsonSchema = exports.Validator = exports.deepCompareStrict = void 0;
4
+ const core_1 = require("zod/v4/core");
4
5
  const zod_to_json_schema_1 = require("zod-to-json-schema");
5
6
  const json_schema_1 = require("@cfworker/json-schema");
6
- const is_zod_schema_js_1 = require("./types/is_zod_schema.cjs");
7
+ const zod_js_1 = require("./types/zod.cjs");
7
8
  var json_schema_2 = require("@cfworker/json-schema");
8
9
  Object.defineProperty(exports, "deepCompareStrict", { enumerable: true, get: function () { return json_schema_2.deepCompareStrict; } });
9
10
  Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return json_schema_2.Validator; } });
@@ -13,7 +14,10 @@ Object.defineProperty(exports, "Validator", { enumerable: true, get: function ()
13
14
  * @returns The converted schema.
14
15
  */
15
16
  function toJsonSchema(schema) {
16
- if ((0, is_zod_schema_js_1.isZodSchema)(schema)) {
17
+ if ((0, zod_js_1.isZodSchemaV4)(schema)) {
18
+ return (0, core_1.toJSONSchema)(schema);
19
+ }
20
+ if ((0, zod_js_1.isZodSchemaV3)(schema)) {
17
21
  return (0, zod_to_json_schema_1.zodToJsonSchema)(schema);
18
22
  }
19
23
  return schema;
@@ -1,5 +1,5 @@
1
- import type { z } from "zod";
2
1
  import { type JsonSchema7Type } from "zod-to-json-schema";
2
+ import { InteropZodType } from "./types/zod.js";
3
3
  export type JSONSchema = JsonSchema7Type;
4
4
  export { deepCompareStrict, Validator } from "@cfworker/json-schema";
5
5
  /**
@@ -7,7 +7,7 @@ export { deepCompareStrict, Validator } from "@cfworker/json-schema";
7
7
  * @param schema - The schema to convert.
8
8
  * @returns The converted schema.
9
9
  */
10
- export declare function toJsonSchema(schema: z.ZodType | JSONSchema): JSONSchema;
10
+ export declare function toJsonSchema(schema: InteropZodType | JSONSchema): JSONSchema;
11
11
  /**
12
12
  * Validates if a JSON schema validates only strings. May return false negatives in some edge cases
13
13
  * (like recursive or unresolvable refs).
@@ -16,3 +16,4 @@ export declare function toJsonSchema(schema: z.ZodType | JSONSchema): JSONSchema
16
16
  * @returns `true` if the schema validates only strings, `false` otherwise.
17
17
  */
18
18
  export declare function validatesOnlyStrings(schema: unknown): boolean;
19
+ export { type JsonSchema7Type, type JsonSchema7ArrayType, type JsonSchema7ObjectType, type JsonSchema7StringType, type JsonSchema7NumberType, type JsonSchema7NullableType, } from "zod-to-json-schema";
@@ -1,6 +1,7 @@
1
+ import { toJSONSchema } from "zod/v4/core";
1
2
  import { zodToJsonSchema } from "zod-to-json-schema";
2
3
  import { dereference } from "@cfworker/json-schema";
3
- import { isZodSchema } from "./types/is_zod_schema.js";
4
+ import { isZodSchemaV3, isZodSchemaV4 } from "./types/zod.js";
4
5
  export { deepCompareStrict, Validator } from "@cfworker/json-schema";
5
6
  /**
6
7
  * Converts a Zod schema or JSON schema to a JSON schema.
@@ -8,7 +9,10 @@ export { deepCompareStrict, Validator } from "@cfworker/json-schema";
8
9
  * @returns The converted schema.
9
10
  */
10
11
  export function toJsonSchema(schema) {
11
- if (isZodSchema(schema)) {
12
+ if (isZodSchemaV4(schema)) {
13
+ return toJSONSchema(schema);
14
+ }
15
+ if (isZodSchemaV3(schema)) {
12
16
  return zodToJsonSchema(schema);
13
17
  }
14
18
  return schema;
@@ -1,4 +1,3 @@
1
- import { z } from "zod";
2
1
  import { BaseCallbackConfig, CallbackManagerForLLMRun, CallbackManagerForToolRun } from "../../callbacks/manager.js";
3
2
  import { BaseChatMessageHistory, BaseListChatMessageHistory } from "../../chat_history.js";
4
3
  import { Document } from "../../documents/document.js";
@@ -10,11 +9,13 @@ import { GenerationChunk, type ChatResult, ChatGenerationChunk } from "../../out
10
9
  import { BaseRetriever } from "../../retrievers/index.js";
11
10
  import { Runnable } from "../../runnables/base.js";
12
11
  import { StructuredTool, ToolParams } from "../../tools/index.js";
12
+ import { ToolInputSchemaOutputType } from "../../tools/types.js";
13
13
  import { BaseTracer, Run } from "../../tracers/base.js";
14
14
  import { Embeddings, EmbeddingsInterface, EmbeddingsParams } from "../../embeddings.js";
15
15
  import { StructuredOutputMethodParams, BaseLanguageModelInput, StructuredOutputMethodOptions } from "../../language_models/base.js";
16
16
  import { VectorStore } from "../../vectorstores.js";
17
17
  import { cosine } from "../ml-distance/similarities.js";
18
+ import { InteropZodObject, InteropZodType } from "../types/zod.js";
18
19
  /**
19
20
  * Parser for comma-separated values. It splits the input text by commas
20
21
  * and trims the resulting values.
@@ -85,7 +86,7 @@ export declare class FakeRetriever extends BaseRetriever {
85
86
  export interface ToolSpec {
86
87
  name: string;
87
88
  description?: string;
88
- schema: z.ZodTypeAny | Record<string, unknown>;
89
+ schema: InteropZodType | Record<string, unknown>;
89
90
  }
90
91
  /**
91
92
  * Interface specific to the Fake Streaming Chat model.
@@ -161,8 +162,8 @@ export declare class FakeListChatModel extends BaseChatModel<FakeListChatModelCa
161
162
  _createResponseChunk(text: string): ChatGenerationChunk;
162
163
  _currentResponse(): string;
163
164
  _incrementResponse(): void;
164
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
165
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
165
+ withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
166
+ withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
166
167
  raw: BaseMessage;
167
168
  parsed: RunOutput;
168
169
  }>;
@@ -190,17 +191,17 @@ export declare class FakeTracer extends BaseTracer {
190
191
  constructor();
191
192
  protected persistRun(run: Run): Promise<void>;
192
193
  }
193
- export interface FakeToolParams<T extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>> extends ToolParams {
194
+ export interface FakeToolParams<T extends InteropZodObject = InteropZodObject> extends ToolParams {
194
195
  name: string;
195
196
  description: string;
196
197
  schema: T;
197
198
  }
198
- export declare class FakeTool<T extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>> extends StructuredTool<T> {
199
+ export declare class FakeTool<T extends InteropZodObject = InteropZodObject> extends StructuredTool<T> {
199
200
  name: string;
200
201
  description: string;
201
202
  schema: T;
202
203
  constructor(fields: FakeToolParams<T>);
203
- protected _call(arg: z.output<T>, _runManager?: CallbackManagerForToolRun): Promise<string>;
204
+ protected _call(arg: ToolInputSchemaOutputType<T>, _runManager?: CallbackManagerForToolRun): Promise<string>;
204
205
  }
205
206
  /**
206
207
  * A class that provides fake embeddings by overriding the embedDocuments
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./is_zod_schema.cjs"), exports);
17
+ __exportStar(require("./zod.cjs"), exports);
@@ -1,4 +1,4 @@
1
- export * from "./is_zod_schema.js";
1
+ export * from "./zod.js";
2
2
  /**
3
3
  * Represents a string value with autocompleted, but not required, suggestions.
4
4
  */
@@ -1 +1 @@
1
- export * from "./is_zod_schema.js";
1
+ export * from "./zod.js";