@librechat/agents 4.2.11 → 4.2.13
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/graphs/Graph.cjs +15 -3
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +63 -35
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseConfig.cjs +6 -0
- package/dist/cjs/langfuseConfig.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +18 -8
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +4 -3
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/container.cjs +37 -0
- package/dist/cjs/llm/anthropic/utils/container.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +25 -23
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +15 -21
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs +16 -14
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -1
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +19 -13
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +59 -13
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +12 -2
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +15 -2
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/responseToolArguments.cjs +62 -0
- package/dist/cjs/llm/openai/responseToolArguments.cjs.map +1 -0
- package/dist/cjs/llm/openrouter/index.cjs +11 -2
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +35 -7
- package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
- package/dist/cjs/main.cjs +9 -3
- package/dist/cjs/messages/alternation.cjs +1 -1
- package/dist/cjs/messages/anthropicServerTools.cjs +20 -0
- package/dist/cjs/messages/anthropicServerTools.cjs.map +1 -0
- package/dist/cjs/messages/budget.cjs +1 -1
- package/dist/cjs/messages/cache.cjs +14 -1
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +4 -3
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +3 -3
- package/dist/cjs/messages/index.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +1 -1
- package/dist/cjs/messages/recency.cjs +1 -1
- package/dist/cjs/messages/toolResultTypes.cjs +21 -45
- package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
- package/dist/cjs/protection/providerText.cjs +4 -0
- package/dist/cjs/protection/providerText.cjs.map +1 -1
- package/dist/cjs/protection/toolResult.cjs +119 -0
- package/dist/cjs/protection/toolResult.cjs.map +1 -0
- package/dist/cjs/run.cjs +31 -13
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/runtime/admission.cjs +1 -1
- package/dist/cjs/runtime/client.cjs +3 -0
- package/dist/cjs/runtime/client.cjs.map +1 -1
- package/dist/cjs/stream.cjs +2 -1
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +9 -4
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +1 -1
- package/dist/cjs/tools/ToolNode.cjs +47 -14
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +1 -1
- package/dist/cjs/tools/search/content.cjs +163 -42
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +8 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +2 -2
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +7 -2
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +15 -3
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +63 -35
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseConfig.mjs +6 -1
- package/dist/esm/langfuseConfig.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +2 -2
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +18 -9
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +4 -3
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/container.mjs +37 -0
- package/dist/esm/llm/anthropic/utils/container.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +25 -23
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +15 -21
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/stream_events.mjs +16 -14
- package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +2 -2
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +19 -14
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +59 -13
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +12 -2
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +16 -3
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/responseToolArguments.mjs +62 -0
- package/dist/esm/llm/openai/responseToolArguments.mjs.map +1 -0
- package/dist/esm/llm/openrouter/index.mjs +11 -2
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +35 -7
- package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
- package/dist/esm/main.mjs +5 -4
- package/dist/esm/messages/alternation.mjs +1 -1
- package/dist/esm/messages/anthropicServerTools.mjs +18 -0
- package/dist/esm/messages/anthropicServerTools.mjs.map +1 -0
- package/dist/esm/messages/budget.mjs +1 -1
- package/dist/esm/messages/cache.mjs +12 -2
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +4 -3
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +3 -3
- package/dist/esm/messages/index.mjs +1 -1
- package/dist/esm/messages/prune.mjs +1 -1
- package/dist/esm/messages/recency.mjs +1 -1
- package/dist/esm/messages/toolResultTypes.mjs +21 -45
- package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
- package/dist/esm/protection/providerText.mjs +4 -1
- package/dist/esm/protection/providerText.mjs.map +1 -1
- package/dist/esm/protection/toolResult.mjs +114 -0
- package/dist/esm/protection/toolResult.mjs.map +1 -0
- package/dist/esm/run.mjs +32 -14
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/runtime/admission.mjs +1 -1
- package/dist/esm/runtime/client.mjs +3 -0
- package/dist/esm/runtime/client.mjs.map +1 -1
- package/dist/esm/stream.mjs +2 -1
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +9 -4
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +1 -1
- package/dist/esm/tools/ToolNode.mjs +47 -14
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +1 -1
- package/dist/esm/tools/search/content.mjs +163 -42
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +8 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +2 -2
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +7 -2
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/common/index.d.ts +2 -2
- package/dist/types/decisions/breaker.d.ts +2 -2
- package/dist/types/decisions/core.d.ts +13 -13
- package/dist/types/decisions/dialect.d.ts +1 -1
- package/dist/types/decisions/http.d.ts +2 -2
- package/dist/types/decisions/index.d.ts +5 -5
- package/dist/types/decisions/node.d.ts +2 -2
- package/dist/types/decisions/presets.d.ts +2 -2
- package/dist/types/decisions/probe.d.ts +1 -1
- package/dist/types/decisions/questions.d.ts +1 -1
- package/dist/types/decisions/structuredChat.d.ts +2 -2
- package/dist/types/decisions/transport.d.ts +1 -1
- package/dist/types/eventActor/EventActorExecutor.d.ts +1 -1
- package/dist/types/eventActor/index.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +6 -2
- package/dist/types/graphs/MultiAgentGraph.d.ts +1 -1
- package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +1 -1
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/graphs/index.d.ts +5 -5
- package/dist/types/harness/fileBindings.d.ts +2 -2
- package/dist/types/harness/fileService.d.ts +2 -2
- package/dist/types/harness/fileStream.d.ts +1 -1
- package/dist/types/harness/index.d.ts +15 -15
- package/dist/types/harness/model.d.ts +1 -1
- package/dist/types/harness/modelService.d.ts +2 -2
- package/dist/types/harness/modelStreamCallbacks.d.ts +1 -1
- package/dist/types/harness/providerText.d.ts +1 -1
- package/dist/types/hitl/index.d.ts +3 -3
- package/dist/types/hooks/HookRegistry.d.ts +1 -1
- package/dist/types/hooks/createToolPolicyHook.d.ts +1 -1
- package/dist/types/hooks/createWorkspacePolicyHook.d.ts +1 -1
- package/dist/types/hooks/executeHooks.d.ts +2 -2
- package/dist/types/hooks/index.d.ts +11 -11
- package/dist/types/index.d.ts +62 -60
- package/dist/types/langchain/index.d.ts +8 -8
- package/dist/types/langfuse.d.ts +7 -4
- package/dist/types/langfuseConfig.d.ts +5 -0
- package/dist/types/langfuseTraceShaping.d.ts +5 -0
- package/dist/types/llm/anthropic/utils/container.d.ts +4 -0
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/stream_events.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +2 -3
- package/dist/types/llm/bedrock/utils/harmony.d.ts +1 -1
- package/dist/types/llm/bedrock/utils/index.d.ts +2 -2
- package/dist/types/llm/bedrock/utils/message_inputs.d.ts +3 -12
- package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/google/index.d.ts +2 -2
- package/dist/types/llm/google/utils/common.d.ts +1 -1
- package/dist/types/llm/google/utils/tools.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -1
- package/dist/types/llm/openai/responseToolArguments.d.ts +7 -0
- package/dist/types/llm/openrouter/index.d.ts +1 -0
- package/dist/types/llm/prepareProviderRequest.d.ts +4 -1
- package/dist/types/llm/providerRegistry.d.ts +1 -1
- package/dist/types/llm/providers.d.ts +1 -1
- package/dist/types/messages/anthropicServerTools.d.ts +13 -0
- package/dist/types/messages/cache.d.ts +13 -0
- package/dist/types/messages/contextPruning.d.ts +1 -1
- package/dist/types/messages/core.d.ts +4 -4
- package/dist/types/messages/format.d.ts +1 -1
- package/dist/types/messages/index.d.ts +21 -21
- package/dist/types/messages/prune.d.ts +1 -1
- package/dist/types/openai/index.d.ts +2 -2
- package/dist/types/openai/toolProjection.d.ts +1 -1
- package/dist/types/prompts/index.d.ts +2 -2
- package/dist/types/protection/providerText.d.ts +3 -1
- package/dist/types/protection/toolResult.d.ts +69 -0
- package/dist/types/provider-registration.d.ts +1 -1
- package/dist/types/rerank/bm25.d.ts +1 -1
- package/dist/types/rerank/core.d.ts +17 -17
- package/dist/types/rerank/crossEncoder.d.ts +3 -3
- package/dist/types/rerank/fallback.d.ts +1 -1
- package/dist/types/rerank/index.d.ts +2 -2
- package/dist/types/rerank/outcome.d.ts +2 -2
- package/dist/types/rerank/pin.d.ts +2 -2
- package/dist/types/rerank/search.d.ts +1 -1
- package/dist/types/rerank/systemone.d.ts +4 -4
- package/dist/types/rerank/types.d.ts +1 -1
- package/dist/types/run.d.ts +2 -0
- package/dist/types/runtime/admission.d.ts +1 -1
- package/dist/types/runtime/checkpoint.d.ts +1 -1
- package/dist/types/runtime/client.d.ts +2 -2
- package/dist/types/runtime/files.d.ts +4 -4
- package/dist/types/runtime/hostTools.d.ts +2 -2
- package/dist/types/runtime/index.d.ts +12 -12
- package/dist/types/runtime/model.d.ts +5 -5
- package/dist/types/runtime/policy.d.ts +3 -3
- package/dist/types/runtime/recovery/client.d.ts +3 -3
- package/dist/types/runtime/recovery/log.d.ts +2 -2
- package/dist/types/runtime/recovery/redis.d.ts +1 -1
- package/dist/types/runtime/recovery/server.d.ts +3 -3
- package/dist/types/runtime/resume.d.ts +1 -1
- package/dist/types/runtime/server.d.ts +3 -3
- package/dist/types/runtime/snapshot.d.ts +1 -1
- package/dist/types/runtime/types.d.ts +2 -2
- package/dist/types/session/AgentSession.d.ts +2 -2
- package/dist/types/session/JsonlSessionStore.d.ts +1 -1
- package/dist/types/session/deriveMessages.d.ts +1 -1
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/index.d.ts +7 -7
- package/dist/types/session/messageSerialization.d.ts +1 -1
- package/dist/types/session/sessionProjection.d.ts +3 -3
- package/dist/types/summarization/index.d.ts +2 -2
- package/dist/types/summarization/node.d.ts +2 -0
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/GitHubCompare.d.ts +6 -6
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/ReadFile.d.ts +6 -6
- package/dist/types/tools/SkillTool.d.ts +6 -6
- package/dist/types/tools/ToolNode.d.ts +5 -1
- package/dist/types/tools/cloudflare/index.d.ts +4 -4
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/attachments.d.ts +1 -1
- package/dist/types/tools/local/index.d.ts +12 -12
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/search/content.d.ts +38 -1
- package/dist/types/tools/search/crw-scraper.d.ts +1 -1
- package/dist/types/tools/search/crw-search.d.ts +1 -1
- package/dist/types/tools/search/firecrawl.d.ts +1 -1
- package/dist/types/tools/search/format.d.ts +1 -1
- package/dist/types/tools/search/highlights.d.ts +1 -1
- package/dist/types/tools/search/index.d.ts +3 -3
- package/dist/types/tools/search/keenable-scraper.d.ts +1 -1
- package/dist/types/tools/search/keenable-search.d.ts +1 -1
- package/dist/types/tools/search/metrics.d.ts +1 -1
- package/dist/types/tools/search/rerankers.d.ts +1 -1
- package/dist/types/tools/search/schema.d.ts +6 -6
- package/dist/types/tools/search/search.d.ts +1 -1
- package/dist/types/tools/search/serper-scraper.d.ts +1 -1
- package/dist/types/tools/search/tavily-scraper.d.ts +1 -1
- package/dist/types/tools/search/tavily-search.d.ts +1 -1
- package/dist/types/tools/search/tool.d.ts +3 -3
- package/dist/types/tools/search/types.d.ts +2 -2
- package/dist/types/tools/search/utils.d.ts +3 -3
- package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +9 -3
- package/dist/types/tools/subagent/diagnostics.d.ts +1 -1
- package/dist/types/tools/subagent/index.d.ts +7 -7
- package/dist/types/types/attachments.d.ts +25 -0
- package/dist/types/types/graph.d.ts +15 -0
- package/dist/types/types/index.d.ts +14 -13
- package/dist/types/types/llm.d.ts +2 -2
- package/dist/types/types/run.d.ts +7 -2
- package/dist/types/types/subagentTasks.d.ts +2 -2
- package/dist/types/types/tools.d.ts +6 -3
- package/dist/types/utils/events.d.ts +2 -1
- package/dist/types/utils/index.d.ts +10 -10
- package/dist/types/utils/tokens.d.ts +1 -0
- package/package.json +14 -12
- package/src/graphs/Graph.ts +32 -1
- package/src/index.ts +8 -0
- package/src/langfuse.ts +129 -41
- package/src/langfuseConfig.ts +14 -0
- package/src/langfuseToolOutputTracing.ts +5 -4
- package/src/langfuseTraceShaping.ts +49 -12
- package/src/llm/anthropic/index.ts +11 -3
- package/src/llm/anthropic/utils/container.ts +63 -0
- package/src/llm/anthropic/utils/message_inputs.ts +57 -51
- package/src/llm/anthropic/utils/message_outputs.ts +12 -39
- package/src/llm/anthropic/utils/stream_events.ts +17 -12
- package/src/llm/bedrock/index.ts +7 -5
- package/src/llm/bedrock/utils/message_inputs.ts +28 -35
- package/src/llm/google/utils/common.ts +88 -36
- package/src/llm/init.ts +35 -3
- package/src/llm/openai/index.ts +17 -2
- package/src/llm/openai/responseToolArguments.ts +104 -0
- package/src/llm/openrouter/index.ts +13 -0
- package/src/llm/prepareProviderRequest.ts +75 -13
- package/src/messages/anthropicServerTools.ts +24 -0
- package/src/messages/cache.ts +25 -5
- package/src/messages/core.ts +12 -11
- package/src/messages/toolResultTypes.ts +80 -88
- package/src/protection/providerText.ts +127 -40
- package/src/protection/toolResult.ts +272 -0
- package/src/run.ts +112 -47
- package/src/runtime/client.ts +7 -0
- package/src/stream.ts +7 -1
- package/src/summarization/node.ts +17 -4
- package/src/tools/ToolNode.ts +114 -18
- package/src/tools/search/content.ts +282 -62
- package/src/tools/subagent/SubagentExecutor.ts +12 -0
- package/src/types/attachments.ts +31 -0
- package/src/types/graph.ts +12 -0
- package/src/types/index.ts +1 -0
- package/src/types/run.ts +8 -1
- package/src/types/tools.ts +3 -0
- package/src/utils/events.ts +9 -2
- package/src/utils/tokens.ts +28 -2
|
@@ -29,9 +29,9 @@ import type {
|
|
|
29
29
|
MessageContentReasoningBlock,
|
|
30
30
|
} from '../types';
|
|
31
31
|
import { serializeStructuredValueBounded } from '@/utils/toolContent';
|
|
32
|
-
import { neutralizeHarmonyRequest } from './harmony';
|
|
33
32
|
import { isReasoningContentBlock } from '@/messages/reasoningTypes';
|
|
34
33
|
import { HARD_MAX_TOOL_RESULT_CHARS } from '@/utils/truncation';
|
|
34
|
+
import { neutralizeHarmonyRequest } from './harmony';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Reasoning blocks from other providers, relative to Bedrock. Bedrock's native
|
|
@@ -272,8 +272,9 @@ const mimeTypeToDocumentFormat: Partial<Record<string, DocumentFormat>> = {
|
|
|
272
272
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
+
/** Decodes natively: `atob` plus a per-character copy takes ~45 ms per MB on the request path. */
|
|
275
276
|
function base64ToBytes(data: string): Uint8Array {
|
|
276
|
-
return
|
|
277
|
+
return Buffer.from(data, 'base64');
|
|
277
278
|
}
|
|
278
279
|
|
|
279
280
|
function getMediaFormat<T extends string>(
|
|
@@ -583,9 +584,7 @@ function convertLangChainContentBlockToConverseContentBlock({
|
|
|
583
584
|
image: {
|
|
584
585
|
format,
|
|
585
586
|
source: {
|
|
586
|
-
bytes:
|
|
587
|
-
c.charCodeAt(0)
|
|
588
|
-
),
|
|
587
|
+
bytes: base64ToBytes(imageBlock.data),
|
|
589
588
|
},
|
|
590
589
|
},
|
|
591
590
|
};
|
|
@@ -1141,37 +1140,31 @@ export interface ConvertToConverseMessagesOptions {
|
|
|
1141
1140
|
model?: string;
|
|
1142
1141
|
}
|
|
1143
1142
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1143
|
+
const BEDROCK_NAMED_MODEL_ARN =
|
|
1144
|
+
/^arn:[^:]+:bedrock:[^:]*:[^:]*:(?:foundation-model|inference-profile)\/(.+)$/;
|
|
1145
|
+
|
|
1146
|
+
function bedrockReplayException(
|
|
1147
|
+
model?: string
|
|
1148
|
+
): 'openai' | 'grok-4.7' | undefined {
|
|
1149
|
+
if (model == null || model === '') return undefined;
|
|
1150
|
+
const normalized = model.toLowerCase();
|
|
1151
|
+
const id = normalized.startsWith('arn:')
|
|
1152
|
+
? BEDROCK_NAMED_MODEL_ARN.exec(normalized)?.[1]
|
|
1153
|
+
: normalized;
|
|
1154
|
+
if (id == null) return undefined;
|
|
1155
|
+
if (/(?:^|\.)openai\./.test(id)) return 'openai';
|
|
1156
|
+
if (/(?:^|\.)xai\.grok-4\.7(?:$|[-:])/.test(id)) return 'grok-4.7';
|
|
1157
|
+
return undefined;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/** Identifies OpenAI models on Bedrock, including named inference profiles. */
|
|
1149
1161
|
export function isBedrockOpenAIModel(model?: string): boolean {
|
|
1150
|
-
|
|
1151
|
-
return false;
|
|
1152
|
-
}
|
|
1153
|
-
let id = model.toLowerCase();
|
|
1154
|
-
if (id.startsWith('arn:')) {
|
|
1155
|
-
const modelId =
|
|
1156
|
-
/^arn:[^:]+:bedrock:[^:]*:[^:]*:(?:foundation-model|inference-profile)\/(.+)$/.exec(
|
|
1157
|
-
id
|
|
1158
|
-
)?.[1];
|
|
1159
|
-
if (modelId == null) {
|
|
1160
|
-
return false;
|
|
1161
|
-
}
|
|
1162
|
-
id = modelId;
|
|
1163
|
-
}
|
|
1164
|
-
return /(?:^|\.)openai\./.test(id);
|
|
1162
|
+
return bedrockReplayException(model) === 'openai';
|
|
1165
1163
|
}
|
|
1166
1164
|
|
|
1167
|
-
/**
|
|
1168
|
-
* OpenAI Bedrock models reject prior `reasoningContent`, including on Claude-to-GPT handoffs.
|
|
1169
|
-
* Only suppress replay for identified OpenAI targets; other model families retain the existing
|
|
1170
|
-
* behavior because their Bedrock reasoning-replay requirements have not been verified here.
|
|
1171
|
-
* Missing model IDs and opaque resource ARNs also retain the existing behavior.
|
|
1172
|
-
*/
|
|
1165
|
+
/** OpenAI and Grok 4.7 reject prior reasoning; opaque resources keep replay. */
|
|
1173
1166
|
export function replaysBedrockReasoning(model?: string): boolean {
|
|
1174
|
-
return
|
|
1167
|
+
return bedrockReplayException(model) == null;
|
|
1175
1168
|
}
|
|
1176
1169
|
|
|
1177
1170
|
/**
|
|
@@ -1184,8 +1177,8 @@ export function convertToConverseMessages(
|
|
|
1184
1177
|
converseMessages: BedrockMessage[];
|
|
1185
1178
|
converseSystem: BedrockSystemContentBlock[];
|
|
1186
1179
|
} {
|
|
1187
|
-
const
|
|
1188
|
-
const replayReasoning =
|
|
1180
|
+
const replayException = bedrockReplayException(options.model);
|
|
1181
|
+
const replayReasoning = replayException == null;
|
|
1189
1182
|
const converseSystem = messages
|
|
1190
1183
|
.filter((msg) => msg._getType() === 'system')
|
|
1191
1184
|
.flatMap((msg) => convertSystemMessageToConverseMessage(msg));
|
|
@@ -1251,7 +1244,7 @@ export function convertToConverseMessages(
|
|
|
1251
1244
|
);
|
|
1252
1245
|
}
|
|
1253
1246
|
|
|
1254
|
-
if (
|
|
1247
|
+
if (replayException !== 'openai') {
|
|
1255
1248
|
return { converseMessages: combinedConverseMessages, converseSystem };
|
|
1256
1249
|
}
|
|
1257
1250
|
return {
|
|
@@ -78,6 +78,10 @@ type GoogleFunctionCallWithId = FunctionCallPart['functionCall'] & {
|
|
|
78
78
|
id?: string;
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
+
type GoogleFunctionCallPart = FunctionCallPart & {
|
|
82
|
+
functionCall: GoogleFunctionCallWithId;
|
|
83
|
+
};
|
|
84
|
+
|
|
81
85
|
type GoogleFunctionResponseWithId = {
|
|
82
86
|
name: string;
|
|
83
87
|
response: object;
|
|
@@ -485,6 +489,75 @@ function _convertLangChainContentToPart(
|
|
|
485
489
|
}
|
|
486
490
|
}
|
|
487
491
|
|
|
492
|
+
function convertFallbackContentWithCalls(
|
|
493
|
+
content: MessageContentComplex[],
|
|
494
|
+
isMultimodalModel: boolean,
|
|
495
|
+
functionCalls: GoogleFunctionCallPart[]
|
|
496
|
+
): Part[] {
|
|
497
|
+
const callsById = new Map<string, number[]>();
|
|
498
|
+
const callNames = new Set<string>();
|
|
499
|
+
for (let i = functionCalls.length - 1; i >= 0; i--) {
|
|
500
|
+
const { id, name } = functionCalls[i].functionCall;
|
|
501
|
+
callNames.add(name);
|
|
502
|
+
if (id == null) continue;
|
|
503
|
+
const indices = callsById.get(id);
|
|
504
|
+
if (indices == null) callsById.set(id, [i]);
|
|
505
|
+
else indices.push(i);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const parts: (Part | undefined)[] = [];
|
|
509
|
+
const placed = new Set<number>();
|
|
510
|
+
let slotsByName: Map<string, { indices: number[]; next: number }> | undefined;
|
|
511
|
+
for (const block of content) {
|
|
512
|
+
if ('functionCall' in block && block.functionCall != null) {
|
|
513
|
+
const { id: nativeId, name } =
|
|
514
|
+
block.functionCall as GoogleFunctionCallWithId;
|
|
515
|
+
const id = getGoogleFunctionId(nativeId);
|
|
516
|
+
if (id != null) {
|
|
517
|
+
const index = callsById.get(id)?.pop();
|
|
518
|
+
if (index != null) {
|
|
519
|
+
placed.add(index);
|
|
520
|
+
parts.push(functionCalls[index]);
|
|
521
|
+
}
|
|
522
|
+
} else if (callNames.has(name)) {
|
|
523
|
+
slotsByName ??= new Map();
|
|
524
|
+
let slots = slotsByName.get(name);
|
|
525
|
+
if (slots == null) {
|
|
526
|
+
slots = { indices: [], next: 0 };
|
|
527
|
+
slotsByName.set(name, slots);
|
|
528
|
+
}
|
|
529
|
+
slots.indices.push(parts.length);
|
|
530
|
+
parts.push(undefined);
|
|
531
|
+
}
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const part = _convertLangChainContentToPart(block, isMultimodalModel);
|
|
536
|
+
if (part == null) continue;
|
|
537
|
+
if ('functionCall' in part && part.functionCall != null) {
|
|
538
|
+
const { id, name } = part.functionCall as GoogleFunctionCallWithId;
|
|
539
|
+
if (id != null ? callsById.has(id) : callNames.has(name)) continue;
|
|
540
|
+
}
|
|
541
|
+
parts.push(part);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// Reserve exact ID matches before filling any name-only slots.
|
|
545
|
+
for (let i = 0; i < functionCalls.length; i++) {
|
|
546
|
+
if (placed.has(i)) continue;
|
|
547
|
+
const part = functionCalls[i];
|
|
548
|
+
const slots = slotsByName?.get(part.functionCall.name);
|
|
549
|
+
if (slots != null && slots.next < slots.indices.length) {
|
|
550
|
+
parts[slots.indices[slots.next++]] = part;
|
|
551
|
+
} else {
|
|
552
|
+
parts.push(part);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return slotsByName == null
|
|
557
|
+
? (parts as Part[])
|
|
558
|
+
: parts.filter((part) => part != null);
|
|
559
|
+
}
|
|
560
|
+
|
|
488
561
|
export function convertMessageContentToParts(
|
|
489
562
|
message: BaseMessage,
|
|
490
563
|
isMultimodalModel: boolean,
|
|
@@ -532,21 +605,7 @@ export function convertMessageContentToParts(
|
|
|
532
605
|
const replayParts = restoreGeminiReplayParts(message);
|
|
533
606
|
if (replayParts != null) return replayParts as Part[];
|
|
534
607
|
|
|
535
|
-
let functionCalls:
|
|
536
|
-
const messageParts: Part[] = [];
|
|
537
|
-
|
|
538
|
-
if (typeof message.content === 'string' && message.content) {
|
|
539
|
-
messageParts.push({ text: message.content });
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
if (Array.isArray(message.content)) {
|
|
543
|
-
messageParts.push(
|
|
544
|
-
...(message.content
|
|
545
|
-
.map((c) => _convertLangChainContentToPart(c, isMultimodalModel))
|
|
546
|
-
.filter((p) => p !== undefined) as Part[])
|
|
547
|
-
);
|
|
548
|
-
}
|
|
549
|
-
|
|
608
|
+
let functionCalls: GoogleFunctionCallPart[] = [];
|
|
550
609
|
const storedSignatures = message.additional_kwargs[_FUNCTION_CALL_THOUGHT_SIGNATURES_MAP_KEY] as Record<string, string> | undefined;
|
|
551
610
|
let functionThoughtSignatures = storedSignatures != null && Object.keys(storedSignatures).length > 0 ? storedSignatures : undefined;
|
|
552
611
|
if (Object.hasOwn(message.additional_kwargs, GEMINI_PARTS) && message.additional_kwargs[GEMINI_REPLAY_UNSUPPORTED] !== true) functionThoughtSignatures = {};
|
|
@@ -579,28 +638,21 @@ export function convertMessageContentToParts(
|
|
|
579
638
|
});
|
|
580
639
|
}
|
|
581
640
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
)
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (!('functionCall' in part) || part.functionCall == null) {
|
|
593
|
-
return true;
|
|
594
|
-
}
|
|
595
|
-
const functionCall = part.functionCall as GoogleFunctionCallWithId;
|
|
596
|
-
return !(
|
|
597
|
-
(functionCall.id != null && parsedFunctionCallIds.has(functionCall.id)) ||
|
|
598
|
-
(functionCall.id == null &&
|
|
599
|
-
parsedFunctionCallNames.has(functionCall.name))
|
|
641
|
+
if (!Array.isArray(message.content)) {
|
|
642
|
+
return typeof message.content === 'string' && message.content
|
|
643
|
+
? [{ text: message.content }, ...functionCalls]
|
|
644
|
+
: functionCalls;
|
|
645
|
+
}
|
|
646
|
+
if (functionCalls.length > 0) {
|
|
647
|
+
return convertFallbackContentWithCalls(
|
|
648
|
+
message.content,
|
|
649
|
+
isMultimodalModel,
|
|
650
|
+
functionCalls
|
|
600
651
|
);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
|
|
652
|
+
}
|
|
653
|
+
return message.content
|
|
654
|
+
.map((block) => _convertLangChainContentToPart(block, isMultimodalModel))
|
|
655
|
+
.filter((part) => part != null);
|
|
604
656
|
}
|
|
605
657
|
|
|
606
658
|
export function convertBaseMessagesToContent(
|
package/src/llm/init.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ChatOpenAICallOptions } from '@langchain/openai';
|
|
1
2
|
import type { Runnable } from '@langchain/core/runnables';
|
|
2
3
|
import type * as t from '@/types';
|
|
3
4
|
import {
|
|
@@ -101,7 +102,38 @@ export function initializeModel<P extends t.ProviderName>({
|
|
|
101
102
|
family === 'openai' ||
|
|
102
103
|
family === 'google' ||
|
|
103
104
|
provider === Providers.MOONSHOT;
|
|
104
|
-
if (disableToolCalling
|
|
105
|
-
return model.bindTools(tools);
|
|
106
|
-
|
|
105
|
+
if (disableToolCalling === true && canDisableTools)
|
|
106
|
+
return model.bindTools(tools, { tool_choice: 'none' });
|
|
107
|
+
const options =
|
|
108
|
+
disableToolCalling !== true && isOpenAILike(provider)
|
|
109
|
+
? getToolCallOptions(clientOptions)
|
|
110
|
+
: undefined;
|
|
111
|
+
if (!options) return model.bindTools(tools);
|
|
112
|
+
return model.bindTools(tools, options);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type ToolCallOptions = Pick<
|
|
116
|
+
ChatOpenAICallOptions,
|
|
117
|
+
'tool_choice' | 'parallel_tool_calls'
|
|
118
|
+
>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Reads `tool_choice` and `parallel_tool_calls` from OpenAI-compatible client
|
|
122
|
+
* options. `ChatOpenAI` only honors them as call options, so constructor
|
|
123
|
+
* fields would otherwise be dropped from the request.
|
|
124
|
+
*/
|
|
125
|
+
function getToolCallOptions(
|
|
126
|
+
clientOptions: unknown
|
|
127
|
+
): ToolCallOptions | undefined {
|
|
128
|
+
if (clientOptions == null || typeof clientOptions !== 'object') return;
|
|
129
|
+
const { tool_choice: choice, parallel_tool_calls: parallel } =
|
|
130
|
+
clientOptions as Record<string, unknown>;
|
|
131
|
+
const options: ToolCallOptions = {};
|
|
132
|
+
if (
|
|
133
|
+
typeof choice === 'string' ||
|
|
134
|
+
(choice != null && typeof choice === 'object' && !Array.isArray(choice))
|
|
135
|
+
)
|
|
136
|
+
options.tool_choice = choice as ToolCallOptions['tool_choice'];
|
|
137
|
+
if (typeof parallel === 'boolean') options.parallel_tool_calls = parallel;
|
|
138
|
+
return Object.keys(options).length > 0 ? options : undefined;
|
|
107
139
|
}
|
package/src/llm/openai/index.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
wrapOpenAIClientError,
|
|
20
20
|
getHeadersWithUserAgent,
|
|
21
21
|
convertMessagesToResponsesInput,
|
|
22
|
-
convertResponsesDeltaToChatGenerationChunk,
|
|
23
22
|
ChatOpenAI as OriginalChatOpenAI,
|
|
24
23
|
ChatOpenAIResponses as OriginalChatOpenAIResponses,
|
|
25
24
|
ChatOpenAICompletions as OriginalChatOpenAICompletions,
|
|
@@ -64,6 +63,7 @@ import {
|
|
|
64
63
|
getReasoningKwargsText,
|
|
65
64
|
} from '@/llm/stream/chunkAdapters';
|
|
66
65
|
import { registerProviderTextChunkConstructor } from '@/llm/providerTextChunk';
|
|
66
|
+
import { createResponsesToolArgumentConverter } from './responseToolArguments';
|
|
67
67
|
import { isReasoningModel, _convertMessagesToOpenAIParams } from './utils';
|
|
68
68
|
import { smoothStream, resolveStreamDelay } from '@/llm/stream/smoother';
|
|
69
69
|
import { INTENT_ARG, isIntentLabelProperty } from '@/tools/intentArg';
|
|
@@ -1203,6 +1203,7 @@ async function* convertLibreChatResponsesStream(
|
|
|
1203
1203
|
): AsyncGenerator<ChatGenerationChunk> {
|
|
1204
1204
|
const seenReplayPositions = new Set<string>();
|
|
1205
1205
|
const responsesTextBlockIndices = new Map<string, number>();
|
|
1206
|
+
const convertResponseEvent = createResponsesToolArgumentConverter();
|
|
1206
1207
|
try {
|
|
1207
1208
|
for await (const event of stream) {
|
|
1208
1209
|
options.signal?.throwIfAborted();
|
|
@@ -1212,7 +1213,7 @@ async function* convertLibreChatResponsesStream(
|
|
|
1212
1213
|
}
|
|
1213
1214
|
ensureResponsesOutputAnnotations(event);
|
|
1214
1215
|
const convertedChunk =
|
|
1215
|
-
|
|
1216
|
+
convertResponseEvent(event) ??
|
|
1216
1217
|
convertDroppedResponsesReplayOutput(event);
|
|
1217
1218
|
if (convertedChunk == null) {
|
|
1218
1219
|
continue;
|
|
@@ -2972,6 +2973,20 @@ export class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptions> {
|
|
|
2972
2973
|
static lc_name(): string {
|
|
2973
2974
|
return 'LibreChatOpenAI';
|
|
2974
2975
|
}
|
|
2976
|
+
|
|
2977
|
+
override withConfig(config: Partial<t.ChatOpenAICallOptions>): this {
|
|
2978
|
+
const Ctor = this.constructor as new (
|
|
2979
|
+
fields?: LibreChatOpenAIFields & t.OpenAIChatInput['modelKwargs']
|
|
2980
|
+
) => this;
|
|
2981
|
+
const newModel = new Ctor(this.fields);
|
|
2982
|
+
newModel.defaultOptions = {
|
|
2983
|
+
...this.defaultOptions,
|
|
2984
|
+
...config,
|
|
2985
|
+
};
|
|
2986
|
+
newModel._lc_stream_delay = this._lc_stream_delay;
|
|
2987
|
+
newModel.firstPartyEndpoint = this.firstPartyEndpoint;
|
|
2988
|
+
return newModel;
|
|
2989
|
+
}
|
|
2975
2990
|
_getClientOptions(
|
|
2976
2991
|
options?: OpenAICoreRequestOptions
|
|
2977
2992
|
): OpenAICoreRequestOptions {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { AIMessageChunk } from '@langchain/core/messages';
|
|
2
|
+
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
3
|
+
import { convertResponsesDeltaToChatGenerationChunk } from '@langchain/openai';
|
|
4
|
+
import type { ToolCallChunk } from '@langchain/core/messages/tool';
|
|
5
|
+
import type { OpenAIClient } from '@langchain/openai';
|
|
6
|
+
|
|
7
|
+
type ResponseEvent = OpenAIClient.Responses.ResponseStreamEvent;
|
|
8
|
+
type ResponseConverter = (event: ResponseEvent) => ChatGenerationChunk | null;
|
|
9
|
+
type FunctionCall = OpenAIClient.Responses.ResponseFunctionToolCall;
|
|
10
|
+
type FunctionCallSnapshot = Pick<FunctionCall, 'arguments'> &
|
|
11
|
+
Partial<Pick<FunctionCall, 'id' | 'call_id' | 'name'>>;
|
|
12
|
+
|
|
13
|
+
function reconcileArguments(
|
|
14
|
+
calls: Map<number, ToolCallChunk>,
|
|
15
|
+
index: number,
|
|
16
|
+
snapshot: FunctionCallSnapshot
|
|
17
|
+
): ChatGenerationChunk | null {
|
|
18
|
+
const call = calls.get(index);
|
|
19
|
+
const previousArgs = call?.args ?? '';
|
|
20
|
+
if (
|
|
21
|
+
!snapshot.arguments.startsWith(previousArgs) ||
|
|
22
|
+
(call?.name != null &&
|
|
23
|
+
snapshot.name != null &&
|
|
24
|
+
call.name !== snapshot.name) ||
|
|
25
|
+
(call?.id != null &&
|
|
26
|
+
snapshot.call_id != null &&
|
|
27
|
+
call.id !== snapshot.call_id)
|
|
28
|
+
) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Responses function call at output index ${index} changed after streaming.`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const missingArgs = snapshot.arguments.slice(previousArgs.length);
|
|
34
|
+
const missingId = call?.id == null ? snapshot.call_id : undefined;
|
|
35
|
+
const missingName = call?.name == null ? snapshot.name : undefined;
|
|
36
|
+
if (missingArgs === '' && missingId == null && missingName == null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
calls.set(index, {
|
|
40
|
+
type: 'tool_call_chunk',
|
|
41
|
+
index,
|
|
42
|
+
id: call?.id ?? snapshot.call_id,
|
|
43
|
+
name: call?.name ?? snapshot.name,
|
|
44
|
+
args: snapshot.arguments,
|
|
45
|
+
});
|
|
46
|
+
return new ChatGenerationChunk({
|
|
47
|
+
text: '',
|
|
48
|
+
message: new AIMessageChunk({
|
|
49
|
+
content: '',
|
|
50
|
+
tool_call_chunks: [
|
|
51
|
+
{
|
|
52
|
+
type: 'tool_call_chunk',
|
|
53
|
+
index,
|
|
54
|
+
args: missingArgs,
|
|
55
|
+
...(missingId != null && { id: missingId }),
|
|
56
|
+
...(missingName != null && { name: missingName }),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
additional_kwargs:
|
|
60
|
+
missingId != null && snapshot.id != null
|
|
61
|
+
? {
|
|
62
|
+
__openai_function_call_ids__: { [missingId]: snapshot.id },
|
|
63
|
+
}
|
|
64
|
+
: {},
|
|
65
|
+
response_metadata: { model_provider: 'openai' },
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Reconcile terminal snapshots with the append-only tool-call chunk stream. */
|
|
71
|
+
export function createResponsesToolArgumentConverter(): ResponseConverter {
|
|
72
|
+
const calls = new Map<number, ToolCallChunk>();
|
|
73
|
+
|
|
74
|
+
return (event): ChatGenerationChunk | null => {
|
|
75
|
+
if (
|
|
76
|
+
event.type === 'response.output_item.added' &&
|
|
77
|
+
event.item.type === 'function_call'
|
|
78
|
+
) {
|
|
79
|
+
calls.set(event.output_index, {
|
|
80
|
+
type: 'tool_call_chunk',
|
|
81
|
+
index: event.output_index,
|
|
82
|
+
id: event.item.call_id,
|
|
83
|
+
name: event.item.name,
|
|
84
|
+
args: event.item.arguments,
|
|
85
|
+
});
|
|
86
|
+
} else if (event.type === 'response.function_call_arguments.delta') {
|
|
87
|
+
const call = calls.get(event.output_index) ?? {
|
|
88
|
+
type: 'tool_call_chunk',
|
|
89
|
+
index: event.output_index,
|
|
90
|
+
args: '',
|
|
91
|
+
};
|
|
92
|
+
call.args = (call.args ?? '') + event.delta;
|
|
93
|
+
calls.set(event.output_index, call);
|
|
94
|
+
} else if (event.type === 'response.function_call_arguments.done') {
|
|
95
|
+
return reconcileArguments(calls, event.output_index, event);
|
|
96
|
+
} else if (
|
|
97
|
+
event.type === 'response.output_item.done' &&
|
|
98
|
+
event.item.type === 'function_call'
|
|
99
|
+
) {
|
|
100
|
+
return reconcileArguments(calls, event.output_index, event.item);
|
|
101
|
+
}
|
|
102
|
+
return convertResponsesDeltaToChatGenerationChunk(event);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -171,6 +171,17 @@ export class ChatOpenRouter extends ChatOpenAI {
|
|
|
171
171
|
return 'LibreChatOpenRouter';
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
override withConfig(config: Partial<ChatOpenRouterCallOptions>): this {
|
|
175
|
+
const newModel = super.withConfig(config);
|
|
176
|
+
if (this.openRouterReasoning != null) {
|
|
177
|
+
newModel.openRouterReasoning = { ...this.openRouterReasoning };
|
|
178
|
+
}
|
|
179
|
+
if (this.includeReasoning !== undefined) {
|
|
180
|
+
newModel.includeReasoning = this.includeReasoning;
|
|
181
|
+
}
|
|
182
|
+
return newModel;
|
|
183
|
+
}
|
|
184
|
+
|
|
174
185
|
// OpenRouter widens OpenAI reasoning with extra effort levels ('xhigh' | 'none' | 'minimal').
|
|
175
186
|
override invocationParams(
|
|
176
187
|
options?: this['ParsedCallOptions'],
|
|
@@ -305,6 +316,8 @@ export class ChatOpenRouter extends ChatOpenAI {
|
|
|
305
316
|
if (finalReasoningDetails.length > 0) {
|
|
306
317
|
generationChunk.message.additional_kwargs.reasoning_details =
|
|
307
318
|
finalReasoningDetails;
|
|
319
|
+
reasoningTextByIndex.clear();
|
|
320
|
+
reasoningEncryptedById.clear();
|
|
308
321
|
} else {
|
|
309
322
|
delete generationChunk.message.additional_kwargs.reasoning_details;
|
|
310
323
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { isIDContentBlock } from '@langchain/core/messages';
|
|
2
3
|
import type {
|
|
3
4
|
BaseMessage,
|
|
4
5
|
Data,
|
|
@@ -18,17 +19,20 @@ import {
|
|
|
18
19
|
projectStructuredToolOutputsToText,
|
|
19
20
|
projectToolStreamContentForProvider,
|
|
20
21
|
} from '@/messages/core';
|
|
22
|
+
import {
|
|
23
|
+
stripAnthropicCacheControl,
|
|
24
|
+
stripBedrockCacheControl,
|
|
25
|
+
isTailCacheableBlock,
|
|
26
|
+
withCacheControl,
|
|
27
|
+
getCacheControl,
|
|
28
|
+
cloneMessage,
|
|
29
|
+
} from '@/messages/cache';
|
|
21
30
|
import {
|
|
22
31
|
coalesceAdjacentUserTurns,
|
|
23
32
|
appendPredecessorHandoffCue,
|
|
24
33
|
appendInstructionlessHandoffCue,
|
|
25
34
|
removePredecessorHandoffCue,
|
|
26
35
|
} from '@/messages';
|
|
27
|
-
import {
|
|
28
|
-
stripAnthropicCacheControl,
|
|
29
|
-
stripBedrockCacheControl,
|
|
30
|
-
cloneMessage,
|
|
31
|
-
} from '@/messages/cache';
|
|
32
36
|
import { createToolHistoryPreparation } from '@/messages/toolHistoryProjection';
|
|
33
37
|
import { isAnthropicLike, isGoogleLike, isOpenAILike } from '@/utils/llm';
|
|
34
38
|
import { annotateMessagesForLLM } from '@/tools/toolOutputReferences';
|
|
@@ -112,8 +116,13 @@ type PreparedProviderRequestData = Omit<
|
|
|
112
116
|
export interface ProviderRequestContext {
|
|
113
117
|
getOrCreateToolOutputRegistry?(): ToolOutputReferenceRegistry | undefined;
|
|
114
118
|
isRunProducedMessage?(message: BaseMessage): boolean;
|
|
119
|
+
resolveAttachment?: t.AttachmentResolver;
|
|
115
120
|
}
|
|
116
121
|
|
|
122
|
+
type ResolveReference = (
|
|
123
|
+
reference: t.AttachmentReference
|
|
124
|
+
) => MessageContentComplex | null | undefined;
|
|
125
|
+
|
|
117
126
|
export interface PrepareProviderRequestParams {
|
|
118
127
|
model: t.ChatModel;
|
|
119
128
|
messages: BaseMessage[];
|
|
@@ -209,6 +218,7 @@ interface ProjectMessagesForProviderParams {
|
|
|
209
218
|
maxToolResultChars?: number;
|
|
210
219
|
callOptions?: unknown;
|
|
211
220
|
toolHistory?: ToolHistoryPreparation;
|
|
221
|
+
resolve?: ResolveReference;
|
|
212
222
|
}
|
|
213
223
|
|
|
214
224
|
function isSerializedBuffer(value: object): value is SerializedBuffer {
|
|
@@ -344,15 +354,31 @@ function copyUsableContentPrefix(
|
|
|
344
354
|
return content;
|
|
345
355
|
}
|
|
346
356
|
|
|
347
|
-
/**
|
|
357
|
+
/** Puts the breakpoint a dropped reference carried on the last block that can hold one. */
|
|
358
|
+
function anchorCacheControl(
|
|
359
|
+
content: MessageContentComplex[],
|
|
360
|
+
marker: NonNullable<ReturnType<typeof getCacheControl>>
|
|
361
|
+
): void {
|
|
362
|
+
for (let index = content.length - 1; index >= 0; index--) {
|
|
363
|
+
if (isTailCacheableBlock(content[index])) {
|
|
364
|
+
content[index] = withCacheControl(content[index], marker);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Resolves referenced attachments and reprojects persisted provider-native
|
|
372
|
+
* ones, in one pass and without changing history.
|
|
373
|
+
*/
|
|
348
374
|
function projectAttachmentsForProvider(
|
|
349
375
|
messages: BaseMessage[],
|
|
350
|
-
provider: t.ProviderName
|
|
376
|
+
provider: t.ProviderName,
|
|
377
|
+
resolve?: ResolveReference
|
|
351
378
|
): BaseMessage[] {
|
|
352
|
-
|
|
353
|
-
provider === Providers.BEDROCK ||
|
|
354
|
-
|
|
355
|
-
) {
|
|
379
|
+
const native =
|
|
380
|
+
provider === Providers.BEDROCK || getProviderFamily(provider) === 'bedrock';
|
|
381
|
+
if (native && resolve == null) {
|
|
356
382
|
return messages;
|
|
357
383
|
}
|
|
358
384
|
let projected: BaseMessage[] | undefined;
|
|
@@ -363,8 +389,29 @@ function projectAttachmentsForProvider(
|
|
|
363
389
|
}
|
|
364
390
|
const sourceContent = message.content as ProviderContentBlock[];
|
|
365
391
|
let content: ProviderContentBlock[] | undefined;
|
|
392
|
+
let displaced: ReturnType<typeof getCacheControl>;
|
|
366
393
|
for (let blockIndex = 0; blockIndex < sourceContent.length; blockIndex++) {
|
|
367
394
|
const block = sourceContent[blockIndex];
|
|
395
|
+
const resolved =
|
|
396
|
+
resolve != null && isIDContentBlock(block) ? resolve(block) : undefined;
|
|
397
|
+
if (resolved !== undefined) {
|
|
398
|
+
content ??= copyUsableContentPrefix(sourceContent, blockIndex);
|
|
399
|
+
const marker = getCacheControl(block);
|
|
400
|
+
if (resolved === null) {
|
|
401
|
+
displaced = marker ?? displaced;
|
|
402
|
+
} else {
|
|
403
|
+
content.push(
|
|
404
|
+
marker == null ? resolved : withCacheControl(resolved, marker)
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (native) {
|
|
410
|
+
if (content != null && !isBlankTextBlock(block)) {
|
|
411
|
+
content.push(block);
|
|
412
|
+
}
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
368
415
|
if (isStandardFileBlock(block)) {
|
|
369
416
|
if (shouldRetainStandardFile(provider, block.mime_type)) {
|
|
370
417
|
content?.push(block);
|
|
@@ -396,6 +443,9 @@ function projectAttachmentsForProvider(
|
|
|
396
443
|
if (content.length === 0) {
|
|
397
444
|
content.push({ type: 'text', text: OMITTED_ATTACHMENT_TEXT });
|
|
398
445
|
}
|
|
446
|
+
if (displaced != null) {
|
|
447
|
+
anchorCacheControl(content as MessageContentComplex[], displaced);
|
|
448
|
+
}
|
|
399
449
|
projected ??= [...messages];
|
|
400
450
|
projected[messageIndex] = cloneMessage(
|
|
401
451
|
message,
|
|
@@ -411,6 +461,7 @@ function projectMessagesForProviderMode(
|
|
|
411
461
|
provider,
|
|
412
462
|
maxToolResultChars,
|
|
413
463
|
toolHistory,
|
|
464
|
+
resolve,
|
|
414
465
|
}: ProjectMessagesForProviderParams,
|
|
415
466
|
projectionMode: ProviderMessageProjectionMode
|
|
416
467
|
): BaseMessage[] {
|
|
@@ -423,7 +474,8 @@ function projectMessagesForProviderMode(
|
|
|
423
474
|
maxToolResultChars,
|
|
424
475
|
toolHistory
|
|
425
476
|
),
|
|
426
|
-
provider
|
|
477
|
+
provider,
|
|
478
|
+
resolve
|
|
427
479
|
);
|
|
428
480
|
if (nativeOpenAIResponses) {
|
|
429
481
|
return projectOpenAIResponsesToolMessageContent(
|
|
@@ -540,6 +592,8 @@ export function prepareProviderRequest({
|
|
|
540
592
|
provider,
|
|
541
593
|
config
|
|
542
594
|
);
|
|
595
|
+
const modelId = resolveServingModelId(model);
|
|
596
|
+
const resolveAttachment = context?.resolveAttachment;
|
|
543
597
|
const projected = projectMessagesForProviderMode(
|
|
544
598
|
{
|
|
545
599
|
model,
|
|
@@ -548,6 +602,15 @@ export function prepareProviderRequest({
|
|
|
548
602
|
maxToolResultChars,
|
|
549
603
|
callOptions: config,
|
|
550
604
|
toolHistory,
|
|
605
|
+
resolve:
|
|
606
|
+
resolveAttachment == null
|
|
607
|
+
? undefined
|
|
608
|
+
: (reference): MessageContentComplex | null | undefined =>
|
|
609
|
+
resolveAttachment(reference, {
|
|
610
|
+
provider,
|
|
611
|
+
modelId,
|
|
612
|
+
projectionMode,
|
|
613
|
+
}),
|
|
551
614
|
},
|
|
552
615
|
projectionMode
|
|
553
616
|
);
|
|
@@ -555,7 +618,6 @@ export function prepareProviderRequest({
|
|
|
555
618
|
const runId = config?.configurable?.run_id as string | undefined;
|
|
556
619
|
const annotated = annotateMessagesForLLM(projected, registry, runId);
|
|
557
620
|
const isRunProduced = context?.isRunProducedMessage;
|
|
558
|
-
const modelId = resolveServingModelId(model);
|
|
559
621
|
const handoffGrounded = appendInstructionlessHandoffCue(annotated, config);
|
|
560
622
|
const cued = isAnthropicLike(provider, {
|
|
561
623
|
model: modelId,
|