@langchain/core 1.2.4 → 1.2.6
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/CHANGELOG.md +16 -0
- package/dist/agents.d.cts.map +1 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/caches/index.cjs.map +1 -1
- package/dist/caches/index.d.cts +0 -1
- package/dist/caches/index.d.cts.map +1 -1
- package/dist/caches/index.d.ts +0 -1
- package/dist/caches/index.d.ts.map +1 -1
- package/dist/caches/index.js.map +1 -1
- package/dist/callbacks/base.cjs.map +1 -1
- package/dist/callbacks/base.d.cts +68 -36
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/callbacks/base.d.ts +68 -36
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/base.js.map +1 -1
- package/dist/callbacks/dispatch/index.cjs +0 -1
- package/dist/callbacks/dispatch/index.cjs.map +1 -1
- package/dist/callbacks/dispatch/index.d.cts +1 -0
- package/dist/callbacks/dispatch/index.d.cts.map +1 -1
- package/dist/callbacks/dispatch/index.d.ts +1 -0
- package/dist/callbacks/dispatch/index.d.ts.map +1 -1
- package/dist/callbacks/dispatch/index.js.map +1 -1
- package/dist/callbacks/dispatch/web.cjs.map +1 -1
- package/dist/callbacks/dispatch/web.d.cts +1 -0
- package/dist/callbacks/dispatch/web.d.cts.map +1 -1
- package/dist/callbacks/dispatch/web.d.ts +1 -0
- package/dist/callbacks/dispatch/web.d.ts.map +1 -1
- package/dist/callbacks/dispatch/web.js.map +1 -1
- package/dist/callbacks/manager.cjs +8 -0
- package/dist/callbacks/manager.cjs.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -2
- package/dist/callbacks/manager.d.cts.map +1 -1
- package/dist/callbacks/manager.d.ts +1 -2
- package/dist/callbacks/manager.d.ts.map +1 -1
- package/dist/callbacks/manager.js +8 -0
- package/dist/callbacks/manager.js.map +1 -1
- package/dist/chat_history.cjs.map +1 -1
- package/dist/chat_history.d.cts +1 -0
- package/dist/chat_history.d.cts.map +1 -1
- package/dist/chat_history.d.ts +1 -0
- package/dist/chat_history.d.ts.map +1 -1
- package/dist/chat_history.js.map +1 -1
- package/dist/context.cjs +0 -1
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +0 -1
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.ts +0 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/document_loaders/base.cjs.map +1 -1
- package/dist/document_loaders/base.d.cts +0 -1
- package/dist/document_loaders/base.d.cts.map +1 -1
- package/dist/document_loaders/base.d.ts +0 -1
- package/dist/document_loaders/base.d.ts.map +1 -1
- package/dist/document_loaders/base.js.map +1 -1
- package/dist/document_loaders/langsmith.cjs.map +1 -1
- package/dist/document_loaders/langsmith.d.cts +0 -1
- package/dist/document_loaders/langsmith.d.cts.map +1 -1
- package/dist/document_loaders/langsmith.d.ts +0 -1
- package/dist/document_loaders/langsmith.d.ts.map +1 -1
- package/dist/document_loaders/langsmith.js.map +1 -1
- package/dist/documents/document.cjs.map +1 -1
- package/dist/documents/document.d.cts.map +1 -1
- package/dist/documents/document.d.ts.map +1 -1
- package/dist/documents/document.js.map +1 -1
- package/dist/documents/transformers.cjs.map +1 -1
- package/dist/documents/transformers.d.cts +0 -1
- package/dist/documents/transformers.d.cts.map +1 -1
- package/dist/documents/transformers.d.ts +0 -1
- package/dist/documents/transformers.d.ts.map +1 -1
- package/dist/documents/transformers.js.map +1 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +0 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +0 -1
- 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.d.cts +0 -1
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/example_selectors/base.cjs.map +1 -1
- package/dist/example_selectors/base.d.cts +0 -1
- package/dist/example_selectors/base.d.cts.map +1 -1
- package/dist/example_selectors/base.d.ts +0 -1
- package/dist/example_selectors/base.d.ts.map +1 -1
- package/dist/example_selectors/base.js.map +1 -1
- package/dist/example_selectors/conditional.cjs.map +1 -1
- package/dist/example_selectors/conditional.d.cts +0 -1
- package/dist/example_selectors/conditional.d.cts.map +1 -1
- package/dist/example_selectors/conditional.d.ts +0 -1
- package/dist/example_selectors/conditional.d.ts.map +1 -1
- package/dist/example_selectors/conditional.js.map +1 -1
- package/dist/example_selectors/length_based.cjs.map +1 -1
- package/dist/example_selectors/length_based.d.cts +0 -1
- package/dist/example_selectors/length_based.d.cts.map +1 -1
- package/dist/example_selectors/length_based.d.ts +0 -1
- package/dist/example_selectors/length_based.d.ts.map +1 -1
- package/dist/example_selectors/length_based.js.map +1 -1
- package/dist/example_selectors/semantic_similarity.cjs +2 -1
- package/dist/example_selectors/semantic_similarity.cjs.map +1 -1
- package/dist/example_selectors/semantic_similarity.d.cts +0 -1
- package/dist/example_selectors/semantic_similarity.d.cts.map +1 -1
- package/dist/example_selectors/semantic_similarity.d.ts +0 -1
- package/dist/example_selectors/semantic_similarity.d.ts.map +1 -1
- package/dist/example_selectors/semantic_similarity.js +2 -1
- package/dist/example_selectors/semantic_similarity.js.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/indexing/base.cjs.map +1 -1
- package/dist/indexing/base.d.cts +0 -1
- package/dist/indexing/base.d.cts.map +1 -1
- package/dist/indexing/base.d.ts +0 -1
- package/dist/indexing/base.d.ts.map +1 -1
- package/dist/indexing/base.js.map +1 -1
- package/dist/indexing/record_manager.cjs.map +1 -1
- package/dist/indexing/record_manager.d.cts +0 -1
- package/dist/indexing/record_manager.d.cts.map +1 -1
- package/dist/indexing/record_manager.d.ts +0 -1
- package/dist/indexing/record_manager.d.ts.map +1 -1
- package/dist/indexing/record_manager.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 +9 -16
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +9 -16
- 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 +12 -6
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +6 -8
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +6 -8
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +12 -6
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/compat.cjs.map +1 -1
- package/dist/language_models/compat.d.cts +0 -1
- package/dist/language_models/compat.d.cts.map +1 -1
- package/dist/language_models/compat.d.ts +0 -1
- package/dist/language_models/compat.d.ts.map +1 -1
- package/dist/language_models/compat.js.map +1 -1
- package/dist/language_models/event.d.cts +0 -1
- package/dist/language_models/event.d.cts.map +1 -1
- package/dist/language_models/event.d.ts +0 -1
- package/dist/language_models/event.d.ts.map +1 -1
- package/dist/language_models/llms.cjs.map +1 -1
- package/dist/language_models/llms.d.cts +2 -9
- package/dist/language_models/llms.d.cts.map +1 -1
- package/dist/language_models/llms.d.ts +2 -9
- package/dist/language_models/llms.d.ts.map +1 -1
- package/dist/language_models/llms.js.map +1 -1
- package/dist/language_models/openai_completions_stream.cjs.map +1 -1
- package/dist/language_models/openai_completions_stream.d.cts +0 -1
- package/dist/language_models/openai_completions_stream.d.cts.map +1 -1
- package/dist/language_models/openai_completions_stream.d.ts +0 -1
- package/dist/language_models/openai_completions_stream.d.ts.map +1 -1
- package/dist/language_models/openai_completions_stream.js.map +1 -1
- package/dist/language_models/profile.d.cts.map +1 -1
- package/dist/language_models/profile.d.ts.map +1 -1
- package/dist/language_models/stream.cjs.map +1 -1
- package/dist/language_models/stream.d.cts +2 -1
- package/dist/language_models/stream.d.cts.map +1 -1
- package/dist/language_models/stream.d.ts +2 -1
- package/dist/language_models/stream.d.ts.map +1 -1
- package/dist/language_models/stream.js.map +1 -1
- package/dist/language_models/structured_output.cjs.map +1 -1
- package/dist/language_models/structured_output.d.cts +4 -0
- package/dist/language_models/structured_output.d.cts.map +1 -1
- package/dist/language_models/structured_output.d.ts +4 -0
- package/dist/language_models/structured_output.d.ts.map +1 -1
- package/dist/language_models/structured_output.js.map +1 -1
- package/dist/language_models/utils.cjs.map +1 -1
- package/dist/language_models/utils.js.map +1 -1
- package/dist/load/import_constants.cjs.map +1 -1
- package/dist/load/import_constants.js.map +1 -1
- package/dist/load/import_map.cjs +410 -0
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +3 -1
- package/dist/load/import_map.js.map +1 -1
- package/dist/load/import_type.d.cts.map +1 -1
- package/dist/load/import_type.d.ts.map +1 -1
- package/dist/load/index.cjs.map +1 -1
- package/dist/load/index.d.cts +0 -1
- package/dist/load/index.d.cts.map +1 -1
- package/dist/load/index.d.ts +0 -1
- package/dist/load/index.d.ts.map +1 -1
- package/dist/load/index.js.map +1 -1
- package/dist/load/map_keys.cjs.map +1 -1
- package/dist/load/map_keys.d.cts.map +1 -1
- package/dist/load/map_keys.d.ts.map +1 -1
- package/dist/load/map_keys.js.map +1 -1
- package/dist/load/serializable.cjs.map +1 -1
- package/dist/load/serializable.d.cts +0 -1
- package/dist/load/serializable.d.cts.map +1 -1
- package/dist/load/serializable.d.ts +0 -1
- package/dist/load/serializable.d.ts.map +1 -1
- package/dist/load/serializable.js.map +1 -1
- package/dist/load/validation.cjs +3 -0
- package/dist/load/validation.cjs.map +1 -1
- package/dist/load/validation.js +1 -1
- package/dist/load/validation.js.map +1 -1
- package/dist/memory.cjs +8 -2
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts.map +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +8 -2
- package/dist/memory.js.map +1 -1
- package/dist/messages/ai.cjs +6 -0
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.d.cts +3 -2
- package/dist/messages/ai.d.cts.map +1 -1
- package/dist/messages/ai.d.ts +3 -2
- package/dist/messages/ai.d.ts.map +1 -1
- package/dist/messages/ai.js +6 -0
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +6 -0
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +9 -10
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +9 -10
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +6 -0
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/block_translators/anthropic.cjs +2 -0
- package/dist/messages/block_translators/anthropic.cjs.map +1 -1
- package/dist/messages/block_translators/anthropic.js +1 -1
- package/dist/messages/block_translators/anthropic.js.map +1 -1
- package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -1
- package/dist/messages/block_translators/bedrock_converse.js.map +1 -1
- package/dist/messages/block_translators/data.cjs +1 -0
- package/dist/messages/block_translators/data.cjs.map +1 -1
- package/dist/messages/block_translators/data.js +1 -1
- package/dist/messages/block_translators/data.js.map +1 -1
- package/dist/messages/block_translators/deepseek.cjs +1 -0
- package/dist/messages/block_translators/deepseek.cjs.map +1 -1
- package/dist/messages/block_translators/deepseek.js +1 -1
- package/dist/messages/block_translators/deepseek.js.map +1 -1
- package/dist/messages/block_translators/google.cjs.map +1 -1
- package/dist/messages/block_translators/google.js.map +1 -1
- package/dist/messages/block_translators/google_genai.cjs.map +1 -1
- package/dist/messages/block_translators/google_genai.js.map +1 -1
- package/dist/messages/block_translators/google_vertexai.cjs.map +1 -1
- package/dist/messages/block_translators/google_vertexai.js.map +1 -1
- package/dist/messages/block_translators/groq.cjs +1 -0
- package/dist/messages/block_translators/groq.cjs.map +1 -1
- package/dist/messages/block_translators/groq.js +1 -1
- package/dist/messages/block_translators/groq.js.map +1 -1
- package/dist/messages/block_translators/index.cjs +1 -1
- package/dist/messages/block_translators/index.cjs.map +1 -1
- package/dist/messages/block_translators/index.js +1 -1
- package/dist/messages/block_translators/index.js.map +1 -1
- package/dist/messages/block_translators/ollama.cjs +1 -0
- package/dist/messages/block_translators/ollama.cjs.map +1 -1
- package/dist/messages/block_translators/ollama.js +1 -1
- package/dist/messages/block_translators/ollama.js.map +1 -1
- package/dist/messages/block_translators/openai.cjs +4 -0
- package/dist/messages/block_translators/openai.cjs.map +1 -1
- package/dist/messages/block_translators/openai.js +1 -1
- package/dist/messages/block_translators/openai.js.map +1 -1
- package/dist/messages/block_translators/openrouter.cjs +1 -0
- package/dist/messages/block_translators/openrouter.cjs.map +1 -1
- package/dist/messages/block_translators/openrouter.js +1 -1
- package/dist/messages/block_translators/openrouter.js.map +1 -1
- package/dist/messages/block_translators/utils.cjs.map +1 -1
- package/dist/messages/block_translators/utils.js.map +1 -1
- package/dist/messages/block_translators/xai.cjs +1 -0
- package/dist/messages/block_translators/xai.cjs.map +1 -1
- package/dist/messages/block_translators/xai.js +1 -1
- package/dist/messages/block_translators/xai.js.map +1 -1
- package/dist/messages/chat.cjs +6 -0
- package/dist/messages/chat.cjs.map +1 -1
- package/dist/messages/chat.d.cts +3 -2
- package/dist/messages/chat.d.cts.map +1 -1
- package/dist/messages/chat.d.ts +3 -2
- package/dist/messages/chat.d.ts.map +1 -1
- package/dist/messages/chat.js +6 -0
- package/dist/messages/chat.js.map +1 -1
- package/dist/messages/content/base.d.cts.map +1 -1
- package/dist/messages/content/base.d.ts.map +1 -1
- package/dist/messages/content/data.cjs.map +1 -1
- package/dist/messages/content/data.d.cts +2 -9
- package/dist/messages/content/data.d.cts.map +1 -1
- package/dist/messages/content/data.d.ts +2 -9
- package/dist/messages/content/data.d.ts.map +1 -1
- package/dist/messages/content/data.js.map +1 -1
- package/dist/messages/content/index.cjs.map +1 -1
- package/dist/messages/content/index.d.cts +0 -1
- package/dist/messages/content/index.d.cts.map +1 -1
- package/dist/messages/content/index.d.ts +0 -1
- package/dist/messages/content/index.d.ts.map +1 -1
- package/dist/messages/content/index.js.map +1 -1
- package/dist/messages/content/multimodal.cjs.map +1 -1
- package/dist/messages/content/multimodal.d.cts +8 -5
- package/dist/messages/content/multimodal.d.cts.map +1 -1
- package/dist/messages/content/multimodal.d.ts +8 -5
- package/dist/messages/content/multimodal.d.ts.map +1 -1
- package/dist/messages/content/multimodal.js.map +1 -1
- package/dist/messages/content/tools.cjs.map +1 -1
- package/dist/messages/content/tools.d.cts +0 -1
- package/dist/messages/content/tools.d.cts.map +1 -1
- package/dist/messages/content/tools.d.ts +0 -1
- package/dist/messages/content/tools.d.ts.map +1 -1
- package/dist/messages/content/tools.js.map +1 -1
- package/dist/messages/format.cjs.map +1 -1
- package/dist/messages/format.d.cts.map +1 -1
- package/dist/messages/format.d.ts.map +1 -1
- package/dist/messages/format.js.map +1 -1
- package/dist/messages/function.cjs +12 -0
- package/dist/messages/function.cjs.map +1 -1
- package/dist/messages/function.d.cts +5 -2
- package/dist/messages/function.d.cts.map +1 -1
- package/dist/messages/function.d.ts +5 -2
- package/dist/messages/function.d.ts.map +1 -1
- package/dist/messages/function.js +12 -0
- package/dist/messages/function.js.map +1 -1
- package/dist/messages/human.cjs +6 -0
- package/dist/messages/human.cjs.map +1 -1
- package/dist/messages/human.d.cts +3 -2
- package/dist/messages/human.d.cts.map +1 -1
- package/dist/messages/human.d.ts +3 -2
- package/dist/messages/human.d.ts.map +1 -1
- package/dist/messages/human.js +6 -0
- package/dist/messages/human.js.map +1 -1
- package/dist/messages/message.cjs.map +1 -1
- package/dist/messages/message.d.cts +31 -22
- package/dist/messages/message.d.cts.map +1 -1
- package/dist/messages/message.d.ts +31 -22
- package/dist/messages/message.d.ts.map +1 -1
- package/dist/messages/message.js.map +1 -1
- package/dist/messages/metadata.cjs.map +1 -1
- package/dist/messages/metadata.d.cts +0 -1
- package/dist/messages/metadata.d.cts.map +1 -1
- package/dist/messages/metadata.d.ts +0 -1
- package/dist/messages/metadata.d.ts.map +1 -1
- package/dist/messages/metadata.js.map +1 -1
- package/dist/messages/modifier.cjs +3 -0
- package/dist/messages/modifier.cjs.map +1 -1
- package/dist/messages/modifier.d.cts +1 -1
- package/dist/messages/modifier.d.cts.map +1 -1
- package/dist/messages/modifier.d.ts +1 -1
- package/dist/messages/modifier.d.ts.map +1 -1
- package/dist/messages/modifier.js +3 -0
- package/dist/messages/modifier.js.map +1 -1
- package/dist/messages/system.cjs +6 -0
- package/dist/messages/system.cjs.map +1 -1
- package/dist/messages/system.d.cts +3 -2
- package/dist/messages/system.d.cts.map +1 -1
- package/dist/messages/system.d.ts +3 -2
- package/dist/messages/system.d.ts.map +1 -1
- package/dist/messages/system.js +6 -0
- package/dist/messages/system.js.map +1 -1
- package/dist/messages/tool.cjs +9 -0
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +7 -5
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +7 -5
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +9 -0
- package/dist/messages/tool.js.map +1 -1
- package/dist/messages/transformers.cjs.map +1 -1
- package/dist/messages/transformers.d.cts +0 -1
- package/dist/messages/transformers.d.cts.map +1 -1
- package/dist/messages/transformers.d.ts +0 -1
- package/dist/messages/transformers.d.ts.map +1 -1
- package/dist/messages/transformers.js.map +1 -1
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.d.cts +4 -5
- package/dist/messages/utils.d.cts.map +1 -1
- package/dist/messages/utils.d.ts +4 -5
- package/dist/messages/utils.d.ts.map +1 -1
- package/dist/messages/utils.js.map +1 -1
- package/dist/output_parsers/base.cjs.map +1 -1
- package/dist/output_parsers/base.d.cts +3 -0
- package/dist/output_parsers/base.d.cts.map +1 -1
- package/dist/output_parsers/base.d.ts +3 -0
- package/dist/output_parsers/base.d.ts.map +1 -1
- package/dist/output_parsers/base.js.map +1 -1
- package/dist/output_parsers/bytes.cjs.map +1 -1
- package/dist/output_parsers/bytes.d.cts +0 -1
- package/dist/output_parsers/bytes.d.cts.map +1 -1
- package/dist/output_parsers/bytes.d.ts +0 -1
- package/dist/output_parsers/bytes.d.ts.map +1 -1
- package/dist/output_parsers/bytes.js.map +1 -1
- package/dist/output_parsers/json.cjs +2 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +2 -2
- package/dist/output_parsers/json.d.cts.map +1 -1
- package/dist/output_parsers/json.d.ts +2 -2
- package/dist/output_parsers/json.d.ts.map +1 -1
- package/dist/output_parsers/json.js +2 -2
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/output_parsers/list.cjs.map +1 -1
- package/dist/output_parsers/list.d.cts +2 -5
- package/dist/output_parsers/list.d.cts.map +1 -1
- package/dist/output_parsers/list.d.ts +2 -5
- package/dist/output_parsers/list.d.ts.map +1 -1
- package/dist/output_parsers/list.js.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.cjs.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.cts.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.js.map +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.d.cts +2 -2
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +2 -2
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
- package/dist/output_parsers/standard_schema.cjs.map +1 -1
- package/dist/output_parsers/standard_schema.d.cts +1 -1
- package/dist/output_parsers/standard_schema.d.cts.map +1 -1
- package/dist/output_parsers/standard_schema.d.ts +1 -1
- package/dist/output_parsers/standard_schema.d.ts.map +1 -1
- package/dist/output_parsers/standard_schema.js.map +1 -1
- package/dist/output_parsers/string.cjs.map +1 -1
- package/dist/output_parsers/string.d.cts +1 -1
- package/dist/output_parsers/string.d.cts.map +1 -1
- package/dist/output_parsers/string.d.ts +1 -1
- package/dist/output_parsers/string.d.ts.map +1 -1
- package/dist/output_parsers/string.js.map +1 -1
- package/dist/output_parsers/structured.cjs +1 -1
- package/dist/output_parsers/structured.cjs.map +1 -1
- package/dist/output_parsers/structured.d.cts +2 -4
- package/dist/output_parsers/structured.d.cts.map +1 -1
- package/dist/output_parsers/structured.d.ts +2 -4
- package/dist/output_parsers/structured.d.ts.map +1 -1
- package/dist/output_parsers/structured.js +1 -0
- package/dist/output_parsers/structured.js.map +1 -1
- package/dist/output_parsers/transform.cjs +0 -1
- package/dist/output_parsers/transform.cjs.map +1 -1
- package/dist/output_parsers/transform.d.cts +0 -1
- package/dist/output_parsers/transform.d.cts.map +1 -1
- package/dist/output_parsers/transform.d.ts +0 -1
- package/dist/output_parsers/transform.d.ts.map +1 -1
- package/dist/output_parsers/transform.js.map +1 -1
- package/dist/output_parsers/xml.cjs.map +1 -1
- package/dist/output_parsers/xml.d.cts +0 -1
- package/dist/output_parsers/xml.d.cts.map +1 -1
- package/dist/output_parsers/xml.d.ts +0 -1
- package/dist/output_parsers/xml.d.ts.map +1 -1
- package/dist/output_parsers/xml.js.map +1 -1
- package/dist/outputs.cjs.map +1 -1
- package/dist/outputs.d.cts +0 -1
- package/dist/outputs.d.cts.map +1 -1
- package/dist/outputs.d.ts +0 -1
- package/dist/outputs.d.ts.map +1 -1
- package/dist/outputs.js.map +1 -1
- package/dist/prompt_values.cjs.map +1 -1
- package/dist/prompt_values.d.cts +3 -2
- package/dist/prompt_values.d.cts.map +1 -1
- package/dist/prompt_values.d.ts +3 -2
- package/dist/prompt_values.d.ts.map +1 -1
- package/dist/prompt_values.js.map +1 -1
- package/dist/prompts/base.cjs.map +1 -1
- package/dist/prompts/base.d.cts +1 -0
- package/dist/prompts/base.d.cts.map +1 -1
- package/dist/prompts/base.d.ts +1 -0
- package/dist/prompts/base.d.ts.map +1 -1
- package/dist/prompts/base.js.map +1 -1
- package/dist/prompts/chat.cjs +3 -2
- package/dist/prompts/chat.cjs.map +1 -1
- package/dist/prompts/chat.d.cts +3 -3
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +3 -3
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/chat.js +3 -2
- package/dist/prompts/chat.js.map +1 -1
- package/dist/prompts/dict.cjs.map +1 -1
- package/dist/prompts/dict.d.cts +0 -1
- package/dist/prompts/dict.d.cts.map +1 -1
- package/dist/prompts/dict.d.ts +0 -1
- package/dist/prompts/dict.d.ts.map +1 -1
- package/dist/prompts/dict.js.map +1 -1
- package/dist/prompts/few_shot.cjs +6 -4
- package/dist/prompts/few_shot.cjs.map +1 -1
- package/dist/prompts/few_shot.d.cts +1 -1
- package/dist/prompts/few_shot.d.cts.map +1 -1
- package/dist/prompts/few_shot.d.ts +1 -1
- package/dist/prompts/few_shot.d.ts.map +1 -1
- package/dist/prompts/few_shot.js +6 -4
- package/dist/prompts/few_shot.js.map +1 -1
- package/dist/prompts/image.cjs +3 -2
- package/dist/prompts/image.cjs.map +1 -1
- package/dist/prompts/image.d.cts +1 -1
- package/dist/prompts/image.d.cts.map +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/image.d.ts.map +1 -1
- package/dist/prompts/image.js +3 -2
- package/dist/prompts/image.js.map +1 -1
- package/dist/prompts/pipeline.cjs.map +1 -1
- package/dist/prompts/pipeline.d.cts +0 -1
- package/dist/prompts/pipeline.d.cts.map +1 -1
- package/dist/prompts/pipeline.d.ts +0 -1
- package/dist/prompts/pipeline.d.ts.map +1 -1
- package/dist/prompts/pipeline.js.map +1 -1
- package/dist/prompts/prompt.cjs +9 -7
- package/dist/prompts/prompt.cjs.map +1 -1
- package/dist/prompts/prompt.d.cts +2 -2
- package/dist/prompts/prompt.d.cts.map +1 -1
- package/dist/prompts/prompt.d.ts +2 -2
- package/dist/prompts/prompt.d.ts.map +1 -1
- package/dist/prompts/prompt.js +9 -7
- package/dist/prompts/prompt.js.map +1 -1
- package/dist/prompts/serde.d.cts +1 -1
- package/dist/prompts/serde.d.cts.map +1 -1
- package/dist/prompts/serde.d.ts +1 -1
- package/dist/prompts/serde.d.ts.map +1 -1
- package/dist/prompts/string.cjs.map +1 -1
- package/dist/prompts/string.d.cts +0 -1
- package/dist/prompts/string.d.cts.map +1 -1
- package/dist/prompts/string.d.ts +0 -1
- package/dist/prompts/string.d.ts.map +1 -1
- package/dist/prompts/string.js.map +1 -1
- package/dist/prompts/structured.cjs.map +1 -1
- package/dist/prompts/structured.d.cts +1 -1
- package/dist/prompts/structured.d.cts.map +1 -1
- package/dist/prompts/structured.d.ts +1 -1
- package/dist/prompts/structured.d.ts.map +1 -1
- package/dist/prompts/structured.js.map +1 -1
- package/dist/prompts/template.cjs +9 -9
- package/dist/prompts/template.cjs.map +1 -1
- package/dist/prompts/template.d.cts +1 -0
- package/dist/prompts/template.d.cts.map +1 -1
- package/dist/prompts/template.d.ts +1 -0
- package/dist/prompts/template.d.ts.map +1 -1
- package/dist/prompts/template.js +9 -9
- package/dist/prompts/template.js.map +1 -1
- package/dist/retrievers/document_compressors/index.cjs.map +1 -1
- package/dist/retrievers/document_compressors/index.d.cts +0 -1
- package/dist/retrievers/document_compressors/index.d.cts.map +1 -1
- package/dist/retrievers/document_compressors/index.d.ts +0 -1
- package/dist/retrievers/document_compressors/index.d.ts.map +1 -1
- package/dist/retrievers/document_compressors/index.js.map +1 -1
- package/dist/retrievers/index.cjs.map +1 -1
- package/dist/retrievers/index.d.cts +1 -1
- package/dist/retrievers/index.d.cts.map +1 -1
- package/dist/retrievers/index.d.ts +1 -1
- package/dist/retrievers/index.d.ts.map +1 -1
- package/dist/retrievers/index.js.map +1 -1
- package/dist/runnables/base.cjs +2 -1
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +7 -19
- package/dist/runnables/base.d.cts.map +1 -1
- package/dist/runnables/base.d.ts +7 -19
- package/dist/runnables/base.d.ts.map +1 -1
- package/dist/runnables/base.js +1 -1
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/branch.cjs.map +1 -1
- package/dist/runnables/branch.d.cts +1 -1
- package/dist/runnables/branch.d.cts.map +1 -1
- package/dist/runnables/branch.d.ts +1 -1
- package/dist/runnables/branch.d.ts.map +1 -1
- package/dist/runnables/branch.js.map +1 -1
- package/dist/runnables/config.cjs +3 -2
- package/dist/runnables/config.cjs.map +1 -1
- package/dist/runnables/config.d.cts +2 -10
- package/dist/runnables/config.d.cts.map +1 -1
- package/dist/runnables/config.d.ts +2 -10
- package/dist/runnables/config.d.ts.map +1 -1
- package/dist/runnables/config.js +3 -3
- package/dist/runnables/config.js.map +1 -1
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.d.cts +1 -2
- package/dist/runnables/graph.d.cts.map +1 -1
- package/dist/runnables/graph.d.ts +1 -2
- package/dist/runnables/graph.d.ts.map +1 -1
- package/dist/runnables/graph.js.map +1 -1
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/history.cjs.map +1 -1
- package/dist/runnables/history.d.cts +2 -1
- package/dist/runnables/history.d.cts.map +1 -1
- package/dist/runnables/history.d.ts +2 -1
- package/dist/runnables/history.d.ts.map +1 -1
- package/dist/runnables/history.js.map +1 -1
- package/dist/runnables/iter.cjs.map +1 -1
- package/dist/runnables/iter.js.map +1 -1
- package/dist/runnables/passthrough.cjs.map +1 -1
- package/dist/runnables/passthrough.d.cts +1 -1
- package/dist/runnables/passthrough.d.cts.map +1 -1
- package/dist/runnables/passthrough.d.ts +1 -1
- package/dist/runnables/passthrough.d.ts.map +1 -1
- package/dist/runnables/passthrough.js.map +1 -1
- package/dist/runnables/router.cjs.map +1 -1
- package/dist/runnables/router.d.cts +1 -1
- package/dist/runnables/router.d.cts.map +1 -1
- package/dist/runnables/router.d.ts +1 -1
- package/dist/runnables/router.d.ts.map +1 -1
- package/dist/runnables/router.js.map +1 -1
- package/dist/runnables/types.d.cts +2 -2
- package/dist/runnables/types.d.cts.map +1 -1
- package/dist/runnables/types.d.ts +2 -2
- package/dist/runnables/types.d.ts.map +1 -1
- package/dist/runnables/utils.cjs.map +1 -1
- package/dist/runnables/utils.js.map +1 -1
- package/dist/runnables/wrappers.cjs.map +1 -1
- package/dist/runnables/wrappers.js.map +1 -1
- package/dist/singletons/async_local_storage/context.cjs +0 -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/async_local_storage/globals.cjs +1 -0
- package/dist/singletons/async_local_storage/globals.cjs.map +1 -1
- package/dist/singletons/async_local_storage/globals.d.cts.map +1 -1
- package/dist/singletons/async_local_storage/globals.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/globals.js +1 -1
- package/dist/singletons/async_local_storage/globals.js.map +1 -1
- package/dist/singletons/async_local_storage/index.cjs +0 -1
- package/dist/singletons/async_local_storage/index.cjs.map +1 -1
- package/dist/singletons/async_local_storage/index.d.cts +1 -2
- package/dist/singletons/async_local_storage/index.d.cts.map +1 -1
- package/dist/singletons/async_local_storage/index.d.ts +1 -2
- package/dist/singletons/async_local_storage/index.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/index.js.map +1 -1
- package/dist/singletons/callbacks.cjs +1 -0
- package/dist/singletons/callbacks.cjs.map +1 -1
- package/dist/singletons/callbacks.d.cts +1 -0
- package/dist/singletons/callbacks.d.cts.map +1 -1
- package/dist/singletons/callbacks.d.ts +0 -1
- package/dist/singletons/callbacks.d.ts.map +1 -1
- package/dist/singletons/callbacks.js +1 -1
- package/dist/singletons/callbacks.js.map +1 -1
- package/dist/singletons/tracer.cjs +0 -1
- package/dist/singletons/tracer.cjs.map +1 -1
- package/dist/singletons/tracer.js.map +1 -1
- package/dist/stores.cjs.map +1 -1
- package/dist/stores.d.cts +0 -1
- package/dist/stores.d.cts.map +1 -1
- package/dist/stores.d.ts +0 -1
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js.map +1 -1
- package/dist/structured_query/base.cjs.map +1 -1
- package/dist/structured_query/base.d.cts +0 -1
- package/dist/structured_query/base.d.cts.map +1 -1
- package/dist/structured_query/base.d.ts +0 -1
- package/dist/structured_query/base.d.ts.map +1 -1
- package/dist/structured_query/base.js.map +1 -1
- package/dist/structured_query/functional.cjs.map +1 -1
- package/dist/structured_query/functional.d.cts +0 -1
- package/dist/structured_query/functional.d.cts.map +1 -1
- package/dist/structured_query/functional.d.ts +0 -1
- package/dist/structured_query/functional.d.ts.map +1 -1
- package/dist/structured_query/functional.js.map +1 -1
- package/dist/structured_query/ir.cjs +7 -0
- package/dist/structured_query/ir.cjs.map +1 -1
- package/dist/structured_query/ir.d.cts +0 -1
- package/dist/structured_query/ir.d.cts.map +1 -1
- package/dist/structured_query/ir.d.ts +0 -1
- package/dist/structured_query/ir.d.ts.map +1 -1
- package/dist/structured_query/ir.js +7 -0
- package/dist/structured_query/ir.js.map +1 -1
- package/dist/structured_query/utils.cjs.map +1 -1
- package/dist/structured_query/utils.d.cts.map +1 -1
- package/dist/structured_query/utils.d.ts.map +1 -1
- package/dist/structured_query/utils.js.map +1 -1
- package/dist/testing/fake_model_builder.cjs.map +1 -1
- package/dist/testing/fake_model_builder.d.cts +1 -1
- package/dist/testing/fake_model_builder.d.cts.map +1 -1
- package/dist/testing/fake_model_builder.d.ts +1 -1
- package/dist/testing/fake_model_builder.d.ts.map +1 -1
- package/dist/testing/fake_model_builder.js.map +1 -1
- package/dist/testing/matchers.cjs.map +1 -1
- package/dist/testing/matchers.d.cts +0 -1
- package/dist/testing/matchers.d.cts.map +1 -1
- package/dist/testing/matchers.d.ts +0 -1
- package/dist/testing/matchers.d.ts.map +1 -1
- package/dist/testing/matchers.js.map +1 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +8 -7
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts +8 -7
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +4 -3
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +4 -3
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/utils.cjs.map +1 -1
- package/dist/tools/utils.d.cts.map +1 -1
- package/dist/tools/utils.d.ts.map +1 -1
- package/dist/tools/utils.js.map +1 -1
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.d.cts +18 -14
- package/dist/tracers/base.d.cts.map +1 -1
- package/dist/tracers/base.d.ts +18 -14
- package/dist/tracers/base.d.ts.map +1 -1
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/console.cjs.map +1 -1
- package/dist/tracers/console.d.cts +0 -1
- package/dist/tracers/console.d.cts.map +1 -1
- package/dist/tracers/console.d.ts +0 -1
- package/dist/tracers/console.d.ts.map +1 -1
- package/dist/tracers/console.js.map +1 -1
- package/dist/tracers/event_stream.cjs.map +1 -1
- package/dist/tracers/event_stream.d.cts +5 -2
- package/dist/tracers/event_stream.d.cts.map +1 -1
- package/dist/tracers/event_stream.d.ts +5 -2
- package/dist/tracers/event_stream.d.ts.map +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.d.cts +30 -15
- package/dist/tracers/log_stream.d.cts.map +1 -1
- package/dist/tracers/log_stream.d.ts +30 -15
- package/dist/tracers/log_stream.d.ts.map +1 -1
- package/dist/tracers/log_stream.js.map +1 -1
- package/dist/tracers/root_listener.cjs.map +1 -1
- package/dist/tracers/root_listener.js.map +1 -1
- package/dist/tracers/run_collector.cjs.map +1 -1
- package/dist/tracers/run_collector.d.cts +1 -4
- package/dist/tracers/run_collector.d.cts.map +1 -1
- package/dist/tracers/run_collector.d.ts +1 -4
- package/dist/tracers/run_collector.d.ts.map +1 -1
- package/dist/tracers/run_collector.js.map +1 -1
- package/dist/tracers/tracer_langchain.cjs +4 -3
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.d.cts +1 -5
- package/dist/tracers/tracer_langchain.d.cts.map +1 -1
- package/dist/tracers/tracer_langchain.d.ts +1 -5
- package/dist/tracers/tracer_langchain.d.ts.map +1 -1
- package/dist/tracers/tracer_langchain.js +4 -3
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/types/_internal.d.cts.map +1 -1
- package/dist/types/_internal.d.ts.map +1 -1
- package/dist/types/stream.d.cts +1 -1
- package/dist/types/stream.d.ts +1 -1
- package/dist/types/type-utils.d.cts +1 -1
- package/dist/types/type-utils.d.cts.map +1 -1
- package/dist/types/type-utils.d.ts +1 -1
- package/dist/types/type-utils.d.ts.map +1 -1
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.d.cts.map +1 -1
- package/dist/utils/async_caller.d.ts.map +1 -1
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/callbacks.cjs.map +1 -1
- package/dist/utils/callbacks.js.map +1 -1
- package/dist/utils/chunk_array.cjs.map +1 -1
- package/dist/utils/chunk_array.d.cts.map +1 -1
- package/dist/utils/chunk_array.d.ts.map +1 -1
- package/dist/utils/chunk_array.js.map +1 -1
- package/dist/utils/context.cjs.map +1 -1
- package/dist/utils/context.d.cts.map +1 -1
- package/dist/utils/context.d.ts.map +1 -1
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.d.cts.map +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/event_source_parse.cjs +2 -2
- package/dist/utils/event_source_parse.cjs.map +1 -1
- package/dist/utils/event_source_parse.d.cts +0 -1
- package/dist/utils/event_source_parse.d.cts.map +1 -1
- package/dist/utils/event_source_parse.d.ts +0 -1
- package/dist/utils/event_source_parse.d.ts.map +1 -1
- package/dist/utils/event_source_parse.js +2 -2
- package/dist/utils/event_source_parse.js.map +1 -1
- package/dist/utils/fast-json-patch/index.cjs +9 -1
- package/dist/utils/fast-json-patch/index.cjs.map +1 -1
- package/dist/utils/fast-json-patch/index.js +3 -3
- package/dist/utils/fast-json-patch/index.js.map +1 -1
- package/dist/utils/fast-json-patch/src/core.cjs +7 -0
- package/dist/utils/fast-json-patch/src/core.cjs.map +1 -1
- package/dist/utils/fast-json-patch/src/core.d.cts +1 -1
- package/dist/utils/fast-json-patch/src/core.d.cts.map +1 -1
- package/dist/utils/fast-json-patch/src/core.d.ts +1 -1
- package/dist/utils/fast-json-patch/src/core.d.ts.map +1 -1
- package/dist/utils/fast-json-patch/src/core.js +6 -1
- package/dist/utils/fast-json-patch/src/core.js.map +1 -1
- package/dist/utils/fast-json-patch/src/duplex.cjs.map +1 -1
- package/dist/utils/fast-json-patch/src/duplex.d.cts +0 -1
- package/dist/utils/fast-json-patch/src/duplex.d.cts.map +1 -1
- package/dist/utils/fast-json-patch/src/duplex.d.ts +0 -1
- package/dist/utils/fast-json-patch/src/duplex.d.ts.map +1 -1
- package/dist/utils/fast-json-patch/src/duplex.js.map +1 -1
- package/dist/utils/fast-json-patch/src/helpers.cjs +4 -0
- package/dist/utils/fast-json-patch/src/helpers.cjs.map +1 -1
- package/dist/utils/fast-json-patch/src/helpers.js +4 -0
- package/dist/utils/fast-json-patch/src/helpers.js.map +1 -1
- package/dist/utils/format.d.cts.map +1 -1
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/function_calling.cjs.map +1 -1
- package/dist/utils/function_calling.d.cts +0 -1
- package/dist/utils/function_calling.d.cts.map +1 -1
- package/dist/utils/function_calling.d.ts +0 -1
- package/dist/utils/function_calling.d.ts.map +1 -1
- package/dist/utils/function_calling.js.map +1 -1
- package/dist/utils/gateway.cjs +43 -0
- package/dist/utils/gateway.cjs.map +1 -0
- package/dist/utils/gateway.d.cts +13 -0
- package/dist/utils/gateway.d.cts.map +1 -0
- package/dist/utils/gateway.d.ts +13 -0
- package/dist/utils/gateway.d.ts.map +1 -0
- package/dist/utils/gateway.js +36 -0
- package/dist/utils/gateway.js.map +1 -0
- package/dist/utils/hash.d.cts +0 -1
- package/dist/utils/hash.d.cts.map +1 -1
- package/dist/utils/hash.d.ts +0 -1
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/is-network-error/index.cjs +1 -1
- package/dist/utils/is-network-error/index.cjs.map +1 -1
- package/dist/utils/is-network-error/index.js +1 -1
- package/dist/utils/is-network-error/index.js.map +1 -1
- package/dist/utils/js-sha256/hash.cjs.map +1 -1
- package/dist/utils/js-sha256/hash.d.cts.map +1 -1
- package/dist/utils/js-sha256/hash.d.ts.map +1 -1
- package/dist/utils/js-sha256/hash.js.map +1 -1
- package/dist/utils/json.cjs +1 -0
- package/dist/utils/json.cjs.map +1 -1
- package/dist/utils/json.d.cts.map +1 -1
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js +1 -1
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/json_schema.cjs.map +1 -1
- package/dist/utils/json_schema.d.cts +1 -1
- package/dist/utils/json_schema.d.cts.map +1 -1
- package/dist/utils/json_schema.d.ts +1 -1
- package/dist/utils/json_schema.d.ts.map +1 -1
- package/dist/utils/json_schema.js.map +1 -1
- package/dist/utils/math.cjs.map +1 -1
- package/dist/utils/math.d.cts.map +1 -1
- package/dist/utils/math.d.ts.map +1 -1
- package/dist/utils/math.js.map +1 -1
- package/dist/utils/ml-distance/distances.cjs.map +1 -1
- package/dist/utils/ml-distance/distances.js.map +1 -1
- package/dist/utils/ml-distance/similarities.cjs.map +1 -1
- package/dist/utils/ml-distance/similarities.d.cts.map +1 -1
- package/dist/utils/ml-distance/similarities.d.ts.map +1 -1
- package/dist/utils/ml-distance/similarities.js.map +1 -1
- package/dist/utils/ml-distance-euclidean/euclidean.cjs +1 -0
- package/dist/utils/ml-distance-euclidean/euclidean.cjs.map +1 -1
- package/dist/utils/ml-distance-euclidean/euclidean.js +1 -1
- package/dist/utils/ml-distance-euclidean/euclidean.js.map +1 -1
- package/dist/utils/namespace.cjs +4 -0
- package/dist/utils/namespace.cjs.map +1 -1
- package/dist/utils/namespace.d.cts.map +1 -1
- package/dist/utils/namespace.d.ts.map +1 -1
- package/dist/utils/namespace.js +4 -1
- package/dist/utils/namespace.js.map +1 -1
- package/dist/utils/p-retry/index.cjs +1 -0
- package/dist/utils/p-retry/index.cjs.map +1 -1
- package/dist/utils/p-retry/index.js +1 -1
- package/dist/utils/p-retry/index.js.map +1 -1
- package/dist/utils/sax-js/sax.cjs.map +1 -1
- package/dist/utils/sax-js/sax.js.map +1 -1
- package/dist/utils/signal.cjs.map +1 -1
- package/dist/utils/signal.d.cts.map +1 -1
- package/dist/utils/signal.d.ts.map +1 -1
- package/dist/utils/signal.js.map +1 -1
- package/dist/utils/ssrf.cjs.map +1 -1
- package/dist/utils/ssrf.d.cts.map +1 -1
- package/dist/utils/ssrf.d.ts.map +1 -1
- package/dist/utils/ssrf.js.map +1 -1
- package/dist/utils/standard_schema.cjs.map +1 -1
- package/dist/utils/standard_schema.d.cts +0 -1
- package/dist/utils/standard_schema.d.cts.map +1 -1
- package/dist/utils/standard_schema.d.ts +0 -1
- package/dist/utils/standard_schema.d.ts.map +1 -1
- package/dist/utils/standard_schema.js.map +1 -1
- package/dist/utils/stream.cjs.map +1 -1
- package/dist/utils/stream.d.cts +0 -1
- package/dist/utils/stream.d.cts.map +1 -1
- package/dist/utils/stream.d.ts +0 -1
- package/dist/utils/stream.d.ts.map +1 -1
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/testing/chat_models.cjs.map +1 -1
- package/dist/utils/testing/chat_models.d.cts +2 -9
- package/dist/utils/testing/chat_models.d.cts.map +1 -1
- package/dist/utils/testing/chat_models.d.ts +2 -9
- package/dist/utils/testing/chat_models.d.ts.map +1 -1
- package/dist/utils/testing/chat_models.js.map +1 -1
- package/dist/utils/testing/embeddings.cjs.map +1 -1
- package/dist/utils/testing/embeddings.d.cts +0 -1
- package/dist/utils/testing/embeddings.d.cts.map +1 -1
- package/dist/utils/testing/embeddings.d.ts +0 -1
- package/dist/utils/testing/embeddings.d.ts.map +1 -1
- package/dist/utils/testing/embeddings.js.map +1 -1
- package/dist/utils/testing/llms.cjs.map +1 -1
- package/dist/utils/testing/llms.d.cts +0 -1
- package/dist/utils/testing/llms.d.cts.map +1 -1
- package/dist/utils/testing/llms.d.ts +0 -1
- package/dist/utils/testing/llms.d.ts.map +1 -1
- package/dist/utils/testing/llms.js.map +1 -1
- package/dist/utils/testing/message_history.cjs.map +1 -1
- package/dist/utils/testing/message_history.d.cts +1 -1
- package/dist/utils/testing/message_history.d.cts.map +1 -1
- package/dist/utils/testing/message_history.d.ts +1 -1
- package/dist/utils/testing/message_history.d.ts.map +1 -1
- package/dist/utils/testing/message_history.js.map +1 -1
- package/dist/utils/testing/openai_stream_fixtures.cjs.map +1 -1
- package/dist/utils/testing/openai_stream_fixtures.d.cts +0 -1
- package/dist/utils/testing/openai_stream_fixtures.d.cts.map +1 -1
- package/dist/utils/testing/openai_stream_fixtures.d.ts +0 -1
- package/dist/utils/testing/openai_stream_fixtures.d.ts.map +1 -1
- package/dist/utils/testing/openai_stream_fixtures.js.map +1 -1
- package/dist/utils/testing/output_parsers.cjs.map +1 -1
- package/dist/utils/testing/output_parsers.d.cts +0 -1
- package/dist/utils/testing/output_parsers.d.cts.map +1 -1
- package/dist/utils/testing/output_parsers.d.ts +0 -1
- package/dist/utils/testing/output_parsers.d.ts.map +1 -1
- package/dist/utils/testing/output_parsers.js.map +1 -1
- package/dist/utils/testing/retrievers.cjs.map +1 -1
- package/dist/utils/testing/retrievers.d.cts +0 -1
- package/dist/utils/testing/retrievers.d.cts.map +1 -1
- package/dist/utils/testing/retrievers.d.ts +0 -1
- package/dist/utils/testing/retrievers.d.ts.map +1 -1
- package/dist/utils/testing/retrievers.js.map +1 -1
- package/dist/utils/testing/runnables.cjs.map +1 -1
- package/dist/utils/testing/runnables.d.cts +0 -1
- package/dist/utils/testing/runnables.d.cts.map +1 -1
- package/dist/utils/testing/runnables.d.ts +0 -1
- package/dist/utils/testing/runnables.d.ts.map +1 -1
- package/dist/utils/testing/runnables.js.map +1 -1
- package/dist/utils/testing/stream.cjs +5 -0
- package/dist/utils/testing/stream.cjs.map +1 -1
- package/dist/utils/testing/stream.d.cts.map +1 -1
- package/dist/utils/testing/stream.d.ts.map +1 -1
- package/dist/utils/testing/stream.js +1 -1
- package/dist/utils/testing/stream.js.map +1 -1
- package/dist/utils/testing/tools.cjs.map +1 -1
- package/dist/utils/testing/tools.d.cts +0 -1
- package/dist/utils/testing/tools.d.cts.map +1 -1
- package/dist/utils/testing/tools.d.ts +0 -1
- package/dist/utils/testing/tools.d.ts.map +1 -1
- package/dist/utils/testing/tools.js.map +1 -1
- package/dist/utils/testing/tracers.cjs.map +1 -1
- package/dist/utils/testing/tracers.d.cts +0 -1
- package/dist/utils/testing/tracers.d.cts.map +1 -1
- package/dist/utils/testing/tracers.d.ts +0 -1
- package/dist/utils/testing/tracers.d.ts.map +1 -1
- package/dist/utils/testing/tracers.js.map +1 -1
- package/dist/utils/testing/vectorstores.cjs.map +1 -1
- package/dist/utils/testing/vectorstores.d.cts +1 -5
- package/dist/utils/testing/vectorstores.d.cts.map +1 -1
- package/dist/utils/testing/vectorstores.d.ts +1 -5
- package/dist/utils/testing/vectorstores.d.ts.map +1 -1
- package/dist/utils/testing/vectorstores.js.map +1 -1
- package/dist/utils/tiktoken.cjs +1 -1
- package/dist/utils/tiktoken.cjs.map +1 -1
- package/dist/utils/tiktoken.d.cts +0 -1
- package/dist/utils/tiktoken.d.cts.map +1 -1
- package/dist/utils/tiktoken.d.ts +0 -1
- package/dist/utils/tiktoken.d.ts.map +1 -1
- package/dist/utils/tiktoken.js +1 -1
- package/dist/utils/tiktoken.js.map +1 -1
- package/dist/utils/types/index.d.cts +0 -1
- package/dist/utils/types/index.d.cts.map +1 -1
- package/dist/utils/types/index.d.ts +0 -1
- package/dist/utils/types/index.d.ts.map +1 -1
- package/dist/utils/types/zod.cjs +0 -1
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +2 -3
- package/dist/utils/types/zod.d.cts.map +1 -1
- package/dist/utils/types/zod.d.ts +2 -3
- package/dist/utils/types/zod.d.ts.map +1 -1
- package/dist/utils/types/zod.js.map +1 -1
- package/dist/utils/uuid/index.d.cts +10 -11
- package/dist/utils/uuid/index.d.cts.map +1 -1
- package/dist/utils/uuid/index.d.ts +10 -11
- package/dist/utils/uuid/index.d.ts.map +1 -1
- package/dist/utils/uuid/parse.cjs.map +1 -1
- package/dist/utils/uuid/parse.d.cts +1 -3
- package/dist/utils/uuid/parse.d.cts.map +1 -1
- package/dist/utils/uuid/parse.d.ts +1 -2
- package/dist/utils/uuid/parse.d.ts.map +1 -1
- package/dist/utils/uuid/parse.js.map +1 -1
- package/dist/utils/uuid/rng.cjs +1 -1
- package/dist/utils/uuid/rng.cjs.map +1 -1
- package/dist/utils/uuid/rng.js +1 -1
- package/dist/utils/uuid/rng.js.map +1 -1
- package/dist/utils/uuid/sha1.cjs +2 -2
- package/dist/utils/uuid/sha1.cjs.map +1 -1
- package/dist/utils/uuid/sha1.js +2 -2
- package/dist/utils/uuid/sha1.js.map +1 -1
- package/dist/utils/uuid/stringify.cjs.map +1 -1
- package/dist/utils/uuid/stringify.d.cts +1 -2
- package/dist/utils/uuid/stringify.d.cts.map +1 -1
- package/dist/utils/uuid/stringify.d.ts +1 -1
- package/dist/utils/uuid/stringify.d.ts.map +1 -1
- package/dist/utils/uuid/stringify.js.map +1 -1
- package/dist/utils/uuid/types.d.cts.map +1 -1
- package/dist/utils/uuid/types.d.ts.map +1 -1
- package/dist/utils/uuid/v1.cjs +2 -1
- package/dist/utils/uuid/v1.cjs.map +1 -1
- package/dist/utils/uuid/v1.d.cts +1 -3
- package/dist/utils/uuid/v1.d.cts.map +1 -1
- package/dist/utils/uuid/v1.d.ts +1 -2
- package/dist/utils/uuid/v1.d.ts.map +1 -1
- package/dist/utils/uuid/v1.js +2 -2
- package/dist/utils/uuid/v1.js.map +1 -1
- package/dist/utils/uuid/v1ToV6.cjs.map +1 -1
- package/dist/utils/uuid/v1ToV6.js.map +1 -1
- package/dist/utils/uuid/v35.cjs +1 -0
- package/dist/utils/uuid/v35.cjs.map +1 -1
- package/dist/utils/uuid/v35.d.cts +6 -0
- package/dist/utils/uuid/v35.d.cts.map +1 -0
- package/dist/utils/uuid/v35.d.ts +6 -0
- package/dist/utils/uuid/v35.d.ts.map +1 -0
- package/dist/utils/uuid/v35.js +1 -1
- package/dist/utils/uuid/v35.js.map +1 -1
- package/dist/utils/uuid/v4.cjs.map +1 -1
- package/dist/utils/uuid/v4.d.cts +1 -3
- package/dist/utils/uuid/v4.d.cts.map +1 -1
- package/dist/utils/uuid/v4.d.ts +1 -2
- package/dist/utils/uuid/v4.d.ts.map +1 -1
- package/dist/utils/uuid/v4.js.map +1 -1
- package/dist/utils/uuid/v5.cjs.map +1 -1
- package/dist/utils/uuid/v5.d.cts +5 -8
- package/dist/utils/uuid/v5.d.cts.map +1 -1
- package/dist/utils/uuid/v5.d.ts +5 -7
- package/dist/utils/uuid/v5.d.ts.map +1 -1
- package/dist/utils/uuid/v5.js.map +1 -1
- package/dist/utils/uuid/v6.cjs +1 -1
- package/dist/utils/uuid/v6.cjs.map +1 -1
- package/dist/utils/uuid/v6.d.cts +1 -3
- package/dist/utils/uuid/v6.d.cts.map +1 -1
- package/dist/utils/uuid/v6.d.ts +1 -2
- package/dist/utils/uuid/v6.d.ts.map +1 -1
- package/dist/utils/uuid/v6.js +1 -1
- package/dist/utils/uuid/v6.js.map +1 -1
- package/dist/utils/uuid/v7.cjs +2 -1
- package/dist/utils/uuid/v7.cjs.map +1 -1
- package/dist/utils/uuid/v7.d.cts +1 -3
- package/dist/utils/uuid/v7.d.cts.map +1 -1
- package/dist/utils/uuid/v7.d.ts +1 -2
- package/dist/utils/uuid/v7.d.ts.map +1 -1
- package/dist/utils/uuid/v7.js +2 -2
- package/dist/utils/uuid/v7.js.map +1 -1
- package/dist/utils/uuid/validate.cjs.map +1 -1
- package/dist/utils/uuid/validate.d.cts +1 -2
- package/dist/utils/uuid/validate.d.cts.map +1 -1
- package/dist/utils/uuid/validate.d.ts +1 -1
- package/dist/utils/uuid/validate.d.ts.map +1 -1
- package/dist/utils/uuid/validate.js.map +1 -1
- package/dist/utils/uuid/version.cjs.map +1 -1
- package/dist/utils/uuid/version.d.cts +1 -2
- package/dist/utils/uuid/version.d.cts.map +1 -1
- package/dist/utils/uuid/version.d.ts +1 -1
- package/dist/utils/uuid/version.d.ts.map +1 -1
- package/dist/utils/uuid/version.js.map +1 -1
- package/dist/utils/zod-to-json-schema/Options.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/Options.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/Options.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/Options.js.map +1 -1
- package/dist/utils/zod-to-json-schema/Refs.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/Refs.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/Refs.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/Refs.js.map +1 -1
- package/dist/utils/zod-to-json-schema/errorMessages.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts +2 -1
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts +2 -1
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/errorMessages.js.map +1 -1
- package/dist/utils/zod-to-json-schema/getRelativePath.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/getRelativePath.js.map +1 -1
- package/dist/utils/zod-to-json-schema/index.cjs +79 -37
- package/dist/utils/zod-to-json-schema/index.d.cts +15 -1
- package/dist/utils/zod-to-json-schema/index.d.ts +15 -1
- package/dist/utils/zod-to-json-schema/index.js +38 -38
- package/dist/utils/zod-to-json-schema/parseDef.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parseDef.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parseDef.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parseDef.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts +0 -1
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts +0 -1
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/any.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/any.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/array.cjs +0 -1
- package/dist/utils/zod-to-json-schema/parsers/array.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/array.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/bigint.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/bigint.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/boolean.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/boolean.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/branded.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/branded.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/branded.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/branded.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/catch.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/catch.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/catch.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/catch.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/date.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts +3 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts +3 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/date.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/default.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/default.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/default.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/default.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/effects.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/effects.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/effects.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/effects.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/enum.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/enum.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/intersection.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/intersection.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/literal.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/literal.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/map.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts +3 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts +3 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/map.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/never.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/never.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/null.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/null.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nullable.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/nullable.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/number.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/number.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/object.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/object.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/optional.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/optional.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/optional.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/optional.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/pipeline.d.cts +4 -1
- package/dist/utils/zod-to-json-schema/parsers/pipeline.d.ts +4 -1
- package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/promise.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/promise.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/promise.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/promise.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/readonly.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/readonly.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/readonly.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/parsers/readonly.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/record.cjs +0 -1
- package/dist/utils/zod-to-json-schema/parsers/record.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/record.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/string.cjs +0 -2
- package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/string.js +0 -2
- package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/tuple.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/tuple.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/undefined.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/undefined.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/union.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/union.js.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/unknown.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema/parsers/unknown.js.map +1 -1
- package/dist/utils/zod-to-json-schema/selectParser.cjs +0 -1
- package/dist/utils/zod-to-json-schema/selectParser.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/selectParser.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/selectParser.d.ts +2 -0
- package/dist/utils/zod-to-json-schema/selectParser.js.map +1 -1
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs.map +1 -1
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.d.cts +3 -1
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.d.ts +3 -1
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.js.map +1 -1
- package/dist/vectorstores.cjs.map +1 -1
- package/dist/vectorstores.d.cts +0 -1
- package/dist/vectorstores.d.cts.map +1 -1
- package/dist/vectorstores.d.ts +0 -1
- package/dist/vectorstores.d.ts.map +1 -1
- package/dist/vectorstores.js.map +1 -1
- package/package.json +15 -4
- package/utils/gateway.cjs +1 -0
- package/utils/gateway.d.cts +1 -0
- package/utils/gateway.d.ts +1 -0
- package/utils/gateway.js +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph_mermaid.cjs","names":["toBase64Url"],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\" <br> \");\n }\n edgeLabel = conditional\n ? ` -. ${edgeData} .-> `\n : ` -- ${edgeData} --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;AAGA,SAAS,iBAAiB,WAA2B;AAEnD,QAAO,UAAU,QAAQ,mBAAmB,IAAI;;AAGlD,MAAM,yBAAyB;CAAC;CAAK;CAAK;CAAI;AAE9C,SAAS,4BACP,YACQ;CACR,IAAI,SAAS;AACb,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,WAAW,CACzD,WAAU,cAAc,UAAU,GAAG,MAAM;AAE7C,QAAO;;;;;AAMT,SAAgB,YACd,OACA,OACA,QAQQ;CACR,MAAM,EACJ,WACA,UACA,YACA,aAAa,MACb,aAAa,UACb,kBAAkB,MAChB,UAAU,EAAE;CAEhB,IAAI,eAAe,aACf,qCAAqC,WAAW,uBAChD;AACJ,KAAI,YAAY;EAEd,MAAM,oBAAoB;EAC1B,MAAM,aAAqC,GACxC,oBAAoB,YACtB;AACD,MAAI,cAAc,KAAA,EAChB,YAAW,aAAa;AAE1B,MAAI,aAAa,KAAA,EACf,YAAW,YAAY;AAIzB,OAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,MAAM,EAAE;GAC/C,MAAM,WAAW,KAAK,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI;GAO/C,IAAI,aANU,uBAAuB,MAClC,SAAS,SAAS,WAAW,KAAK,IAAI,SAAS,SAAS,KAAK,CAC/D,GACG,MAAM,SAAS,Q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AAgB,QAAQ;CACpG,MAAM,MAAM,MAAM,MAAM,SAAS;AACjC,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR;EACE;EACA,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;EACrB,CAAC,KAAK,KAAK,CACb;AAGH,QAAO,MADe,IAAI,MAAM"}
|
|
1
|
+
{"version":3,"file":"graph_mermaid.cjs","names":["toBase64Url"],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\" <br> \");\n }\n edgeLabel = conditional\n ? ` -. ${edgeData} .-> `\n : ` -- ${edgeData} --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;AAGA,SAAS,iBAAiB,WAA2B;CAEnD,OAAO,UAAU,QAAQ,mBAAmB,GAAG;AACjD;AAEA,MAAM,yBAAyB;CAAC;CAAK;CAAK;AAAG;AAE7C,SAAS,4BACP,YACQ;CACR,IAAI,SAAS;CACb,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,UAAU,GACxD,UAAU,cAAc,UAAU,GAAG,MAAM;CAE7C,OAAO;AACT;;;;AAKA,SAAgB,YACd,OACA,OACA,QAQQ;CACR,MAAM,EACJ,WACA,UACA,YACA,aAAa,MACb,aAAa,UACb,kBAAkB,MAChB,UAAU,CAAC;CAEf,IAAI,eAAe,aACf,qCAAqC,WAAW,uBAChD;CACJ,IAAI,YAAY;EAEd,MAAM,oBAAoB;EAC1B,MAAM,aAAqC,GACxC,oBAAoB,WACvB;EACA,IAAI,cAAc,KAAA,GAChB,WAAW,aAAa;EAE1B,IAAI,aAAa,KAAA,GACf,WAAW,YAAY;EAIzB,KAAK,MAAM,CAAC,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1C,IAAI,YACF,gBAAgB,4BAA4B,cAAc,CAAC,CAAC;CAG9D,OAAO;AACT;;;;;;;;;;;;;;;;;AAkBA,eAAsB,iBACpB,eACA,QAQA;CACA,IAAI,kBAAkB,QAAQ,mBAAmB;CACjD,MAAM,YAAY,QAAQ,aAAa;CAEvC,MAAM,uBAAuBA,cAAAA,YAAY,aAAa;CAGtD,IAAI,oBAAoB,KAAA,GAElB;MAAA,CAAC,6BAAgB,KAAK,eAAe,GACvC,kBAAkB,IAAI;CAAA;CAG1B,MAAM,WAAW,2BAA2B,qBAAqB,WAAW,gBAAgB,QAAQ;CACpG,MAAM,MAAM,MAAM,MAAM,QAAQ;CAChC,IAAI,CAAC,IAAI,IACP,MAAM,IAAI,MACR;EACE;EACA,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;CACtB,CAAC,CAAC,KAAK,IAAI,CACb;CAGF,OAAO,MADe,IAAI,KAAK;AAEjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph_mermaid.js","names":[],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\" <br> \");\n }\n edgeLabel = conditional\n ? ` -. ${edgeData} .-> `\n : ` -- ${edgeData} --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;AAGA,SAAS,iBAAiB,WAA2B;AAEnD,QAAO,UAAU,QAAQ,mBAAmB,IAAI;;AAGlD,MAAM,yBAAyB;CAAC;CAAK;CAAK;CAAI;AAE9C,SAAS,4BACP,YACQ;CACR,IAAI,SAAS;AACb,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,WAAW,CACzD,WAAU,cAAc,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iBACnB,OACD,GAAG,YAAY,iBAAiB,OAAO,CAAC;;AAG3C,MAAI,UAAU,CAAC,SACb,iBAAgB;;AAKpB,aAAY,WAAW,OAAO,EAAE,EAAE,GAAG;AAGrC,MAAK,MAAM,UAAU,WACnB,KAAI,CAAC,OAAO,SAAS,IAAI,IAAI,WAAW,GACtC,aAAY,WAAW,SAAS,OAAO;AAK3C,KAAI,WACF,iBAAgB,4BAA4B,cAAc,EAAE,CAAC;AAG/D,QAAO;;;;;;;;;;;;;;;;;;AAmBT,eAAsB,iBACpB,eACA,QAQA;CACA,IAAI,kBAAkB,QAAQ,mBAAmB;CACjD,MAAM,YAAY,QAAQ,aAAa;CAEvC,MAAM,uBAAuB,YAAY,cAAc;AAGvD,KAAI,oBAAoB,KAAA;MAElB,CAAC,6BAAgB,KAAK,gBAAgB,CACxC,mBAAkB,IAAI;;CAG1B,MAAM,WAAW,2BAA2B,qBAAqB,WAAW,gBAAgB,QAAQ;CACpG,MAAM,MAAM,MAAM,MAAM,SAAS;AACjC,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR;EACE;EACA,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;EACrB,CAAC,KAAK,KAAK,CACb;AAGH,QAAO,MADe,IAAI,MAAM"}
|
|
1
|
+
{"version":3,"file":"graph_mermaid.js","names":[],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\" <br> \");\n }\n edgeLabel = conditional\n ? ` -. ${edgeData} .-> `\n : ` -- ${edgeData} --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;AAGA,SAAS,iBAAiB,WAA2B;CAEnD,OAAO,UAAU,QAA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Message","HumanMessage","AIMessage"],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n *\n * @deprecated Use LangGraph's built-in persistence instead.\n *\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"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pB,UAAS,IAAI;EAEf,IAAI,gBAAgB,KAAK,kBAAkB,OAAO;AAGlD,MAAI,KAAK,uBAAuB,KAAA,GAAW;GACzC,MAAM,mBAAmB,MAAM,QAAQ,aAAa;AACpD,mBAAgB,cAAc,MAAM,iBAAiB,OAAO;;EAG9D,MAAM,cAAc,IAAI;AACxB,MAAI,CAAC,YACH,OAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,EACD,GACF;EAEH,MAAM,iBAAiB,KAAK,mBAAmB,YAAY;AAC3D,QAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,eAAe,CAAC;;CAGlE,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,QAAQ;AAEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UACxD,EAJkB,cAAc,EAAE,WAAW,OAAO,EAIvC,CACd,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
|
|
1
|
+
{"version":3,"file":"history.cjs","names":["RunnableBinding","RunnableLambda","RunnablePassthrough","isBaseMessage","HumanMessage","AIMessage"],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n *\n * @deprecated Use LangGraph's built-in persistence instead.\n *\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAa,6BAAb,cAGUA,eAAAA,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyBC,eAAAA,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,CAAC,CAAC,CACzC,CAAC,CAAC,WAAW,EAAE,SAAS,cAAc,CAAC;EAEvC,MAAM,cAAc,OAAO,sBAAsB,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C,aACH,MAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,CACF,GACF;EAEF,MAAM,iBAAiB,KAAK,mBAAmB,WAAW;EAC1D,MAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,cAAc,CAAC;CACjE;CAEA,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,OAAO;EAElD,IAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,MACtC;GAEA,MAAM,IAAI,MACR,gHACsB,KAAK,UAAU,YAAY,EAAE,IAAI,KAAK,UACxD,EAJkB,cAAc,EAAE,WAAW,MAAM,EAIvC,CACd,EAAE,EACN;EACF;EAEA,MAAM,EAAE,cAAc,OAAO;EAC7B,OAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,SAAS;EACxC,OAAO;CACT;AACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseMessage } from "../messages/base.cjs";
|
|
2
2
|
import { RunnableConfig } from "./types.cjs";
|
|
3
|
+
import "./config.cjs";
|
|
3
4
|
import { Run } from "../tracers/base.cjs";
|
|
4
5
|
import { Runnable, RunnableBinding, RunnableBindingArgs } from "./base.cjs";
|
|
6
|
+
import "../messages/index.cjs";
|
|
5
7
|
import { BaseChatMessageHistory, BaseListChatMessageHistory } from "../chat_history.cjs";
|
|
6
|
-
|
|
7
8
|
//#region src/runnables/history.d.ts
|
|
8
9
|
type GetSessionHistoryCallable = (...args: Array<any>) => Promise<BaseChatMessageHistory | BaseListChatMessageHistory> | BaseChatMessageHistory | BaseListChatMessageHistory;
|
|
9
10
|
interface RunnableWithMessageHistoryInputs<RunInput, RunOutput> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, "bound" | "config"> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.cts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"history.d.cts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":";;;;;;;;KAoBK,gCAEA,MAAM,eAEP,QAAQ,yBAAyB,8BACjC,yBACA;UAEa,iCACf,UACA,mBACQ,KAAK,oBAAoB,UAAU;EAC3C,UAAU,SAAS,UAAU;EAC7B,mBAAmB;EACnB;EACA;EACA;EACA,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoEE,2BACX,UACA,mBACQ,gBAAgB,UAAU;EAClC,UAAU,SAAS,UAAU;EAE7B;EAEA;EAEA;EAEA,mBAAmB;EAEnB,YAAY,QAAQ,iCAAiC,UAAU;EAkC/D,kBAEE,qBAAqB,cAAc,MAAM,eAAe,sBACvD,MAAM;EAwCT,mBAEE,sBAAsB,cAAc,MAAM,eAAe,sBACxD,MAAM;EA2CH,cAEJ,YACA,SAAS,iBACR,QAAQ;EASL,aAAa,KAAK,KAAK,QAAQ,iBAAiB;EAiChD,gBAAgB,SAAS,MAAM,8BAA2B,QAAA,QAAA,eAAA"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseMessage } from "../messages/base.js";
|
|
2
2
|
import { RunnableConfig } from "./types.js";
|
|
3
|
+
import "./config.js";
|
|
3
4
|
import { Run } from "../tracers/base.js";
|
|
4
5
|
import { Runnable, RunnableBinding, RunnableBindingArgs } from "./base.js";
|
|
6
|
+
import "../messages/index.js";
|
|
5
7
|
import { BaseChatMessageHistory, BaseListChatMessageHistory } from "../chat_history.js";
|
|
6
|
-
|
|
7
8
|
//#region src/runnables/history.d.ts
|
|
8
9
|
type GetSessionHistoryCallable = (...args: Array<any>) => Promise<BaseChatMessageHistory | BaseListChatMessageHistory> | BaseChatMessageHistory | BaseListChatMessageHistory;
|
|
9
10
|
interface RunnableWithMessageHistoryInputs<RunInput, RunOutput> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, "bound" | "config"> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"history.d.ts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":";;;;;;;;KAoBK,gCAEA,MAAM,eAEP,QAAQ,yBAAyB,8BACjC,yBACA;UAEa,iCACf,UACA,mBACQ,KAAK,oBAAoB,UAAU;EAC3C,UAAU,SAAS,UAAU;EAC7B,mBAAmB;EACnB;EACA;EACA;EACA,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoEE,2BACX,UACA,mBACQ,gBAAgB,UAAU;EAClC,UAAU,SAAS,UAAU;EAE7B;EAEA;EAEA;EAEA,mBAAmB;EAEnB,YAAY,QAAQ,iCAAiC,UAAU;EAkC/D,kBAEE,qBAAqB,cAAc,MAAM,eAAe,sBACvD,MAAM;EAwCT,mBAEE,sBAAsB,cAAc,MAAM,eAAe,sBACxD,MAAM;EA2CH,cAEJ,YACA,SAAS,iBACR,QAAQ;EASL,aAAa,KAAK,KAAK,QAAQ,iBAAiB;EAiChD,gBAAgB,SAAS,MAAM,8BAA2B,QAAA,QAAA,eAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","names":[],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n *\n * @deprecated Use LangGraph's built-in persistence instead.\n *\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAa,6BAAb,cAGU,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyB,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,EAAE,CAAC,CACzC,CAAC,WAAW,EAAE,SAAS,eAAe,CAAC;EAExC,MAAM,cAAc,OAAO,sBAAsB,OAAO;AACxD,MAAI,YACF,gBAAe,oBAAoB,OAAO,GACvC,cAAc,cAChB,CA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AEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UACxD,EAJkB,cAAc,EAAE,WAAW,OAAO,EAIvC,CACd,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
|
|
1
|
+
{"version":3,"file":"history.js","names":[],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n *\n * @deprecated Use LangGraph's built-in persistence instead.\n *\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAa,6BAAb,cAGU,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyB,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,CAAC,CAAC,CACzC,CAAC,CAAC,WAAW,EAAE,SAAS,cAAc,CAAC;EAEvC,MAAM,cAAc,OAAO,sBAAsB,OAAO;EACxD,IAAI,aACF,eAAe,oBAAoB,OAAO,GACvC,cAAc,aACjB,CAAC,CAAC,CAAC,WAAW,EAAE,SAAS,gBAAgB,CAAC;EAG5C,MAAM,QAAQ,aACX,KACC,OAAO,SAAS,cAAc,EAC5B,QAAQ,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,CAAC,CAAC,EAC7D,CAAC,CACH,CAAC,CACA,WAAW,EAAE,SAAS,6BAA6B,CAAC;EAEvD,MAAM,SAAS,OAAO,UAAU,CAAC;EAEjC,MAAM;GACJ,GAAG;GACH;GACA;EACF,CAAC;EACD,KAAK,WAAW,OAAO;EACvB,KAAK,oBAAoB,OAAO;EAChC,KAAK,mBAAmB,OAAO;EAC/B,KAAK,oBAAoB,OAAO;EAChC,KAAK,qBAAqB,OAAO;CACnC;CAEA,kBAEE,YACoB;EACpB,IAAI;EACJ,IACE,OA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
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iter.cjs","names":["AsyncLocalStorageProviderSingleton","pickRunnableConfigKeys"],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;AAIA,SAAgB,mBACd,OACoC;
|
|
1
|
+
{"version":3,"file":"iter.cjs","names":["AsyncLocalStorageProviderSingleton","pickRunnableConfigKeys"],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;AAIA,SAAgB,mBACd,OACoC;CACpC,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoB,OAAO,cAAc,cAEjD,OAAQ,MAAoB,SAAS;AAEzC;AAEA,MAAa,cAAc,MACzB,KAAK,QACL,OAAO,MAAM,YACb,UAAU,KACV,OAAO,EAAE,SAAS;AAEpB,SAAgB,gBACd,OACiC;CACjC,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,OAAO,mBAC9C;AAEN;AAEA,SAAgB,iBAAiB,GAAiC;CAChE,OACE,KAAK,QACL,OAAO,MAAM,YACb,OAAQ,EAAqB,SAAS;AAE1C;AAEA,eAAsB,sBACpB,WACA,SACkB;CAClB,IAAI;EACF,IAAI,aAAa,MAAM,UAAU,KAAK;EACtC,OAAO,CAAC,WAAW,MAAM;GACvB,MAAM,UAAU,WAAW,KAAK;GAChC,aAAa,MAAM,UAAU,KAAK;EACpC;EACA,OAAO,WAAW;CACpB,UAAU;EACR,MAAM,UAAU,SAAS,KAAA,CAAoB;CAC/C;AACF;AAEA,UAAiB,yBACf,SACA,MACqB;CACrB,OAAO,MAAM;EACX,MAAM,EAAE,OAAO,SAASA,cAAAA,mCAAmC,cACzDC,eAAAA,uBAAuB,OAAO,GAC9B,KAAK,KAAK,KAAK,IAAI,GACnB,IACF;EACA,IAAI,MACF;OAEA,MAAM;CAEV;AACF;AAEA,gBAAuB,8BACrB,SACA,MAC0B;CAC1B,MAAM,WAAW,KAAK,OAAO,cAAc,CAAC;CAC5C,OAAO,MAAM;EACX,MAAM,EAAE,OAAO,SACb,MAAMD,cAAAA,mCAAmC,cACvCC,eAAAA,uBAAuB,OAAO,GAC9B,SAAS,KAAK,KAAK,IAAI,GACvB,IACF;EACF,IAAI,MACF;OAEA,MAAM;CAEV;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iter.js","names":[],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;AAIA,SAAgB,mBACd,OACoC;
|
|
1
|
+
{"version":3,"file":"iter.js","names":[],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;AAIA,SAAgB,mBACd,OACoC;CACpC,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoB,OAAO,cAAc,cAEjD,OAAQ,MAAoB,SAAS;AAEzC;AAEA,MAAa,cAAc,MACzB,KAAK,QACL,OAAO,MAAM,YACb,UAAU,KACV,OAAO,EAAE,SAAS;AAEpB,SAAgB,gBACd,OACiC;CACjC,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,OAAO,mBAC9C;AAEN;AAEA,SAAgB,iBAAiB,GAAiC;CAChE,OACE,KAAK,QACL,OAAO,MAAM,YACb,OAAQ,EAAqB,SAAS;AAE1C;AAEA,eAAsB,sBACpB,WACA,SACkB;CAClB,IAAI;EACF,IAAI,aAAa,MAAM,UAAU,KAAK;EACtC,OAAO,CAAC,WAAW,MAAM;GACvB,MAAM,UAAU,WAAW,KAAK;GAChC,aAAa,MAAM,UAAU,KAAK;EACpC;EACA,OAAO,WAAW;CACpB,UAAU;EACR,MAAM,UAAU,SAAS,KAAA,CAAoB;CAC/C;AACF;AAEA,UAAiB,yBACf,SACA,MACqB;CACrB,OAAO,MAAM;EACX,MAAM,EAAE,OAAO,SAAS,mCAAmC,cACzD,uBAAuB,OAAO,GAC9B,KAAK,KAAK,KAAK,IAAI,GACnB,IACF;EACA,IAAI,MACF;OAEA,MAAM;CAEV;AACF;AAEA,gBAAuB,8BACrB,SACA,MAC0B;CAC1B,MAAM,WAAW,KAAK,OAAO,cAAc,CAAC;CAC5C,OAAO,MAAM;EACX,MAAM,EAAE,OAAO,SACb,MAAM,mCAAmC,cACvC,uBAAuB,OAAO,GAC9B,SAAS,KAAK,KAAK,IAAI,GACvB,IACF;EACF,IAAI,MACF;OAEA,MAAM;CAEV;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passthrough.cjs","names":["Runnable","ensureConfig","concat","RunnableAssign","RunnableMap"],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyDA,aAAAA,SAGvD;CACA,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"passthrough.cjs","names":["Runnable","ensureConfig","concat","RunnableAssign","RunnableMap"],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyDA,aAAAA,SAGvD;CACA,OAAO,UAAU;EACf,OAAO;CACT;CAEA,eAAe,CAAC,kBAAkB,WAAW;CAE7C,kBAAkB;CAElB;CAEA,YAAY,QAAuD;EACjE,MAAM,MAAM;EACZ,IAAI,QACF,KAAK,OAAO,OAAO;CAEvB;CAEA,MAAM,OACJ,OACA,SACmB;EACnB,MAAM,SAASC,eAAAA,aAAa,OAAO;EACnC,IAAI,KAAK,MACP,MAAM,KAAK,KAAK,OAAO,MAAM;EAG/B,OAAO,KAAK,iBACT,UAAoB,QAAQ,QAAQ,KAAK,GAC1C,OACA,MACF;CACF;CAEA,OAAO,UACL,WACA,SAC0B;EAC1B,MAAM,SAASA,eAAAA,aAAa,OAAO;EACnC,IAAI;EACJ,IAAI,uBAAuB;EAE3B,WAAW,MAAM,SAAS,KAAK,2BAC7B,YACC,UAAoC,OACrC,MACF,GAAG;GACD,MAAM;GACN,IAAI,sBACF,IAAI,gBAAgB,KAAA,GAClB,cAAc;QAEd,IAAI;IAEF,cAAcC,qBAAAA,OAAO,aAAa,KAAY;GAChD,QAAQ;IACN,cAAc,KAAA;IACd,uBAAuB;GACzB;EAGN;EAEA,IAAI,KAAK,QAAQ,gBAAgB,KAAA,GAC/B,MAAM,KAAK,KAAK,aAAa,MAAM;CAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BA,OAAO,OAIL,SACgD;EAChD,OAAO,IAAIC,aAAAA,eAAe,IAAIC,aAAAA,YAAY,EAAE,OAAO,QAAQ,CAAC,CAAC;CAC/D;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RunnableConfig } from "./types.cjs";
|
|
2
|
+
import "./config.cjs";
|
|
2
3
|
import { Runnable, RunnableAssign, RunnableMapLike } from "./base.cjs";
|
|
3
|
-
|
|
4
4
|
//#region src/runnables/passthrough.d.ts
|
|
5
5
|
type RunnablePassthroughFunc<RunInput = any> = ((input: RunInput) => void) | ((input: RunInput, config?: RunnableConfig) => void) | ((input: RunInput) => Promise<void>) | ((input: RunInput, config?: RunnableConfig) => Promise<void>);
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passthrough.d.cts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;KAUK,
|
|
1
|
+
{"version":3,"file":"passthrough.d.cts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;KAUK,wBAAwB,oBACvB,OAAO,uBACP,OAAO,UAAU,SAAS,6BAC1B,OAAO,aAAa,mBACpB,OAAO,UAAU,SAAS,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6BtC,oBAAoB,wBAAwB,SACvD,UACA;SAEO;EAIP;EAEA;EAEA,OAAO,wBAAwB;EAE/B,YAAY;IAAW,OAAO,wBAAwB;;EAOhD,OACJ,OAAO,UACP,UAAU,QAAQ,kBACjB,QAAQ;EAaJ,UACL,WAAW,eAAe,WAC1B,SAAS,QAAQ,kBAChB,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA2DX,OACL,iBAAiB,0BAA0B,yBAC3C,kBAAkB,0BAA0B,yBAE5C,SAAS,gBAAgB,UAAU,aAClC,eAAe,UAAU,WAAW"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RunnableConfig } from "./types.js";
|
|
2
|
+
import "./config.js";
|
|
2
3
|
import { Runnable, RunnableAssign, RunnableMapLike } from "./base.js";
|
|
3
|
-
|
|
4
4
|
//#region src/runnables/passthrough.d.ts
|
|
5
5
|
type RunnablePassthroughFunc<RunInput = any> = ((input: RunInput) => void) | ((input: RunInput, config?: RunnableConfig) => void) | ((input: RunInput) => Promise<void>) | ((input: RunInput, config?: RunnableConfig) => Promise<void>);
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passthrough.d.ts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;KAUK,
|
|
1
|
+
{"version":3,"file":"passthrough.d.ts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;KAUK,wBAAwB,oBACvB,OAAO,uBACP,OAAO,UAAU,SAAS,6BAC1B,OAAO,aAAa,mBACpB,OAAO,UAAU,SAAS,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6BtC,oBAAoB,wBAAwB,SACvD,UACA;SAEO;EAIP;EAEA;EAEA,OAAO,wBAAwB;EAE/B,YAAY;IAAW,OAAO,wBAAwB;;EAOhD,OACJ,OAAO,UACP,UAAU,QAAQ,kBACjB,QAAQ;EAaJ,UACL,WAAW,eAAe,WAC1B,SAAS,QAAQ,kBAChB,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA2DX,OACL,iBAAiB,0BAA0B,yBAC3C,kBAAkB,0BAA0B,yBAE5C,SAAS,gBAAgB,UAAU,aAClC,eAAe,UAAU,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passthrough.js","names":[],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyD,SAGvD;CACA,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"passthrough.js","names":[],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyD,SAGvD;CACA,OAAO,UAAU;EACf,OAAO;CACT;CAEA,eAAe,CAAC,kBAAkB,WAAW;CAE7C,kBAAkB;CAElB;CAEA,YAAY,QAAuD;EACjE,MAAM,MAAM;EACZ,IAAI,QACF,KAAK,OAAO,OAAO;CAEvB;CAEA,MAAM,OACJ,OACA,SACmB;EACnB,MAAM,SAAS,aAAa,OAAO;EACnC,IAAI,KAAK,MACP,MAAM,KAAK,KAAK,OAAO,MAAM;EAG/B,OAAO,KAAK,iBACT,UAAoB,QAAQ,QAAQ,KAAK,GAC1C,OACA,MACF;CACF;CAEA,OAAO,UACL,WACA,SAC0B;EAC1B,MAAM,SAAS,aAAa,OAAO;EACnC,IAAI;EACJ,IAAI,uBAAuB;EAE3B,WAAW,MAAM,SAAS,KAAK,2BAC7B,YACC,UAAoC,OACrC,MACF,GAAG;GACD,MAAM;GACN,IAAI,sBACF,IAAI,gBAAgB,KAAA,GAClB,cAAc;QAEd,IAAI;IAEF,cAAc,OAAO,aAAa,KAAY;GAChD,QAAQ;IACN,cAAc,KAAA;IACd,uBAAuB;GACzB;EAGN;EAEA,IAAI,KAAK,QAAQ,gBAAgB,KAAA,GAC/B,MAAM,KAAK,KAAK,aAAa,MAAM;CAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BA,OAAO,OAIL,SACgD;EAChD,OAAO,IAAI,eAAe,IAAI,YAAY,EAAE,OAAO,QAAQ,CAAC,CAAC;CAC/D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.cjs","names":["Runnable","ensureConfig"],"sources":["../../src/runnables/router.ts"],"sourcesContent":["import { Runnable, type RunnableBatchOptions } from \"./base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\nexport type RouterInput = {\n key: string;\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any;\n};\n\n/**\n * A runnable that routes to a set of runnables based on Input['key'].\n * Returns the output of the selected runnable.\n * @example\n * ```typescript\n * import { RouterRunnable, RunnableLambda } from \"@langchain/core/runnables\";\n *\n * const router = new RouterRunnable({\n * runnables: {\n * toUpperCase: RunnableLambda.from((text: string) => text.toUpperCase()),\n * reverseText: RunnableLambda.from((text: string) =>\n * text.split(\"\").reverse().join(\"\")\n * ),\n * },\n * });\n *\n * // Invoke the 'reverseText' runnable\n * const result1 = router.invoke({ key: \"reverseText\", input: \"Hello World\" });\n *\n * // \"dlroW olleH\"\n *\n * // Invoke the 'toUpperCase' runnable\n * const result2 = router.invoke({ key: \"toUpperCase\", input: \"Hello World\" });\n *\n * // \"HELLO WORLD\"\n * ```\n */\nexport class RouterRunnable<\n RunInput extends RouterInput,\n RunnableInput,\n RunOutput,\n> extends Runnable<RunInput, RunOutput> {\n static lc_name() {\n return \"RouterRunnable\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n\n constructor(fields: {\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n }) {\n super(fields);\n this.runnables = fields.runnables;\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunOutput> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.invoke(actualInput, ensureConfig(options));\n }\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions?: false }\n ): Promise<RunOutput[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions: true }\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]> {\n const keys = inputs.map((input) => input.key);\n const actualInputs = inputs.map((input) => input.input);\n const missingKey = keys.find((key) => this.runnables[key] === undefined);\n if (missingKey !== undefined) {\n throw new Error(`One or more keys do not have a corresponding runnable.`);\n }\n const runnables = keys.map((key) => this.runnables[key]);\n const optionsList = this._getOptionsList(options ?? {}, inputs.length);\n const maxConcurrency =\n optionsList[0]?.maxConcurrency ?? batchOptions?.maxConcurrency;\n const batchSize =\n maxConcurrency && maxConcurrency > 0 ? maxConcurrency : inputs.length;\n const batchResults = [];\n for (let i = 0; i < actualInputs.length; i += batchSize) {\n const batchPromises = actualInputs\n .slice(i, i + batchSize)\n .map((actualInput, i) =>\n runnables[i].invoke(actualInput, optionsList[i])\n );\n const batchResult = await Promise.all(batchPromises);\n batchResults.push(batchResult);\n }\n return batchResults.flat();\n }\n\n async stream(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<IterableReadableStream<RunOutput>> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.stream(actualInput, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,iBAAb,cAIUA,aAAAA,SAA8B;CACtC,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"router.cjs","names":["Runnable","ensureConfig"],"sources":["../../src/runnables/router.ts"],"sourcesContent":["import { Runnable, type RunnableBatchOptions } from \"./base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\nexport type RouterInput = {\n key: string;\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any;\n};\n\n/**\n * A runnable that routes to a set of runnables based on Input['key'].\n * Returns the output of the selected runnable.\n * @example\n * ```typescript\n * import { RouterRunnable, RunnableLambda } from \"@langchain/core/runnables\";\n *\n * const router = new RouterRunnable({\n * runnables: {\n * toUpperCase: RunnableLambda.from((text: string) => text.toUpperCase()),\n * reverseText: RunnableLambda.from((text: string) =>\n * text.split(\"\").reverse().join(\"\")\n * ),\n * },\n * });\n *\n * // Invoke the 'reverseText' runnable\n * const result1 = router.invoke({ key: \"reverseText\", input: \"Hello World\" });\n *\n * // \"dlroW olleH\"\n *\n * // Invoke the 'toUpperCase' runnable\n * const result2 = router.invoke({ key: \"toUpperCase\", input: \"Hello World\" });\n *\n * // \"HELLO WORLD\"\n * ```\n */\nexport class RouterRunnable<\n RunInput extends RouterInput,\n RunnableInput,\n RunOutput,\n> extends Runnable<RunInput, RunOutput> {\n static lc_name() {\n return \"RouterRunnable\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n\n constructor(fields: {\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n }) {\n super(fields);\n this.runnables = fields.runnables;\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunOutput> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.invoke(actualInput, ensureConfig(options));\n }\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions?: false }\n ): Promise<RunOutput[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions: true }\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]> {\n const keys = inputs.map((input) => input.key);\n const actualInputs = inputs.map((input) => input.input);\n const missingKey = keys.find((key) => this.runnables[key] === undefined);\n if (missingKey !== undefined) {\n throw new Error(`One or more keys do not have a corresponding runnable.`);\n }\n const runnables = keys.map((key) => this.runnables[key]);\n const optionsList = this._getOptionsList(options ?? {}, inputs.length);\n const maxConcurrency =\n optionsList[0]?.maxConcurrency ?? batchOptions?.maxConcurrency;\n const batchSize =\n maxConcurrency && maxConcurrency > 0 ? maxConcurrency : inputs.length;\n const batchResults = [];\n for (let i = 0; i < actualInputs.length; i += batchSize) {\n const batchPromises = actualInputs\n .slice(i, i + batchSize)\n .map((actualInput, i) =>\n runnables[i].invoke(actualInput, optionsList[i])\n );\n const batchResult = await Promise.all(batchPromises);\n batchResults.push(batchResult);\n }\n return batchResults.flat();\n }\n\n async stream(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<IterableReadableStream<RunOutput>> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.stream(actualInput, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,iBAAb,cAIUA,aAAAA,SAA8B;CACtC,OAAO,UAAU;EACf,OAAO;CACT;CAEA,eAAe,CAAC,kBAAkB,WAAW;CAE7C,kBAAkB;CAElB;CAEA,YAAY,QAET;EACD,MAAM,MAAM;EACZ,KAAK,YAAY,OAAO;CAC1B;CAEA,MAAM,OACJ,OACA,SACoB;EACpB,MAAM,EAAE,KAAK,OAAO,gBAAgB;EACpC,MAAM,WAAW,KAAK,UAAU;EAChC,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MAAM,oCAAoC,IAAI,GAAG;EAE7D,OAAO,SAAS,OAAO,aAAaC,eAAAA,aAAa,OAAO,CAAC;CAC3D;CAoBA,MAAM,MACJ,QACA,SACA,cACgC;EAChC,MAAM,OAAO,OAAO,KAAK,UAAU,MAAM,GAAG;EAC5C,MAAM,eAAe,OAAO,KAAK,UAAU,MAAM,KAAK;EAEtD,IADmB,KAAK,MAAM,QAAQ,KAAK,UAAU,SAAS,KAAA,CACjD,MAAM,KAAA,GACjB,MAAM,IAAI,MAAM,wDAAwD;EAE1E,MAAM,YAAY,KAAK,KAAK,QAAQ,KAAK,UAAU,IAAI;EACvD,MAAM,cAAc,KAAK,gBAAgB,WAAW,CAAC,GAAG,OAAO,MAAM;EACrE,MAAM,iBACJ,YAAY,EAAE,EAAE,kBAAkB,cAAc;EAClD,MAAM,YACJ,kBAAkB,iBAAiB,IAAI,iBAAiB,OAAO;EACjE,MAAM,eAAe,CAAC;EACtB,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK,WAAW;GACvD,MAAM,gBAAgB,aACnB,MAAM,GAAG,IAAI,SAAS,CAAC,CACvB,KAAK,aAAa,MACjB,UAAU,EAAE,CAAC,OAAO,aAAa,YAAY,EAAE,CACjD;GACF,MAAM,cAAc,MAAM,QAAQ,IAAI,aAAa;GACnD,aAAa,KAAK,WAAW;EAC/B;EACA,OAAO,aAAa,KAAK;CAC3B;CAEA,MAAM,OACJ,OACA,SAC4C;EAC5C,MAAM,EAAE,KAAK,OAAO,gBAAgB;EACpC,MAAM,WAAW,KAAK,UAAU;EAChC,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MAAM,oCAAoC,IAAI,GAAG;EAE7D,OAAO,SAAS,OAAO,aAAa,OAAO;CAC7C;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RunnableBatchOptions, RunnableConfig } from "./types.cjs";
|
|
2
|
+
import "./config.cjs";
|
|
2
3
|
import { IterableReadableStream } from "../utils/stream.cjs";
|
|
3
4
|
import { Runnable } from "./base.cjs";
|
|
4
|
-
|
|
5
5
|
//#region src/runnables/router.d.ts
|
|
6
6
|
type RouterInput = {
|
|
7
7
|
key: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.cts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":";;;;;KAIY
|
|
1
|
+
{"version":3,"file":"router.d.cts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":";;;;;KAIY;EACV;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BW,eACX,iBAAiB,aACjB,eACA,mBACQ,SAAS,UAAU;SACpB;EAIP;EAEA;EAEA,WAAW,eAAe,SAAS,eAAe;EAElD,YAAY;IACV,WAAW,eAAe,SAAS,eAAe;;EAM9C,OACJ,OAAO,UACP,UAAU,QAAQ,kBACjB,QAAQ;EASL,MACJ,QAAQ,YACR,UAAU,QAAQ,kBAAkB,QAAQ,mBAC5C,eAAe;IAAyB;MACvC,QAAQ;EAEL,MACJ,QAAQ,YACR,UAAU,QAAQ,kBAAkB,QAAQ,mBAC5C,eAAe;IAAyB;MACvC,SAAS,YAAY;EAElB,MACJ,QAAQ,YACR,UAAU,QAAQ,kBAAkB,QAAQ,mBAC5C,eAAe,uBACd,SAAS,YAAY;EAgClB,OACJ,OAAO,UACP,UAAU,QAAQ,kBACjB,QAAQ,uBAAuB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RunnableBatchOptions, RunnableConfig } from "./types.js";
|
|
2
|
+
import "./config.js";
|
|
2
3
|
import { IterableReadableStream } from "../utils/stream.js";
|
|
3
4
|
import { Runnable } from "./base.js";
|
|
4
|
-
|
|
5
5
|
//#region src/runnables/router.d.ts
|
|
6
6
|
type RouterInput = {
|
|
7
7
|
key: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":";;;;;KAIY
|
|
1
|
+
{"version":3,"file":"router.d.ts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":";;;;;KAIY;EACV;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BW,eACX,iBAAiB,aACjB,eACA,mBACQ,SAAS,UAAU;SACpB;EAIP;EAEA;EAEA,WAAW,eAAe,SAAS,eAAe;EAElD,YAAY;IACV,WAAW,eAAe,SAAS,eAAe;;EAM9C,OACJ,OAAO,UACP,UAAU,QAAQ,kBACjB,QAAQ;EASL,MACJ,QAAQ,YACR,UAAU,QAAQ,kBAAkB,QAAQ,mBAC5C,eAAe;IAAyB;MACvC,QAAQ;EAEL,MACJ,QAAQ,YACR,UAAU,QAAQ,kBAAkB,QAAQ,mBAC5C,eAAe;IAAyB;MACvC,SAAS,YAAY;EAElB,MACJ,QAAQ,YACR,UAAU,QAAQ,kBAAkB,QAAQ,mBAC5C,eAAe,uBACd,SAAS,YAAY;EAgClB,OACJ,OAAO,UACP,UAAU,QAAQ,kBACjB,QAAQ,uBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","names":[],"sources":["../../src/runnables/router.ts"],"sourcesContent":["import { Runnable, type RunnableBatchOptions } from \"./base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\nexport type RouterInput = {\n key: string;\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any;\n};\n\n/**\n * A runnable that routes to a set of runnables based on Input['key'].\n * Returns the output of the selected runnable.\n * @example\n * ```typescript\n * import { RouterRunnable, RunnableLambda } from \"@langchain/core/runnables\";\n *\n * const router = new RouterRunnable({\n * runnables: {\n * toUpperCase: RunnableLambda.from((text: string) => text.toUpperCase()),\n * reverseText: RunnableLambda.from((text: string) =>\n * text.split(\"\").reverse().join(\"\")\n * ),\n * },\n * });\n *\n * // Invoke the 'reverseText' runnable\n * const result1 = router.invoke({ key: \"reverseText\", input: \"Hello World\" });\n *\n * // \"dlroW olleH\"\n *\n * // Invoke the 'toUpperCase' runnable\n * const result2 = router.invoke({ key: \"toUpperCase\", input: \"Hello World\" });\n *\n * // \"HELLO WORLD\"\n * ```\n */\nexport class RouterRunnable<\n RunInput extends RouterInput,\n RunnableInput,\n RunOutput,\n> extends Runnable<RunInput, RunOutput> {\n static lc_name() {\n return \"RouterRunnable\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n\n constructor(fields: {\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n }) {\n super(fields);\n this.runnables = fields.runnables;\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunOutput> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.invoke(actualInput, ensureConfig(options));\n }\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions?: false }\n ): Promise<RunOutput[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions: true }\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]> {\n const keys = inputs.map((input) => input.key);\n const actualInputs = inputs.map((input) => input.input);\n const missingKey = keys.find((key) => this.runnables[key] === undefined);\n if (missingKey !== undefined) {\n throw new Error(`One or more keys do not have a corresponding runnable.`);\n }\n const runnables = keys.map((key) => this.runnables[key]);\n const optionsList = this._getOptionsList(options ?? {}, inputs.length);\n const maxConcurrency =\n optionsList[0]?.maxConcurrency ?? batchOptions?.maxConcurrency;\n const batchSize =\n maxConcurrency && maxConcurrency > 0 ? maxConcurrency : inputs.length;\n const batchResults = [];\n for (let i = 0; i < actualInputs.length; i += batchSize) {\n const batchPromises = actualInputs\n .slice(i, i + batchSize)\n .map((actualInput, i) =>\n runnables[i].invoke(actualInput, optionsList[i])\n );\n const batchResult = await Promise.all(batchPromises);\n batchResults.push(batchResult);\n }\n return batchResults.flat();\n }\n\n async stream(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<IterableReadableStream<RunOutput>> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.stream(actualInput, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,iBAAb,cAIU,SAA8B;CACtC,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"router.js","names":[],"sources":["../../src/runnables/router.ts"],"sourcesContent":["import { Runnable, type RunnableBatchOptions } from \"./base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\nexport type RouterInput = {\n key: string;\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any;\n};\n\n/**\n * A runnable that routes to a set of runnables based on Input['key'].\n * Returns the output of the selected runnable.\n * @example\n * ```typescript\n * import { RouterRunnable, RunnableLambda } from \"@langchain/core/runnables\";\n *\n * const router = new RouterRunnable({\n * runnables: {\n * toUpperCase: RunnableLambda.from((text: string) => text.toUpperCase()),\n * reverseText: RunnableLambda.from((text: string) =>\n * text.split(\"\").reverse().join(\"\")\n * ),\n * },\n * });\n *\n * // Invoke the 'reverseText' runnable\n * const result1 = router.invoke({ key: \"reverseText\", input: \"Hello World\" });\n *\n * // \"dlroW olleH\"\n *\n * // Invoke the 'toUpperCase' runnable\n * const result2 = router.invoke({ key: \"toUpperCase\", input: \"Hello World\" });\n *\n * // \"HELLO WORLD\"\n * ```\n */\nexport class RouterRunnable<\n RunInput extends RouterInput,\n RunnableInput,\n RunOutput,\n> extends Runnable<RunInput, RunOutput> {\n static lc_name() {\n return \"RouterRunnable\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n\n constructor(fields: {\n runnables: Record<string, Runnable<RunnableInput, RunOutput>>;\n }) {\n super(fields);\n this.runnables = fields.runnables;\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunOutput> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.invoke(actualInput, ensureConfig(options));\n }\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions?: false }\n ): Promise<RunOutput[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions & { returnExceptions: true }\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]>;\n\n async batch(\n inputs: RunInput[],\n options?: Partial<RunnableConfig> | Partial<RunnableConfig>[],\n batchOptions?: RunnableBatchOptions\n ): Promise<(RunOutput | Error)[]> {\n const keys = inputs.map((input) => input.key);\n const actualInputs = inputs.map((input) => input.input);\n const missingKey = keys.find((key) => this.runnables[key] === undefined);\n if (missingKey !== undefined) {\n throw new Error(`One or more keys do not have a corresponding runnable.`);\n }\n const runnables = keys.map((key) => this.runnables[key]);\n const optionsList = this._getOptionsList(options ?? {}, inputs.length);\n const maxConcurrency =\n optionsList[0]?.maxConcurrency ?? batchOptions?.maxConcurrency;\n const batchSize =\n maxConcurrency && maxConcurrency > 0 ? maxConcurrency : inputs.length;\n const batchResults = [];\n for (let i = 0; i < actualInputs.length; i += batchSize) {\n const batchPromises = actualInputs\n .slice(i, i + batchSize)\n .map((actualInput, i) =>\n runnables[i].invoke(actualInput, optionsList[i])\n );\n const batchResult = await Promise.all(batchPromises);\n batchResults.push(batchResult);\n }\n return batchResults.flat();\n }\n\n async stream(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<IterableReadableStream<RunOutput>> {\n const { key, input: actualInput } = input;\n const runnable = this.runnables[key];\n if (runnable === undefined) {\n throw new Error(`No runnable associated with key \"${key}\".`);\n }\n return runnable.stream(actualInput, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,iBAAb,cAIU,SAA8B;CACtC,OAAO,UAAU;EACf,OAAO;CACT;CAEA,eAAe,CAAC,kBAAkB,WAAW;CAE7C,kBAAkB;CAElB;CAEA,YAAY,QAET;EACD,MAAM,MAAM;EACZ,KAAK,YAAY,OAAO;CAC1B;CAEA,MAAM,OACJ,OACA,SACoB;EACpB,MAAM,EAAE,KAAK,OAAO,gBAAgB;EACpC,MAAM,WAAW,KAAK,UAAU;EAChC,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MAAM,oCAAoC,IAAI,GAAG;EAE7D,OAAO,SAAS,OAAO,aAAa,aAAa,OAAO,CAAC;CAC3D;CAoBA,MAAM,MACJ,QACA,SACA,cACgC;EAChC,MAAM,OAAO,OAAO,KAAK,UAAU,MAAM,GAAG;EAC5C,MAAM,eAAe,OAAO,KAAK,UAAU,MAAM,KAAK;EAEtD,IADmB,KAAK,MAAM,QAAQ,KAAK,UAAU,SAAS,KAAA,CACjD,MAAM,KAAA,GACjB,MAAM,IAAI,MAAM,wDAAwD;EAE1E,MAAM,YAAY,KAAK,KAAK,QAAQ,KAAK,UAAU,IAAI;EACvD,MAAM,cAAc,KAAK,gBAAgB,WAAW,CAAC,GAAG,OAAO,MAAM;EACrE,MAAM,iBACJ,YAAY,EAAE,EAAE,kBAAkB,cAAc;EAClD,MAAM,YACJ,kBAAkB,iBAAiB,IAAI,iBAAiB,OAAO;EACjE,MAAM,eAAe,CAAC;EACtB,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK,WAAW;GACvD,MAAM,gBAAgB,aACnB,MAAM,GAAG,IAAI,SAAS,CAAC,CACvB,KAAK,aAAa,MACjB,UAAU,EAAE,CAAC,OAAO,aAAa,YAAY,EAAE,CACjD;GACF,MAAM,cAAc,MAAM,QAAQ,IAAI,aAAa;GACnD,aAAa,KAAK,WAAW;EAC/B;EACA,OAAO,aAAa,KAAK;CAC3B;CAEA,MAAM,OACJ,OACA,SAC4C;EAC5C,MAAM,EAAE,KAAK,OAAO,gBAAgB;EACpC,MAAM,WAAW,KAAK,UAAU;EAChC,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MAAM,oCAAoC,IAAI,GAAG;EAE7D,OAAO,SAAS,OAAO,aAAa,OAAO;CAC7C;AACF"}
|
|
@@ -2,10 +2,10 @@ import { SerializableInterface } from "../load/serializable.cjs";
|
|
|
2
2
|
import { InteropZodType } from "../utils/types/zod.cjs";
|
|
3
3
|
import { BaseCallbackConfig } from "../callbacks/manager.cjs";
|
|
4
4
|
import { IterableReadableStreamInterface } from "../types/_internal.cjs";
|
|
5
|
-
|
|
6
5
|
//#region src/runnables/types.d.ts
|
|
7
6
|
type RunnableBatchOptions = {
|
|
8
|
-
/** @deprecated Pass in via the standard runnable config object instead */
|
|
7
|
+
/** @deprecated Pass in via the standard runnable config object instead */
|
|
8
|
+
maxConcurrency?: number;
|
|
9
9
|
returnExceptions?: boolean;
|
|
10
10
|
};
|
|
11
11
|
type RunnableIOSchema = {
|