@librechat/agents 3.4.6 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/AgentContext.cjs +0 -356
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/agents/projection.cjs +0 -9
- package/dist/cjs/agents/projection.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +0 -26
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +0 -85
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +0 -14
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +1 -909
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +7 -272
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -1
- package/dist/cjs/graphs/createGraph.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestion.cjs +0 -53
- package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestions.cjs +0 -20
- package/dist/cjs/hitl/askUserQuestions.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs +0 -6
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs.map +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs +0 -127
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/createToolPolicyHook.cjs +0 -38
- package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +0 -77
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +0 -79
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs +0 -16
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/matchers.cjs +0 -104
- package/dist/cjs/hooks/matchers.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +0 -8
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +0 -14
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +0 -75
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseConfig.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeContext.cjs +0 -13
- package/dist/cjs/langfuseRuntimeContext.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeScope.cjs +0 -4
- package/dist/cjs/langfuseRuntimeScope.cjs.map +1 -1
- package/dist/cjs/langfuseSpanRegistry.cjs +0 -28
- package/dist/cjs/langfuseSpanRegistry.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +0 -3
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +0 -74
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +0 -3
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -111
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +0 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs +0 -8
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/cachePoints.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -95
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +0 -78
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +0 -24
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/contextOverflowRecovery.cjs +0 -62
- package/dist/cjs/llm/contextOverflowRecovery.cjs.map +1 -1
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +2 -21
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +5 -35
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +0 -9
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +1 -270
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/mistral/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +0 -99
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/streamMetadata.cjs +0 -21
- package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +0 -1
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +0 -6
- package/dist/cjs/llm/openrouter/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/preempt.cjs +0 -75
- package/dist/cjs/llm/preempt.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/request.cjs +0 -10
- package/dist/cjs/llm/request.cjs.map +1 -1
- package/dist/cjs/llm/stream/chunkAdapters.cjs +0 -62
- package/dist/cjs/llm/stream/chunkAdapters.cjs.map +1 -1
- package/dist/cjs/llm/stream/smoother.cjs +0 -58
- package/dist/cjs/llm/stream/smoother.cjs.map +1 -1
- package/dist/cjs/llm/streamLimits.cjs +4 -293
- package/dist/cjs/llm/streamLimits.cjs.map +1 -1
- package/dist/cjs/llm/truncation.cjs +0 -36
- package/dist/cjs/llm/truncation.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +0 -330
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/messages/alternation.cjs +0 -43
- package/dist/cjs/messages/alternation.cjs.map +1 -1
- package/dist/cjs/messages/anthropicToolCache.cjs +0 -45
- package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -1
- package/dist/cjs/messages/assistantPhase.cjs +0 -12
- package/dist/cjs/messages/assistantPhase.cjs.map +1 -1
- package/dist/cjs/messages/budget.cjs +0 -9
- package/dist/cjs/messages/budget.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +0 -172
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/content.cjs +0 -9
- package/dist/cjs/messages/content.cjs.map +1 -1
- package/dist/cjs/messages/contextPruning.cjs +0 -15
- package/dist/cjs/messages/contextPruning.cjs.map +1 -1
- package/dist/cjs/messages/contextPruningSettings.cjs +0 -3
- package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +0 -48
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +1 -345
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/handoffCue.cjs +0 -36
- package/dist/cjs/messages/handoffCue.cjs.map +1 -1
- package/dist/cjs/messages/ids.cjs.map +1 -1
- package/dist/cjs/messages/injected.cjs +0 -33
- package/dist/cjs/messages/injected.cjs.map +1 -1
- package/dist/cjs/messages/langchain.cjs +0 -14
- package/dist/cjs/messages/langchain.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +1 -184
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +0 -32
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/messages/reducer.cjs +0 -30
- package/dist/cjs/messages/reducer.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +0 -14
- package/dist/cjs/messages/tools.cjs.map +1 -1
- package/dist/cjs/openai/index.cjs.map +1 -1
- package/dist/cjs/prompts/activityLabel.cjs +9 -79
- package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
- package/dist/cjs/responses/index.cjs.map +1 -1
- package/dist/cjs/run.cjs +2 -538
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +1 -17
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
- package/dist/cjs/session/handlers.cjs +0 -7
- package/dist/cjs/session/handlers.cjs.map +1 -1
- package/dist/cjs/session/ids.cjs.map +1 -1
- package/dist/cjs/session/messageSerialization.cjs +0 -4
- package/dist/cjs/session/messageSerialization.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -93
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs +0 -27
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +0 -273
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +0 -35
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -24
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +0 -13
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +0 -101
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ReadFile.cjs.map +1 -1
- package/dist/cjs/tools/SkillTool.cjs +0 -5
- package/dist/cjs/tools/SkillTool.cjs.map +1 -1
- package/dist/cjs/tools/SubagentTool.cjs +0 -10
- package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +6 -1038
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +0 -179
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +0 -39
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -1
- package/dist/cjs/tools/eagerEventExecution.cjs +0 -6
- package/dist/cjs/tools/eagerEventExecution.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +1 -41
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/intentArg.cjs +1 -132
- package/dist/cjs/tools/intentArg.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +0 -25
- package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
- package/dist/cjs/tools/local/FileCheckpointer.cjs +0 -23
- package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +0 -80
- package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +0 -126
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +0 -12
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/attachments.cjs +0 -44
- package/dist/cjs/tools/local/attachments.cjs.map +1 -1
- package/dist/cjs/tools/local/bashAst.cjs +0 -16
- package/dist/cjs/tools/local/bashAst.cjs.map +1 -1
- package/dist/cjs/tools/local/editStrategies.cjs +0 -14
- package/dist/cjs/tools/local/editStrategies.cjs.map +1 -1
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/syntaxCheck.cjs +0 -31
- package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -1
- package/dist/cjs/tools/local/textEncoding.cjs +0 -11
- package/dist/cjs/tools/local/textEncoding.cjs.map +1 -1
- package/dist/cjs/tools/local/workspaceFS.cjs +0 -33
- package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -1
- package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
- package/dist/cjs/tools/schema.cjs +0 -8
- package/dist/cjs/tools/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/anthropic.cjs +0 -9
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -1
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-scraper.cjs +0 -33
- package/dist/cjs/tools/search/crw-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-search.cjs +0 -2
- package/dist/cjs/tools/search/crw-search.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +0 -25
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +0 -30
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/highlights.cjs +0 -16
- package/dist/cjs/tools/search/highlights.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-scraper.cjs +0 -8
- package/dist/cjs/tools/search/keenable-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-search.cjs +0 -7
- package/dist/cjs/tools/search/keenable-search.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +0 -35
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +0 -1
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +1 -14
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/serper-scraper.cjs +0 -46
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +0 -25
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +0 -8
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/tools/skillCatalog.cjs +0 -6
- package/dist/cjs/tools/skillCatalog.cjs.map +1 -1
- package/dist/cjs/tools/streamedToolCallSeals.cjs +0 -6
- package/dist/cjs/tools/streamedToolCallSeals.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -2
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +3 -213
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs +0 -4
- package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
- package/dist/cjs/tools/subagent/runtimeLimits.cjs.map +1 -1
- package/dist/cjs/tools/toolOutputReferences.cjs +1 -322
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/cjs/types/hitl.cjs +0 -5
- package/dist/cjs/types/hitl.cjs.map +1 -1
- package/dist/cjs/utils/callbacks.cjs.map +1 -1
- package/dist/cjs/utils/errors.cjs +14 -165
- package/dist/cjs/utils/errors.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +0 -10
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/graph.cjs.map +1 -1
- package/dist/cjs/utils/handlers.cjs +0 -3
- package/dist/cjs/utils/handlers.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs +0 -1
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/misc.cjs +0 -16
- package/dist/cjs/utils/misc.cjs.map +1 -1
- package/dist/cjs/utils/proxy.cjs +0 -26
- package/dist/cjs/utils/proxy.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +0 -6
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/cjs/utils/schema.cjs +0 -5
- package/dist/cjs/utils/schema.cjs.map +1 -1
- package/dist/cjs/utils/title.cjs +0 -6
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +0 -113
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/cjs/utils/toolContent.cjs +0 -41
- package/dist/cjs/utils/toolContent.cjs.map +1 -1
- package/dist/cjs/utils/truncation.cjs +0 -61
- package/dist/cjs/utils/truncation.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +0 -356
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/agents/projection.mjs +0 -9
- package/dist/esm/agents/projection.mjs.map +1 -1
- package/dist/esm/common/constants.mjs +0 -26
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +0 -85
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +0 -14
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +1 -909
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +7 -272
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/applyGraphRuntimeConfig.mjs.map +1 -1
- package/dist/esm/graphs/createGraph.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestion.mjs +0 -53
- package/dist/esm/hitl/askUserQuestion.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestions.mjs +0 -20
- package/dist/esm/hitl/askUserQuestions.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestionsInterrupt.mjs +0 -6
- package/dist/esm/hitl/askUserQuestionsInterrupt.mjs.map +1 -1
- package/dist/esm/hooks/HookRegistry.mjs +0 -127
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/createToolPolicyHook.mjs +0 -38
- package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +0 -77
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs +0 -79
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/hooks/index.mjs +0 -16
- package/dist/esm/hooks/index.mjs.map +1 -1
- package/dist/esm/hooks/matchers.mjs +0 -104
- package/dist/esm/hooks/matchers.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs +0 -8
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +0 -14
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +0 -75
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseConfig.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeContext.mjs +0 -13
- package/dist/esm/langfuseRuntimeContext.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeScope.mjs +0 -4
- package/dist/esm/langfuseRuntimeScope.mjs.map +1 -1
- package/dist/esm/langfuseSpanRegistry.mjs +0 -28
- package/dist/esm/langfuseSpanRegistry.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +0 -3
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +0 -74
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +0 -3
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -111
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +0 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/stream_events.mjs +0 -8
- package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
- package/dist/esm/llm/bedrock/cachePoints.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +1 -95
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +0 -78
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +0 -24
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/contextOverflowRecovery.mjs +0 -62
- package/dist/esm/llm/contextOverflowRecovery.mjs.map +1 -1
- package/dist/esm/llm/fake.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs +2 -21
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +5 -35
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +0 -9
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +1 -270
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/mistral/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +0 -99
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/streamMetadata.mjs +0 -21
- package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +0 -1
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +0 -6
- package/dist/esm/llm/openrouter/toolCache.mjs.map +1 -1
- package/dist/esm/llm/preempt.mjs +0 -75
- package/dist/esm/llm/preempt.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/request.mjs +0 -10
- package/dist/esm/llm/request.mjs.map +1 -1
- package/dist/esm/llm/stream/chunkAdapters.mjs +0 -62
- package/dist/esm/llm/stream/chunkAdapters.mjs.map +1 -1
- package/dist/esm/llm/stream/smoother.mjs +0 -58
- package/dist/esm/llm/stream/smoother.mjs.map +1 -1
- package/dist/esm/llm/streamLimits.mjs +4 -293
- package/dist/esm/llm/streamLimits.mjs.map +1 -1
- package/dist/esm/llm/truncation.mjs +0 -36
- package/dist/esm/llm/truncation.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +0 -330
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/messages/alternation.mjs +0 -43
- package/dist/esm/messages/alternation.mjs.map +1 -1
- package/dist/esm/messages/anthropicToolCache.mjs +0 -45
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
- package/dist/esm/messages/assistantPhase.mjs +0 -12
- package/dist/esm/messages/assistantPhase.mjs.map +1 -1
- package/dist/esm/messages/budget.mjs +0 -9
- package/dist/esm/messages/budget.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +0 -172
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/content.mjs +0 -9
- package/dist/esm/messages/content.mjs.map +1 -1
- package/dist/esm/messages/contextPruning.mjs +0 -15
- package/dist/esm/messages/contextPruning.mjs.map +1 -1
- package/dist/esm/messages/contextPruningSettings.mjs +0 -3
- package/dist/esm/messages/contextPruningSettings.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +0 -48
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +1 -345
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/handoffCue.mjs +0 -36
- package/dist/esm/messages/handoffCue.mjs.map +1 -1
- package/dist/esm/messages/ids.mjs.map +1 -1
- package/dist/esm/messages/injected.mjs +0 -33
- package/dist/esm/messages/injected.mjs.map +1 -1
- package/dist/esm/messages/langchain.mjs +0 -14
- package/dist/esm/messages/langchain.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +1 -184
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +0 -32
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/messages/reducer.mjs +0 -30
- package/dist/esm/messages/reducer.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +0 -14
- package/dist/esm/messages/tools.mjs.map +1 -1
- package/dist/esm/openai/index.mjs.map +1 -1
- package/dist/esm/prompts/activityLabel.mjs +9 -79
- package/dist/esm/prompts/activityLabel.mjs.map +1 -1
- package/dist/esm/responses/index.mjs.map +1 -1
- package/dist/esm/run.mjs +2 -538
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +1 -17
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/handlers.mjs +0 -7
- package/dist/esm/session/handlers.mjs.map +1 -1
- package/dist/esm/session/ids.mjs.map +1 -1
- package/dist/esm/session/messageSerialization.mjs +0 -4
- package/dist/esm/session/messageSerialization.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -93
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs +0 -27
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +0 -273
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +0 -35
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -24
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +0 -13
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +0 -101
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ReadFile.mjs.map +1 -1
- package/dist/esm/tools/SkillTool.mjs +0 -5
- package/dist/esm/tools/SkillTool.mjs.map +1 -1
- package/dist/esm/tools/SubagentTool.mjs +0 -10
- package/dist/esm/tools/SubagentTool.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +6 -1038
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +0 -179
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +0 -39
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
- package/dist/esm/tools/eagerEventExecution.mjs +0 -6
- package/dist/esm/tools/eagerEventExecution.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +1 -41
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/intentArg.mjs +1 -132
- package/dist/esm/tools/intentArg.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +0 -25
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
- package/dist/esm/tools/local/FileCheckpointer.mjs +0 -23
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +0 -80
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +0 -126
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +0 -12
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/attachments.mjs +0 -44
- package/dist/esm/tools/local/attachments.mjs.map +1 -1
- package/dist/esm/tools/local/bashAst.mjs +0 -16
- package/dist/esm/tools/local/bashAst.mjs.map +1 -1
- package/dist/esm/tools/local/editStrategies.mjs +0 -14
- package/dist/esm/tools/local/editStrategies.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/syntaxCheck.mjs +0 -31
- package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -1
- package/dist/esm/tools/local/textEncoding.mjs +0 -11
- package/dist/esm/tools/local/textEncoding.mjs.map +1 -1
- package/dist/esm/tools/local/workspaceFS.mjs +0 -33
- package/dist/esm/tools/local/workspaceFS.mjs.map +1 -1
- package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
- package/dist/esm/tools/schema.mjs +0 -8
- package/dist/esm/tools/schema.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +0 -9
- package/dist/esm/tools/search/anthropic.mjs.map +1 -1
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/search/crw-scraper.mjs +0 -33
- package/dist/esm/tools/search/crw-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/crw-search.mjs +0 -2
- package/dist/esm/tools/search/crw-search.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +0 -25
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +0 -30
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/highlights.mjs +0 -16
- package/dist/esm/tools/search/highlights.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-scraper.mjs +0 -8
- package/dist/esm/tools/search/keenable-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-search.mjs +0 -7
- package/dist/esm/tools/search/keenable-search.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +0 -35
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +0 -1
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +1 -14
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/serper-scraper.mjs +0 -46
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +0 -25
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +0 -8
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/skillCatalog.mjs +0 -6
- package/dist/esm/tools/skillCatalog.mjs.map +1 -1
- package/dist/esm/tools/streamedToolCallSeals.mjs +0 -6
- package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -2
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +3 -213
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs +0 -4
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
- package/dist/esm/tools/subagent/runtimeLimits.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +1 -322
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/types/hitl.mjs +0 -5
- package/dist/esm/types/hitl.mjs.map +1 -1
- package/dist/esm/utils/callbacks.mjs.map +1 -1
- package/dist/esm/utils/errors.mjs +14 -165
- package/dist/esm/utils/errors.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +0 -10
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/graph.mjs.map +1 -1
- package/dist/esm/utils/handlers.mjs +0 -3
- package/dist/esm/utils/handlers.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs +0 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/misc.mjs +0 -16
- package/dist/esm/utils/misc.mjs.map +1 -1
- package/dist/esm/utils/proxy.mjs +0 -26
- package/dist/esm/utils/proxy.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +0 -6
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/esm/utils/schema.mjs +0 -5
- package/dist/esm/utils/schema.mjs.map +1 -1
- package/dist/esm/utils/title.mjs +0 -6
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +0 -113
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/esm/utils/toolContent.mjs +0 -41
- package/dist/esm/utils/toolContent.mjs.map +1 -1
- package/dist/esm/utils/truncation.mjs +0 -61
- package/dist/esm/utils/truncation.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +3 -3
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +3 -3
- package/dist/types/agents/projection.d.ts +1 -1
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +11 -11
- package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
- package/dist/types/graphs/createGraph.d.ts +4 -4
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/hitl/askUserQuestion.d.ts +1 -1
- package/dist/types/hitl/askUserQuestions.d.ts +1 -1
- package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
- package/dist/types/hooks/types.d.ts +1 -1
- package/dist/types/instrumentation.d.ts +1 -1
- package/dist/types/langfuse.d.ts +3 -3
- package/dist/types/langfuseConfig.d.ts +2 -2
- package/dist/types/langfuseRuntimeContext.d.ts +1 -1
- package/dist/types/langfuseRuntimeScope.d.ts +2 -2
- package/dist/types/langfuseSpanRegistry.d.ts +1 -1
- package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
- package/dist/types/llm/anthropic/index.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +1 -1
- package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
- package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
- package/dist/types/llm/google/index.d.ts +1 -1
- package/dist/types/llm/init.d.ts +2 -2
- package/dist/types/llm/invoke.d.ts +6 -6
- package/dist/types/llm/mistral/index.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -2
- package/dist/types/llm/openrouter/index.d.ts +2 -2
- package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
- package/dist/types/llm/providers.d.ts +2 -2
- package/dist/types/llm/request.d.ts +2 -2
- package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
- package/dist/types/llm/streamLimits.d.ts +1 -1
- package/dist/types/llm/truncation.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +1 -1
- package/dist/types/messages/alternation.d.ts +1 -1
- package/dist/types/messages/anthropicToolCache.d.ts +2 -2
- package/dist/types/messages/assistantPhase.d.ts +3 -3
- package/dist/types/messages/budget.d.ts +1 -1
- package/dist/types/messages/cache.d.ts +1 -1
- package/dist/types/messages/contextPruning.d.ts +2 -2
- package/dist/types/messages/core.d.ts +2 -2
- package/dist/types/messages/format.d.ts +2 -2
- package/dist/types/messages/ids.d.ts +2 -2
- package/dist/types/messages/injected.d.ts +1 -1
- package/dist/types/messages/langchain.d.ts +1 -1
- package/dist/types/messages/prune.d.ts +3 -3
- package/dist/types/openai/index.d.ts +1 -1
- package/dist/types/prompts/activityLabel.d.ts +2 -2
- package/dist/types/responses/index.d.ts +1 -1
- package/dist/types/run.d.ts +3 -3
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/types.d.ts +1 -1
- package/dist/types/stream.d.ts +4 -4
- package/dist/types/summarization/index.d.ts +1 -1
- package/dist/types/summarization/node.d.ts +6 -6
- package/dist/types/test/mockTools.d.ts +1 -1
- package/dist/types/tools/BashExecutor.d.ts +2 -2
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/CodeExecutor.d.ts +3 -3
- package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/ReadFile.d.ts +1 -1
- package/dist/types/tools/SkillTool.d.ts +1 -1
- package/dist/types/tools/SubagentTool.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +5 -5
- package/dist/types/tools/ToolSearch.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
- package/dist/types/tools/eagerEventExecution.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +3 -3
- package/dist/types/tools/intentArg.d.ts +1 -1
- package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/local/bashAst.d.ts +1 -1
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
- package/dist/types/tools/ptcTimeout.d.ts +1 -1
- package/dist/types/tools/schema.d.ts +1 -1
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/skillCatalog.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +5 -5
- package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -3
- package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
- package/dist/types/types/activityLabel.d.ts +3 -3
- package/dist/types/types/graph.d.ts +7 -7
- package/dist/types/types/llm.d.ts +9 -9
- package/dist/types/types/run.d.ts +7 -7
- package/dist/types/types/stream.d.ts +5 -5
- package/dist/types/types/summarize.d.ts +2 -2
- package/dist/types/types/tools.d.ts +5 -5
- package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +1 -1
- package/dist/types/utils/errors.d.ts +1 -1
- package/dist/types/utils/events.d.ts +1 -1
- package/dist/types/utils/handlers.d.ts +3 -3
- package/dist/types/utils/llm.d.ts +1 -1
- package/dist/types/utils/llmConfig.d.ts +1 -1
- package/dist/types/utils/title.d.ts +1 -1
- package/package.json +10 -3
- package/src/llm/google/utils/common.ts +6 -4
- package/src/__tests__/stream.eagerArgsDivergence.test.ts +0 -911
- package/src/__tests__/stream.eagerEventExecution.test.ts +0 -5046
- package/src/__tests__/stream.streamLimits.test.ts +0 -1982
- package/src/agents/__tests__/AgentContext.anthropic.live.test.ts +0 -448
- package/src/agents/__tests__/AgentContext.bedrock.live.test.ts +0 -655
- package/src/agents/__tests__/AgentContext.openrouter.live.test.ts +0 -128
- package/src/agents/__tests__/AgentContext.overflow.test.ts +0 -205
- package/src/agents/__tests__/AgentContext.test.ts +0 -2425
- package/src/agents/__tests__/projection.test.ts +0 -73
- package/src/agents/__tests__/promptCacheLiveHelpers.ts +0 -175
- package/src/aggregator.test.ts +0 -1214
- package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +0 -273
- package/src/graphs/__tests__/Graph.closeRunStep.test.ts +0 -385
- package/src/graphs/__tests__/Graph.contextOverflow.test.ts +0 -1766
- package/src/graphs/__tests__/Graph.preemptSignal.test.ts +0 -126
- package/src/graphs/__tests__/Graph.reasoning.test.ts +0 -1717
- package/src/graphs/__tests__/Graph.subagentResumeState.test.ts +0 -80
- package/src/graphs/__tests__/MultiAgentGraph.test.ts +0 -177
- package/src/graphs/__tests__/composition.smoke.test.ts +0 -509
- package/src/graphs/__tests__/createGraph.test.ts +0 -206
- package/src/hooks/__tests__/HookRegistry.test.ts +0 -334
- package/src/hooks/__tests__/compactHooks.test.ts +0 -250
- package/src/hooks/__tests__/createToolPolicyHook.test.ts +0 -268
- package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +0 -405
- package/src/hooks/__tests__/executeHooks.test.ts +0 -1294
- package/src/hooks/__tests__/integration.test.ts +0 -337
- package/src/hooks/__tests__/matchers.test.ts +0 -238
- package/src/hooks/__tests__/preemptBoundary.test.ts +0 -152
- package/src/hooks/__tests__/toolHooks.test.ts +0 -669
- package/src/llm/__tests__/contextOverflowRecovery.test.ts +0 -401
- package/src/llm/__tests__/fallbackOverflow.test.ts +0 -287
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/inherited-content-utils.spec.ts +0 -249
- package/src/llm/anthropic/inherited-stream-events.spec.ts +0 -1259
- package/src/llm/anthropic/inherited-strict.spec.ts +0 -302
- package/src/llm/anthropic/llm.spec.ts +0 -3394
- package/src/llm/anthropic/utils/cross-provider-reasoning.test.ts +0 -383
- package/src/llm/anthropic/utils/cross-provider-server-tools.test.ts +0 -110
- package/src/llm/anthropic/utils/server-tool-inputs.test.ts +0 -508
- package/src/llm/anthropic/utils/streaming-tool-input.test.ts +0 -361
- package/src/llm/anthropic/utils/stripPrefillCache.test.ts +0 -111
- package/src/llm/anthropic/utils/tool-id-normalization.test.ts +0 -287
- package/src/llm/bedrock/inherited-cache.spec.ts +0 -144
- package/src/llm/bedrock/inherited.spec.ts +0 -724
- package/src/llm/bedrock/llm.spec.ts +0 -1533
- package/src/llm/bedrock/streamSealDispatch.test.ts +0 -331
- package/src/llm/bedrock/toolCache.test.ts +0 -194
- package/src/llm/bedrock/utils/cross-provider-reasoning.test.ts +0 -131
- package/src/llm/bedrock/utils/cross-provider-server-tools.test.ts +0 -122
- package/src/llm/bedrock/utils/message_inputs.test.ts +0 -650
- package/src/llm/bedrock/utils/message_outputs.test.ts +0 -85
- package/src/llm/bedrock/utils/toolResultCachePoint.test.ts +0 -118
- package/src/llm/custom-chat-models.smoke.test.ts +0 -1966
- package/src/llm/google/data/gettysburg10.wav +0 -0
- package/src/llm/google/data/hotdog.jpg +0 -0
- package/src/llm/google/inherited-stream-events.spec.ts +0 -350
- package/src/llm/google/llm.spec.ts +0 -1388
- package/src/llm/google/streamSmoothing.test.ts +0 -121
- package/src/llm/google/utils/common.test.ts +0 -185
- package/src/llm/invoke.alternation.test.ts +0 -87
- package/src/llm/invoke.handoffCue.test.ts +0 -112
- package/src/llm/invoke.streamLimits.test.ts +0 -142
- package/src/llm/invoke.test.ts +0 -1198
- package/src/llm/mistral/streamSmoothing.test.ts +0 -97
- package/src/llm/openai/cacheWriteTokens.test.ts +0 -112
- package/src/llm/openai/contentBlocks.test.ts +0 -381
- package/src/llm/openai/deepseek.test.ts +0 -747
- package/src/llm/openai/inherited-deepseek.spec.ts +0 -347
- package/src/llm/openai/inherited-xai.spec.ts +0 -416
- package/src/llm/openai/llm.spec.ts +0 -1774
- package/src/llm/openai/managedRequests.test.ts +0 -182
- package/src/llm/openai/sequentialToolCallSeals.test.ts +0 -199
- package/src/llm/openai/streamMetadata.spec.ts +0 -86
- package/src/llm/openai/streamMetadataDedup.spec.ts +0 -166
- package/src/llm/openai/utils/isReasoningModel.test.ts +0 -90
- package/src/llm/openai/utils/messages.test.ts +0 -488
- package/src/llm/openrouter/reasoning.test.ts +0 -561
- package/src/llm/openrouter/toolCache.test.ts +0 -134
- package/src/llm/preempt.test.ts +0 -323
- package/src/llm/stream/chunkAdapters.test.ts +0 -202
- package/src/llm/stream/reassembly.test.ts +0 -241
- package/src/llm/stream/smoother.bench.test.ts +0 -155
- package/src/llm/stream/smoother.test.ts +0 -519
- package/src/llm/streamLimits.test.ts +0 -450
- package/src/llm/truncation.test.ts +0 -242
- package/src/llm/vertexai/fixThoughtSignatures.test.ts +0 -154
- package/src/llm/vertexai/inherited-stream-events.spec.ts +0 -271
- package/src/llm/vertexai/llm.spec.ts +0 -159
- package/src/llm/vertexai/repairUsageMetadata.test.ts +0 -54
- package/src/llm/vertexai/sealStreamedToolCalls.test.ts +0 -88
- package/src/llm/vertexai/streamSealDispatch.test.ts +0 -148
- package/src/llm/vertexai/streamSmoothing.test.ts +0 -109
- package/src/messages/__tests__/anthropicToolCache.test.ts +0 -339
- package/src/messages/__tests__/observationMasking.test.ts +0 -312
- package/src/messages/__tests__/recency.test.ts +0 -267
- package/src/messages/__tests__/tools.test.ts +0 -473
- package/src/messages/alternation.test.ts +0 -212
- package/src/messages/assistantPhase.test.ts +0 -75
- package/src/messages/cache.tail.test.ts +0 -533
- package/src/messages/cache.test.ts +0 -2166
- package/src/messages/content.test.ts +0 -362
- package/src/messages/contextPruning.test.ts +0 -184
- package/src/messages/ensureThinkingBlock.test.ts +0 -1427
- package/src/messages/foldToollessToolBlocks.test.ts +0 -596
- package/src/messages/formatAgentMessages.reducer.test.ts +0 -162
- package/src/messages/formatAgentMessages.skills.test.ts +0 -513
- package/src/messages/formatAgentMessages.steer.test.ts +0 -598
- package/src/messages/formatAgentMessages.test.ts +0 -8111
- package/src/messages/formatAgentMessages.tools.test.ts +0 -522
- package/src/messages/formatMessage.test.ts +0 -693
- package/src/messages/handoffCue.test.ts +0 -96
- package/src/messages/injected.test.ts +0 -107
- package/src/messages/labelContentByAgent.test.ts +0 -962
- package/src/messages/reducer.spec.ts +0 -32
- package/src/messages/shiftIndexTokenCountMap.test.ts +0 -81
- package/src/messages/tailCacheConversion.test.ts +0 -161
- package/src/openai/__tests__/openai.test.ts +0 -337
- package/src/responses/__tests__/responses.test.ts +0 -652
- package/src/scripts/abort.ts +0 -157
- package/src/scripts/activity-labels/captured.json +0 -56
- package/src/scripts/activity-labels/checks.cjs +0 -205
- package/src/scripts/activity-labels/corpus.cjs +0 -473
- package/src/scripts/activity-labels/report.cjs +0 -203
- package/src/scripts/activity-labels/rescore.cjs +0 -102
- package/src/scripts/activity-labels/run.ts +0 -705
- package/src/scripts/activity-labels/variants.ts +0 -71
- package/src/scripts/ant_web_search.ts +0 -159
- package/src/scripts/ant_web_search_edge_case.ts +0 -163
- package/src/scripts/ant_web_search_error_edge_case.ts +0 -149
- package/src/scripts/args.ts +0 -48
- package/src/scripts/bedrock-cache-debug.ts +0 -250
- package/src/scripts/bedrock-content-aggregation-test.ts +0 -266
- package/src/scripts/bedrock-merge-test.ts +0 -107
- package/src/scripts/bedrock-parallel-tools-test.ts +0 -204
- package/src/scripts/bench-prompt-cache.ts +0 -479
- package/src/scripts/caching.ts +0 -132
- package/src/scripts/cli.ts +0 -172
- package/src/scripts/cli2.ts +0 -133
- package/src/scripts/cli3.ts +0 -184
- package/src/scripts/cli4.ts +0 -191
- package/src/scripts/cli5.ts +0 -191
- package/src/scripts/code_exec.ts +0 -214
- package/src/scripts/code_exec_files.ts +0 -237
- package/src/scripts/code_exec_multi_session.ts +0 -237
- package/src/scripts/code_exec_ptc.ts +0 -335
- package/src/scripts/code_exec_session.ts +0 -283
- package/src/scripts/code_exec_simple.ts +0 -148
- package/src/scripts/compare_pi_vs_ours.ts +0 -1259
- package/src/scripts/content.ts +0 -139
- package/src/scripts/context-overflow-probe.ts +0 -997
- package/src/scripts/empty_input.ts +0 -137
- package/src/scripts/handoff-test.ts +0 -134
- package/src/scripts/local_engine.ts +0 -166
- package/src/scripts/local_engine_checkpointer.ts +0 -205
- package/src/scripts/local_engine_compile.ts +0 -263
- package/src/scripts/local_engine_hooks.ts +0 -226
- package/src/scripts/local_engine_image.ts +0 -201
- package/src/scripts/local_engine_ptc.ts +0 -151
- package/src/scripts/local_engine_workspace.ts +0 -258
- package/src/scripts/memory.ts +0 -107
- package/src/scripts/multi-agent-chain.ts +0 -332
- package/src/scripts/multi-agent-conditional.ts +0 -222
- package/src/scripts/multi-agent-document-review-chain.ts +0 -198
- package/src/scripts/multi-agent-hybrid-flow.ts +0 -311
- package/src/scripts/multi-agent-parallel-start.ts +0 -265
- package/src/scripts/multi-agent-parallel.ts +0 -395
- package/src/scripts/multi-agent-sequence.ts +0 -217
- package/src/scripts/multi-agent-subagent.ts +0 -246
- package/src/scripts/multi-agent-supervisor.ts +0 -366
- package/src/scripts/multi-agent-test.ts +0 -187
- package/src/scripts/openrouter_prompt_cache_live.ts +0 -310
- package/src/scripts/parallel-asymmetric-tools-test.ts +0 -275
- package/src/scripts/parallel-full-metadata-test.ts +0 -241
- package/src/scripts/parallel-tools-test.ts +0 -341
- package/src/scripts/preempt-probe.ts +0 -330
- package/src/scripts/preempt-scenarios.ts +0 -388
- package/src/scripts/programmatic_exec.ts +0 -387
- package/src/scripts/programmatic_exec_agent.ts +0 -232
- package/src/scripts/search.ts +0 -147
- package/src/scripts/sequential-full-metadata-test.ts +0 -198
- package/src/scripts/session_live.ts +0 -548
- package/src/scripts/simple.ts +0 -226
- package/src/scripts/single-agent-metadata-test.ts +0 -196
- package/src/scripts/stream.ts +0 -141
- package/src/scripts/subagent-configurable-inheritance.ts +0 -252
- package/src/scripts/subagent-event-driven-debug.ts +0 -190
- package/src/scripts/subagent-tools-debug.ts +0 -160
- package/src/scripts/subagent-usage-sink.ts +0 -176
- package/src/scripts/summarization-recency.ts +0 -462
- package/src/scripts/test-custom-prompt-key.ts +0 -145
- package/src/scripts/test-handoff-input.ts +0 -170
- package/src/scripts/test-handoff-preamble.ts +0 -278
- package/src/scripts/test-handoff-steering.ts +0 -430
- package/src/scripts/test-multi-agent-list-handoff.ts +0 -418
- package/src/scripts/test-parallel-agent-labeling.ts +0 -327
- package/src/scripts/test-parallel-handoffs.ts +0 -292
- package/src/scripts/test-thinking-handoff-bedrock.ts +0 -154
- package/src/scripts/test-thinking-handoff.ts +0 -156
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +0 -166
- package/src/scripts/test-tool-before-handoff-role-order.ts +0 -276
- package/src/scripts/test-tools-before-handoff.ts +0 -222
- package/src/scripts/test_code_api.ts +0 -354
- package/src/scripts/thinking-bedrock.ts +0 -160
- package/src/scripts/thinking-vertexai.ts +0 -168
- package/src/scripts/thinking.ts +0 -172
- package/src/scripts/tool_search.ts +0 -153
- package/src/scripts/tools.ts +0 -163
- package/src/session/__tests__/JsonlSessionStore.test.ts +0 -1463
- package/src/session/__tests__/handlers.test.ts +0 -161
- package/src/specs/activity-label-observability.live.test.ts +0 -262
- package/src/specs/activity-label-observability.test.ts +0 -167
- package/src/specs/activity-label-prompt.test.ts +0 -359
- package/src/specs/activity-label-trace-seed.test.ts +0 -47
- package/src/specs/activity-phase-label.test.ts +0 -306
- package/src/specs/agent-handoffs.live.test.ts +0 -140
- package/src/specs/agent-handoffs.test.ts +0 -2465
- package/src/specs/anthropic.simple.test.ts +0 -453
- package/src/specs/ask-user-question-batch.test.ts +0 -289
- package/src/specs/ask-user-questions.live.test.ts +0 -185
- package/src/specs/ask-user-questions.test.ts +0 -293
- package/src/specs/azure.simple.test.ts +0 -502
- package/src/specs/bedrock-toolless.live.test.ts +0 -123
- package/src/specs/bedrock-truncation.live.test.ts +0 -191
- package/src/specs/cache.simple.test.ts +0 -416
- package/src/specs/context-accuracy.live.test.ts +0 -409
- package/src/specs/context-overflow-recovery.live.test.ts +0 -213
- package/src/specs/context-usage-event.test.ts +0 -117
- package/src/specs/context-usage.live.test.ts +0 -297
- package/src/specs/custom-event-await.test.ts +0 -304
- package/src/specs/deepseek.simple.test.ts +0 -290
- package/src/specs/deterministic-trace-id.test.ts +0 -43
- package/src/specs/discovered-tools.test.ts +0 -217
- package/src/specs/durability-checkpoint.integration.test.ts +0 -243
- package/src/specs/graph-subagent.live.test.ts +0 -242
- package/src/specs/graph-subagent.test.ts +0 -322
- package/src/specs/handoffCue.test.ts +0 -165
- package/src/specs/langfuse-callbacks.test.ts +0 -1578
- package/src/specs/langfuse-config.test.ts +0 -247
- package/src/specs/langfuse-instrumentation.test.ts +0 -393
- package/src/specs/langfuse-metadata.test.ts +0 -245
- package/src/specs/langfuse-routing.integration.test.ts +0 -844
- package/src/specs/langfuse-runtime-context.test.ts +0 -92
- package/src/specs/langfuse-span-registry.test.ts +0 -87
- package/src/specs/langfuse-tool-output-tracing.test.ts +0 -1858
- package/src/specs/langfuse-trace-shaping.test.ts +0 -591
- package/src/specs/moonshot.simple.test.ts +0 -367
- package/src/specs/multi-agent-summarization.test.ts +0 -396
- package/src/specs/openai.simple.test.ts +0 -315
- package/src/specs/openrouter.simple.test.ts +0 -275
- package/src/specs/preemptSeal.test.ts +0 -678
- package/src/specs/prune.test.ts +0 -3741
- package/src/specs/reasoning.test.ts +0 -201
- package/src/specs/run-step-timestamps.test.ts +0 -414
- package/src/specs/spec.utils.ts +0 -15
- package/src/specs/subagent.test.ts +0 -864
- package/src/specs/summarization-unit.test.ts +0 -973
- package/src/specs/summarization.test.ts +0 -3823
- package/src/specs/summarize-prune.test.ts +0 -376
- package/src/specs/thinking-handoff.test.ts +0 -621
- package/src/specs/thinking-prune.test.ts +0 -827
- package/src/specs/token-accounting-e2e.test.ts +0 -1034
- package/src/specs/token-accounting-pipeline.test.ts +0 -1008
- package/src/specs/token-distribution-edge-case.test.ts +0 -315
- package/src/specs/token-memoization.test.ts +0 -40
- package/src/specs/tokens.test.ts +0 -1000
- package/src/specs/tool-error-resume.test.ts +0 -194
- package/src/specs/tool-error.test.ts +0 -198
- package/src/specs/vllm-reasoning-toolcalls.test.ts +0 -340
- package/src/stream.dispatch.test.ts +0 -63
- package/src/stream.test.ts +0 -144
- package/src/summarization/__tests__/aggregator.test.ts +0 -236
- package/src/summarization/__tests__/node.test.ts +0 -1996
- package/src/summarization/__tests__/trigger.test.ts +0 -149
- package/src/summarization/chunkHandler.test.ts +0 -196
- package/src/test/mockTools.ts +0 -386
- package/src/tools/Calculator.test.ts +0 -278
- package/src/tools/__tests__/BashExecutor.test.ts +0 -108
- package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +0 -939
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +0 -858
- package/src/tools/__tests__/CodeExecutor.stateful.test.ts +0 -124
- package/src/tools/__tests__/LocalExecutionRoots.test.ts +0 -8
- package/src/tools/__tests__/LocalExecutionTools.test.ts +0 -2733
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +0 -318
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1557
- package/src/tools/__tests__/ReadFile.test.ts +0 -44
- package/src/tools/__tests__/SkillTool.test.ts +0 -442
- package/src/tools/__tests__/SubagentExecutor.test.ts +0 -3728
- package/src/tools/__tests__/SubagentReplay.test.ts +0 -329
- package/src/tools/__tests__/SubagentTool.test.ts +0 -149
- package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +0 -595
- package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +0 -1191
- package/src/tools/__tests__/ToolNode.invalidToolCalls.test.ts +0 -757
- package/src/tools/__tests__/ToolNode.langfuse.test.ts +0 -57
- package/src/tools/__tests__/ToolNode.onResultCompletion.test.ts +0 -736
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +0 -1710
- package/src/tools/__tests__/ToolNode.runtimeState.test.ts +0 -120
- package/src/tools/__tests__/ToolNode.session.test.ts +0 -1352
- package/src/tools/__tests__/ToolNode.streamLimits.test.ts +0 -69
- package/src/tools/__tests__/ToolSearch.integration.test.ts +0 -161
- package/src/tools/__tests__/ToolSearch.test.ts +0 -1227
- package/src/tools/__tests__/annotateMessagesForLLM.test.ts +0 -561
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +0 -980
- package/src/tools/__tests__/directToolHooks.test.ts +0 -700
- package/src/tools/__tests__/eagerEventExecution.session.test.ts +0 -92
- package/src/tools/__tests__/handlers.test.ts +0 -997
- package/src/tools/__tests__/hitl.test.ts +0 -4663
- package/src/tools/__tests__/intentArg.test.ts +0 -357
- package/src/tools/__tests__/intentCoverage.test.ts +0 -139
- package/src/tools/__tests__/localToolNames.test.ts +0 -75
- package/src/tools/__tests__/skillCatalog.test.ts +0 -161
- package/src/tools/__tests__/subagentHooks.test.ts +0 -1651
- package/src/tools/__tests__/toolOutputReferences.test.ts +0 -515
- package/src/tools/__tests__/workspaceSeam.test.ts +0 -147
- package/src/tools/local/__tests__/FileCheckpointer.test.ts +0 -162
- package/src/tools/local/__tests__/editStrategies.test.ts +0 -134
- package/src/tools/search/content.test.ts +0 -173
- package/src/tools/search/crw.test.ts +0 -836
- package/src/tools/search/format.test.ts +0 -242
- package/src/tools/search/http-agent.test.ts +0 -133
- package/src/tools/search/jina-reranker.test.ts +0 -306
- package/src/tools/search/keenable-scraper.test.ts +0 -153
- package/src/tools/search/keenable.test.ts +0 -183
- package/src/tools/search/outcome.test.ts +0 -90
- package/src/tools/search/output.md +0 -2775
- package/src/tools/search/rag-api-reranker.test.ts +0 -891
- package/src/tools/search/source-processing.test.ts +0 -516
- package/src/tools/search/tavily.test.ts +0 -965
- package/src/tools/search/test.html +0 -884
- package/src/tools/search/test.md +0 -643
- package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +0 -637
- package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +0 -3054
- package/src/tools/subagent/__tests__/childGraphConfig.test.ts +0 -521
- package/src/utils/__tests__/apportion.test.ts +0 -32
- package/src/utils/__tests__/errors.test.ts +0 -270
- package/src/utils/__tests__/fixtures/contextOverflowSignatures.ts +0 -336
- package/src/utils/__tests__/redactSecrets.test.ts +0 -56
- package/src/utils/__tests__/truncation.test.ts +0 -66
- package/src/utils/llm.test.ts +0 -18
- package/src/utils/proxy.test.ts +0 -176
- package/src/utils/toolContent.test.ts +0 -1432
|
@@ -1,1388 +0,0 @@
|
|
|
1
|
-
import { config } from 'dotenv';
|
|
2
|
-
config();
|
|
3
|
-
import { beforeEach, test, jest } from '@jest/globals';
|
|
4
|
-
|
|
5
|
-
jest.setTimeout(Number(process.env.GOOGLE_TEST_TIMEOUT_MS ?? 120000));
|
|
6
|
-
import * as fs from 'node:fs/promises';
|
|
7
|
-
import * as path from 'node:path';
|
|
8
|
-
import {
|
|
9
|
-
AIMessage,
|
|
10
|
-
AIMessageChunk,
|
|
11
|
-
HumanMessage,
|
|
12
|
-
SystemMessage,
|
|
13
|
-
ToolMessage,
|
|
14
|
-
} from '@langchain/core/messages';
|
|
15
|
-
import {
|
|
16
|
-
ChatPromptTemplate,
|
|
17
|
-
MessagesPlaceholder,
|
|
18
|
-
} from '@langchain/core/prompts';
|
|
19
|
-
import { StructuredTool, tool } from '@langchain/core/tools';
|
|
20
|
-
import { z } from 'zod/v3';
|
|
21
|
-
import {
|
|
22
|
-
DynamicRetrievalMode,
|
|
23
|
-
SchemaType as FunctionDeclarationSchemaType,
|
|
24
|
-
} from '@google/generative-ai';
|
|
25
|
-
import { concat } from '@langchain/core/utils/stream';
|
|
26
|
-
import type {
|
|
27
|
-
CodeExecutionTool,
|
|
28
|
-
GoogleSearchRetrievalTool,
|
|
29
|
-
} from '@google/generative-ai';
|
|
30
|
-
import type { ContentBlock } from '@langchain/core/messages';
|
|
31
|
-
import { CustomChatGoogleGenerativeAI as ChatGoogleGenerativeAI } from './index';
|
|
32
|
-
import {
|
|
33
|
-
convertMessageContentToParts,
|
|
34
|
-
convertResponseContentToChatGenerationChunk,
|
|
35
|
-
mapGenerateContentResultToChatResult,
|
|
36
|
-
_FUNCTION_CALL_THOUGHT_SIGNATURES_MAP_KEY,
|
|
37
|
-
} from './utils/common';
|
|
38
|
-
|
|
39
|
-
// Save the original value of the 'LANGCHAIN_CALLBACKS_BACKGROUND' environment variable
|
|
40
|
-
const originalBackground = process.env.LANGCHAIN_CALLBACKS_BACKGROUND;
|
|
41
|
-
|
|
42
|
-
const GOOGLE_TEST_MAX_RETRIES = Number(
|
|
43
|
-
process.env.GOOGLE_TEST_MAX_RETRIES ?? 2
|
|
44
|
-
);
|
|
45
|
-
const GOOGLE_TEST_CALL_GAP_MS = Number(
|
|
46
|
-
process.env.GOOGLE_TEST_CALL_GAP_MS ?? 1000
|
|
47
|
-
);
|
|
48
|
-
const GOOGLE_TEST_MAX_RETRY_DELAY_MS = Number(
|
|
49
|
-
process.env.GOOGLE_TEST_MAX_RETRY_DELAY_MS ?? 50000
|
|
50
|
-
);
|
|
51
|
-
let lastGoogleTestCallAt = 0;
|
|
52
|
-
|
|
53
|
-
const wait = async (ms: number): Promise<void> =>
|
|
54
|
-
new Promise((resolve) => {
|
|
55
|
-
setTimeout(resolve, ms);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
async function waitForGoogleTestSlot(): Promise<void> {
|
|
59
|
-
const waitMs = Math.max(
|
|
60
|
-
0,
|
|
61
|
-
lastGoogleTestCallAt + GOOGLE_TEST_CALL_GAP_MS - Date.now()
|
|
62
|
-
);
|
|
63
|
-
if (waitMs > 0) {
|
|
64
|
-
await wait(waitMs);
|
|
65
|
-
}
|
|
66
|
-
lastGoogleTestCallAt = Date.now();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const GOOGLE_NO_RETRY_STATUSES = new Set([
|
|
70
|
-
400, 401, 402, 403, 404, 405, 406, 407, 409,
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
interface GoogleRetryInfoDetail {
|
|
74
|
-
'@type'?: string;
|
|
75
|
-
retryDelay?: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
interface GoogleFetchErrorLike extends Error {
|
|
79
|
-
status?: number;
|
|
80
|
-
errorDetails?: GoogleRetryInfoDetail[];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
interface ErrorWithCode extends Error {
|
|
84
|
-
code?: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function throwIfNonRetryableError(error: unknown): void {
|
|
88
|
-
if (!(error instanceof Error)) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (
|
|
92
|
-
error.message.startsWith('Cancel') ||
|
|
93
|
-
error.message.startsWith('AbortError') ||
|
|
94
|
-
error.name === 'AbortError'
|
|
95
|
-
) {
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
const errorCode = (error as Partial<ErrorWithCode>).code;
|
|
99
|
-
if (errorCode === 'ECONNABORTED') {
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function getGoogleFetchError(error: unknown): GoogleFetchErrorLike | undefined {
|
|
105
|
-
if (!(error instanceof Error)) {
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
const possibleError = error as Partial<GoogleFetchErrorLike>;
|
|
109
|
-
if (
|
|
110
|
-
typeof possibleError.status !== 'number' &&
|
|
111
|
-
!Array.isArray(possibleError.errorDetails)
|
|
112
|
-
) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
return possibleError as GoogleFetchErrorLike;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function parseGoogleRetryDelayMs(retryDelay: string): number | undefined {
|
|
119
|
-
const retryDelaySeconds = /^(\d+(?:\.\d+)?)s$/.exec(retryDelay)?.[1];
|
|
120
|
-
if (retryDelaySeconds === undefined) {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
return Math.ceil(Number(retryDelaySeconds) * 1000);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function getGoogleRetryDelayMs(
|
|
127
|
-
error: GoogleFetchErrorLike
|
|
128
|
-
): number | undefined {
|
|
129
|
-
const retryInfoDelay = error.errorDetails?.find(
|
|
130
|
-
(detail) => detail['@type'] === 'type.googleapis.com/google.rpc.RetryInfo'
|
|
131
|
-
)?.retryDelay;
|
|
132
|
-
if (retryInfoDelay !== undefined) {
|
|
133
|
-
return parseGoogleRetryDelayMs(retryInfoDelay);
|
|
134
|
-
}
|
|
135
|
-
const messageDelay = /Please retry in (\d+(?:\.\d+)?)s/.exec(
|
|
136
|
-
error.message
|
|
137
|
-
)?.[1];
|
|
138
|
-
if (messageDelay === undefined) {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
return Math.ceil(Number(messageDelay) * 1000);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function handleGoogleFailedAttempt(error: unknown): Promise<void> {
|
|
145
|
-
throwIfNonRetryableError(error);
|
|
146
|
-
const googleError = getGoogleFetchError(error);
|
|
147
|
-
if (googleError === undefined) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (
|
|
151
|
-
googleError.status !== undefined &&
|
|
152
|
-
GOOGLE_NO_RETRY_STATUSES.has(googleError.status)
|
|
153
|
-
) {
|
|
154
|
-
throw googleError;
|
|
155
|
-
}
|
|
156
|
-
if (googleError.status !== 429) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (/\blimit:\s*0\b/.test(googleError.message)) {
|
|
160
|
-
throw googleError;
|
|
161
|
-
}
|
|
162
|
-
const retryDelayMs = getGoogleRetryDelayMs(googleError);
|
|
163
|
-
if (retryDelayMs === undefined) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
await wait(Math.min(retryDelayMs, GOOGLE_TEST_MAX_RETRY_DELAY_MS));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function createGoogleModel(
|
|
170
|
-
fields: ConstructorParameters<typeof ChatGoogleGenerativeAI>[0]
|
|
171
|
-
): ChatGoogleGenerativeAI {
|
|
172
|
-
return new ChatGoogleGenerativeAI({
|
|
173
|
-
...fields,
|
|
174
|
-
maxRetries: GOOGLE_TEST_MAX_RETRIES,
|
|
175
|
-
onFailedAttempt: handleGoogleFailedAttempt,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
beforeEach(async () => {
|
|
180
|
-
await waitForGoogleTestSlot();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const dummyToolResponse =
|
|
184
|
-
"[{\"title\":\"Weather in New York City\",\"url\":\"https://www.weatherapi.com/\",\"content\":\"{'location': {'name': 'New York', 'region': 'New York', 'country': 'United States of America', 'lat': 40.71, 'lon': -74.01, 'tz_id': 'America/New_York', 'localtime_epoch': 1718659486, 'localtime': '2024-06-17 17:24'}, 'current': {'last_updated_epoch': 1718658900, 'last_updated': '2024-06-17 17:15', 'temp_c': 27.8, 'temp_f': 82.0, 'is_day': 1, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/day/116.png', 'code': 1003}, 'wind_mph': 2.2, 'wind_kph': 3.6, 'wind_degree': 159, 'wind_dir': 'SSE', 'pressure_mb': 1021.0, 'pressure_in': 30.15, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 58, 'cloud': 25, 'feelslike_c': 29.0, 'feelslike_f': 84.2, 'windchill_c': 26.9, 'windchill_f': 80.5, 'heatindex_c': 27.9, 'heatindex_f': 82.2, 'dewpoint_c': 17.1, 'dewpoint_f': 62.8, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 7.0, 'gust_mph': 18.3, 'gust_kph': 29.4}}\",\"score\":0.98192,\"raw_content\":null},{\"title\":\"New York, NY Monthly Weather | AccuWeather\",\"url\":\"https://www.accuweather.com/en/us/new-york/10021/june-weather/349727\",\"content\":\"Get the monthly weather forecast for New York, NY, including daily high/low, historical averages, to help you plan ahead.\",\"score\":0.97504,\"raw_content\":null}]";
|
|
185
|
-
|
|
186
|
-
test('Test Google AI', async () => {
|
|
187
|
-
const model = createGoogleModel({
|
|
188
|
-
model: 'gemini-2.0-flash',
|
|
189
|
-
});
|
|
190
|
-
const res = await model.invoke('what is 1 + 1?');
|
|
191
|
-
expect(res).toBeTruthy();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('Test Google AI generation', async () => {
|
|
195
|
-
const model = createGoogleModel({
|
|
196
|
-
model: 'gemini-2.0-flash',
|
|
197
|
-
});
|
|
198
|
-
const res = await model.generate([
|
|
199
|
-
[['human', 'Translate "I love programming" into Korean.']],
|
|
200
|
-
]);
|
|
201
|
-
expect(res).toBeTruthy();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
test('Test Google AI generation with a stop sequence', async () => {
|
|
205
|
-
const model = createGoogleModel({
|
|
206
|
-
model: 'gemini-2.0-flash',
|
|
207
|
-
stopSequences: ['two', '2'],
|
|
208
|
-
});
|
|
209
|
-
const res = await model.invoke([
|
|
210
|
-
['human', 'What are the first three positive whole numbers?'],
|
|
211
|
-
]);
|
|
212
|
-
expect(res).toBeTruthy();
|
|
213
|
-
expect(res.additional_kwargs.finishReason).toBe('STOP');
|
|
214
|
-
expect(res.content).not.toContain('2');
|
|
215
|
-
expect(res.content).not.toContain('two');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('Test Google AI generation with a system message', async () => {
|
|
219
|
-
const model = createGoogleModel({
|
|
220
|
-
model: 'gemini-2.0-flash',
|
|
221
|
-
});
|
|
222
|
-
const res = await model.generate([
|
|
223
|
-
[
|
|
224
|
-
['system', 'You are an amazing translator.'],
|
|
225
|
-
['human', 'Translate "I love programming" into Korean.'],
|
|
226
|
-
],
|
|
227
|
-
]);
|
|
228
|
-
expect(res).toBeTruthy();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('Test Google AI multimodal generation', async () => {
|
|
232
|
-
const imageData = (
|
|
233
|
-
await fs.readFile(path.join(__dirname, '/data/hotdog.jpg'))
|
|
234
|
-
).toString('base64');
|
|
235
|
-
const model = createGoogleModel({
|
|
236
|
-
model: 'gemini-2.0-flash',
|
|
237
|
-
});
|
|
238
|
-
const res = await model.invoke([
|
|
239
|
-
new HumanMessage({
|
|
240
|
-
content: [
|
|
241
|
-
{
|
|
242
|
-
type: 'text',
|
|
243
|
-
text: 'Describe the following image:',
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
type: 'image_url',
|
|
247
|
-
image_url: `data:image/png;base64,${imageData}`,
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
}),
|
|
251
|
-
]);
|
|
252
|
-
expect(res).toBeTruthy();
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
test('Test Google AI handleLLMNewToken callback', async () => {
|
|
256
|
-
// Running LangChain callbacks in the background will sometimes cause the callbackManager to execute
|
|
257
|
-
// after the test/llm call has already finished & returned. Set that environment variable to false
|
|
258
|
-
// to prevent that from happening.
|
|
259
|
-
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = 'false';
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
const model = createGoogleModel({
|
|
263
|
-
model: 'gemini-2.0-flash',
|
|
264
|
-
});
|
|
265
|
-
let tokens = '';
|
|
266
|
-
const res = await model.invoke([new HumanMessage('what is 1 + 1?')], {
|
|
267
|
-
callbacks: [
|
|
268
|
-
{
|
|
269
|
-
handleLLMNewToken(token: string): void {
|
|
270
|
-
tokens += token;
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
});
|
|
275
|
-
const responseContent = typeof res.content === 'string' ? res.content : '';
|
|
276
|
-
expect(tokens).toBe(responseContent);
|
|
277
|
-
} finally {
|
|
278
|
-
// Reset the environment variable
|
|
279
|
-
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = originalBackground;
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
test('Test Google AI handleLLMNewToken callback with streaming', async () => {
|
|
284
|
-
// Running LangChain callbacks in the background will sometimes cause the callbackManager to execute
|
|
285
|
-
// after the test/llm call has already finished & returned. Set that environment variable to false
|
|
286
|
-
// to prevent that from happening.
|
|
287
|
-
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = 'false';
|
|
288
|
-
|
|
289
|
-
try {
|
|
290
|
-
const model = createGoogleModel({
|
|
291
|
-
model: 'gemini-2.0-flash',
|
|
292
|
-
});
|
|
293
|
-
let tokens = '';
|
|
294
|
-
const res = await model.stream([new HumanMessage('what is 1 + 1?')], {
|
|
295
|
-
callbacks: [
|
|
296
|
-
{
|
|
297
|
-
handleLLMNewToken(token: string): void {
|
|
298
|
-
tokens += token;
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
],
|
|
302
|
-
});
|
|
303
|
-
let responseContent = '';
|
|
304
|
-
for await (const streamItem of res) {
|
|
305
|
-
responseContent += streamItem.content;
|
|
306
|
-
}
|
|
307
|
-
expect(tokens).toBe(responseContent);
|
|
308
|
-
} finally {
|
|
309
|
-
// Reset the environment variable
|
|
310
|
-
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = originalBackground;
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
test('Test Google AI in streaming mode', async () => {
|
|
315
|
-
// Running LangChain callbacks in the background will sometimes cause the callbackManager to execute
|
|
316
|
-
// after the test/llm call has already finished & returned. Set that environment variable to false
|
|
317
|
-
// to prevent that from happening.
|
|
318
|
-
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = 'false';
|
|
319
|
-
|
|
320
|
-
try {
|
|
321
|
-
const model = createGoogleModel({
|
|
322
|
-
model: 'gemini-2.0-flash',
|
|
323
|
-
streaming: true,
|
|
324
|
-
});
|
|
325
|
-
let tokens = '';
|
|
326
|
-
let nrNewTokens = 0;
|
|
327
|
-
const res = await model.invoke([new HumanMessage('Write a haiku?')], {
|
|
328
|
-
callbacks: [
|
|
329
|
-
{
|
|
330
|
-
handleLLMNewToken(token: string): void {
|
|
331
|
-
nrNewTokens += 1;
|
|
332
|
-
tokens += token;
|
|
333
|
-
},
|
|
334
|
-
},
|
|
335
|
-
],
|
|
336
|
-
});
|
|
337
|
-
expect(nrNewTokens).toBeGreaterThanOrEqual(1);
|
|
338
|
-
expect(res.content).toBe(tokens);
|
|
339
|
-
} finally {
|
|
340
|
-
// Reset the environment variable
|
|
341
|
-
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = originalBackground;
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
async function fileToBase64(filePath: string): Promise<string> {
|
|
346
|
-
const fileData = await fs.readFile(filePath);
|
|
347
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
348
|
-
/** @ts-ignore */
|
|
349
|
-
const base64String = Buffer.from(fileData).toString('base64');
|
|
350
|
-
return base64String;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
test('Gemini can understand audio', async () => {
|
|
354
|
-
// Update this with the correct path to an audio file on your machine.
|
|
355
|
-
const audioPath = path.join(__dirname, 'data/gettysburg10.wav');
|
|
356
|
-
const audioMimeType = 'audio/wav';
|
|
357
|
-
|
|
358
|
-
const model = createGoogleModel({
|
|
359
|
-
model: 'gemini-2.0-flash',
|
|
360
|
-
temperature: 0,
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
const audioBase64 = await fileToBase64(audioPath);
|
|
364
|
-
|
|
365
|
-
const prompt = ChatPromptTemplate.fromMessages([
|
|
366
|
-
new MessagesPlaceholder('audio'),
|
|
367
|
-
]);
|
|
368
|
-
|
|
369
|
-
const chain = prompt.pipe(model);
|
|
370
|
-
const response = await chain.invoke({
|
|
371
|
-
audio: new HumanMessage({
|
|
372
|
-
content: [
|
|
373
|
-
{
|
|
374
|
-
type: 'media',
|
|
375
|
-
mimeType: audioMimeType,
|
|
376
|
-
data: audioBase64,
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
type: 'text',
|
|
380
|
-
text: "Summarize the content in this audio. ALso, what is the speaker's tone?",
|
|
381
|
-
},
|
|
382
|
-
],
|
|
383
|
-
}),
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
expect(typeof response.content).toBe('string');
|
|
387
|
-
expect((response.content as string).length).toBeGreaterThan(15);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
class FakeBrowserTool extends StructuredTool {
|
|
391
|
-
schema = z.object({
|
|
392
|
-
url: z.string(),
|
|
393
|
-
query: z.string().optional(),
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
name = 'fake_browser_tool';
|
|
397
|
-
|
|
398
|
-
description =
|
|
399
|
-
'useful for when you need to find something on the web or summarize a webpage.';
|
|
400
|
-
|
|
401
|
-
async _call(_: z.infer<this['schema']>): Promise<string> {
|
|
402
|
-
return 'fake_browser_tool';
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
const googleGenAITool = {
|
|
406
|
-
functionDeclarations: [
|
|
407
|
-
{
|
|
408
|
-
name: 'fake_browser_tool',
|
|
409
|
-
description:
|
|
410
|
-
'useful for when you need to find something on the web or summarize a webpage.',
|
|
411
|
-
parameters: {
|
|
412
|
-
type: FunctionDeclarationSchemaType.OBJECT,
|
|
413
|
-
required: ['url'],
|
|
414
|
-
properties: {
|
|
415
|
-
url: {
|
|
416
|
-
type: FunctionDeclarationSchemaType.STRING,
|
|
417
|
-
},
|
|
418
|
-
query: {
|
|
419
|
-
type: FunctionDeclarationSchemaType.STRING,
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
},
|
|
423
|
-
},
|
|
424
|
-
],
|
|
425
|
-
};
|
|
426
|
-
const prompt = new HumanMessage(
|
|
427
|
-
'Search the web and tell me what the weather will be like tonight in new york. use weather.com'
|
|
428
|
-
);
|
|
429
|
-
|
|
430
|
-
test('ChatGoogleGenerativeAI can bind and invoke langchain tools', async () => {
|
|
431
|
-
const model = createGoogleModel({
|
|
432
|
-
model: 'gemini-2.5-flash',
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
const modelWithTools = model.bindTools([new FakeBrowserTool()]);
|
|
436
|
-
const res = await modelWithTools.invoke([prompt]);
|
|
437
|
-
const toolCalls = res.tool_calls;
|
|
438
|
-
expect(toolCalls).toBeDefined();
|
|
439
|
-
if (!toolCalls) {
|
|
440
|
-
throw new Error('tool_calls not in response');
|
|
441
|
-
}
|
|
442
|
-
expect(toolCalls.length).toBe(1);
|
|
443
|
-
expect(toolCalls[0].name).toBe('fake_browser_tool');
|
|
444
|
-
expect('url' in toolCalls[0].args).toBe(true);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
test('ChatGoogleGenerativeAI can bind and stream langchain tools', async () => {
|
|
448
|
-
const model = createGoogleModel({
|
|
449
|
-
model: 'gemini-2.5-flash',
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
const modelWithTools = model.bindTools([new FakeBrowserTool()]);
|
|
453
|
-
let finalChunk: AIMessageChunk | undefined;
|
|
454
|
-
for await (const chunk of await modelWithTools.stream([prompt])) {
|
|
455
|
-
if (!finalChunk) {
|
|
456
|
-
finalChunk = chunk;
|
|
457
|
-
} else {
|
|
458
|
-
finalChunk = finalChunk.concat(chunk);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
if (!finalChunk) {
|
|
462
|
-
throw new Error('finalChunk is undefined');
|
|
463
|
-
}
|
|
464
|
-
const toolCalls = finalChunk.tool_calls;
|
|
465
|
-
expect(toolCalls).toBeDefined();
|
|
466
|
-
if (!toolCalls) {
|
|
467
|
-
throw new Error('tool_calls not in response');
|
|
468
|
-
}
|
|
469
|
-
expect(toolCalls.length).toBe(1);
|
|
470
|
-
expect(toolCalls[0].name).toBe('fake_browser_tool');
|
|
471
|
-
expect(toolCalls[0].id).toBeDefined();
|
|
472
|
-
expect('url' in toolCalls[0].args).toBe(true);
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
test('ChatGoogleGenerativeAI can handle streaming tool messages.', async () => {
|
|
476
|
-
const model = createGoogleModel({
|
|
477
|
-
model: 'gemini-2.5-flash',
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
const browserTool = new FakeBrowserTool();
|
|
481
|
-
|
|
482
|
-
const modelWithTools = model.bindTools([browserTool]);
|
|
483
|
-
let finalChunk: AIMessageChunk | undefined;
|
|
484
|
-
const fullPrompt = [
|
|
485
|
-
new SystemMessage(
|
|
486
|
-
'You are a helpful assistant. If the chat history contains the tool results, you should use that and not call the tool again.'
|
|
487
|
-
),
|
|
488
|
-
prompt,
|
|
489
|
-
new AIMessage({
|
|
490
|
-
content: '',
|
|
491
|
-
tool_calls: [
|
|
492
|
-
{
|
|
493
|
-
name: browserTool.name,
|
|
494
|
-
args: {
|
|
495
|
-
query: 'weather tonight new york',
|
|
496
|
-
url: 'https://weather.com',
|
|
497
|
-
},
|
|
498
|
-
},
|
|
499
|
-
],
|
|
500
|
-
}),
|
|
501
|
-
new ToolMessage(dummyToolResponse, 'id', browserTool.name),
|
|
502
|
-
];
|
|
503
|
-
for await (const chunk of await modelWithTools.stream(fullPrompt)) {
|
|
504
|
-
if (!finalChunk) {
|
|
505
|
-
finalChunk = chunk;
|
|
506
|
-
} else {
|
|
507
|
-
finalChunk = finalChunk.concat(chunk);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (!finalChunk) {
|
|
511
|
-
throw new Error('finalChunk is undefined');
|
|
512
|
-
}
|
|
513
|
-
expect(typeof finalChunk.content).toBe('string');
|
|
514
|
-
expect(finalChunk.content.length).toBeGreaterThan(1);
|
|
515
|
-
expect(finalChunk.tool_calls).toHaveLength(0);
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
test('ChatGoogleGenerativeAI can handle invoking tool messages.', async () => {
|
|
519
|
-
const model = createGoogleModel({
|
|
520
|
-
model: 'gemini-2.5-flash',
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
const browserTool = new FakeBrowserTool();
|
|
524
|
-
|
|
525
|
-
const modelWithTools = model.bindTools([browserTool]);
|
|
526
|
-
const fullPrompt = [
|
|
527
|
-
new SystemMessage(
|
|
528
|
-
'You are a helpful assistant. If the chat history contains the tool results, you should use that and not call the tool again.'
|
|
529
|
-
),
|
|
530
|
-
prompt,
|
|
531
|
-
new AIMessage({
|
|
532
|
-
content: '',
|
|
533
|
-
tool_calls: [
|
|
534
|
-
{
|
|
535
|
-
name: browserTool.name,
|
|
536
|
-
args: {
|
|
537
|
-
query: 'weather tonight new york',
|
|
538
|
-
url: 'https://weather.com',
|
|
539
|
-
},
|
|
540
|
-
},
|
|
541
|
-
],
|
|
542
|
-
}),
|
|
543
|
-
new ToolMessage(dummyToolResponse, 'id', browserTool.name),
|
|
544
|
-
];
|
|
545
|
-
const response = await modelWithTools.invoke(fullPrompt);
|
|
546
|
-
expect(typeof response.content).toBe('string');
|
|
547
|
-
expect(response.content.length).toBeGreaterThan(1);
|
|
548
|
-
expect(response.tool_calls).toHaveLength(0);
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
test('ChatGoogleGenerativeAI can bind and invoke genai tools', async () => {
|
|
552
|
-
const model = createGoogleModel({
|
|
553
|
-
model: 'gemini-2.5-flash',
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
const modelWithTools = model.bindTools([googleGenAITool]);
|
|
557
|
-
const res = await modelWithTools.invoke([prompt]);
|
|
558
|
-
const toolCalls = res.tool_calls;
|
|
559
|
-
expect(toolCalls).toBeDefined();
|
|
560
|
-
if (!toolCalls) {
|
|
561
|
-
throw new Error('tool_calls not in response');
|
|
562
|
-
}
|
|
563
|
-
expect(toolCalls.length).toBe(1);
|
|
564
|
-
expect(toolCalls[0].name).toBe('fake_browser_tool');
|
|
565
|
-
expect('url' in toolCalls[0].args).toBe(true);
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
test('ChatGoogleGenerativeAI can bindTools with langchain tools and invoke', async () => {
|
|
569
|
-
const model = createGoogleModel({
|
|
570
|
-
model: 'gemini-2.5-flash',
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
const modelWithTools = model.bindTools([new FakeBrowserTool()]);
|
|
574
|
-
const res = await modelWithTools.invoke([prompt]);
|
|
575
|
-
const toolCalls = res.tool_calls;
|
|
576
|
-
expect(toolCalls).toBeDefined();
|
|
577
|
-
if (!toolCalls) {
|
|
578
|
-
throw new Error('tool_calls not in response');
|
|
579
|
-
}
|
|
580
|
-
expect(toolCalls.length).toBe(1);
|
|
581
|
-
expect(toolCalls[0].name).toBe('fake_browser_tool');
|
|
582
|
-
expect('url' in toolCalls[0].args).toBe(true);
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
test('ChatGoogleGenerativeAI can bindTools with genai tools and invoke', async () => {
|
|
586
|
-
const model = createGoogleModel({
|
|
587
|
-
model: 'gemini-2.5-flash',
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
const modelWithTools = model.bindTools([googleGenAITool]);
|
|
591
|
-
const res = await modelWithTools.invoke([prompt]);
|
|
592
|
-
const toolCalls = res.tool_calls;
|
|
593
|
-
expect(toolCalls).toBeDefined();
|
|
594
|
-
if (!toolCalls) {
|
|
595
|
-
throw new Error('tool_calls not in response');
|
|
596
|
-
}
|
|
597
|
-
expect(toolCalls.length).toBe(1);
|
|
598
|
-
expect(toolCalls[0].name).toBe('fake_browser_tool');
|
|
599
|
-
expect('url' in toolCalls[0].args).toBe(true);
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
test('ChatGoogleGenerativeAI can call withStructuredOutput langchain tools and invoke', async () => {
|
|
603
|
-
const model = createGoogleModel({
|
|
604
|
-
model: 'gemini-2.0-flash',
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
const modelWithTools = model.withStructuredOutput(
|
|
608
|
-
z.object({
|
|
609
|
-
zomg: z.string(),
|
|
610
|
-
omg: z.number().optional(),
|
|
611
|
-
})
|
|
612
|
-
);
|
|
613
|
-
const res = await modelWithTools.invoke([prompt]);
|
|
614
|
-
expect(typeof res.zomg === 'string').toBe(true);
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
test('ChatGoogleGenerativeAI can call withStructuredOutput genai tools and invoke', async () => {
|
|
618
|
-
const model = createGoogleModel({
|
|
619
|
-
model: 'gemini-2.0-flash',
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
type GeminiTool = {
|
|
623
|
-
url: string;
|
|
624
|
-
query?: string;
|
|
625
|
-
};
|
|
626
|
-
|
|
627
|
-
const modelWithTools = model.withStructuredOutput<GeminiTool>(
|
|
628
|
-
googleGenAITool.functionDeclarations[0].parameters
|
|
629
|
-
);
|
|
630
|
-
const res = await modelWithTools.invoke([prompt]);
|
|
631
|
-
expect(typeof res.url === 'string').toBe(true);
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
test('Stream token count usage_metadata', async () => {
|
|
635
|
-
const model = createGoogleModel({
|
|
636
|
-
temperature: 0,
|
|
637
|
-
model: 'gemini-2.0-flash',
|
|
638
|
-
maxOutputTokens: 10,
|
|
639
|
-
});
|
|
640
|
-
let res: AIMessageChunk | null = null;
|
|
641
|
-
for await (const chunk of await model.stream(
|
|
642
|
-
'Why is the sky blue? Be concise.'
|
|
643
|
-
)) {
|
|
644
|
-
if (!res) {
|
|
645
|
-
res = chunk;
|
|
646
|
-
} else {
|
|
647
|
-
res = res.concat(chunk);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
expect(res?.usage_metadata).toBeDefined();
|
|
651
|
-
if (!res?.usage_metadata) {
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
expect(res.usage_metadata.input_tokens).toBeGreaterThan(1);
|
|
655
|
-
expect(res.usage_metadata.output_tokens).toBeGreaterThan(1);
|
|
656
|
-
expect(res.usage_metadata.total_tokens).toBe(
|
|
657
|
-
res.usage_metadata.input_tokens + res.usage_metadata.output_tokens
|
|
658
|
-
);
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
describe('ChatGoogleGenerativeAI should count tokens correctly', () => {
|
|
662
|
-
describe('when streaming', () => {
|
|
663
|
-
test.each(['gemini-2.5-flash', 'gemini-2.5-pro'])(
|
|
664
|
-
'with %s',
|
|
665
|
-
async (modelName) => {
|
|
666
|
-
const model = createGoogleModel({
|
|
667
|
-
model: modelName,
|
|
668
|
-
temperature: 0,
|
|
669
|
-
});
|
|
670
|
-
const res = await model.stream('Why is the sky blue? Be concise.');
|
|
671
|
-
let full: AIMessageChunk | undefined;
|
|
672
|
-
for await (const chunk of res) {
|
|
673
|
-
full ??= chunk;
|
|
674
|
-
full = full.concat(chunk);
|
|
675
|
-
}
|
|
676
|
-
// expect(full?.usage_metadata);
|
|
677
|
-
// expect(res.usage_metadata).toBeDefined();
|
|
678
|
-
}
|
|
679
|
-
);
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
test('streamUsage excludes token usage', async () => {
|
|
684
|
-
const model = createGoogleModel({
|
|
685
|
-
temperature: 0,
|
|
686
|
-
model: 'gemini-2.0-flash',
|
|
687
|
-
streamUsage: false,
|
|
688
|
-
});
|
|
689
|
-
let res: AIMessageChunk | null = null;
|
|
690
|
-
for await (const chunk of await model.stream(
|
|
691
|
-
'Why is the sky blue? Be concise.'
|
|
692
|
-
)) {
|
|
693
|
-
if (!res) {
|
|
694
|
-
res = chunk;
|
|
695
|
-
} else {
|
|
696
|
-
res = res.concat(chunk);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
expect(res?.usage_metadata).not.toBeDefined();
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
test('Invoke token count usage_metadata', async () => {
|
|
703
|
-
const model = createGoogleModel({
|
|
704
|
-
temperature: 0,
|
|
705
|
-
model: 'gemini-2.0-flash',
|
|
706
|
-
maxOutputTokens: 10,
|
|
707
|
-
});
|
|
708
|
-
const res = await model.invoke('Why is the sky blue? Be concise.');
|
|
709
|
-
expect(res?.usage_metadata).toBeDefined();
|
|
710
|
-
if (!res?.usage_metadata) {
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
expect(res.usage_metadata.input_tokens).toBeGreaterThan(1);
|
|
714
|
-
expect(res.usage_metadata.output_tokens).toBeGreaterThan(1);
|
|
715
|
-
expect(res.usage_metadata.total_tokens).toBe(
|
|
716
|
-
res.usage_metadata.input_tokens + res.usage_metadata.output_tokens
|
|
717
|
-
);
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
test('Invoke with JSON mode', async () => {
|
|
721
|
-
const model = createGoogleModel({
|
|
722
|
-
model: 'gemini-2.0-flash',
|
|
723
|
-
temperature: 0,
|
|
724
|
-
maxOutputTokens: 10,
|
|
725
|
-
json: true,
|
|
726
|
-
});
|
|
727
|
-
const res = await model.invoke('Why is the sky blue? Be concise.');
|
|
728
|
-
expect(res?.usage_metadata).toBeDefined();
|
|
729
|
-
if (!res?.usage_metadata) {
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
expect(res.usage_metadata.input_tokens).toBeGreaterThan(1);
|
|
733
|
-
expect(res.usage_metadata.output_tokens).toBeGreaterThan(1);
|
|
734
|
-
expect(res.usage_metadata.total_tokens).toBe(
|
|
735
|
-
res.usage_metadata.input_tokens + res.usage_metadata.output_tokens
|
|
736
|
-
);
|
|
737
|
-
});
|
|
738
|
-
|
|
739
|
-
test('Includes server-side tool invocation config when enabled', () => {
|
|
740
|
-
const model = new ChatGoogleGenerativeAI({
|
|
741
|
-
apiKey: 'test-key',
|
|
742
|
-
model: 'gemini-3.5-flash',
|
|
743
|
-
includeServerSideToolInvocations: true,
|
|
744
|
-
});
|
|
745
|
-
const getWeather = {
|
|
746
|
-
name: 'get_weather',
|
|
747
|
-
description: 'Get the weather',
|
|
748
|
-
};
|
|
749
|
-
|
|
750
|
-
const request = model.invocationParams({
|
|
751
|
-
tools: [{ googleSearch: {} }, { functionDeclarations: [getWeather] }],
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
expect(request.toolConfig).toEqual(
|
|
755
|
-
expect.objectContaining({
|
|
756
|
-
includeServerSideToolInvocations: true,
|
|
757
|
-
})
|
|
758
|
-
);
|
|
759
|
-
});
|
|
760
|
-
|
|
761
|
-
test('Normalizes auto tool choice when server-side tool invocation config is enabled', () => {
|
|
762
|
-
const model = new ChatGoogleGenerativeAI({
|
|
763
|
-
apiKey: 'test-key',
|
|
764
|
-
model: 'gemini-3.5-flash',
|
|
765
|
-
includeServerSideToolInvocations: true,
|
|
766
|
-
});
|
|
767
|
-
const getWeather = {
|
|
768
|
-
name: 'get_weather',
|
|
769
|
-
description: 'Get the weather',
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
const request = model.invocationParams({
|
|
773
|
-
tools: [{ googleSearch: {} }, { functionDeclarations: [getWeather] }],
|
|
774
|
-
tool_choice: 'auto',
|
|
775
|
-
});
|
|
776
|
-
const toolConfig = request.toolConfig as
|
|
777
|
-
| {
|
|
778
|
-
includeServerSideToolInvocations?: boolean;
|
|
779
|
-
functionCallingConfig?: { mode?: string };
|
|
780
|
-
}
|
|
781
|
-
| undefined;
|
|
782
|
-
|
|
783
|
-
expect(toolConfig).toEqual(
|
|
784
|
-
expect.objectContaining({
|
|
785
|
-
includeServerSideToolInvocations: true,
|
|
786
|
-
})
|
|
787
|
-
);
|
|
788
|
-
expect(toolConfig?.functionCallingConfig?.mode).toBe('VALIDATED');
|
|
789
|
-
});
|
|
790
|
-
|
|
791
|
-
test('Preserves Gemini server-side tool context parts in history', () => {
|
|
792
|
-
const toolCallPart = {
|
|
793
|
-
type: 'toolCall',
|
|
794
|
-
agentId: 'agent_1',
|
|
795
|
-
groupId: 1,
|
|
796
|
-
thoughtSignature: 'signature-1',
|
|
797
|
-
toolCall: {
|
|
798
|
-
id: 'server-search-1',
|
|
799
|
-
name: 'google_search',
|
|
800
|
-
args: {},
|
|
801
|
-
},
|
|
802
|
-
} as const;
|
|
803
|
-
const toolResponsePart = {
|
|
804
|
-
type: 'toolResponse',
|
|
805
|
-
agentId: 'agent_1',
|
|
806
|
-
groupId: 1,
|
|
807
|
-
toolResponse: {
|
|
808
|
-
id: 'server-search-1',
|
|
809
|
-
name: 'google_search',
|
|
810
|
-
response: { results: [] },
|
|
811
|
-
},
|
|
812
|
-
} as const;
|
|
813
|
-
const message = new AIMessage({
|
|
814
|
-
content: [toolCallPart, toolResponsePart],
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
expect(convertMessageContentToParts(message, true, [])).toEqual([
|
|
818
|
-
{
|
|
819
|
-
toolCall: toolCallPart.toolCall,
|
|
820
|
-
thoughtSignature: 'signature-1',
|
|
821
|
-
},
|
|
822
|
-
{
|
|
823
|
-
toolResponse: toolResponsePart.toolResponse,
|
|
824
|
-
},
|
|
825
|
-
]);
|
|
826
|
-
});
|
|
827
|
-
|
|
828
|
-
test('Preserves Gemini function-call ids in history', () => {
|
|
829
|
-
const aiMessage = new AIMessage({
|
|
830
|
-
content: '',
|
|
831
|
-
tool_calls: [
|
|
832
|
-
{
|
|
833
|
-
id: 'call_weather_1',
|
|
834
|
-
name: 'get_weather',
|
|
835
|
-
args: { city: 'NYC' },
|
|
836
|
-
},
|
|
837
|
-
],
|
|
838
|
-
});
|
|
839
|
-
const toolMessage = new ToolMessage({
|
|
840
|
-
content: 'sunny',
|
|
841
|
-
name: 'get_weather',
|
|
842
|
-
tool_call_id: 'call_weather_1',
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
expect(convertMessageContentToParts(aiMessage, true, [])).toEqual([
|
|
846
|
-
{
|
|
847
|
-
functionCall: {
|
|
848
|
-
id: 'call_weather_1',
|
|
849
|
-
name: 'get_weather',
|
|
850
|
-
args: { city: 'NYC' },
|
|
851
|
-
},
|
|
852
|
-
},
|
|
853
|
-
]);
|
|
854
|
-
expect(convertMessageContentToParts(toolMessage, true, [aiMessage])).toEqual([
|
|
855
|
-
{
|
|
856
|
-
functionResponse: {
|
|
857
|
-
id: 'call_weather_1',
|
|
858
|
-
name: 'get_weather',
|
|
859
|
-
response: { result: 'sunny' },
|
|
860
|
-
},
|
|
861
|
-
},
|
|
862
|
-
]);
|
|
863
|
-
});
|
|
864
|
-
|
|
865
|
-
test('Preserves Gemini server-side tool context parts from responses', () => {
|
|
866
|
-
const toolCallPart = {
|
|
867
|
-
toolCall: {
|
|
868
|
-
id: 'server-search-1',
|
|
869
|
-
name: 'google_search',
|
|
870
|
-
args: {},
|
|
871
|
-
},
|
|
872
|
-
};
|
|
873
|
-
const toolResponsePart = {
|
|
874
|
-
toolResponse: {
|
|
875
|
-
id: 'server-search-1',
|
|
876
|
-
name: 'google_search',
|
|
877
|
-
response: { results: [] },
|
|
878
|
-
},
|
|
879
|
-
};
|
|
880
|
-
const response = {
|
|
881
|
-
candidates: [
|
|
882
|
-
{
|
|
883
|
-
content: {
|
|
884
|
-
role: 'model',
|
|
885
|
-
parts: [toolCallPart, toolResponsePart],
|
|
886
|
-
},
|
|
887
|
-
},
|
|
888
|
-
],
|
|
889
|
-
} as unknown as Parameters<
|
|
890
|
-
typeof convertResponseContentToChatGenerationChunk
|
|
891
|
-
>[0];
|
|
892
|
-
|
|
893
|
-
const chunk = convertResponseContentToChatGenerationChunk(response, {
|
|
894
|
-
index: 0,
|
|
895
|
-
});
|
|
896
|
-
const result = mapGenerateContentResultToChatResult(response);
|
|
897
|
-
|
|
898
|
-
const expectedContent = [
|
|
899
|
-
{ ...toolCallPart, type: 'toolCall' },
|
|
900
|
-
{ ...toolResponsePart, type: 'toolResponse' },
|
|
901
|
-
];
|
|
902
|
-
expect(chunk?.message.content).toEqual(expectedContent);
|
|
903
|
-
expect(result.generations[0].message.content).toEqual(expectedContent);
|
|
904
|
-
});
|
|
905
|
-
|
|
906
|
-
test('Supports tool_choice', async () => {
|
|
907
|
-
const model = createGoogleModel({
|
|
908
|
-
model: 'gemini-2.0-flash',
|
|
909
|
-
});
|
|
910
|
-
const tools = [
|
|
911
|
-
{
|
|
912
|
-
name: 'get_weather',
|
|
913
|
-
description: 'Get the weather',
|
|
914
|
-
schema: z.object({
|
|
915
|
-
location: z.string(),
|
|
916
|
-
}),
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
name: 'calculator',
|
|
920
|
-
description: 'Preform calculations',
|
|
921
|
-
schema: z.object({
|
|
922
|
-
expression: z.string(),
|
|
923
|
-
}),
|
|
924
|
-
},
|
|
925
|
-
];
|
|
926
|
-
|
|
927
|
-
const modelWithTools = model.bindTools(tools, {
|
|
928
|
-
tool_choice: 'calculator',
|
|
929
|
-
allowedFunctionNames: ['calculator'],
|
|
930
|
-
});
|
|
931
|
-
const response = await modelWithTools.invoke(
|
|
932
|
-
'What is 27725327 times 283683? Also whats the weather in New York?'
|
|
933
|
-
);
|
|
934
|
-
expect(response.tool_calls?.length).toBe(1);
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
describe('GoogleSearchRetrievalTool', () => {
|
|
938
|
-
test('Supports GoogleSearchRetrievalTool', async () => {
|
|
939
|
-
const searchRetrievalTool: GoogleSearchRetrievalTool = {
|
|
940
|
-
googleSearchRetrieval: {
|
|
941
|
-
dynamicRetrievalConfig: {
|
|
942
|
-
mode: DynamicRetrievalMode.MODE_DYNAMIC,
|
|
943
|
-
dynamicThreshold: 0.7,
|
|
944
|
-
},
|
|
945
|
-
},
|
|
946
|
-
};
|
|
947
|
-
const model = createGoogleModel({
|
|
948
|
-
model: 'gemini-1.5-pro',
|
|
949
|
-
temperature: 0,
|
|
950
|
-
}).bindTools([searchRetrievalTool]);
|
|
951
|
-
|
|
952
|
-
const result = await model.invoke('Who won the 2024 MLB World Series?');
|
|
953
|
-
|
|
954
|
-
expect(result.response_metadata?.groundingMetadata).toBeDefined();
|
|
955
|
-
expect(result.content as string).toContain('Dodgers');
|
|
956
|
-
});
|
|
957
|
-
|
|
958
|
-
test('Can stream GoogleSearchRetrievalTool', async () => {
|
|
959
|
-
const searchRetrievalTool: GoogleSearchRetrievalTool = {
|
|
960
|
-
googleSearchRetrieval: {
|
|
961
|
-
dynamicRetrievalConfig: {
|
|
962
|
-
mode: DynamicRetrievalMode.MODE_DYNAMIC,
|
|
963
|
-
dynamicThreshold: 0.7,
|
|
964
|
-
},
|
|
965
|
-
},
|
|
966
|
-
};
|
|
967
|
-
const model = createGoogleModel({
|
|
968
|
-
model: 'gemini-1.5-pro',
|
|
969
|
-
temperature: 0,
|
|
970
|
-
}).bindTools([searchRetrievalTool]);
|
|
971
|
-
|
|
972
|
-
const stream = await model.stream('Who won the 2024 MLB World Series?');
|
|
973
|
-
let finalMsg: AIMessageChunk | undefined;
|
|
974
|
-
for await (const msg of stream) {
|
|
975
|
-
finalMsg = finalMsg ? concat(finalMsg, msg) : msg;
|
|
976
|
-
}
|
|
977
|
-
if (!finalMsg) {
|
|
978
|
-
throw new Error('finalMsg is undefined');
|
|
979
|
-
}
|
|
980
|
-
expect(finalMsg.response_metadata?.groundingMetadata).toBeDefined();
|
|
981
|
-
expect(finalMsg.content as string).toContain('Dodgers');
|
|
982
|
-
});
|
|
983
|
-
});
|
|
984
|
-
|
|
985
|
-
describe('GoogleSearch (new API)', () => {
|
|
986
|
-
test('Supports GoogleSearch tool', async () => {
|
|
987
|
-
// New google_search tool for Gemini 2.0+ models
|
|
988
|
-
const googleSearchTool = {
|
|
989
|
-
googleSearch: {},
|
|
990
|
-
};
|
|
991
|
-
const model = createGoogleModel({
|
|
992
|
-
model: 'gemini-2.5-flash',
|
|
993
|
-
temperature: 0,
|
|
994
|
-
}).bindTools([googleSearchTool]);
|
|
995
|
-
|
|
996
|
-
// Ask about something that requires current web data beyond training cutoff
|
|
997
|
-
const result = await model.invoke(
|
|
998
|
-
'What was the closing price of NVIDIA stock yesterday? Use web search to find the exact current price.'
|
|
999
|
-
);
|
|
1000
|
-
|
|
1001
|
-
expect(result.content).toBeDefined();
|
|
1002
|
-
expect(
|
|
1003
|
-
typeof result.content === 'string' || Array.isArray(result.content)
|
|
1004
|
-
).toBe(true);
|
|
1005
|
-
|
|
1006
|
-
// Grounding metadata should be present when Google Search is used
|
|
1007
|
-
expect(result.response_metadata?.groundingMetadata).toBeDefined();
|
|
1008
|
-
expect(result.response_metadata.groundingMetadata).toHaveProperty(
|
|
1009
|
-
'groundingChunks'
|
|
1010
|
-
);
|
|
1011
|
-
expect(result.response_metadata.groundingMetadata).toHaveProperty(
|
|
1012
|
-
'webSearchQueries'
|
|
1013
|
-
);
|
|
1014
|
-
});
|
|
1015
|
-
|
|
1016
|
-
test('Can stream GoogleSearch tool', async () => {
|
|
1017
|
-
const googleSearchTool = {
|
|
1018
|
-
googleSearch: {},
|
|
1019
|
-
};
|
|
1020
|
-
const model = createGoogleModel({
|
|
1021
|
-
model: 'gemini-2.5-flash',
|
|
1022
|
-
temperature: 0,
|
|
1023
|
-
}).bindTools([googleSearchTool]);
|
|
1024
|
-
|
|
1025
|
-
const stream = await model.stream(
|
|
1026
|
-
'What was the closing price of NVIDIA stock yesterday? Use web search to find the exact current price.'
|
|
1027
|
-
);
|
|
1028
|
-
let finalMsg: AIMessageChunk | undefined;
|
|
1029
|
-
for await (const msg of stream) {
|
|
1030
|
-
finalMsg = finalMsg ? concat(finalMsg, msg) : msg;
|
|
1031
|
-
}
|
|
1032
|
-
if (!finalMsg) {
|
|
1033
|
-
throw new Error('finalMsg is undefined');
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
expect(finalMsg.content).toBeDefined();
|
|
1037
|
-
expect(
|
|
1038
|
-
typeof finalMsg.content === 'string' || Array.isArray(finalMsg.content)
|
|
1039
|
-
).toBe(true);
|
|
1040
|
-
|
|
1041
|
-
// Grounding metadata should be present when Google Search is used
|
|
1042
|
-
expect(finalMsg.response_metadata?.groundingMetadata).toBeDefined();
|
|
1043
|
-
expect(finalMsg.response_metadata.groundingMetadata).toHaveProperty(
|
|
1044
|
-
'groundingChunks'
|
|
1045
|
-
);
|
|
1046
|
-
expect(finalMsg.response_metadata.groundingMetadata).toHaveProperty(
|
|
1047
|
-
'webSearchQueries'
|
|
1048
|
-
);
|
|
1049
|
-
});
|
|
1050
|
-
});
|
|
1051
|
-
|
|
1052
|
-
describe('CodeExecutionTool', () => {
|
|
1053
|
-
test('Supports CodeExecutionTool', async () => {
|
|
1054
|
-
const codeExecutionTool: CodeExecutionTool = {
|
|
1055
|
-
codeExecution: {}, // Simply pass an empty object to enable it.
|
|
1056
|
-
};
|
|
1057
|
-
const model = createGoogleModel({
|
|
1058
|
-
model: 'gemini-2.5-flash',
|
|
1059
|
-
temperature: 0,
|
|
1060
|
-
}).bindTools([codeExecutionTool]);
|
|
1061
|
-
|
|
1062
|
-
const result = await model.invoke(
|
|
1063
|
-
'Use code execution to find the sum of the first and last 3 numbers in the following list: [1, 2, 3, 72638, 8, 727, 4, 5, 6]'
|
|
1064
|
-
);
|
|
1065
|
-
|
|
1066
|
-
expect(Array.isArray(result.content)).toBeTruthy();
|
|
1067
|
-
if (!Array.isArray(result.content)) {
|
|
1068
|
-
throw new Error('Content is not an array');
|
|
1069
|
-
}
|
|
1070
|
-
const texts = result.content
|
|
1071
|
-
.flatMap((item) => ('text' in item ? [item.text] : []))
|
|
1072
|
-
.join('\n');
|
|
1073
|
-
expect(texts).toContain('21');
|
|
1074
|
-
|
|
1075
|
-
const executableCode = result.content.find(
|
|
1076
|
-
(item) => item.type === 'executableCode'
|
|
1077
|
-
);
|
|
1078
|
-
expect(executableCode).toBeDefined();
|
|
1079
|
-
const codeResult = result.content.find(
|
|
1080
|
-
(item) => item.type === 'codeExecutionResult'
|
|
1081
|
-
);
|
|
1082
|
-
expect(codeResult).toBeDefined();
|
|
1083
|
-
});
|
|
1084
|
-
|
|
1085
|
-
test('CodeExecutionTool contents can be passed in chat history', async () => {
|
|
1086
|
-
const codeExecutionTool: CodeExecutionTool = {
|
|
1087
|
-
codeExecution: {}, // Simply pass an empty object to enable it.
|
|
1088
|
-
};
|
|
1089
|
-
const model = createGoogleModel({
|
|
1090
|
-
model: 'gemini-2.5-flash',
|
|
1091
|
-
temperature: 0,
|
|
1092
|
-
}).bindTools([codeExecutionTool]);
|
|
1093
|
-
|
|
1094
|
-
const codeResult = await model.invoke(
|
|
1095
|
-
'Use code execution to find the sum of the first and last 3 numbers in the following list: [1, 2, 3, 72638, 8, 727, 4, 5, 6]'
|
|
1096
|
-
);
|
|
1097
|
-
|
|
1098
|
-
const explanation = await model.invoke([
|
|
1099
|
-
codeResult,
|
|
1100
|
-
{
|
|
1101
|
-
role: 'user',
|
|
1102
|
-
content:
|
|
1103
|
-
'Please explain the question I asked, the code you wrote, and the answer you got.',
|
|
1104
|
-
},
|
|
1105
|
-
]);
|
|
1106
|
-
|
|
1107
|
-
// Content can be string or array depending on response format
|
|
1108
|
-
if (typeof explanation.content === 'string') {
|
|
1109
|
-
expect(explanation.content.length).toBeGreaterThan(10);
|
|
1110
|
-
} else if (Array.isArray(explanation.content)) {
|
|
1111
|
-
expect(explanation.content.length).toBeGreaterThan(0);
|
|
1112
|
-
} else {
|
|
1113
|
-
expect(explanation.content).toBeDefined();
|
|
1114
|
-
}
|
|
1115
|
-
});
|
|
1116
|
-
|
|
1117
|
-
test('Can stream CodeExecutionTool', async () => {
|
|
1118
|
-
const codeExecutionTool: CodeExecutionTool = {
|
|
1119
|
-
codeExecution: {}, // Simply pass an empty object to enable it.
|
|
1120
|
-
};
|
|
1121
|
-
const model = createGoogleModel({
|
|
1122
|
-
model: 'gemini-2.5-flash',
|
|
1123
|
-
temperature: 0,
|
|
1124
|
-
}).bindTools([codeExecutionTool]);
|
|
1125
|
-
|
|
1126
|
-
const stream = await model.stream(
|
|
1127
|
-
'Use code execution to find the sum of the first and last 3 numbers in the following list: [1, 2, 3, 72638, 8, 727, 4, 5, 6]'
|
|
1128
|
-
);
|
|
1129
|
-
let finalMsg: AIMessageChunk | undefined;
|
|
1130
|
-
for await (const msg of stream) {
|
|
1131
|
-
finalMsg = finalMsg ? concat(finalMsg, msg) : msg;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
if (!finalMsg) {
|
|
1135
|
-
throw new Error('finalMsg is undefined');
|
|
1136
|
-
}
|
|
1137
|
-
expect(Array.isArray(finalMsg.content)).toBeTruthy();
|
|
1138
|
-
if (!Array.isArray(finalMsg.content)) {
|
|
1139
|
-
throw new Error('Content is not an array');
|
|
1140
|
-
}
|
|
1141
|
-
const texts = finalMsg.content
|
|
1142
|
-
.flatMap((item) => ('text' in item ? [item.text] : []))
|
|
1143
|
-
.join('\n');
|
|
1144
|
-
expect(texts).toContain('21');
|
|
1145
|
-
|
|
1146
|
-
const executableCode = finalMsg.content.find(
|
|
1147
|
-
(item) => item.type === 'executableCode'
|
|
1148
|
-
);
|
|
1149
|
-
expect(executableCode).toBeDefined();
|
|
1150
|
-
const codeResult = finalMsg.content.find(
|
|
1151
|
-
(item) => item.type === 'codeExecutionResult'
|
|
1152
|
-
);
|
|
1153
|
-
expect(codeResult).toBeDefined();
|
|
1154
|
-
});
|
|
1155
|
-
});
|
|
1156
|
-
|
|
1157
|
-
test('pass pdf to request', async () => {
|
|
1158
|
-
const model = createGoogleModel({
|
|
1159
|
-
model: 'gemini-2.0-flash-exp',
|
|
1160
|
-
temperature: 0,
|
|
1161
|
-
});
|
|
1162
|
-
const pdfPath = path.join(
|
|
1163
|
-
__dirname,
|
|
1164
|
-
'../anthropic/Jacob_Lee_Resume_2023.pdf'
|
|
1165
|
-
);
|
|
1166
|
-
const pdfBase64 = await fs.readFile(pdfPath, 'base64');
|
|
1167
|
-
|
|
1168
|
-
const response = await model.invoke([
|
|
1169
|
-
['system', 'Use the provided documents to answer the question'],
|
|
1170
|
-
[
|
|
1171
|
-
'user',
|
|
1172
|
-
[
|
|
1173
|
-
{
|
|
1174
|
-
type: 'application/pdf',
|
|
1175
|
-
data: pdfBase64,
|
|
1176
|
-
},
|
|
1177
|
-
{
|
|
1178
|
-
type: 'text',
|
|
1179
|
-
text: 'Summarize the contents of this PDF',
|
|
1180
|
-
},
|
|
1181
|
-
],
|
|
1182
|
-
],
|
|
1183
|
-
]);
|
|
1184
|
-
|
|
1185
|
-
expect(response.content.length).toBeGreaterThan(10);
|
|
1186
|
-
});
|
|
1187
|
-
|
|
1188
|
-
test('calling tool with no args should work', async () => {
|
|
1189
|
-
const llm = createGoogleModel({
|
|
1190
|
-
model: 'gemini-2.0-flash',
|
|
1191
|
-
});
|
|
1192
|
-
const sfWeatherTool = tool(
|
|
1193
|
-
async () => 'The weather is 80 degrees and sunny',
|
|
1194
|
-
{
|
|
1195
|
-
name: 'sf_weather',
|
|
1196
|
-
description: 'Gets the weather in SF',
|
|
1197
|
-
schema: z.object({}),
|
|
1198
|
-
}
|
|
1199
|
-
);
|
|
1200
|
-
const llmWithTools = llm.bindTools([sfWeatherTool]);
|
|
1201
|
-
const result = await llmWithTools.invoke([
|
|
1202
|
-
{
|
|
1203
|
-
role: 'user',
|
|
1204
|
-
content: 'What is the current weather in SF?',
|
|
1205
|
-
},
|
|
1206
|
-
]);
|
|
1207
|
-
const nextMessage = await sfWeatherTool.invoke(result.tool_calls![0]);
|
|
1208
|
-
delete nextMessage.name; // Should work even if name is not present
|
|
1209
|
-
const finalResult = await llmWithTools.invoke([
|
|
1210
|
-
{
|
|
1211
|
-
role: 'user',
|
|
1212
|
-
content: 'What is the current weather in SF?',
|
|
1213
|
-
},
|
|
1214
|
-
result,
|
|
1215
|
-
nextMessage,
|
|
1216
|
-
]);
|
|
1217
|
-
expect(finalResult.content).toContain('80');
|
|
1218
|
-
});
|
|
1219
|
-
|
|
1220
|
-
describe('tool calling with thought signatures', () => {
|
|
1221
|
-
const model = createGoogleModel({
|
|
1222
|
-
model: 'gemini-3-pro-preview',
|
|
1223
|
-
});
|
|
1224
|
-
const weatherTool = tool(async () => 'The weather is 80 degrees and sunny', {
|
|
1225
|
-
name: 'weather',
|
|
1226
|
-
description: 'Gets the weather in SF',
|
|
1227
|
-
schema: z.object({}),
|
|
1228
|
-
});
|
|
1229
|
-
const modelWithTools = model.bindTools([weatherTool]);
|
|
1230
|
-
|
|
1231
|
-
test('works when invoking', async () => {
|
|
1232
|
-
const result = await modelWithTools.invoke(
|
|
1233
|
-
'What is the current weather in SF?'
|
|
1234
|
-
);
|
|
1235
|
-
expect(result.tool_calls).toBeDefined();
|
|
1236
|
-
expect(result.tool_calls!.length).toBe(1);
|
|
1237
|
-
expect(result.tool_calls![0].id).toBeDefined();
|
|
1238
|
-
|
|
1239
|
-
const toolMessage = new ToolMessage({
|
|
1240
|
-
content: 'The weather is 80 degrees and sunny',
|
|
1241
|
-
tool_call_id: result.tool_calls![0].id ?? '',
|
|
1242
|
-
});
|
|
1243
|
-
|
|
1244
|
-
// Thought signatures are stored in additional_kwargs
|
|
1245
|
-
const thoughtSignatures = result.additional_kwargs?.[
|
|
1246
|
-
_FUNCTION_CALL_THOUGHT_SIGNATURES_MAP_KEY
|
|
1247
|
-
] as Record<string, string> | undefined;
|
|
1248
|
-
|
|
1249
|
-
// Gemini 3 REQUIRES thought signatures - not optional
|
|
1250
|
-
expect(thoughtSignatures).toBeDefined();
|
|
1251
|
-
expect(thoughtSignatures![result.tool_calls![0].id ?? '']).toBeDefined();
|
|
1252
|
-
|
|
1253
|
-
const finalResult = await model.invoke([
|
|
1254
|
-
new HumanMessage('What is the current weather in SF?'),
|
|
1255
|
-
result,
|
|
1256
|
-
toolMessage,
|
|
1257
|
-
]);
|
|
1258
|
-
expect(finalResult.content).toBeDefined();
|
|
1259
|
-
});
|
|
1260
|
-
|
|
1261
|
-
test('works when streaming', async () => {
|
|
1262
|
-
let finalChunk: AIMessageChunk | undefined;
|
|
1263
|
-
for await (const chunk of await modelWithTools.stream(
|
|
1264
|
-
'What is the current weather in SF?'
|
|
1265
|
-
)) {
|
|
1266
|
-
finalChunk = finalChunk ? finalChunk.concat(chunk) : chunk;
|
|
1267
|
-
}
|
|
1268
|
-
expect(finalChunk).toBeDefined();
|
|
1269
|
-
expect(finalChunk?.tool_calls).toBeDefined();
|
|
1270
|
-
expect(finalChunk?.tool_calls!.length).toBe(1);
|
|
1271
|
-
const toolMessage = new ToolMessage({
|
|
1272
|
-
content: 'The weather is 80 degrees and sunny',
|
|
1273
|
-
tool_call_id: finalChunk?.tool_calls![0].id ?? '',
|
|
1274
|
-
});
|
|
1275
|
-
|
|
1276
|
-
// Thought signatures are stored in additional_kwargs
|
|
1277
|
-
const thoughtSignatures = finalChunk?.additional_kwargs[
|
|
1278
|
-
_FUNCTION_CALL_THOUGHT_SIGNATURES_MAP_KEY
|
|
1279
|
-
] as Record<string, string> | undefined;
|
|
1280
|
-
|
|
1281
|
-
// Only check if thought signatures exist (may not be present for all models/responses)
|
|
1282
|
-
if (thoughtSignatures) {
|
|
1283
|
-
expect(
|
|
1284
|
-
thoughtSignatures[finalChunk?.tool_calls![0].id ?? '']
|
|
1285
|
-
).toBeDefined();
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
const finalResult = await model.invoke([
|
|
1289
|
-
new HumanMessage('What is the current weather in SF?'),
|
|
1290
|
-
finalChunk!,
|
|
1291
|
-
toolMessage,
|
|
1292
|
-
]);
|
|
1293
|
-
expect(finalResult.content).toBeDefined();
|
|
1294
|
-
});
|
|
1295
|
-
});
|
|
1296
|
-
|
|
1297
|
-
test('works with thinking config', async () => {
|
|
1298
|
-
const model = createGoogleModel({
|
|
1299
|
-
model: 'gemini-3-pro-preview',
|
|
1300
|
-
thinkingConfig: {
|
|
1301
|
-
includeThoughts: true,
|
|
1302
|
-
thinkingBudget: 100,
|
|
1303
|
-
},
|
|
1304
|
-
});
|
|
1305
|
-
const result = await model.invoke('What is 2+2?');
|
|
1306
|
-
expect(result.content).toBeDefined();
|
|
1307
|
-
|
|
1308
|
-
if (Array.isArray(result.content)) {
|
|
1309
|
-
const thinkingBlocks = result.content.filter(
|
|
1310
|
-
(block): block is ContentBlock =>
|
|
1311
|
-
typeof block === 'object' &&
|
|
1312
|
-
block !== null &&
|
|
1313
|
-
'type' in block &&
|
|
1314
|
-
block.type === 'thinking'
|
|
1315
|
-
);
|
|
1316
|
-
const textBlocks = result.content.filter(
|
|
1317
|
-
(block): block is ContentBlock =>
|
|
1318
|
-
typeof block === 'object' &&
|
|
1319
|
-
block !== null &&
|
|
1320
|
-
'type' in block &&
|
|
1321
|
-
block.type === 'text'
|
|
1322
|
-
);
|
|
1323
|
-
|
|
1324
|
-
expect(thinkingBlocks.length).toBeGreaterThan(0);
|
|
1325
|
-
|
|
1326
|
-
thinkingBlocks.forEach((block) => {
|
|
1327
|
-
expect(block).toHaveProperty('thinking');
|
|
1328
|
-
expect(typeof block.thinking).toBe('string');
|
|
1329
|
-
});
|
|
1330
|
-
|
|
1331
|
-
textBlocks.forEach((block) => {
|
|
1332
|
-
expect(block).toHaveProperty('text');
|
|
1333
|
-
expect(typeof block.text).toBe('string');
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
});
|
|
1337
|
-
|
|
1338
|
-
describe('Google GenAI Reasoning with contentBlocks', () => {
|
|
1339
|
-
test('invoke returns thinking as reasoning in contentBlocks', async () => {
|
|
1340
|
-
const model = createGoogleModel({
|
|
1341
|
-
model: 'gemini-3-pro-preview',
|
|
1342
|
-
thinkingConfig: {
|
|
1343
|
-
includeThoughts: true,
|
|
1344
|
-
thinkingBudget: 100,
|
|
1345
|
-
},
|
|
1346
|
-
});
|
|
1347
|
-
|
|
1348
|
-
const result = await model.invoke('What is 2 + 2?');
|
|
1349
|
-
const blocks = result.contentBlocks;
|
|
1350
|
-
|
|
1351
|
-
expect(blocks.length).toBeGreaterThan(0);
|
|
1352
|
-
|
|
1353
|
-
const reasoningBlocks = blocks.filter(
|
|
1354
|
-
(block): block is ContentBlock.Reasoning => block.type === 'reasoning'
|
|
1355
|
-
);
|
|
1356
|
-
expect(reasoningBlocks.length).toBeGreaterThan(0);
|
|
1357
|
-
expect(reasoningBlocks[0].reasoning.length).toBeGreaterThan(0);
|
|
1358
|
-
|
|
1359
|
-
const textBlocks = blocks.filter((block) => block.type === 'text');
|
|
1360
|
-
expect(textBlocks.length).toBeGreaterThan(0);
|
|
1361
|
-
});
|
|
1362
|
-
|
|
1363
|
-
test('stream returns thinking as reasoning in contentBlocks', async () => {
|
|
1364
|
-
const model = createGoogleModel({
|
|
1365
|
-
model: 'gemini-3-pro-preview',
|
|
1366
|
-
thinkingConfig: {
|
|
1367
|
-
includeThoughts: true,
|
|
1368
|
-
thinkingBudget: 100,
|
|
1369
|
-
},
|
|
1370
|
-
});
|
|
1371
|
-
|
|
1372
|
-
let fullMessage: AIMessageChunk | null = null;
|
|
1373
|
-
for await (const chunk of await model.stream('What is 3 + 3?')) {
|
|
1374
|
-
fullMessage = fullMessage ? concat(fullMessage, chunk) : chunk;
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
expect(fullMessage).toBeDefined();
|
|
1378
|
-
|
|
1379
|
-
const blocks = fullMessage!.contentBlocks;
|
|
1380
|
-
expect(blocks.length).toBeGreaterThan(0);
|
|
1381
|
-
|
|
1382
|
-
const reasoningBlocks = blocks.filter(
|
|
1383
|
-
(block): block is ContentBlock.Reasoning => block.type === 'reasoning'
|
|
1384
|
-
);
|
|
1385
|
-
expect(reasoningBlocks.length).toBeGreaterThan(0);
|
|
1386
|
-
expect(reasoningBlocks[0].reasoning.length).toBeGreaterThan(0);
|
|
1387
|
-
});
|
|
1388
|
-
});
|