@langchain/core 1.0.0-alpha.3 → 1.0.0-alpha.4
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/README.md +3 -19
- package/dist/caches/base.cjs +2 -2
- package/dist/caches/base.cjs.map +1 -1
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/document_loaders/langsmith.cjs +1 -1
- package/dist/document_loaders/langsmith.cjs.map +1 -1
- package/dist/document_loaders/langsmith.js +1 -1
- package/dist/document_loaders/langsmith.js.map +1 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +6 -6
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +6 -6
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/indexing/base.cjs +2 -2
- package/dist/indexing/base.cjs.map +1 -1
- package/dist/indexing/base.d.cts +0 -3
- package/dist/indexing/base.d.cts.map +1 -1
- package/dist/indexing/base.d.ts +0 -3
- package/dist/indexing/base.d.ts.map +1 -1
- package/dist/indexing/base.js +2 -2
- package/dist/indexing/base.js.map +1 -1
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +3 -3
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +3 -3
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.cjs.map +1 -1
- package/dist/language_models/llms.js.map +1 -1
- package/dist/load/import_map.cjs +1 -5
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +3 -7
- package/dist/load/import_map.js.map +1 -1
- package/dist/load/index.cjs.map +1 -1
- package/dist/load/index.js.map +1 -1
- package/dist/load/serializable.cjs.map +1 -1
- package/dist/load/serializable.d.cts +1 -3
- package/dist/load/serializable.d.cts.map +1 -1
- package/dist/load/serializable.d.ts +1 -3
- package/dist/load/serializable.d.ts.map +1 -1
- package/dist/load/serializable.js.map +1 -1
- package/dist/messages/ai.cjs +2 -2
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +2 -2
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +5 -5
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +1 -2
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +1 -2
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +5 -5
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/block_translators/utils.cjs +1 -1
- package/dist/messages/block_translators/utils.cjs.map +1 -1
- package/dist/messages/block_translators/utils.js +1 -1
- package/dist/messages/block_translators/utils.js.map +1 -1
- package/dist/messages/index.cjs +1 -1
- package/dist/messages/index.js +1 -1
- package/dist/messages/modifier.cjs +4 -1
- package/dist/messages/modifier.cjs.map +1 -1
- package/dist/messages/modifier.js +4 -1
- package/dist/messages/modifier.js.map +1 -1
- package/dist/messages/tool.cjs +7 -7
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.js +7 -7
- package/dist/messages/tool.js.map +1 -1
- package/dist/messages/transformers.cjs +2 -2
- package/dist/messages/transformers.cjs.map +1 -1
- package/dist/messages/transformers.js +2 -2
- package/dist/messages/transformers.js.map +1 -1
- package/dist/messages/utils.cjs +5 -0
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.js +5 -0
- package/dist/messages/utils.js.map +1 -1
- package/dist/output_parsers/list.cjs +1 -1
- package/dist/output_parsers/list.cjs.map +1 -1
- package/dist/output_parsers/list.js +1 -1
- package/dist/output_parsers/list.js.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
- package/dist/output_parsers/structured.cjs +2 -1
- package/dist/output_parsers/structured.cjs.map +1 -1
- package/dist/output_parsers/structured.js +2 -1
- package/dist/output_parsers/structured.js.map +1 -1
- package/dist/prompts/chat.cjs +3 -1
- package/dist/prompts/chat.cjs.map +1 -1
- package/dist/prompts/chat.d.cts +4 -12
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +4 -12
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/chat.js +3 -1
- package/dist/prompts/chat.js.map +1 -1
- package/dist/prompts/image.cjs.map +1 -1
- package/dist/prompts/image.d.cts +0 -2
- package/dist/prompts/image.d.cts.map +1 -1
- package/dist/prompts/image.d.ts +0 -2
- package/dist/prompts/image.d.ts.map +1 -1
- package/dist/prompts/image.js.map +1 -1
- package/dist/prompts/pipeline.cjs.map +1 -1
- package/dist/prompts/pipeline.js.map +1 -1
- package/dist/prompts/prompt.cjs.map +1 -1
- package/dist/prompts/prompt.d.cts +4 -16
- package/dist/prompts/prompt.d.cts.map +1 -1
- package/dist/prompts/prompt.d.ts +4 -16
- package/dist/prompts/prompt.d.ts.map +1 -1
- package/dist/prompts/prompt.js.map +1 -1
- package/dist/prompts/structured.cjs.map +1 -1
- package/dist/prompts/structured.js.map +1 -1
- package/dist/prompts/template.cjs +4 -2
- package/dist/prompts/template.cjs.map +1 -1
- package/dist/prompts/template.js +4 -2
- package/dist/prompts/template.js.map +1 -1
- package/dist/runnables/base.cjs +6 -6
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +0 -3
- package/dist/runnables/base.d.cts.map +1 -1
- package/dist/runnables/base.d.ts +0 -3
- package/dist/runnables/base.d.ts.map +1 -1
- package/dist/runnables/base.js +6 -6
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/branch.cjs +2 -2
- package/dist/runnables/branch.cjs.map +1 -1
- package/dist/runnables/branch.js +2 -2
- package/dist/runnables/branch.js.map +1 -1
- package/dist/runnables/config.cjs.map +1 -1
- package/dist/runnables/config.js.map +1 -1
- package/dist/runnables/graph.cjs +1 -1
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.js +1 -1
- package/dist/runnables/graph.js.map +1 -1
- package/dist/runnables/graph_mermaid.cjs +26 -3
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +26 -3
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/remote.cjs.map +1 -1
- package/dist/runnables/remote.js.map +1 -1
- package/dist/runnables/types.d.cts +0 -1
- package/dist/runnables/types.d.cts.map +1 -1
- package/dist/runnables/types.d.ts +0 -1
- package/dist/runnables/types.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/context.cjs.map +1 -1
- package/dist/singletons/async_local_storage/context.d.cts +0 -1
- package/dist/singletons/async_local_storage/context.d.cts.map +1 -1
- package/dist/singletons/async_local_storage/context.d.ts +0 -1
- package/dist/singletons/async_local_storage/context.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/context.js.map +1 -1
- package/dist/singletons/callbacks.cjs.map +1 -1
- package/dist/singletons/callbacks.js.map +1 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +2 -2
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.cts +5 -5
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +5 -5
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/console.cjs +1 -1
- package/dist/tracers/console.cjs.map +1 -1
- package/dist/tracers/console.js +1 -1
- package/dist/tracers/console.js.map +1 -1
- package/dist/tracers/event_stream.cjs +1 -1
- package/dist/tracers/event_stream.cjs.map +1 -1
- package/dist/tracers/event_stream.d.cts +0 -1
- package/dist/tracers/event_stream.d.cts.map +1 -1
- package/dist/tracers/event_stream.d.ts +0 -1
- package/dist/tracers/event_stream.d.ts.map +1 -1
- package/dist/tracers/event_stream.js +1 -1
- package/dist/tracers/event_stream.js.map +1 -1
- package/dist/tracers/log_stream.cjs.map +1 -1
- package/dist/tracers/log_stream.js.map +1 -1
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/utils/chunk_array.cjs.map +1 -1
- package/dist/utils/chunk_array.js.map +1 -1
- package/dist/utils/env.cjs +1 -1
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.js +1 -1
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/event_source_parse.cjs.map +1 -1
- package/dist/utils/event_source_parse.d.cts.map +1 -1
- package/dist/utils/event_source_parse.d.ts.map +1 -1
- package/dist/utils/event_source_parse.js.map +1 -1
- package/dist/utils/hash.cjs +3 -8
- package/dist/utils/hash.cjs.map +1 -1
- package/dist/utils/hash.d.cts +1 -2
- package/dist/utils/hash.d.cts.map +1 -1
- package/dist/utils/hash.d.ts +1 -2
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +2 -6
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/js-sha256/hash.cjs +0 -9
- package/dist/utils/js-sha256/hash.cjs.map +1 -1
- package/dist/utils/js-sha256/hash.js +1 -5
- package/dist/utils/js-sha256/hash.js.map +1 -1
- package/dist/utils/json.cjs +2 -2
- package/dist/utils/json.cjs.map +1 -1
- package/dist/utils/json.js +2 -2
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/json_schema.cjs +3 -2
- package/dist/utils/json_schema.cjs.map +1 -1
- package/dist/utils/json_schema.d.cts +8 -4
- package/dist/utils/json_schema.d.cts.map +1 -1
- package/dist/utils/json_schema.d.ts +8 -4
- package/dist/utils/json_schema.d.ts.map +1 -1
- package/dist/utils/json_schema.js +2 -1
- package/dist/utils/json_schema.js.map +1 -1
- package/dist/utils/stream.cjs.map +1 -1
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/testing/index.cjs.map +1 -1
- package/dist/utils/testing/index.d.cts +4 -9
- package/dist/utils/testing/index.d.cts.map +1 -1
- package/dist/utils/testing/index.d.ts +4 -9
- package/dist/utils/testing/index.d.ts.map +1 -1
- package/dist/utils/testing/index.js.map +1 -1
- package/dist/utils/zod-to-json-schema/Options.cjs +40 -0
- package/dist/utils/zod-to-json-schema/Options.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/Options.js +37 -0
- package/dist/utils/zod-to-json-schema/Options.js.map +1 -0
- package/dist/utils/zod-to-json-schema/Refs.cjs +30 -0
- package/dist/utils/zod-to-json-schema/Refs.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/Refs.js +30 -0
- package/dist/utils/zod-to-json-schema/Refs.js.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.cjs +18 -0
- package/dist/utils/zod-to-json-schema/errorMessages.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts +11 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts +11 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.js +16 -0
- package/dist/utils/zod-to-json-schema/errorMessages.js.map +1 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.cjs +11 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.js +10 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.js.map +1 -0
- package/dist/utils/zod-to-json-schema/index.cjs +37 -0
- package/dist/utils/zod-to-json-schema/index.js +37 -0
- package/dist/utils/zod-to-json-schema/parseDef.cjs +57 -0
- package/dist/utils/zod-to-json-schema/parseDef.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parseDef.js +57 -0
- package/dist/utils/zod-to-json-schema/parseDef.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts +38 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts +38 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.cjs +17 -0
- package/dist/utils/zod-to-json-schema/parsers/any.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/any.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.cjs +24 -0
- package/dist/utils/zod-to-json-schema/parsers/array.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts +14 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.js +23 -0
- package/dist/utils/zod-to-json-schema/parsers/array.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.cjs +36 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.js +36 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.cjs +9 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.js +8 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.cjs +39 -0
- package/dist/utils/zod-to-json-schema/parsers/date.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.js +39 -0
- package/dist/utils/zod-to-json-schema/parsers/date.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/default.cjs +13 -0
- package/dist/utils/zod-to-json-schema/parsers/default.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/default.js +13 -0
- package/dist/utils/zod-to-json-schema/parsers/default.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.cjs +11 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.cjs +12 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts +8 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.cjs +47 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts +11 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.js +47 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.cjs +18 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts +11 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.cjs +40 -0
- package/dist/utils/zod-to-json-schema/parsers/map.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.js +40 -0
- package/dist/utils/zod-to-json-schema/parsers/map.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs +18 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts +8 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.cjs +13 -0
- package/dist/utils/zod-to-json-schema/parsers/never.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.js +13 -0
- package/dist/utils/zod-to-json-schema/parsers/never.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.cjs +12 -0
- package/dist/utils/zod-to-json-schema/parsers/null.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/null.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.cjs +46 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts +13 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.js +46 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.cjs +37 -0
- package/dist/utils/zod-to-json-schema/parsers/number.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.js +37 -0
- package/dist/utils/zod-to-json-schema/parsers/number.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.cjs +64 -0
- package/dist/utils/zod-to-json-schema/parsers/object.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts +13 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.js +64 -0
- package/dist/utils/zod-to-json-schema/parsers/object.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.cjs +20 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.js +20 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs +28 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.js +28 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.cjs +57 -0
- package/dist/utils/zod-to-json-schema/parsers/record.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts +14 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.js +56 -0
- package/dist/utils/zod-to-json-schema/parsers/record.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.cjs +22 -0
- package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.js +22 -0
- package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.cjs +255 -0
- package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts +28 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts +29 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.js +254 -0
- package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.cjs +38 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.js +38 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.cjs +67 -0
- package/dist/utils/zod-to-json-schema/parsers/union.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts +24 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts +25 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.js +66 -0
- package/dist/utils/zod-to-json-schema/parsers/union.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.js.map +1 -0
- package/dist/utils/zod-to-json-schema/selectParser.cjs +81 -0
- package/dist/utils/zod-to-json-schema/selectParser.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/selectParser.js +80 -0
- package/dist/utils/zod-to-json-schema/selectParser.js.map +1 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs +70 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.js +70 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.js.map +1 -0
- package/package.json +7 -36
- package/dist/utils/js-sha1/hash.cjs +0 -291
- package/dist/utils/js-sha1/hash.cjs.map +0 -1
- package/dist/utils/js-sha1/hash.d.cts +0 -9
- package/dist/utils/js-sha1/hash.d.cts.map +0 -1
- package/dist/utils/js-sha1/hash.d.ts +0 -9
- package/dist/utils/js-sha1/hash.d.ts.map +0 -1
- package/dist/utils/js-sha1/hash.js +0 -284
- package/dist/utils/js-sha1/hash.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 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 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 }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,IAAsB,iBAAtB,cAMU,cAKV;;;;;;;CAaE,eAAe;CAEf,uBAAuB;CAEvB,IAAI,eAAe;AACjB,SAAO,CAAC,aAAa,OAAQ;CAC9B;;;;;;;;;;CAWD,iBAAkC;;;;CAKlC;CAEA,YAAYA,QAAqB;EAC/B,MAAM,UAAU,CAAE,EAAC;EAEnB,KAAK,uBACH,QAAQ,wBAAwB,KAAK;EACvC,KAAK,iBAAiB,QAAQ,kBAAkB,KAAK;EACrD,KAAK,gBAAgB,QAAQ,iBAAiB,KAAK;CACpD;;;;;;;CAcD,MAAM,OAIJC,OACAC,QACuD;EACvD,IAAIC;EAKJ,IAAIC,iBAAqC,aACvC,aAAa,KAAK,eAAe,OAAO,CACzC;AACD,MAAI,YAAY,MAAM,EAAE;GACtB,YAAY,MAAM;GAIlB,iBAAiB;IACf,GAAG;IACH,UAAU;GACX;EACF,OACC,YAAY;AAMd,S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["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 }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,IAAsB,iBAAtB,cAMU,cAKV;;;;;;;CAaE,eAAe;CAEf,uBAAuB;CAEvB,IAAI,eAAe;AACjB,SAAO,CAAC,aAAa,OAAQ;CAC9B;;;;;;;;;;CAWD,iBAAkC;;;;CAKlC;CAEA,YAAYA,QAAqB;EAC/B,MAAM,UAAU,CAAE,EAAC;EAEnB,KAAK,uBACH,QAAQ,wBAAwB,KAAK;EACvC,KAAK,iBAAiB,QAAQ,kBAAkB,KAAK;EACrD,KAAK,gBAAgB,QAAQ,iBAAiB,KAAK;CACpD;;;;;;;CAcD,MAAM,OAIJC,OACAC,QACuD;EACvD,IAAIC;EAKJ,IAAIC,iBAAqC,aACvC,aAAa,KAAK,eAAe,OAAO,CACzC;AACD,MAAI,YAAY,MAAM,EAAE;GACtB,YAAY,MAAM;GAIlB,iBAAiB;IACf,GAAG;IACH,UAAU;GACX;EACF,OACC,YAAY;AAMd,SAAO,KAAK,KAAK,WAAW,eAAe;CAG5C;;;;;;;;;;;;CAaD,MAAM,KAIJC,KACAC,WAEAC,MACqD;EAGrD,MAAM,qBAAqB,YAAY,IAAI,GAAG,IAAI,OAAO;EAEzD,IAAIC;AACJ,MAAI,mBAAmB,KAAK,OAAO,CACjC,KAAI;GAEF,SAAS,MAAM,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WAAW;AACzC,UAAO,IAAI,QAAqB,CAAC,SAAS,WAAW;AACnD,QAAI,QAAQ,QACV,OAAO,OAAO,iBAAiB,SAAS,MAAM;AAC5C,YAAO,OAAO,oBAAoB,OAAO,OAAO,CAAC;IAClD,EAAC;IAGJ,MAAM,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,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"}
|
package/dist/tools/types.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { InferInteropZodInput, InferInteropZodOutput, InteropZodType } from "../
|
|
|
4
4
|
import { CallbackManagerForToolRun } from "../callbacks/manager.cjs";
|
|
5
5
|
import { RunnableConfig, RunnableInterface } from "../runnables/types.cjs";
|
|
6
6
|
import { RunnableToolLike } from "../runnables/base.cjs";
|
|
7
|
-
import {
|
|
7
|
+
import { JsonSchema7Type } from "../utils/zod-to-json-schema/parseTypes.cjs";
|
|
8
8
|
import { BaseLangChainParams, ToolDefinition } from "../language_models/base.cjs";
|
|
9
9
|
import { z } from "zod/v3";
|
|
10
10
|
|
|
@@ -37,7 +37,7 @@ type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput
|
|
|
37
37
|
* Base type that establishes the types of input schemas that can be used for LangChain tool
|
|
38
38
|
* definitions.
|
|
39
39
|
*/
|
|
40
|
-
type ToolInputSchemaBase = z.ZodTypeAny |
|
|
40
|
+
type ToolInputSchemaBase = z.ZodTypeAny | JsonSchema7Type;
|
|
41
41
|
/**
|
|
42
42
|
* Parameters for the Tool classes.
|
|
43
43
|
*/
|
|
@@ -93,7 +93,7 @@ interface StructuredToolParams extends Pick<StructuredToolInterface, "name" | "s
|
|
|
93
93
|
* applying any transforms defined in your schema. If there are no transforms, the input and output
|
|
94
94
|
* types will be the same.
|
|
95
95
|
*/
|
|
96
|
-
type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends
|
|
96
|
+
type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JsonSchema7Type ? unknown : never;
|
|
97
97
|
/**
|
|
98
98
|
* Utility type that resolves the input type of a tool input schema.
|
|
99
99
|
*
|
|
@@ -105,7 +105,7 @@ type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOu
|
|
|
105
105
|
* applying any transforms defined in your schema. If there are no transforms, the input and output
|
|
106
106
|
* types will be the same.
|
|
107
107
|
*/
|
|
108
|
-
type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends
|
|
108
|
+
type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JsonSchema7Type ? unknown : never;
|
|
109
109
|
/**
|
|
110
110
|
* Defines the type that will be passed into a tool handler function as a result of a tool call.
|
|
111
111
|
*
|
|
@@ -254,7 +254,7 @@ interface DynamicStructuredToolInput<SchemaT = ToolInputSchemaBase, SchemaOutput
|
|
|
254
254
|
* @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.
|
|
255
255
|
* @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.
|
|
256
256
|
*/
|
|
257
|
-
declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition |
|
|
257
|
+
declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition | JsonSchema7Type): tool is StructuredToolInterface;
|
|
258
258
|
/**
|
|
259
259
|
* Confirm whether the inputted tool is an instance of `RunnableToolLike`.
|
|
260
260
|
*
|
|
@@ -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,UAIvB;;;;AAA4B,UAAtCU,UAAAA,SAAmBtB,mBAAmB,CAAA;EAsB3CuB;;;;;;;;AAMe;EAOVI,cAAAA,CAAAA,EAzBId,cAyBgB;EAAA;;;EAAa,aAAA,CAAA,EArB9BU,kBAqB8B;EAiBtCO;;;;;EAAiF,oBAAvBpB,CAAAA,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A;;;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,qBAAqBgB;;;;;;;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}\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;;;AAA6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AAA,EAAA,gBAlEnGZ,kBAkEmG,GAAA,SAAA,CAAA,CAAA,GAAA,EAlE9DkB,IAkE8D,EAAA,SAAA,CAAA,EAlE5CvB,OAkE4C,EAkBjK+B;EAAgB,IAAA,CAAA,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"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { InferInteropZodInput, InferInteropZodOutput, InteropZodType } from "../
|
|
|
4
4
|
import { CallbackManagerForToolRun } from "../callbacks/manager.js";
|
|
5
5
|
import { RunnableConfig, RunnableInterface } from "../runnables/types.js";
|
|
6
6
|
import { RunnableToolLike } from "../runnables/base.js";
|
|
7
|
-
import {
|
|
7
|
+
import { JsonSchema7Type } from "../utils/zod-to-json-schema/parseTypes.js";
|
|
8
8
|
import { BaseLangChainParams, ToolDefinition } from "../language_models/base.js";
|
|
9
9
|
import { z } from "zod/v3";
|
|
10
10
|
|
|
@@ -37,7 +37,7 @@ type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput
|
|
|
37
37
|
* Base type that establishes the types of input schemas that can be used for LangChain tool
|
|
38
38
|
* definitions.
|
|
39
39
|
*/
|
|
40
|
-
type ToolInputSchemaBase = z.ZodTypeAny |
|
|
40
|
+
type ToolInputSchemaBase = z.ZodTypeAny | JsonSchema7Type;
|
|
41
41
|
/**
|
|
42
42
|
* Parameters for the Tool classes.
|
|
43
43
|
*/
|
|
@@ -93,7 +93,7 @@ interface StructuredToolParams extends Pick<StructuredToolInterface, "name" | "s
|
|
|
93
93
|
* applying any transforms defined in your schema. If there are no transforms, the input and output
|
|
94
94
|
* types will be the same.
|
|
95
95
|
*/
|
|
96
|
-
type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends
|
|
96
|
+
type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JsonSchema7Type ? unknown : never;
|
|
97
97
|
/**
|
|
98
98
|
* Utility type that resolves the input type of a tool input schema.
|
|
99
99
|
*
|
|
@@ -105,7 +105,7 @@ type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOu
|
|
|
105
105
|
* applying any transforms defined in your schema. If there are no transforms, the input and output
|
|
106
106
|
* types will be the same.
|
|
107
107
|
*/
|
|
108
|
-
type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends
|
|
108
|
+
type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JsonSchema7Type ? unknown : never;
|
|
109
109
|
/**
|
|
110
110
|
* Defines the type that will be passed into a tool handler function as a result of a tool call.
|
|
111
111
|
*
|
|
@@ -254,7 +254,7 @@ interface DynamicStructuredToolInput<SchemaT = ToolInputSchemaBase, SchemaOutput
|
|
|
254
254
|
* @param {StructuredToolInterface | JSONSchema | undefined} tool The tool to check if it is an instance of `StructuredToolInterface`.
|
|
255
255
|
* @returns {tool is StructuredToolInterface} Whether the inputted tool is an instance of `StructuredToolInterface`.
|
|
256
256
|
*/
|
|
257
|
-
declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition |
|
|
257
|
+
declare function isStructuredTool(tool?: StructuredToolInterface | ToolDefinition | JsonSchema7Type): tool is StructuredToolInterface;
|
|
258
258
|
/**
|
|
259
259
|
* Confirm whether the inputted tool is an instance of `RunnableToolLike`.
|
|
260
260
|
*
|
|
@@ -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,UAIvB;;;;AAA4B,UAAtCU,UAAAA,SAAmBtB,mBAAmB,CAAA;EAsB3CuB;;;;;;;;AAMe;EAOVI,cAAAA,CAAAA,EAzBId,cAyBgB;EAAA;;;EAAa,aAAA,CAAA,EArB9BU,kBAqB8B;EAiBtCO;;;;;EAAiF,oBAAvB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,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,qBAAqBgB;;;;;;;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}\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,OAK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,YAkEkI,CAAA,EAAA,gBAlEnGZ,kBAkEmG,GAAA,SAAA,CAAA,CAAA,GAAA,EAlE9DkB,IAkE8D,EAAA,SAAA,CAAA,EAlE5CvB,OAkE4C,EAkBjK+B;EAAgB,IAAA,CAAA,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.cjs","names":["runTree?: RunTree","run?: Run","parentRun?: Run","RunTree","getRuntimeEnvironmentSync","value: any","defaultKey: string","x: BaseCallbackHandler","BaseCallbackHandler","_fields?: BaseCallbackHandlerInput","runId?: string","error: unknown","parentRun: Run","childRun: Run","run: Run","parentRunId: string | undefined","llm: Serialized","prompts: string[]","runId: string","parentRunId?: string","extraParams?: KVMap","tags?: string[]","metadata?: KVMap","name?: string","messages: BaseMessage[][]","output: LLMResult","_parentRunId?: string","_tags?: string[]","extraParams?: Record<string, unknown>","chain: Serialized","inputs: ChainValues","runType?: string","outputs: ChainValues","kwargs?: { inputs?: Record<string, unknown> }","tool: Serialized","input: string","output: any","action: AgentAction","action: AgentFinish","retriever: Serialized","query: string","documents: Document<Record<string, unknown>>[]","text: string","token: string","idx: NewTokenIndices","fields?: HandleLLMNewTokenCallbackFields"],"sources":["../../src/tracers/base.ts"],"sourcesContent":["import { KVMap, BaseRun } from \"langsmith/schemas\";\nimport { RunTree, convertToDottedOrderFormat } from \"langsmith/run_trees\";\n\nimport type { ChainValues } from \"../utils/types/index.js\";\nimport type { AgentAction, AgentFinish } from \"../agents.js\";\nimport type { LLMResult } from \"../outputs.js\";\nimport type { BaseMessage } from \"../messages/base.js\";\nimport { Serialized } from \"../load/serializable.js\";\nimport {\n BaseCallbackHandler,\n BaseCallbackHandlerInput,\n HandleLLMNewTokenCallbackFields,\n NewTokenIndices,\n} from \"../callbacks/base.js\";\nimport type { Document } from \"../documents/document.js\";\nimport { getRuntimeEnvironmentSync } from \"../utils/env.js\";\n\nexport type RunType = string;\n\n// TODO: Remove this type and just use the base LangSmith Run type.\nexport interface Run extends BaseRun {\n // some optional fields are always present here\n id: string;\n start_time: number;\n end_time?: number;\n execution_order: number;\n // some additional fields that don't exist in sdk runs\n child_runs: this[];\n child_execution_order: number;\n events: Array<{\n name: string;\n time: string;\n kwargs?: Record<string, unknown>;\n }>;\n trace_id?: string;\n dotted_order?: string;\n /** @internal */\n _serialized_start_time?: string;\n}\n\n// TODO: Remove and just use base LangSmith Run type\nconst convertRunTreeToRun = (runTree?: RunTree): Run | undefined => {\n if (!runTree) {\n return undefined;\n }\n // Important that we return the raw run tree object since the reference\n // is mutated in other places.\n // TODO: Remove places where this is being done.\n\n // eslint-disable-next-line no-param-reassign\n runTree.events = runTree.events ?? [];\n // eslint-disable-next-line no-param-reassign\n runTree.child_runs = runTree.child_runs ?? [];\n // TODO: Remove this cast and just use the LangSmith RunTree type.\n return runTree as unknown as Run;\n};\n\nfunction convertRunToRunTree(run?: Run, parentRun?: Run): RunTree | undefined {\n if (!run) {\n return undefined;\n }\n return new RunTree({\n ...run,\n start_time: run._serialized_start_time ?? run.start_time,\n parent_run: convertRunToRunTree(parentRun),\n child_runs: run.child_runs\n .map((r) => convertRunToRunTree(r))\n .filter((r): r is RunTree => r !== undefined),\n extra: {\n ...run.extra,\n runtime: getRuntimeEnvironmentSync(),\n },\n tracingEnabled: false,\n });\n}\n\nexport interface AgentRun extends Run {\n actions: AgentAction[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _coerceToDict(value: any, defaultKey: string) {\n return value && !Array.isArray(value) && typeof value === \"object\"\n ? value\n : { [defaultKey]: value };\n}\n\nexport function isBaseTracer(x: BaseCallbackHandler): x is BaseTracer {\n return typeof (x as BaseTracer)._addRunToRunMap === \"function\";\n}\n\nexport abstract class BaseTracer extends BaseCallbackHandler {\n /** @deprecated Use `runTreeMap` instead. */\n protected runMap: Map<string, Run> = new Map();\n\n protected runTreeMap: Map<string, RunTree> = new Map();\n\n protected usesRunTreeMap = false;\n\n constructor(_fields?: BaseCallbackHandlerInput) {\n super(...arguments);\n }\n\n copy(): this {\n return this;\n }\n\n protected getRunById(runId?: string): Run | undefined {\n if (runId === undefined) {\n return undefined;\n }\n return this.usesRunTreeMap\n ? convertRunTreeToRun(this.runTreeMap.get(runId))\n : this.runMap.get(runId);\n }\n\n protected stringifyError(error: unknown) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n return error.message + (error?.stack ? `\\n\\n${error.stack}` : \"\");\n }\n\n if (typeof error === \"string\") {\n return error;\n }\n\n return `${error}`;\n }\n\n protected abstract persistRun(run: Run): Promise<void>;\n\n protected _addChildRun(parentRun: Run, childRun: Run) {\n parentRun.child_runs.push(childRun);\n }\n\n _addRunToRunMap(run: Run) {\n const { dottedOrder: currentDottedOrder, microsecondPrecisionDatestring } =\n convertToDottedOrderFormat(\n new Date(run.start_time).getTime(),\n run.id,\n run.execution_order\n );\n const storedRun = { ...run };\n const parentRun = this.getRunById(storedRun.parent_run_id);\n if (storedRun.parent_run_id !== undefined) {\n if (parentRun) {\n this._addChildRun(parentRun, storedRun);\n parentRun.child_execution_order = Math.max(\n parentRun.child_execution_order,\n storedRun.child_execution_order\n );\n storedRun.trace_id = parentRun.trace_id;\n if (parentRun.dotted_order !== undefined) {\n storedRun.dotted_order = [\n parentRun.dotted_order,\n currentDottedOrder,\n ].join(\".\");\n storedRun._serialized_start_time = microsecondPrecisionDatestring;\n } else {\n // This can happen naturally for callbacks added within a run\n // console.debug(`Parent run with UUID ${storedRun.parent_run_id} has no dotted order.`);\n }\n } else {\n // This can happen naturally for callbacks added within a run\n // console.debug(\n // `Parent run with UUID ${storedRun.parent_run_id} not found.`\n // );\n }\n } else {\n storedRun.trace_id = storedRun.id;\n storedRun.dotted_order = currentDottedOrder;\n storedRun._serialized_start_time = microsecondPrecisionDatestring;\n }\n if (this.usesRunTreeMap) {\n const runTree = convertRunToRunTree(storedRun, parentRun);\n if (runTree !== undefined) {\n this.runTreeMap.set(storedRun.id, runTree);\n }\n } else {\n this.runMap.set(storedRun.id, storedRun);\n }\n return storedRun;\n }\n\n protected async _endTrace(run: Run): Promise<void> {\n const parentRun =\n run.parent_run_id !== undefined && this.getRunById(run.parent_run_id);\n if (parentRun) {\n parentRun.child_execution_order = Math.max(\n parentRun.child_execution_order,\n run.child_execution_order\n );\n } else {\n await this.persistRun(run);\n }\n await this.onRunUpdate?.(run);\n if (this.usesRunTreeMap) {\n this.runTreeMap.delete(run.id);\n } else {\n this.runMap.delete(run.id);\n }\n }\n\n protected _getExecutionOrder(parentRunId: string | undefined): number {\n const parentRun = parentRunId !== undefined && this.getRunById(parentRunId);\n // If a run has no parent then execution order is 1\n if (!parentRun) {\n return 1;\n }\n\n return parentRun.child_execution_order + 1;\n }\n\n /**\n * Create and add a run to the run map for LLM start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForLLMStart(\n llm: Serialized,\n prompts: string[],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const finalExtraParams = metadata\n ? { ...extraParams, metadata }\n : extraParams;\n const run: Run = {\n id: runId,\n name: name ?? llm.id[llm.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: llm,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { prompts },\n execution_order,\n child_runs: [],\n child_execution_order: execution_order,\n run_type: \"llm\",\n extra: finalExtraParams ?? {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleLLMStart(\n llm: Serialized,\n prompts: string[],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForLLMStart(\n llm,\n prompts,\n runId,\n parentRunId,\n extraParams,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onLLMStart?.(run);\n return run;\n }\n\n /**\n * Create and add a run to the run map for chat model start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForChatModelStart(\n llm: Serialized,\n messages: BaseMessage[][],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const finalExtraParams = metadata\n ? { ...extraParams, metadata }\n : extraParams;\n const run: Run = {\n id: runId,\n name: name ?? llm.id[llm.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: llm,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { messages },\n execution_order,\n child_runs: [],\n child_execution_order: execution_order,\n run_type: \"llm\",\n extra: finalExtraParams ?? {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleChatModelStart(\n llm: Serialized,\n messages: BaseMessage[][],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForChatModelStart(\n llm,\n messages,\n runId,\n parentRunId,\n extraParams,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onLLMStart?.(run);\n return run;\n }\n\n async handleLLMEnd(\n output: LLMResult,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n extraParams?: Record<string, unknown>\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"llm\") {\n throw new Error(\"No LLM run to end.\");\n }\n run.end_time = Date.now();\n run.outputs = output;\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n run.extra = { ...run.extra, ...extraParams };\n await this.onLLMEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleLLMError(\n error: unknown,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n extraParams?: Record<string, unknown>\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"llm\") {\n throw new Error(\"No LLM run to end.\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n run.extra = { ...run.extra, ...extraParams };\n await this.onLLMError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n /**\n * Create and add a run to the run map for chain start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForChainStart(\n chain: Serialized,\n inputs: ChainValues,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n runType?: string,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const run: Run = {\n id: runId,\n name: name ?? chain.id[chain.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: chain,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs,\n execution_order,\n child_execution_order: execution_order,\n run_type: runType ?? \"chain\",\n child_runs: [],\n extra: metadata ? { metadata } : {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleChainStart(\n chain: Serialized,\n inputs: ChainValues,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n runType?: string,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForChainStart(\n chain,\n inputs,\n runId,\n parentRunId,\n tags,\n metadata,\n runType,\n name\n );\n await this.onRunCreate?.(run);\n await this.onChainStart?.(run);\n return run;\n }\n\n async handleChainEnd(\n outputs: ChainValues,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n kwargs?: { inputs?: Record<string, unknown> }\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run) {\n throw new Error(\"No chain run to end.\");\n }\n run.end_time = Date.now();\n run.outputs = _coerceToDict(outputs, \"output\");\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n if (kwargs?.inputs !== undefined) {\n run.inputs = _coerceToDict(kwargs.inputs, \"input\");\n }\n await this.onChainEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleChainError(\n error: unknown,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n kwargs?: { inputs?: Record<string, unknown> }\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run) {\n throw new Error(\"No chain run to end.\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n if (kwargs?.inputs !== undefined) {\n run.inputs = _coerceToDict(kwargs.inputs, \"input\");\n }\n await this.onChainError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n /**\n * Create and add a run to the run map for tool start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForToolStart(\n tool: Serialized,\n input: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const run: Run = {\n id: runId,\n name: name ?? tool.id[tool.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: tool,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { input },\n execution_order,\n child_execution_order: execution_order,\n run_type: \"tool\",\n child_runs: [],\n extra: metadata ? { metadata } : {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleToolStart(\n tool: Serialized,\n input: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForToolStart(\n tool,\n input,\n runId,\n parentRunId,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onToolStart?.(run);\n return run;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async handleToolEnd(output: any, runId: string): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"tool\") {\n throw new Error(\"No tool run to end\");\n }\n run.end_time = Date.now();\n run.outputs = { output };\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onToolEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleToolError(error: unknown, runId: string): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"tool\") {\n throw new Error(\"No tool run to end\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onToolError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleAgentAction(action: AgentAction, runId: string): Promise<void> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"chain\") {\n return;\n }\n const agentRun = run as AgentRun;\n agentRun.actions = agentRun.actions || [];\n agentRun.actions.push(action);\n agentRun.events.push({\n name: \"agent_action\",\n time: new Date().toISOString(),\n kwargs: { action },\n });\n await this.onAgentAction?.(run as AgentRun);\n }\n\n async handleAgentEnd(action: AgentFinish, runId: string): Promise<void> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"chain\") {\n return;\n }\n run.events.push({\n name: \"agent_end\",\n time: new Date().toISOString(),\n kwargs: { action },\n });\n await this.onAgentEnd?.(run);\n }\n\n /**\n * Create and add a run to the run map for retriever start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForRetrieverStart(\n retriever: Serialized,\n query: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const run: Run = {\n id: runId,\n name: name ?? retriever.id[retriever.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: retriever,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { query },\n execution_order,\n child_execution_order: execution_order,\n run_type: \"retriever\",\n child_runs: [],\n extra: metadata ? { metadata } : {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleRetrieverStart(\n retriever: Serialized,\n query: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForRetrieverStart(\n retriever,\n query,\n runId,\n parentRunId,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onRetrieverStart?.(run);\n return run;\n }\n\n async handleRetrieverEnd(\n documents: Document<Record<string, unknown>>[],\n runId: string\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"retriever\") {\n throw new Error(\"No retriever run to end\");\n }\n run.end_time = Date.now();\n run.outputs = { documents };\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onRetrieverEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleRetrieverError(error: unknown, runId: string): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"retriever\") {\n throw new Error(\"No retriever run to end\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onRetrieverError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleText(text: string, runId: string): Promise<void> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"chain\") {\n return;\n }\n run.events.push({\n name: \"text\",\n time: new Date().toISOString(),\n kwargs: { text },\n });\n await this.onText?.(run);\n }\n\n async handleLLMNewToken(\n token: string,\n idx: NewTokenIndices,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n fields?: HandleLLMNewTokenCallbackFields\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"llm\") {\n throw new Error(\n `Invalid \"runId\" provided to \"handleLLMNewToken\" callback.`\n );\n }\n run.events.push({\n name: \"new_token\",\n time: new Date().toISOString(),\n kwargs: { token, idx, chunk: fields?.chunk },\n });\n await this.onLLMNewToken?.(run, token, { chunk: fields?.chunk });\n return run;\n }\n\n // custom event handlers\n\n onRunCreate?(run: Run): void | Promise<void>;\n\n onRunUpdate?(run: Run): void | Promise<void>;\n\n onLLMStart?(run: Run): void | Promise<void>;\n\n onLLMEnd?(run: Run): void | Promise<void>;\n\n onLLMError?(run: Run): void | Promise<void>;\n\n onChainStart?(run: Run): void | Promise<void>;\n\n onChainEnd?(run: Run): void | Promise<void>;\n\n onChainError?(run: Run): void | Promise<void>;\n\n onToolStart?(run: Run): void | Promise<void>;\n\n onToolEnd?(run: Run): void | Promise<void>;\n\n onToolError?(run: Run): void | Promise<void>;\n\n onAgentAction?(run: Run): void | Promise<void>;\n\n onAgentEnd?(run: Run): void | Promise<void>;\n\n onRetrieverStart?(run: Run): void | Promise<void>;\n\n onRetrieverEnd?(run: Run): void | Promise<void>;\n\n onRetrieverError?(run: Run): void | Promise<void>;\n\n onText?(run: Run): void | Promise<void>;\n\n onLLMNewToken?(\n run: Run,\n token: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n kwargs?: { chunk: any }\n ): void | Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;AAyCA,MAAM,sBAAsB,CAACA,YAAuC;AAClE,KAAI,CAAC,QACH,QAAO;CAOT,QAAQ,SAAS,QAAQ,UAAU,CAAE;CAErC,QAAQ,aAAa,QAAQ,cAAc,CAAE;AAE7C,QAAO;AACR;AAED,SAAS,oBAAoBC,KAAWC,WAAsC;AAC5E,KAAI,CAAC,IACH,QAAO;AAET,QAAO,IAAIC,4BAAQ;EACjB,GAAG;EACH,YAAY,IAAI,0BAA0B,IAAI;EAC9C,YAAY,oBAAoB,UAAU;EAC1C,YAAY,IAAI,WACb,IAAI,CAAC,MAAM,oBAAoB,EAAE,CAAC,CAClC,OAAO,CAAC,MAAoB,MAAM,OAAU;EAC/C,OAAO;GACL,GAAG,IAAI;GACP,SAASC,6CAA2B;EACrC;EACD,gBAAgB;CACjB;AACF;AAOD,SAAS,cAAcC,OAAYC,YAAoB;AACrD,QAAO,SAAS,CAAC,MAAM,QAAQ,MAAM,IAAI,OAAO,UAAU,WACtD,QACA,GAAG,aAAa,MAAO;AAC5B;AAED,SAAgB,aAAaC,GAAyC;AACpE,QAAO,OAAQ,EAAiB,oBAAoB;AACrD;AAED,IAAsB,aAAtB,cAAyCC,2CAAoB;;CAE3D,AAAU,y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,EAAE,OAAO,QAAQ,MAAO,EAAC;AAChE,SAAO;CACR;AA4CF"}
|
|
1
|
+
{"version":3,"file":"base.cjs","names":["runTree?: RunTree","run?: Run","parentRun?: Run","RunTree","getRuntimeEnvironmentSync","value: any","defaultKey: string","x: BaseCallbackHandler","BaseCallbackHandler","_fields?: BaseCallbackHandlerInput","runId?: string","error: unknown","parentRun: Run","childRun: Run","run: Run","parentRunId: string | undefined","llm: Serialized","prompts: string[]","runId: string","parentRunId?: string","extraParams?: KVMap","tags?: string[]","metadata?: KVMap","name?: string","messages: BaseMessage[][]","output: LLMResult","_parentRunId?: string","_tags?: string[]","extraParams?: Record<string, unknown>","chain: Serialized","inputs: ChainValues","runType?: string","outputs: ChainValues","kwargs?: { inputs?: Record<string, unknown> }","tool: Serialized","input: string","output: any","action: AgentAction","action: AgentFinish","retriever: Serialized","query: string","documents: Document<Record<string, unknown>>[]","text: string","token: string","idx: NewTokenIndices","fields?: HandleLLMNewTokenCallbackFields"],"sources":["../../src/tracers/base.ts"],"sourcesContent":["import { KVMap, BaseRun } from \"langsmith/schemas\";\nimport { RunTree, convertToDottedOrderFormat } from \"langsmith/run_trees\";\n\nimport type { ChainValues } from \"../utils/types/index.js\";\nimport type { AgentAction, AgentFinish } from \"../agents.js\";\nimport type { LLMResult } from \"../outputs.js\";\nimport type { BaseMessage } from \"../messages/base.js\";\nimport { Serialized } from \"../load/serializable.js\";\nimport {\n BaseCallbackHandler,\n BaseCallbackHandlerInput,\n HandleLLMNewTokenCallbackFields,\n NewTokenIndices,\n} from \"../callbacks/base.js\";\nimport type { Document } from \"../documents/document.js\";\nimport { getRuntimeEnvironmentSync } from \"../utils/env.js\";\n\nexport type RunType = string;\n\n// TODO: Remove this type and just use the base LangSmith Run type.\nexport interface Run extends BaseRun {\n // some optional fields are always present here\n id: string;\n start_time: number;\n end_time?: number;\n execution_order: number;\n // some additional fields that don't exist in sdk runs\n child_runs: this[];\n child_execution_order: number;\n events: Array<{\n name: string;\n time: string;\n kwargs?: Record<string, unknown>;\n }>;\n trace_id?: string;\n dotted_order?: string;\n /** @internal */\n _serialized_start_time?: string;\n}\n\n// TODO: Remove and just use base LangSmith Run type\nconst convertRunTreeToRun = (runTree?: RunTree): Run | undefined => {\n if (!runTree) {\n return undefined;\n }\n // Important that we return the raw run tree object since the reference\n // is mutated in other places.\n // TODO: Remove places where this is being done.\n\n runTree.events = runTree.events ?? [];\n runTree.child_runs = runTree.child_runs ?? [];\n // TODO: Remove this cast and just use the LangSmith RunTree type.\n return runTree as unknown as Run;\n};\n\nfunction convertRunToRunTree(run?: Run, parentRun?: Run): RunTree | undefined {\n if (!run) {\n return undefined;\n }\n return new RunTree({\n ...run,\n start_time: run._serialized_start_time ?? run.start_time,\n parent_run: convertRunToRunTree(parentRun),\n child_runs: run.child_runs\n .map((r) => convertRunToRunTree(r))\n .filter((r): r is RunTree => r !== undefined),\n extra: {\n ...run.extra,\n runtime: getRuntimeEnvironmentSync(),\n },\n tracingEnabled: false,\n });\n}\n\nexport interface AgentRun extends Run {\n actions: AgentAction[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _coerceToDict(value: any, defaultKey: string) {\n return value && !Array.isArray(value) && typeof value === \"object\"\n ? value\n : { [defaultKey]: value };\n}\n\nexport function isBaseTracer(x: BaseCallbackHandler): x is BaseTracer {\n return typeof (x as BaseTracer)._addRunToRunMap === \"function\";\n}\n\nexport abstract class BaseTracer extends BaseCallbackHandler {\n /** @deprecated Use `runTreeMap` instead. */\n protected runMap: Map<string, Run> = new Map();\n\n protected runTreeMap: Map<string, RunTree> = new Map();\n\n protected usesRunTreeMap = false;\n\n constructor(_fields?: BaseCallbackHandlerInput) {\n super(...arguments);\n }\n\n copy(): this {\n return this;\n }\n\n protected getRunById(runId?: string): Run | undefined {\n if (runId === undefined) {\n return undefined;\n }\n return this.usesRunTreeMap\n ? convertRunTreeToRun(this.runTreeMap.get(runId))\n : this.runMap.get(runId);\n }\n\n protected stringifyError(error: unknown) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n return error.message + (error?.stack ? `\\n\\n${error.stack}` : \"\");\n }\n\n if (typeof error === \"string\") {\n return error;\n }\n\n return `${error}`;\n }\n\n protected abstract persistRun(run: Run): Promise<void>;\n\n protected _addChildRun(parentRun: Run, childRun: Run) {\n parentRun.child_runs.push(childRun);\n }\n\n _addRunToRunMap(run: Run) {\n const { dottedOrder: currentDottedOrder, microsecondPrecisionDatestring } =\n convertToDottedOrderFormat(\n new Date(run.start_time).getTime(),\n run.id,\n run.execution_order\n );\n const storedRun = { ...run };\n const parentRun = this.getRunById(storedRun.parent_run_id);\n if (storedRun.parent_run_id !== undefined) {\n if (parentRun) {\n this._addChildRun(parentRun, storedRun);\n parentRun.child_execution_order = Math.max(\n parentRun.child_execution_order,\n storedRun.child_execution_order\n );\n storedRun.trace_id = parentRun.trace_id;\n if (parentRun.dotted_order !== undefined) {\n storedRun.dotted_order = [\n parentRun.dotted_order,\n currentDottedOrder,\n ].join(\".\");\n storedRun._serialized_start_time = microsecondPrecisionDatestring;\n } else {\n // This can happen naturally for callbacks added within a run\n // console.debug(`Parent run with UUID ${storedRun.parent_run_id} has no dotted order.`);\n }\n } else {\n // This can happen naturally for callbacks added within a run\n // console.debug(\n // `Parent run with UUID ${storedRun.parent_run_id} not found.`\n // );\n }\n } else {\n storedRun.trace_id = storedRun.id;\n storedRun.dotted_order = currentDottedOrder;\n storedRun._serialized_start_time = microsecondPrecisionDatestring;\n }\n if (this.usesRunTreeMap) {\n const runTree = convertRunToRunTree(storedRun, parentRun);\n if (runTree !== undefined) {\n this.runTreeMap.set(storedRun.id, runTree);\n }\n } else {\n this.runMap.set(storedRun.id, storedRun);\n }\n return storedRun;\n }\n\n protected async _endTrace(run: Run): Promise<void> {\n const parentRun =\n run.parent_run_id !== undefined && this.getRunById(run.parent_run_id);\n if (parentRun) {\n parentRun.child_execution_order = Math.max(\n parentRun.child_execution_order,\n run.child_execution_order\n );\n } else {\n await this.persistRun(run);\n }\n await this.onRunUpdate?.(run);\n if (this.usesRunTreeMap) {\n this.runTreeMap.delete(run.id);\n } else {\n this.runMap.delete(run.id);\n }\n }\n\n protected _getExecutionOrder(parentRunId: string | undefined): number {\n const parentRun = parentRunId !== undefined && this.getRunById(parentRunId);\n // If a run has no parent then execution order is 1\n if (!parentRun) {\n return 1;\n }\n\n return parentRun.child_execution_order + 1;\n }\n\n /**\n * Create and add a run to the run map for LLM start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForLLMStart(\n llm: Serialized,\n prompts: string[],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const finalExtraParams = metadata\n ? { ...extraParams, metadata }\n : extraParams;\n const run: Run = {\n id: runId,\n name: name ?? llm.id[llm.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: llm,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { prompts },\n execution_order,\n child_runs: [],\n child_execution_order: execution_order,\n run_type: \"llm\",\n extra: finalExtraParams ?? {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleLLMStart(\n llm: Serialized,\n prompts: string[],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForLLMStart(\n llm,\n prompts,\n runId,\n parentRunId,\n extraParams,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onLLMStart?.(run);\n return run;\n }\n\n /**\n * Create and add a run to the run map for chat model start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForChatModelStart(\n llm: Serialized,\n messages: BaseMessage[][],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const finalExtraParams = metadata\n ? { ...extraParams, metadata }\n : extraParams;\n const run: Run = {\n id: runId,\n name: name ?? llm.id[llm.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: llm,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { messages },\n execution_order,\n child_runs: [],\n child_execution_order: execution_order,\n run_type: \"llm\",\n extra: finalExtraParams ?? {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleChatModelStart(\n llm: Serialized,\n messages: BaseMessage[][],\n runId: string,\n parentRunId?: string,\n extraParams?: KVMap,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForChatModelStart(\n llm,\n messages,\n runId,\n parentRunId,\n extraParams,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onLLMStart?.(run);\n return run;\n }\n\n async handleLLMEnd(\n output: LLMResult,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n extraParams?: Record<string, unknown>\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"llm\") {\n throw new Error(\"No LLM run to end.\");\n }\n run.end_time = Date.now();\n run.outputs = output;\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n run.extra = { ...run.extra, ...extraParams };\n await this.onLLMEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleLLMError(\n error: unknown,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n extraParams?: Record<string, unknown>\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"llm\") {\n throw new Error(\"No LLM run to end.\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n run.extra = { ...run.extra, ...extraParams };\n await this.onLLMError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n /**\n * Create and add a run to the run map for chain start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForChainStart(\n chain: Serialized,\n inputs: ChainValues,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n runType?: string,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const run: Run = {\n id: runId,\n name: name ?? chain.id[chain.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: chain,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs,\n execution_order,\n child_execution_order: execution_order,\n run_type: runType ?? \"chain\",\n child_runs: [],\n extra: metadata ? { metadata } : {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleChainStart(\n chain: Serialized,\n inputs: ChainValues,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n runType?: string,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForChainStart(\n chain,\n inputs,\n runId,\n parentRunId,\n tags,\n metadata,\n runType,\n name\n );\n await this.onRunCreate?.(run);\n await this.onChainStart?.(run);\n return run;\n }\n\n async handleChainEnd(\n outputs: ChainValues,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n kwargs?: { inputs?: Record<string, unknown> }\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run) {\n throw new Error(\"No chain run to end.\");\n }\n run.end_time = Date.now();\n run.outputs = _coerceToDict(outputs, \"output\");\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n if (kwargs?.inputs !== undefined) {\n run.inputs = _coerceToDict(kwargs.inputs, \"input\");\n }\n await this.onChainEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleChainError(\n error: unknown,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n kwargs?: { inputs?: Record<string, unknown> }\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run) {\n throw new Error(\"No chain run to end.\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n if (kwargs?.inputs !== undefined) {\n run.inputs = _coerceToDict(kwargs.inputs, \"input\");\n }\n await this.onChainError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n /**\n * Create and add a run to the run map for tool start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForToolStart(\n tool: Serialized,\n input: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const run: Run = {\n id: runId,\n name: name ?? tool.id[tool.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: tool,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { input },\n execution_order,\n child_execution_order: execution_order,\n run_type: \"tool\",\n child_runs: [],\n extra: metadata ? { metadata } : {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleToolStart(\n tool: Serialized,\n input: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForToolStart(\n tool,\n input,\n runId,\n parentRunId,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onToolStart?.(run);\n return run;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async handleToolEnd(output: any, runId: string): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"tool\") {\n throw new Error(\"No tool run to end\");\n }\n run.end_time = Date.now();\n run.outputs = { output };\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onToolEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleToolError(error: unknown, runId: string): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"tool\") {\n throw new Error(\"No tool run to end\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onToolError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleAgentAction(action: AgentAction, runId: string): Promise<void> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"chain\") {\n return;\n }\n const agentRun = run as AgentRun;\n agentRun.actions = agentRun.actions || [];\n agentRun.actions.push(action);\n agentRun.events.push({\n name: \"agent_action\",\n time: new Date().toISOString(),\n kwargs: { action },\n });\n await this.onAgentAction?.(run as AgentRun);\n }\n\n async handleAgentEnd(action: AgentFinish, runId: string): Promise<void> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"chain\") {\n return;\n }\n run.events.push({\n name: \"agent_end\",\n time: new Date().toISOString(),\n kwargs: { action },\n });\n await this.onAgentEnd?.(run);\n }\n\n /**\n * Create and add a run to the run map for retriever start events.\n * This must sometimes be done synchronously to avoid race conditions\n * when callbacks are backgrounded, so we expose it as a separate method here.\n */\n _createRunForRetrieverStart(\n retriever: Serialized,\n query: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ) {\n const execution_order = this._getExecutionOrder(parentRunId);\n const start_time = Date.now();\n const run: Run = {\n id: runId,\n name: name ?? retriever.id[retriever.id.length - 1],\n parent_run_id: parentRunId,\n start_time,\n serialized: retriever,\n events: [\n {\n name: \"start\",\n time: new Date(start_time).toISOString(),\n },\n ],\n inputs: { query },\n execution_order,\n child_execution_order: execution_order,\n run_type: \"retriever\",\n child_runs: [],\n extra: metadata ? { metadata } : {},\n tags: tags || [],\n };\n return this._addRunToRunMap(run);\n }\n\n async handleRetrieverStart(\n retriever: Serialized,\n query: string,\n runId: string,\n parentRunId?: string,\n tags?: string[],\n metadata?: KVMap,\n name?: string\n ): Promise<Run> {\n const run =\n this.getRunById(runId) ??\n this._createRunForRetrieverStart(\n retriever,\n query,\n runId,\n parentRunId,\n tags,\n metadata,\n name\n );\n await this.onRunCreate?.(run);\n await this.onRetrieverStart?.(run);\n return run;\n }\n\n async handleRetrieverEnd(\n documents: Document<Record<string, unknown>>[],\n runId: string\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"retriever\") {\n throw new Error(\"No retriever run to end\");\n }\n run.end_time = Date.now();\n run.outputs = { documents };\n run.events.push({\n name: \"end\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onRetrieverEnd?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleRetrieverError(error: unknown, runId: string): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"retriever\") {\n throw new Error(\"No retriever run to end\");\n }\n run.end_time = Date.now();\n run.error = this.stringifyError(error);\n run.events.push({\n name: \"error\",\n time: new Date(run.end_time).toISOString(),\n });\n await this.onRetrieverError?.(run);\n await this._endTrace(run);\n return run;\n }\n\n async handleText(text: string, runId: string): Promise<void> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"chain\") {\n return;\n }\n run.events.push({\n name: \"text\",\n time: new Date().toISOString(),\n kwargs: { text },\n });\n await this.onText?.(run);\n }\n\n async handleLLMNewToken(\n token: string,\n idx: NewTokenIndices,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n fields?: HandleLLMNewTokenCallbackFields\n ): Promise<Run> {\n const run = this.getRunById(runId);\n if (!run || run?.run_type !== \"llm\") {\n throw new Error(\n `Invalid \"runId\" provided to \"handleLLMNewToken\" callback.`\n );\n }\n run.events.push({\n name: \"new_token\",\n time: new Date().toISOString(),\n kwargs: { token, idx, chunk: fields?.chunk },\n });\n await this.onLLMNewToken?.(run, token, { chunk: fields?.chunk });\n return run;\n }\n\n // custom event handlers\n\n onRunCreate?(run: Run): void | Promise<void>;\n\n onRunUpdate?(run: Run): void | Promise<void>;\n\n onLLMStart?(run: Run): void | Promise<void>;\n\n onLLMEnd?(run: Run): void | Promise<void>;\n\n onLLMError?(run: Run): void | Promise<void>;\n\n onChainStart?(run: Run): void | Promise<void>;\n\n onChainEnd?(run: Run): void | Promise<void>;\n\n onChainError?(run: Run): void | Promise<void>;\n\n onToolStart?(run: Run): void | Promise<void>;\n\n onToolEnd?(run: Run): void | Promise<void>;\n\n onToolError?(run: Run): void | Promise<void>;\n\n onAgentAction?(run: Run): void | Promise<void>;\n\n onAgentEnd?(run: Run): void | Promise<void>;\n\n onRetrieverStart?(run: Run): void | Promise<void>;\n\n onRetrieverEnd?(run: Run): void | Promise<void>;\n\n onRetrieverError?(run: Run): void | Promise<void>;\n\n onText?(run: Run): void | Promise<void>;\n\n onLLMNewToken?(\n run: Run,\n token: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n kwargs?: { chunk: any }\n ): void | Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;AAyCA,MAAM,sBAAsB,CAACA,YAAuC;AAClE,KAAI,CAAC,QACH,QAAO;CAMT,QAAQ,SAAS,QAAQ,UAAU,CAAE;CACrC,QAAQ,aAAa,QAAQ,cAAc,CAAE;AAE7C,QAAO;AACR;AAED,SAAS,oBAAoBC,KAAWC,WAAsC;AAC5E,KAAI,CAAC,IACH,QAAO;AAET,QAAO,IAAIC,4BAAQ;EACjB,GAAG;EACH,YAAY,IAAI,0BAA0B,IAAI;EAC9C,YAAY,oBAAoB,UAAU;EAC1C,YAAY,IAAI,WACb,IAAI,CAAC,MAAM,oBAAoB,EAAE,CAAC,CAClC,OAAO,CAAC,MAAoB,MAAM,OAAU;EAC/C,OAAO;GACL,GAAG,IAAI;GACP,SAASC,6CAA2B;EACrC;EACD,gBAAgB;CACjB;AACF;AAOD,SAAS,cAAcC,OAAYC,YAAoB;AACrD,QAAO,SAA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