@langchain/core 1.0.0-alpha.5 → 1.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -6
- package/dist/agents.d.ts.map +1 -1
- package/dist/caches/base.d.ts.map +1 -1
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/manager.cjs +9 -64
- package/dist/callbacks/manager.cjs.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -23
- package/dist/callbacks/manager.d.cts.map +1 -1
- package/dist/callbacks/manager.d.ts +1 -23
- package/dist/callbacks/manager.d.ts.map +1 -1
- package/dist/callbacks/manager.js +10 -63
- package/dist/callbacks/manager.js.map +1 -1
- package/dist/chat_history.cjs +0 -4
- package/dist/chat_history.cjs.map +1 -1
- package/dist/chat_history.d.cts +1 -3
- package/dist/chat_history.d.cts.map +1 -1
- package/dist/chat_history.d.ts +1 -3
- package/dist/chat_history.d.ts.map +1 -1
- package/dist/chat_history.js +0 -4
- package/dist/chat_history.js.map +1 -1
- package/dist/document_loaders/base.cjs +1 -13
- package/dist/document_loaders/base.cjs.map +1 -1
- package/dist/document_loaders/base.d.cts +0 -9
- package/dist/document_loaders/base.d.cts.map +1 -1
- package/dist/document_loaders/base.d.ts +0 -9
- package/dist/document_loaders/base.d.ts.map +1 -1
- package/dist/document_loaders/base.js +1 -13
- package/dist/document_loaders/base.js.map +1 -1
- package/dist/document_loaders/langsmith.d.cts +1 -1
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +0 -16
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +0 -16
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs +1 -80
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +1 -53
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +1 -53
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +2 -80
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.cjs +0 -56
- package/dist/language_models/llms.cjs.map +1 -1
- package/dist/language_models/llms.d.cts +1 -43
- package/dist/language_models/llms.d.cts.map +1 -1
- package/dist/language_models/llms.d.ts +1 -43
- package/dist/language_models/llms.d.ts.map +1 -1
- package/dist/language_models/llms.js +0 -56
- package/dist/language_models/llms.js.map +1 -1
- package/dist/load/import_map.cjs +1 -7
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +1 -7
- package/dist/load/import_map.js.map +1 -1
- package/dist/messages/ai.cjs +8 -4
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +8 -4
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +1 -1
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +2 -2
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +2 -2
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +1 -1
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/block_translators/anthropic.cjs +191 -144
- package/dist/messages/block_translators/anthropic.cjs.map +1 -1
- package/dist/messages/block_translators/anthropic.js +191 -144
- package/dist/messages/block_translators/anthropic.js.map +1 -1
- package/dist/messages/block_translators/bedrock_converse.cjs +213 -0
- package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -0
- package/dist/messages/block_translators/bedrock_converse.js +213 -0
- package/dist/messages/block_translators/bedrock_converse.js.map +1 -0
- package/dist/messages/block_translators/google_genai.cjs +73 -0
- package/dist/messages/block_translators/google_genai.cjs.map +1 -0
- package/dist/messages/block_translators/google_genai.js +73 -0
- package/dist/messages/block_translators/google_genai.js.map +1 -0
- package/dist/messages/block_translators/google_vertexai.cjs +74 -0
- package/dist/messages/block_translators/google_vertexai.cjs.map +1 -0
- package/dist/messages/block_translators/google_vertexai.js +74 -0
- package/dist/messages/block_translators/google_vertexai.js.map +1 -0
- package/dist/messages/block_translators/index.cjs +10 -1
- package/dist/messages/block_translators/index.cjs.map +1 -1
- package/dist/messages/block_translators/index.js +12 -3
- package/dist/messages/block_translators/index.js.map +1 -1
- package/dist/messages/block_translators/openai.cjs +78 -22
- package/dist/messages/block_translators/openai.cjs.map +1 -1
- package/dist/messages/block_translators/openai.js +78 -22
- package/dist/messages/block_translators/openai.js.map +1 -1
- package/dist/messages/block_translators/utils.cjs +4 -0
- package/dist/messages/block_translators/utils.cjs.map +1 -1
- package/dist/messages/block_translators/utils.js +4 -1
- package/dist/messages/block_translators/utils.js.map +1 -1
- package/dist/messages/content/index.cjs.map +1 -1
- package/dist/messages/content/index.d.cts +20 -1
- package/dist/messages/content/index.d.cts.map +1 -1
- package/dist/messages/content/index.d.ts +20 -1
- package/dist/messages/content/index.d.ts.map +1 -1
- package/dist/messages/content/index.js.map +1 -1
- package/dist/messages/content/tools.cjs +3 -4
- package/dist/messages/content/tools.cjs.map +1 -1
- package/dist/messages/content/tools.d.cts +22 -45
- package/dist/messages/content/tools.d.cts.map +1 -1
- package/dist/messages/content/tools.d.ts +22 -45
- package/dist/messages/content/tools.d.ts.map +1 -1
- package/dist/messages/content/tools.js +3 -4
- package/dist/messages/content/tools.js.map +1 -1
- package/dist/messages/index.cjs +4 -0
- package/dist/messages/index.cjs.map +1 -1
- package/dist/messages/index.d.cts +2 -2
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.js +4 -2
- package/dist/messages/index.js.map +1 -1
- package/dist/messages/message.cjs.map +1 -1
- package/dist/messages/message.d.cts +6 -6
- package/dist/messages/message.d.cts.map +1 -1
- package/dist/messages/message.d.ts +6 -6
- package/dist/messages/message.d.ts.map +1 -1
- package/dist/messages/message.js.map +1 -1
- package/dist/messages/metadata.cjs.map +1 -1
- package/dist/messages/metadata.d.cts +3 -0
- package/dist/messages/metadata.d.cts.map +1 -1
- package/dist/messages/metadata.d.ts +3 -0
- package/dist/messages/metadata.d.ts.map +1 -1
- package/dist/messages/metadata.js.map +1 -1
- package/dist/messages/tool.cjs +2 -0
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +5 -1
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +5 -1
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +2 -0
- package/dist/messages/tool.js.map +1 -1
- package/dist/output_parsers/json.cjs +5 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +2 -0
- package/dist/output_parsers/json.d.cts.map +1 -1
- package/dist/output_parsers/json.d.ts +2 -0
- package/dist/output_parsers/json.d.ts.map +1 -1
- package/dist/output_parsers/json.js +5 -0
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/prompts/base.cjs +0 -36
- package/dist/prompts/base.cjs.map +1 -1
- package/dist/prompts/base.d.cts +0 -16
- package/dist/prompts/base.d.cts.map +1 -1
- package/dist/prompts/base.d.ts +0 -16
- package/dist/prompts/base.d.ts.map +1 -1
- package/dist/prompts/base.js +0 -36
- package/dist/prompts/base.js.map +1 -1
- package/dist/prompts/chat.cjs +1 -5
- package/dist/prompts/chat.cjs.map +1 -1
- package/dist/prompts/chat.d.cts +1 -4
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +1 -4
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/chat.js +1 -5
- package/dist/prompts/chat.js.map +1 -1
- package/dist/prompts/dict.d.cts +1 -1
- package/dist/prompts/dict.d.ts +1 -1
- package/dist/prompts/few_shot.d.cts +2 -2
- package/dist/prompts/few_shot.d.ts +2 -2
- package/dist/prompts/image.d.cts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/index.d.cts +2 -2
- package/dist/prompts/index.d.ts +2 -2
- package/dist/prompts/pipeline.d.cts +1 -1
- package/dist/prompts/pipeline.d.ts +1 -1
- package/dist/prompts/prompt.d.cts +2 -2
- package/dist/prompts/prompt.d.ts +2 -2
- package/dist/retrievers/index.cjs +3 -18
- package/dist/retrievers/index.cjs.map +1 -1
- package/dist/retrievers/index.d.cts +2 -27
- package/dist/retrievers/index.d.cts.map +1 -1
- package/dist/retrievers/index.d.ts +2 -27
- package/dist/retrievers/index.d.ts.map +1 -1
- package/dist/retrievers/index.js +3 -18
- package/dist/retrievers/index.js.map +1 -1
- package/dist/runnables/base.cjs +24 -63
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +10 -39
- package/dist/runnables/base.d.cts.map +1 -1
- package/dist/runnables/base.d.ts +10 -39
- package/dist/runnables/base.d.ts.map +1 -1
- package/dist/runnables/base.js +24 -63
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/graph.cjs +1 -1
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.js +2 -2
- package/dist/runnables/graph.js.map +1 -1
- package/dist/runnables/graph_mermaid.cjs +1 -10
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +1 -10
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/history.cjs +1 -1
- package/dist/runnables/history.cjs.map +1 -1
- package/dist/runnables/history.d.cts +2 -2
- package/dist/runnables/history.d.cts.map +1 -1
- package/dist/runnables/history.d.ts +2 -2
- package/dist/runnables/history.d.ts.map +1 -1
- package/dist/runnables/history.js +1 -1
- package/dist/runnables/history.js.map +1 -1
- package/dist/stores.cjs.map +1 -1
- package/dist/stores.d.cts +3 -29
- package/dist/stores.d.cts.map +1 -1
- package/dist/stores.d.ts +3 -29
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js.map +1 -1
- package/dist/tools/index.cjs +12 -4
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +12 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +4 -0
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +4 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tracers/base.cjs +1 -1
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.d.cts +1 -1
- package/dist/tracers/base.js +2 -2
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/log_stream.d.cts +1 -1
- package/dist/tracers/log_stream.d.ts +1 -1
- package/dist/tracers/tracer_langchain.cjs +1 -0
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.d.cts +2 -2
- package/dist/tracers/tracer_langchain.js +1 -0
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/utils/env.cjs +1 -9
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.d.cts +2 -6
- package/dist/utils/env.d.cts.map +1 -1
- package/dist/utils/env.d.ts +2 -6
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +2 -9
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/testing/message_history.cjs +1 -1
- package/dist/utils/testing/message_history.cjs.map +1 -1
- package/dist/utils/testing/message_history.d.cts +1 -1
- package/dist/utils/testing/message_history.d.cts.map +1 -1
- package/dist/utils/testing/message_history.d.ts +1 -1
- package/dist/utils/testing/message_history.d.ts.map +1 -1
- package/dist/utils/testing/message_history.js +1 -1
- package/dist/utils/testing/message_history.js.map +1 -1
- package/dist/utils/types/index.cjs +8 -0
- package/dist/utils/types/index.d.cts +2 -2
- package/dist/utils/types/index.d.ts +2 -2
- package/dist/utils/types/index.js +6 -2
- package/dist/utils/types/zod.cjs +62 -3
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +28 -1
- package/dist/utils/types/zod.d.cts.map +1 -1
- package/dist/utils/types/zod.d.ts +28 -1
- package/dist/utils/types/zod.d.ts.map +1 -1
- package/dist/utils/types/zod.js +59 -4
- package/dist/utils/types/zod.js.map +1 -1
- package/package.json +1 -37
- package/dist/runnables/remote.cjs +0 -399
- package/dist/runnables/remote.cjs.map +0 -1
- package/dist/runnables/remote.d.cts +0 -73
- package/dist/runnables/remote.d.cts.map +0 -1
- package/dist/runnables/remote.d.ts +0 -73
- package/dist/runnables/remote.d.ts.map +0 -1
- package/dist/runnables/remote.js +0 -393
- package/dist/runnables/remote.js.map +0 -1
- package/dist/tracers/initialize.cjs +0 -46
- package/dist/tracers/initialize.cjs.map +0 -1
- package/dist/tracers/initialize.d.cts +0 -26
- package/dist/tracers/initialize.d.cts.map +0 -1
- package/dist/tracers/initialize.d.ts +0 -26
- package/dist/tracers/initialize.d.ts.map +0 -1
- package/dist/tracers/initialize.js +0 -39
- package/dist/tracers/initialize.js.map +0 -1
- package/dist/tracers/tracer_langchain_v1.cjs +0 -168
- package/dist/tracers/tracer_langchain_v1.cjs.map +0 -1
- package/dist/tracers/tracer_langchain_v1.d.cts +0 -64
- package/dist/tracers/tracer_langchain_v1.d.cts.map +0 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +0 -64
- package/dist/tracers/tracer_langchain_v1.d.ts.map +0 -1
- package/dist/tracers/tracer_langchain_v1.js +0 -162
- package/dist/tracers/tracer_langchain_v1.js.map +0 -1
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fields?: ToolParams","input: TInput","config?: TConfig","toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >","enrichedConfig: ToolRunnableConfig","arg: TArg","configArg?: TConfig","tags?: string[]","parsed: SchemaOutputT","result","toolCallId: string | undefined","callbacks?: TConfig","fields: DynamicToolInput<ToolOutputT>","input: string","runManager?: CallbackManagerForToolRun","parentConfig?: ToolRunnableConfig","fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>","arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0]","parentConfig?: RunnableConfig","func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>","fields: ToolWrapperParams<SchemaT>","params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n}","content: unknown"],"sources":["../../src/tools/index.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport {\n validate,\n type Schema as ValidationSchema,\n} from \"@cfworker/json-schema\";\nimport {\n CallbackManager,\n CallbackManagerForToolRun,\n parseCallbackConfigArg,\n} from \"../callbacks/manager.js\";\nimport { BaseLangChain } from \"../language_models/base.js\";\nimport {\n mergeConfigs,\n ensureConfig,\n patchConfig,\n pickRunnableConfigKeys,\n type RunnableConfig,\n} from \"../runnables/config.js\";\nimport type { RunnableFunc } from \"../runnables/base.js\";\nimport { isDirectToolOutput, ToolCall, ToolMessage } from \"../messages/tool.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport {\n _configHasToolCallId,\n _isToolCall,\n ToolInputParsingException,\n} from \"./utils.js\";\nimport {\n type InferInteropZodInput,\n type InferInteropZodOutput,\n type InteropZodObject,\n type InteropZodType,\n interopParseAsync,\n isSimpleStringZodSchema,\n isInteropZodSchema,\n type ZodStringV3,\n type ZodStringV4,\n type ZodObjectV3,\n type ZodObjectV4,\n} from \"../utils/types/zod.js\";\nimport { getAbortSignalError } from \"../utils/signal.js\";\nimport type {\n StructuredToolCallInput,\n ToolInputSchemaBase,\n ToolReturnType,\n ResponseFormat,\n ToolInputSchemaInputType,\n ToolInputSchemaOutputType,\n ToolParams,\n ToolRunnableConfig,\n StructuredToolInterface,\n DynamicToolInput,\n DynamicStructuredToolInput,\n StringInputToolSchema,\n ToolInterface,\n ToolOutputType,\n} from \"./types.js\";\nimport { type JSONSchema, validatesOnlyStrings } from \"../utils/json_schema.js\";\n\nexport type {\n BaseDynamicToolInput,\n ContentAndArtifact,\n DynamicToolInput,\n DynamicStructuredToolInput,\n ResponseFormat,\n StructuredToolCallInput,\n StructuredToolInterface,\n StructuredToolParams,\n ToolInterface,\n ToolParams,\n ToolReturnType,\n ToolRunnableConfig,\n ToolInputSchemaBase as ToolSchemaBase,\n} from \"./types.js\";\n\nexport {\n isLangChainTool,\n isRunnableToolLike,\n isStructuredTool,\n isStructuredToolParams,\n} from \"./types.js\";\n\nexport { ToolInputParsingException };\n/**\n * Base class for Tools that accept input of any shape defined by a Zod schema.\n */\nexport abstract class StructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n >\n extends BaseLangChain<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolOutputT | ToolMessage\n >\n implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT>\n{\n abstract name: string;\n\n abstract description: string;\n\n abstract schema: SchemaT;\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 = false;\n\n verboseParsingErrors = false;\n\n get lc_namespace() {\n return [\"langchain\", \"tools\"];\n }\n\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 = \"content\";\n\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n\n constructor(fields?: ToolParams) {\n super(fields ?? {});\n\n this.verboseParsingErrors =\n fields?.verboseParsingErrors ?? this.verboseParsingErrors;\n this.responseFormat = fields?.responseFormat ?? this.responseFormat;\n this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;\n }\n\n protected abstract _call(\n arg: SchemaOutputT,\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT>;\n\n /**\n * Invokes the tool with the provided input and configuration.\n * @param input The input for the tool.\n * @param config Optional configuration for the tool.\n * @returns A Promise that resolves with the tool's output.\n */\n async invoke<\n TInput extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n input: TInput,\n config?: TConfig\n ): Promise<ToolReturnType<TInput, TConfig, ToolOutputT>> {\n let toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n\n let enrichedConfig: ToolRunnableConfig = ensureConfig(\n mergeConfigs(this.defaultConfig, config)\n );\n if (_isToolCall(input)) {\n toolInput = input.args as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n enrichedConfig = {\n ...enrichedConfig,\n toolCall: input,\n };\n } else {\n toolInput = input as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n }\n\n return this.call(toolInput, enrichedConfig) as Promise<\n ToolReturnType<TInput, TConfig, ToolOutputT>\n >;\n }\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 async 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 // Determine the actual input that needs parsing/validation.\n // If arg is a ToolCall, use its args; otherwise, use arg directly.\n const inputForValidation = _isToolCall(arg) ? arg.args : arg;\n\n let parsed: SchemaOutputT; // This will hold the successfully parsed input of the expected output type.\n if (isInteropZodSchema(this.schema)) {\n try {\n // Validate the inputForValidation - TS needs help here as it can't exclude ToolCall based on the check\n parsed = await interopParseAsync(\n this.schema as InteropZodType,\n inputForValidation as Exclude<TArg, ToolCall>\n );\n } catch (e) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${(e as Error).message}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n } else {\n const result = validate(\n inputForValidation,\n this.schema as ValidationSchema\n );\n if (!result.valid) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${result.errors\n .map((e) => `${e.keywordLocation}: ${e.error}`)\n .join(\"\\n\")}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n // Assign the validated input to parsed\n // We cast here because validate() doesn't narrow the type sufficiently for TS, but we know it's valid.\n parsed = inputForValidation as SchemaOutputT;\n }\n\n const config = parseCallbackConfigArg(configArg);\n const callbackManager_ = CallbackManager.configure(\n config.callbacks,\n this.callbacks,\n config.tags || tags,\n this.tags,\n config.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const runManager = await callbackManager_?.handleToolStart(\n this.toJSON(),\n // Log the original raw input arg\n typeof arg === \"string\" ? arg : JSON.stringify(arg),\n config.runId,\n undefined,\n undefined,\n undefined,\n config.runName\n );\n delete config.runId;\n let result;\n try {\n // Pass the correctly typed parsed input to _call\n result = await this._call(parsed, runManager, config);\n } catch (e) {\n await runManager?.handleToolError(e);\n throw e;\n }\n let content;\n let artifact;\n if (this.responseFormat === \"content_and_artifact\") {\n if (Array.isArray(result) && result.length === 2) {\n [content, artifact] = result;\n } else {\n throw new Error(\n `Tool response format is \"content_and_artifact\" but the output was not a two-tuple.\\nResult: ${JSON.stringify(\n result\n )}`\n );\n }\n } else {\n content = result;\n }\n\n let toolCallId: string | undefined;\n // Extract toolCallId ONLY if the original arg was a ToolCall\n if (_isToolCall(arg)) {\n toolCallId = arg.id;\n }\n // Or if it was provided in the config's toolCall property\n if (!toolCallId && _configHasToolCallId(config)) {\n toolCallId = config.toolCall.id;\n }\n\n const formattedOutput = _formatToolOutput<ToolOutputT>({\n content,\n artifact,\n toolCallId,\n name: this.name,\n });\n await runManager?.handleToolEnd(formattedOutput);\n return formattedOutput as ToolReturnType<TArg, TConfig, ToolOutputT>;\n }\n}\n\n/**\n * Base class for Tools that accept input as a string.\n */\nexport abstract class Tool<ToolOutputT = ToolOutputType>\n extends StructuredTool<\n StringInputToolSchema,\n ToolInputSchemaOutputType<StringInputToolSchema>,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n implements\n ToolInterface<\n StringInputToolSchema,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n{\n schema = z\n .object({ input: z.string().optional() })\n .transform((obj) => obj.input);\n\n constructor(fields?: ToolParams) {\n super(fields);\n }\n\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 // Match the base class signature including the generics and conditional return type\n call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n callbacks?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n // Prepare the input for the base class call method.\n // If arg is string or undefined, wrap it; otherwise, pass ToolCall or { input: ... } directly.\n const structuredArg =\n typeof arg === \"string\" || arg == null ? { input: arg } : arg;\n\n // Ensure TConfig is passed to super.call\n return super.call(structuredArg, callbacks);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and description.\n */\nexport class DynamicTool<\n ToolOutputT = ToolOutputType\n> extends Tool<ToolOutputT> {\n static lc_name() {\n return \"DynamicTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicToolInput<ToolOutputT>[\"func\"];\n\n constructor(fields: DynamicToolInput<ToolOutputT>) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n async call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n // Call the Tool class's call method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig);\n }\n\n /** @ignore */\n async _call(\n input: string, // DynamicTool's _call specifically expects a string after schema transformation\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(input, runManager, parentConfig);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and\n * description, designed to work with structured data. It extends the\n * StructuredTool class and overrides the _call method to execute the\n * provided function when the tool is called.\n *\n * Schema can be passed as Zod or JSON schema. The tool will not validate\n * input if JSON schema is passed.\n */\nexport class DynamicStructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends StructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT> {\n static lc_name() {\n return \"DynamicStructuredTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>[\"func\"];\n\n schema: SchemaT;\n\n constructor(\n fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>\n ) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n this.schema = fields.schema;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n // Match the base class signature\n async 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<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n\n // Call the base class method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig, tags);\n }\n\n protected _call(\n arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0],\n runManager?: CallbackManagerForToolRun,\n parentConfig?: RunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(arg, runManager, parentConfig);\n }\n}\n\n/**\n * Abstract base class for toolkits in LangChain. Toolkits are collections\n * of tools that agents can use. Subclasses must implement the `tools`\n * property to provide the specific tools for the toolkit.\n */\nexport abstract class BaseToolkit {\n abstract tools: StructuredToolInterface[];\n\n getTools(): StructuredToolInterface[] {\n return this.tools;\n }\n}\n\n/**\n * Parameters for the tool function.\n * Schema can be provided as Zod or JSON schema.\n * Both schema types will be validated.\n * @template {ToolInputSchemaBase} RunInput The input schema for the tool.\n */\ninterface ToolWrapperParams<RunInput = ToolInputSchemaBase | undefined>\n extends ToolParams {\n /**\n * The name of the tool. If using with an LLM, this\n * will be passed as the tool name.\n */\n name: string;\n /**\n * The description of the tool.\n * @default `${fields.name} tool`\n */\n description?: string;\n /**\n * The input schema for the tool. If using an LLM, this\n * will be passed as the tool schema to generate arguments\n * for.\n */\n schema?: RunInput;\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 * 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 * Creates a new StructuredTool instance with the provided function, name, description, and schema.\n *\n * Schema can be provided as Zod or JSON schema, and both will be validated.\n *\n * @function\n * @template {ToolInputSchemaBase} SchemaT The input schema for the tool.\n * @template {ToolReturnType} ToolOutputT The output type of the tool.\n *\n * @param {RunnableFunc<z.output<SchemaT>, ToolOutputT>} func - The function to invoke when the tool is called.\n * @param {ToolWrapperParams<SchemaT>} fields - An object containing the following properties:\n * @param {string} fields.name The name of the tool.\n * @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`.\n * @param {z.AnyZodObject | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema.\n *\n * @returns {DynamicStructuredTool<SchemaT>} A new StructuredTool instance.\n */\nexport function tool<SchemaT extends ZodStringV3, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<SchemaT extends ZodStringV4, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV3,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV4,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends JSONSchema,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<\n Parameters<DynamicStructuredToolInput<SchemaT>[\"func\"]>[0],\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends\n | InteropZodObject\n | InteropZodType<string>\n | JSONSchema = InteropZodObject,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n):\n | DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>\n | DynamicTool<ToolOutputT> {\n const isSimpleStringSchema = isSimpleStringZodSchema(fields.schema);\n const isStringJSONSchema = validatesOnlyStrings(fields.schema);\n\n // If the schema is not provided, or it's a simple string schema, create a DynamicTool\n if (!fields.schema || isSimpleStringSchema || isStringJSONSchema) {\n return new DynamicTool<ToolOutputT>({\n ...fields,\n description:\n fields.description ??\n (fields.schema as { description?: string } | undefined)?.description ??\n `${fields.name} tool`,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n // TS doesn't restrict the type here based on the guard above\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(func(input as any, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n });\n }\n\n const schema = fields.schema as InteropZodObject | JSONSchema;\n\n const description =\n fields.description ??\n (fields.schema as { description?: string }).description ??\n `${fields.name} tool`;\n\n return new DynamicStructuredTool<\n typeof schema,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >({\n ...fields,\n description,\n schema,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n if (config?.signal) {\n config.signal.addEventListener(\"abort\", () => {\n return reject(getAbortSignalError(config.signal));\n });\n }\n\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n const result = await func(input, childConfig);\n\n /**\n * If the signal is aborted, we don't want to resolve the promise\n * as the promise is already rejected.\n */\n if (config?.signal?.aborted) {\n return;\n }\n\n resolve(result);\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n }) as DynamicStructuredTool<\n SchemaT,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >;\n}\n\nfunction _formatToolOutput<TOutput extends ToolOutputType>(params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n}): ToolMessage | TOutput {\n const { content, artifact, toolCallId } = params;\n if (toolCallId && !isDirectToolOutput(content)) {\n if (\n typeof content === \"string\" ||\n (Array.isArray(content) &&\n content.every((item) => typeof item === \"object\"))\n ) {\n return new ToolMessage({\n content,\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n });\n } else {\n return new ToolMessage({\n content: _stringify(content),\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n });\n }\n } else {\n return content;\n }\n}\n\nfunction _stringify(content: unknown): string {\n try {\n return JSON.stringify(content, null, 2) ?? \"\";\n } catch (_noOp) {\n return `${content}`;\n }\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SAAQ,GAAG;MACV,OAAO,EAAE;KACV;IACF,EACF;GACF;EACF;CACF;AAMF;AAED,SAAS,kBAAkDC,QAKjC;CACxB,MAAM,EAAE,SAAS,UAAU,YAAY,GAAG;AAC1C,KAAI,cAAc,CAAC,mBAAmB,QAAQ,CAC5C,KACE,OAAO,YAAY,YAClB,MAAM,QAAQ,QAAQ,IACrB,QAAQ,MAAM,CAAC,SAAS,OAAO,SAAS,SAAS,CAEnD,QAAO,IAAI,YAAY;EACrB;EACA;EACA,cAAc;EACd,MAAM,OAAO;CACd;KAED,QAAO,IAAI,YAAY;EACrB,SAAS,WAAW,QAAQ;EAC5B;EACA,cAAc;EACd,MAAM,OAAO;CACd;KAGH,QAAO;AAEV;AAED,SAAS,WAAWC,SAA0B;AAC5C,KAAI;AACF,SAAO,KAAK,UAAU,SAAS,MAAM,EAAE,IAAI;CAC5C,SAAQ,OAAO;AACd,SAAO,GAAG,SAAS;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fields?: ToolParams","input: TInput","config?: TConfig","toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >","enrichedConfig: ToolRunnableConfig","arg: TArg","configArg?: TConfig","tags?: string[]","parsed: SchemaOutputT","z4","result","toolCallId: string | undefined","callbacks?: TConfig","fields: DynamicToolInput<ToolOutputT>","input: string","runManager?: CallbackManagerForToolRun","parentConfig?: ToolRunnableConfig","fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>","arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0]","parentConfig?: RunnableConfig","func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>","fields: ToolWrapperParams<SchemaT>","params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n metadata?: Record<string, unknown>;\n}","content: unknown"],"sources":["../../src/tools/index.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { z as z4, ZodError } from \"zod/v4\";\nimport {\n validate,\n type Schema as ValidationSchema,\n} from \"@cfworker/json-schema\";\nimport {\n CallbackManager,\n CallbackManagerForToolRun,\n parseCallbackConfigArg,\n} from \"../callbacks/manager.js\";\nimport { BaseLangChain } from \"../language_models/base.js\";\nimport {\n mergeConfigs,\n ensureConfig,\n patchConfig,\n pickRunnableConfigKeys,\n type RunnableConfig,\n} from \"../runnables/config.js\";\nimport type { RunnableFunc } from \"../runnables/base.js\";\nimport { isDirectToolOutput, ToolCall, ToolMessage } from \"../messages/tool.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport {\n _configHasToolCallId,\n _isToolCall,\n ToolInputParsingException,\n} from \"./utils.js\";\nimport {\n type InferInteropZodInput,\n type InferInteropZodOutput,\n type InteropZodObject,\n type InteropZodType,\n interopParseAsync,\n isSimpleStringZodSchema,\n isInteropZodSchema,\n type ZodStringV3,\n type ZodStringV4,\n type ZodObjectV3,\n type ZodObjectV4,\n} from \"../utils/types/zod.js\";\nimport { getAbortSignalError } from \"../utils/signal.js\";\nimport type {\n StructuredToolCallInput,\n ToolInputSchemaBase,\n ToolReturnType,\n ResponseFormat,\n ToolInputSchemaInputType,\n ToolInputSchemaOutputType,\n ToolParams,\n ToolRunnableConfig,\n StructuredToolInterface,\n DynamicToolInput,\n DynamicStructuredToolInput,\n StringInputToolSchema,\n ToolInterface,\n ToolOutputType,\n} from \"./types.js\";\nimport { type JSONSchema, validatesOnlyStrings } from \"../utils/json_schema.js\";\n\nexport type {\n BaseDynamicToolInput,\n ContentAndArtifact,\n DynamicToolInput,\n DynamicStructuredToolInput,\n ResponseFormat,\n StructuredToolCallInput,\n StructuredToolInterface,\n StructuredToolParams,\n ToolInterface,\n ToolParams,\n ToolReturnType,\n ToolRunnableConfig,\n ToolInputSchemaBase as ToolSchemaBase,\n} from \"./types.js\";\n\nexport {\n isLangChainTool,\n isRunnableToolLike,\n isStructuredTool,\n isStructuredToolParams,\n} from \"./types.js\";\n\nexport { ToolInputParsingException };\n/**\n * Base class for Tools that accept input of any shape defined by a Zod schema.\n */\nexport abstract class StructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n >\n extends BaseLangChain<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolOutputT | ToolMessage\n >\n implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT>\n{\n abstract name: string;\n\n abstract description: string;\n\n abstract schema: SchemaT;\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 = false;\n\n verboseParsingErrors = false;\n\n get lc_namespace() {\n return [\"langchain\", \"tools\"];\n }\n\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 = \"content\";\n\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n\n constructor(fields?: ToolParams) {\n super(fields ?? {});\n\n this.verboseParsingErrors =\n fields?.verboseParsingErrors ?? this.verboseParsingErrors;\n this.responseFormat = fields?.responseFormat ?? this.responseFormat;\n this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;\n this.metadata = fields?.metadata ?? this.metadata;\n }\n\n protected abstract _call(\n arg: SchemaOutputT,\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT>;\n\n /**\n * Invokes the tool with the provided input and configuration.\n * @param input The input for the tool.\n * @param config Optional configuration for the tool.\n * @returns A Promise that resolves with the tool's output.\n */\n async invoke<\n TInput extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n input: TInput,\n config?: TConfig\n ): Promise<ToolReturnType<TInput, TConfig, ToolOutputT>> {\n let toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n\n let enrichedConfig: ToolRunnableConfig = ensureConfig(\n mergeConfigs(this.defaultConfig, config)\n );\n if (_isToolCall(input)) {\n toolInput = input.args as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n enrichedConfig = {\n ...enrichedConfig,\n toolCall: input,\n };\n } else {\n toolInput = input as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n }\n\n return this.call(toolInput, enrichedConfig) as Promise<\n ToolReturnType<TInput, TConfig, ToolOutputT>\n >;\n }\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 async 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 // Determine the actual input that needs parsing/validation.\n // If arg is a ToolCall, use its args; otherwise, use arg directly.\n const inputForValidation = _isToolCall(arg) ? arg.args : arg;\n\n let parsed: SchemaOutputT; // This will hold the successfully parsed input of the expected output type.\n if (isInteropZodSchema(this.schema)) {\n try {\n // Validate the inputForValidation - TS needs help here as it can't exclude ToolCall based on the check\n parsed = await interopParseAsync(\n this.schema as InteropZodType,\n inputForValidation as Exclude<TArg, ToolCall>\n );\n } catch (e) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${(e as Error).message}`;\n }\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (e instanceof Error && e.constructor.name === \"ZodError\") {\n message = `${message}\\n\\n${z4.prettifyError(e as ZodError)}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n } else {\n const result = validate(\n inputForValidation,\n this.schema as ValidationSchema\n );\n if (!result.valid) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${result.errors\n .map((e) => `${e.keywordLocation}: ${e.error}`)\n .join(\"\\n\")}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n // Assign the validated input to parsed\n // We cast here because validate() doesn't narrow the type sufficiently for TS, but we know it's valid.\n parsed = inputForValidation as SchemaOutputT;\n }\n\n const config = parseCallbackConfigArg(configArg);\n const callbackManager_ = CallbackManager.configure(\n config.callbacks,\n this.callbacks,\n config.tags || tags,\n this.tags,\n config.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const runManager = await callbackManager_?.handleToolStart(\n this.toJSON(),\n // Log the original raw input arg\n typeof arg === \"string\" ? arg : JSON.stringify(arg),\n config.runId,\n undefined,\n undefined,\n undefined,\n config.runName\n );\n delete config.runId;\n let result;\n try {\n // Pass the correctly typed parsed input to _call\n result = await this._call(parsed, runManager, config);\n } catch (e) {\n await runManager?.handleToolError(e);\n throw e;\n }\n let content;\n let artifact;\n if (this.responseFormat === \"content_and_artifact\") {\n if (Array.isArray(result) && result.length === 2) {\n [content, artifact] = result;\n } else {\n throw new Error(\n `Tool response format is \"content_and_artifact\" but the output was not a two-tuple.\\nResult: ${JSON.stringify(\n result\n )}`\n );\n }\n } else {\n content = result;\n }\n\n let toolCallId: string | undefined;\n // Extract toolCallId ONLY if the original arg was a ToolCall\n if (_isToolCall(arg)) {\n toolCallId = arg.id;\n }\n // Or if it was provided in the config's toolCall property\n if (!toolCallId && _configHasToolCallId(config)) {\n toolCallId = config.toolCall.id;\n }\n\n const formattedOutput = _formatToolOutput<ToolOutputT>({\n content,\n artifact,\n toolCallId,\n name: this.name,\n metadata: this.metadata,\n });\n await runManager?.handleToolEnd(formattedOutput);\n return formattedOutput as ToolReturnType<TArg, TConfig, ToolOutputT>;\n }\n}\n\n/**\n * Base class for Tools that accept input as a string.\n */\nexport abstract class Tool<ToolOutputT = ToolOutputType>\n extends StructuredTool<\n StringInputToolSchema,\n ToolInputSchemaOutputType<StringInputToolSchema>,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n implements\n ToolInterface<\n StringInputToolSchema,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n{\n schema = z\n .object({ input: z.string().optional() })\n .transform((obj) => obj.input);\n\n constructor(fields?: ToolParams) {\n super(fields);\n }\n\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 // Match the base class signature including the generics and conditional return type\n call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n callbacks?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n // Prepare the input for the base class call method.\n // If arg is string or undefined, wrap it; otherwise, pass ToolCall or { input: ... } directly.\n const structuredArg =\n typeof arg === \"string\" || arg == null ? { input: arg } : arg;\n\n // Ensure TConfig is passed to super.call\n return super.call(structuredArg, callbacks);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and description.\n */\nexport class DynamicTool<\n ToolOutputT = ToolOutputType\n> extends Tool<ToolOutputT> {\n static lc_name() {\n return \"DynamicTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicToolInput<ToolOutputT>[\"func\"];\n\n constructor(fields: DynamicToolInput<ToolOutputT>) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n async call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n // Call the Tool class's call method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig);\n }\n\n /** @ignore */\n async _call(\n input: string, // DynamicTool's _call specifically expects a string after schema transformation\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(input, runManager, parentConfig);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and\n * description, designed to work with structured data. It extends the\n * StructuredTool class and overrides the _call method to execute the\n * provided function when the tool is called.\n *\n * Schema can be passed as Zod or JSON schema. The tool will not validate\n * input if JSON schema is passed.\n */\nexport class DynamicStructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends StructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT> {\n static lc_name() {\n return \"DynamicStructuredTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>[\"func\"];\n\n schema: SchemaT;\n\n constructor(\n fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>\n ) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n this.schema = fields.schema;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n // Match the base class signature\n async 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<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n\n // Call the base class method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig, tags);\n }\n\n protected _call(\n arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0],\n runManager?: CallbackManagerForToolRun,\n parentConfig?: RunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(arg, runManager, parentConfig);\n }\n}\n\n/**\n * Abstract base class for toolkits in LangChain. Toolkits are collections\n * of tools that agents can use. Subclasses must implement the `tools`\n * property to provide the specific tools for the toolkit.\n */\nexport abstract class BaseToolkit {\n abstract tools: StructuredToolInterface[];\n\n getTools(): StructuredToolInterface[] {\n return this.tools;\n }\n}\n\n/**\n * Parameters for the tool function.\n * Schema can be provided as Zod or JSON schema.\n * Both schema types will be validated.\n * @template {ToolInputSchemaBase} RunInput The input schema for the tool.\n */\ninterface ToolWrapperParams<RunInput = ToolInputSchemaBase | undefined>\n extends ToolParams {\n /**\n * The name of the tool. If using with an LLM, this\n * will be passed as the tool name.\n */\n name: string;\n /**\n * The description of the tool.\n * @default `${fields.name} tool`\n */\n description?: string;\n /**\n * The input schema for the tool. If using an LLM, this\n * will be passed as the tool schema to generate arguments\n * for.\n */\n schema?: RunInput;\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 * 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 * Creates a new StructuredTool instance with the provided function, name, description, and schema.\n *\n * Schema can be provided as Zod or JSON schema, and both will be validated.\n *\n * @function\n * @template {ToolInputSchemaBase} SchemaT The input schema for the tool.\n * @template {ToolReturnType} ToolOutputT The output type of the tool.\n *\n * @param {RunnableFunc<z.output<SchemaT>, ToolOutputT>} func - The function to invoke when the tool is called.\n * @param {ToolWrapperParams<SchemaT>} fields - An object containing the following properties:\n * @param {string} fields.name The name of the tool.\n * @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`.\n * @param {z.AnyZodObject | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema.\n *\n * @returns {DynamicStructuredTool<SchemaT>} A new StructuredTool instance.\n */\nexport function tool<SchemaT extends ZodStringV3, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<SchemaT extends ZodStringV4, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV3,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV4,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends JSONSchema,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<\n Parameters<DynamicStructuredToolInput<SchemaT>[\"func\"]>[0],\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends\n | InteropZodObject\n | InteropZodType<string>\n | JSONSchema = InteropZodObject,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n):\n | DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>\n | DynamicTool<ToolOutputT> {\n const isSimpleStringSchema = isSimpleStringZodSchema(fields.schema);\n const isStringJSONSchema = validatesOnlyStrings(fields.schema);\n\n // If the schema is not provided, or it's a simple string schema, create a DynamicTool\n if (!fields.schema || isSimpleStringSchema || isStringJSONSchema) {\n return new DynamicTool<ToolOutputT>({\n ...fields,\n description:\n fields.description ??\n (fields.schema as { description?: string } | undefined)?.description ??\n `${fields.name} tool`,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n // TS doesn't restrict the type here based on the guard above\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(func(input as any, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n });\n }\n\n const schema = fields.schema as InteropZodObject | JSONSchema;\n\n const description =\n fields.description ??\n (fields.schema as { description?: string }).description ??\n `${fields.name} tool`;\n\n return new DynamicStructuredTool<\n typeof schema,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >({\n ...fields,\n description,\n schema,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n if (config?.signal) {\n config.signal.addEventListener(\"abort\", () => {\n return reject(getAbortSignalError(config.signal));\n });\n }\n\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n const result = await func(input, childConfig);\n\n /**\n * If the signal is aborted, we don't want to resolve the promise\n * as the promise is already rejected.\n */\n if (config?.signal?.aborted) {\n return;\n }\n\n resolve(result);\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n }) as DynamicStructuredTool<\n SchemaT,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >;\n}\n\nfunction _formatToolOutput<TOutput extends ToolOutputType>(params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n metadata?: Record<string, unknown>;\n}): ToolMessage | TOutput {\n const { content, artifact, toolCallId, metadata } = params;\n if (toolCallId && !isDirectToolOutput(content)) {\n if (\n typeof content === \"string\" ||\n (Array.isArray(content) &&\n content.every((item) => typeof item === \"object\"))\n ) {\n return new ToolMessage({\n status: \"success\",\n content,\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n metadata,\n });\n } else {\n return new ToolMessage({\n status: \"success\",\n content: _stringify(content),\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n metadata,\n });\n }\n } else {\n return content;\n }\n}\n\nfunction _stringify(content: unknown): string {\n try {\n return J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AM,cAAc,YAAY,QAAQ,EACtC,WAAW,YAAY,UAAU,CAClC,EAAC;IAEG,mCAAmC,cACtC,uBAAuB,YAAY,EACnC,YAAY;AACV,SAAI;MACF,MAAM,SAAS,MAAM,KAAK,OAAO,YAAY;;;;;AAM7C,UAAI,QAAQ,QAAQ,QAClB;MAGF,QAAQ,OAAO;KAChB,SAAQ,GAAG;MACV,OAAO,EAAE;KACV;IACF,EACF;GACF;EACF;CACF;AAMF;AAED,SAAS,kBAAkDC,QAMjC;CACxB,MAAM,EAAE,SAAS,UAAU,YAAY,UAAU,GAAG;AACpD,KAAI,cAAc,CAAC,mBAAmB,QAAQ,CAC5C,KACE,OAAO,YAAY,YAClB,MAAM,QAAQ,QAAQ,IACrB,QAAQ,MAAM,CAAC,SAAS,OAAO,SAAS,SAAS,CAEnD,QAAO,IAAI,YAAY;EACrB,QAAQ;EACR;EACA;EACA,cAAc;EACd,MAAM,OAAO;EACb;CACD;KAED,QAAO,IAAI,YAAY;EACrB,QAAQ;EACR,SAAS,WAAW,QAAQ;EAC5B;EACA,cAAc;EACd,MAAM,OAAO;EACb;CACD;KAGH,QAAO;AAEV;AAED,SAAS,WAAWC,SAA0B;AAC5C,KAAI;AACF,SAAO,KAAK,UAAU,SAAS,MAAM,EAAE,IAAI;CAC5C,SAAQ,OAAO;AACd,SAAO,GAAG,SAAS;CACpB;AACF"}
|
package/dist/tools/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","names":["tool?: StructuredToolInterface | ToolDefinition | JSONSchema","tool?: unknown","Runnable","isInteropZodSchema"],"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\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":";;;;;;;;;;AAoWA,SAAgB,iBACdA,MACiC;AACjC,QACE,SAAS,UACT,MAAM,QAAS,KAAiC,aAAa;AAEhE;;;;;;;AAQD,SAAgB,mBAAmBC,MAA0C;AAC3E,QACE,SAAS,UACTC,sBAAS,WAAW,KAAK,IACzB,aAAa,KAAK,eAClB,OAAO,KAAK,YAAY,YAAY,cACpC,KAAK,YAAY,SAAS,KAAK;AAElC;;;;;;;AAQD,SAAgB,uBACdD,MAC8B;AAC9B,QACE,CAAC,CAAC,QACF,OAAO,SAAS,YAChB,UAAU,QACV,YAAY,SAEXE,+BAAmB,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,gBAAgBF,MAA8C;AAC5E,QACE,uBAAuB,KAAK,IAC5B,mBAAmB,KAAK,IAExB,iBAAiB,KAAY;AAEhC"}
|
|
1
|
+
{"version":3,"file":"types.cjs","names":["tool?: StructuredToolInterface | ToolDefinition | JSONSchema","tool?: unknown","Runnable","isInteropZodSchema"],"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,UACTC,sBAAS,WAAW,KAAK,IACzB,aAAa,KAAK,eAClB,OAAO,KAAK,YAAY,YAAY,cACpC,KAAK,YAAY,SAAS,KAAK;AAElC;;;;;;;AAQD,SAAgB,uBACdD,MAC8B;AAC9B,QACE,CAAC,CAAC,QACF,OAAO,SAAS,YAChB,UAAU,QACV,YAAY,SAEXE,+BAAmB,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,gBAAgBF,MAA8C;AAC5E,QACE,uBAAuB,KAAK,IAC5B,mBAAmB,KAAK,IAExB,iBAAiB,KAAY;AAEhC"}
|
package/dist/tools/types.d.cts
CHANGED
|
@@ -62,6 +62,10 @@ interface ToolParams extends BaseLangChainParams {
|
|
|
62
62
|
* @default false
|
|
63
63
|
*/
|
|
64
64
|
verboseParsingErrors?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Metadata for the tool.
|
|
67
|
+
*/
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
65
69
|
}
|
|
66
70
|
type ToolRunnableConfig<
|
|
67
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -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}\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;;;;AAA4B,UAAtCU,UAAAA,SAAmBtB,mBAAmB,CAAA;EAsB3CuB;;;;;;;;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EAAA,MAAA,EAAA,CAAA,EAlFlBP,OAkFkB,CAlFV1B,cAkFU,CAlFKyB,IAkFL,EAlFWvB,OAkFX,EAlFoBsB,WAkFpB,CAAA,CAAA;EAAA;;;EAA6D,IAAWZ,EAAAA,MAAAA;EAAuB;AAOvI;AAOA;EASwBwB,WAAAA,EAAAA,MAAe;;;;;;;;;;;;;;;UAlFtBT,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","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,S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AAA,0BAA4C/C;;;;;;;iBAO5CgD,sBAAAA,0BAAgDxB;;;;;;;;;iBAShDyB,eAAAA,0BAAyCzB"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -62,6 +62,10 @@ interface ToolParams extends BaseLangChainParams {
|
|
|
62
62
|
* @default false
|
|
63
63
|
*/
|
|
64
64
|
verboseParsingErrors?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Metadata for the tool.
|
|
67
|
+
*/
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
65
69
|
}
|
|
66
70
|
type ToolRunnableConfig<
|
|
67
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -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}\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;;;;AAA4B,UAAtCU,UAAAA,SAAmBtB,mBAAmB,CAAA;EAsB3CuB;;;;;;;;AAMe;EAOVI,cAAAA,CAAAA,EAzBId,cAyBgB;EAAA;;;EAAa,aAAA,CAAA,EArB9BU,kBAqB8B;EAiBtCO;;;;;EAAiF,oBAAvBpB,CAAAA,EAAAA,OAAAA;;AAAqCE,K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A,MAAAA;EAAuB;AAOvI;AAOA;EASwBwB,WAAAA,EAAAA,MAAe;;;;;;;;;;;;;;;UAlFtBT,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","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,GALq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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\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":";;;;;;;;;;AAoWA,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} 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"}
|
package/dist/tracers/base.cjs
CHANGED
|
@@ -24,7 +24,7 @@ function convertRunToRunTree(run, parentRun) {
|
|
|
24
24
|
child_runs: run.child_runs.map((r) => convertRunToRunTree(r)).filter((r) => r !== void 0),
|
|
25
25
|
extra: {
|
|
26
26
|
...run.extra,
|
|
27
|
-
runtime: require_utils_env.
|
|
27
|
+
runtime: require_utils_env.getRuntimeEnvironment()
|
|
28
28
|
},
|
|
29
29
|
tracingEnabled: false
|
|
30
30
|
});
|