illuma-agents 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/common/enum.cjs +163 -0
- package/dist/cjs/common/enum.cjs.map +1 -0
- package/dist/cjs/events.cjs +143 -0
- package/dist/cjs/events.cjs.map +1 -0
- package/dist/cjs/graphs/Graph.cjs +581 -0
- package/dist/cjs/graphs/Graph.cjs.map +1 -0
- package/dist/cjs/instrumentation.cjs +21 -0
- package/dist/cjs/instrumentation.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +292 -0
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/types.cjs +50 -0
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +553 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +218 -0
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs +29 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -0
- package/dist/cjs/llm/fake.cjs +97 -0
- package/dist/cjs/llm/fake.cjs.map +1 -0
- package/dist/cjs/llm/google/index.cjs +147 -0
- package/dist/cjs/llm/google/index.cjs.map +1 -0
- package/dist/cjs/llm/google/utils/common.cjs +490 -0
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -0
- package/dist/cjs/llm/ollama/index.cjs +70 -0
- package/dist/cjs/llm/ollama/index.cjs.map +1 -0
- package/dist/cjs/llm/ollama/utils.cjs +158 -0
- package/dist/cjs/llm/ollama/utils.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +613 -0
- package/dist/cjs/llm/openai/index.cjs.map +1 -0
- package/dist/cjs/llm/openai/utils/index.cjs +677 -0
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -0
- package/dist/cjs/llm/openrouter/index.cjs +29 -0
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -0
- package/dist/cjs/llm/providers.cjs +47 -0
- package/dist/cjs/llm/providers.cjs.map +1 -0
- package/dist/cjs/llm/text.cjs +69 -0
- package/dist/cjs/llm/text.cjs.map +1 -0
- package/dist/cjs/llm/vertexai/index.cjs +330 -0
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -0
- package/dist/cjs/main.cjs +127 -0
- package/dist/cjs/main.cjs.map +1 -0
- package/dist/cjs/messages/core.cjs +359 -0
- package/dist/cjs/messages/core.cjs.map +1 -0
- package/dist/cjs/messages/format.cjs +455 -0
- package/dist/cjs/messages/format.cjs.map +1 -0
- package/dist/cjs/messages/ids.cjs +23 -0
- package/dist/cjs/messages/ids.cjs.map +1 -0
- package/dist/cjs/messages/prune.cjs +398 -0
- package/dist/cjs/messages/prune.cjs.map +1 -0
- package/dist/cjs/run.cjs +264 -0
- package/dist/cjs/run.cjs.map +1 -0
- package/dist/cjs/splitStream.cjs +210 -0
- package/dist/cjs/splitStream.cjs.map +1 -0
- package/dist/cjs/stream.cjs +504 -0
- package/dist/cjs/stream.cjs.map +1 -0
- package/dist/cjs/tools/CodeExecutor.cjs +192 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +125 -0
- package/dist/cjs/tools/ToolNode.cjs.map +1 -0
- package/dist/cjs/tools/handlers.cjs +250 -0
- package/dist/cjs/tools/handlers.cjs.map +1 -0
- package/dist/cjs/tools/search/anthropic.cjs +40 -0
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
- package/dist/cjs/tools/search/content.cjs +140 -0
- package/dist/cjs/tools/search/content.cjs.map +1 -0
- package/dist/cjs/tools/search/firecrawl.cjs +179 -0
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -0
- package/dist/cjs/tools/search/format.cjs +203 -0
- package/dist/cjs/tools/search/format.cjs.map +1 -0
- package/dist/cjs/tools/search/highlights.cjs +245 -0
- package/dist/cjs/tools/search/highlights.cjs.map +1 -0
- package/dist/cjs/tools/search/rerankers.cjs +174 -0
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -0
- package/dist/cjs/tools/search/schema.cjs +70 -0
- package/dist/cjs/tools/search/schema.cjs.map +1 -0
- package/dist/cjs/tools/search/search.cjs +561 -0
- package/dist/cjs/tools/search/search.cjs.map +1 -0
- package/dist/cjs/tools/search/serper-scraper.cjs +132 -0
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -0
- package/dist/cjs/tools/search/tool.cjs +331 -0
- package/dist/cjs/tools/search/tool.cjs.map +1 -0
- package/dist/cjs/tools/search/utils.cjs +66 -0
- package/dist/cjs/tools/search/utils.cjs.map +1 -0
- package/dist/cjs/utils/graph.cjs +16 -0
- package/dist/cjs/utils/graph.cjs.map +1 -0
- package/dist/cjs/utils/llm.cjs +28 -0
- package/dist/cjs/utils/llm.cjs.map +1 -0
- package/dist/cjs/utils/misc.cjs +56 -0
- package/dist/cjs/utils/misc.cjs.map +1 -0
- package/dist/cjs/utils/run.cjs +69 -0
- package/dist/cjs/utils/run.cjs.map +1 -0
- package/dist/cjs/utils/title.cjs +111 -0
- package/dist/cjs/utils/title.cjs.map +1 -0
- package/dist/cjs/utils/tokens.cjs +65 -0
- package/dist/cjs/utils/tokens.cjs.map +1 -0
- package/dist/esm/common/enum.mjs +163 -0
- package/dist/esm/common/enum.mjs.map +1 -0
- package/dist/esm/events.mjs +135 -0
- package/dist/esm/events.mjs.map +1 -0
- package/dist/esm/graphs/Graph.mjs +578 -0
- package/dist/esm/graphs/Graph.mjs.map +1 -0
- package/dist/esm/instrumentation.mjs +19 -0
- package/dist/esm/instrumentation.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +290 -0
- package/dist/esm/llm/anthropic/index.mjs.map +1 -0
- package/dist/esm/llm/anthropic/types.mjs +48 -0
- package/dist/esm/llm/anthropic/types.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +550 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +216 -0
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs +27 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -0
- package/dist/esm/llm/fake.mjs +94 -0
- package/dist/esm/llm/fake.mjs.map +1 -0
- package/dist/esm/llm/google/index.mjs +145 -0
- package/dist/esm/llm/google/index.mjs.map +1 -0
- package/dist/esm/llm/google/utils/common.mjs +484 -0
- package/dist/esm/llm/google/utils/common.mjs.map +1 -0
- package/dist/esm/llm/ollama/index.mjs +68 -0
- package/dist/esm/llm/ollama/index.mjs.map +1 -0
- package/dist/esm/llm/ollama/utils.mjs +155 -0
- package/dist/esm/llm/ollama/utils.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +604 -0
- package/dist/esm/llm/openai/index.mjs.map +1 -0
- package/dist/esm/llm/openai/utils/index.mjs +671 -0
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -0
- package/dist/esm/llm/openrouter/index.mjs +27 -0
- package/dist/esm/llm/openrouter/index.mjs.map +1 -0
- package/dist/esm/llm/providers.mjs +43 -0
- package/dist/esm/llm/providers.mjs.map +1 -0
- package/dist/esm/llm/text.mjs +67 -0
- package/dist/esm/llm/text.mjs.map +1 -0
- package/dist/esm/llm/vertexai/index.mjs +328 -0
- package/dist/esm/llm/vertexai/index.mjs.map +1 -0
- package/dist/esm/main.mjs +20 -0
- package/dist/esm/main.mjs.map +1 -0
- package/dist/esm/messages/core.mjs +351 -0
- package/dist/esm/messages/core.mjs.map +1 -0
- package/dist/esm/messages/format.mjs +447 -0
- package/dist/esm/messages/format.mjs.map +1 -0
- package/dist/esm/messages/ids.mjs +21 -0
- package/dist/esm/messages/ids.mjs.map +1 -0
- package/dist/esm/messages/prune.mjs +393 -0
- package/dist/esm/messages/prune.mjs.map +1 -0
- package/dist/esm/run.mjs +261 -0
- package/dist/esm/run.mjs.map +1 -0
- package/dist/esm/splitStream.mjs +207 -0
- package/dist/esm/splitStream.mjs.map +1 -0
- package/dist/esm/stream.mjs +500 -0
- package/dist/esm/stream.mjs.map +1 -0
- package/dist/esm/tools/CodeExecutor.mjs +188 -0
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +122 -0
- package/dist/esm/tools/ToolNode.mjs.map +1 -0
- package/dist/esm/tools/handlers.mjs +245 -0
- package/dist/esm/tools/handlers.mjs.map +1 -0
- package/dist/esm/tools/search/anthropic.mjs +37 -0
- package/dist/esm/tools/search/anthropic.mjs.map +1 -0
- package/dist/esm/tools/search/content.mjs +119 -0
- package/dist/esm/tools/search/content.mjs.map +1 -0
- package/dist/esm/tools/search/firecrawl.mjs +176 -0
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -0
- package/dist/esm/tools/search/format.mjs +201 -0
- package/dist/esm/tools/search/format.mjs.map +1 -0
- package/dist/esm/tools/search/highlights.mjs +243 -0
- package/dist/esm/tools/search/highlights.mjs.map +1 -0
- package/dist/esm/tools/search/rerankers.mjs +168 -0
- package/dist/esm/tools/search/rerankers.mjs.map +1 -0
- package/dist/esm/tools/search/schema.mjs +61 -0
- package/dist/esm/tools/search/schema.mjs.map +1 -0
- package/dist/esm/tools/search/search.mjs +558 -0
- package/dist/esm/tools/search/search.mjs.map +1 -0
- package/dist/esm/tools/search/serper-scraper.mjs +129 -0
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -0
- package/dist/esm/tools/search/tool.mjs +329 -0
- package/dist/esm/tools/search/tool.mjs.map +1 -0
- package/dist/esm/tools/search/utils.mjs +61 -0
- package/dist/esm/tools/search/utils.mjs.map +1 -0
- package/dist/esm/utils/graph.mjs +13 -0
- package/dist/esm/utils/graph.mjs.map +1 -0
- package/dist/esm/utils/llm.mjs +25 -0
- package/dist/esm/utils/llm.mjs.map +1 -0
- package/dist/esm/utils/misc.mjs +53 -0
- package/dist/esm/utils/misc.mjs.map +1 -0
- package/dist/esm/utils/run.mjs +66 -0
- package/dist/esm/utils/run.mjs.map +1 -0
- package/dist/esm/utils/title.mjs +108 -0
- package/dist/esm/utils/title.mjs.map +1 -0
- package/dist/esm/utils/tokens.mjs +62 -0
- package/dist/esm/utils/tokens.mjs.map +1 -0
- package/dist/types/common/enum.d.ts +128 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/events.d.ts +29 -0
- package/dist/types/graphs/Graph.d.ts +122 -0
- package/dist/types/graphs/index.d.ts +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/instrumentation.d.ts +1 -0
- package/dist/types/llm/anthropic/index.d.ts +39 -0
- package/dist/types/llm/anthropic/types.d.ts +37 -0
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +14 -0
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +14 -0
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +22 -0
- package/dist/types/llm/anthropic/utils/tools.d.ts +3 -0
- package/dist/types/llm/fake.d.ts +31 -0
- package/dist/types/llm/google/index.d.ts +14 -0
- package/dist/types/llm/google/types.d.ts +32 -0
- package/dist/types/llm/google/utils/common.d.ts +19 -0
- package/dist/types/llm/google/utils/tools.d.ts +10 -0
- package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +14 -0
- package/dist/types/llm/ollama/index.d.ts +8 -0
- package/dist/types/llm/ollama/utils.d.ts +7 -0
- package/dist/types/llm/openai/index.d.ts +103 -0
- package/dist/types/llm/openai/types.d.ts +10 -0
- package/dist/types/llm/openai/utils/index.d.ts +20 -0
- package/dist/types/llm/openrouter/index.d.ts +12 -0
- package/dist/types/llm/providers.d.ts +5 -0
- package/dist/types/llm/text.d.ts +21 -0
- package/dist/types/llm/vertexai/index.d.ts +293 -0
- package/dist/types/messages/core.d.ts +14 -0
- package/dist/types/messages/format.d.ts +113 -0
- package/dist/types/messages/ids.d.ts +3 -0
- package/dist/types/messages/index.d.ts +4 -0
- package/dist/types/messages/prune.d.ts +51 -0
- package/dist/types/mockStream.d.ts +32 -0
- package/dist/types/prompts/collab.d.ts +1 -0
- package/dist/types/prompts/index.d.ts +2 -0
- package/dist/types/prompts/taskmanager.d.ts +41 -0
- package/dist/types/run.d.ts +30 -0
- package/dist/types/scripts/abort.d.ts +1 -0
- package/dist/types/scripts/ant_web_search.d.ts +1 -0
- package/dist/types/scripts/args.d.ts +7 -0
- package/dist/types/scripts/caching.d.ts +1 -0
- package/dist/types/scripts/cli.d.ts +1 -0
- package/dist/types/scripts/cli2.d.ts +1 -0
- package/dist/types/scripts/cli3.d.ts +1 -0
- package/dist/types/scripts/cli4.d.ts +1 -0
- package/dist/types/scripts/cli5.d.ts +1 -0
- package/dist/types/scripts/code_exec.d.ts +1 -0
- package/dist/types/scripts/code_exec_files.d.ts +1 -0
- package/dist/types/scripts/code_exec_simple.d.ts +1 -0
- package/dist/types/scripts/content.d.ts +1 -0
- package/dist/types/scripts/empty_input.d.ts +1 -0
- package/dist/types/scripts/image.d.ts +1 -0
- package/dist/types/scripts/memory.d.ts +1 -0
- package/dist/types/scripts/search.d.ts +1 -0
- package/dist/types/scripts/simple.d.ts +1 -0
- package/dist/types/scripts/stream.d.ts +1 -0
- package/dist/types/scripts/thinking.d.ts +1 -0
- package/dist/types/scripts/tools.d.ts +1 -0
- package/dist/types/specs/spec.utils.d.ts +1 -0
- package/dist/types/splitStream.d.ts +37 -0
- package/dist/types/stream.d.ts +14 -0
- package/dist/types/tools/CodeExecutor.d.ts +23 -0
- package/dist/types/tools/ToolNode.d.ts +22 -0
- package/dist/types/tools/example.d.ts +78 -0
- package/dist/types/tools/handlers.d.ts +19 -0
- package/dist/types/tools/search/anthropic.d.ts +16 -0
- package/dist/types/tools/search/content.d.ts +4 -0
- package/dist/types/tools/search/firecrawl.d.ts +54 -0
- package/dist/types/tools/search/format.d.ts +5 -0
- package/dist/types/tools/search/highlights.d.ts +13 -0
- package/dist/types/tools/search/index.d.ts +2 -0
- package/dist/types/tools/search/rerankers.d.ts +38 -0
- package/dist/types/tools/search/schema.d.ts +16 -0
- package/dist/types/tools/search/search.d.ts +8 -0
- package/dist/types/tools/search/serper-scraper.d.ts +59 -0
- package/dist/types/tools/search/test.d.ts +1 -0
- package/dist/types/tools/search/tool.d.ts +54 -0
- package/dist/types/tools/search/types.d.ts +591 -0
- package/dist/types/tools/search/utils.d.ts +10 -0
- package/dist/types/types/graph.d.ts +138 -0
- package/dist/types/types/index.d.ts +5 -0
- package/dist/types/types/llm.d.ts +102 -0
- package/dist/types/types/run.d.ts +74 -0
- package/dist/types/types/stream.d.ts +293 -0
- package/dist/types/types/tools.d.ts +61 -0
- package/dist/types/utils/graph.d.ts +2 -0
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/llm.d.ts +3 -0
- package/dist/types/utils/llmConfig.d.ts +3 -0
- package/dist/types/utils/logging.d.ts +1 -0
- package/dist/types/utils/misc.d.ts +7 -0
- package/dist/types/utils/run.d.ts +27 -0
- package/dist/types/utils/title.d.ts +4 -0
- package/dist/types/utils/tokens.d.ts +3 -0
- package/package.json +145 -0
- package/src/common/enum.ts +176 -0
- package/src/common/index.ts +2 -0
- package/src/events.ts +191 -0
- package/src/graphs/Graph.ts +846 -0
- package/src/graphs/index.ts +1 -0
- package/src/index.ts +24 -0
- package/src/instrumentation.ts +22 -0
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/index.ts +413 -0
- package/src/llm/anthropic/llm.spec.ts +1442 -0
- package/src/llm/anthropic/types.ts +140 -0
- package/src/llm/anthropic/utils/message_inputs.ts +660 -0
- package/src/llm/anthropic/utils/message_outputs.ts +289 -0
- package/src/llm/anthropic/utils/output_parsers.ts +133 -0
- package/src/llm/anthropic/utils/tools.ts +29 -0
- package/src/llm/fake.ts +133 -0
- package/src/llm/google/index.ts +222 -0
- package/src/llm/google/types.ts +43 -0
- package/src/llm/google/utils/common.ts +660 -0
- package/src/llm/google/utils/tools.ts +160 -0
- package/src/llm/google/utils/zod_to_genai_parameters.ts +88 -0
- package/src/llm/ollama/index.ts +92 -0
- package/src/llm/ollama/utils.ts +193 -0
- package/src/llm/openai/index.ts +853 -0
- package/src/llm/openai/types.ts +24 -0
- package/src/llm/openai/utils/index.ts +918 -0
- package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
- package/src/llm/openrouter/index.ts +60 -0
- package/src/llm/providers.ts +57 -0
- package/src/llm/text.ts +94 -0
- package/src/llm/vertexai/index.ts +360 -0
- package/src/messages/core.ts +463 -0
- package/src/messages/format.ts +625 -0
- package/src/messages/formatAgentMessages.test.ts +917 -0
- package/src/messages/formatAgentMessages.tools.test.ts +400 -0
- package/src/messages/formatMessage.test.ts +693 -0
- package/src/messages/ids.ts +26 -0
- package/src/messages/index.ts +4 -0
- package/src/messages/prune.ts +567 -0
- package/src/messages/shiftIndexTokenCountMap.test.ts +81 -0
- package/src/mockStream.ts +99 -0
- package/src/prompts/collab.ts +6 -0
- package/src/prompts/index.ts +2 -0
- package/src/prompts/taskmanager.ts +61 -0
- package/src/proto/CollabGraph.ts +269 -0
- package/src/proto/TaskManager.ts +243 -0
- package/src/proto/collab.ts +200 -0
- package/src/proto/collab_design.ts +184 -0
- package/src/proto/collab_design_v2.ts +224 -0
- package/src/proto/collab_design_v3.ts +255 -0
- package/src/proto/collab_design_v4.ts +220 -0
- package/src/proto/collab_design_v5.ts +251 -0
- package/src/proto/collab_graph.ts +181 -0
- package/src/proto/collab_original.ts +123 -0
- package/src/proto/example.ts +93 -0
- package/src/proto/example_new.ts +68 -0
- package/src/proto/example_old.ts +201 -0
- package/src/proto/example_test.ts +152 -0
- package/src/proto/example_test_anthropic.ts +100 -0
- package/src/proto/log_stream.ts +202 -0
- package/src/proto/main_collab_community_event.ts +133 -0
- package/src/proto/main_collab_design_v2.ts +96 -0
- package/src/proto/main_collab_design_v4.ts +100 -0
- package/src/proto/main_collab_design_v5.ts +135 -0
- package/src/proto/main_collab_global_analysis.ts +122 -0
- package/src/proto/main_collab_hackathon_event.ts +153 -0
- package/src/proto/main_collab_space_mission.ts +153 -0
- package/src/proto/main_philosophy.ts +210 -0
- package/src/proto/original_script.ts +126 -0
- package/src/proto/standard.ts +100 -0
- package/src/proto/stream.ts +56 -0
- package/src/proto/tasks.ts +118 -0
- package/src/proto/tools/global_analysis_tools.ts +86 -0
- package/src/proto/tools/space_mission_tools.ts +60 -0
- package/src/proto/vertexai.ts +54 -0
- package/src/run.ts +381 -0
- package/src/scripts/abort.ts +138 -0
- package/src/scripts/ant_web_search.ts +158 -0
- package/src/scripts/args.ts +48 -0
- package/src/scripts/caching.ts +124 -0
- package/src/scripts/cli.ts +167 -0
- package/src/scripts/cli2.ts +125 -0
- package/src/scripts/cli3.ts +178 -0
- package/src/scripts/cli4.ts +184 -0
- package/src/scripts/cli5.ts +184 -0
- package/src/scripts/code_exec.ts +214 -0
- package/src/scripts/code_exec_files.ts +193 -0
- package/src/scripts/code_exec_simple.ts +129 -0
- package/src/scripts/content.ts +120 -0
- package/src/scripts/empty_input.ts +137 -0
- package/src/scripts/image.ts +178 -0
- package/src/scripts/memory.ts +97 -0
- package/src/scripts/search.ts +150 -0
- package/src/scripts/simple.ts +225 -0
- package/src/scripts/stream.ts +122 -0
- package/src/scripts/thinking.ts +150 -0
- package/src/scripts/tools.ts +155 -0
- package/src/specs/anthropic.simple.test.ts +317 -0
- package/src/specs/azure.simple.test.ts +316 -0
- package/src/specs/openai.simple.test.ts +316 -0
- package/src/specs/prune.test.ts +763 -0
- package/src/specs/reasoning.test.ts +165 -0
- package/src/specs/spec.utils.ts +3 -0
- package/src/specs/thinking-prune.test.ts +703 -0
- package/src/specs/token-distribution-edge-case.test.ts +316 -0
- package/src/specs/tool-error.test.ts +193 -0
- package/src/splitStream.test.ts +691 -0
- package/src/splitStream.ts +234 -0
- package/src/stream.test.ts +94 -0
- package/src/stream.ts +651 -0
- package/src/tools/CodeExecutor.ts +220 -0
- package/src/tools/ToolNode.ts +170 -0
- package/src/tools/example.ts +129 -0
- package/src/tools/handlers.ts +336 -0
- package/src/tools/search/anthropic.ts +51 -0
- package/src/tools/search/content.test.ts +173 -0
- package/src/tools/search/content.ts +147 -0
- package/src/tools/search/firecrawl.ts +210 -0
- package/src/tools/search/format.ts +250 -0
- package/src/tools/search/highlights.ts +320 -0
- package/src/tools/search/index.ts +2 -0
- package/src/tools/search/jina-reranker.test.ts +126 -0
- package/src/tools/search/output.md +2775 -0
- package/src/tools/search/rerankers.ts +242 -0
- package/src/tools/search/schema.ts +63 -0
- package/src/tools/search/search.ts +759 -0
- package/src/tools/search/serper-scraper.ts +155 -0
- package/src/tools/search/test.html +884 -0
- package/src/tools/search/test.md +643 -0
- package/src/tools/search/test.ts +159 -0
- package/src/tools/search/tool.ts +471 -0
- package/src/tools/search/types.ts +687 -0
- package/src/tools/search/utils.ts +79 -0
- package/src/types/graph.ts +185 -0
- package/src/types/index.ts +6 -0
- package/src/types/llm.ts +140 -0
- package/src/types/run.ts +89 -0
- package/src/types/stream.ts +400 -0
- package/src/types/tools.ts +80 -0
- package/src/utils/graph.ts +11 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/llm.ts +27 -0
- package/src/utils/llmConfig.ts +183 -0
- package/src/utils/logging.ts +48 -0
- package/src/utils/misc.ts +57 -0
- package/src/utils/run.ts +101 -0
- package/src/utils/title.ts +165 -0
- package/src/utils/tokens.ts +70 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var messages = require('@langchain/core/messages');
|
|
4
|
+
var types = require('../types.cjs');
|
|
5
|
+
|
|
6
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
7
|
+
/* eslint-disable no-console */
|
|
8
|
+
/**
|
|
9
|
+
* This util file contains functions for converting LangChain messages to Anthropic messages.
|
|
10
|
+
*/
|
|
11
|
+
function _formatImage(imageUrl) {
|
|
12
|
+
const parsed = messages.parseBase64DataUrl({ dataUrl: imageUrl });
|
|
13
|
+
if (parsed) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'base64',
|
|
16
|
+
media_type: parsed.mime_type,
|
|
17
|
+
data: parsed.data,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let parsedUrl;
|
|
21
|
+
try {
|
|
22
|
+
parsedUrl = new URL(imageUrl);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new Error([
|
|
26
|
+
`Malformed image URL: ${JSON.stringify(imageUrl)}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,
|
|
27
|
+
'Example: data:image/png;base64,/9j/4AAQSk...',
|
|
28
|
+
'Example: https://example.com/image.jpg',
|
|
29
|
+
].join('\n\n'));
|
|
30
|
+
}
|
|
31
|
+
if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
|
|
32
|
+
return {
|
|
33
|
+
type: 'url',
|
|
34
|
+
url: imageUrl,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
throw new Error([
|
|
38
|
+
`Invalid image URL protocol: ${JSON.stringify(parsedUrl.protocol)}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,
|
|
39
|
+
'Example: data:image/png;base64,/9j/4AAQSk...',
|
|
40
|
+
'Example: https://example.com/image.jpg',
|
|
41
|
+
].join('\n\n'));
|
|
42
|
+
}
|
|
43
|
+
function _ensureMessageContents(messages$1) {
|
|
44
|
+
// Merge runs of human/tool messages into single human messages with content blocks.
|
|
45
|
+
const updatedMsgs = [];
|
|
46
|
+
for (const message of messages$1) {
|
|
47
|
+
if (message._getType() === 'tool') {
|
|
48
|
+
if (typeof message.content === 'string') {
|
|
49
|
+
const previousMessage = updatedMsgs[updatedMsgs.length - 1];
|
|
50
|
+
if (previousMessage._getType() === 'human' &&
|
|
51
|
+
Array.isArray(previousMessage.content) &&
|
|
52
|
+
'type' in previousMessage.content[0] &&
|
|
53
|
+
previousMessage.content[0].type === 'tool_result') {
|
|
54
|
+
// If the previous message was a tool result, we merge this tool message into it.
|
|
55
|
+
previousMessage.content.push({
|
|
56
|
+
type: 'tool_result',
|
|
57
|
+
content: message.content,
|
|
58
|
+
tool_use_id: message.tool_call_id,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// If not, we create a new human message with the tool result.
|
|
63
|
+
updatedMsgs.push(new messages.HumanMessage({
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'tool_result',
|
|
67
|
+
content: message.content,
|
|
68
|
+
tool_use_id: message.tool_call_id,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
updatedMsgs.push(new messages.HumanMessage({
|
|
76
|
+
content: [
|
|
77
|
+
{
|
|
78
|
+
type: 'tool_result',
|
|
79
|
+
// rare case: message.content could be undefined
|
|
80
|
+
...(message.content != null
|
|
81
|
+
? { content: _formatContent(message) }
|
|
82
|
+
: {}),
|
|
83
|
+
tool_use_id: message.tool_call_id,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
updatedMsgs.push(message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return updatedMsgs;
|
|
94
|
+
}
|
|
95
|
+
function _convertLangChainToolCallToAnthropic(toolCall) {
|
|
96
|
+
if (toolCall.id === undefined) {
|
|
97
|
+
throw new Error('Anthropic requires all tool calls to have an "id".');
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
type: 'tool_use',
|
|
101
|
+
id: toolCall.id,
|
|
102
|
+
name: toolCall.name,
|
|
103
|
+
input: toolCall.args,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const standardContentBlockConverter = {
|
|
107
|
+
providerName: 'anthropic',
|
|
108
|
+
fromStandardTextBlock(block) {
|
|
109
|
+
return {
|
|
110
|
+
type: 'text',
|
|
111
|
+
text: block.text,
|
|
112
|
+
...('citations' in (block.metadata ?? {})
|
|
113
|
+
? { citations: block.metadata.citations }
|
|
114
|
+
: {}),
|
|
115
|
+
...('cache_control' in (block.metadata ?? {})
|
|
116
|
+
? { cache_control: block.metadata.cache_control }
|
|
117
|
+
: {}),
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
fromStandardImageBlock(block) {
|
|
121
|
+
if (block.source_type === 'url') {
|
|
122
|
+
const data = messages.parseBase64DataUrl({
|
|
123
|
+
dataUrl: block.url,
|
|
124
|
+
asTypedArray: false,
|
|
125
|
+
});
|
|
126
|
+
if (data) {
|
|
127
|
+
return {
|
|
128
|
+
type: 'image',
|
|
129
|
+
source: {
|
|
130
|
+
type: 'base64',
|
|
131
|
+
data: data.data,
|
|
132
|
+
media_type: data.mime_type,
|
|
133
|
+
},
|
|
134
|
+
...('cache_control' in (block.metadata ?? {})
|
|
135
|
+
? { cache_control: block.metadata.cache_control }
|
|
136
|
+
: {}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return {
|
|
141
|
+
type: 'image',
|
|
142
|
+
source: {
|
|
143
|
+
type: 'url',
|
|
144
|
+
url: block.url,
|
|
145
|
+
media_type: block.mime_type ?? '',
|
|
146
|
+
},
|
|
147
|
+
...('cache_control' in (block.metadata ?? {})
|
|
148
|
+
? { cache_control: block.metadata.cache_control }
|
|
149
|
+
: {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (block.source_type === 'base64') {
|
|
155
|
+
return {
|
|
156
|
+
type: 'image',
|
|
157
|
+
source: {
|
|
158
|
+
type: 'base64',
|
|
159
|
+
data: block.data,
|
|
160
|
+
media_type: block.mime_type ?? '',
|
|
161
|
+
},
|
|
162
|
+
...('cache_control' in (block.metadata ?? {})
|
|
163
|
+
? { cache_control: block.metadata.cache_control }
|
|
164
|
+
: {}),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
throw new Error(`Unsupported image source type: ${block.source_type}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
fromStandardFileBlock(block) {
|
|
173
|
+
const mime_type = (block.mime_type ?? '').split(';')[0];
|
|
174
|
+
if (block.source_type === 'url') {
|
|
175
|
+
if (mime_type === 'application/pdf' || mime_type === '') {
|
|
176
|
+
return {
|
|
177
|
+
type: 'document',
|
|
178
|
+
source: {
|
|
179
|
+
type: 'url',
|
|
180
|
+
url: block.url,
|
|
181
|
+
media_type: block.mime_type ?? '',
|
|
182
|
+
},
|
|
183
|
+
...('cache_control' in (block.metadata ?? {})
|
|
184
|
+
? { cache_control: block.metadata.cache_control }
|
|
185
|
+
: {}),
|
|
186
|
+
...('citations' in (block.metadata ?? {})
|
|
187
|
+
? { citations: block.metadata.citations }
|
|
188
|
+
: {}),
|
|
189
|
+
...('context' in (block.metadata ?? {})
|
|
190
|
+
? { context: block.metadata.context }
|
|
191
|
+
: {}),
|
|
192
|
+
...('title' in (block.metadata ?? {})
|
|
193
|
+
? { title: block.metadata.title }
|
|
194
|
+
: {}),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
throw new Error(`Unsupported file mime type for file url source: ${block.mime_type}`);
|
|
198
|
+
}
|
|
199
|
+
else if (block.source_type === 'text') {
|
|
200
|
+
if (mime_type === 'text/plain' || mime_type === '') {
|
|
201
|
+
return {
|
|
202
|
+
type: 'document',
|
|
203
|
+
source: {
|
|
204
|
+
type: 'text',
|
|
205
|
+
data: block.text,
|
|
206
|
+
media_type: block.mime_type ?? '',
|
|
207
|
+
},
|
|
208
|
+
...('cache_control' in (block.metadata ?? {})
|
|
209
|
+
? { cache_control: block.metadata.cache_control }
|
|
210
|
+
: {}),
|
|
211
|
+
...('citations' in (block.metadata ?? {})
|
|
212
|
+
? { citations: block.metadata.citations }
|
|
213
|
+
: {}),
|
|
214
|
+
...('context' in (block.metadata ?? {})
|
|
215
|
+
? { context: block.metadata.context }
|
|
216
|
+
: {}),
|
|
217
|
+
...('title' in (block.metadata ?? {})
|
|
218
|
+
? { title: block.metadata.title }
|
|
219
|
+
: {}),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
throw new Error(`Unsupported file mime type for file text source: ${block.mime_type}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (block.source_type === 'base64') {
|
|
227
|
+
if (mime_type === 'application/pdf' || mime_type === '') {
|
|
228
|
+
return {
|
|
229
|
+
type: 'document',
|
|
230
|
+
source: {
|
|
231
|
+
type: 'base64',
|
|
232
|
+
data: block.data,
|
|
233
|
+
media_type: 'application/pdf',
|
|
234
|
+
},
|
|
235
|
+
...('cache_control' in (block.metadata ?? {})
|
|
236
|
+
? { cache_control: block.metadata.cache_control }
|
|
237
|
+
: {}),
|
|
238
|
+
...('citations' in (block.metadata ?? {})
|
|
239
|
+
? { citations: block.metadata.citations }
|
|
240
|
+
: {}),
|
|
241
|
+
...('context' in (block.metadata ?? {})
|
|
242
|
+
? { context: block.metadata.context }
|
|
243
|
+
: {}),
|
|
244
|
+
...('title' in (block.metadata ?? {})
|
|
245
|
+
? { title: block.metadata.title }
|
|
246
|
+
: {}),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
else if (['image/jpeg', 'image/png', 'image/gif', 'image/webp'].includes(mime_type)) {
|
|
250
|
+
return {
|
|
251
|
+
type: 'document',
|
|
252
|
+
source: {
|
|
253
|
+
type: 'content',
|
|
254
|
+
content: [
|
|
255
|
+
{
|
|
256
|
+
type: 'image',
|
|
257
|
+
source: {
|
|
258
|
+
type: 'base64',
|
|
259
|
+
data: block.data,
|
|
260
|
+
media_type: mime_type,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
},
|
|
265
|
+
...('cache_control' in (block.metadata ?? {})
|
|
266
|
+
? { cache_control: block.metadata.cache_control }
|
|
267
|
+
: {}),
|
|
268
|
+
...('citations' in (block.metadata ?? {})
|
|
269
|
+
? { citations: block.metadata.citations }
|
|
270
|
+
: {}),
|
|
271
|
+
...('context' in (block.metadata ?? {})
|
|
272
|
+
? { context: block.metadata.context }
|
|
273
|
+
: {}),
|
|
274
|
+
...('title' in (block.metadata ?? {})
|
|
275
|
+
? { title: block.metadata.title }
|
|
276
|
+
: {}),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
throw new Error(`Unsupported file mime type for file base64 source: ${block.mime_type}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
throw new Error(`Unsupported file source type: ${block.source_type}`);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
function _formatContent(message) {
|
|
289
|
+
const toolTypes = [
|
|
290
|
+
'tool_use',
|
|
291
|
+
'tool_result',
|
|
292
|
+
'input_json_delta',
|
|
293
|
+
'server_tool_use',
|
|
294
|
+
'web_search_tool_result',
|
|
295
|
+
'web_search_result',
|
|
296
|
+
];
|
|
297
|
+
const textTypes = ['text', 'text_delta'];
|
|
298
|
+
const { content } = message;
|
|
299
|
+
if (typeof content === 'string') {
|
|
300
|
+
return content;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const contentBlocks = content.map((contentPart) => {
|
|
304
|
+
if (messages.isDataContentBlock(contentPart)) {
|
|
305
|
+
return messages.convertToProviderContentBlock(contentPart, standardContentBlockConverter);
|
|
306
|
+
}
|
|
307
|
+
const cacheControl = 'cache_control' in contentPart ? contentPart.cache_control : undefined;
|
|
308
|
+
if (contentPart.type === 'image_url') {
|
|
309
|
+
let source;
|
|
310
|
+
if (typeof contentPart.image_url === 'string') {
|
|
311
|
+
source = _formatImage(contentPart.image_url);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
source = _formatImage(contentPart.image_url.url);
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
type: 'image', // Explicitly setting the type as "image"
|
|
318
|
+
source,
|
|
319
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
else if (types.isAnthropicImageBlockParam(contentPart)) {
|
|
323
|
+
return contentPart;
|
|
324
|
+
}
|
|
325
|
+
else if (contentPart.type === 'document') {
|
|
326
|
+
// PDF
|
|
327
|
+
return {
|
|
328
|
+
...contentPart,
|
|
329
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
else if (contentPart.type === 'thinking') {
|
|
333
|
+
const block = {
|
|
334
|
+
type: 'thinking', // Explicitly setting the type as "thinking"
|
|
335
|
+
thinking: contentPart.thinking,
|
|
336
|
+
signature: contentPart.signature,
|
|
337
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
338
|
+
};
|
|
339
|
+
return block;
|
|
340
|
+
}
|
|
341
|
+
else if (contentPart.type === 'redacted_thinking') {
|
|
342
|
+
const block = {
|
|
343
|
+
type: 'redacted_thinking', // Explicitly setting the type as "redacted_thinking"
|
|
344
|
+
data: contentPart.data,
|
|
345
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
346
|
+
};
|
|
347
|
+
return block;
|
|
348
|
+
}
|
|
349
|
+
else if (contentPart.type === 'search_result') {
|
|
350
|
+
const block = {
|
|
351
|
+
type: 'search_result', // Explicitly setting the type as "search_result"
|
|
352
|
+
title: contentPart.title,
|
|
353
|
+
source: contentPart.source,
|
|
354
|
+
...('cache_control' in contentPart && contentPart.cache_control
|
|
355
|
+
? { cache_control: contentPart.cache_control }
|
|
356
|
+
: {}),
|
|
357
|
+
...('citations' in contentPart && contentPart.citations
|
|
358
|
+
? { citations: contentPart.citations }
|
|
359
|
+
: {}),
|
|
360
|
+
content: contentPart.content,
|
|
361
|
+
};
|
|
362
|
+
return block;
|
|
363
|
+
}
|
|
364
|
+
else if (textTypes.find((t) => t === contentPart.type) &&
|
|
365
|
+
'text' in contentPart) {
|
|
366
|
+
// Assuming contentPart is of type MessageContentText here
|
|
367
|
+
return {
|
|
368
|
+
type: 'text', // Explicitly setting the type as "text"
|
|
369
|
+
text: contentPart.text,
|
|
370
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
371
|
+
...('citations' in contentPart && contentPart.citations
|
|
372
|
+
? { citations: contentPart.citations }
|
|
373
|
+
: {}),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
else if (toolTypes.find((t) => t === contentPart.type)) {
|
|
377
|
+
const contentPartCopy = { ...contentPart };
|
|
378
|
+
if ('index' in contentPartCopy) {
|
|
379
|
+
// Anthropic does not support passing the index field here, so we remove it.
|
|
380
|
+
delete contentPartCopy.index;
|
|
381
|
+
}
|
|
382
|
+
if (contentPartCopy.type === 'input_json_delta') {
|
|
383
|
+
// `input_json_delta` type only represents yielding partial tool inputs
|
|
384
|
+
// and is not a valid type for Anthropic messages.
|
|
385
|
+
contentPartCopy.type = 'tool_use';
|
|
386
|
+
}
|
|
387
|
+
if ('input' in contentPartCopy) {
|
|
388
|
+
// Anthropic tool use inputs should be valid objects, when applicable.
|
|
389
|
+
if (typeof contentPartCopy.input === 'string') {
|
|
390
|
+
try {
|
|
391
|
+
contentPartCopy.input = JSON.parse(contentPartCopy.input);
|
|
392
|
+
}
|
|
393
|
+
catch {
|
|
394
|
+
contentPartCopy.input = {};
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// TODO: Fix when SDK types are fixed
|
|
399
|
+
return {
|
|
400
|
+
...contentPartCopy,
|
|
401
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
402
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
else if ('functionCall' in contentPart &&
|
|
406
|
+
contentPart.functionCall &&
|
|
407
|
+
typeof contentPart.functionCall === 'object' &&
|
|
408
|
+
messages.isAIMessage(message)) {
|
|
409
|
+
const correspondingToolCall = message.tool_calls?.find((toolCall) => toolCall.name === contentPart.functionCall.name);
|
|
410
|
+
if (!correspondingToolCall) {
|
|
411
|
+
throw new Error(`Could not find tool call for function call ${contentPart.functionCall.name}`);
|
|
412
|
+
}
|
|
413
|
+
// Google GenAI models include a `functionCall` object inside content. We should ignore it as Anthropic will not support it.
|
|
414
|
+
return {
|
|
415
|
+
id: correspondingToolCall.id,
|
|
416
|
+
type: 'tool_use',
|
|
417
|
+
name: correspondingToolCall.name,
|
|
418
|
+
input: contentPart.functionCall.args,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
throw new Error('Unsupported message content format');
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
return contentBlocks;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Formats messages as a prompt for the model.
|
|
430
|
+
* Used in LangSmith, export is important here.
|
|
431
|
+
* @param messages The base messages to format as a prompt.
|
|
432
|
+
* @returns The formatted prompt.
|
|
433
|
+
*/
|
|
434
|
+
function _convertMessagesToAnthropicPayload(messages$1) {
|
|
435
|
+
const mergedMessages = _ensureMessageContents(messages$1);
|
|
436
|
+
let system;
|
|
437
|
+
if (mergedMessages.length > 0 && mergedMessages[0]._getType() === 'system') {
|
|
438
|
+
system = messages$1[0].content;
|
|
439
|
+
}
|
|
440
|
+
const conversationMessages = system !== undefined ? mergedMessages.slice(1) : mergedMessages;
|
|
441
|
+
const formattedMessages = conversationMessages.map((message) => {
|
|
442
|
+
let role;
|
|
443
|
+
if (message._getType() === 'human') {
|
|
444
|
+
role = 'user';
|
|
445
|
+
}
|
|
446
|
+
else if (message._getType() === 'ai') {
|
|
447
|
+
role = 'assistant';
|
|
448
|
+
}
|
|
449
|
+
else if (message._getType() === 'tool') {
|
|
450
|
+
role = 'user';
|
|
451
|
+
}
|
|
452
|
+
else if (message._getType() === 'system') {
|
|
453
|
+
throw new Error('System messages are only permitted as the first passed message.');
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
throw new Error(`Message type "${message._getType()}" is not supported.`);
|
|
457
|
+
}
|
|
458
|
+
if (messages.isAIMessage(message) && !!message.tool_calls?.length) {
|
|
459
|
+
if (typeof message.content === 'string') {
|
|
460
|
+
if (message.content === '') {
|
|
461
|
+
return {
|
|
462
|
+
role,
|
|
463
|
+
content: message.tool_calls.map(_convertLangChainToolCallToAnthropic),
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
return {
|
|
468
|
+
role,
|
|
469
|
+
content: [
|
|
470
|
+
{ type: 'text', text: message.content },
|
|
471
|
+
...message.tool_calls.map(_convertLangChainToolCallToAnthropic),
|
|
472
|
+
],
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
const { content } = message;
|
|
478
|
+
const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) => content.find((contentPart) => (contentPart.type === 'tool_use' ||
|
|
479
|
+
contentPart.type === 'input_json_delta' ||
|
|
480
|
+
contentPart.type === 'server_tool_use') &&
|
|
481
|
+
contentPart.id === toolCall.id));
|
|
482
|
+
if (hasMismatchedToolCalls) {
|
|
483
|
+
console.warn('The "tool_calls" field on a message is only respected if content is a string.');
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
role,
|
|
487
|
+
content: _formatContent(message),
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
return {
|
|
493
|
+
role,
|
|
494
|
+
content: _formatContent(message),
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
return {
|
|
499
|
+
messages: mergeMessages(formattedMessages),
|
|
500
|
+
system,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function mergeMessages(messages) {
|
|
504
|
+
if (!messages || messages.length <= 1) {
|
|
505
|
+
return messages;
|
|
506
|
+
}
|
|
507
|
+
const result = [];
|
|
508
|
+
let currentMessage = messages[0];
|
|
509
|
+
const normalizeContent = (content) => {
|
|
510
|
+
if (typeof content === 'string') {
|
|
511
|
+
return [
|
|
512
|
+
{
|
|
513
|
+
type: 'text',
|
|
514
|
+
text: content,
|
|
515
|
+
},
|
|
516
|
+
];
|
|
517
|
+
}
|
|
518
|
+
return content;
|
|
519
|
+
};
|
|
520
|
+
const isToolResultMessage = (msg) => {
|
|
521
|
+
if (msg.role !== 'user')
|
|
522
|
+
return false;
|
|
523
|
+
if (typeof msg.content === 'string') {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
return (Array.isArray(msg.content) &&
|
|
527
|
+
msg.content.every((item) => item.type === 'tool_result'));
|
|
528
|
+
};
|
|
529
|
+
for (let i = 1; i < messages.length; i += 1) {
|
|
530
|
+
const nextMessage = messages[i];
|
|
531
|
+
if (isToolResultMessage(currentMessage) &&
|
|
532
|
+
isToolResultMessage(nextMessage)) {
|
|
533
|
+
// Merge the messages by combining their content arrays
|
|
534
|
+
currentMessage = {
|
|
535
|
+
...currentMessage,
|
|
536
|
+
content: [
|
|
537
|
+
...normalizeContent(currentMessage.content),
|
|
538
|
+
...normalizeContent(nextMessage.content),
|
|
539
|
+
],
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
result.push(currentMessage);
|
|
544
|
+
currentMessage = nextMessage;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
result.push(currentMessage);
|
|
548
|
+
return result;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
exports._convertLangChainToolCallToAnthropic = _convertLangChainToolCallToAnthropic;
|
|
552
|
+
exports._convertMessagesToAnthropicPayload = _convertMessagesToAnthropicPayload;
|
|
553
|
+
//# sourceMappingURL=message_inputs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message_inputs.cjs","sources":["../../../../../src/llm/anthropic/utils/message_inputs.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\r\n/* eslint-disable no-console */\r\n/**\r\n * This util file contains functions for converting LangChain messages to Anthropic messages.\r\n */\r\nimport {\r\n type BaseMessage,\r\n type SystemMessage,\r\n HumanMessage,\r\n type AIMessage,\r\n type ToolMessage,\r\n isAIMessage,\r\n type StandardContentBlockConverter,\r\n type StandardTextBlock,\r\n type StandardImageBlock,\r\n type StandardFileBlock,\r\n MessageContentComplex,\r\n isDataContentBlock,\r\n convertToProviderContentBlock,\r\n parseBase64DataUrl,\r\n} from '@langchain/core/messages';\r\nimport { ToolCall } from '@langchain/core/messages/tool';\r\nimport {\r\n AnthropicImageBlockParam,\r\n AnthropicMessageCreateParams,\r\n AnthropicTextBlockParam,\r\n AnthropicToolResultBlockParam,\r\n AnthropicToolUseBlockParam,\r\n AnthropicDocumentBlockParam,\r\n AnthropicThinkingBlockParam,\r\n AnthropicRedactedThinkingBlockParam,\r\n AnthropicServerToolUseBlockParam,\r\n AnthropicWebSearchToolResultBlockParam,\r\n isAnthropicImageBlockParam,\r\n AnthropicSearchResultBlockParam,\r\n AnthropicToolResponse,\r\n} from '../types';\r\n\r\nfunction _formatImage(imageUrl: string) {\r\n const parsed = parseBase64DataUrl({ dataUrl: imageUrl });\r\n if (parsed) {\r\n return {\r\n type: 'base64',\r\n media_type: parsed.mime_type,\r\n data: parsed.data,\r\n };\r\n }\r\n let parsedUrl: URL;\r\n\r\n try {\r\n parsedUrl = new URL(imageUrl);\r\n } catch {\r\n throw new Error(\r\n [\r\n `Malformed image URL: ${JSON.stringify(\r\n imageUrl\r\n )}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,\r\n 'Example: data:image/png;base64,/9j/4AAQSk...',\r\n 'Example: https://example.com/image.jpg',\r\n ].join('\\n\\n')\r\n );\r\n }\r\n\r\n if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {\r\n return {\r\n type: 'url',\r\n url: imageUrl,\r\n };\r\n }\r\n\r\n throw new Error(\r\n [\r\n `Invalid image URL protocol: ${JSON.stringify(\r\n parsedUrl.protocol\r\n )}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,\r\n 'Example: data:image/png;base64,/9j/4AAQSk...',\r\n 'Example: https://example.com/image.jpg',\r\n ].join('\\n\\n')\r\n );\r\n}\r\n\r\nfunction _ensureMessageContents(\r\n messages: BaseMessage[]\r\n): (SystemMessage | HumanMessage | AIMessage)[] {\r\n // Merge runs of human/tool messages into single human messages with content blocks.\r\n const updatedMsgs = [];\r\n for (const message of messages) {\r\n if (message._getType() === 'tool') {\r\n if (typeof message.content === 'string') {\r\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\r\n if (\r\n previousMessage._getType() === 'human' &&\r\n Array.isArray(previousMessage.content) &&\r\n 'type' in previousMessage.content[0] &&\r\n previousMessage.content[0].type === 'tool_result'\r\n ) {\r\n // If the previous message was a tool result, we merge this tool message into it.\r\n (previousMessage.content as MessageContentComplex[]).push({\r\n type: 'tool_result',\r\n content: message.content,\r\n tool_use_id: (message as ToolMessage).tool_call_id,\r\n });\r\n } else {\r\n // If not, we create a new human message with the tool result.\r\n updatedMsgs.push(\r\n new HumanMessage({\r\n content: [\r\n {\r\n type: 'tool_result',\r\n content: message.content,\r\n tool_use_id: (message as ToolMessage).tool_call_id,\r\n },\r\n ],\r\n })\r\n );\r\n }\r\n } else {\r\n updatedMsgs.push(\r\n new HumanMessage({\r\n content: [\r\n {\r\n type: 'tool_result',\r\n // rare case: message.content could be undefined\r\n ...(message.content != null\r\n ? { content: _formatContent(message) }\r\n : {}),\r\n tool_use_id: (message as ToolMessage).tool_call_id,\r\n },\r\n ],\r\n })\r\n );\r\n }\r\n } else {\r\n updatedMsgs.push(message);\r\n }\r\n }\r\n return updatedMsgs;\r\n}\r\n\r\nexport function _convertLangChainToolCallToAnthropic(\r\n toolCall: ToolCall\r\n): AnthropicToolResponse {\r\n if (toolCall.id === undefined) {\r\n throw new Error('Anthropic requires all tool calls to have an \"id\".');\r\n }\r\n return {\r\n type: 'tool_use',\r\n id: toolCall.id,\r\n name: toolCall.name,\r\n input: toolCall.args,\r\n };\r\n}\r\n\r\nconst standardContentBlockConverter: StandardContentBlockConverter<{\r\n text: AnthropicTextBlockParam;\r\n image: AnthropicImageBlockParam;\r\n file: AnthropicDocumentBlockParam;\r\n}> = {\r\n providerName: 'anthropic',\r\n\r\n fromStandardTextBlock(block: StandardTextBlock): AnthropicTextBlockParam {\r\n return {\r\n type: 'text',\r\n text: block.text,\r\n ...('citations' in (block.metadata ?? {})\r\n ? { citations: block.metadata!.citations }\r\n : {}),\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n } as AnthropicTextBlockParam;\r\n },\r\n\r\n fromStandardImageBlock(block: StandardImageBlock): AnthropicImageBlockParam {\r\n if (block.source_type === 'url') {\r\n const data = parseBase64DataUrl({\r\n dataUrl: block.url,\r\n asTypedArray: false,\r\n });\r\n if (data) {\r\n return {\r\n type: 'image',\r\n source: {\r\n type: 'base64',\r\n data: data.data,\r\n media_type: data.mime_type,\r\n },\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n } as AnthropicImageBlockParam;\r\n } else {\r\n return {\r\n type: 'image',\r\n source: {\r\n type: 'url',\r\n url: block.url,\r\n media_type: block.mime_type ?? '',\r\n },\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n } as AnthropicImageBlockParam;\r\n }\r\n } else {\r\n if (block.source_type === 'base64') {\r\n return {\r\n type: 'image',\r\n source: {\r\n type: 'base64',\r\n data: block.data,\r\n media_type: block.mime_type ?? '',\r\n },\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n } as AnthropicImageBlockParam;\r\n } else {\r\n throw new Error(`Unsupported image source type: ${block.source_type}`);\r\n }\r\n }\r\n },\r\n\r\n fromStandardFileBlock(block: StandardFileBlock): AnthropicDocumentBlockParam {\r\n const mime_type = (block.mime_type ?? '').split(';')[0];\r\n\r\n if (block.source_type === 'url') {\r\n if (mime_type === 'application/pdf' || mime_type === '') {\r\n return {\r\n type: 'document',\r\n source: {\r\n type: 'url',\r\n url: block.url,\r\n media_type: block.mime_type ?? '',\r\n },\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n ...('citations' in (block.metadata ?? {})\r\n ? { citations: block.metadata!.citations }\r\n : {}),\r\n ...('context' in (block.metadata ?? {})\r\n ? { context: block.metadata!.context }\r\n : {}),\r\n ...('title' in (block.metadata ?? {})\r\n ? { title: block.metadata!.title }\r\n : {}),\r\n } as AnthropicDocumentBlockParam;\r\n }\r\n throw new Error(\r\n `Unsupported file mime type for file url source: ${block.mime_type}`\r\n );\r\n } else if (block.source_type === 'text') {\r\n if (mime_type === 'text/plain' || mime_type === '') {\r\n return {\r\n type: 'document',\r\n source: {\r\n type: 'text',\r\n data: block.text,\r\n media_type: block.mime_type ?? '',\r\n },\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n ...('citations' in (block.metadata ?? {})\r\n ? { citations: block.metadata!.citations }\r\n : {}),\r\n ...('context' in (block.metadata ?? {})\r\n ? { context: block.metadata!.context }\r\n : {}),\r\n ...('title' in (block.metadata ?? {})\r\n ? { title: block.metadata!.title }\r\n : {}),\r\n } as AnthropicDocumentBlockParam;\r\n } else {\r\n throw new Error(\r\n `Unsupported file mime type for file text source: ${block.mime_type}`\r\n );\r\n }\r\n } else if (block.source_type === 'base64') {\r\n if (mime_type === 'application/pdf' || mime_type === '') {\r\n return {\r\n type: 'document',\r\n source: {\r\n type: 'base64',\r\n data: block.data,\r\n media_type: 'application/pdf',\r\n },\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n ...('citations' in (block.metadata ?? {})\r\n ? { citations: block.metadata!.citations }\r\n : {}),\r\n ...('context' in (block.metadata ?? {})\r\n ? { context: block.metadata!.context }\r\n : {}),\r\n ...('title' in (block.metadata ?? {})\r\n ? { title: block.metadata!.title }\r\n : {}),\r\n } as AnthropicDocumentBlockParam;\r\n } else if (\r\n ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].includes(\r\n mime_type\r\n )\r\n ) {\r\n return {\r\n type: 'document',\r\n source: {\r\n type: 'content',\r\n content: [\r\n {\r\n type: 'image',\r\n source: {\r\n type: 'base64',\r\n data: block.data,\r\n media_type: mime_type as\r\n | 'image/jpeg'\r\n | 'image/png'\r\n | 'image/gif'\r\n | 'image/webp',\r\n },\r\n },\r\n ],\r\n },\r\n ...('cache_control' in (block.metadata ?? {})\r\n ? { cache_control: block.metadata!.cache_control }\r\n : {}),\r\n ...('citations' in (block.metadata ?? {})\r\n ? { citations: block.metadata!.citations }\r\n : {}),\r\n ...('context' in (block.metadata ?? {})\r\n ? { context: block.metadata!.context }\r\n : {}),\r\n ...('title' in (block.metadata ?? {})\r\n ? { title: block.metadata!.title }\r\n : {}),\r\n } as AnthropicDocumentBlockParam;\r\n } else {\r\n throw new Error(\r\n `Unsupported file mime type for file base64 source: ${block.mime_type}`\r\n );\r\n }\r\n } else {\r\n throw new Error(`Unsupported file source type: ${block.source_type}`);\r\n }\r\n },\r\n};\r\n\r\nfunction _formatContent(message: BaseMessage) {\r\n const toolTypes = [\r\n 'tool_use',\r\n 'tool_result',\r\n 'input_json_delta',\r\n 'server_tool_use',\r\n 'web_search_tool_result',\r\n 'web_search_result',\r\n ];\r\n const textTypes = ['text', 'text_delta'];\r\n const { content } = message;\r\n\r\n if (typeof content === 'string') {\r\n return content;\r\n } else {\r\n const contentBlocks = content.map((contentPart) => {\r\n if (isDataContentBlock(contentPart)) {\r\n return convertToProviderContentBlock(\r\n contentPart,\r\n standardContentBlockConverter\r\n );\r\n }\r\n\r\n const cacheControl =\r\n 'cache_control' in contentPart ? contentPart.cache_control : undefined;\r\n\r\n if (contentPart.type === 'image_url') {\r\n let source;\r\n if (typeof contentPart.image_url === 'string') {\r\n source = _formatImage(contentPart.image_url);\r\n } else {\r\n source = _formatImage(contentPart.image_url.url);\r\n }\r\n return {\r\n type: 'image' as const, // Explicitly setting the type as \"image\"\r\n source,\r\n ...(cacheControl ? { cache_control: cacheControl } : {}),\r\n };\r\n } else if (isAnthropicImageBlockParam(contentPart)) {\r\n return contentPart;\r\n } else if (contentPart.type === 'document') {\r\n // PDF\r\n return {\r\n ...contentPart,\r\n ...(cacheControl ? { cache_control: cacheControl } : {}),\r\n };\r\n } else if (contentPart.type === 'thinking') {\r\n const block: AnthropicThinkingBlockParam = {\r\n type: 'thinking' as const, // Explicitly setting the type as \"thinking\"\r\n thinking: contentPart.thinking,\r\n signature: contentPart.signature,\r\n ...(cacheControl ? { cache_control: cacheControl } : {}),\r\n };\r\n return block;\r\n } else if (contentPart.type === 'redacted_thinking') {\r\n const block: AnthropicRedactedThinkingBlockParam = {\r\n type: 'redacted_thinking' as const, // Explicitly setting the type as \"redacted_thinking\"\r\n data: contentPart.data,\r\n ...(cacheControl ? { cache_control: cacheControl } : {}),\r\n };\r\n return block;\r\n } else if (contentPart.type === 'search_result') {\r\n const block: AnthropicSearchResultBlockParam = {\r\n type: 'search_result' as const, // Explicitly setting the type as \"search_result\"\r\n title: contentPart.title,\r\n source: contentPart.source,\r\n ...('cache_control' in contentPart && contentPart.cache_control\r\n ? { cache_control: contentPart.cache_control }\r\n : {}),\r\n ...('citations' in contentPart && contentPart.citations\r\n ? { citations: contentPart.citations }\r\n : {}),\r\n content: contentPart.content,\r\n };\r\n return block;\r\n } else if (\r\n textTypes.find((t) => t === contentPart.type) &&\r\n 'text' in contentPart\r\n ) {\r\n // Assuming contentPart is of type MessageContentText here\r\n return {\r\n type: 'text' as const, // Explicitly setting the type as \"text\"\r\n text: contentPart.text,\r\n ...(cacheControl ? { cache_control: cacheControl } : {}),\r\n ...('citations' in contentPart && contentPart.citations\r\n ? { citations: contentPart.citations }\r\n : {}),\r\n };\r\n } else if (toolTypes.find((t) => t === contentPart.type)) {\r\n const contentPartCopy = { ...contentPart };\r\n if ('index' in contentPartCopy) {\r\n // Anthropic does not support passing the index field here, so we remove it.\r\n delete contentPartCopy.index;\r\n }\r\n\r\n if (contentPartCopy.type === 'input_json_delta') {\r\n // `input_json_delta` type only represents yielding partial tool inputs\r\n // and is not a valid type for Anthropic messages.\r\n contentPartCopy.type = 'tool_use';\r\n }\r\n\r\n if ('input' in contentPartCopy) {\r\n // Anthropic tool use inputs should be valid objects, when applicable.\r\n if (typeof contentPartCopy.input === 'string') {\r\n try {\r\n contentPartCopy.input = JSON.parse(contentPartCopy.input);\r\n } catch {\r\n contentPartCopy.input = {};\r\n }\r\n }\r\n }\r\n\r\n // TODO: Fix when SDK types are fixed\r\n return {\r\n ...contentPartCopy,\r\n ...(cacheControl ? { cache_control: cacheControl } : {}),\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n } as any;\r\n } else if (\r\n 'functionCall' in contentPart &&\r\n contentPart.functionCall &&\r\n typeof contentPart.functionCall === 'object' &&\r\n isAIMessage(message)\r\n ) {\r\n const correspondingToolCall = message.tool_calls?.find(\r\n (toolCall) => toolCall.name === contentPart.functionCall.name\r\n );\r\n if (!correspondingToolCall) {\r\n throw new Error(\r\n `Could not find tool call for function call ${contentPart.functionCall.name}`\r\n );\r\n }\r\n // Google GenAI models include a `functionCall` object inside content. We should ignore it as Anthropic will not support it.\r\n return {\r\n id: correspondingToolCall.id,\r\n type: 'tool_use',\r\n name: correspondingToolCall.name,\r\n input: contentPart.functionCall.args,\r\n };\r\n } else {\r\n throw new Error('Unsupported message content format');\r\n }\r\n });\r\n return contentBlocks;\r\n }\r\n}\r\n\r\n/**\r\n * Formats messages as a prompt for the model.\r\n * Used in LangSmith, export is important here.\r\n * @param messages The base messages to format as a prompt.\r\n * @returns The formatted prompt.\r\n */\r\nexport function _convertMessagesToAnthropicPayload(\r\n messages: BaseMessage[]\r\n): AnthropicMessageCreateParams {\r\n const mergedMessages = _ensureMessageContents(messages);\r\n let system;\r\n if (mergedMessages.length > 0 && mergedMessages[0]._getType() === 'system') {\r\n system = messages[0].content;\r\n }\r\n const conversationMessages =\r\n system !== undefined ? mergedMessages.slice(1) : mergedMessages;\r\n const formattedMessages = conversationMessages.map((message) => {\r\n let role;\r\n if (message._getType() === 'human') {\r\n role = 'user' as const;\r\n } else if (message._getType() === 'ai') {\r\n role = 'assistant' as const;\r\n } else if (message._getType() === 'tool') {\r\n role = 'user' as const;\r\n } else if (message._getType() === 'system') {\r\n throw new Error(\r\n 'System messages are only permitted as the first passed message.'\r\n );\r\n } else {\r\n throw new Error(`Message type \"${message._getType()}\" is not supported.`);\r\n }\r\n if (isAIMessage(message) && !!message.tool_calls?.length) {\r\n if (typeof message.content === 'string') {\r\n if (message.content === '') {\r\n return {\r\n role,\r\n content: message.tool_calls.map(\r\n _convertLangChainToolCallToAnthropic\r\n ),\r\n };\r\n } else {\r\n return {\r\n role,\r\n content: [\r\n { type: 'text', text: message.content },\r\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\r\n ],\r\n };\r\n }\r\n } else {\r\n const { content } = message;\r\n const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) =>\r\n content.find(\r\n (contentPart) =>\r\n (contentPart.type === 'tool_use' ||\r\n contentPart.type === 'input_json_delta' ||\r\n contentPart.type === 'server_tool_use') &&\r\n contentPart.id === toolCall.id\r\n )\r\n );\r\n if (hasMismatchedToolCalls) {\r\n console.warn(\r\n 'The \"tool_calls\" field on a message is only respected if content is a string.'\r\n );\r\n }\r\n return {\r\n role,\r\n content: _formatContent(message),\r\n };\r\n }\r\n } else {\r\n return {\r\n role,\r\n content: _formatContent(message),\r\n };\r\n }\r\n });\r\n return {\r\n messages: mergeMessages(formattedMessages),\r\n system,\r\n } as AnthropicMessageCreateParams;\r\n}\r\n\r\nfunction mergeMessages(messages: AnthropicMessageCreateParams['messages']) {\r\n if (!messages || messages.length <= 1) {\r\n return messages;\r\n }\r\n\r\n const result: AnthropicMessageCreateParams['messages'] = [];\r\n let currentMessage = messages[0];\r\n\r\n const normalizeContent = (\r\n content:\r\n | string\r\n | Array<\r\n | AnthropicTextBlockParam\r\n | AnthropicImageBlockParam\r\n | AnthropicToolUseBlockParam\r\n | AnthropicToolResultBlockParam\r\n | AnthropicDocumentBlockParam\r\n | AnthropicThinkingBlockParam\r\n | AnthropicRedactedThinkingBlockParam\r\n | AnthropicServerToolUseBlockParam\r\n | AnthropicWebSearchToolResultBlockParam\r\n >\r\n ): Array<\r\n | AnthropicTextBlockParam\r\n | AnthropicImageBlockParam\r\n | AnthropicToolUseBlockParam\r\n | AnthropicToolResultBlockParam\r\n | AnthropicDocumentBlockParam\r\n | AnthropicThinkingBlockParam\r\n | AnthropicRedactedThinkingBlockParam\r\n | AnthropicServerToolUseBlockParam\r\n | AnthropicWebSearchToolResultBlockParam\r\n > => {\r\n if (typeof content === 'string') {\r\n return [\r\n {\r\n type: 'text',\r\n text: content,\r\n },\r\n ];\r\n }\r\n return content;\r\n };\r\n\r\n const isToolResultMessage = (msg: (typeof messages)[0]) => {\r\n if (msg.role !== 'user') return false;\r\n\r\n if (typeof msg.content === 'string') {\r\n return false;\r\n }\r\n\r\n return (\r\n Array.isArray(msg.content) &&\r\n msg.content.every((item) => item.type === 'tool_result')\r\n );\r\n };\r\n\r\n for (let i = 1; i < messages.length; i += 1) {\r\n const nextMessage = messages[i];\r\n\r\n if (\r\n isToolResultMessage(currentMessage) &&\r\n isToolResultMessage(nextMessage)\r\n ) {\r\n // Merge the messages by combining their content arrays\r\n currentMessage = {\r\n ...currentMessage,\r\n content: [\r\n ...normalizeContent(currentMessage.content),\r\n ...normalizeContent(nextMessage.content),\r\n ],\r\n };\r\n } else {\r\n result.push(currentMessage);\r\n currentMessage = nextMessage;\r\n }\r\n }\r\n\r\n result.push(currentMessage);\r\n return result;\r\n}\r\n"],"names":["parseBase64DataUrl","messages","HumanMessage","isDataContentBlock","convertToProviderContentBlock","isAnthropicImageBlockParam","isAIMessage"],"mappings":";;;;;AAAA;AACA;AACA;;AAEG;AAkCH,SAAS,YAAY,CAAC,QAAgB,EAAA;IACpC,MAAM,MAAM,GAAGA,2BAAkB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IACxD,IAAI,MAAM,EAAE;QACV,OAAO;AACL,YAAA,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,MAAM,CAAC,SAAS;YAC5B,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;;AAEH,IAAA,IAAI,SAAc;AAElB,IAAA,IAAI;AACF,QAAA,SAAS,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC;;AAC7B,IAAA,MAAM;QACN,MAAM,IAAI,KAAK,CACb;AACE,YAAA,CAAA,qBAAA,EAAwB,IAAI,CAAC,SAAS,CACpC,QAAQ,CACT,CAA+F,6FAAA,CAAA;YAChG,8CAA8C;YAC9C,wCAAwC;AACzC,SAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CACf;;AAGH,IAAA,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE;QACrE,OAAO;AACL,YAAA,IAAI,EAAE,KAAK;AACX,YAAA,GAAG,EAAE,QAAQ;SACd;;IAGH,MAAM,IAAI,KAAK,CACb;QACE,CAA+B,4BAAA,EAAA,IAAI,CAAC,SAAS,CAC3C,SAAS,CAAC,QAAQ,CACnB,CAA6G,2GAAA,CAAA;QAC9G,8CAA8C;QAC9C,wCAAwC;AACzC,KAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CACf;AACH;AAEA,SAAS,sBAAsB,CAC7BC,UAAuB,EAAA;;IAGvB,MAAM,WAAW,GAAG,EAAE;AACtB,IAAA,KAAK,M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