@langchain/core 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,12 @@
1
1
  import { MessageContent } from "../messages/base.cjs";
2
2
  import { DirectToolOutput, ToolCall, ToolMessage } from "../messages/tool.cjs";
3
- import { InferInteropZodInput, InferInteropZodOutput, InteropZodType } from "../utils/types/zod.cjs";
3
+ import { InferInteropZodInput, InferInteropZodOutput, InteropZodObject, InteropZodType } from "../utils/types/zod.cjs";
4
4
  import { CallbackManagerForToolRun } from "../callbacks/manager.cjs";
5
5
  import { RunnableConfig, RunnableInterface } from "../runnables/types.cjs";
6
6
  import { RunnableToolLike } from "../runnables/base.cjs";
7
7
  import { JsonSchema7Type } from "../utils/zod-to-json-schema/parseTypes.cjs";
8
8
  import { BaseLangChainParams, ToolDefinition } from "../language_models/base.cjs";
9
+ import { BaseStore } from "../stores.cjs";
9
10
  import { z } from "zod/v3";
10
11
 
11
12
  //#region src/tools/types.d.ts
@@ -282,6 +283,97 @@ declare function isStructuredToolParams(tool?: unknown): tool is StructuredToolP
282
283
  * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.
283
284
  */
284
285
  declare function isLangChainTool(tool?: unknown): tool is StructuredToolParams;
286
+ /**
287
+ * Runtime context automatically injected into tools.
288
+ *
289
+ * When a tool function has a parameter named `tool_runtime` with type hint
290
+ * `ToolRuntime`, the tool execution system will automatically inject an instance
291
+ * containing:
292
+ *
293
+ * - `state`: The current graph state
294
+ * - `toolCallId`: The ID of the current tool call
295
+ * - `config`: `RunnableConfig` for the current execution
296
+ * - `context`: Runtime context
297
+ * - `store`: `BaseStore` instance for persistent storage
298
+ * - `writer`: Stream writer for streaming output
299
+ *
300
+ * No `Annotated` wrapper is needed - just use `runtime: ToolRuntime`
301
+ * as a parameter.
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * import { tool, ToolRuntime } from "@langchain/core/tools";
306
+ * import { z } from "zod";
307
+ *
308
+ * const stateSchema = z.object({
309
+ * messages: z.array(z.any()),
310
+ * userId: z.string().optional(),
311
+ * });
312
+ *
313
+ * const greet = tool(
314
+ * async ({ name }, runtime) => {
315
+ * // Access state
316
+ * const messages = runtime.state.messages;
317
+ *
318
+ * // Access tool_call_id
319
+ * console.log(`Tool call ID: ${runtime.toolCallId}`);
320
+ *
321
+ * // Access config
322
+ * console.log(`Run ID: ${runtime.config.runId}`);
323
+ *
324
+ * // Access runtime context
325
+ * const userId = runtime.context?.userId;
326
+ *
327
+ * // Access store
328
+ * await runtime.store?.mset([["key", "value"]]);
329
+ *
330
+ * // Stream output
331
+ * runtime.writer?.("Processing...");
332
+ *
333
+ * return `Hello! User ID: ${runtime.state.userId || "unknown"} ${name}`;
334
+ * },
335
+ * {
336
+ * name: "greet",
337
+ * description: "Use this to greet the user once you found their info.",
338
+ * schema: z.object({ name: z.string() }),
339
+ * stateSchema,
340
+ * }
341
+ * );
342
+ * ```
343
+ *
344
+ * @template StateT - The type of the state schema (inferred from stateSchema)
345
+ * @template ContextT - The type of the context schema (inferred from contextSchema)
346
+ */
347
+ type ToolRuntime<TState = unknown, TContext = unknown> = RunnableConfig & {
348
+ /**
349
+ * The current graph state.
350
+ */
351
+ state: TState extends InteropZodObject ? InferInteropZodOutput<TState> : TState extends Record<string, unknown> ? TState : unknown;
352
+ /**
353
+ * The ID of the current tool call.
354
+ */
355
+ toolCallId: string;
356
+ /**
357
+ * The current tool call.
358
+ */
359
+ toolCall?: ToolCall;
360
+ /**
361
+ * RunnableConfig for the current execution.
362
+ */
363
+ config: ToolRunnableConfig;
364
+ /**
365
+ * Runtime context (from langgraph `Runtime`).
366
+ */
367
+ context: TContext extends InteropZodObject ? InferInteropZodOutput<TContext> : TContext extends Record<string, unknown> ? TContext : unknown;
368
+ /**
369
+ * BaseStore instance for persistent storage (from langgraph `Runtime`).
370
+ */
371
+ store: BaseStore<string, unknown> | null;
372
+ /**
373
+ * Stream writer for streaming output (from langgraph `Runtime`).
374
+ */
375
+ writer: ((chunk: unknown) => void) | null;
376
+ };
285
377
  //#endregion
286
- export { BaseDynamicToolInput, ContentAndArtifact, DynamicStructuredToolInput, DynamicToolInput, ResponseFormat, StringInputToolSchema, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInputSchemaBase, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolInterface, ToolOutputType, ToolParams, ToolReturnType, ToolRunnableConfig, isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams };
378
+ export { BaseDynamicToolInput, ContentAndArtifact, DynamicStructuredToolInput, DynamicToolInput, ResponseFormat, StringInputToolSchema, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInputSchemaBase, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolInterface, ToolOutputType, ToolParams, ToolReturnType, ToolRunnableConfig, ToolRuntime, isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams };
287
379
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":["z","z3","CallbackManagerForToolRun","BaseLangChainParams","ToolDefinition","RunnableConfig","RunnableToolLike","RunnableInterface","DirectToolOutput","ToolCall","ToolMessage","MessageContent","InferInteropZodInput","InferInteropZodOutput","InteropZodType","JSONSchema","ResponseFormat","ToolOutputType","ContentAndArtifact","ToolReturnType","TOutput","TConfig","TInput","ToolInputSchemaBase","ZodTypeAny","ToolParams","ToolRunnableConfig","Record","ConfigurableFieldType","ContextSchema","StructuredToolParams","StructuredToolInterface","Pick","ToolInputSchemaOutputType","T","ToolInputSchemaInputType","StructuredToolCallInput","SchemaT","SchemaInputT","StringInputToolSchema","ZodTypeDef","ZodType","ToolCallInput","ToolOutputT","TArg","Promise","ToolInterface","NonNullable","BaseDynamicToolInput","DynamicToolInput","DynamicStructuredToolInput","SchemaOutputT","isStructuredTool","isRunnableToolLike","isStructuredToolParams","isLangChainTool"],"sources":["../../src/tools/types.d.ts"],"sourcesContent":["import type { z as z3 } from \"zod/v3\";\nimport { CallbackManagerForToolRun } from \"../callbacks/manager.js\";\nimport type { BaseLangChainParams, ToolDefinition } from \"../language_models/base.js\";\nimport type { RunnableConfig } from \"../runnables/config.js\";\nimport { RunnableToolLike, type RunnableInterface } from \"../runnables/base.js\";\nimport { type DirectToolOutput, type ToolCall, type ToolMessage } from \"../messages/tool.js\";\nimport type { MessageContent } from \"../messages/base.js\";\nimport { type InferInteropZodInput, type InferInteropZodOutput, type InteropZodType } from \"../utils/types/zod.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\nexport type ResponseFormat = \"content\" | \"content_and_artifact\" | string;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolOutputType = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ContentAndArtifact = [MessageContent, any];\n/**\n * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.\n * - If the input is a ToolCall, it returns a ToolMessage\n * - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage\n * - Otherwise, it returns the original output type\n */\nexport type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput ? TOutput : TConfig extends {\n toolCall: {\n id: string;\n };\n} ? ToolMessage : TConfig extends {\n toolCall: {\n id: undefined;\n };\n} ? TOutput : TConfig extends {\n toolCall: {\n id?: string;\n };\n} ? TOutput | ToolMessage : TInput extends ToolCall ? ToolMessage : TOutput;\n/**\n * Base type that establishes the types of input schemas that can be used for LangChain tool\n * definitions.\n */\nexport type ToolInputSchemaBase = z3.ZodTypeAny | JSONSchema;\n/**\n * Parameters for the Tool classes.\n */\nexport interface ToolParams extends BaseLangChainParams {\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n /**\n * Whether to show full details in the thrown parsing errors.\n *\n * @default false\n */\n verboseParsingErrors?: boolean;\n /**\n * Metadata for the tool.\n */\n metadata?: Record<string, unknown>;\n}\nexport type ToolRunnableConfig<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfigurableFieldType extends Record<string, any> = Record<string, any>, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nContextSchema = any> = RunnableConfig<ConfigurableFieldType> & {\n toolCall?: ToolCall;\n context?: ContextSchema;\n};\n/**\n * Schema for defining tools.\n *\n * @version 0.2.19\n */\nexport interface StructuredToolParams extends Pick<StructuredToolInterface, \"name\" | \"schema\"> {\n /**\n * An optional description of the tool to pass to the model.\n */\n description?: string;\n}\n/**\n * Utility type that resolves the output type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Utility type that resolves the input type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Defines the type that will be passed into a tool handler function as a result of a tool call.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport type StructuredToolCallInput<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;\n/**\n * An input schema type for tools that accept a single string input.\n *\n * This schema defines a tool that takes an optional string parameter named \"input\".\n * It uses Zod's effects to transform the input and strip any extra properties.\n *\n * This is primarily used for creating simple string-based tools where the LLM\n * only needs to provide a single text value as input to the tool.\n */\nexport type StringInputToolSchema = z3.ZodType<string | undefined, z3.ZodTypeDef, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany>;\n/**\n * Defines the type for input to a tool's call method.\n *\n * This type is a convenience alias for StructuredToolCallInput with the input type\n * derived from the schema. It represents the possible inputs that can be passed to a tool,\n * which can be either:\n * - A string (if the tool accepts string input)\n * - A structured input matching the tool's schema\n * - A ToolCall object (typically from an LLM)\n *\n * @param SchemaT - The schema type for the tool input, defaults to StringInputToolSchema\n */\nexport type ToolCallInput<SchemaT = StringInputToolSchema> = StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;\n/**\n * Interface that defines the shape of a LangChain structured tool.\n *\n * A structured tool is a tool that uses a schema to define the structure of the arguments that the\n * LLM generates as part of its {@link ToolCall}.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface StructuredToolInterface<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {\n lc_namespace: string[];\n /**\n * A Zod schema representing the parameters of the tool.\n */\n schema: SchemaT;\n /**\n * Invokes the tool with the provided argument and configuration.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration for the tool call.\n * @returns A Promise that resolves with the tool's output.\n */\n invoke<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig, \n /** @deprecated */\n tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * The name of the tool.\n */\n name: string;\n /**\n * A description of the tool.\n */\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect: boolean;\n}\n/**\n * A special interface for tools that accept a string input, usually defined with the {@link Tool} class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface ToolInterface<SchemaT = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(\n // TODO: shouldn't this be narrowed based on SchemaT?\n arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;\n}\n/**\n * Base interface for the input parameters of the {@link DynamicTool} and\n * {@link DynamicStructuredTool} classes.\n */\nexport interface BaseDynamicToolInput extends ToolParams {\n name: string;\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n/**\n * Interface for the input parameters of the DynamicTool class.\n */\nexport interface DynamicToolInput<ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n func: (input: string, runManager?: CallbackManagerForToolRun, config?: ToolRunnableConfig) => Promise<ToolOutputT>;\n}\n/**\n * Interface for the input parameters of the DynamicStructuredTool class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface DynamicStructuredToolInput<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n /**\n * Tool handler function - the function that will be called when the tool is invoked.\n *\n * @param input - The input to the tool.\n * @param runManager - The run manager for the tool.\n * @param config - The configuration for the tool.\n * @returns The result of the tool.\n */\n func: (input: SchemaOutputT, runManager?: CallbackManagerForToolRun, config?: RunnableConfig) => Promise<ToolOutputT>;\n schema: SchemaT;\n}\n/**\n * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.\n *\n * @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.\n * @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.\n */\nexport declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition | JSONSchema): tool is StructuredToolInterface;\n/**\n * Confirm whether the inputted tool is an instance of `RunnableToolLike`.\n *\n * @param {unknown | undefined} tool The tool to check if it is an instance of `RunnableToolLike`.\n * @returns {tool is RunnableToolLike} Whether the inputted tool is an instance of `RunnableToolLike`.\n */\nexport declare function isRunnableToolLike(tool?: unknown): tool is RunnableToolLike;\n/**\n * Confirm whether or not the tool contains the necessary properties to be considered a `StructuredToolParams`.\n *\n * @param {unknown | undefined} tool The object to check if it is a `StructuredToolParams`.\n * @returns {tool is StructuredToolParams} Whether the inputted object is a `StructuredToolParams`.\n */\nexport declare function isStructuredToolParams(tool?: unknown): tool is StructuredToolParams;\n/**\n * Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams.\n * It returns `is StructuredToolParams` since that is the most minimal interface of the three,\n * while still containing the necessary properties to be passed to a LLM for tool calling.\n *\n * @param {unknown | undefined} tool The tool to check if it is a LangChain tool.\n * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.\n */\nexport declare function isLangChainTool(tool?: unknown): tool is StructuredToolParams;\n"],"mappings":";;;;;;;;;;;KASYgB,cAAAA;;AAAAA,KAEAC,cAAAA,GAFc,GAAA;AAE1B;AAEYC,KAAAA,kBAAAA,GAAkB,CAAIP,cAAAA,EAAAA,GAAc,CAAA;AAOhD;;;;;;AAIID,KAJQS,cAIRT,CAAAA,MAAAA,EAAAA,OAAAA,EAAAA,OAAAA,CAAAA,GAJmDU,OAInDV,SAJmEF,gBAInEE,GAJsFU,OAItFV,GAJgGW,OAIhGX,SAAAA;EAAW,QAAGW,EAAAA;IAIdD,EAAAA,EAAAA,MAAAA;EAAO,CAAA;CAAU,GAJjBV,WAQAU,GARcC,OAQdD,SAAAA;EAAO,QAAGV,EAAAA;IAAcY,EAAAA,EAAAA,SAAAA;EAAM,CAAA;CAAiB,GAJ/CF,OAIkDV,GAJxCW,OAIwCX,SAAAA;EAAW,QAAGU,EAAAA;IAAO,EAAA,CAAA,EAAA,MAAA;EAK/DG,CAAAA;CAAmB,GAL3BH,OAK2B,GALjBV,WAKiB,GALHY,MAKG,SALYb,QAKZ,GALuBC,WAKvB,GALqCU,OAKrC;;;AAA6B;AAI5D;AAA2B,KAJfG,mBAAAA,GAAsBtB,CAAAA,CAAGuB,UAI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;;EAAwC,IAAQF,CAAAA,aApF1BK,uBAoF0BL,CApFFM,OAoFEN,EApFOO,YAoFPP,CAAAA,EAAAA,gBApFsCL,kBAoFtCK,GAAAA,SAAAA,CAAAA,CAAAA,GAAAA,EApF2Ea,IAoF3Eb,EAAAA,SAAAA,CAAAA,EApF6FV,OAoF7FU,EAAuB;EAAiB,IAAGhB,CAAAA,EAAAA,MAAAA,EAAAA,CAAAA,EAlFrE8B,OAkFqE9B,CAlF7DI,cAkF6DJ,CAlF9C6B,IAkF8C7B,EAlFxCM,OAkFwCN,EAlF/B4B,WAkF+B5B,CAAAA,CAAAA;EAAU;AAAkC;AAOvI;EAOwBuC,IAAAA,EAAAA,MAAAA;EASAC;;;;;;;;;;;;;;;;;;UAlFPT,wBAAwBP,sCAAsCJ,yBAAyBE,wBAAwBpB,wBAAwBc,wBAAwBM,SAASC,cAAcK;;;;;;;;;;oBAUjLP,wBAAwBC,SAASC,+BAA+BZ;;OAE7EkB,kBAAkBvB,UAAUwB,QAAQ1B,eAAe4B,YAAYH,OAAOvB,SAASsB;;;;;;UAMvEK,oBAAAA,SAA6BvB;;;;;;;;;;;;;;UAc7BwB,+BAA+BhC,wBAAwB+B;qCACjC9C,oCAAoCwB,uBAAuBmB,QAAQF;;;;;;;;UAQzFO,qCAAqC3B,qCAAqCU,0BAA0BI,wBAAwBpB,wBAAwB+B;;;;;;;;;gBASnJG,4BAA4BjD,oCAAoCG,mBAAmBwC,QAAQF;UACjGN;;;;;;;;iBAQYe,gBAAAA,QAAwBrB,0BAA0B3B,iBAAiBW,0BAAqBgB;;;;;;;iBAOxFsB,kBAAAA,0BAA4C/C;;;;;;;iBAO5CgD,sBAAAA,0BAAgDxB;;;;;;;;;iBAShDyB,eAAAA,0BAAyCzB"}
1
+ {"version":3,"file":"types.d.cts","names":["z","z3","CallbackManagerForToolRun","BaseLangChainParams","ToolDefinition","RunnableConfig","RunnableToolLike","RunnableInterface","DirectToolOutput","ToolCall","ToolMessage","MessageContent","InferInteropZodInput","InferInteropZodOutput","InteropZodType","InteropZodObject","JSONSchema","BaseStore","ResponseFormat","ToolOutputType","ContentAndArtifact","ToolReturnType","TOutput","TConfig","TInput","ToolInputSchemaBase","ZodTypeAny","ToolParams","ToolRunnableConfig","Record","ConfigurableFieldType","ContextSchema","StructuredToolParams","StructuredToolInterface","Pick","ToolInputSchemaOutputType","T","ToolInputSchemaInputType","StructuredToolCallInput","SchemaT","SchemaInputT","StringInputToolSchema","ZodTypeDef","ZodType","ToolCallInput","ToolOutputT","TArg","Promise","ToolInterface","NonNullable","BaseDynamicToolInput","DynamicToolInput","DynamicStructuredToolInput","SchemaOutputT","isStructuredTool","isRunnableToolLike","isStructuredToolParams","isLangChainTool","ToolRuntime","TState","TContext"],"sources":["../../src/tools/types.d.ts"],"sourcesContent":["import type { z as z3 } from \"zod/v3\";\nimport { CallbackManagerForToolRun } from \"../callbacks/manager.js\";\nimport type { BaseLangChainParams, ToolDefinition } from \"../language_models/base.js\";\nimport type { RunnableConfig } from \"../runnables/config.js\";\nimport { RunnableToolLike, type RunnableInterface } from \"../runnables/base.js\";\nimport { type DirectToolOutput, type ToolCall, type ToolMessage } from \"../messages/tool.js\";\nimport type { MessageContent } from \"../messages/base.js\";\nimport { type InferInteropZodInput, type InferInteropZodOutput, type InteropZodType, type InteropZodObject } from \"../utils/types/zod.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\nimport type { BaseStore } from \"../stores.js\";\nexport type ResponseFormat = \"content\" | \"content_and_artifact\" | string;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolOutputType = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ContentAndArtifact = [MessageContent, any];\n/**\n * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.\n * - If the input is a ToolCall, it returns a ToolMessage\n * - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage\n * - Otherwise, it returns the original output type\n */\nexport type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput ? TOutput : TConfig extends {\n toolCall: {\n id: string;\n };\n} ? ToolMessage : TConfig extends {\n toolCall: {\n id: undefined;\n };\n} ? TOutput : TConfig extends {\n toolCall: {\n id?: string;\n };\n} ? TOutput | ToolMessage : TInput extends ToolCall ? ToolMessage : TOutput;\n/**\n * Base type that establishes the types of input schemas that can be used for LangChain tool\n * definitions.\n */\nexport type ToolInputSchemaBase = z3.ZodTypeAny | JSONSchema;\n/**\n * Parameters for the Tool classes.\n */\nexport interface ToolParams extends BaseLangChainParams {\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n /**\n * Whether to show full details in the thrown parsing errors.\n *\n * @default false\n */\n verboseParsingErrors?: boolean;\n /**\n * Metadata for the tool.\n */\n metadata?: Record<string, unknown>;\n}\nexport type ToolRunnableConfig<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfigurableFieldType extends Record<string, any> = Record<string, any>, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nContextSchema = any> = RunnableConfig<ConfigurableFieldType> & {\n toolCall?: ToolCall;\n context?: ContextSchema;\n};\n/**\n * Schema for defining tools.\n *\n * @version 0.2.19\n */\nexport interface StructuredToolParams extends Pick<StructuredToolInterface, \"name\" | \"schema\"> {\n /**\n * An optional description of the tool to pass to the model.\n */\n description?: string;\n}\n/**\n * Utility type that resolves the output type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Utility type that resolves the input type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Defines the type that will be passed into a tool handler function as a result of a tool call.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport type StructuredToolCallInput<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;\n/**\n * An input schema type for tools that accept a single string input.\n *\n * This schema defines a tool that takes an optional string parameter named \"input\".\n * It uses Zod's effects to transform the input and strip any extra properties.\n *\n * This is primarily used for creating simple string-based tools where the LLM\n * only needs to provide a single text value as input to the tool.\n */\nexport type StringInputToolSchema = z3.ZodType<string | undefined, z3.ZodTypeDef, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany>;\n/**\n * Defines the type for input to a tool's call method.\n *\n * This type is a convenience alias for StructuredToolCallInput with the input type\n * derived from the schema. It represents the possible inputs that can be passed to a tool,\n * which can be either:\n * - A string (if the tool accepts string input)\n * - A structured input matching the tool's schema\n * - A ToolCall object (typically from an LLM)\n *\n * @param SchemaT - The schema type for the tool input, defaults to StringInputToolSchema\n */\nexport type ToolCallInput<SchemaT = StringInputToolSchema> = StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;\n/**\n * Interface that defines the shape of a LangChain structured tool.\n *\n * A structured tool is a tool that uses a schema to define the structure of the arguments that the\n * LLM generates as part of its {@link ToolCall}.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface StructuredToolInterface<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {\n lc_namespace: string[];\n /**\n * A Zod schema representing the parameters of the tool.\n */\n schema: SchemaT;\n /**\n * Invokes the tool with the provided argument and configuration.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration for the tool call.\n * @returns A Promise that resolves with the tool's output.\n */\n invoke<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig, \n /** @deprecated */\n tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * The name of the tool.\n */\n name: string;\n /**\n * A description of the tool.\n */\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect: boolean;\n}\n/**\n * A special interface for tools that accept a string input, usually defined with the {@link Tool} class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface ToolInterface<SchemaT = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(\n // TODO: shouldn't this be narrowed based on SchemaT?\n arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;\n}\n/**\n * Base interface for the input parameters of the {@link DynamicTool} and\n * {@link DynamicStructuredTool} classes.\n */\nexport interface BaseDynamicToolInput extends ToolParams {\n name: string;\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n/**\n * Interface for the input parameters of the DynamicTool class.\n */\nexport interface DynamicToolInput<ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n func: (input: string, runManager?: CallbackManagerForToolRun, config?: ToolRunnableConfig) => Promise<ToolOutputT>;\n}\n/**\n * Interface for the input parameters of the DynamicStructuredTool class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface DynamicStructuredToolInput<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n /**\n * Tool handler function - the function that will be called when the tool is invoked.\n *\n * @param input - The input to the tool.\n * @param runManager - The run manager for the tool.\n * @param config - The configuration for the tool.\n * @returns The result of the tool.\n */\n func: (input: SchemaOutputT, runManager?: CallbackManagerForToolRun, config?: RunnableConfig) => Promise<ToolOutputT>;\n schema: SchemaT;\n}\n/**\n * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.\n *\n * @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.\n * @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.\n */\nexport declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition | JSONSchema): tool is StructuredToolInterface;\n/**\n * Confirm whether the inputted tool is an instance of `RunnableToolLike`.\n *\n * @param {unknown | undefined} tool The tool to check if it is an instance of `RunnableToolLike`.\n * @returns {tool is RunnableToolLike} Whether the inputted tool is an instance of `RunnableToolLike`.\n */\nexport declare function isRunnableToolLike(tool?: unknown): tool is RunnableToolLike;\n/**\n * Confirm whether or not the tool contains the necessary properties to be considered a `StructuredToolParams`.\n *\n * @param {unknown | undefined} tool The object to check if it is a `StructuredToolParams`.\n * @returns {tool is StructuredToolParams} Whether the inputted object is a `StructuredToolParams`.\n */\nexport declare function isStructuredToolParams(tool?: unknown): tool is StructuredToolParams;\n/**\n * Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams.\n * It returns `is StructuredToolParams` since that is the most minimal interface of the three,\n * while still containing the necessary properties to be passed to a LLM for tool calling.\n *\n * @param {unknown | undefined} tool The tool to check if it is a LangChain tool.\n * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.\n */\nexport declare function isLangChainTool(tool?: unknown): tool is StructuredToolParams;\n/**\n * Runtime context automatically injected into tools.\n *\n * When a tool function has a parameter named `tool_runtime` with type hint\n * `ToolRuntime`, the tool execution system will automatically inject an instance\n * containing:\n *\n * - `state`: The current graph state\n * - `toolCallId`: The ID of the current tool call\n * - `config`: `RunnableConfig` for the current execution\n * - `context`: Runtime context\n * - `store`: `BaseStore` instance for persistent storage\n * - `writer`: Stream writer for streaming output\n *\n * No `Annotated` wrapper is needed - just use `runtime: ToolRuntime`\n * as a parameter.\n *\n * @example\n * ```typescript\n * import { tool, ToolRuntime } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n *\n * const stateSchema = z.object({\n * messages: z.array(z.any()),\n * userId: z.string().optional(),\n * });\n *\n * const greet = tool(\n * async ({ name }, runtime) => {\n * // Access state\n * const messages = runtime.state.messages;\n *\n * // Access tool_call_id\n * console.log(`Tool call ID: ${runtime.toolCallId}`);\n *\n * // Access config\n * console.log(`Run ID: ${runtime.config.runId}`);\n *\n * // Access runtime context\n * const userId = runtime.context?.userId;\n *\n * // Access store\n * await runtime.store?.mset([[\"key\", \"value\"]]);\n *\n * // Stream output\n * runtime.writer?.(\"Processing...\");\n *\n * return `Hello! User ID: ${runtime.state.userId || \"unknown\"} ${name}`;\n * },\n * {\n * name: \"greet\",\n * description: \"Use this to greet the user once you found their info.\",\n * schema: z.object({ name: z.string() }),\n * stateSchema,\n * }\n * );\n * ```\n *\n * @template StateT - The type of the state schema (inferred from stateSchema)\n * @template ContextT - The type of the context schema (inferred from contextSchema)\n */\nexport type ToolRuntime<TState = unknown, TContext = unknown> = RunnableConfig & {\n /**\n * The current graph state.\n */\n state: TState extends InteropZodObject ? InferInteropZodOutput<TState> : TState extends Record<string, unknown> ? TState : unknown;\n /**\n * The ID of the current tool call.\n */\n toolCallId: string;\n /**\n * The current tool call.\n */\n toolCall?: ToolCall;\n /**\n * RunnableConfig for the current execution.\n */\n config: ToolRunnableConfig;\n /**\n * Runtime context (from langgraph `Runtime`).\n */\n context: TContext extends InteropZodObject ? InferInteropZodOutput<TContext> : TContext extends Record<string, unknown> ? TContext : unknown;\n /**\n * BaseStore instance for persistent storage (from langgraph `Runtime`).\n */\n store: BaseStore<string, unknown> | null;\n /**\n * Stream writer for streaming output (from langgraph `Runtime`).\n */\n writer: ((chunk: unknown) => void) | null;\n};\n"],"mappings":";;;;;;;;;;;;KAUYkB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AA,OAAAA;;;;;;;;AAgBlB9B,UApKnFmB,aAoKmFnB,CAAAA,UApK3DY,qBAoK2DZ,EAAAA,eApKrBQ,wBAoKqBR,CApKIU,OAoKJV,CAAAA,EAAAA,cApK4BV,cAoK5BU,CAAAA,SApKoDI,uBAoKpDJ,CApK4EU,OAoK5EV,EApKqFW,YAoKrFX,EApKmGgB,WAoKnGhB,CAAAA,CAAAA;EAAM;;AAItF;;;;;;;oBA9JES,wBAAwBC,SAASC,+BAA+BZ;;OAE7EkB,kBAAkBvB,UAAUwB,QAAQ1B,eAAe4B,YAAYH,OAAOvB,SAASsB;;;;;;UAMvEK,oBAAAA,SAA6BvB;;;;;;;;;;;;;;UAc7BwB,+BAA+BhC,wBAAwB+B;qCACjChD,oCAAoC0B,uBAAuBmB,QAAQF;;;;;;;;UAQzFO,qCAAqC3B,qCAAqCU,0BAA0BI,wBAAwBpB,wBAAwB+B;;;;;;;;;gBASnJG,4BAA4BnD,oCAAoCG,mBAAmB0C,QAAQF;UACjGN;;;;;;;;iBAQYe,gBAAAA,QAAwBrB,0BAA0B7B,iBAAiBY,0BAAqBiB;;;;;;;iBAOxFsB,kBAAAA,0BAA4CjD;;;;;;;iBAO5CkD,sBAAAA,0BAAgDxB;;;;;;;;;iBAShDyB,eAAAA,0BAAyCzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8DrD0B,oDAAoDrD;;;;SAIrDsD,eAAe5C,mBAAmBF,sBAAsB8C,UAAUA,eAAe9B,0BAA0B8B;;;;;;;;aAQvGlD;;;;UAIHmB;;;;WAICgC,iBAAiB7C,mBAAmBF,sBAAsB+C,YAAYA,iBAAiB/B,0BAA0B+B;;;;SAInH3C"}
@@ -1,11 +1,12 @@
1
1
  import { MessageContent } from "../messages/base.js";
2
2
  import { DirectToolOutput, ToolCall, ToolMessage } from "../messages/tool.js";
3
- import { InferInteropZodInput, InferInteropZodOutput, InteropZodType } from "../utils/types/zod.js";
3
+ import { InferInteropZodInput, InferInteropZodOutput, InteropZodObject, InteropZodType } from "../utils/types/zod.js";
4
4
  import { CallbackManagerForToolRun } from "../callbacks/manager.js";
5
5
  import { RunnableConfig, RunnableInterface } from "../runnables/types.js";
6
6
  import { RunnableToolLike } from "../runnables/base.js";
7
7
  import { JsonSchema7Type } from "../utils/zod-to-json-schema/parseTypes.js";
8
8
  import { BaseLangChainParams, ToolDefinition } from "../language_models/base.js";
9
+ import { BaseStore } from "../stores.js";
9
10
  import { z } from "zod/v3";
10
11
 
11
12
  //#region src/tools/types.d.ts
@@ -282,6 +283,97 @@ declare function isStructuredToolParams(tool?: unknown): tool is StructuredToolP
282
283
  * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.
283
284
  */
284
285
  declare function isLangChainTool(tool?: unknown): tool is StructuredToolParams;
286
+ /**
287
+ * Runtime context automatically injected into tools.
288
+ *
289
+ * When a tool function has a parameter named `tool_runtime` with type hint
290
+ * `ToolRuntime`, the tool execution system will automatically inject an instance
291
+ * containing:
292
+ *
293
+ * - `state`: The current graph state
294
+ * - `toolCallId`: The ID of the current tool call
295
+ * - `config`: `RunnableConfig` for the current execution
296
+ * - `context`: Runtime context
297
+ * - `store`: `BaseStore` instance for persistent storage
298
+ * - `writer`: Stream writer for streaming output
299
+ *
300
+ * No `Annotated` wrapper is needed - just use `runtime: ToolRuntime`
301
+ * as a parameter.
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * import { tool, ToolRuntime } from "@langchain/core/tools";
306
+ * import { z } from "zod";
307
+ *
308
+ * const stateSchema = z.object({
309
+ * messages: z.array(z.any()),
310
+ * userId: z.string().optional(),
311
+ * });
312
+ *
313
+ * const greet = tool(
314
+ * async ({ name }, runtime) => {
315
+ * // Access state
316
+ * const messages = runtime.state.messages;
317
+ *
318
+ * // Access tool_call_id
319
+ * console.log(`Tool call ID: ${runtime.toolCallId}`);
320
+ *
321
+ * // Access config
322
+ * console.log(`Run ID: ${runtime.config.runId}`);
323
+ *
324
+ * // Access runtime context
325
+ * const userId = runtime.context?.userId;
326
+ *
327
+ * // Access store
328
+ * await runtime.store?.mset([["key", "value"]]);
329
+ *
330
+ * // Stream output
331
+ * runtime.writer?.("Processing...");
332
+ *
333
+ * return `Hello! User ID: ${runtime.state.userId || "unknown"} ${name}`;
334
+ * },
335
+ * {
336
+ * name: "greet",
337
+ * description: "Use this to greet the user once you found their info.",
338
+ * schema: z.object({ name: z.string() }),
339
+ * stateSchema,
340
+ * }
341
+ * );
342
+ * ```
343
+ *
344
+ * @template StateT - The type of the state schema (inferred from stateSchema)
345
+ * @template ContextT - The type of the context schema (inferred from contextSchema)
346
+ */
347
+ type ToolRuntime<TState = unknown, TContext = unknown> = RunnableConfig & {
348
+ /**
349
+ * The current graph state.
350
+ */
351
+ state: TState extends InteropZodObject ? InferInteropZodOutput<TState> : TState extends Record<string, unknown> ? TState : unknown;
352
+ /**
353
+ * The ID of the current tool call.
354
+ */
355
+ toolCallId: string;
356
+ /**
357
+ * The current tool call.
358
+ */
359
+ toolCall?: ToolCall;
360
+ /**
361
+ * RunnableConfig for the current execution.
362
+ */
363
+ config: ToolRunnableConfig;
364
+ /**
365
+ * Runtime context (from langgraph `Runtime`).
366
+ */
367
+ context: TContext extends InteropZodObject ? InferInteropZodOutput<TContext> : TContext extends Record<string, unknown> ? TContext : unknown;
368
+ /**
369
+ * BaseStore instance for persistent storage (from langgraph `Runtime`).
370
+ */
371
+ store: BaseStore<string, unknown> | null;
372
+ /**
373
+ * Stream writer for streaming output (from langgraph `Runtime`).
374
+ */
375
+ writer: ((chunk: unknown) => void) | null;
376
+ };
285
377
  //#endregion
286
- export { BaseDynamicToolInput, ContentAndArtifact, DynamicStructuredToolInput, DynamicToolInput, ResponseFormat, StringInputToolSchema, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInputSchemaBase, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolInterface, ToolOutputType, ToolParams, ToolReturnType, ToolRunnableConfig, isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams };
378
+ export { BaseDynamicToolInput, ContentAndArtifact, DynamicStructuredToolInput, DynamicToolInput, ResponseFormat, StringInputToolSchema, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInputSchemaBase, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolInterface, ToolOutputType, ToolParams, ToolReturnType, ToolRunnableConfig, ToolRuntime, isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams };
287
379
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":["z","z3","CallbackManagerForToolRun","BaseLangChainParams","ToolDefinition","RunnableConfig","RunnableToolLike","RunnableInterface","DirectToolOutput","ToolCall","ToolMessage","MessageContent","InferInteropZodInput","InferInteropZodOutput","InteropZodType","JSONSchema","ResponseFormat","ToolOutputType","ContentAndArtifact","ToolReturnType","TOutput","TConfig","TInput","ToolInputSchemaBase","ZodTypeAny","ToolParams","ToolRunnableConfig","Record","ConfigurableFieldType","ContextSchema","StructuredToolParams","StructuredToolInterface","Pick","ToolInputSchemaOutputType","T","ToolInputSchemaInputType","StructuredToolCallInput","SchemaT","SchemaInputT","StringInputToolSchema","ZodTypeDef","ZodType","ToolCallInput","ToolOutputT","TArg","Promise","ToolInterface","NonNullable","BaseDynamicToolInput","DynamicToolInput","DynamicStructuredToolInput","SchemaOutputT","isStructuredTool","isRunnableToolLike","isStructuredToolParams","isLangChainTool"],"sources":["../../src/tools/types.d.ts"],"sourcesContent":["import type { z as z3 } from \"zod/v3\";\nimport { CallbackManagerForToolRun } from \"../callbacks/manager.js\";\nimport type { BaseLangChainParams, ToolDefinition } from \"../language_models/base.js\";\nimport type { RunnableConfig } from \"../runnables/config.js\";\nimport { RunnableToolLike, type RunnableInterface } from \"../runnables/base.js\";\nimport { type DirectToolOutput, type ToolCall, type ToolMessage } from \"../messages/tool.js\";\nimport type { MessageContent } from \"../messages/base.js\";\nimport { type InferInteropZodInput, type InferInteropZodOutput, type InteropZodType } from \"../utils/types/zod.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\nexport type ResponseFormat = \"content\" | \"content_and_artifact\" | string;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolOutputType = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ContentAndArtifact = [MessageContent, any];\n/**\n * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.\n * - If the input is a ToolCall, it returns a ToolMessage\n * - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage\n * - Otherwise, it returns the original output type\n */\nexport type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput ? TOutput : TConfig extends {\n toolCall: {\n id: string;\n };\n} ? ToolMessage : TConfig extends {\n toolCall: {\n id: undefined;\n };\n} ? TOutput : TConfig extends {\n toolCall: {\n id?: string;\n };\n} ? TOutput | ToolMessage : TInput extends ToolCall ? ToolMessage : TOutput;\n/**\n * Base type that establishes the types of input schemas that can be used for LangChain tool\n * definitions.\n */\nexport type ToolInputSchemaBase = z3.ZodTypeAny | JSONSchema;\n/**\n * Parameters for the Tool classes.\n */\nexport interface ToolParams extends BaseLangChainParams {\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n /**\n * Whether to show full details in the thrown parsing errors.\n *\n * @default false\n */\n verboseParsingErrors?: boolean;\n /**\n * Metadata for the tool.\n */\n metadata?: Record<string, unknown>;\n}\nexport type ToolRunnableConfig<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfigurableFieldType extends Record<string, any> = Record<string, any>, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nContextSchema = any> = RunnableConfig<ConfigurableFieldType> & {\n toolCall?: ToolCall;\n context?: ContextSchema;\n};\n/**\n * Schema for defining tools.\n *\n * @version 0.2.19\n */\nexport interface StructuredToolParams extends Pick<StructuredToolInterface, \"name\" | \"schema\"> {\n /**\n * An optional description of the tool to pass to the model.\n */\n description?: string;\n}\n/**\n * Utility type that resolves the output type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Utility type that resolves the input type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Defines the type that will be passed into a tool handler function as a result of a tool call.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport type StructuredToolCallInput<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;\n/**\n * An input schema type for tools that accept a single string input.\n *\n * This schema defines a tool that takes an optional string parameter named \"input\".\n * It uses Zod's effects to transform the input and strip any extra properties.\n *\n * This is primarily used for creating simple string-based tools where the LLM\n * only needs to provide a single text value as input to the tool.\n */\nexport type StringInputToolSchema = z3.ZodType<string | undefined, z3.ZodTypeDef, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany>;\n/**\n * Defines the type for input to a tool's call method.\n *\n * This type is a convenience alias for StructuredToolCallInput with the input type\n * derived from the schema. It represents the possible inputs that can be passed to a tool,\n * which can be either:\n * - A string (if the tool accepts string input)\n * - A structured input matching the tool's schema\n * - A ToolCall object (typically from an LLM)\n *\n * @param SchemaT - The schema type for the tool input, defaults to StringInputToolSchema\n */\nexport type ToolCallInput<SchemaT = StringInputToolSchema> = StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;\n/**\n * Interface that defines the shape of a LangChain structured tool.\n *\n * A structured tool is a tool that uses a schema to define the structure of the arguments that the\n * LLM generates as part of its {@link ToolCall}.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface StructuredToolInterface<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {\n lc_namespace: string[];\n /**\n * A Zod schema representing the parameters of the tool.\n */\n schema: SchemaT;\n /**\n * Invokes the tool with the provided argument and configuration.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration for the tool call.\n * @returns A Promise that resolves with the tool's output.\n */\n invoke<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig, \n /** @deprecated */\n tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * The name of the tool.\n */\n name: string;\n /**\n * A description of the tool.\n */\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect: boolean;\n}\n/**\n * A special interface for tools that accept a string input, usually defined with the {@link Tool} class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface ToolInterface<SchemaT = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(\n // TODO: shouldn't this be narrowed based on SchemaT?\n arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;\n}\n/**\n * Base interface for the input parameters of the {@link DynamicTool} and\n * {@link DynamicStructuredTool} classes.\n */\nexport interface BaseDynamicToolInput extends ToolParams {\n name: string;\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n/**\n * Interface for the input parameters of the DynamicTool class.\n */\nexport interface DynamicToolInput<ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n func: (input: string, runManager?: CallbackManagerForToolRun, config?: ToolRunnableConfig) => Promise<ToolOutputT>;\n}\n/**\n * Interface for the input parameters of the DynamicStructuredTool class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface DynamicStructuredToolInput<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n /**\n * Tool handler function - the function that will be called when the tool is invoked.\n *\n * @param input - The input to the tool.\n * @param runManager - The run manager for the tool.\n * @param config - The configuration for the tool.\n * @returns The result of the tool.\n */\n func: (input: SchemaOutputT, runManager?: CallbackManagerForToolRun, config?: RunnableConfig) => Promise<ToolOutputT>;\n schema: SchemaT;\n}\n/**\n * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.\n *\n * @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.\n * @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.\n */\nexport declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition | JSONSchema): tool is StructuredToolInterface;\n/**\n * Confirm whether the inputted tool is an instance of `RunnableToolLike`.\n *\n * @param {unknown | undefined} tool The tool to check if it is an instance of `RunnableToolLike`.\n * @returns {tool is RunnableToolLike} Whether the inputted tool is an instance of `RunnableToolLike`.\n */\nexport declare function isRunnableToolLike(tool?: unknown): tool is RunnableToolLike;\n/**\n * Confirm whether or not the tool contains the necessary properties to be considered a `StructuredToolParams`.\n *\n * @param {unknown | undefined} tool The object to check if it is a `StructuredToolParams`.\n * @returns {tool is StructuredToolParams} Whether the inputted object is a `StructuredToolParams`.\n */\nexport declare function isStructuredToolParams(tool?: unknown): tool is StructuredToolParams;\n/**\n * Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams.\n * It returns `is StructuredToolParams` since that is the most minimal interface of the three,\n * while still containing the necessary properties to be passed to a LLM for tool calling.\n *\n * @param {unknown | undefined} tool The tool to check if it is a LangChain tool.\n * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.\n */\nexport declare function isLangChainTool(tool?: unknown): tool is StructuredToolParams;\n"],"mappings":";;;;;;;;;;;KASYgB,cAAAA;;AAAAA,KAEAC,cAAAA,GAFc,GAAA;AAE1B;AAEYC,KAAAA,kBAAAA,GAAkB,CAAIP,cAAAA,EAAAA,GAAc,CAAA;AAOhD;;;;;;AAIID,KAJQS,cAIRT,CAAAA,MAAAA,EAAAA,OAAAA,EAAAA,OAAAA,CAAAA,GAJmDU,OAInDV,SAJmEF,gBAInEE,GAJsFU,OAItFV,GAJgGW,OAIhGX,SAAAA;EAAW,QAAGW,EAAAA;IAIdD,EAAAA,EAAAA,MAAAA;EAAO,CAAA;CAAU,GAJjBV,WAQAU,GARcC,OAQdD,SAAAA;EAAO,QAAGV,EAAAA;IAAcY,EAAAA,EAAAA,SAAAA;EAAM,CAAA;CAAiB,GAJ/CF,OAIkDV,GAJxCW,OAIwCX,SAAAA;EAAW,QAAGU,EAAAA;IAAO,EAAA,CAAA,EAAA,MAAA;EAK/DG,CAAAA;CAAmB,GAL3BH,OAK2B,GALjBV,WAKiB,GALHY,MAKG,SALYb,QAKZ,GALuBC,WAKvB,GALqCU,OAKrC;;;AAA6B;AAI5D;AAA2B,KAJfG,mBAAAA,GAAsBtB,CAAAA,CAAGuB,UAIV,GAJuBT,eAIvB;;;;AAASZ,UAAnBsB,UAAAA,SAAmBtB,mBAAAA,CAAAA;EAAmB;AA0BvD;;;;;;;;EAM2B,cAAA,CAAA,EAtBNa,cAsBM;EAOVc;;;EAAyD,aAA5BE,CAAAA,EAzB1BN,kBAyB0BM;EAAI;AAiBlD;;;;EAAmE,oBAAyBE,CAAAA,EAAAA,OAAAA;EAAC;;;EAAwB,QAAA,CAAA,EAhCtGP,MA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FqE9B,CAlF7DI,cAkF6DJ,CAlF9C6B,IAkF8C7B,EAlFxCM,OAkFwCN,EAlF/B4B,WAkF+B5B,CAAAA,CAAAA;EAAU;AAAkC;AAOvI;EAOwBuC,IAAAA,EAAAA,MAAAA;EASAC;;;;;;;;;;;;;;;;;;UAlFPT,wBAAwBP,sCAAsCJ,yBAAyBE,wBAAwBpB,wBAAwBc,wBAAwBM,SAASC,cAAcK;;;;;;;;;;oBAUjLP,wBAAwBC,SAASC,+BAA+BZ;;OAE7EkB,kBAAkBvB,UAAUwB,QAAQ1B,eAAe4B,YAAYH,OAAOvB,SAASsB;;;;;;UAMvEK,oBAAAA,SAA6BvB;;;;;;;;;;;;;;UAc7BwB,+BAA+BhC,wBAAwB+B;qCACjC9C,oCAAoCwB,uBAAuBmB,QAAQF;;;;;;;;UAQzFO,qCAAqC3B,qCAAqCU,0BAA0BI,wBAAwBpB,wBAAwB+B;;;;;;;;;gBASnJG,4BAA4BjD,oCAAoCG,mBAAmBwC,QAAQF;UACjGN;;;;;;;;iBAQYe,gBAAAA,QAAwBrB,0BAA0B3B,iBAAiBW,0BAAqBgB;;;;;;;iBAOxFsB,kBAAAA,0BAA4C/C;;;;;;;iBAO5CgD,sBAAAA,0BAAgDxB;;;;;;;;;iBAShDyB,eAAAA,0BAAyCzB"}
1
+ {"version":3,"file":"types.d.ts","names":["z","z3","CallbackManagerForToolRun","BaseLangChainParams","ToolDefinition","RunnableConfig","RunnableToolLike","RunnableInterface","DirectToolOutput","ToolCall","ToolMessage","MessageContent","InferInteropZodInput","InferInteropZodOutput","InteropZodType","InteropZodObject","JSONSchema","BaseStore","ResponseFormat","ToolOutputType","ContentAndArtifact","ToolReturnType","TOutput","TConfig","TInput","ToolInputSchemaBase","ZodTypeAny","ToolParams","ToolRunnableConfig","Record","ConfigurableFieldType","ContextSchema","StructuredToolParams","StructuredToolInterface","Pick","ToolInputSchemaOutputType","T","ToolInputSchemaInputType","StructuredToolCallInput","SchemaT","SchemaInputT","StringInputToolSchema","ZodTypeDef","ZodType","ToolCallInput","ToolOutputT","TArg","Promise","ToolInterface","NonNullable","BaseDynamicToolInput","DynamicToolInput","DynamicStructuredToolInput","SchemaOutputT","isStructuredTool","isRunnableToolLike","isStructuredToolParams","isLangChainTool","ToolRuntime","TState","TContext"],"sources":["../../src/tools/types.d.ts"],"sourcesContent":["import type { z as z3 } from \"zod/v3\";\nimport { CallbackManagerForToolRun } from \"../callbacks/manager.js\";\nimport type { BaseLangChainParams, ToolDefinition } from \"../language_models/base.js\";\nimport type { RunnableConfig } from \"../runnables/config.js\";\nimport { RunnableToolLike, type RunnableInterface } from \"../runnables/base.js\";\nimport { type DirectToolOutput, type ToolCall, type ToolMessage } from \"../messages/tool.js\";\nimport type { MessageContent } from \"../messages/base.js\";\nimport { type InferInteropZodInput, type InferInteropZodOutput, type InteropZodType, type InteropZodObject } from \"../utils/types/zod.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\nimport type { BaseStore } from \"../stores.js\";\nexport type ResponseFormat = \"content\" | \"content_and_artifact\" | string;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolOutputType = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ContentAndArtifact = [MessageContent, any];\n/**\n * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.\n * - If the input is a ToolCall, it returns a ToolMessage\n * - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage\n * - Otherwise, it returns the original output type\n */\nexport type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput ? TOutput : TConfig extends {\n toolCall: {\n id: string;\n };\n} ? ToolMessage : TConfig extends {\n toolCall: {\n id: undefined;\n };\n} ? TOutput : TConfig extends {\n toolCall: {\n id?: string;\n };\n} ? TOutput | ToolMessage : TInput extends ToolCall ? ToolMessage : TOutput;\n/**\n * Base type that establishes the types of input schemas that can be used for LangChain tool\n * definitions.\n */\nexport type ToolInputSchemaBase = z3.ZodTypeAny | JSONSchema;\n/**\n * Parameters for the Tool classes.\n */\nexport interface ToolParams extends BaseLangChainParams {\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n /**\n * Whether to show full details in the thrown parsing errors.\n *\n * @default false\n */\n verboseParsingErrors?: boolean;\n /**\n * Metadata for the tool.\n */\n metadata?: Record<string, unknown>;\n}\nexport type ToolRunnableConfig<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfigurableFieldType extends Record<string, any> = Record<string, any>, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nContextSchema = any> = RunnableConfig<ConfigurableFieldType> & {\n toolCall?: ToolCall;\n context?: ContextSchema;\n};\n/**\n * Schema for defining tools.\n *\n * @version 0.2.19\n */\nexport interface StructuredToolParams extends Pick<StructuredToolInterface, \"name\" | \"schema\"> {\n /**\n * An optional description of the tool to pass to the model.\n */\n description?: string;\n}\n/**\n * Utility type that resolves the output type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Utility type that resolves the input type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JSONSchema ? unknown : never;\n/**\n * Defines the type that will be passed into a tool handler function as a result of a tool call.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport type StructuredToolCallInput<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;\n/**\n * An input schema type for tools that accept a single string input.\n *\n * This schema defines a tool that takes an optional string parameter named \"input\".\n * It uses Zod's effects to transform the input and strip any extra properties.\n *\n * This is primarily used for creating simple string-based tools where the LLM\n * only needs to provide a single text value as input to the tool.\n */\nexport type StringInputToolSchema = z3.ZodType<string | undefined, z3.ZodTypeDef, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany>;\n/**\n * Defines the type for input to a tool's call method.\n *\n * This type is a convenience alias for StructuredToolCallInput with the input type\n * derived from the schema. It represents the possible inputs that can be passed to a tool,\n * which can be either:\n * - A string (if the tool accepts string input)\n * - A structured input matching the tool's schema\n * - A ToolCall object (typically from an LLM)\n *\n * @param SchemaT - The schema type for the tool input, defaults to StringInputToolSchema\n */\nexport type ToolCallInput<SchemaT = StringInputToolSchema> = StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;\n/**\n * Interface that defines the shape of a LangChain structured tool.\n *\n * A structured tool is a tool that uses a schema to define the structure of the arguments that the\n * LLM generates as part of its {@link ToolCall}.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface StructuredToolInterface<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {\n lc_namespace: string[];\n /**\n * A Zod schema representing the parameters of the tool.\n */\n schema: SchemaT;\n /**\n * Invokes the tool with the provided argument and configuration.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration for the tool call.\n * @returns A Promise that resolves with the tool's output.\n */\n invoke<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig, \n /** @deprecated */\n tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n /**\n * The name of the tool.\n */\n name: string;\n /**\n * A description of the tool.\n */\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect: boolean;\n}\n/**\n * A special interface for tools that accept a string input, usually defined with the {@link Tool} class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface ToolInterface<SchemaT = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(\n // TODO: shouldn't this be narrowed based on SchemaT?\n arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;\n}\n/**\n * Base interface for the input parameters of the {@link DynamicTool} and\n * {@link DynamicStructuredTool} classes.\n */\nexport interface BaseDynamicToolInput extends ToolParams {\n name: string;\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n/**\n * Interface for the input parameters of the DynamicTool class.\n */\nexport interface DynamicToolInput<ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n func: (input: string, runManager?: CallbackManagerForToolRun, config?: ToolRunnableConfig) => Promise<ToolOutputT>;\n}\n/**\n * Interface for the input parameters of the DynamicStructuredTool class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface DynamicStructuredToolInput<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {\n /**\n * Tool handler function - the function that will be called when the tool is invoked.\n *\n * @param input - The input to the tool.\n * @param runManager - The run manager for the tool.\n * @param config - The configuration for the tool.\n * @returns The result of the tool.\n */\n func: (input: SchemaOutputT, runManager?: CallbackManagerForToolRun, config?: RunnableConfig) => Promise<ToolOutputT>;\n schema: SchemaT;\n}\n/**\n * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.\n *\n * @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.\n * @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.\n */\nexport declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition | JSONSchema): tool is StructuredToolInterface;\n/**\n * Confirm whether the inputted tool is an instance of `RunnableToolLike`.\n *\n * @param {unknown | undefined} tool The tool to check if it is an instance of `RunnableToolLike`.\n * @returns {tool is RunnableToolLike} Whether the inputted tool is an instance of `RunnableToolLike`.\n */\nexport declare function isRunnableToolLike(tool?: unknown): tool is RunnableToolLike;\n/**\n * Confirm whether or not the tool contains the necessary properties to be considered a `StructuredToolParams`.\n *\n * @param {unknown | undefined} tool The object to check if it is a `StructuredToolParams`.\n * @returns {tool is StructuredToolParams} Whether the inputted object is a `StructuredToolParams`.\n */\nexport declare function isStructuredToolParams(tool?: unknown): tool is StructuredToolParams;\n/**\n * Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams.\n * It returns `is StructuredToolParams` since that is the most minimal interface of the three,\n * while still containing the necessary properties to be passed to a LLM for tool calling.\n *\n * @param {unknown | undefined} tool The tool to check if it is a LangChain tool.\n * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.\n */\nexport declare function isLangChainTool(tool?: unknown): tool is StructuredToolParams;\n/**\n * Runtime context automatically injected into tools.\n *\n * When a tool function has a parameter named `tool_runtime` with type hint\n * `ToolRuntime`, the tool execution system will automatically inject an instance\n * containing:\n *\n * - `state`: The current graph state\n * - `toolCallId`: The ID of the current tool call\n * - `config`: `RunnableConfig` for the current execution\n * - `context`: Runtime context\n * - `store`: `BaseStore` instance for persistent storage\n * - `writer`: Stream writer for streaming output\n *\n * No `Annotated` wrapper is needed - just use `runtime: ToolRuntime`\n * as a parameter.\n *\n * @example\n * ```typescript\n * import { tool, ToolRuntime } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n *\n * const stateSchema = z.object({\n * messages: z.array(z.any()),\n * userId: z.string().optional(),\n * });\n *\n * const greet = tool(\n * async ({ name }, runtime) => {\n * // Access state\n * const messages = runtime.state.messages;\n *\n * // Access tool_call_id\n * console.log(`Tool call ID: ${runtime.toolCallId}`);\n *\n * // Access config\n * console.log(`Run ID: ${runtime.config.runId}`);\n *\n * // Access runtime context\n * const userId = runtime.context?.userId;\n *\n * // Access store\n * await runtime.store?.mset([[\"key\", \"value\"]]);\n *\n * // Stream output\n * runtime.writer?.(\"Processing...\");\n *\n * return `Hello! User ID: ${runtime.state.userId || \"unknown\"} ${name}`;\n * },\n * {\n * name: \"greet\",\n * description: \"Use this to greet the user once you found their info.\",\n * schema: z.object({ name: z.string() }),\n * stateSchema,\n * }\n * );\n * ```\n *\n * @template StateT - The type of the state schema (inferred from stateSchema)\n * @template ContextT - The type of the context schema (inferred from contextSchema)\n */\nexport type ToolRuntime<TState = unknown, TContext = unknown> = RunnableConfig & {\n /**\n * The current graph state.\n */\n state: TState extends InteropZodObject ? InferInteropZodOutput<TState> : TState extends Record<string, unknown> ? TState : unknown;\n /**\n * The ID of the current tool call.\n */\n toolCallId: string;\n /**\n * The current tool call.\n */\n toolCall?: ToolCall;\n /**\n * RunnableConfig for the current execution.\n */\n config: ToolRunnableConfig;\n /**\n * Runtime context (from langgraph `Runtime`).\n */\n context: TContext extends InteropZodObject ? InferInteropZodOutput<TContext> : TContext extends Record<string, unknown> ? TContext : unknown;\n /**\n * BaseStore instance for persistent storage (from langgraph `Runtime`).\n */\n store: BaseStore<string, unknown> | null;\n /**\n * Stream writer for streaming output (from langgraph `Runtime`).\n */\n writer: ((chunk: unknown) => void) | null;\n};\n"],"mappings":";;;;;;;;;;;;KAUYkB,cAAAA;;AAAAA,KAEAC,cAAAA,GAFc,GAAA;AAE1B;AAEYC,KAAAA,kBAAAA,GAAkB,CAAIT,cAAAA,EAAAA,GAAc,CAAA;AAOhD;;;;;;AAIID,KAJQW,cAIRX,CAAAA,MAAAA,EAAAA,OAAAA,EAAAA,OAAAA,CAAAA,GAJmDY,OAInDZ,SAJmEF,gBAInEE,GAJsFY,OAItFZ,GAJgGa,OAIhGb,SAAAA;EAAW,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ES,wBAAwBC,SAASC,+BAA+BZ;;OAE7EkB,kBAAkBvB,UAAUwB,QAAQ1B,eAAe4B,YAAYH,OAAOvB,SAASsB;;;;;;UAMvEK,oBAAAA,SAA6BvB;;;;;;;;;;;;;;UAc7BwB,+BAA+BhC,wBAAwB+B;qCACjChD,oCAAoC0B,uBAAuBmB,QAAQF;;;;;;;;UAQzFO,qCAAqC3B,qCAAqCU,0BAA0BI,wBAAwBpB,wBAAwB+B;;;;;;;;;gBASnJG,4BAA4BnD,oCAAoCG,mBAAmB0C,QAAQF;UACjGN;;;;;;;;iBAQYe,gBAAAA,QAAwBrB,0BAA0B7B,iBAAiBY,0BAAqBiB;;;;;;;iBAOxFsB,kBAAAA,0BAA4CjD;;;;;;;iBAO5CkD,sBAAAA,0BAAgDxB;;;;;;;;;iBAShDyB,eAAAA,0BAAyCzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8DrD0B,oDAAoDrD;;;;SAIrDsD,eAAe5C,mBAAmBF,sBAAsB8C,UAAUA,eAAe9B,0BAA0B8B;;;;;;;;aAQvGlD;;;;UAIHmB;;;;WAICgC,iBAAiB7C,mBAAmBF,sBAAsB+C,YAAYA,iBAAiB/B,0BAA0B+B;;;;SAInH3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":["tool?: StructuredToolInterface | ToolDefinition | JSONSchema","tool?: unknown"],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type { z as z3 } from \"zod/v3\";\nimport { CallbackManagerForToolRun } from \"../callbacks/manager.js\";\nimport type {\n BaseLangChainParams,\n ToolDefinition,\n} from \"../language_models/base.js\";\nimport type { RunnableConfig } from \"../runnables/config.js\";\nimport {\n Runnable,\n RunnableToolLike,\n type RunnableInterface,\n} from \"../runnables/base.js\";\nimport {\n type DirectToolOutput,\n type ToolCall,\n type ToolMessage,\n} from \"../messages/tool.js\";\nimport type { MessageContent } from \"../messages/base.js\";\nimport {\n type InferInteropZodInput,\n type InferInteropZodOutput,\n type InteropZodType,\n isInteropZodSchema,\n} from \"../utils/types/zod.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\n\nexport type ResponseFormat = \"content\" | \"content_and_artifact\" | string;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolOutputType = any;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ContentAndArtifact = [MessageContent, any];\n\n/**\n * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.\n * - If the input is a ToolCall, it returns a ToolMessage\n * - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage\n * - Otherwise, it returns the original output type\n */\nexport type ToolReturnType<TInput, TConfig, TOutput> =\n TOutput extends DirectToolOutput\n ? TOutput\n : TConfig extends { toolCall: { id: string } }\n ? ToolMessage\n : TConfig extends { toolCall: { id: undefined } }\n ? TOutput\n : TConfig extends { toolCall: { id?: string } }\n ? TOutput | ToolMessage\n : TInput extends ToolCall\n ? ToolMessage\n : TOutput;\n\n/**\n * Base type that establishes the types of input schemas that can be used for LangChain tool\n * definitions.\n */\nexport type ToolInputSchemaBase = z3.ZodTypeAny | JSONSchema;\n\n/**\n * Parameters for the Tool classes.\n */\nexport interface ToolParams extends BaseLangChainParams {\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n /**\n * Whether to show full details in the thrown parsing errors.\n *\n * @default false\n */\n verboseParsingErrors?: boolean;\n /**\n * Metadata for the tool.\n */\n metadata?: Record<string, unknown>;\n}\n\nexport type ToolRunnableConfig<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ConfigurableFieldType extends Record<string, any> = Record<string, any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ContextSchema = any\n> = RunnableConfig<ConfigurableFieldType> & {\n toolCall?: ToolCall;\n context?: ContextSchema;\n};\n\n/**\n * Schema for defining tools.\n *\n * @version 0.2.19\n */\nexport interface StructuredToolParams\n extends Pick<StructuredToolInterface, \"name\" | \"schema\"> {\n /**\n * An optional description of the tool to pass to the model.\n */\n description?: string;\n}\n\n/**\n * Utility type that resolves the output type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaOutputType<T> = T extends InteropZodType\n ? InferInteropZodOutput<T>\n : T extends JSONSchema\n ? unknown\n : never;\n\n/**\n * Utility type that resolves the input type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaInputType<T> = T extends InteropZodType\n ? InferInteropZodInput<T>\n : T extends JSONSchema\n ? unknown\n : never;\n\n/**\n * Defines the type that will be passed into a tool handler function as a result of a tool call.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport type StructuredToolCallInput<\n SchemaT = ToolInputSchemaBase,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>\n> =\n | (ToolInputSchemaOutputType<SchemaT> extends string ? string : never)\n | SchemaInputT\n | ToolCall;\n\n/**\n * An input schema type for tools that accept a single string input.\n *\n * This schema defines a tool that takes an optional string parameter named \"input\".\n * It uses Zod's effects to transform the input and strip any extra properties.\n *\n * This is primarily used for creating simple string-based tools where the LLM\n * only needs to provide a single text value as input to the tool.\n */\nexport type StringInputToolSchema = z3.ZodType<\n string | undefined,\n z3.ZodTypeDef,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * Defines the type for input to a tool's call method.\n *\n * This type is a convenience alias for StructuredToolCallInput with the input type\n * derived from the schema. It represents the possible inputs that can be passed to a tool,\n * which can be either:\n * - A string (if the tool accepts string input)\n * - A structured input matching the tool's schema\n * - A ToolCall object (typically from an LLM)\n *\n * @param SchemaT - The schema type for the tool input, defaults to StringInputToolSchema\n */\nexport type ToolCallInput<SchemaT = StringInputToolSchema> =\n StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;\n\n/**\n * Interface that defines the shape of a LangChain structured tool.\n *\n * A structured tool is a tool that uses a schema to define the structure of the arguments that the\n * LLM generates as part of its {@link ToolCall}.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface StructuredToolInterface<\n SchemaT = ToolInputSchemaBase,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends RunnableInterface<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolOutputT | ToolMessage\n > {\n lc_namespace: string[];\n\n /**\n * A Zod schema representing the parameters of the tool.\n */\n schema: SchemaT;\n\n /**\n * Invokes the tool with the provided argument and configuration.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration for the tool call.\n * @returns A Promise that resolves with the tool's output.\n */\n invoke<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig\n ): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig,\n /** @deprecated */\n tags?: string[]\n ): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n\n /**\n * The name of the tool.\n */\n name: string;\n\n /**\n * A description of the tool.\n */\n description: string;\n\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect: boolean;\n}\n\n/**\n * A special interface for tools that accept a string input, usually defined with the {@link Tool} class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface ToolInterface<\n SchemaT = StringInputToolSchema,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n // TODO: shouldn't this be narrowed based on SchemaT?\n arg: TArg,\n callbacks?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;\n}\n\n/**\n * Base interface for the input parameters of the {@link DynamicTool} and\n * {@link DynamicStructuredTool} classes.\n */\nexport interface BaseDynamicToolInput extends ToolParams {\n name: string;\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n\n/**\n * Interface for the input parameters of the DynamicTool class.\n */\nexport interface DynamicToolInput<ToolOutputT = ToolOutputType>\n extends BaseDynamicToolInput {\n func: (\n input: string,\n runManager?: CallbackManagerForToolRun,\n config?: ToolRunnableConfig\n ) => Promise<ToolOutputT>;\n}\n\n/**\n * Interface for the input parameters of the DynamicStructuredTool class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface DynamicStructuredToolInput<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends BaseDynamicToolInput {\n /**\n * Tool handler function - the function that will be called when the tool is invoked.\n *\n * @param input - The input to the tool.\n * @param runManager - The run manager for the tool.\n * @param config - The configuration for the tool.\n * @returns The result of the tool.\n */\n func: (\n input: SchemaOutputT,\n runManager?: CallbackManagerForToolRun,\n config?: RunnableConfig\n ) => Promise<ToolOutputT>;\n schema: SchemaT;\n}\n\n/**\n * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.\n *\n * @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.\n * @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.\n */\nexport function isStructuredTool(\n tool?: StructuredToolInterface | ToolDefinition | JSONSchema\n): tool is StructuredToolInterface {\n return (\n tool !== undefined &&\n Array.isArray((tool as StructuredToolInterface).lc_namespace)\n );\n}\n\n/**\n * Confirm whether the inputted tool is an instance of `RunnableToolLike`.\n *\n * @param {unknown | undefined} tool The tool to check if it is an instance of `RunnableToolLike`.\n * @returns {tool is RunnableToolLike} Whether the inputted tool is an instance of `RunnableToolLike`.\n */\nexport function isRunnableToolLike(tool?: unknown): tool is RunnableToolLike {\n return (\n tool !== undefined &&\n Runnable.isRunnable(tool) &&\n \"lc_name\" in tool.constructor &&\n typeof tool.constructor.lc_name === \"function\" &&\n tool.constructor.lc_name() === \"RunnableToolLike\"\n );\n}\n\n/**\n * Confirm whether or not the tool contains the necessary properties to be considered a `StructuredToolParams`.\n *\n * @param {unknown | undefined} tool The object to check if it is a `StructuredToolParams`.\n * @returns {tool is StructuredToolParams} Whether the inputted object is a `StructuredToolParams`.\n */\nexport function isStructuredToolParams(\n tool?: unknown\n): tool is StructuredToolParams {\n return (\n !!tool &&\n typeof tool === \"object\" &&\n \"name\" in tool &&\n \"schema\" in tool &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (isInteropZodSchema(tool.schema as Record<string, any>) ||\n (tool.schema != null &&\n typeof tool.schema === \"object\" &&\n \"type\" in tool.schema &&\n typeof tool.schema.type === \"string\" &&\n [\"null\", \"boolean\", \"object\", \"array\", \"number\", \"string\"].includes(\n tool.schema.type\n )))\n );\n}\n\n/**\n * Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams.\n * It returns `is StructuredToolParams` since that is the most minimal interface of the three,\n * while still containing the necessary properties to be passed to a LLM for tool calling.\n *\n * @param {unknown | undefined} tool The tool to check if it is a LangChain tool.\n * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.\n */\nexport function isLangChainTool(tool?: unknown): tool is StructuredToolParams {\n return (\n isStructuredToolParams(tool) ||\n isRunnableToolLike(tool) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isStructuredTool(tool as any)\n );\n}\n"],"mappings":";;;;;;;;;;AAwWA,SAAgB,iBACdA,MACiC;AACjC,QACE,SAAS,UACT,MAAM,QAAS,KAAiC,aAAa;AAEhE;;;;;;;AAQD,SAAgB,mBAAmBC,MAA0C;AAC3E,QACE,SAAS,UACT,SAAS,WAAW,KAAK,IACzB,aAAa,KAAK,eAClB,OAAO,KAAK,YAAY,YAAY,cACpC,KAAK,YAAY,SAAS,KAAK;AAElC;;;;;;;AAQD,SAAgB,uBACdA,MAC8B;AAC9B,QACE,CAAC,CAAC,QACF,OAAO,SAAS,YAChB,UAAU,QACV,YAAY,SAEX,mBAAmB,KAAK,OAA8B,IACpD,KAAK,UAAU,QACd,OAAO,KAAK,WAAW,YACvB,UAAU,KAAK,UACf,OAAO,KAAK,OAAO,SAAS,YAC5B;EAAC;EAAQ;EAAW;EAAU;EAAS;EAAU;CAAS,EAAC,SACzD,KAAK,OAAO,KACb;AAER;;;;;;;;;AAUD,SAAgB,gBAAgBA,MAA8C;AAC5E,QACE,uBAAuB,KAAK,IAC5B,mBAAmB,KAAK,IAExB,iBAAiB,KAAY;AAEhC"}
1
+ {"version":3,"file":"types.js","names":["tool?: StructuredToolInterface | ToolDefinition | JSONSchema","tool?: unknown"],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type { z as z3 } from \"zod/v3\";\nimport { CallbackManagerForToolRun } from \"../callbacks/manager.js\";\nimport type {\n BaseLangChainParams,\n ToolDefinition,\n} from \"../language_models/base.js\";\nimport type { RunnableConfig } from \"../runnables/config.js\";\nimport {\n Runnable,\n RunnableToolLike,\n type RunnableInterface,\n} from \"../runnables/base.js\";\nimport {\n type DirectToolOutput,\n type ToolCall,\n type ToolMessage,\n} from \"../messages/tool.js\";\nimport type { MessageContent } from \"../messages/base.js\";\nimport {\n type InferInteropZodInput,\n type InferInteropZodOutput,\n type InteropZodType,\n isInteropZodSchema,\n type InteropZodObject,\n} from \"../utils/types/zod.js\";\n\nimport { JSONSchema } from \"../utils/json_schema.js\";\nimport type { BaseStore } from \"../stores.js\";\n\nexport type ResponseFormat = \"content\" | \"content_and_artifact\" | string;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolOutputType = any;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ContentAndArtifact = [MessageContent, any];\n\n/**\n * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.\n * - If the input is a ToolCall, it returns a ToolMessage\n * - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage\n * - Otherwise, it returns the original output type\n */\nexport type ToolReturnType<TInput, TConfig, TOutput> =\n TOutput extends DirectToolOutput\n ? TOutput\n : TConfig extends { toolCall: { id: string } }\n ? ToolMessage\n : TConfig extends { toolCall: { id: undefined } }\n ? TOutput\n : TConfig extends { toolCall: { id?: string } }\n ? TOutput | ToolMessage\n : TInput extends ToolCall\n ? ToolMessage\n : TOutput;\n\n/**\n * Base type that establishes the types of input schemas that can be used for LangChain tool\n * definitions.\n */\nexport type ToolInputSchemaBase = z3.ZodTypeAny | JSONSchema;\n\n/**\n * Parameters for the Tool classes.\n */\nexport interface ToolParams extends BaseLangChainParams {\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n /**\n * Whether to show full details in the thrown parsing errors.\n *\n * @default false\n */\n verboseParsingErrors?: boolean;\n /**\n * Metadata for the tool.\n */\n metadata?: Record<string, unknown>;\n}\n\nexport type ToolRunnableConfig<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ConfigurableFieldType extends Record<string, any> = Record<string, any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ContextSchema = any\n> = RunnableConfig<ConfigurableFieldType> & {\n toolCall?: ToolCall;\n context?: ContextSchema;\n};\n\n/**\n * Schema for defining tools.\n *\n * @version 0.2.19\n */\nexport interface StructuredToolParams\n extends Pick<StructuredToolInterface, \"name\" | \"schema\"> {\n /**\n * An optional description of the tool to pass to the model.\n */\n description?: string;\n}\n\n/**\n * Utility type that resolves the output type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaOutputType<T> = T extends InteropZodType\n ? InferInteropZodOutput<T>\n : T extends JSONSchema\n ? unknown\n : never;\n\n/**\n * Utility type that resolves the input type of a tool input schema.\n *\n * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur\n * during parsing. When using JSONSchema, input and output types are the same.\n *\n * The input type for a given schema should match the structure of the arguments that the LLM\n * generates as part of its {@link ToolCall}. The output type will be the type that results from\n * applying any transforms defined in your schema. If there are no transforms, the input and output\n * types will be the same.\n */\nexport type ToolInputSchemaInputType<T> = T extends InteropZodType\n ? InferInteropZodInput<T>\n : T extends JSONSchema\n ? unknown\n : never;\n\n/**\n * Defines the type that will be passed into a tool handler function as a result of a tool call.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport type StructuredToolCallInput<\n SchemaT = ToolInputSchemaBase,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>\n> =\n | (ToolInputSchemaOutputType<SchemaT> extends string ? string : never)\n | SchemaInputT\n | ToolCall;\n\n/**\n * An input schema type for tools that accept a single string input.\n *\n * This schema defines a tool that takes an optional string parameter named \"input\".\n * It uses Zod's effects to transform the input and strip any extra properties.\n *\n * This is primarily used for creating simple string-based tools where the LLM\n * only needs to provide a single text value as input to the tool.\n */\nexport type StringInputToolSchema = z3.ZodType<\n string | undefined,\n z3.ZodTypeDef,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * Defines the type for input to a tool's call method.\n *\n * This type is a convenience alias for StructuredToolCallInput with the input type\n * derived from the schema. It represents the possible inputs that can be passed to a tool,\n * which can be either:\n * - A string (if the tool accepts string input)\n * - A structured input matching the tool's schema\n * - A ToolCall object (typically from an LLM)\n *\n * @param SchemaT - The schema type for the tool input, defaults to StringInputToolSchema\n */\nexport type ToolCallInput<SchemaT = StringInputToolSchema> =\n StructuredToolCallInput<SchemaT, ToolInputSchemaInputType<SchemaT>>;\n\n/**\n * Interface that defines the shape of a LangChain structured tool.\n *\n * A structured tool is a tool that uses a schema to define the structure of the arguments that the\n * LLM generates as part of its {@link ToolCall}.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface StructuredToolInterface<\n SchemaT = ToolInputSchemaBase,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends RunnableInterface<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolOutputT | ToolMessage\n > {\n lc_namespace: string[];\n\n /**\n * A Zod schema representing the parameters of the tool.\n */\n schema: SchemaT;\n\n /**\n * Invokes the tool with the provided argument and configuration.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration for the tool call.\n * @returns A Promise that resolves with the tool's output.\n */\n invoke<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig\n ): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig,\n /** @deprecated */\n tags?: string[]\n ): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;\n\n /**\n * The name of the tool.\n */\n name: string;\n\n /**\n * A description of the tool.\n */\n description: string;\n\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect: boolean;\n}\n\n/**\n * A special interface for tools that accept a string input, usually defined with the {@link Tool} class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface ToolInterface<\n SchemaT = StringInputToolSchema,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n // TODO: shouldn't this be narrowed based on SchemaT?\n arg: TArg,\n callbacks?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;\n}\n\n/**\n * Base interface for the input parameters of the {@link DynamicTool} and\n * {@link DynamicStructuredTool} classes.\n */\nexport interface BaseDynamicToolInput extends ToolParams {\n name: string;\n description: string;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n\n/**\n * Interface for the input parameters of the DynamicTool class.\n */\nexport interface DynamicToolInput<ToolOutputT = ToolOutputType>\n extends BaseDynamicToolInput {\n func: (\n input: string,\n runManager?: CallbackManagerForToolRun,\n config?: ToolRunnableConfig\n ) => Promise<ToolOutputT>;\n}\n\n/**\n * Interface for the input parameters of the DynamicStructuredTool class.\n *\n * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.\n * @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.\n */\nexport interface DynamicStructuredToolInput<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends BaseDynamicToolInput {\n /**\n * Tool handler function - the function that will be called when the tool is invoked.\n *\n * @param input - The input to the tool.\n * @param runManager - The run manager for the tool.\n * @param config - The configuration for the tool.\n * @returns The result of the tool.\n */\n func: (\n input: SchemaOutputT,\n runManager?: CallbackManagerForToolRun,\n config?: RunnableConfig\n ) => Promise<ToolOutputT>;\n schema: SchemaT;\n}\n\n/**\n * Confirm whether the inputted tool is an instance of `StructuredToolInterface`.\n *\n * @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.\n * @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.\n */\nexport function isStructuredTool(\n tool?: StructuredToolInterface | ToolDefinition | JSONSchema\n): tool is StructuredToolInterface {\n return (\n tool !== undefined &&\n Array.isArray((tool as StructuredToolInterface).lc_namespace)\n );\n}\n\n/**\n * Confirm whether the inputted tool is an instance of `RunnableToolLike`.\n *\n * @param {unknown | undefined} tool The tool to check if it is an instance of `RunnableToolLike`.\n * @returns {tool is RunnableToolLike} Whether the inputted tool is an instance of `RunnableToolLike`.\n */\nexport function isRunnableToolLike(tool?: unknown): tool is RunnableToolLike {\n return (\n tool !== undefined &&\n Runnable.isRunnable(tool) &&\n \"lc_name\" in tool.constructor &&\n typeof tool.constructor.lc_name === \"function\" &&\n tool.constructor.lc_name() === \"RunnableToolLike\"\n );\n}\n\n/**\n * Confirm whether or not the tool contains the necessary properties to be considered a `StructuredToolParams`.\n *\n * @param {unknown | undefined} tool The object to check if it is a `StructuredToolParams`.\n * @returns {tool is StructuredToolParams} Whether the inputted object is a `StructuredToolParams`.\n */\nexport function isStructuredToolParams(\n tool?: unknown\n): tool is StructuredToolParams {\n return (\n !!tool &&\n typeof tool === \"object\" &&\n \"name\" in tool &&\n \"schema\" in tool &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (isInteropZodSchema(tool.schema as Record<string, any>) ||\n (tool.schema != null &&\n typeof tool.schema === \"object\" &&\n \"type\" in tool.schema &&\n typeof tool.schema.type === \"string\" &&\n [\"null\", \"boolean\", \"object\", \"array\", \"number\", \"string\"].includes(\n tool.schema.type\n )))\n );\n}\n\n/**\n * Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams.\n * It returns `is StructuredToolParams` since that is the most minimal interface of the three,\n * while still containing the necessary properties to be passed to a LLM for tool calling.\n *\n * @param {unknown | undefined} tool The tool to check if it is a LangChain tool.\n * @returns {tool is StructuredToolParams} Whether the inputted tool is a LangChain tool.\n */\nexport function isLangChainTool(tool?: unknown): tool is StructuredToolParams {\n return (\n isStructuredToolParams(tool) ||\n isRunnableToolLike(tool) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isStructuredTool(tool as any)\n );\n}\n\n/**\n * Runtime context automatically injected into tools.\n *\n * When a tool function has a parameter named `tool_runtime` with type hint\n * `ToolRuntime`, the tool execution system will automatically inject an instance\n * containing:\n *\n * - `state`: The current graph state\n * - `toolCallId`: The ID of the current tool call\n * - `config`: `RunnableConfig` for the current execution\n * - `context`: Runtime context\n * - `store`: `BaseStore` instance for persistent storage\n * - `writer`: Stream writer for streaming output\n *\n * No `Annotated` wrapper is needed - just use `runtime: ToolRuntime`\n * as a parameter.\n *\n * @example\n * ```typescript\n * import { tool, ToolRuntime } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n *\n * const stateSchema = z.object({\n * messages: z.array(z.any()),\n * userId: z.string().optional(),\n * });\n *\n * const greet = tool(\n * async ({ name }, runtime) => {\n * // Access state\n * const messages = runtime.state.messages;\n *\n * // Access tool_call_id\n * console.log(`Tool call ID: ${runtime.toolCallId}`);\n *\n * // Access config\n * console.log(`Run ID: ${runtime.config.runId}`);\n *\n * // Access runtime context\n * const userId = runtime.context?.userId;\n *\n * // Access store\n * await runtime.store?.mset([[\"key\", \"value\"]]);\n *\n * // Stream output\n * runtime.writer?.(\"Processing...\");\n *\n * return `Hello! User ID: ${runtime.state.userId || \"unknown\"} ${name}`;\n * },\n * {\n * name: \"greet\",\n * description: \"Use this to greet the user once you found their info.\",\n * schema: z.object({ name: z.string() }),\n * stateSchema,\n * }\n * );\n * ```\n *\n * @template StateT - The type of the state schema (inferred from stateSchema)\n * @template ContextT - The type of the context schema (inferred from contextSchema)\n */\nexport type ToolRuntime<\n TState = unknown,\n TContext = unknown\n> = RunnableConfig & {\n /**\n * The current graph state.\n */\n state: TState extends InteropZodObject\n ? InferInteropZodOutput<TState>\n : TState extends Record<string, unknown>\n ? TState\n : unknown;\n /**\n * The ID of the current tool call.\n */\n toolCallId: string;\n /**\n * The current tool call.\n */\n toolCall?: ToolCall;\n /**\n * RunnableConfig for the current execution.\n */\n config: ToolRunnableConfig;\n /**\n * Runtime context (from langgraph `Runtime`).\n */\n context: TContext extends InteropZodObject\n ? InferInteropZodOutput<TContext>\n : TContext extends Record<string, unknown>\n ? TContext\n : unknown;\n /**\n * BaseStore instance for persistent storage (from langgraph `Runtime`).\n */\n store: BaseStore<string, unknown> | null;\n /**\n * Stream writer for streaming output (from langgraph `Runtime`).\n */\n writer: ((chunk: unknown) => void) | null;\n};\n"],"mappings":";;;;;;;;;;AA2WA,SAAgB,iBACdA,MACiC;AACjC,QACE,SAAS,UACT,MAAM,QAAS,KAAiC,aAAa;AAEhE;;;;;;;AAQD,SAAgB,mBAAmBC,MAA0C;AAC3E,QACE,SAAS,UACT,SAAS,WAAW,KAAK,IACzB,aAAa,KAAK,eAClB,OAAO,KAAK,YAAY,YAAY,cACpC,KAAK,YAAY,SAAS,KAAK;AAElC;;;;;;;AAQD,SAAgB,uBACdA,MAC8B;AAC9B,QACE,CAAC,CAAC,QACF,OAAO,SAAS,YAChB,UAAU,QACV,YAAY,SAEX,mBAAmB,KAAK,OAA8B,IACpD,KAAK,UAAU,QACd,OAAO,KAAK,WAAW,YACvB,UAAU,KAAK,UACf,OAAO,KAAK,OAAO,SAAS,YAC5B;EAAC;EAAQ;EAAW;EAAU;EAAS;EAAU;CAAS,EAAC,SACzD,KAAK,OAAO,KACb;AAER;;;;;;;;;AAUD,SAAgB,gBAAgBA,MAA8C;AAC5E,QACE,uBAAuB,KAAK,IAC5B,mBAAmB,KAAK,IAExB,iBAAiB,KAAY;AAEhC"}
@@ -1 +1 @@
1
- {"version":3,"file":"async_caller.d.cts","names":["FailedAttemptHandler","AsyncCallerParams","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","Promise","T","Parameters","ReturnType","Awaited","fetch"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n private queue;\n constructor(params: AsyncCallerParams);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\n"],"mappings":";;AACYA,KAAAA,oBAAAA,GAAoB,CAAA,KAAA,EAAA,GAAA,EAAA,GAAA,GAAA;AACfC,UAAAA,iBAAAA,CAgBKD;EAELE;AAgBjB;;;EAC+C,cACrBD,CAAAA,EAAAA,MAAAA;EAAiB;;;;EAKgB,UAAiBM,CAAAA,EAAAA,MAAAA;EAAC;;;;;EAA0C,eAAfD,CAAAA,EAzBlFN,oBAyBkFM;;AAEzCA,UAzB9CJ,sBAAAA,CAyB8CI;EAAO,MAAgBJ,CAAAA,EAxBzEC,WAwByED;;;;;;;;;;;;AAC9B;;;cAVnCE,WAAAA;4BACSH;wBACJA;6BACKA;;sBAEPA;;4CAEsBI,MAAMC,wBAAwBC,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;;uDAE1EF,MAAMC,uBAAuBJ,kCAAkCK,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;iBAC5JC,kBAAkBG,SAASF,kBAAkBE"}
1
+ {"version":3,"file":"async_caller.d.cts","names":["FailedAttemptHandler","AsyncCallerParams","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","Promise","T","Parameters","ReturnType","Awaited","fetch"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n private queue;\n constructor(params: AsyncCallerParams);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\n"],"mappings":";;AACYA,KAAAA,oBAAAA,GAAoB,CAAA,KAAA,EAAA,GAAA,EAAA,GAAA,GAAA;AACfC,UAAAA,iBAAAA,CAAiB;EAkBjBC;AAgBjB;;;EAC+C,cACrBD,CAAAA,EAAAA,MAAAA;EAAiB;;;;EAKgB,UAAiBM,CAAAA,EAAAA,MAAAA;EAAC;;;;;EAA0C,eAAfD,CAAAA,EAzBlFN,oBAyBkFM;;AAEzCA,UAzB9CJ,sBAAAA,CAyB8CI;EAAO,MAAgBJ,CAAAA,EAxBzEC,WAwByED;;;;;;;;;;;;AAC9B;;;cAVnCE,WAAAA;4BACSH;wBACJA;6BACKA;;sBAEPA;;4CAEsBI,MAAMC,wBAAwBC,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;;uDAE1EF,MAAMC,uBAAuBJ,kCAAkCK,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;iBAC5JC,kBAAkBG,SAASF,kBAAkBE"}
@@ -1 +1 @@
1
- {"version":3,"file":"async_caller.d.ts","names":["FailedAttemptHandler","AsyncCallerParams","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","Promise","T","Parameters","ReturnType","Awaited","fetch"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n private queue;\n constructor(params: AsyncCallerParams);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\n"],"mappings":";;AACYA,KAAAA,oBAAAA,GAAoB,CAAA,KAAA,EAAA,GAAA,EAAA,GAAA,GAAA;AACfC,UAAAA,iBAAAA,CAgBKD;EAELE;AAgBjB;;;EAC+C,cACrBD,CAAAA,EAAAA,MAAAA;EAAiB;;;;EAKgB,UAAiBM,CAAAA,EAAAA,MAAAA;EAAC;;;;;EAA0C,eAAfD,CAAAA,EAzBlFN,oBAyBkFM;;AAEzCA,UAzB9CJ,sBAAAA,CAyB8CI;EAAO,MAAgBJ,CAAAA,EAxBzEC,WAwByED;;;;;;;;;;;;AAC9B;;;cAVnCE,WAAAA;4BACSH;wBACJA;6BACKA;;sBAEPA;;4CAEsBI,MAAMC,wBAAwBC,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;;uDAE1EF,MAAMC,uBAAuBJ,kCAAkCK,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;iBAC5JC,kBAAkBG,SAASF,kBAAkBE"}
1
+ {"version":3,"file":"async_caller.d.ts","names":["FailedAttemptHandler","AsyncCallerParams","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","Promise","T","Parameters","ReturnType","Awaited","fetch"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n private queue;\n constructor(params: AsyncCallerParams);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\n"],"mappings":";;AACYA,KAAAA,oBAAAA,GAAoB,CAAA,KAAA,EAAA,GAAA,EAAA,GAAA,GAAA;AACfC,UAAAA,iBAAAA,CAAiB;EAkBjBC;AAgBjB;;;EAC+C,cACrBD,CAAAA,EAAAA,MAAAA;EAAiB;;;;EAKgB,UAAiBM,CAAAA,EAAAA,MAAAA;EAAC;;;;;EAA0C,eAAfD,CAAAA,EAzBlFN,oBAyBkFM;;AAEzCA,UAzB9CJ,sBAAAA,CAyB8CI;EAAO,MAAgBJ,CAAAA,EAxBzEC,WAwByED;;;;;;;;;;;;AAC9B;;;cAVnCE,WAAAA;4BACSH;wBACJA;6BACKA;;sBAEPA;;4CAEsBI,MAAMC,wBAAwBC,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;;uDAE1EF,MAAMC,uBAAuBJ,kCAAkCK,YAAYC,WAAWD,KAAKD,QAAQI,QAAQD,WAAWF;iBAC5JC,kBAAkBG,SAASF,kBAAkBE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {