@langchain/core 1.1.31 → 1.1.32-dev-1773345797648
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/dist/callbacks/dispatch/index.d.ts +0 -1
- package/dist/callbacks/dispatch/index.d.ts.map +1 -1
- package/dist/callbacks/dispatch/web.d.ts +0 -1
- package/dist/callbacks/dispatch/web.d.ts.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 +5 -7
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +5 -8
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +5 -6
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +5 -7
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.d.ts +0 -1
- package/dist/language_models/llms.d.ts.map +1 -1
- package/dist/language_models/structured_output.d.ts +0 -1
- package/dist/language_models/structured_output.d.ts.map +1 -1
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +4 -3
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +4 -3
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/block_translators/google.cjs +16 -1
- package/dist/messages/block_translators/google.cjs.map +1 -1
- package/dist/messages/block_translators/google.js +16 -1
- package/dist/messages/block_translators/google.js.map +1 -1
- package/dist/output_parsers/base.d.ts +0 -1
- package/dist/output_parsers/base.d.ts.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 +3 -5
- 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 +3 -5
- 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/prompts/structured.d.ts +0 -1
- package/dist/prompts/structured.d.ts.map +1 -1
- package/dist/retrievers/index.d.ts +0 -1
- package/dist/retrievers/index.d.ts.map +1 -1
- package/dist/runnables/branch.d.ts +0 -1
- package/dist/runnables/branch.d.ts.map +1 -1
- package/dist/runnables/history.d.ts +0 -1
- package/dist/runnables/history.d.ts.map +1 -1
- package/dist/runnables/passthrough.d.ts +0 -1
- package/dist/runnables/passthrough.d.ts.map +1 -1
- package/dist/runnables/router.d.ts +0 -1
- package/dist/runnables/router.d.ts.map +1 -1
- package/dist/testing/fake_model_builder.cjs +69 -17
- package/dist/testing/fake_model_builder.cjs.map +1 -1
- package/dist/testing/fake_model_builder.d.cts +69 -18
- package/dist/testing/fake_model_builder.d.cts.map +1 -1
- package/dist/testing/fake_model_builder.d.ts +69 -18
- package/dist/testing/fake_model_builder.d.ts.map +1 -1
- package/dist/testing/fake_model_builder.js +69 -18
- package/dist/testing/fake_model_builder.js.map +1 -1
- package/dist/testing/index.cjs +2 -0
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +3 -2
- package/dist/testing/index.js.map +1 -1
- package/dist/tools/index.cjs +4 -0
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +22 -21
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts +22 -22
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +16 -9
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +16 -10
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.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.map +1 -1
- package/dist/utils/json_schema.js.map +1 -1
- package/dist/utils/types/index.d.cts +2 -2
- package/dist/utils/types/index.d.ts +2 -2
- package/dist/utils/types/zod.cjs +1 -1
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +141 -35
- package/dist/utils/types/zod.d.cts.map +1 -1
- package/dist/utils/types/zod.d.ts +141 -35
- package/dist/utils/types/zod.d.ts.map +1 -1
- package/dist/utils/types/zod.js +1 -1
- package/dist/utils/types/zod.js.map +1 -1
- package/package.json +4 -4
- package/agents.cjs +0 -1
- package/agents.d.cts +0 -1
- package/agents.d.ts +0 -1
- package/agents.js +0 -1
- package/caches.cjs +0 -1
- package/caches.d.cts +0 -1
- package/caches.d.ts +0 -1
- package/caches.js +0 -1
- package/callbacks/base.cjs +0 -1
- package/callbacks/base.d.cts +0 -1
- package/callbacks/base.d.ts +0 -1
- package/callbacks/base.js +0 -1
- package/callbacks/dispatch/web.cjs +0 -1
- package/callbacks/dispatch/web.d.cts +0 -1
- package/callbacks/dispatch/web.d.ts +0 -1
- package/callbacks/dispatch/web.js +0 -1
- package/callbacks/dispatch.cjs +0 -1
- package/callbacks/dispatch.d.cts +0 -1
- package/callbacks/dispatch.d.ts +0 -1
- package/callbacks/dispatch.js +0 -1
- package/callbacks/manager.cjs +0 -1
- package/callbacks/manager.d.cts +0 -1
- package/callbacks/manager.d.ts +0 -1
- package/callbacks/manager.js +0 -1
- package/callbacks/promises.cjs +0 -1
- package/callbacks/promises.d.cts +0 -1
- package/callbacks/promises.d.ts +0 -1
- package/callbacks/promises.js +0 -1
- package/chat_history.cjs +0 -1
- package/chat_history.d.cts +0 -1
- package/chat_history.d.ts +0 -1
- package/chat_history.js +0 -1
- package/context.cjs +0 -1
- package/context.d.cts +0 -1
- package/context.d.ts +0 -1
- package/context.js +0 -1
- package/document_loaders/base.cjs +0 -1
- package/document_loaders/base.d.cts +0 -1
- package/document_loaders/base.d.ts +0 -1
- package/document_loaders/base.js +0 -1
- package/document_loaders/langsmith.cjs +0 -1
- package/document_loaders/langsmith.d.cts +0 -1
- package/document_loaders/langsmith.d.ts +0 -1
- package/document_loaders/langsmith.js +0 -1
- package/documents.cjs +0 -1
- package/documents.d.cts +0 -1
- package/documents.d.ts +0 -1
- package/documents.js +0 -1
- package/embeddings.cjs +0 -1
- package/embeddings.d.cts +0 -1
- package/embeddings.d.ts +0 -1
- package/embeddings.js +0 -1
- package/errors.cjs +0 -1
- package/errors.d.cts +0 -1
- package/errors.d.ts +0 -1
- package/errors.js +0 -1
- package/example_selectors.cjs +0 -1
- package/example_selectors.d.cts +0 -1
- package/example_selectors.d.ts +0 -1
- package/example_selectors.js +0 -1
- package/indexing.cjs +0 -1
- package/indexing.d.cts +0 -1
- package/indexing.d.ts +0 -1
- package/indexing.js +0 -1
- package/language_models/base.cjs +0 -1
- package/language_models/base.d.cts +0 -1
- package/language_models/base.d.ts +0 -1
- package/language_models/base.js +0 -1
- package/language_models/chat_models.cjs +0 -1
- package/language_models/chat_models.d.cts +0 -1
- package/language_models/chat_models.d.ts +0 -1
- package/language_models/chat_models.js +0 -1
- package/language_models/llms.cjs +0 -1
- package/language_models/llms.d.cts +0 -1
- package/language_models/llms.d.ts +0 -1
- package/language_models/llms.js +0 -1
- package/language_models/profile.cjs +0 -1
- package/language_models/profile.d.cts +0 -1
- package/language_models/profile.d.ts +0 -1
- package/language_models/profile.js +0 -1
- package/language_models/structured_output.cjs +0 -1
- package/language_models/structured_output.d.cts +0 -1
- package/language_models/structured_output.d.ts +0 -1
- package/language_models/structured_output.js +0 -1
- package/load/serializable.cjs +0 -1
- package/load/serializable.d.cts +0 -1
- package/load/serializable.d.ts +0 -1
- package/load/serializable.js +0 -1
- package/load.cjs +0 -1
- package/load.d.cts +0 -1
- package/load.d.ts +0 -1
- package/load.js +0 -1
- package/memory.cjs +0 -1
- package/memory.d.cts +0 -1
- package/memory.d.ts +0 -1
- package/memory.js +0 -1
- package/messages/tool.cjs +0 -1
- package/messages/tool.d.cts +0 -1
- package/messages/tool.d.ts +0 -1
- package/messages/tool.js +0 -1
- package/messages.cjs +0 -1
- package/messages.d.cts +0 -1
- package/messages.d.ts +0 -1
- package/messages.js +0 -1
- package/output_parsers/openai_functions.cjs +0 -1
- package/output_parsers/openai_functions.d.cts +0 -1
- package/output_parsers/openai_functions.d.ts +0 -1
- package/output_parsers/openai_functions.js +0 -1
- package/output_parsers/openai_tools.cjs +0 -1
- package/output_parsers/openai_tools.d.cts +0 -1
- package/output_parsers/openai_tools.d.ts +0 -1
- package/output_parsers/openai_tools.js +0 -1
- package/output_parsers.cjs +0 -1
- package/output_parsers.d.cts +0 -1
- package/output_parsers.d.ts +0 -1
- package/output_parsers.js +0 -1
- package/outputs.cjs +0 -1
- package/outputs.d.cts +0 -1
- package/outputs.d.ts +0 -1
- package/outputs.js +0 -1
- package/prompt_values.cjs +0 -1
- package/prompt_values.d.cts +0 -1
- package/prompt_values.d.ts +0 -1
- package/prompt_values.js +0 -1
- package/prompts.cjs +0 -1
- package/prompts.d.cts +0 -1
- package/prompts.d.ts +0 -1
- package/prompts.js +0 -1
- package/retrievers/document_compressors.cjs +0 -1
- package/retrievers/document_compressors.d.cts +0 -1
- package/retrievers/document_compressors.d.ts +0 -1
- package/retrievers/document_compressors.js +0 -1
- package/retrievers.cjs +0 -1
- package/retrievers.d.cts +0 -1
- package/retrievers.d.ts +0 -1
- package/retrievers.js +0 -1
- package/runnables/graph.cjs +0 -1
- package/runnables/graph.d.cts +0 -1
- package/runnables/graph.d.ts +0 -1
- package/runnables/graph.js +0 -1
- package/runnables.cjs +0 -1
- package/runnables.d.cts +0 -1
- package/runnables.d.ts +0 -1
- package/runnables.js +0 -1
- package/singletons.cjs +0 -1
- package/singletons.d.cts +0 -1
- package/singletons.d.ts +0 -1
- package/singletons.js +0 -1
- package/stores.cjs +0 -1
- package/stores.d.cts +0 -1
- package/stores.d.ts +0 -1
- package/stores.js +0 -1
- package/structured_query.cjs +0 -1
- package/structured_query.d.cts +0 -1
- package/structured_query.d.ts +0 -1
- package/structured_query.js +0 -1
- package/tools.cjs +0 -1
- package/tools.d.cts +0 -1
- package/tools.d.ts +0 -1
- package/tools.js +0 -1
- package/tracers/base.cjs +0 -1
- package/tracers/base.d.cts +0 -1
- package/tracers/base.d.ts +0 -1
- package/tracers/base.js +0 -1
- package/tracers/console.cjs +0 -1
- package/tracers/console.d.cts +0 -1
- package/tracers/console.d.ts +0 -1
- package/tracers/console.js +0 -1
- package/tracers/log_stream.cjs +0 -1
- package/tracers/log_stream.d.cts +0 -1
- package/tracers/log_stream.d.ts +0 -1
- package/tracers/log_stream.js +0 -1
- package/tracers/run_collector.cjs +0 -1
- package/tracers/run_collector.d.cts +0 -1
- package/tracers/run_collector.d.ts +0 -1
- package/tracers/run_collector.js +0 -1
- package/tracers/tracer_langchain.cjs +0 -1
- package/tracers/tracer_langchain.d.cts +0 -1
- package/tracers/tracer_langchain.d.ts +0 -1
- package/tracers/tracer_langchain.js +0 -1
- package/types/stream.cjs +0 -1
- package/types/stream.d.cts +0 -1
- package/types/stream.d.ts +0 -1
- package/types/stream.js +0 -1
- package/utils/async_caller.cjs +0 -1
- package/utils/async_caller.d.cts +0 -1
- package/utils/async_caller.d.ts +0 -1
- package/utils/async_caller.js +0 -1
- package/utils/chunk_array.cjs +0 -1
- package/utils/chunk_array.d.cts +0 -1
- package/utils/chunk_array.d.ts +0 -1
- package/utils/chunk_array.js +0 -1
- package/utils/context.cjs +0 -1
- package/utils/context.d.cts +0 -1
- package/utils/context.d.ts +0 -1
- package/utils/context.js +0 -1
- package/utils/env.cjs +0 -1
- package/utils/env.d.cts +0 -1
- package/utils/env.d.ts +0 -1
- package/utils/env.js +0 -1
- package/utils/event_source_parse.cjs +0 -1
- package/utils/event_source_parse.d.cts +0 -1
- package/utils/event_source_parse.d.ts +0 -1
- package/utils/event_source_parse.js +0 -1
- package/utils/format.cjs +0 -1
- package/utils/format.d.cts +0 -1
- package/utils/format.d.ts +0 -1
- package/utils/format.js +0 -1
- package/utils/function_calling.cjs +0 -1
- package/utils/function_calling.d.cts +0 -1
- package/utils/function_calling.d.ts +0 -1
- package/utils/function_calling.js +0 -1
- package/utils/hash.cjs +0 -1
- package/utils/hash.d.cts +0 -1
- package/utils/hash.d.ts +0 -1
- package/utils/hash.js +0 -1
- package/utils/json_patch.cjs +0 -1
- package/utils/json_patch.d.cts +0 -1
- package/utils/json_patch.d.ts +0 -1
- package/utils/json_patch.js +0 -1
- package/utils/json_schema.cjs +0 -1
- package/utils/json_schema.d.cts +0 -1
- package/utils/json_schema.d.ts +0 -1
- package/utils/json_schema.js +0 -1
- package/utils/math.cjs +0 -1
- package/utils/math.d.cts +0 -1
- package/utils/math.d.ts +0 -1
- package/utils/math.js +0 -1
- package/utils/ssrf.cjs +0 -1
- package/utils/ssrf.d.cts +0 -1
- package/utils/ssrf.d.ts +0 -1
- package/utils/ssrf.js +0 -1
- package/utils/standard_schema.cjs +0 -1
- package/utils/standard_schema.d.cts +0 -1
- package/utils/standard_schema.d.ts +0 -1
- package/utils/standard_schema.js +0 -1
- package/utils/stream.cjs +0 -1
- package/utils/stream.d.cts +0 -1
- package/utils/stream.d.ts +0 -1
- package/utils/stream.js +0 -1
- package/utils/testing.cjs +0 -1
- package/utils/testing.d.cts +0 -1
- package/utils/testing.d.ts +0 -1
- package/utils/testing.js +0 -1
- package/utils/tiktoken.cjs +0 -1
- package/utils/tiktoken.d.cts +0 -1
- package/utils/tiktoken.d.ts +0 -1
- package/utils/tiktoken.js +0 -1
- package/utils/types.cjs +0 -1
- package/utils/types.d.cts +0 -1
- package/utils/types.d.ts +0 -1
- package/utils/types.js +0 -1
- package/vectorstores.cjs +0 -1
- package/vectorstores.d.cts +0 -1
- package/vectorstores.d.ts +0 -1
- package/vectorstores.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.cjs","names":["iife","_isContentBlock","_isString","_isObject"],"sources":["../../../src/messages/block_translators/google.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { iife, _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content = iife(() => {\n if (typeof message.content === \"string\") {\n if (message.additional_kwargs.originalTextContentBlock) {\n return [\n {\n ...message.additional_kwargs.originalTextContentBlock,\n type: \"text\",\n },\n ];\n } else {\n return [{ type: \"text\", text: message.content }];\n }\n } else {\n return message.content;\n }\n });\n for (const block of content) {\n const contentBlockBase: ContentBlock.Standard = iife(() => {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n return {\n type: \"text\",\n text: block.text,\n };\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n return {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n return {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n } else if (_isContentBlock(block, \"functionResponse\")) {\n return { type: \"non_standard\", value: block };\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n return {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n } else if (_isContentBlock(block, \"executableCode\")) {\n return { type: \"non_standard\", value: block };\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n return { type: \"non_standard\", value: block };\n }\n return { type: \"non_standard\", value: block };\n });\n const contentBlock: ContentBlock.Standard = iife(() => {\n if (\"thought\" in block && block.thought) {\n const reasoning: string =\n contentBlockBase.type === \"text\" ? contentBlockBase.text : \"\";\n return {\n type: \"reasoning\",\n reasoning,\n reasoningContentBlock: contentBlockBase,\n };\n } else {\n return contentBlockBase;\n }\n });\n\n const ret: ContentBlock.Standard = {\n thought: block.thought,\n thoughtSignature: block.thoughtSignature,\n partMetadata: block.partMetadata,\n ...contentBlock,\n };\n for (const attribute in ret) {\n if (ret[attribute] === undefined) {\n delete ret[attribute];\n }\n }\n\n yield ret;\n continue;\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACP,SAC8B;CAC9B,UAAU,iBAAkD;EAC1D,MAAM,UAAUA,yBAAW;AACzB,OAAI,OAAO,QAAQ,YAAY,SAC7B,KAAI,QAAQ,kBAAkB,yBAC5B,QAAO,CACL;IACE,GAAG,QAAQ,kBAAkB;IAC7B,MAAM;IACP,CACF;OAED,QAAO,CAAC;IAAE,MAAM;IAAQ,MAAM,QAAQ;IAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"google.cjs","names":["iife","_isContentBlock","_isString","_isObject"],"sources":["../../../src/messages/block_translators/google.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { iife, _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content = iife(() => {\n if (typeof message.content === \"string\") {\n if (message.additional_kwargs.originalTextContentBlock) {\n return [\n {\n ...message.additional_kwargs.originalTextContentBlock,\n type: \"text\",\n },\n ];\n } else {\n return [{ type: \"text\", text: message.content }];\n }\n } else {\n const originalBlock = message.additional_kwargs\n ?.originalTextContentBlock as Record<string, unknown> | undefined;\n if (originalBlock?.thoughtSignature) {\n // During streaming with thinking models, thoughtSignature arrives in\n // a metadata-only chunk and is stored in originalTextContentBlock.\n // When content is an array (due to thinking parts), this signature\n // isn't carried into the content array by mergeContent().\n // Merge it into the last non-thinking text block.\n const hasSignatureInContent = message.content.some(\n (b: Record<string, unknown>) => \"thoughtSignature\" in b\n );\n if (!hasSignatureInContent) {\n const result = [...message.content];\n for (let i = result.length - 1; i >= 0; i--) {\n const block = result[i] as Record<string, unknown>;\n if (block.type === \"text\" && !block.thought) {\n block.thoughtSignature = originalBlock.thoughtSignature;\n return result;\n }\n }\n }\n }\n return message.content;\n }\n });\n for (const block of content) {\n const contentBlockBase: ContentBlock.Standard = iife(() => {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n return {\n type: \"text\",\n text: block.text,\n };\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n return {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n return {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n } else if (_isContentBlock(block, \"functionResponse\")) {\n return { type: \"non_standard\", value: block };\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n return {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n } else if (_isContentBlock(block, \"executableCode\")) {\n return { type: \"non_standard\", value: block };\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n return { type: \"non_standard\", value: block };\n }\n return { type: \"non_standard\", value: block };\n });\n const contentBlock: ContentBlock.Standard = iife(() => {\n if (\"thought\" in block && block.thought) {\n const reasoning: string =\n contentBlockBase.type === \"text\" ? contentBlockBase.text : \"\";\n return {\n type: \"reasoning\",\n reasoning,\n reasoningContentBlock: contentBlockBase,\n };\n } else {\n return contentBlockBase;\n }\n });\n\n const ret: ContentBlock.Standard = {\n thought: block.thought,\n thoughtSignature: block.thoughtSignature,\n partMetadata: block.partMetadata,\n ...contentBlock,\n };\n for (const attribute in ret) {\n if (ret[attribute] === undefined) {\n delete ret[attribute];\n }\n }\n\n yield ret;\n continue;\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACP,SAC8B;CAC9B,UAAU,iBAAkD;EAC1D,MAAM,UAAUA,yBAAW;AACzB,OAAI,OAAO,QAAQ,YAAY,SAC7B,KAAI,QAAQ,kBAAkB,yBAC5B,QAAO,CACL;IACE,GAAG,QAAQ,kBAAkB;IAC7B,MAAM;IACP,CACF;OAED,QAAO,CAAC;IAAE,MAAM;IAAQ,MAAM,QAAQ;IAAS,CAAC;QAE7C;IACL,MAAM,gBAAgB,QAAQ,mBAC1B;AACJ,QAAI,eAAe,kBASjB;SAAI,CAH0B,QAAQ,QAAQ,MAC3C,MAA+B,sBAAsB,EACvD,EAC2B;MAC1B,MAAM,SAAS,CAAC,GAAG,QAAQ,QAAQ;AACnC,WAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;OAC3C,MAAM,QAAQ,OAAO;AACrB,WAAI,MAAM,SAAS,UAAU,C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AiB,SAAS,SAAS,iBAAiB,OAAO;KAI3D,uBAAuB;KACxB;QAED,QAAO;KAET;GAEF,MAAM,MAA6B;IACjC,SAAS,MAAM;IACf,kBAAkB,MAAM;IACxB,cAAc,MAAM;IACpB,GAAG;IACJ;AACD,QAAK,MAAM,aAAa,IACtB,KAAI,IAAI,eAAe,OACrB,QAAO,IAAI;AAIf,SAAM;;;AAIV,QAAO,MAAM,KAAK,gBAAgB,CAAC;;AAGrC,MAAa,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;CACxB"}
|
|
@@ -12,7 +12,22 @@ function convertToV1FromChatGoogleMessage(message) {
|
|
|
12
12
|
type: "text",
|
|
13
13
|
text: message.content
|
|
14
14
|
}];
|
|
15
|
-
else
|
|
15
|
+
else {
|
|
16
|
+
const originalBlock = message.additional_kwargs?.originalTextContentBlock;
|
|
17
|
+
if (originalBlock?.thoughtSignature) {
|
|
18
|
+
if (!message.content.some((b) => "thoughtSignature" in b)) {
|
|
19
|
+
const result = [...message.content];
|
|
20
|
+
for (let i = result.length - 1; i >= 0; i--) {
|
|
21
|
+
const block = result[i];
|
|
22
|
+
if (block.type === "text" && !block.thought) {
|
|
23
|
+
block.thoughtSignature = originalBlock.thoughtSignature;
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return message.content;
|
|
30
|
+
}
|
|
16
31
|
});
|
|
17
32
|
for (const block of content) {
|
|
18
33
|
const contentBlockBase = iife(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.js","names":[],"sources":["../../../src/messages/block_translators/google.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { iife, _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content = iife(() => {\n if (typeof message.content === \"string\") {\n if (message.additional_kwargs.originalTextContentBlock) {\n return [\n {\n ...message.additional_kwargs.originalTextContentBlock,\n type: \"text\",\n },\n ];\n } else {\n return [{ type: \"text\", text: message.content }];\n }\n } else {\n return message.content;\n }\n });\n for (const block of content) {\n const contentBlockBase: ContentBlock.Standard = iife(() => {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n return {\n type: \"text\",\n text: block.text,\n };\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n return {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n return {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n } else if (_isContentBlock(block, \"functionResponse\")) {\n return { type: \"non_standard\", value: block };\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n return {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n } else if (_isContentBlock(block, \"executableCode\")) {\n return { type: \"non_standard\", value: block };\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n return { type: \"non_standard\", value: block };\n }\n return { type: \"non_standard\", value: block };\n });\n const contentBlock: ContentBlock.Standard = iife(() => {\n if (\"thought\" in block && block.thought) {\n const reasoning: string =\n contentBlockBase.type === \"text\" ? contentBlockBase.text : \"\";\n return {\n type: \"reasoning\",\n reasoning,\n reasoningContentBlock: contentBlockBase,\n };\n } else {\n return contentBlockBase;\n }\n });\n\n const ret: ContentBlock.Standard = {\n thought: block.thought,\n thoughtSignature: block.thoughtSignature,\n partMetadata: block.partMetadata,\n ...contentBlock,\n };\n for (const attribute in ret) {\n if (ret[attribute] === undefined) {\n delete ret[attribute];\n }\n }\n\n yield ret;\n continue;\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACP,SAC8B;CAC9B,UAAU,iBAAkD;EAC1D,MAAM,UAAU,WAAW;AACzB,OAAI,OAAO,QAAQ,YAAY,SAC7B,KAAI,QAAQ,kBAAkB,yBAC5B,QAAO,CACL;IACE,GAAG,QAAQ,kBAAkB;IAC7B,MAAM;IACP,CACF;OAED,QAAO,CAAC;IAAE,MAAM;IAAQ,MAAM,QAAQ;IAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"google.js","names":[],"sources":["../../../src/messages/block_translators/google.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { iife, _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content = iife(() => {\n if (typeof message.content === \"string\") {\n if (message.additional_kwargs.originalTextContentBlock) {\n return [\n {\n ...message.additional_kwargs.originalTextContentBlock,\n type: \"text\",\n },\n ];\n } else {\n return [{ type: \"text\", text: message.content }];\n }\n } else {\n const originalBlock = message.additional_kwargs\n ?.originalTextContentBlock as Record<string, unknown> | undefined;\n if (originalBlock?.thoughtSignature) {\n // During streaming with thinking models, thoughtSignature arrives in\n // a metadata-only chunk and is stored in originalTextContentBlock.\n // When content is an array (due to thinking parts), this signature\n // isn't carried into the content array by mergeContent().\n // Merge it into the last non-thinking text block.\n const hasSignatureInContent = message.content.some(\n (b: Record<string, unknown>) => \"thoughtSignature\" in b\n );\n if (!hasSignatureInContent) {\n const result = [...message.content];\n for (let i = result.length - 1; i >= 0; i--) {\n const block = result[i] as Record<string, unknown>;\n if (block.type === \"text\" && !block.thought) {\n block.thoughtSignature = originalBlock.thoughtSignature;\n return result;\n }\n }\n }\n }\n return message.content;\n }\n });\n for (const block of content) {\n const contentBlockBase: ContentBlock.Standard = iife(() => {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n return {\n type: \"text\",\n text: block.text,\n };\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n return {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n return {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n } else if (_isContentBlock(block, \"functionResponse\")) {\n return { type: \"non_standard\", value: block };\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n return {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n } else if (_isContentBlock(block, \"executableCode\")) {\n return { type: \"non_standard\", value: block };\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n return { type: \"non_standard\", value: block };\n }\n return { type: \"non_standard\", value: block };\n });\n const contentBlock: ContentBlock.Standard = iife(() => {\n if (\"thought\" in block && block.thought) {\n const reasoning: string =\n contentBlockBase.type === \"text\" ? contentBlockBase.text : \"\";\n return {\n type: \"reasoning\",\n reasoning,\n reasoningContentBlock: contentBlockBase,\n };\n } else {\n return contentBlockBase;\n }\n });\n\n const ret: ContentBlock.Standard = {\n thought: block.thought,\n thoughtSignature: block.thoughtSignature,\n partMetadata: block.partMetadata,\n ...contentBlock,\n };\n for (const attribute in ret) {\n if (ret[attribute] === undefined) {\n delete ret[attribute];\n }\n }\n\n yield ret;\n continue;\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACP,SAC8B;CAC9B,UAAU,iBAAkD;EAC1D,MAAM,UAAU,WAAW;AACzB,OAAI,OAAO,QAAQ,YAAY,SAC7B,KAAI,QAAQ,kBAAkB,yBAC5B,QAAO,CACL;IACE,GAAG,QAAQ,kBAAkB;IAC7B,MAAM;IACP,CACF;OAED,QAAO,CAAC;IAAE,MAAM;IAAQ,MAAM,QAAQ;IAAS,CAAC;QAE7C;IACL,MAAM,gBAAgB,QAAQ,mBAC1B;AACJ,QAAI,eAAe,kBASjB;SAAI,CAH0B,QAAQ,QAAQ,MAC3C,MAA+B,sBAAsB,EACvD,EAC2B;MAC1B,MAAM,SAAS,CAAC,GAAG,QAAQ,QAAQ;AACnC,WAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;OAC3C,MAAM,QAAQ,OAAO;AACrB,WAAI,MAAM,SAAS,UAAU,CAAC,MAAM,SAAS;AAC3C,cAAM,mBAAmB,cAAc;AACvC,eAAO;;;;;AAKf,WAAO,QAAQ;;IAEjB;AACF,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,mBAA0C,WAAW;AACzD,QAAI,gBAAgB,OAAO,OAAO,IAAI,UAAU,MAAM,KAAK,CACzD,QAAO;KACL,MAAM;KACN,MAAM,MAAM;KACb;aAED,gBAAgB,OAAO,aAAa,IACpC,UAAU,MAAM,WAAW,IAC3B,UAAU,MAAM,WAAW,SAAS,IACpC,UAAU,MAAM,WAAW,KAAK,CAEhC,QAAO;KACL,MAAM;KACN,UAAU,MAAM,WAAW;KAC3B,MAAM,MAAM,WAAW;KACxB;aAED,gBAAgB,OAAO,eAAe,IACtC,UAAU,MAAM,aAAa,IAC7B,UAAU,MAAM,aAAa,KAAK,IAClC,UAAU,MAAM,aAAa,KAAK,CAElC,QAAO;KACL,MAAM;KACN,IAAI,QAAQ;KACZ,MAAM,MAAM,aAAa;KACzB,MAAM,MAAM,aAAa;KAC1B;aACQ,gBAAgB,OAAO,mBAAmB,CACnD,QAAO;KAAE,MAAM;KAAgB,OAAO;KAAO;aAE7C,gBAAgB,OAAO,WAAW,IAClC,UAAU,MAAM,SAAS,IACzB,UAAU,MAAM,SAAS,SAAS,IAClC,UAAU,MAAM,SAAS,QAAQ,CAEjC,QAAO;KACL,MAAM;KACN,UAAU,MAAM,SAAS;KACzB,QAAQ,MAAM,SAAS;KACxB;aACQ,gBAAgB,OAAO,iBAAiB,CACjD,QAAO;KAAE,MAAM;KAAgB,OAAO;KAAO;aACpC,gBAAgB,OAAO,sBAAsB,CACtD,QAAO;KAAE,MAAM;KAAgB,OAAO;KAAO;AAE/C,WAAO;KAAE,MAAM;KAAgB,OAAO;KAAO;KAC7C;GACF,MAAM,eAAsC,WAAW;AACrD,QAAI,aAAa,SAAS,MAAM,QAG9B,QAAO;KACL,MAAM;KACN,WAHA,iBAAiB,SAAS,SAAS,iBAAiB,OAAO;KAI3D,uBAAuB;KACxB;QAED,QAAO;KAET;GAEF,MAAM,MAA6B;IACjC,SAAS,MAAM;IACf,kBAAkB,MAAM;IACxB,cAAc,MAAM;IACpB,GAAG;IACJ;AACD,QAAK,MAAM,aAAa,IACtB,KAAI,IAAI,eAAe,OACrB,QAAO,IAAI;AAIf,SAAM;;;AAIV,QAAO,MAAM,KAAK,gBAAgB,CAAC;;AAGrC,MAAa,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;CACxB"}
|
|
@@ -3,7 +3,6 @@ import { BaseMessage } from "../messages/base.js";
|
|
|
3
3
|
import { ChatGeneration, Generation } from "../outputs.js";
|
|
4
4
|
import { Callbacks } from "../callbacks/manager.js";
|
|
5
5
|
import { RunnableConfig } from "../runnables/types.js";
|
|
6
|
-
import "../runnables/config.js";
|
|
7
6
|
import { Runnable } from "../runnables/base.js";
|
|
8
7
|
import { BasePromptValueInterface } from "../prompt_values.js";
|
|
9
8
|
import "../messages/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","names":[],"sources":["../../src/output_parsers/base.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.d.ts","names":[],"sources":["../../src/output_parsers/base.ts"],"mappings":";;;;;;;;;;;;;;UAWiB,yBAAA;AAAjB;;;;;AAAA,uBAOsB,mBAAA,sBAAyC,QAAA,UACpD,WAAA,EACT,CAAA;EAFuC;;;;;;;;EAAA,SAY9B,WAAA,CACP,WAAA,EAAa,UAAA,KAAe,cAAA,IAC5B,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EAWI;;;;;;;;EADf,qBAAA,CACE,WAAA,EAAa,UAAA,KAAe,cAAA,IAC5B,OAAA,EAAS,wBAAA,EACT,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EAAA,UAID,oBAAA,CAAqB,OAAA,EAAS,WAAA;EAAA,UAM9B,2BAAA,CAA4B,OAAA,EAAS,YAAA;EAiB5C;;;;;;;;;;EAHG,MAAA,CACJ,KAAA,WAAgB,WAAA,EAChB,OAAA,GAAU,cAAA,GACT,OAAA,CAAQ,CAAA;AAAA;;;;uBA8BS,gBAAA,sBAEZ,mBAAA,CAAoB,CAAA;EAC5B,WAAA,CACE,WAAA,EAAa,UAAA,KAAe,cAAA,IAC5B,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EAlEI;;;;;;EAAA,SA4EN,KAAA,CAAM,IAAA,UAAc,SAAA,GAAY,SAAA,GAAY,OAAA,CAAQ,CAAA;EAEvD,eAAA,CACJ,IAAA,UACA,OAAA,EAAS,wBAAA,EACT,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EA/EA;;;;;;;;;;;EAAA,SA8FF,qBAAA,CAAsB,OAAA,GAAU,yBAAA;EAnEtC;;;EAwEH,KAAA,CAAA;AAAA;;;;;;;;;;;;;;;;;;;cAuBW,qBAAA,SAA8B,KAAA;EACzC,SAAA;EAEA,WAAA;EAEA,SAAA;EAEA,WAAA,CACE,OAAA,UACA,SAAA,WACA,WAAA,WACA,SAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.cjs","names":["parsePartialJson","OutputParserException","BaseCumulativeTransformOutputParser","isAIMessage","interopSafeParseAsync"],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z3.ZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z4.$ZodType<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(zodParsedResult.error?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;;AA8CA,SAAgB,cAEd,aACA,SACsB;AACtB,KAAI,YAAY,aAAa,OAC3B;CAEF,IAAI;AACJ,KAAI,SAAS,QACX,KAAI;AACF,iBAAeA,8BAAiB,YAAY,SAAS,aAAa,KAAK;SACjE;AACN;;KAGF,KAAI;AACF,iBAAe,KAAK,MAAM,YAAY,SAAS,UAAU;UAElD,GAAQ;AACf,QAAM,IAAIC,mCACR;GACE,aAAa,YAAY,SAAS,KAAK;GACvC;GACA,YAAY,SAAS;GACrB;GACA;GACA,UAAU,EAAE;GACb,CAAC,KAAK,KAAK,CACb;;CAIL,MAAM,iBAA2B;EAC/B,MAAM,YAAY,SAAS;EAC3B,MAAM;EACN,MAAM;EACP;AAED,KAAI,SAAS,SACX,gBAAe,KAAK,YAAY;AAGlC,QAAO;;AAGT,SAAgB,iCAAiC,UAAoB;AACnE,KAAI,SAAS,OAAO,OAClB,OAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAO;EACL,IAAI,SAAS;EACb,MAAM;EACN,UAAU;GACR,MAAM,SAAS;GACf,WAAW,KAAK,UAAU,SAAS,KAAK;GACzC;EACF;;AAGH,SAAgB,oBAEd,aACA,UACiB;AACjB,QAAO;EACL,MAAM,YAAY,UAAU;EAC5B,MAAM,YAAY,UAAU;EAC5B,IAAI,YAAY;EAChB,OAAO;EACP,MAAM;EACP;;;;;AAMH,IAAa,wBAAb,cAEUC,sDAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;;CAGT,WAAW;CAEX,eAAe;EAAC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AAI,KAAK,aACP,QAAO,KAAK,gBAAgB,eAAe,GAAG;AAKhD,SAHwB,MAAM,QAAQ,IACpC,eAAe,KAAK,UAAU,KAAK,gBAAgB,MAAM,CAAC,CAC3D"}
|
|
1
|
+
{"version":3,"file":"json_output_tools_parsers.cjs","names":["parsePartialJson","OutputParserException","BaseCumulativeTransformOutputParser","isAIMessage","interopSafeParseAsync"],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type { ZodV3Like, ZodV4Like } from \"../../utils/types/zod.js\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV3Like<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV4Like<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n )}\". Error: ${JSON.stringify((zodParsedResult.error as any)?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;;AA6CA,SAAgB,cAEd,aACA,SACsB;AACtB,KAAI,YAAY,aAAa,OAC3B;CAEF,IAAI;AACJ,KAAI,SAAS,QACX,KAAI;AACF,iBAAeA,8BAAiB,YAAY,SAAS,aAAa,KAAK;SACjE;AACN;;KAGF,KAAI;AACF,iBAAe,KAAK,MAAM,YAAY,SAAS,UAAU;UAElD,GAAQ;AACf,QAAM,IAAIC,mCACR;GACE,aAAa,YAAY,SAAS,KAAK;GACvC;GACA,YAAY,SAAS;GACrB;GACA;GACA,UAAU,EAAE;GACb,CAAC,KAAK,KAAK,CACb;;CAIL,MAAM,iBAA2B;EAC/B,MAAM,YAAY,SAAS;EAC3B,MAAM;EACN,MAAM;EACP;AAED,KAAI,SAAS,SACX,gBAAe,KAAK,YAAY;AAGlC,QAAO;;AAGT,SAAgB,iCAAiC,UAAoB;AACnE,KAAI,SAAS,OAAO,OAClB,OAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAO;EACL,IAAI,SAAS;EACb,MAAM;EACN,UAAU;GACR,MAAM,SAAS;GACf,WAAW,KAAK,UAAU,SAAS,KAAK;GACzC;EACF;;AAGH,SAAgB,oBAEd,aACA,UACiB;AACjB,QAAO;EACL,MAAM,YAAY,UAAU;EAC5B,MAAM,YAAY,UAAU;EAC5B,IAAI,YAAY;EAChB,OAAO;EACP,MAAM;EACP;;;;;AAMH,IAAa,wBAAb,cAEUC,sDAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;;CAGT,WAAW;CAEX,eAAe;EAAC;EAAa;EAAkB;EAAe;CAE9D,kBAAkB;CAElB,YAAY,QAAsC;AAChD,QAAM,OAAO;AACb,OAAK,WAAW,QAAQ,YA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AAK,gBAAgB,MAAM,CAAC,CAC3D"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { InvalidToolCall, ToolCall } from "../../messages/tool.cjs";
|
|
2
2
|
import { ChatGeneration, ChatGenerationChunk } from "../../outputs.cjs";
|
|
3
3
|
import { SerializableSchema } from "../../utils/standard_schema.cjs";
|
|
4
|
-
import { InteropZodType } from "../../utils/types/zod.cjs";
|
|
4
|
+
import { InteropZodType, ZodV3Like, ZodV4Like } from "../../utils/types/zod.cjs";
|
|
5
5
|
import { BaseCumulativeTransformOutputParser, BaseCumulativeTransformOutputParserInput } from "../transform.cjs";
|
|
6
|
-
import * as z3 from "zod/v3";
|
|
7
|
-
import * as z4 from "zod/v4/core";
|
|
8
6
|
|
|
9
7
|
//#region src/output_parsers/openai_tools/json_output_tools_parsers.d.ts
|
|
10
8
|
type ParsedToolCall = {
|
|
@@ -61,10 +59,10 @@ type JsonOutputKeyToolsParserParamsBase = {
|
|
|
61
59
|
returnSingle?: boolean;
|
|
62
60
|
} & JsonOutputToolsParserParams;
|
|
63
61
|
type JsonOutputKeyToolsParserParamsV3<T extends Record<string, any> = Record<string, any>> = {
|
|
64
|
-
zodSchema?:
|
|
62
|
+
zodSchema?: ZodV3Like<T>;
|
|
65
63
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
66
64
|
type JsonOutputKeyToolsParserParamsV4<T extends Record<string, any> = Record<string, any>> = {
|
|
67
|
-
zodSchema?:
|
|
65
|
+
zodSchema?: ZodV4Like<T, T>;
|
|
68
66
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
69
67
|
type JsonOutputKeyToolsParserParamsInterop<T extends Record<string, any> = Record<string, any>> = {
|
|
70
68
|
zodSchema?: InteropZodType<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.d.cts","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json_output_tools_pars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,IAAO,kCAAA;AAAA,KAE1B,qCAAA,WAEA,MAAA,gBAAsB,MAAA;EAC5B,SAAA,GAAY,cAAA,CAAe,CAAA;AAAA,IAAO,kCAAA;AAAA,KAE5B,0CAAA,WAEA,MAAA,gBAAsB,MAAA;EAEhC,kBAAA,GAAqB,kBAAA,CAAmB,CAAA;AAAA,IACtC,kCAAA;AAAA,KAGQ,8BAAA,WAEA,MAAA,gBAAsB,MAAA,iBAC9B,gCAAA,CAAiC,CAAA;;;;;cAMxB,wBAAA,WAED,MAAA,gBAAsB,MAAA,uBACxB,qBAAA,CAAsB,CAAA;EAAA,OACvB,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,QAAA;EAlIgC;EAqIhC,OAAA;EAnI4C;EAsI5C,YAAA;EAEA,SAAA,GAAY,cAAA,CAAe,CAAA;EAE3B,kBAAA,GAAqB,kBAAA,CAAmB,CAAA;EAExC,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,CAAA;EAErD,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,CAAA;EAErD,WAAA,CAAY,MAAA,EAAQ,qCAAA,CAAsC,CAAA;EAAA,UAoB1C,eAAA,CAAgB,MAAA,YAAkB,OAAA,CAAQ,CAAA;EAoCpD,kBAAA,CAAmB,WAAA,EAAa,cAAA,KAAmB,OAAA;EAuBnD,WAAA,CAAY,WAAA,EAAa,cAAA,KAAmB,OAAA;AAAA"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { InvalidToolCall, ToolCall } from "../../messages/tool.js";
|
|
2
2
|
import { ChatGeneration, ChatGenerationChunk } from "../../outputs.js";
|
|
3
3
|
import { SerializableSchema } from "../../utils/standard_schema.js";
|
|
4
|
-
import { InteropZodType } from "../../utils/types/zod.js";
|
|
4
|
+
import { InteropZodType, ZodV3Like, ZodV4Like } from "../../utils/types/zod.js";
|
|
5
5
|
import { BaseCumulativeTransformOutputParser, BaseCumulativeTransformOutputParserInput } from "../transform.js";
|
|
6
|
-
import * as z3 from "zod/v3";
|
|
7
|
-
import * as z4 from "zod/v4/core";
|
|
8
6
|
|
|
9
7
|
//#region src/output_parsers/openai_tools/json_output_tools_parsers.d.ts
|
|
10
8
|
type ParsedToolCall = {
|
|
@@ -61,10 +59,10 @@ type JsonOutputKeyToolsParserParamsBase = {
|
|
|
61
59
|
returnSingle?: boolean;
|
|
62
60
|
} & JsonOutputToolsParserParams;
|
|
63
61
|
type JsonOutputKeyToolsParserParamsV3<T extends Record<string, any> = Record<string, any>> = {
|
|
64
|
-
zodSchema?:
|
|
62
|
+
zodSchema?: ZodV3Like<T>;
|
|
65
63
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
66
64
|
type JsonOutputKeyToolsParserParamsV4<T extends Record<string, any> = Record<string, any>> = {
|
|
67
|
-
zodSchema?:
|
|
65
|
+
zodSchema?: ZodV4Like<T, T>;
|
|
68
66
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
69
67
|
type JsonOutputKeyToolsParserParamsInterop<T extends Record<string, any> = Record<string, any>> = {
|
|
70
68
|
zodSchema?: InteropZodType<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.d.ts","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json_output_tools_parsers.d.ts","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"mappings":";;;;;;;KAgBY,cAAA;EACV,EAAA;EAEA,IAAA;EAGA,IAAA,EAAM,MAAA;AAAA;AAAA,KAGI,2BAAA;EANV,0CAQA,QAAA;AAAA,IACE,wCAAA;AAAA,iBAEY,aAAA,CAEd,WAAA,EAAa,MAAA,eACb,OAAA;EAAW,QAAA;EAAoB,OAAA;AAAA,IAC9B,QAAA;AAAA,iBACa,aAAA,CAEd,WAAA,EAAa,MAAA,eACb,OAAA;EAAY,QAAA;EAAoB,OAAA;AAAA,IAC/B,QAAA;AAA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AAA;EAIP,YAAA;EAEA,eAAA;EAEA,QAAA;EAlIgC;EAqIhC,OAAA;EAnI4C;EAsI5C,YAAA;EAEA,SAAA,GAAY,cAAA,CAAe,CAAA;EAE3B,kBAAA,GAAqB,kBAAA,CAAmB,CAAA;EAExC,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,CAAA;EAErD,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,CAAA;EAErD,WAAA,CAAY,MAAA,EAAQ,qCAAA,CAAsC,CAAA;EAAA,UAoB1C,eAAA,CAAgB,MAAA,YAAkB,OAAA,CAAQ,CAAA;EAoCpD,kBAAA,CAAmB,WAAA,EAAa,cAAA,KAAmB,OAAA;EAuBnD,WAAA,CAAY,WAAA,EAAa,cAAA,KAAmB,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.js","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z3.ZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z4.$ZodType<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(zodParsedResult.error?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;;AA8CA,SAAgB,cAEd,aACA,SACsB;AACtB,KAAI,YAAY,aAAa,OAC3B;CAEF,IAAI;AACJ,KAAI,SAAS,QACX,KAAI;AACF,iBAAe,iBAAiB,YAAY,SAAS,aAAa,KAAK;SACjE;AACN;;KAGF,KAAI;AACF,iBAAe,KAAK,MAAM,YAAY,SAAS,UAAU;UAElD,GAAQ;AACf,QAAM,IAAI,sBACR;GACE,aAAa,YAAY,SAAS,KAAK;GACvC;GACA,YAAY,SAAS;GACrB;GACA;GACA,UAAU,EAAE;GACb,CAAC,KAAK,KAAK,CACb;;CAIL,MAAM,iBAA2B;EAC/B,MAAM,YAAY,SAAS;EAC3B,MAAM;EACN,MAAM;EACP;AAED,KAAI,SAAS,SACX,gBAAe,KAAK,YAAY;AAGlC,QAAO;;AAGT,SAAgB,iCAAiC,UAAoB;AACnE,KAAI,SAAS,OAAO,OAClB,OAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAO;EACL,IAAI,SAAS;EACb,MAAM;EACN,UAAU;GACR,MAAM,SAAS;GACf,WAAW,KAAK,UAAU,SAAS,KAAK;GACzC;EACF;;AAGH,SAAgB,oBAEd,aACA,UACiB;AACjB,QAAO;EACL,MAAM,Y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AM,EAClC,QAC7B,WAA2B,OAAO,SAAS,KAAK,QAClD;EAED,IAAI,iBACF;AACF,MAAI,CAAC,gBAAgB,OACnB;AAEF,MAAI,CAAC,KAAK,SACR,kBAAiB,gBAAgB,KAC9B,WAA2B,OAAO,KACpC;AAEH,MAAI,KAAK,aACP,QAAO,KAAK,gBAAgB,eAAe,GAAG;AAKhD,SAHwB,MAAM,QAAQ,IACpC,eAAe,KAAK,UAAU,KAAK,gBAAgB,MAAM,CAAC,CAC3D"}
|
|
1
|
+
{"version":3,"file":"json_output_tools_parsers.js","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type { ZodV3Like, ZodV4Like } from \"../../utils/types/zod.js\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV3Like<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV4Like<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n )}\". Error: ${JSON.stringify((zodParsedResult.error as any)?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;;AA6CA,SAAgB,cAEd,aACA,SACsB;AACtB,KAAI,YAAY,aAAa,OAC3B;CAEF,IAAI;AACJ,KAAI,SAAS,QACX,KAAI;AACF,iBAAe,iBAAiB,YAAY,SAAS,aAAa,KAAK;SACjE;AACN;;KAGF,KAAI;AACF,iBAAe,KAAK,MAAM,YAAY,SAAS,UAAU;UAElD,GAAQ;AACf,QAAM,IAAI,sBACR;GACE,aAAa,YAAY,SAAS,KAAK;GACvC;GACA,YAAY,SAAS;GACrB;GACA;GACA,UAAU,EAAE;GACb,CAAC,KAAK,KAAK,CACb;;CAIL,MAAM,iBAA2B;EAC/B,MAAM,YAAY,SAAS;EAC3B,MAAM;EACN,MAAM;EACP;AAED,KAAI,SAAS,SACX,gBAAe,KAAK,YAAY;AAGlC,QAAO;;AAGT,SAAgB,iCAAiC,UAAoB;AACnE,KAAI,SAAS,OAAO,OAClB,OAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAO;EACL,IAAI,SAAS;EACb,MAAM;EACN,UAAU;GACR,MAAM,SAAS;GACf,WAAW,KAAK,UAAU,SAAS,KAAK;GACzC;EACF;;AAGH,SAAgB,oBAEd,aACA,UACiB;AACjB,QAAO;EACL,MAAM,YAAY,UAAU;EAC5B,MAAM,YAAY,UAAU;EAC5B,IAAI,YAAY;EAChB,OAAO;EACP,MAAM;EACP;;;;;AAMH,IAAa,wBAAb,cAEU,oCAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;;CAGT,WAAW;CAEX,e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,MAAI,KAAK,aACP,QAAO,KAAK,gBAAgB,eAAe,GAAG;AAKhD,SAHwB,MAAM,QAAQ,IACpC,eAAe,KAAK,UAAU,KAAK,gBAAgB,MAAM,CAAC,CAC3D"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { InputValues } from "../utils/types/index.js";
|
|
2
2
|
import { RunnableConfig } from "../runnables/types.js";
|
|
3
|
-
import "../runnables/config.js";
|
|
4
3
|
import { Runnable, RunnableLike } from "../runnables/base.js";
|
|
5
4
|
import { ChatPromptValueInterface } from "../prompt_values.js";
|
|
6
5
|
import { BaseMessagePromptTemplateLike, ChatPromptTemplate, ChatPromptTemplateInput } from "./chat.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured.d.ts","names":[],"sources":["../../src/prompts/structured.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"structured.d.ts","names":[],"sources":["../../src/prompts/structured.ts"],"mappings":";;;;;;;;;AAkCA;UAAiB,qBAAA,kBAEE,WAAA,0DAGT,uBAAA,CAAwB,QAAA,EAAU,mBAAA;EAE1C,MAAA,EAAQ,MAAA;EACR,MAAA;AAAA;AAAA,cAGW,gBAAA,kBAEM,WAAA,0DAIT,kBAAA,CAAmB,QAAA,EAAU,mBAAA,aAC1B,qBAAA,CAAsB,QAAA,EAAU,mBAAA;EAG3C,MAAA,EAAQ,MAAA;EAER,MAAA;EAEA,YAAA;EAAA,IAEI,UAAA,CAAA,GAAc,MAAA;EAOlB,WAAA,CAAY,KAAA,EAAO,qBAAA,CAAsB,QAAA,EAAU,mBAAA;EAMnD,IAAA,cAAA,CACE,UAAA,EAAY,YAAA,CAAa,wBAAA,EAA0B,YAAA,IAClD,QAAA,CAAS,QAAA,EAAU,OAAA,CAAQ,YAAA,EAAc,KAAA,GAAQ,cAAA;EAAA,OA4B7C,qBAAA,kBAAuC,WAAA,OAAA,CAC5C,cAAA,GACI,kBAAA,CAAmB,WAAA,YACnB,6BAAA,KAEJ,MAAA,EAAQ,qBAAA,YACR,MAAA,gDAEC,kBAAA,CAAmB,QAAA;AAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DocumentInterface } from "../documents/document.js";
|
|
2
2
|
import { CallbackManagerForRetrieverRun, Callbacks } from "../callbacks/manager.js";
|
|
3
3
|
import { RunnableConfig, RunnableInterface } from "../runnables/types.js";
|
|
4
|
-
import "../runnables/config.js";
|
|
5
4
|
import { Runnable } from "../runnables/base.js";
|
|
6
5
|
|
|
7
6
|
//#region src/retrievers/index.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/retrievers/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/retrievers/index.ts"],"mappings":";;;;;;;;AA8BA;;;;;;;;;;;;AAiBA;;;;;;UAjBiB,kBAAA;EACf,SAAA,GAAY,SAAA;EACZ,IAAA;EACA,QAAA,GAAW,MAAA;EACX,OAAA;AAAA;;;;;;;AA8BF;;;;UAjBiB,sBAAA,kBAEE,MAAA,gBAAsB,MAAA,uBAC/B,iBAAA,SAA0B,iBAAA,CAAkB,QAAA;;;;;;;;;;;;;uBAchC,aAAA,kBAEH,MAAA,gBAAsB,MAAA,uBAE/B,QAAA,SAAiB,iBAAA,CAAkB,QAAA,gBAChC,sBAAA;EAAA;;;EAKX,SAAA,GAAY,SAAA;EARK;;;EAajB,IAAA;EAX2C;;;;EAiB3C,QAAA,GAAW,MAAA;EAAX;;;EAKA,OAAA;EAQqB;;;;;;EAArB,WAAA,CAAY,MAAA,GAAS,kBAAA;EA8BV;;;;;EAeT;;;;;;;;;;;;;;EAlBF,qBAAA,CACE,MAAA,UACA,UAAA,GAAa,8BAAA,GACZ,OAAA,CAAQ,iBAAA,CAAkB,QAAA;;;;;;;;;;EAavB,MAAA,CACJ,KAAA,UACA,OAAA,GAAU,cAAA,GACT,OAAA,CAAQ,iBAAA,CAAkB,QAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.d.ts","names":[],"sources":["../../src/runnables/branch.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"branch.d.ts","names":[],"sources":["../../src/runnables/branch.ts"],"mappings":";;;;;;;AAoBA;;;;KAAY,MAAA,yBACV,QAAA,CAAS,QAAA,YACT,QAAA,CAAS,QAAA,EAAU,SAAA;AAAA,KAGT,UAAA,yBACV,YAAA,CAAa,QAAA,YACb,YAAA,CAAa,QAAA,EAAU,SAAA;;;;;;;;AAFzB;;;;;;;;;;;;;;;;;;;AAyCA;;;;;;;;;cAAa,cAAA,0CAAwD,QAAA,CACnE,QAAA,EACA,SAAA;EAAA,OAEO,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,OAAA,EAAS,QAAA,CAAS,QAAA,EAAU,SAAA;EAE5B,QAAA,EAAU,MAAA,CAAO,QAAA,EAAU,SAAA;EAE3B,WAAA,CAAY,MAAA;IACV,QAAA,EAAU,MAAA,CAAO,QAAA,EAAU,SAAA;IAC3B,OAAA,EAAS,QAAA,CAAS,QAAA,EAAU,SAAA;EAAA;EAmCvB;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,OAFA,IAAA,iCAAA,CACL,QAAA,MACK,UAAA,CAAW,QAAA,EAAU,SAAA,KACxB,YAAA,CAAa,QAAA,EAAU,SAAA,KACxB,cAAA,CAAA,QAAA,EAAA,SAAA;EAwBG,OAAA,CACJ,KAAA,EAAO,QAAA,EACP,MAAA,GAAS,OAAA,CAAQ,cAAA,GACjB,UAAA,GAAa,0BAAA,GACZ,OAAA,CAAQ,SAAA;EA+BL,MAAA,CACJ,KAAA,EAAO,QAAA,EACP,MAAA,GAAQ,cAAA,GACP,OAAA,CAAQ,SAAA;EAIJ,eAAA,CAAgB,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,OAAA,CAAQ,cAAA,IAAe,cAAA,CAAA,OAAA,CAAA,SAAA;AAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseMessage } from "../messages/base.js";
|
|
2
2
|
import { RunnableConfig } from "./types.js";
|
|
3
|
-
import "./config.js";
|
|
4
3
|
import { Run } from "../tracers/base.js";
|
|
5
4
|
import { Runnable, RunnableBinding, RunnableBindingArgs } from "./base.js";
|
|
6
5
|
import "../messages/index.js";
|
|
@@ -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,yBAAA,OAEA,IAAA,EAAM,KAAA,UAEP,OAAA,CAAQ,sBAAA,GAAyB,0BAAA,IACjC,sBAAA,GACA,0BAAA;AAAA,UAEa,gCAAA,8BAGP,IAAA,CAAK,mBAAA,CAAoB,QAAA,EAAU,SAAA;EAC3C,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAC7B,iBAAA,EAAmB,yBAAA;EACnB,gBAAA;EACA,iBAAA;EACA,kBAAA;EACA,MAAA,GAAS,cAAA;AAAA;;;;;;;;;;;;;;;AATX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA;;;;;;;;;;;;;;;;;cAAa,0BAAA,8BAGH,eAAA,CAAgB,QAAA,EAAU,SAAA;EAClC,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAE7B,gBAAA;EAEA,iBAAA;EAEA,kBAAA;EAEA,iBAAA,EAAmB,yBAAA;EAEnB,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,QAAA,EAAU,SAAA;EAkC/D,iBAAA,CAEE,UAAA,WAAqB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACvD,KAAA,CAAM,WAAA;EAwCT,kBAAA,CAEE,WAAA,WAAsB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACxD,KAAA,CAAM,WAAA;EA2CH,aAAA,CAEJ,KAAA,OACA,MAAA,GAAS,cAAA,GACR,OAAA,CAAQ,WAAA;EASL,YAAA,CAAa,GAAA,EAAK,GAAA,EAAK,MAAA,EAAQ,cAAA,GAAiB,OAAA;EAiChD,YAAA,CAAA,GAAgB,OAAA,EAAS,KAAA,CAAM,cAAA,gBAA2B,OAAA,CAAA,OAAA,CAAA,cAAA,CAAA,MAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passthrough.d.ts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"passthrough.d.ts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;KAUK,uBAAA,qBACC,KAAA,EAAO,QAAA,eACP,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,cAAA,eAC1B,KAAA,EAAO,QAAA,KAAa,OAAA,YACpB,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,cAAA,KAAmB,OAAA;;AAPa;;;;;;;;;;;;;;;;;;;;;;;;;cAoCnD,mBAAA,yBAA4C,QAAA,CACvD,QAAA,EACA,QAAA;EAAA,OAEO,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,IAAA,GAAO,uBAAA,CAAwB,QAAA;EAE/B,WAAA,CAAY,MAAA;IAAW,IAAA,GAAO,uBAAA,CAAwB,QAAA;EAAA;EAOhD,MAAA,CACJ,KAAA,EAAO,QAAA,EACP,OAAA,GAAU,OAAA,CAAQ,cAAA,IACjB,OAAA,CAAQ,QAAA;EAaJ,SAAA,CACL,SAAA,EAAW,cAAA,CAAe,QAAA,GAC1B,OAAA,EAAS,OAAA,CAAQ,cAAA,IAChB,cAAA,CAAe,QAAA;EA5Ba;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,OAuFxB,MAAA,kBACY,MAAA,oBAA0B,MAAA,qCACzB,MAAA,oBAA0B,MAAA,kBAAA,CAE5C,OAAA,EAAS,eAAA,CAAgB,QAAA,EAAU,SAAA,IAClC,cAAA,CAAe,QAAA,EAAU,QAAA,GAAW,SAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":";;;;;KAIY,WAAA;EACV,GAAA;EAEA,KAAA;AAAA;;;;AA8BF;;;;;;;;;;;;;;;;;;;;;;;;cAAa,cAAA,kBACM,WAAA,oCAGT,QAAA,CAAS,QAAA,EAAU,SAAA;EAAA,OACpB,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,SAAA,EAAW,MAAA,SAAe,QAAA,CAAS,aAAA,EAAe,SAAA;EAElD,WAAA,CAAY,MAAA;IACV,SAAA,EAAW,MAAA,SAAe,QAAA,CAAS,aAAA,EAAe,SAAA;EAAA;EAM9C,MAAA,CACJ,KAAA,EAAO,QAAA,EACP,OAAA,GAAU,OAAA,CAAQ,cAAA,IACjB,OAAA,CAAQ,SAAA;EASL,KAAA,CACJ,MAAA,EAAQ,QAAA,IACR,OAAA,GAAU,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,KAC5C,YAAA,GAAe,oBAAA;IAAyB,gBAAA;EAAA,IACvC,OAAA,CAAQ,SAAA;EAEL,KAAA,CACJ,MAAA,EAAQ,QAAA,IACR,OAAA,GAAU,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,KAC5C,YAAA,GAAe,oBAAA;IAAyB,gBAAA;EAAA,IACvC,OAAA,EAAS,SAAA,GAAY,KAAA;EAElB,KAAA,CACJ,MAAA,EAAQ,QAAA,IACR,OAAA,GAAU,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,KAC5C,YAAA,GAAe,oBAAA,GACd,OAAA,EAAS,SAAA,GAAY,KAAA;EAgClB,MAAA,CACJ,KAAA,EAAO,QAAA,EACP,OAAA,GAAU,OAAA,CAAQ,cAAA,IACjB,OAAA,CAAQ,sBAAA,CAAuB,SAAA;AAAA"}
|
|
@@ -18,22 +18,8 @@ function nextToolCallId() {
|
|
|
18
18
|
*
|
|
19
19
|
* Queue responses with `.respond()` and `.respondWithTools()`, then
|
|
20
20
|
* pass the instance directly wherever a chat model is expected.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `.respond(entry)` — enqueue a `BaseMessage`, `Error`, or factory function.
|
|
25
|
-
*
|
|
26
|
-
* `.respondWithTools(toolCalls[])` — enqueue an `AIMessage` with the given
|
|
27
|
-
* tool calls. Content is derived from the input messages automatically.
|
|
28
|
-
*
|
|
29
|
-
* Both can be mixed freely in one chain. When all queued responses are
|
|
30
|
-
* consumed, further invocations throw.
|
|
31
|
-
*
|
|
32
|
-
* Additional configuration:
|
|
33
|
-
* - `.alwaysThrow(error)` — every call throws (overrides the queue)
|
|
34
|
-
* - `.structuredResponse(value)` — value returned by `withStructuredOutput()`
|
|
35
|
-
*
|
|
36
|
-
* The model records all invocations in `.calls` / `.callCount`.
|
|
21
|
+
* Responses are consumed in first-in-first-out order — one per `invoke()` call.
|
|
22
|
+
* When all queued responses are consumed, further invocations throw.
|
|
37
23
|
*/
|
|
38
24
|
var FakeBuiltModel = class FakeBuiltModel extends require_language_models_chat_models.BaseChatModel {
|
|
39
25
|
queue = [];
|
|
@@ -42,9 +28,17 @@ var FakeBuiltModel = class FakeBuiltModel extends require_language_models_chat_m
|
|
|
42
28
|
_tools = [];
|
|
43
29
|
_callIndex = 0;
|
|
44
30
|
_calls = [];
|
|
31
|
+
/**
|
|
32
|
+
* All invocations recorded by this model, in order.
|
|
33
|
+
* Each entry contains the `messages` array and `options` that were
|
|
34
|
+
* passed to `invoke()`.
|
|
35
|
+
*/
|
|
45
36
|
get calls() {
|
|
46
37
|
return this._calls;
|
|
47
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* The number of times this model has been invoked.
|
|
41
|
+
*/
|
|
48
42
|
get callCount() {
|
|
49
43
|
return this._calls.length;
|
|
50
44
|
}
|
|
@@ -57,6 +51,12 @@ var FakeBuiltModel = class FakeBuiltModel extends require_language_models_chat_m
|
|
|
57
51
|
_combineLLMOutput() {
|
|
58
52
|
return [];
|
|
59
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Enqueue a response that the model will return on its next invocation.
|
|
56
|
+
* @param entry A {@link BaseMessage} to return, an `Error` to throw, or
|
|
57
|
+
* a factory `(messages) => BaseMessage | Error` for dynamic responses.
|
|
58
|
+
* @returns `this`, for chaining.
|
|
59
|
+
*/
|
|
60
60
|
respond(entry) {
|
|
61
61
|
if (typeof entry === "function") this.queue.push({
|
|
62
62
|
kind: "factory",
|
|
@@ -72,6 +72,13 @@ var FakeBuiltModel = class FakeBuiltModel extends require_language_models_chat_m
|
|
|
72
72
|
});
|
|
73
73
|
return this;
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Enqueue an {@link AIMessage} that carries the given tool calls.
|
|
77
|
+
* Content is derived from the input messages at invocation time.
|
|
78
|
+
* @param toolCalls Array of tool calls. Each entry needs `name` and
|
|
79
|
+
* `args`; `id` is optional and auto-generated when omitted.
|
|
80
|
+
* @returns `this`, for chaining.
|
|
81
|
+
*/
|
|
75
82
|
respondWithTools(toolCalls) {
|
|
76
83
|
this.queue.push({
|
|
77
84
|
kind: "toolCalls",
|
|
@@ -84,14 +91,31 @@ var FakeBuiltModel = class FakeBuiltModel extends require_language_models_chat_m
|
|
|
84
91
|
});
|
|
85
92
|
return this;
|
|
86
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Make every invocation throw the given error, regardless of the queue.
|
|
96
|
+
* @param error The error to throw.
|
|
97
|
+
* @returns `this`, for chaining.
|
|
98
|
+
*/
|
|
87
99
|
alwaysThrow(error) {
|
|
88
100
|
this._alwaysThrowError = error;
|
|
89
101
|
return this;
|
|
90
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Set the value that {@link withStructuredOutput} will resolve to.
|
|
105
|
+
* @param value The structured object to return.
|
|
106
|
+
* @returns `this`, for chaining.
|
|
107
|
+
*/
|
|
91
108
|
structuredResponse(value) {
|
|
92
109
|
this._structuredResponseValue = value;
|
|
93
110
|
return this;
|
|
94
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Bind tools to the model. Returns a new model that shares the same
|
|
114
|
+
* response queue and call history.
|
|
115
|
+
* @param tools The tools to bind, as {@link StructuredTool} instances or
|
|
116
|
+
* plain {@link ToolSpec} objects.
|
|
117
|
+
* @returns A new RunnableBinding with the tools bound.
|
|
118
|
+
*/
|
|
95
119
|
bindTools(tools) {
|
|
96
120
|
const merged = [...this._tools, ...tools];
|
|
97
121
|
const next = new FakeBuiltModel();
|
|
@@ -103,6 +127,13 @@ var FakeBuiltModel = class FakeBuiltModel extends require_language_models_chat_m
|
|
|
103
127
|
next._callIndex = this._callIndex;
|
|
104
128
|
return next.withConfig({});
|
|
105
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns a {@link Runnable} that produces the {@link structuredResponse}
|
|
132
|
+
* value. The schema argument is accepted for compatibility but ignored.
|
|
133
|
+
* @param _params Schema or params (ignored).
|
|
134
|
+
* @param _config Options (ignored).
|
|
135
|
+
* @returns A Runnable that resolves to the structured response value.
|
|
136
|
+
*/
|
|
106
137
|
withStructuredOutput(_params, _config) {
|
|
107
138
|
const { _structuredResponseValue } = this;
|
|
108
139
|
return require_base$1.RunnableLambda.from(async () => {
|
|
@@ -150,7 +181,27 @@ var FakeBuiltModel = class FakeBuiltModel extends require_language_models_chat_m
|
|
|
150
181
|
}
|
|
151
182
|
};
|
|
152
183
|
/**
|
|
153
|
-
* Creates a
|
|
184
|
+
* Creates a new {@link FakeBuiltModel} for testing.
|
|
185
|
+
*
|
|
186
|
+
* Returns a chainable builder — queue responses, then pass the model
|
|
187
|
+
* anywhere a chat model is expected. Responses are consumed in FIFO
|
|
188
|
+
* order, one per `invoke()` call.
|
|
189
|
+
*
|
|
190
|
+
* ## API summary
|
|
191
|
+
*
|
|
192
|
+
* | Method | Description |
|
|
193
|
+
* | --- | --- |
|
|
194
|
+
* | `fakeModel()` | Creates a new fake chat model. Returns a chainable builder. |
|
|
195
|
+
* | `.respond(message)` | Queue an `AIMessage` (or any `BaseMessage`) to return on the next invocation. |
|
|
196
|
+
* | `.respond(error)` | Queue an `Error` to throw on the next invocation. |
|
|
197
|
+
* | `.respond(factory)` | Queue a function `(messages) => BaseMessage \| Error` for dynamic responses. |
|
|
198
|
+
* | `.respondWithTools(toolCalls)` | Shorthand for `.respond()` with tool calls. Each entry needs `name` and `args`; `id` is optional. |
|
|
199
|
+
* | `.alwaysThrow(error)` | Make every invocation throw this error, regardless of the queue. |
|
|
200
|
+
* | `.structuredResponse(value)` | Set the value returned by `.withStructuredOutput()`. |
|
|
201
|
+
* | `.bindTools(tools)` | Bind tools to the model. Returns a `RunnableBinding` that shares the response queue and call recording. |
|
|
202
|
+
* | `.withStructuredOutput(schema)` | Returns a runnable that produces the `.structuredResponse()` value. |
|
|
203
|
+
* | `.calls` | Array of `{ messages, options }` for every invocation (read-only). |
|
|
204
|
+
* | `.callCount` | Number of times the model has been invoked. |
|
|
154
205
|
*
|
|
155
206
|
* @example
|
|
156
207
|
* ```typescript
|
|
@@ -170,5 +221,6 @@ function fakeModel() {
|
|
|
170
221
|
}
|
|
171
222
|
|
|
172
223
|
//#endregion
|
|
224
|
+
exports.FakeBuiltModel = FakeBuiltModel;
|
|
173
225
|
exports.fakeModel = fakeModel;
|
|
174
226
|
//# sourceMappingURL=fake_model_builder.cjs.map
|