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,604 @@
|
|
|
1
|
+
import { AzureOpenAI } from 'openai';
|
|
2
|
+
import { AIMessageChunk } from '@langchain/core/messages';
|
|
3
|
+
import { ChatXAI as ChatXAI$1 } from '@langchain/xai';
|
|
4
|
+
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
5
|
+
import '@langchain/core/utils/function_calling';
|
|
6
|
+
import { ChatDeepSeek as ChatDeepSeek$1 } from '@langchain/deepseek';
|
|
7
|
+
import { getEndpoint, AzureChatOpenAI as AzureChatOpenAI$1, ChatOpenAI as ChatOpenAI$1, OpenAIClient } from '@langchain/openai';
|
|
8
|
+
import { isReasoningModel, _convertMessagesToOpenAIResponsesParams, _convertOpenAIResponsesDeltaToBaseMessageChunk, _convertMessagesToOpenAIParams } from './utils/index.mjs';
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
11
|
+
const iife = (fn) => fn();
|
|
12
|
+
function isHeaders(headers) {
|
|
13
|
+
return (typeof Headers !== 'undefined' &&
|
|
14
|
+
headers !== null &&
|
|
15
|
+
typeof headers === 'object' &&
|
|
16
|
+
Object.prototype.toString.call(headers) === '[object Headers]');
|
|
17
|
+
}
|
|
18
|
+
function normalizeHeaders(headers) {
|
|
19
|
+
const output = iife(() => {
|
|
20
|
+
// If headers is a Headers instance
|
|
21
|
+
if (isHeaders(headers)) {
|
|
22
|
+
return headers;
|
|
23
|
+
}
|
|
24
|
+
// If headers is an array of [key, value] pairs
|
|
25
|
+
else if (Array.isArray(headers)) {
|
|
26
|
+
return new Headers(headers);
|
|
27
|
+
}
|
|
28
|
+
// If headers is a NullableHeaders-like object (has 'values' property that is a Headers)
|
|
29
|
+
else if (typeof headers === 'object' &&
|
|
30
|
+
headers !== null &&
|
|
31
|
+
'values' in headers &&
|
|
32
|
+
isHeaders(headers.values)) {
|
|
33
|
+
return headers.values;
|
|
34
|
+
}
|
|
35
|
+
// If headers is a plain object
|
|
36
|
+
else if (typeof headers === 'object' && headers !== null) {
|
|
37
|
+
const entries = Object.entries(headers)
|
|
38
|
+
.filter(([, v]) => typeof v === 'string')
|
|
39
|
+
.map(([k, v]) => [k, v]);
|
|
40
|
+
return new Headers(entries);
|
|
41
|
+
}
|
|
42
|
+
return new Headers();
|
|
43
|
+
});
|
|
44
|
+
return Object.fromEntries(output.entries());
|
|
45
|
+
}
|
|
46
|
+
function createAbortHandler(controller) {
|
|
47
|
+
return function () {
|
|
48
|
+
controller.abort();
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
class CustomOpenAIClient extends OpenAIClient {
|
|
52
|
+
abortHandler;
|
|
53
|
+
async fetchWithTimeout(url, init, ms, controller) {
|
|
54
|
+
const { signal, ...options } = init || {};
|
|
55
|
+
const handler = createAbortHandler(controller);
|
|
56
|
+
this.abortHandler = handler;
|
|
57
|
+
if (signal)
|
|
58
|
+
signal.addEventListener('abort', handler, { once: true });
|
|
59
|
+
const timeout = setTimeout(() => handler, ms);
|
|
60
|
+
const fetchOptions = {
|
|
61
|
+
signal: controller.signal,
|
|
62
|
+
...options,
|
|
63
|
+
};
|
|
64
|
+
if (fetchOptions.method != null) {
|
|
65
|
+
// Custom methods like 'patch' need to be uppercased
|
|
66
|
+
// See https://github.com/nodejs/undici/issues/2294
|
|
67
|
+
fetchOptions.method = fetchOptions.method.toUpperCase();
|
|
68
|
+
}
|
|
69
|
+
return (
|
|
70
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
72
|
+
/** @ts-ignore */
|
|
73
|
+
this.fetch.call(undefined, url, fetchOptions).finally(() => {
|
|
74
|
+
clearTimeout(timeout);
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class CustomAzureOpenAIClient extends AzureOpenAI {
|
|
79
|
+
abortHandler;
|
|
80
|
+
async fetchWithTimeout(url, init, ms, controller) {
|
|
81
|
+
const { signal, ...options } = init || {};
|
|
82
|
+
const handler = createAbortHandler(controller);
|
|
83
|
+
this.abortHandler = handler;
|
|
84
|
+
if (signal)
|
|
85
|
+
signal.addEventListener('abort', handler, { once: true });
|
|
86
|
+
const timeout = setTimeout(() => handler, ms);
|
|
87
|
+
const fetchOptions = {
|
|
88
|
+
signal: controller.signal,
|
|
89
|
+
...options,
|
|
90
|
+
};
|
|
91
|
+
if (fetchOptions.method != null) {
|
|
92
|
+
// Custom methods like 'patch' need to be uppercased
|
|
93
|
+
// See https://github.com/nodejs/undici/issues/2294
|
|
94
|
+
fetchOptions.method = fetchOptions.method.toUpperCase();
|
|
95
|
+
}
|
|
96
|
+
return (
|
|
97
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
99
|
+
/** @ts-ignore */
|
|
100
|
+
this.fetch.call(undefined, url, fetchOptions).finally(() => {
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
106
|
+
class ChatOpenAI extends ChatOpenAI$1 {
|
|
107
|
+
get exposedClient() {
|
|
108
|
+
return this.client;
|
|
109
|
+
}
|
|
110
|
+
static lc_name() {
|
|
111
|
+
return 'IllumaOpenAI';
|
|
112
|
+
}
|
|
113
|
+
_getClientOptions(options) {
|
|
114
|
+
if (!this.client) {
|
|
115
|
+
const openAIEndpointConfig = {
|
|
116
|
+
baseURL: this.clientConfig.baseURL,
|
|
117
|
+
};
|
|
118
|
+
const endpoint = getEndpoint(openAIEndpointConfig);
|
|
119
|
+
const params = {
|
|
120
|
+
...this.clientConfig,
|
|
121
|
+
baseURL: endpoint,
|
|
122
|
+
timeout: this.timeout,
|
|
123
|
+
maxRetries: 0,
|
|
124
|
+
};
|
|
125
|
+
if (params.baseURL == null) {
|
|
126
|
+
delete params.baseURL;
|
|
127
|
+
}
|
|
128
|
+
this.client = new CustomOpenAIClient(params);
|
|
129
|
+
}
|
|
130
|
+
const requestOptions = {
|
|
131
|
+
...this.clientConfig,
|
|
132
|
+
...options,
|
|
133
|
+
};
|
|
134
|
+
return requestOptions;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns backwards compatible reasoning parameters from constructor params and call options
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
getReasoningParams(options) {
|
|
141
|
+
// apply options in reverse order of importance -- newer options supersede older options
|
|
142
|
+
let reasoning;
|
|
143
|
+
if (this.reasoning !== undefined) {
|
|
144
|
+
reasoning = {
|
|
145
|
+
...reasoning,
|
|
146
|
+
...this.reasoning,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (options?.reasoning !== undefined) {
|
|
150
|
+
reasoning = {
|
|
151
|
+
...reasoning,
|
|
152
|
+
...options.reasoning,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return reasoning;
|
|
156
|
+
}
|
|
157
|
+
_getReasoningParams(options) {
|
|
158
|
+
return this.getReasoningParams(options);
|
|
159
|
+
}
|
|
160
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
161
|
+
if (!this._useResponseApi(options)) {
|
|
162
|
+
return yield* this._streamResponseChunks2(messages, options, runManager);
|
|
163
|
+
}
|
|
164
|
+
const streamIterable = await this.responseApiWithRetry({
|
|
165
|
+
...this.invocationParams(options, { streaming: true }),
|
|
166
|
+
input: _convertMessagesToOpenAIResponsesParams(messages, this.model, this.zdrEnabled),
|
|
167
|
+
stream: true,
|
|
168
|
+
}, options);
|
|
169
|
+
for await (const data of streamIterable) {
|
|
170
|
+
const chunk = _convertOpenAIResponsesDeltaToBaseMessageChunk(data);
|
|
171
|
+
if (chunk == null)
|
|
172
|
+
continue;
|
|
173
|
+
yield chunk;
|
|
174
|
+
await runManager?.handleLLMNewToken(chunk.text || '', undefined, undefined, undefined, undefined, { chunk });
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
async *_streamResponseChunks2(messages, options, runManager) {
|
|
179
|
+
const messagesMapped = _convertMessagesToOpenAIParams(messages, this.model);
|
|
180
|
+
const params = {
|
|
181
|
+
...this.invocationParams(options, {
|
|
182
|
+
streaming: true,
|
|
183
|
+
}),
|
|
184
|
+
messages: messagesMapped,
|
|
185
|
+
stream: true,
|
|
186
|
+
};
|
|
187
|
+
let defaultRole;
|
|
188
|
+
const streamIterable = await this.completionWithRetry(params, options);
|
|
189
|
+
let usage;
|
|
190
|
+
for await (const data of streamIterable) {
|
|
191
|
+
const choice = data.choices[0];
|
|
192
|
+
if (data.usage) {
|
|
193
|
+
usage = data.usage;
|
|
194
|
+
}
|
|
195
|
+
if (!choice) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const { delta } = choice;
|
|
199
|
+
if (!delta) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const chunk = this._convertOpenAIDeltaToBaseMessageChunk(delta, data, defaultRole);
|
|
203
|
+
if ('reasoning_content' in delta) {
|
|
204
|
+
chunk.additional_kwargs.reasoning_content = delta.reasoning_content;
|
|
205
|
+
}
|
|
206
|
+
else if ('reasoning' in delta) {
|
|
207
|
+
chunk.additional_kwargs.reasoning_content = delta.reasoning;
|
|
208
|
+
}
|
|
209
|
+
if ('provider_specific_fields' in delta) {
|
|
210
|
+
chunk.additional_kwargs.provider_specific_fields =
|
|
211
|
+
delta.provider_specific_fields;
|
|
212
|
+
}
|
|
213
|
+
defaultRole = delta.role ?? defaultRole;
|
|
214
|
+
const newTokenIndices = {
|
|
215
|
+
prompt: options.promptIndex ?? 0,
|
|
216
|
+
completion: choice.index ?? 0,
|
|
217
|
+
};
|
|
218
|
+
if (typeof chunk.content !== 'string') {
|
|
219
|
+
// eslint-disable-next-line no-console
|
|
220
|
+
console.log('[WARNING]: Received non-string content from OpenAI. This is currently not supported.');
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
|
+
const generationInfo = { ...newTokenIndices };
|
|
225
|
+
if (choice.finish_reason != null) {
|
|
226
|
+
generationInfo.finish_reason = choice.finish_reason;
|
|
227
|
+
// Only include system fingerprint in the last chunk for now
|
|
228
|
+
// to avoid concatenation issues
|
|
229
|
+
generationInfo.system_fingerprint = data.system_fingerprint;
|
|
230
|
+
generationInfo.model_name = data.model;
|
|
231
|
+
generationInfo.service_tier = data.service_tier;
|
|
232
|
+
}
|
|
233
|
+
if (this.logprobs == true) {
|
|
234
|
+
generationInfo.logprobs = choice.logprobs;
|
|
235
|
+
}
|
|
236
|
+
const generationChunk = new ChatGenerationChunk({
|
|
237
|
+
message: chunk,
|
|
238
|
+
text: chunk.content,
|
|
239
|
+
generationInfo,
|
|
240
|
+
});
|
|
241
|
+
yield generationChunk;
|
|
242
|
+
await runManager?.handleLLMNewToken(generationChunk.text || '', newTokenIndices, undefined, undefined, undefined, { chunk: generationChunk });
|
|
243
|
+
}
|
|
244
|
+
if (usage) {
|
|
245
|
+
const inputTokenDetails = {
|
|
246
|
+
...(usage.prompt_tokens_details?.audio_tokens != null && {
|
|
247
|
+
audio: usage.prompt_tokens_details.audio_tokens,
|
|
248
|
+
}),
|
|
249
|
+
...(usage.prompt_tokens_details?.cached_tokens != null && {
|
|
250
|
+
cache_read: usage.prompt_tokens_details.cached_tokens,
|
|
251
|
+
}),
|
|
252
|
+
};
|
|
253
|
+
const outputTokenDetails = {
|
|
254
|
+
...(usage.completion_tokens_details?.audio_tokens != null && {
|
|
255
|
+
audio: usage.completion_tokens_details.audio_tokens,
|
|
256
|
+
}),
|
|
257
|
+
...(usage.completion_tokens_details?.reasoning_tokens != null && {
|
|
258
|
+
reasoning: usage.completion_tokens_details.reasoning_tokens,
|
|
259
|
+
}),
|
|
260
|
+
};
|
|
261
|
+
const generationChunk = new ChatGenerationChunk({
|
|
262
|
+
message: new AIMessageChunk({
|
|
263
|
+
content: '',
|
|
264
|
+
response_metadata: {
|
|
265
|
+
usage: { ...usage },
|
|
266
|
+
},
|
|
267
|
+
usage_metadata: {
|
|
268
|
+
input_tokens: usage.prompt_tokens,
|
|
269
|
+
output_tokens: usage.completion_tokens,
|
|
270
|
+
total_tokens: usage.total_tokens,
|
|
271
|
+
...(Object.keys(inputTokenDetails).length > 0 && {
|
|
272
|
+
input_token_details: inputTokenDetails,
|
|
273
|
+
}),
|
|
274
|
+
...(Object.keys(outputTokenDetails).length > 0 && {
|
|
275
|
+
output_token_details: outputTokenDetails,
|
|
276
|
+
}),
|
|
277
|
+
},
|
|
278
|
+
}),
|
|
279
|
+
text: '',
|
|
280
|
+
});
|
|
281
|
+
yield generationChunk;
|
|
282
|
+
}
|
|
283
|
+
if (options.signal?.aborted === true) {
|
|
284
|
+
throw new Error('AbortError');
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
289
|
+
class AzureChatOpenAI extends AzureChatOpenAI$1 {
|
|
290
|
+
get exposedClient() {
|
|
291
|
+
return this.client;
|
|
292
|
+
}
|
|
293
|
+
static lc_name() {
|
|
294
|
+
return 'IllumaAzureOpenAI';
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns backwards compatible reasoning parameters from constructor params and call options
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
getReasoningParams(options) {
|
|
301
|
+
if (!isReasoningModel(this.model)) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
// apply options in reverse order of importance -- newer options supersede older options
|
|
305
|
+
let reasoning;
|
|
306
|
+
if (this.reasoning !== undefined) {
|
|
307
|
+
reasoning = {
|
|
308
|
+
...reasoning,
|
|
309
|
+
...this.reasoning,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (options?.reasoning !== undefined) {
|
|
313
|
+
reasoning = {
|
|
314
|
+
...reasoning,
|
|
315
|
+
...options.reasoning,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
return reasoning;
|
|
319
|
+
}
|
|
320
|
+
_getReasoningParams(options) {
|
|
321
|
+
return this.getReasoningParams(options);
|
|
322
|
+
}
|
|
323
|
+
_getClientOptions(options) {
|
|
324
|
+
if (!this.client) {
|
|
325
|
+
const openAIEndpointConfig = {
|
|
326
|
+
azureOpenAIApiDeploymentName: this.azureOpenAIApiDeploymentName,
|
|
327
|
+
azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
|
|
328
|
+
azureOpenAIApiKey: this.azureOpenAIApiKey,
|
|
329
|
+
azureOpenAIBasePath: this.azureOpenAIBasePath,
|
|
330
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
331
|
+
baseURL: this.clientConfig.baseURL,
|
|
332
|
+
};
|
|
333
|
+
const endpoint = getEndpoint(openAIEndpointConfig);
|
|
334
|
+
const params = {
|
|
335
|
+
...this.clientConfig,
|
|
336
|
+
baseURL: endpoint,
|
|
337
|
+
timeout: this.timeout,
|
|
338
|
+
maxRetries: 0,
|
|
339
|
+
};
|
|
340
|
+
if (!this.azureADTokenProvider) {
|
|
341
|
+
params.apiKey = openAIEndpointConfig.azureOpenAIApiKey;
|
|
342
|
+
}
|
|
343
|
+
if (params.baseURL == null) {
|
|
344
|
+
delete params.baseURL;
|
|
345
|
+
}
|
|
346
|
+
const defaultHeaders = normalizeHeaders(params.defaultHeaders);
|
|
347
|
+
params.defaultHeaders = {
|
|
348
|
+
...params.defaultHeaders,
|
|
349
|
+
'User-Agent': defaultHeaders['User-Agent'] != null
|
|
350
|
+
? `${defaultHeaders['User-Agent']}: illuma-azure-openai-v2`
|
|
351
|
+
: 'illuma-azure-openai-v2',
|
|
352
|
+
};
|
|
353
|
+
this.client = new CustomAzureOpenAIClient({
|
|
354
|
+
apiVersion: this.azureOpenAIApiVersion,
|
|
355
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
356
|
+
...params,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
const requestOptions = {
|
|
360
|
+
...this.clientConfig,
|
|
361
|
+
...options,
|
|
362
|
+
};
|
|
363
|
+
if (this.azureOpenAIApiKey != null) {
|
|
364
|
+
requestOptions.headers = {
|
|
365
|
+
'api-key': this.azureOpenAIApiKey,
|
|
366
|
+
...requestOptions.headers,
|
|
367
|
+
};
|
|
368
|
+
requestOptions.query = {
|
|
369
|
+
'api-version': this.azureOpenAIApiVersion,
|
|
370
|
+
...requestOptions.query,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
return requestOptions;
|
|
374
|
+
}
|
|
375
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
376
|
+
if (!this._useResponseApi(options)) {
|
|
377
|
+
return yield* super._streamResponseChunks(messages, options, runManager);
|
|
378
|
+
}
|
|
379
|
+
const streamIterable = await this.responseApiWithRetry({
|
|
380
|
+
...this.invocationParams(options, { streaming: true }),
|
|
381
|
+
input: _convertMessagesToOpenAIResponsesParams(messages, this.model, this.zdrEnabled),
|
|
382
|
+
stream: true,
|
|
383
|
+
}, options);
|
|
384
|
+
for await (const data of streamIterable) {
|
|
385
|
+
const chunk = _convertOpenAIResponsesDeltaToBaseMessageChunk(data);
|
|
386
|
+
if (chunk == null)
|
|
387
|
+
continue;
|
|
388
|
+
yield chunk;
|
|
389
|
+
await runManager?.handleLLMNewToken(chunk.text || '', undefined, undefined, undefined, undefined, { chunk });
|
|
390
|
+
}
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
class ChatDeepSeek extends ChatDeepSeek$1 {
|
|
395
|
+
get exposedClient() {
|
|
396
|
+
return this.client;
|
|
397
|
+
}
|
|
398
|
+
static lc_name() {
|
|
399
|
+
return 'IllumaDeepSeek';
|
|
400
|
+
}
|
|
401
|
+
_getClientOptions(options) {
|
|
402
|
+
if (!this.client) {
|
|
403
|
+
const openAIEndpointConfig = {
|
|
404
|
+
baseURL: this.clientConfig.baseURL,
|
|
405
|
+
};
|
|
406
|
+
const endpoint = getEndpoint(openAIEndpointConfig);
|
|
407
|
+
const params = {
|
|
408
|
+
...this.clientConfig,
|
|
409
|
+
baseURL: endpoint,
|
|
410
|
+
timeout: this.timeout,
|
|
411
|
+
maxRetries: 0,
|
|
412
|
+
};
|
|
413
|
+
if (params.baseURL == null) {
|
|
414
|
+
delete params.baseURL;
|
|
415
|
+
}
|
|
416
|
+
this.client = new CustomOpenAIClient(params);
|
|
417
|
+
}
|
|
418
|
+
const requestOptions = {
|
|
419
|
+
...this.clientConfig,
|
|
420
|
+
...options,
|
|
421
|
+
};
|
|
422
|
+
return requestOptions;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
class ChatXAI extends ChatXAI$1 {
|
|
426
|
+
constructor(fields) {
|
|
427
|
+
super(fields);
|
|
428
|
+
const customBaseURL = fields?.configuration?.baseURL ?? fields?.clientConfig?.baseURL;
|
|
429
|
+
if (customBaseURL != null && customBaseURL) {
|
|
430
|
+
this.clientConfig = {
|
|
431
|
+
...this.clientConfig,
|
|
432
|
+
baseURL: customBaseURL,
|
|
433
|
+
};
|
|
434
|
+
// Reset the client to force recreation with new config
|
|
435
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
436
|
+
this.client = undefined;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
static lc_name() {
|
|
440
|
+
return 'IllumaXAI';
|
|
441
|
+
}
|
|
442
|
+
get exposedClient() {
|
|
443
|
+
return this.client;
|
|
444
|
+
}
|
|
445
|
+
_getClientOptions(options) {
|
|
446
|
+
if (!this.client) {
|
|
447
|
+
const openAIEndpointConfig = {
|
|
448
|
+
baseURL: this.clientConfig.baseURL,
|
|
449
|
+
};
|
|
450
|
+
const endpoint = getEndpoint(openAIEndpointConfig);
|
|
451
|
+
const params = {
|
|
452
|
+
...this.clientConfig,
|
|
453
|
+
baseURL: endpoint,
|
|
454
|
+
timeout: this.timeout,
|
|
455
|
+
maxRetries: 0,
|
|
456
|
+
};
|
|
457
|
+
if (params.baseURL == null) {
|
|
458
|
+
delete params.baseURL;
|
|
459
|
+
}
|
|
460
|
+
this.client = new CustomOpenAIClient(params);
|
|
461
|
+
}
|
|
462
|
+
const requestOptions = {
|
|
463
|
+
...this.clientConfig,
|
|
464
|
+
...options,
|
|
465
|
+
};
|
|
466
|
+
return requestOptions;
|
|
467
|
+
}
|
|
468
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
469
|
+
const messagesMapped = _convertMessagesToOpenAIParams(messages, this.model);
|
|
470
|
+
const params = {
|
|
471
|
+
...this.invocationParams(options, {
|
|
472
|
+
streaming: true,
|
|
473
|
+
}),
|
|
474
|
+
messages: messagesMapped,
|
|
475
|
+
stream: true,
|
|
476
|
+
};
|
|
477
|
+
let defaultRole;
|
|
478
|
+
const streamIterable = await this.completionWithRetry(params, options);
|
|
479
|
+
let usage;
|
|
480
|
+
for await (const data of streamIterable) {
|
|
481
|
+
const choice = data.choices[0];
|
|
482
|
+
if (data.usage) {
|
|
483
|
+
usage = data.usage;
|
|
484
|
+
}
|
|
485
|
+
if (!choice) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
const { delta } = choice;
|
|
489
|
+
if (!delta) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
const chunk = this._convertOpenAIDeltaToBaseMessageChunk(delta, data, defaultRole);
|
|
493
|
+
if (chunk.usage_metadata != null) {
|
|
494
|
+
chunk.usage_metadata = {
|
|
495
|
+
input_tokens: chunk.usage_metadata.input_tokens ?? 0,
|
|
496
|
+
output_tokens: chunk.usage_metadata.output_tokens ?? 0,
|
|
497
|
+
total_tokens: chunk.usage_metadata.total_tokens ?? 0,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
if ('reasoning_content' in delta) {
|
|
501
|
+
chunk.additional_kwargs.reasoning_content = delta.reasoning_content;
|
|
502
|
+
}
|
|
503
|
+
defaultRole = delta.role ?? defaultRole;
|
|
504
|
+
const newTokenIndices = {
|
|
505
|
+
prompt: options.promptIndex ?? 0,
|
|
506
|
+
completion: choice.index ?? 0,
|
|
507
|
+
};
|
|
508
|
+
if (typeof chunk.content !== 'string') {
|
|
509
|
+
// eslint-disable-next-line no-console
|
|
510
|
+
console.log('[WARNING]: Received non-string content from OpenAI. This is currently not supported.');
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
514
|
+
const generationInfo = { ...newTokenIndices };
|
|
515
|
+
if (choice.finish_reason != null) {
|
|
516
|
+
generationInfo.finish_reason = choice.finish_reason;
|
|
517
|
+
// Only include system fingerprint in the last chunk for now
|
|
518
|
+
// to avoid concatenation issues
|
|
519
|
+
generationInfo.system_fingerprint = data.system_fingerprint;
|
|
520
|
+
generationInfo.model_name = data.model;
|
|
521
|
+
generationInfo.service_tier = data.service_tier;
|
|
522
|
+
}
|
|
523
|
+
if (this.logprobs == true) {
|
|
524
|
+
generationInfo.logprobs = choice.logprobs;
|
|
525
|
+
}
|
|
526
|
+
const generationChunk = new ChatGenerationChunk({
|
|
527
|
+
message: chunk,
|
|
528
|
+
text: chunk.content,
|
|
529
|
+
generationInfo,
|
|
530
|
+
});
|
|
531
|
+
yield generationChunk;
|
|
532
|
+
await runManager?.handleLLMNewToken(generationChunk.text || '', newTokenIndices, undefined, undefined, undefined, { chunk: generationChunk });
|
|
533
|
+
}
|
|
534
|
+
if (usage) {
|
|
535
|
+
// Type assertion for xAI-specific usage structure
|
|
536
|
+
const xaiUsage = usage;
|
|
537
|
+
const inputTokenDetails = {
|
|
538
|
+
// Standard OpenAI fields
|
|
539
|
+
...(usage.prompt_tokens_details?.audio_tokens != null && {
|
|
540
|
+
audio: usage.prompt_tokens_details.audio_tokens,
|
|
541
|
+
}),
|
|
542
|
+
...(usage.prompt_tokens_details?.cached_tokens != null && {
|
|
543
|
+
cache_read: usage.prompt_tokens_details.cached_tokens,
|
|
544
|
+
}),
|
|
545
|
+
// Add xAI-specific prompt token details if they exist
|
|
546
|
+
...(xaiUsage.prompt_tokens_details?.text_tokens != null && {
|
|
547
|
+
text: xaiUsage.prompt_tokens_details.text_tokens,
|
|
548
|
+
}),
|
|
549
|
+
...(xaiUsage.prompt_tokens_details?.image_tokens != null && {
|
|
550
|
+
image: xaiUsage.prompt_tokens_details.image_tokens,
|
|
551
|
+
}),
|
|
552
|
+
};
|
|
553
|
+
const outputTokenDetails = {
|
|
554
|
+
// Standard OpenAI fields
|
|
555
|
+
...(usage.completion_tokens_details?.audio_tokens != null && {
|
|
556
|
+
audio: usage.completion_tokens_details.audio_tokens,
|
|
557
|
+
}),
|
|
558
|
+
...(usage.completion_tokens_details?.reasoning_tokens != null && {
|
|
559
|
+
reasoning: usage.completion_tokens_details.reasoning_tokens,
|
|
560
|
+
}),
|
|
561
|
+
// Add xAI-specific completion token details if they exist
|
|
562
|
+
...(xaiUsage.completion_tokens_details?.accepted_prediction_tokens !=
|
|
563
|
+
null && {
|
|
564
|
+
accepted_prediction: xaiUsage.completion_tokens_details.accepted_prediction_tokens,
|
|
565
|
+
}),
|
|
566
|
+
...(xaiUsage.completion_tokens_details?.rejected_prediction_tokens !=
|
|
567
|
+
null && {
|
|
568
|
+
rejected_prediction: xaiUsage.completion_tokens_details.rejected_prediction_tokens,
|
|
569
|
+
}),
|
|
570
|
+
};
|
|
571
|
+
const generationChunk = new ChatGenerationChunk({
|
|
572
|
+
message: new AIMessageChunk({
|
|
573
|
+
content: '',
|
|
574
|
+
response_metadata: {
|
|
575
|
+
usage: { ...usage },
|
|
576
|
+
// Include xAI-specific metadata if it exists
|
|
577
|
+
...(xaiUsage.num_sources_used != null && {
|
|
578
|
+
num_sources_used: xaiUsage.num_sources_used,
|
|
579
|
+
}),
|
|
580
|
+
},
|
|
581
|
+
usage_metadata: {
|
|
582
|
+
input_tokens: usage.prompt_tokens,
|
|
583
|
+
output_tokens: usage.completion_tokens,
|
|
584
|
+
total_tokens: usage.total_tokens,
|
|
585
|
+
...(Object.keys(inputTokenDetails).length > 0 && {
|
|
586
|
+
input_token_details: inputTokenDetails,
|
|
587
|
+
}),
|
|
588
|
+
...(Object.keys(outputTokenDetails).length > 0 && {
|
|
589
|
+
output_token_details: outputTokenDetails,
|
|
590
|
+
}),
|
|
591
|
+
},
|
|
592
|
+
}),
|
|
593
|
+
text: '',
|
|
594
|
+
});
|
|
595
|
+
yield generationChunk;
|
|
596
|
+
}
|
|
597
|
+
if (options.signal?.aborted === true) {
|
|
598
|
+
throw new Error('AbortError');
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export { AzureChatOpenAI, ChatDeepSeek, ChatOpenAI, ChatXAI, CustomAzureOpenAIClient, CustomOpenAIClient, isHeaders, normalizeHeaders };
|
|
604
|
+
//# sourceMappingURL=index.mjs.map
|