@librechat/agents 4.2.12 → 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 +11 -3
- package/dist/cjs/graphs/Graph.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 +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +1 -1
- package/dist/cjs/main.cjs +6 -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/core.cjs +3 -2
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +2 -2
- 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 +7 -1
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/runtime/client.cjs +2 -0
- package/dist/cjs/runtime/client.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -0
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +1 -1
- package/dist/cjs/tools/ToolNode.cjs +46 -13
- package/dist/cjs/tools/ToolNode.cjs.map +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 +4 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.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 +11 -3
- package/dist/esm/graphs/Graph.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 +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +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/core.mjs +3 -2
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +2 -2
- 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 +7 -1
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/runtime/client.mjs +2 -0
- package/dist/esm/runtime/client.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -0
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +1 -1
- package/dist/esm/tools/ToolNode.mjs +46 -13
- package/dist/esm/tools/ToolNode.mjs.map +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 +4 -0
- package/dist/esm/tools/subagent/SubagentExecutor.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 +4 -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/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 +1 -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/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 +1 -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 +3 -3
- 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/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 +6 -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 +1 -1
- package/dist/types/types/graph.d.ts +4 -1
- package/dist/types/types/index.d.ts +14 -14
- package/dist/types/types/llm.d.ts +2 -2
- package/dist/types/types/run.d.ts +3 -1
- package/dist/types/types/subagentTasks.d.ts +2 -2
- package/dist/types/types/tools.d.ts +6 -3
- package/dist/types/utils/index.d.ts +10 -10
- package/dist/types/utils/tokens.d.ts +1 -0
- package/package.json +3 -2
- package/src/graphs/Graph.ts +22 -0
- package/src/index.ts +8 -0
- 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/messages/anthropicServerTools.ts +24 -0
- 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 +15 -4
- package/src/runtime/client.ts +3 -0
- package/src/stream.ts +5 -0
- package/src/tools/ToolNode.ts +112 -17
- package/src/tools/search/content.ts +282 -62
- package/src/tools/subagent/SubagentExecutor.ts +6 -0
- package/src/types/graph.ts +3 -0
- package/src/types/run.ts +3 -0
- package/src/types/tools.ts +3 -0
- 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
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE = {
|
|
2
|
+
advisor_tool_result: ['advisor'],
|
|
3
|
+
bash_code_execution_tool_result: ['bash_code_execution'],
|
|
4
|
+
code_execution_tool_result: ['code_execution'],
|
|
5
|
+
text_editor_code_execution_tool_result: ['text_editor_code_execution'],
|
|
6
|
+
tool_search_tool_result: ['tool_search_tool_regex', 'tool_search_tool_bm25'],
|
|
7
|
+
web_fetch_tool_result: ['web_fetch'],
|
|
8
|
+
web_search_tool_result: ['web_search'],
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
type AnthropicServerToolResultType =
|
|
12
|
+
keyof typeof ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE;
|
|
13
|
+
|
|
14
|
+
export const ANTHROPIC_SERVER_TOOL_RESULT_TYPES = Object.keys(
|
|
15
|
+
ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE
|
|
16
|
+
) as AnthropicServerToolResultType[];
|
|
17
|
+
|
|
18
|
+
export function isAnthropicServerToolResultType(
|
|
19
|
+
type: string | undefined
|
|
20
|
+
): type is AnthropicServerToolResultType {
|
|
21
|
+
return (
|
|
22
|
+
type != null && Object.hasOwn(ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE, type)
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/messages/core.ts
CHANGED
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
} from '@langchain/core/messages';
|
|
10
10
|
import type { ContentBlock as LangChainContentBlock } from '@langchain/core/messages';
|
|
11
11
|
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
|
12
|
-
import type { ProviderMessageProvenancePart } from './provenance';
|
|
13
|
-
import type * as t from '@/types';
|
|
14
12
|
import type {
|
|
15
13
|
ResponsesReplayPosition,
|
|
16
14
|
ToolHistoryPreparation,
|
|
17
15
|
OrderedToolHistoryProjection,
|
|
18
16
|
} from './toolHistoryProjection';
|
|
17
|
+
import type { ProviderMessageProvenancePart } from './provenance';
|
|
18
|
+
import type * as t from '@/types';
|
|
19
19
|
import {
|
|
20
20
|
cloneToolMessageWithContent,
|
|
21
21
|
compactToolContent,
|
|
@@ -27,6 +27,13 @@ import {
|
|
|
27
27
|
isComputerCallOutputMessage,
|
|
28
28
|
serializeToolContentBounded,
|
|
29
29
|
} from '@/utils/toolContent';
|
|
30
|
+
import {
|
|
31
|
+
OPENAI_RESPONSES_REPLAY_POSITIONS_KEY,
|
|
32
|
+
createToolHistoryPreparation,
|
|
33
|
+
getGeneratedImageMimeType,
|
|
34
|
+
getResponsesHistorySource,
|
|
35
|
+
isResponsesReplayPosition,
|
|
36
|
+
} from './toolHistoryProjection';
|
|
30
37
|
import {
|
|
31
38
|
getProviderMessageProvenance,
|
|
32
39
|
getProviderSourceMessageIds,
|
|
@@ -34,18 +41,12 @@ import {
|
|
|
34
41
|
setProviderMessageProvenance,
|
|
35
42
|
stampSyntheticProviderMessage,
|
|
36
43
|
} from './provenance';
|
|
44
|
+
import { ANTHROPIC_SERVER_TOOL_RESULT_TYPES } from './anthropicServerTools';
|
|
37
45
|
import { HARD_MAX_TOOL_RESULT_CHARS } from '@/utils/truncation';
|
|
38
|
-
import { stripAnthropicCacheControl } from './cache';
|
|
39
46
|
import { isReasoningContentBlock } from './reasoningTypes';
|
|
47
|
+
import { stripAnthropicCacheControl } from './cache';
|
|
40
48
|
import { ContentTypes, Providers } from '@/common';
|
|
41
49
|
import { toLangChainContent } from './langchain';
|
|
42
|
-
import {
|
|
43
|
-
OPENAI_RESPONSES_REPLAY_POSITIONS_KEY,
|
|
44
|
-
createToolHistoryPreparation,
|
|
45
|
-
getGeneratedImageMimeType,
|
|
46
|
-
getResponsesHistorySource,
|
|
47
|
-
isResponsesReplayPosition,
|
|
48
|
-
} from './toolHistoryProjection';
|
|
49
50
|
|
|
50
51
|
type ReasoningSummary = { summary?: Array<{ text?: string }> };
|
|
51
52
|
type ReasoningDetail = { type?: string; text?: string };
|
|
@@ -91,7 +92,7 @@ const allowedTypesByProvider: Record<string, string[]> = {
|
|
|
91
92
|
'thinking',
|
|
92
93
|
'redacted_thinking',
|
|
93
94
|
'server_tool_use',
|
|
94
|
-
|
|
95
|
+
...ANTHROPIC_SERVER_TOOL_RESULT_TYPES,
|
|
95
96
|
'web_search_result',
|
|
96
97
|
],
|
|
97
98
|
[Providers.BEDROCK]: [..._allowedTypes, 'reasoning_content'],
|
|
@@ -5,6 +5,10 @@ import type {
|
|
|
5
5
|
ToolMessage,
|
|
6
6
|
} from '@langchain/core/messages';
|
|
7
7
|
import type { ProviderName } from '@/types/llm';
|
|
8
|
+
import {
|
|
9
|
+
ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE,
|
|
10
|
+
isAnthropicServerToolResultType,
|
|
11
|
+
} from './anthropicServerTools';
|
|
8
12
|
import { getProviderFamily } from '@/llm/providers';
|
|
9
13
|
|
|
10
14
|
export type ProviderToolCallKind =
|
|
@@ -61,16 +65,6 @@ const MCP_CALL_KINDS = ['mcp'] as const;
|
|
|
61
65
|
const GOOGLE_CALL_KINDS = ['google'] as const;
|
|
62
66
|
const BEDROCK_CALL_KINDS = ['bedrock', 'tool'] as const;
|
|
63
67
|
|
|
64
|
-
const ADVISOR_TOOL_NAMES = ['advisor'] as const;
|
|
65
|
-
const BASH_TOOL_NAMES = ['bash_code_execution'] as const;
|
|
66
|
-
const CODE_EXECUTION_TOOL_NAMES = ['code_execution'] as const;
|
|
67
|
-
const TEXT_EDITOR_TOOL_NAMES = ['text_editor_code_execution'] as const;
|
|
68
|
-
const TOOL_SEARCH_TOOL_NAMES = [
|
|
69
|
-
'tool_search_tool_regex',
|
|
70
|
-
'tool_search_tool_bm25',
|
|
71
|
-
] as const;
|
|
72
|
-
const WEB_FETCH_TOOL_NAMES = ['web_fetch'] as const;
|
|
73
|
-
const WEB_SEARCH_TOOL_NAMES = ['web_search'] as const;
|
|
74
68
|
const ANTHROPIC_SERVER_TOOL_ID_PREFIX = 'srvtoolu_';
|
|
75
69
|
|
|
76
70
|
function stringSet(values: readonly string[]): ReadonlySet<string> {
|
|
@@ -95,15 +89,9 @@ const PROVIDER_TOOL_CALL_KINDS = stringSet([
|
|
|
95
89
|
'server',
|
|
96
90
|
'tool',
|
|
97
91
|
]);
|
|
98
|
-
const ANTHROPIC_SERVER_TOOL_NAMES = stringSet(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
...CODE_EXECUTION_TOOL_NAMES,
|
|
102
|
-
...TEXT_EDITOR_TOOL_NAMES,
|
|
103
|
-
...TOOL_SEARCH_TOOL_NAMES,
|
|
104
|
-
...WEB_FETCH_TOOL_NAMES,
|
|
105
|
-
...WEB_SEARCH_TOOL_NAMES,
|
|
106
|
-
]);
|
|
92
|
+
const ANTHROPIC_SERVER_TOOL_NAMES = stringSet(
|
|
93
|
+
Object.values(ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE).flat()
|
|
94
|
+
);
|
|
107
95
|
|
|
108
96
|
function getRecord(value: unknown): Record<string, unknown> | undefined {
|
|
109
97
|
if (value == null || typeof value !== 'object') {
|
|
@@ -399,17 +387,6 @@ function hasValidProviderMetadata(record: Record<string, unknown>): boolean {
|
|
|
399
387
|
);
|
|
400
388
|
}
|
|
401
389
|
|
|
402
|
-
const ANTHROPIC_STRUCTURED_RESULT_TOOL_NAMES: Readonly<
|
|
403
|
-
Partial<Record<string, readonly string[]>>
|
|
404
|
-
> = {
|
|
405
|
-
advisor_tool_result: ADVISOR_TOOL_NAMES,
|
|
406
|
-
bash_code_execution_tool_result: BASH_TOOL_NAMES,
|
|
407
|
-
code_execution_tool_result: CODE_EXECUTION_TOOL_NAMES,
|
|
408
|
-
text_editor_code_execution_tool_result: TEXT_EDITOR_TOOL_NAMES,
|
|
409
|
-
tool_search_tool_result: TOOL_SEARCH_TOOL_NAMES,
|
|
410
|
-
web_fetch_tool_result: WEB_FETCH_TOOL_NAMES,
|
|
411
|
-
};
|
|
412
|
-
|
|
413
390
|
/** Designated provider output is opaque once its exact envelope and matching
|
|
414
391
|
* call establish authorship. Only its container size/proxy identity is read;
|
|
415
392
|
* nested values are deliberately not walked on the formatting hot path. */
|
|
@@ -601,42 +578,36 @@ const LOCAL_RESULT_METADATA_FIELDS = [
|
|
|
601
578
|
'agentId',
|
|
602
579
|
'groupId',
|
|
603
580
|
] as const;
|
|
604
|
-
const TOOL_RESULT_ENVELOPE_FIELDS: Readonly<
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
'thoughtSignature',
|
|
635
|
-
'agentId',
|
|
636
|
-
'groupId',
|
|
637
|
-
],
|
|
638
|
-
toolResult: ['type', 'toolResult', 'agentId', 'groupId'],
|
|
639
|
-
};
|
|
581
|
+
const TOOL_RESULT_ENVELOPE_FIELDS: Readonly<
|
|
582
|
+
Partial<Record<string, readonly string[]>>
|
|
583
|
+
> = {
|
|
584
|
+
mcp_tool_result: ANTHROPIC_GENERIC_RESULT_FIELDS,
|
|
585
|
+
tool_result: ANTHROPIC_GENERIC_RESULT_FIELDS,
|
|
586
|
+
server_tool_call_result: [
|
|
587
|
+
'type',
|
|
588
|
+
'toolCallId',
|
|
589
|
+
'status',
|
|
590
|
+
'output',
|
|
591
|
+
...LOCAL_RESULT_METADATA_FIELDS,
|
|
592
|
+
],
|
|
593
|
+
server_tool_result: [
|
|
594
|
+
'type',
|
|
595
|
+
'tool_call_id',
|
|
596
|
+
'status',
|
|
597
|
+
'output',
|
|
598
|
+
...LOCAL_RESULT_METADATA_FIELDS,
|
|
599
|
+
],
|
|
600
|
+
codeExecutionResult: ['type', 'codeExecutionResult', 'agentId', 'groupId'],
|
|
601
|
+
toolResponse: [
|
|
602
|
+
'type',
|
|
603
|
+
'toolResponse',
|
|
604
|
+
'thought',
|
|
605
|
+
'thoughtSignature',
|
|
606
|
+
'agentId',
|
|
607
|
+
'groupId',
|
|
608
|
+
],
|
|
609
|
+
toolResult: ['type', 'toolResult', 'agentId', 'groupId'],
|
|
610
|
+
};
|
|
640
611
|
|
|
641
612
|
function anthropicDescriptor(
|
|
642
613
|
record: Record<string, unknown>,
|
|
@@ -663,10 +634,18 @@ export function getProviderToolResultPartDescriptor(
|
|
|
663
634
|
return undefined;
|
|
664
635
|
}
|
|
665
636
|
const type = readString(record, 'type');
|
|
666
|
-
|
|
667
|
-
|
|
637
|
+
if (type == null) {
|
|
638
|
+
return undefined;
|
|
639
|
+
}
|
|
640
|
+
const isAnthropicResult = isAnthropicServerToolResultType(type);
|
|
641
|
+
let allowedFields = TOOL_RESULT_ENVELOPE_FIELDS[type];
|
|
642
|
+
if (isAnthropicResult) {
|
|
643
|
+
allowedFields =
|
|
644
|
+
type === 'web_search_tool_result' || type === 'web_fetch_tool_result'
|
|
645
|
+
? ANTHROPIC_SERVER_RESULT_FIELDS
|
|
646
|
+
: ANTHROPIC_RESULT_FIELDS;
|
|
647
|
+
}
|
|
668
648
|
if (
|
|
669
|
-
type == null ||
|
|
670
649
|
allowedFields == null ||
|
|
671
650
|
!hasOnlyOwnDataProperties(record, allowedFields) ||
|
|
672
651
|
!hasValidProviderMetadata(record) ||
|
|
@@ -675,9 +654,12 @@ export function getProviderToolResultPartDescriptor(
|
|
|
675
654
|
) {
|
|
676
655
|
return undefined;
|
|
677
656
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
657
|
+
if (isAnthropicResult && type !== 'web_search_tool_result') {
|
|
658
|
+
return anthropicDescriptor(
|
|
659
|
+
record,
|
|
660
|
+
type,
|
|
661
|
+
ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE[type]
|
|
662
|
+
);
|
|
681
663
|
}
|
|
682
664
|
if (type === 'web_search_tool_result') {
|
|
683
665
|
const toolCallId = readPairingString(record, 'tool_use_id');
|
|
@@ -689,7 +671,7 @@ export function getProviderToolResultPartDescriptor(
|
|
|
689
671
|
type,
|
|
690
672
|
toolCallId,
|
|
691
673
|
compatibleCallKinds: ANTHROPIC_SERVER_CALL_KINDS,
|
|
692
|
-
expectedToolNames:
|
|
674
|
+
expectedToolNames: ANTHROPIC_SERVER_TOOL_NAMES_BY_RESULT_TYPE[type],
|
|
693
675
|
}
|
|
694
676
|
: undefined;
|
|
695
677
|
}
|
|
@@ -776,7 +758,8 @@ export function isProviderToolContentPart(part: unknown): boolean {
|
|
|
776
758
|
return (
|
|
777
759
|
type != null &&
|
|
778
760
|
(PROVIDER_TOOL_CALL_CONTENT_TYPES.has(type) ||
|
|
779
|
-
|
|
761
|
+
isAnthropicServerToolResultType(type) ||
|
|
762
|
+
Object.hasOwn(TOOL_RESULT_ENVELOPE_FIELDS, type))
|
|
780
763
|
);
|
|
781
764
|
}
|
|
782
765
|
|
|
@@ -847,6 +830,10 @@ const STANDARD_CALL_FIELDS = [
|
|
|
847
830
|
'index',
|
|
848
831
|
...LOCAL_CALL_METADATA_FIELDS,
|
|
849
832
|
] as const;
|
|
833
|
+
const STANDARD_CALL_WITH_CALLER_FIELDS = [
|
|
834
|
+
...STANDARD_CALL_FIELDS,
|
|
835
|
+
'caller',
|
|
836
|
+
] as const;
|
|
850
837
|
const LIBRECHAT_CALL_FIELDS = [
|
|
851
838
|
'type',
|
|
852
839
|
'id',
|
|
@@ -927,7 +914,8 @@ export function getProviderToolCallPartDescriptor(
|
|
|
927
914
|
['type', 'tool_call', 'agentId', 'groupId'],
|
|
928
915
|
['tool_call']
|
|
929
916
|
)
|
|
930
|
-
: hasExactCallShape(record,
|
|
917
|
+
: hasExactCallShape(record, STANDARD_CALL_WITH_CALLER_FIELDS, ['id', 'name', 'args']) &&
|
|
918
|
+
hasValidCallerProperty(record);
|
|
931
919
|
const callIsValid = nested.found
|
|
932
920
|
? call != null &&
|
|
933
921
|
hasExactCallShape(call, LIBRECHAT_CALL_FIELDS, [
|
|
@@ -993,23 +981,27 @@ export function getProviderToolCallPartDescriptor(
|
|
|
993
981
|
};
|
|
994
982
|
}
|
|
995
983
|
if (type === 'server_tool_call') {
|
|
984
|
+
const callId = readPairingString(record, 'id');
|
|
985
|
+
const name = optionalName(record);
|
|
986
|
+
if (callId == null || name == null) {
|
|
987
|
+
return undefined;
|
|
988
|
+
}
|
|
989
|
+
const isAnthropic = isAnthropicServerToolCall(callId, name.name);
|
|
990
|
+
const fields = isAnthropic
|
|
991
|
+
? STANDARD_CALL_WITH_CALLER_FIELDS
|
|
992
|
+
: STANDARD_CALL_FIELDS;
|
|
996
993
|
if (
|
|
997
|
-
!hasExactCallShape(record,
|
|
994
|
+
!hasExactCallShape(record, fields, ['id', 'name', 'args']) ||
|
|
995
|
+
!hasValidCallerProperty(record)
|
|
998
996
|
) {
|
|
999
997
|
return undefined;
|
|
1000
998
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
kind: isAnthropicServerToolCall(callId, name.name)
|
|
1008
|
-
? 'anthropic-server'
|
|
1009
|
-
: 'server',
|
|
1010
|
-
sourceType: type,
|
|
1011
|
-
...name,
|
|
1012
|
-
};
|
|
999
|
+
return {
|
|
1000
|
+
callId,
|
|
1001
|
+
kind: isAnthropic ? 'anthropic-server' : 'server',
|
|
1002
|
+
sourceType: type,
|
|
1003
|
+
...name,
|
|
1004
|
+
};
|
|
1013
1005
|
}
|
|
1014
1006
|
if (type === 'toolCall' || type === 'toolUse') {
|
|
1015
1007
|
const outerFields =
|