@kingsoftcloud/agentkit-harness-node 0.0.30 → 0.0.32

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/index.mjs CHANGED
@@ -1455,8 +1455,7 @@ function parseRetryAfterMs(headerValue) {
1455
1455
  const trimmed = String(headerValue).trim();
1456
1456
  if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
1457
1457
  const seconds = Number(trimmed);
1458
- if (Number.isFinite(seconds) && seconds >= 0) return Math.round(seconds * 1e3);
1459
- return null;
1458
+ return Math.min(Number.MAX_SAFE_INTEGER, Math.round(seconds * 1e3));
1460
1459
  }
1461
1460
  const parsed = Date.parse(trimmed);
1462
1461
  if (Number.isNaN(parsed)) return null;
@@ -1662,6 +1661,25 @@ async function* readModelSse(body, { maxFrameBytes = 8 * 1024 * 1024, maxBytes,
1662
1661
  }
1663
1662
  }
1664
1663
 
1664
+ // packages/agentkit-harness-node/src/native/model-tool-view.mjs
1665
+ function modelToolView(text, toolName, tools) {
1666
+ if (typeof text !== "string" || !text) return text;
1667
+ if (toolName !== "run_command" || !tools?.some((tool) => tool.name === toolName && tool.backgroundCommandPolicy === "owned-command-launch/v1" && tool.workspaceChangePolicy === "observed-command/v1" && tool.permissions?.includes("sandbox:execute"))) return text;
1668
+ let receipt, inexact = false;
1669
+ try {
1670
+ receipt = JSON.parse(text, (key, value, context) => {
1671
+ const source = context?.source;
1672
+ if (typeof value === "number" && typeof source === "string" && /^-?\d+$/.test(source) && JSON.stringify(value) !== source) inexact = true;
1673
+ return value;
1674
+ });
1675
+ } catch {
1676
+ return text;
1677
+ }
1678
+ if (inexact || receipt?.backend !== "sandbox/local_process") return text;
1679
+ const { command, controls, sandbox_id, ...view } = receipt;
1680
+ return JSON.stringify(view);
1681
+ }
1682
+
1665
1683
  // packages/agentkit-harness-node/src/native/model-stream-budget.mjs
1666
1684
  var ModelStreamLimitError = class extends ProtocolError {
1667
1685
  };
@@ -2069,6 +2087,7 @@ import { FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL2 } from "@kingsoftcloud/
2069
2087
  var strict = /* @__PURE__ */ new Set(["openai", "strict-openai", "cerebras", "groq"]);
2070
2088
  var requiredAuto = /* @__PURE__ */ new Set(["claude-opus-5-5", "claude-sonnet-5-5", "claude-fable-5-1", "claude-mythos-5-1"]);
2071
2089
  var mandatory = /* @__PURE__ */ new Set(["claude-fable-5-1", "claude-opus-5-5", "claude-sonnet-5-5"]);
2090
+ var gatewayMandatoryGlm = /* @__PURE__ */ new Set(["glm-5.3", "glm-5.3-flash", "glm-5.3-flashx"]);
2072
2091
  var ranks = { none: 0, minimal: 1, low: 2, medium: 3, high: 4, xhigh: 5, max: 5 };
2073
2092
  var normalized = (model) => String(model ?? "").trim().toLowerCase().replaceAll("_", "-");
2074
2093
  var object = (value) => value && typeof value === "object" && !Array.isArray(value);
@@ -2096,13 +2115,15 @@ function applyAnthropicThinking(payload, profile, binding) {
2096
2115
  }
2097
2116
  function resolveProviderCompatibility(policy, binding) {
2098
2117
  if (!policy) return null;
2099
- const version = ["provider-compat/v1", "provider-compat/v2", "provider-compat/v3", "provider-compat/v4", "provider-compat/v5"].indexOf(policy.contract) + 1;
2118
+ const version = ["provider-compat/v1", "provider-compat/v2", "provider-compat/v3", "provider-compat/v4", "provider-compat/v5", "provider-compat/v6"].indexOf(policy.contract) + 1;
2100
2119
  if (!version) throw new ProtocolError("invalid_provider_compatibility_policy");
2101
2120
  const rule = resolveCompatibilityRule(policy.rule, binding);
2102
2121
  const name = String(binding.model ?? "").trim().toLowerCase();
2103
2122
  const kimi = ["kspmas-gateway", "moonshot"].includes(rule) && ["kimi-k2.7-code", "kimi-k2.7-code-highspeed"].includes(name);
2104
2123
  const modern = version >= 3;
2105
- const reasoningRequired = modern && rule === "kspmas-gateway" && name === "glm-5.3-flash";
2124
+ const gatewayFlash = rule === "kspmas-gateway" && name === "glm-5.3-flash";
2125
+ const gatewayMandatoryThinking = version >= 6 && rule === "kspmas-gateway" && gatewayMandatoryGlm.has(name);
2126
+ const reasoningRequired = gatewayMandatoryThinking || modern && gatewayFlash;
2106
2127
  const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2107
2128
  return {
2108
2129
  rule,
@@ -2111,7 +2132,8 @@ function resolveProviderCompatibility(policy, binding) {
2111
2132
  supportsToolArgumentStreaming: version >= 2 && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2112
2133
  reasoningRequired,
2113
2134
  modern,
2114
- firstToolLowEffort: version >= 5 && reasoningRequired,
2135
+ firstToolLowEffort: version >= 5 && gatewayFlash,
2136
+ minimumReasoningEffort: gatewayMandatoryThinking ? "low" : null,
2115
2137
  // This route already uses the supported non-thinking mode for tool work.
2116
2138
  // A bounded summary has no tools: omitting the switch can instead select
2117
2139
  // the provider's default high reasoning and consume its whole output cap.
@@ -2164,6 +2186,7 @@ function applyProviderChatCompatibility(payload, request, binding) {
2164
2186
  if (requested === null && options.controllerReasoningPolicy === "disclosed-delegate/v1" && ["zai", "kspmas-gateway"].includes(compat.rule) && name.startsWith("glm-5.3") && result.tools?.some((tool) => tool.type === "function" && tool.function?.name === "delegate_task")) effort = "low";
2165
2187
  if (requested === null && request.purpose === "compaction" && compat.rule === "kspmas-gateway" && ["glm-5.2", "deepseek-v4-flash"].includes(name)) effort = "none";
2166
2188
  if (requested === null && request.purpose === "compaction" && compat.reasoningRequired) effort = "low";
2189
+ if (compat.minimumReasoningEffort && (effort === "none" || effort === "minimal")) effort = compat.minimumReasoningEffort;
2167
2190
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
2168
2191
  if (effort !== null) result.reasoning_effort = effort;
2169
2192
  if (result.stream) result.stream_options = { ...object(result.stream_options) ? result.stream_options : {}, include_usage: true };
@@ -2473,7 +2496,7 @@ function buildOpenAIRequest(binding, request) {
2473
2496
  function projectMessagesOpenAI(request, maxInlineImageBytes) {
2474
2497
  const profile = request.profile;
2475
2498
  const projected = [];
2476
- const pending = /* @__PURE__ */ new Set();
2499
+ const pending = /* @__PURE__ */ new Map();
2477
2500
  let images = [];
2478
2501
  for (const message of request.messages || []) {
2479
2502
  const role = message.role;
@@ -2482,12 +2505,14 @@ function projectMessagesOpenAI(request, maxInlineImageBytes) {
2482
2505
  }
2483
2506
  if (role === "assistant" && message.toolCalls && message.toolCalls.length) {
2484
2507
  validateAssistantToolIds(message.toolCalls);
2485
- for (const call of message.toolCalls) pending.add(call.callId);
2508
+ for (const call of message.toolCalls) pending.set(call.callId, call.name);
2486
2509
  }
2510
+ let toolName;
2487
2511
  if (role === "tool") {
2488
2512
  if (!pending.has(message.callId)) {
2489
2513
  throw new ProtocolError("tool receipt does not match the pending assistant batch");
2490
2514
  }
2515
+ toolName = pending.get(message.callId);
2491
2516
  pending.delete(message.callId);
2492
2517
  }
2493
2518
  const media = message.media ? message.media.map((b) => validateMediaBlock(b, maxInlineImageBytes)) : null;
@@ -2519,7 +2544,7 @@ function projectMessagesOpenAI(request, maxInlineImageBytes) {
2519
2544
  Object.assign(msg, openAIReplayFields(message, profile));
2520
2545
  projected.push(msg);
2521
2546
  } else if (role === "tool") {
2522
- projected.push({ role: "tool", tool_call_id: message.callId, content: message.content || "" });
2547
+ projected.push({ role: "tool", tool_call_id: message.callId, content: modelToolView(message.content || "", toolName, request.tools) });
2523
2548
  } else {
2524
2549
  projected.push({ role, content: message.content || "" });
2525
2550
  }
@@ -3170,8 +3195,7 @@ function projectAnthropicMessages(request, maxInlineImageBytes) {
3170
3195
  const native = isNativeToolSearch(profile) && !["compaction", "delivery_review"].includes(request.purpose);
3171
3196
  const systemParts = [];
3172
3197
  const items = [];
3173
- const pending = /* @__PURE__ */ new Set();
3174
- const pendingNames = /* @__PURE__ */ new Map();
3198
+ const pending = /* @__PURE__ */ new Map();
3175
3199
  const wireIds = /* @__PURE__ */ new Map();
3176
3200
  const midSystem = profile.anthropicPolicy?.midSystem === true;
3177
3201
  for (const message of request.messages || []) {
@@ -3181,16 +3205,12 @@ function projectAnthropicMessages(request, maxInlineImageBytes) {
3181
3205
  if (role !== "tool" && pending.size) throw new ProtocolError("incomplete assistant tool batch before next message");
3182
3206
  if (role === "assistant" && message.toolCalls?.length) {
3183
3207
  validateAssistantToolIds2(message.toolCalls);
3184
- for (const call of message.toolCalls) {
3185
- pending.add(call.callId);
3186
- pendingNames.set(call.callId, modelWireToolCall3(call).name);
3187
- }
3208
+ for (const call of message.toolCalls) pending.set(call.callId, call);
3188
3209
  }
3189
- let pairedName;
3210
+ let pairedCall;
3190
3211
  if (role === "tool") {
3212
+ pairedCall = pending.get(message.callId);
3191
3213
  if (!pending.delete(message.callId)) throw new ProtocolError("tool receipt does not match the pending assistant batch");
3192
- pairedName = pendingNames.get(message.callId);
3193
- pendingNames.delete(message.callId);
3194
3214
  }
3195
3215
  if (role === "system" || role === "developer") {
3196
3216
  if (midSystem && items.length) items.push({ role: "system", content: message.content || "" });
@@ -3199,12 +3219,12 @@ function projectAnthropicMessages(request, maxInlineImageBytes) {
3199
3219
  }
3200
3220
  let item;
3201
3221
  if (role === "tool") {
3202
- const references = native ? nativeToolReferenceContent(message, pairedName, request.tools) : void 0;
3222
+ const references = native ? nativeToolReferenceContent(message, modelWireToolCall3(pairedCall).name, request.tools) : void 0;
3203
3223
  const media = message.media ? message.media.map((b) => validateMediaBlock(b, maxInlineImageBytes)) : null;
3204
3224
  let content;
3205
3225
  if (references) content = [...references, ...media?.length ? projectMediaAnthropic(media) : []];
3206
3226
  else if (media && media.length) content = [{ type: "text", text: message.content || "" }, ...projectMediaAnthropic(media)];
3207
- else content = message.content || "";
3227
+ else content = modelToolView(message.content || "", pairedCall.name, request.tools);
3208
3228
  item = {
3209
3229
  role: "user",
3210
3230
  content: [{
@@ -3896,7 +3916,7 @@ function projectMessagesResponses(request, maxInlineImageBytes) {
3896
3916
  const profile = request.profile;
3897
3917
  const instructions = [];
3898
3918
  const items = [];
3899
- const pending = /* @__PURE__ */ new Set();
3919
+ const pending = /* @__PURE__ */ new Map();
3900
3920
  for (const message of request.messages || []) {
3901
3921
  const role = message.role;
3902
3922
  if (role !== "tool" && pending.size) {
@@ -3904,12 +3924,14 @@ function projectMessagesResponses(request, maxInlineImageBytes) {
3904
3924
  }
3905
3925
  if (role === "assistant" && message.toolCalls && message.toolCalls.length) {
3906
3926
  validateAssistantToolIds3(message.toolCalls);
3907
- for (const call of message.toolCalls) pending.add(call.callId);
3927
+ for (const call of message.toolCalls) pending.set(call.callId, call.name);
3908
3928
  }
3929
+ let toolName;
3909
3930
  if (role === "tool") {
3910
3931
  if (!pending.has(message.callId)) {
3911
3932
  throw new ProtocolError("tool receipt does not match the pending assistant batch");
3912
3933
  }
3934
+ toolName = pending.get(message.callId);
3913
3935
  pending.delete(message.callId);
3914
3936
  }
3915
3937
  if (message.providerReplay && message.providerReplay.version === "model-replay/v2") {
@@ -3921,7 +3943,7 @@ function projectMessagesResponses(request, maxInlineImageBytes) {
3921
3943
  }
3922
3944
  if (role === "tool") {
3923
3945
  const media2 = message.media ? message.media.map((b) => validateMediaBlock(b, maxInlineImageBytes)) : null;
3924
- const output = media2 && media2.length ? [{ type: "input_text", text: message.content || "" }, ...projectMediaResponses(media2)] : message.content || "";
3946
+ const output = media2 && media2.length ? [{ type: "input_text", text: message.content || "" }, ...projectMediaResponses(media2)] : modelToolView(message.content || "", toolName, request.tools);
3925
3947
  items.push({ type: "function_call_output", call_id: message.callId, output });
3926
3948
  continue;
3927
3949
  }
@@ -1466,8 +1466,7 @@ function parseRetryAfterMs(headerValue) {
1466
1466
  const trimmed = String(headerValue).trim();
1467
1467
  if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
1468
1468
  const seconds = Number(trimmed);
1469
- if (Number.isFinite(seconds) && seconds >= 0) return Math.round(seconds * 1e3);
1470
- return null;
1469
+ return Math.min(Number.MAX_SAFE_INTEGER, Math.round(seconds * 1e3));
1471
1470
  }
1472
1471
  const parsed = Date.parse(trimmed);
1473
1472
  if (Number.isNaN(parsed)) return null;
@@ -1673,6 +1672,25 @@ async function* readModelSse(body, { maxFrameBytes = 8 * 1024 * 1024, maxBytes,
1673
1672
  }
1674
1673
  }
1675
1674
 
1675
+ // packages/agentkit-harness-node/src/native/model-tool-view.mjs
1676
+ function modelToolView(text, toolName, tools) {
1677
+ if (typeof text !== "string" || !text) return text;
1678
+ if (toolName !== "run_command" || !tools?.some((tool) => tool.name === toolName && tool.backgroundCommandPolicy === "owned-command-launch/v1" && tool.workspaceChangePolicy === "observed-command/v1" && tool.permissions?.includes("sandbox:execute"))) return text;
1679
+ let receipt, inexact = false;
1680
+ try {
1681
+ receipt = JSON.parse(text, (key, value, context) => {
1682
+ const source = context?.source;
1683
+ if (typeof value === "number" && typeof source === "string" && /^-?\d+$/.test(source) && JSON.stringify(value) !== source) inexact = true;
1684
+ return value;
1685
+ });
1686
+ } catch {
1687
+ return text;
1688
+ }
1689
+ if (inexact || receipt?.backend !== "sandbox/local_process") return text;
1690
+ const { command, controls, sandbox_id, ...view } = receipt;
1691
+ return JSON.stringify(view);
1692
+ }
1693
+
1676
1694
  // packages/agentkit-harness-node/src/native/model-stream-budget.mjs
1677
1695
  var ModelStreamLimitError = class extends ProtocolError {
1678
1696
  };
@@ -2080,6 +2098,7 @@ import { FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL2 } from "@kingsoftcloud/
2080
2098
  var strict = /* @__PURE__ */ new Set(["openai", "strict-openai", "cerebras", "groq"]);
2081
2099
  var requiredAuto = /* @__PURE__ */ new Set(["claude-opus-5-5", "claude-sonnet-5-5", "claude-fable-5-1", "claude-mythos-5-1"]);
2082
2100
  var mandatory = /* @__PURE__ */ new Set(["claude-fable-5-1", "claude-opus-5-5", "claude-sonnet-5-5"]);
2101
+ var gatewayMandatoryGlm = /* @__PURE__ */ new Set(["glm-5.3", "glm-5.3-flash", "glm-5.3-flashx"]);
2083
2102
  var ranks = { none: 0, minimal: 1, low: 2, medium: 3, high: 4, xhigh: 5, max: 5 };
2084
2103
  var normalized = (model) => String(model ?? "").trim().toLowerCase().replaceAll("_", "-");
2085
2104
  var object = (value) => value && typeof value === "object" && !Array.isArray(value);
@@ -2107,13 +2126,15 @@ function applyAnthropicThinking(payload, profile, binding) {
2107
2126
  }
2108
2127
  function resolveProviderCompatibility(policy, binding) {
2109
2128
  if (!policy) return null;
2110
- const version = ["provider-compat/v1", "provider-compat/v2", "provider-compat/v3", "provider-compat/v4", "provider-compat/v5"].indexOf(policy.contract) + 1;
2129
+ const version = ["provider-compat/v1", "provider-compat/v2", "provider-compat/v3", "provider-compat/v4", "provider-compat/v5", "provider-compat/v6"].indexOf(policy.contract) + 1;
2111
2130
  if (!version) throw new ProtocolError("invalid_provider_compatibility_policy");
2112
2131
  const rule = resolveCompatibilityRule(policy.rule, binding);
2113
2132
  const name = String(binding.model ?? "").trim().toLowerCase();
2114
2133
  const kimi = ["kspmas-gateway", "moonshot"].includes(rule) && ["kimi-k2.7-code", "kimi-k2.7-code-highspeed"].includes(name);
2115
2134
  const modern = version >= 3;
2116
- const reasoningRequired = modern && rule === "kspmas-gateway" && name === "glm-5.3-flash";
2135
+ const gatewayFlash = rule === "kspmas-gateway" && name === "glm-5.3-flash";
2136
+ const gatewayMandatoryThinking = version >= 6 && rule === "kspmas-gateway" && gatewayMandatoryGlm.has(name);
2137
+ const reasoningRequired = gatewayMandatoryThinking || modern && gatewayFlash;
2117
2138
  const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2118
2139
  return {
2119
2140
  rule,
@@ -2122,7 +2143,8 @@ function resolveProviderCompatibility(policy, binding) {
2122
2143
  supportsToolArgumentStreaming: version >= 2 && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2123
2144
  reasoningRequired,
2124
2145
  modern,
2125
- firstToolLowEffort: version >= 5 && reasoningRequired,
2146
+ firstToolLowEffort: version >= 5 && gatewayFlash,
2147
+ minimumReasoningEffort: gatewayMandatoryThinking ? "low" : null,
2126
2148
  // This route already uses the supported non-thinking mode for tool work.
2127
2149
  // A bounded summary has no tools: omitting the switch can instead select
2128
2150
  // the provider's default high reasoning and consume its whole output cap.
@@ -2175,6 +2197,7 @@ function applyProviderChatCompatibility(payload, request, binding) {
2175
2197
  if (requested === null && options.controllerReasoningPolicy === "disclosed-delegate/v1" && ["zai", "kspmas-gateway"].includes(compat.rule) && name.startsWith("glm-5.3") && result.tools?.some((tool) => tool.type === "function" && tool.function?.name === "delegate_task")) effort = "low";
2176
2198
  if (requested === null && request.purpose === "compaction" && compat.rule === "kspmas-gateway" && ["glm-5.2", "deepseek-v4-flash"].includes(name)) effort = "none";
2177
2199
  if (requested === null && request.purpose === "compaction" && compat.reasoningRequired) effort = "low";
2200
+ if (compat.minimumReasoningEffort && (effort === "none" || effort === "minimal")) effort = compat.minimumReasoningEffort;
2178
2201
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
2179
2202
  if (effort !== null) result.reasoning_effort = effort;
2180
2203
  if (result.stream) result.stream_options = { ...object(result.stream_options) ? result.stream_options : {}, include_usage: true };
@@ -2484,7 +2507,7 @@ function buildOpenAIRequest(binding, request) {
2484
2507
  function projectMessagesOpenAI(request, maxInlineImageBytes) {
2485
2508
  const profile = request.profile;
2486
2509
  const projected = [];
2487
- const pending = /* @__PURE__ */ new Set();
2510
+ const pending = /* @__PURE__ */ new Map();
2488
2511
  let images = [];
2489
2512
  for (const message of request.messages || []) {
2490
2513
  const role = message.role;
@@ -2493,12 +2516,14 @@ function projectMessagesOpenAI(request, maxInlineImageBytes) {
2493
2516
  }
2494
2517
  if (role === "assistant" && message.toolCalls && message.toolCalls.length) {
2495
2518
  validateAssistantToolIds(message.toolCalls);
2496
- for (const call of message.toolCalls) pending.add(call.callId);
2519
+ for (const call of message.toolCalls) pending.set(call.callId, call.name);
2497
2520
  }
2521
+ let toolName;
2498
2522
  if (role === "tool") {
2499
2523
  if (!pending.has(message.callId)) {
2500
2524
  throw new ProtocolError("tool receipt does not match the pending assistant batch");
2501
2525
  }
2526
+ toolName = pending.get(message.callId);
2502
2527
  pending.delete(message.callId);
2503
2528
  }
2504
2529
  const media = message.media ? message.media.map((b) => validateMediaBlock(b, maxInlineImageBytes)) : null;
@@ -2530,7 +2555,7 @@ function projectMessagesOpenAI(request, maxInlineImageBytes) {
2530
2555
  Object.assign(msg, openAIReplayFields(message, profile));
2531
2556
  projected.push(msg);
2532
2557
  } else if (role === "tool") {
2533
- projected.push({ role: "tool", tool_call_id: message.callId, content: message.content || "" });
2558
+ projected.push({ role: "tool", tool_call_id: message.callId, content: modelToolView(message.content || "", toolName, request.tools) });
2534
2559
  } else {
2535
2560
  projected.push({ role, content: message.content || "" });
2536
2561
  }
@@ -3181,8 +3206,7 @@ function projectAnthropicMessages(request, maxInlineImageBytes) {
3181
3206
  const native = isNativeToolSearch(profile) && !["compaction", "delivery_review"].includes(request.purpose);
3182
3207
  const systemParts = [];
3183
3208
  const items = [];
3184
- const pending = /* @__PURE__ */ new Set();
3185
- const pendingNames = /* @__PURE__ */ new Map();
3209
+ const pending = /* @__PURE__ */ new Map();
3186
3210
  const wireIds = /* @__PURE__ */ new Map();
3187
3211
  const midSystem = profile.anthropicPolicy?.midSystem === true;
3188
3212
  for (const message of request.messages || []) {
@@ -3192,16 +3216,12 @@ function projectAnthropicMessages(request, maxInlineImageBytes) {
3192
3216
  if (role !== "tool" && pending.size) throw new ProtocolError("incomplete assistant tool batch before next message");
3193
3217
  if (role === "assistant" && message.toolCalls?.length) {
3194
3218
  validateAssistantToolIds2(message.toolCalls);
3195
- for (const call of message.toolCalls) {
3196
- pending.add(call.callId);
3197
- pendingNames.set(call.callId, modelWireToolCall3(call).name);
3198
- }
3219
+ for (const call of message.toolCalls) pending.set(call.callId, call);
3199
3220
  }
3200
- let pairedName;
3221
+ let pairedCall;
3201
3222
  if (role === "tool") {
3223
+ pairedCall = pending.get(message.callId);
3202
3224
  if (!pending.delete(message.callId)) throw new ProtocolError("tool receipt does not match the pending assistant batch");
3203
- pairedName = pendingNames.get(message.callId);
3204
- pendingNames.delete(message.callId);
3205
3225
  }
3206
3226
  if (role === "system" || role === "developer") {
3207
3227
  if (midSystem && items.length) items.push({ role: "system", content: message.content || "" });
@@ -3210,12 +3230,12 @@ function projectAnthropicMessages(request, maxInlineImageBytes) {
3210
3230
  }
3211
3231
  let item;
3212
3232
  if (role === "tool") {
3213
- const references = native ? nativeToolReferenceContent(message, pairedName, request.tools) : void 0;
3233
+ const references = native ? nativeToolReferenceContent(message, modelWireToolCall3(pairedCall).name, request.tools) : void 0;
3214
3234
  const media = message.media ? message.media.map((b) => validateMediaBlock(b, maxInlineImageBytes)) : null;
3215
3235
  let content;
3216
3236
  if (references) content = [...references, ...media?.length ? projectMediaAnthropic(media) : []];
3217
3237
  else if (media && media.length) content = [{ type: "text", text: message.content || "" }, ...projectMediaAnthropic(media)];
3218
- else content = message.content || "";
3238
+ else content = modelToolView(message.content || "", pairedCall.name, request.tools);
3219
3239
  item = {
3220
3240
  role: "user",
3221
3241
  content: [{
@@ -3907,7 +3927,7 @@ function projectMessagesResponses(request, maxInlineImageBytes) {
3907
3927
  const profile = request.profile;
3908
3928
  const instructions = [];
3909
3929
  const items = [];
3910
- const pending = /* @__PURE__ */ new Set();
3930
+ const pending = /* @__PURE__ */ new Map();
3911
3931
  for (const message of request.messages || []) {
3912
3932
  const role = message.role;
3913
3933
  if (role !== "tool" && pending.size) {
@@ -3915,12 +3935,14 @@ function projectMessagesResponses(request, maxInlineImageBytes) {
3915
3935
  }
3916
3936
  if (role === "assistant" && message.toolCalls && message.toolCalls.length) {
3917
3937
  validateAssistantToolIds3(message.toolCalls);
3918
- for (const call of message.toolCalls) pending.add(call.callId);
3938
+ for (const call of message.toolCalls) pending.set(call.callId, call.name);
3919
3939
  }
3940
+ let toolName;
3920
3941
  if (role === "tool") {
3921
3942
  if (!pending.has(message.callId)) {
3922
3943
  throw new ProtocolError("tool receipt does not match the pending assistant batch");
3923
3944
  }
3945
+ toolName = pending.get(message.callId);
3924
3946
  pending.delete(message.callId);
3925
3947
  }
3926
3948
  if (message.providerReplay && message.providerReplay.version === "model-replay/v2") {
@@ -3932,7 +3954,7 @@ function projectMessagesResponses(request, maxInlineImageBytes) {
3932
3954
  }
3933
3955
  if (role === "tool") {
3934
3956
  const media2 = message.media ? message.media.map((b) => validateMediaBlock(b, maxInlineImageBytes)) : null;
3935
- const output = media2 && media2.length ? [{ type: "input_text", text: message.content || "" }, ...projectMediaResponses(media2)] : message.content || "";
3957
+ const output = media2 && media2.length ? [{ type: "input_text", text: message.content || "" }, ...projectMediaResponses(media2)] : modelToolView(message.content || "", toolName, request.tools);
3936
3958
  items.push({ type: "function_call_output", call_id: message.callId, output });
3937
3959
  continue;
3938
3960
  }