@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.
Files changed (280) hide show
  1. package/dist/cjs/graphs/Graph.cjs +11 -3
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/llm/anthropic/index.cjs +4 -3
  4. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  5. package/dist/cjs/llm/anthropic/utils/container.cjs +37 -0
  6. package/dist/cjs/llm/anthropic/utils/container.cjs.map +1 -0
  7. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +25 -23
  8. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  9. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +15 -21
  10. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  11. package/dist/cjs/llm/anthropic/utils/stream_events.cjs +16 -14
  12. package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
  13. package/dist/cjs/llm/bedrock/index.cjs +1 -1
  14. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  15. package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
  16. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +19 -13
  17. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
  18. package/dist/cjs/llm/google/utils/common.cjs +59 -13
  19. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  20. package/dist/cjs/llm/init.cjs +12 -2
  21. package/dist/cjs/llm/init.cjs.map +1 -1
  22. package/dist/cjs/llm/openai/index.cjs +1 -1
  23. package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
  24. package/dist/cjs/llm/prepareProviderRequest.cjs +1 -1
  25. package/dist/cjs/main.cjs +6 -3
  26. package/dist/cjs/messages/alternation.cjs +1 -1
  27. package/dist/cjs/messages/anthropicServerTools.cjs +20 -0
  28. package/dist/cjs/messages/anthropicServerTools.cjs.map +1 -0
  29. package/dist/cjs/messages/budget.cjs +1 -1
  30. package/dist/cjs/messages/core.cjs +3 -2
  31. package/dist/cjs/messages/core.cjs.map +1 -1
  32. package/dist/cjs/messages/format.cjs +2 -2
  33. package/dist/cjs/messages/index.cjs +1 -1
  34. package/dist/cjs/messages/prune.cjs +1 -1
  35. package/dist/cjs/messages/recency.cjs +1 -1
  36. package/dist/cjs/messages/toolResultTypes.cjs +21 -45
  37. package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
  38. package/dist/cjs/protection/providerText.cjs +4 -0
  39. package/dist/cjs/protection/providerText.cjs.map +1 -1
  40. package/dist/cjs/protection/toolResult.cjs +119 -0
  41. package/dist/cjs/protection/toolResult.cjs.map +1 -0
  42. package/dist/cjs/run.cjs +7 -1
  43. package/dist/cjs/run.cjs.map +1 -1
  44. package/dist/cjs/runtime/client.cjs +2 -0
  45. package/dist/cjs/runtime/client.cjs.map +1 -1
  46. package/dist/cjs/stream.cjs +1 -0
  47. package/dist/cjs/stream.cjs.map +1 -1
  48. package/dist/cjs/summarization/node.cjs +1 -1
  49. package/dist/cjs/tools/ToolNode.cjs +46 -13
  50. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  51. package/dist/cjs/tools/search/content.cjs +163 -42
  52. package/dist/cjs/tools/search/content.cjs.map +1 -1
  53. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +4 -0
  54. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  55. package/dist/cjs/utils/tokens.cjs +7 -2
  56. package/dist/cjs/utils/tokens.cjs.map +1 -1
  57. package/dist/esm/graphs/Graph.mjs +11 -3
  58. package/dist/esm/graphs/Graph.mjs.map +1 -1
  59. package/dist/esm/llm/anthropic/index.mjs +4 -3
  60. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  61. package/dist/esm/llm/anthropic/utils/container.mjs +37 -0
  62. package/dist/esm/llm/anthropic/utils/container.mjs.map +1 -0
  63. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +25 -23
  64. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  65. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +15 -21
  66. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  67. package/dist/esm/llm/anthropic/utils/stream_events.mjs +16 -14
  68. package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
  69. package/dist/esm/llm/bedrock/index.mjs +2 -2
  70. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  71. package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
  72. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +19 -14
  73. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
  74. package/dist/esm/llm/google/utils/common.mjs +59 -13
  75. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  76. package/dist/esm/llm/init.mjs +12 -2
  77. package/dist/esm/llm/init.mjs.map +1 -1
  78. package/dist/esm/llm/openai/index.mjs +1 -1
  79. package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
  80. package/dist/esm/llm/prepareProviderRequest.mjs +1 -1
  81. package/dist/esm/main.mjs +5 -4
  82. package/dist/esm/messages/alternation.mjs +1 -1
  83. package/dist/esm/messages/anthropicServerTools.mjs +18 -0
  84. package/dist/esm/messages/anthropicServerTools.mjs.map +1 -0
  85. package/dist/esm/messages/budget.mjs +1 -1
  86. package/dist/esm/messages/core.mjs +3 -2
  87. package/dist/esm/messages/core.mjs.map +1 -1
  88. package/dist/esm/messages/format.mjs +2 -2
  89. package/dist/esm/messages/index.mjs +1 -1
  90. package/dist/esm/messages/prune.mjs +1 -1
  91. package/dist/esm/messages/recency.mjs +1 -1
  92. package/dist/esm/messages/toolResultTypes.mjs +21 -45
  93. package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
  94. package/dist/esm/protection/providerText.mjs +4 -1
  95. package/dist/esm/protection/providerText.mjs.map +1 -1
  96. package/dist/esm/protection/toolResult.mjs +114 -0
  97. package/dist/esm/protection/toolResult.mjs.map +1 -0
  98. package/dist/esm/run.mjs +7 -1
  99. package/dist/esm/run.mjs.map +1 -1
  100. package/dist/esm/runtime/client.mjs +2 -0
  101. package/dist/esm/runtime/client.mjs.map +1 -1
  102. package/dist/esm/stream.mjs +1 -0
  103. package/dist/esm/stream.mjs.map +1 -1
  104. package/dist/esm/summarization/node.mjs +1 -1
  105. package/dist/esm/tools/ToolNode.mjs +46 -13
  106. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  107. package/dist/esm/tools/search/content.mjs +163 -42
  108. package/dist/esm/tools/search/content.mjs.map +1 -1
  109. package/dist/esm/tools/subagent/SubagentExecutor.mjs +4 -0
  110. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  111. package/dist/esm/utils/tokens.mjs +7 -2
  112. package/dist/esm/utils/tokens.mjs.map +1 -1
  113. package/dist/types/common/index.d.ts +2 -2
  114. package/dist/types/decisions/breaker.d.ts +2 -2
  115. package/dist/types/decisions/core.d.ts +13 -13
  116. package/dist/types/decisions/dialect.d.ts +1 -1
  117. package/dist/types/decisions/http.d.ts +2 -2
  118. package/dist/types/decisions/index.d.ts +5 -5
  119. package/dist/types/decisions/node.d.ts +2 -2
  120. package/dist/types/decisions/presets.d.ts +2 -2
  121. package/dist/types/decisions/probe.d.ts +1 -1
  122. package/dist/types/decisions/questions.d.ts +1 -1
  123. package/dist/types/decisions/structuredChat.d.ts +2 -2
  124. package/dist/types/decisions/transport.d.ts +1 -1
  125. package/dist/types/eventActor/EventActorExecutor.d.ts +1 -1
  126. package/dist/types/eventActor/index.d.ts +2 -2
  127. package/dist/types/graphs/Graph.d.ts +4 -2
  128. package/dist/types/graphs/MultiAgentGraph.d.ts +1 -1
  129. package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +1 -1
  130. package/dist/types/graphs/graphFactory.d.ts +1 -1
  131. package/dist/types/graphs/index.d.ts +5 -5
  132. package/dist/types/harness/fileBindings.d.ts +2 -2
  133. package/dist/types/harness/fileService.d.ts +2 -2
  134. package/dist/types/harness/fileStream.d.ts +1 -1
  135. package/dist/types/harness/index.d.ts +15 -15
  136. package/dist/types/harness/model.d.ts +1 -1
  137. package/dist/types/harness/modelService.d.ts +2 -2
  138. package/dist/types/harness/modelStreamCallbacks.d.ts +1 -1
  139. package/dist/types/harness/providerText.d.ts +1 -1
  140. package/dist/types/hitl/index.d.ts +3 -3
  141. package/dist/types/hooks/HookRegistry.d.ts +1 -1
  142. package/dist/types/hooks/createToolPolicyHook.d.ts +1 -1
  143. package/dist/types/hooks/createWorkspacePolicyHook.d.ts +1 -1
  144. package/dist/types/hooks/executeHooks.d.ts +2 -2
  145. package/dist/types/hooks/index.d.ts +11 -11
  146. package/dist/types/index.d.ts +62 -60
  147. package/dist/types/langchain/index.d.ts +8 -8
  148. package/dist/types/llm/anthropic/utils/container.d.ts +4 -0
  149. package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
  150. package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
  151. package/dist/types/llm/anthropic/utils/stream_events.d.ts +1 -1
  152. package/dist/types/llm/bedrock/index.d.ts +2 -3
  153. package/dist/types/llm/bedrock/utils/harmony.d.ts +1 -1
  154. package/dist/types/llm/bedrock/utils/index.d.ts +2 -2
  155. package/dist/types/llm/bedrock/utils/message_inputs.d.ts +3 -12
  156. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
  157. package/dist/types/llm/google/index.d.ts +2 -2
  158. package/dist/types/llm/google/utils/common.d.ts +1 -1
  159. package/dist/types/llm/google/utils/tools.d.ts +1 -1
  160. package/dist/types/llm/openai/index.d.ts +1 -1
  161. package/dist/types/llm/providerRegistry.d.ts +1 -1
  162. package/dist/types/llm/providers.d.ts +1 -1
  163. package/dist/types/messages/anthropicServerTools.d.ts +13 -0
  164. package/dist/types/messages/contextPruning.d.ts +1 -1
  165. package/dist/types/messages/core.d.ts +4 -4
  166. package/dist/types/messages/format.d.ts +1 -1
  167. package/dist/types/messages/index.d.ts +21 -21
  168. package/dist/types/messages/prune.d.ts +1 -1
  169. package/dist/types/openai/index.d.ts +2 -2
  170. package/dist/types/openai/toolProjection.d.ts +1 -1
  171. package/dist/types/prompts/index.d.ts +2 -2
  172. package/dist/types/protection/providerText.d.ts +3 -1
  173. package/dist/types/protection/toolResult.d.ts +69 -0
  174. package/dist/types/provider-registration.d.ts +1 -1
  175. package/dist/types/rerank/bm25.d.ts +1 -1
  176. package/dist/types/rerank/core.d.ts +17 -17
  177. package/dist/types/rerank/crossEncoder.d.ts +3 -3
  178. package/dist/types/rerank/fallback.d.ts +1 -1
  179. package/dist/types/rerank/index.d.ts +2 -2
  180. package/dist/types/rerank/outcome.d.ts +2 -2
  181. package/dist/types/rerank/pin.d.ts +2 -2
  182. package/dist/types/rerank/search.d.ts +1 -1
  183. package/dist/types/rerank/systemone.d.ts +4 -4
  184. package/dist/types/rerank/types.d.ts +1 -1
  185. package/dist/types/run.d.ts +1 -0
  186. package/dist/types/runtime/admission.d.ts +1 -1
  187. package/dist/types/runtime/checkpoint.d.ts +1 -1
  188. package/dist/types/runtime/client.d.ts +2 -2
  189. package/dist/types/runtime/files.d.ts +3 -3
  190. package/dist/types/runtime/hostTools.d.ts +2 -2
  191. package/dist/types/runtime/index.d.ts +12 -12
  192. package/dist/types/runtime/model.d.ts +5 -5
  193. package/dist/types/runtime/policy.d.ts +3 -3
  194. package/dist/types/runtime/recovery/client.d.ts +3 -3
  195. package/dist/types/runtime/recovery/log.d.ts +2 -2
  196. package/dist/types/runtime/recovery/redis.d.ts +1 -1
  197. package/dist/types/runtime/recovery/server.d.ts +3 -3
  198. package/dist/types/runtime/resume.d.ts +1 -1
  199. package/dist/types/runtime/server.d.ts +3 -3
  200. package/dist/types/runtime/snapshot.d.ts +1 -1
  201. package/dist/types/runtime/types.d.ts +2 -2
  202. package/dist/types/session/AgentSession.d.ts +2 -2
  203. package/dist/types/session/JsonlSessionStore.d.ts +1 -1
  204. package/dist/types/session/deriveMessages.d.ts +1 -1
  205. package/dist/types/session/handlers.d.ts +1 -1
  206. package/dist/types/session/index.d.ts +7 -7
  207. package/dist/types/session/messageSerialization.d.ts +1 -1
  208. package/dist/types/session/sessionProjection.d.ts +3 -3
  209. package/dist/types/summarization/index.d.ts +2 -2
  210. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -1
  211. package/dist/types/tools/GitHubCompare.d.ts +6 -6
  212. package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
  213. package/dist/types/tools/ReadFile.d.ts +6 -6
  214. package/dist/types/tools/SkillTool.d.ts +6 -6
  215. package/dist/types/tools/ToolNode.d.ts +5 -1
  216. package/dist/types/tools/cloudflare/index.d.ts +4 -4
  217. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  218. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  219. package/dist/types/tools/local/attachments.d.ts +1 -1
  220. package/dist/types/tools/local/index.d.ts +12 -12
  221. package/dist/types/tools/search/anthropic.d.ts +1 -1
  222. package/dist/types/tools/search/content.d.ts +38 -1
  223. package/dist/types/tools/search/crw-scraper.d.ts +1 -1
  224. package/dist/types/tools/search/crw-search.d.ts +1 -1
  225. package/dist/types/tools/search/firecrawl.d.ts +1 -1
  226. package/dist/types/tools/search/format.d.ts +1 -1
  227. package/dist/types/tools/search/highlights.d.ts +1 -1
  228. package/dist/types/tools/search/index.d.ts +3 -3
  229. package/dist/types/tools/search/keenable-scraper.d.ts +1 -1
  230. package/dist/types/tools/search/keenable-search.d.ts +1 -1
  231. package/dist/types/tools/search/metrics.d.ts +1 -1
  232. package/dist/types/tools/search/rerankers.d.ts +1 -1
  233. package/dist/types/tools/search/schema.d.ts +6 -6
  234. package/dist/types/tools/search/search.d.ts +1 -1
  235. package/dist/types/tools/search/serper-scraper.d.ts +1 -1
  236. package/dist/types/tools/search/tavily-scraper.d.ts +1 -1
  237. package/dist/types/tools/search/tavily-search.d.ts +1 -1
  238. package/dist/types/tools/search/tool.d.ts +3 -3
  239. package/dist/types/tools/search/types.d.ts +2 -2
  240. package/dist/types/tools/search/utils.d.ts +3 -3
  241. package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +1 -1
  242. package/dist/types/tools/subagent/SubagentExecutor.d.ts +6 -3
  243. package/dist/types/tools/subagent/diagnostics.d.ts +1 -1
  244. package/dist/types/tools/subagent/index.d.ts +7 -7
  245. package/dist/types/types/attachments.d.ts +1 -1
  246. package/dist/types/types/graph.d.ts +4 -1
  247. package/dist/types/types/index.d.ts +14 -14
  248. package/dist/types/types/llm.d.ts +2 -2
  249. package/dist/types/types/run.d.ts +3 -1
  250. package/dist/types/types/subagentTasks.d.ts +2 -2
  251. package/dist/types/types/tools.d.ts +6 -3
  252. package/dist/types/utils/index.d.ts +10 -10
  253. package/dist/types/utils/tokens.d.ts +1 -0
  254. package/package.json +3 -2
  255. package/src/graphs/Graph.ts +22 -0
  256. package/src/index.ts +8 -0
  257. package/src/llm/anthropic/index.ts +11 -3
  258. package/src/llm/anthropic/utils/container.ts +63 -0
  259. package/src/llm/anthropic/utils/message_inputs.ts +57 -51
  260. package/src/llm/anthropic/utils/message_outputs.ts +12 -39
  261. package/src/llm/anthropic/utils/stream_events.ts +17 -12
  262. package/src/llm/bedrock/index.ts +7 -5
  263. package/src/llm/bedrock/utils/message_inputs.ts +28 -35
  264. package/src/llm/google/utils/common.ts +88 -36
  265. package/src/llm/init.ts +35 -3
  266. package/src/messages/anthropicServerTools.ts +24 -0
  267. package/src/messages/core.ts +12 -11
  268. package/src/messages/toolResultTypes.ts +80 -88
  269. package/src/protection/providerText.ts +127 -40
  270. package/src/protection/toolResult.ts +272 -0
  271. package/src/run.ts +15 -4
  272. package/src/runtime/client.ts +3 -0
  273. package/src/stream.ts +5 -0
  274. package/src/tools/ToolNode.ts +112 -17
  275. package/src/tools/search/content.ts +282 -62
  276. package/src/tools/subagent/SubagentExecutor.ts +6 -0
  277. package/src/types/graph.ts +3 -0
  278. package/src/types/run.ts +3 -0
  279. package/src/types/tools.ts +3 -0
  280. 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 Uint8Array.from(atob(data), (char) => char.charCodeAt(0));
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: Uint8Array.from(atob(imageBlock.data), (c) =>
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
- * Whether the model is an identified OpenAI model on Bedrock (`openai.*`, a geo/global
1146
- * inference profile such as `global.openai.*`, or an ARN naming one). Missing model IDs and
1147
- * opaque resource ARNs are not identified.
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
- if (model == null || model === '') {
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 !isBedrockOpenAIModel(model);
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 openAITarget = isBedrockOpenAIModel(options.model);
1188
- const replayReasoning = !openAITarget;
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 (!openAITarget) {
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: FunctionCallPart[] = [];
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
- const parsedFunctionCallIds = new Set(
583
- functionCalls.flatMap((part) => {
584
- const functionCall = part.functionCall as GoogleFunctionCallWithId;
585
- return functionCall.id != null ? [functionCall.id] : [];
586
- })
587
- );
588
- const parsedFunctionCallNames = new Set(
589
- functionCalls.map((part) => part.functionCall.name)
590
- );
591
- const contentWithoutParsedMirrors = messageParts.filter((part) => {
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
- return [...contentWithoutParsedMirrors, ...functionCalls];
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 !== true || !canDisableTools)
105
- return model.bindTools(tools);
106
- return model.bindTools(tools, { tool_choice: 'none' });
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
+ }
@@ -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
- 'web_search_tool_result',
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
- ...ADVISOR_TOOL_NAMES,
100
- ...BASH_TOOL_NAMES,
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<Record<string, readonly string[]>> =
605
- {
606
- advisor_tool_result: ANTHROPIC_RESULT_FIELDS,
607
- bash_code_execution_tool_result: ANTHROPIC_RESULT_FIELDS,
608
- code_execution_tool_result: ANTHROPIC_RESULT_FIELDS,
609
- mcp_tool_result: ANTHROPIC_GENERIC_RESULT_FIELDS,
610
- text_editor_code_execution_tool_result: ANTHROPIC_RESULT_FIELDS,
611
- tool_search_tool_result: ANTHROPIC_RESULT_FIELDS,
612
- tool_result: ANTHROPIC_GENERIC_RESULT_FIELDS,
613
- web_fetch_tool_result: ANTHROPIC_SERVER_RESULT_FIELDS,
614
- web_search_tool_result: ANTHROPIC_SERVER_RESULT_FIELDS,
615
- server_tool_call_result: [
616
- 'type',
617
- 'toolCallId',
618
- 'status',
619
- 'output',
620
- ...LOCAL_RESULT_METADATA_FIELDS,
621
- ],
622
- server_tool_result: [
623
- 'type',
624
- 'tool_call_id',
625
- 'status',
626
- 'output',
627
- ...LOCAL_RESULT_METADATA_FIELDS,
628
- ],
629
- codeExecutionResult: ['type', 'codeExecutionResult', 'agentId', 'groupId'],
630
- toolResponse: [
631
- 'type',
632
- 'toolResponse',
633
- 'thought',
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
- const allowedFields =
667
- type == null ? undefined : TOOL_RESULT_ENVELOPE_FIELDS[type];
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
- const structuredToolNames = ANTHROPIC_STRUCTURED_RESULT_TOOL_NAMES[type];
679
- if (structuredToolNames != null) {
680
- return anthropicDescriptor(record, type, structuredToolNames);
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: WEB_SEARCH_TOOL_NAMES,
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
- Object.prototype.hasOwnProperty.call(TOOL_RESULT_ENVELOPE_FIELDS, type))
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, STANDARD_CALL_FIELDS, ['id', 'name', 'args']);
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, STANDARD_CALL_FIELDS, ['id', 'name', 'args'])
994
+ !hasExactCallShape(record, fields, ['id', 'name', 'args']) ||
995
+ !hasValidCallerProperty(record)
998
996
  ) {
999
997
  return undefined;
1000
998
  }
1001
- const callId = readPairingString(record, 'id');
1002
- const name = optionalName(record);
1003
- return callId == null || name == null
1004
- ? undefined
1005
- : {
1006
- callId,
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 =