@openclaw/ai 2026.8.1-beta.3 → 2026.8.2

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 (91) hide show
  1. package/dist/{anthropic-B8KwTtlb.mjs → anthropic-DTGZ4VMY.mjs} +25 -23
  2. package/dist/{anthropic-compaction-replay-4Zx7-aCr.mjs → anthropic-compaction-replay-CKCDrZJv.mjs} +34 -35
  3. package/dist/{anthropic-payload-policy-CSx7MoKH.d.mts → anthropic-payload-policy-BTzmNC14.d.mts} +3 -2
  4. package/dist/{api-registry-DFxSnFqG.d.mts → api-registry-BbUHEKER.d.mts} +2 -1
  5. package/dist/{azure-openai-responses-Aa4mVcYG.mjs → azure-openai-responses-BmqaDXM1.mjs} +6 -5
  6. package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
  7. package/dist/diagnostics.d.mts +2 -3
  8. package/dist/diagnostics.mjs +1 -1
  9. package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
  10. package/dist/{event-stream-D91-ohD_.d.mts → event-stream-DcvAPSBe.d.mts} +1 -2
  11. package/dist/event-stream-pXT3FI6X.d.mts +1 -0
  12. package/dist/event-stream.d.mts +2 -1
  13. package/dist/{google-yDRnipeq.mjs → google-CqjVZMwo.mjs} +8 -6
  14. package/dist/{google-shared-M1dl64nz.mjs → google-shared-Bnqni5j3.mjs} +34 -25
  15. package/dist/{google-vertex-DCJHM_a5.mjs → google-vertex-D_WREEJi.mjs} +8 -6
  16. package/dist/{host-DF_yxOsA.mjs → host-BIaiBURL.mjs} +4 -8
  17. package/dist/{host-DJq_FGcz.d.mts → host-DKFUAmCn.d.mts} +3 -3
  18. package/dist/index-CefaUGSS.d.mts +111 -0
  19. package/dist/index.d.mts +9 -10
  20. package/dist/index.mjs +4 -5
  21. package/dist/internal/anthropic.d.mts +51 -49
  22. package/dist/internal/anthropic.mjs +5 -5
  23. package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
  24. package/dist/internal/openai-responses-payload-policy.mjs +2 -3
  25. package/dist/internal/openai.d.mts +65 -63
  26. package/dist/internal/openai.mjs +10 -9
  27. package/dist/internal/retry-after.d.mts +2 -3
  28. package/dist/internal/runtime.d.mts +51 -40
  29. package/dist/internal/runtime.mjs +9 -9
  30. package/dist/internal/shared.d.mts +25 -25
  31. package/dist/internal/shared.mjs +3 -3
  32. package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
  33. package/dist/{mistral-D6hRXI7A.mjs → mistral-C24jVd6f.mjs} +34 -32
  34. package/dist/{openai-chatgpt-responses-C339VIfT.mjs → openai-chatgpt-responses-Czum0oXz.mjs} +38 -20
  35. package/dist/openai-completions-BfFwac6f.mjs +404 -0
  36. package/dist/{openai-completions-compat-B0KTleXp.d.mts → openai-completions-compat-SZhi0Lf4.d.mts} +3 -3
  37. package/dist/openai-completions-stream-DGOvau4J.mjs +1625 -0
  38. package/dist/{openai-responses-BXEcr-Tp.mjs → openai-responses-BAryVEJM.mjs} +11 -7
  39. package/dist/openai-responses-compaction-window-DO7yV7az.mjs +686 -0
  40. package/dist/{openai-responses-contracts-CD75pQ0m.d.mts → openai-responses-contracts-BthRXano.d.mts} +14 -5
  41. package/dist/{openai-responses-payload-policy-CNGFT9zr.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +1 -0
  42. package/dist/{openai-responses-prompt-observer-internal-BG-1AsBI.mjs → openai-responses-prompt-observer-internal--R0kZLOZ.mjs} +3 -2
  43. package/dist/{openai-responses-shared-Cvt5MgEm.mjs → openai-responses-shared-CxgdGBvm.mjs} +332 -1484
  44. package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
  45. package/dist/openai-tool-schema-CSMh5e9O.mjs +1697 -0
  46. package/dist/{provider-error-C8mBRJDl.mjs → provider-error-BI8kIViN.mjs} +14 -88
  47. package/dist/{provider-options-Cc5ZQ6Aa.d.mts → provider-options-DJd_9euj.d.mts} +13 -4
  48. package/dist/{provider-transcript-transform--gtf0ZbR.mjs → provider-transcript-transform-WvJmFUAf.mjs} +1 -1
  49. package/dist/provider-types.d.mts +18 -17
  50. package/dist/providers.d.mts +5 -6
  51. package/dist/providers.mjs +9 -9
  52. package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-BsUX44Tq.mjs} +30 -20
  53. package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
  54. package/dist/{sanitize-unicode-BP7HLLZn.mjs → sanitize-unicode-S6binQG-.mjs} +2 -9
  55. package/dist/simple-options-rdOPzr7Z.mjs +155 -0
  56. package/dist/{anthropic-BQXQudmA.mjs → src-C8U7lkoa.mjs} +75 -1
  57. package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
  58. package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
  59. package/dist/string-normalization--fwJ4S2q.mjs +16 -0
  60. package/dist/{tool-schema-json-projection-FEr-jOoZ.mjs → tool-schema-json-projection-BtZiml7r.mjs} +22 -32
  61. package/dist/transport-stream-shared-BbG7PThh.d.mts +138 -0
  62. package/dist/{simple-options-oqsXB6U3.mjs → transport-stream-shared-D8nQWCUo.mjs} +10 -118
  63. package/dist/{transport-utils-Bv0FHkd0.mjs → transport-utils-CtuS1Upe.mjs} +10 -10
  64. package/dist/transports.d.mts +130 -189
  65. package/dist/transports.mjs +227 -1249
  66. package/dist/{types-DTAP49HF.d.mts → types-Beemor2E.d.mts} +58 -24
  67. package/dist/types-COdhCX0U.d.mts +1 -0
  68. package/dist/types.d.mts +6 -5
  69. package/dist/types.mjs +3 -4
  70. package/dist/utf16-slice-qz3nsy87.mjs +84 -0
  71. package/dist/{validation-DYNNrU9u.d.mts → validation-CC6s7Smp.d.mts} +1 -2
  72. package/dist/{validation-B61OhAio.mjs → validation-CJZtym2g.mjs} +7 -5
  73. package/dist/validation.d.mts +1 -1
  74. package/dist/validation.mjs +1 -1
  75. package/package.json +6 -6
  76. package/dist/anthropic-BECQCNdF.d.mts +0 -98
  77. package/dist/event-stream-BVVgDSdq.d.mts +0 -1
  78. package/dist/headers-B_e4-1J0.mjs +0 -9
  79. package/dist/index-BVVgDSdq.d.mts +0 -1
  80. package/dist/openai-completions-D88orSJ9.mjs +0 -632
  81. package/dist/openai-responses-contracts-DvILoqBk.mjs +0 -247
  82. package/dist/openai-responses-payload-policy-BDo8CQsx.mjs +0 -208
  83. package/dist/openai-stop-reason-9OONKyAm.mjs +0 -579
  84. package/dist/openai-tool-projection-CHGLt03m.mjs +0 -426
  85. package/dist/provider-options-AvldWZt8.mjs +0 -21
  86. package/dist/record-coerce-DdXsgUd_.mjs +0 -23
  87. package/dist/src-D2H6yKkH.mjs +0 -2
  88. package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
  89. package/dist/string-coerce-fsri9iCu.mjs +0 -34
  90. package/dist/types-BVVgDSdq.d.mts +0 -1
  91. package/dist/utf16-slice-CvGodqok.mjs +0 -29
@@ -1,18 +1,20 @@
1
- import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
2
- import { d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, p as supportsClaudeAdaptiveThinking, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-BQXQudmA.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
+ import { g as supportsClaudeAdaptiveThinking, m as resolveClaudeSonnet5ModelIdentity, p as resolveClaudeOpus5ModelIdentity, y as supportsClaudeNativeXhighEffort } from "./src-C8U7lkoa.mjs";
3
3
  import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
4
- import { r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-BP7HLLZn.mjs";
5
- import { S as usesClaudeStreamingRefusalContract, _ as prepareClaudeNoPrefillRequestContext, a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, f as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, g as mapAnthropicStopReason, m as applyClaudeRequestContract, n as getAiTransportHost, p as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as extractToolResultBlockText, v as requiresClaudeAdaptiveThinking, x as usesClaudeFable5MessagesContract, y as resolveAnthropicThinkingEffort } from "./host-DF_yxOsA.mjs";
6
- import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
7
- import { n as projectProviderError } from "./provider-error-C8mBRJDl.mjs";
4
+ import { o as isRecord } from "./utf16-slice-qz3nsy87.mjs";
5
+ import { r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-S6binQG-.mjs";
6
+ import { S as usesClaudeStreamingRefusalContract, _ as prepareClaudeNoPrefillRequestContext, a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, f as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, g as mapAnthropicStopReason, m as applyClaudeRequestContract, n as getAiTransportHost, p as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as extractToolResultBlockText, v as requiresClaudeAdaptiveThinking, x as usesClaudeFable5MessagesContract, y as resolveAnthropicThinkingEffort } from "./host-BIaiBURL.mjs";
7
+ import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
8
+ import { A as applyAnthropicCacheControlToMessages, C as applyAnthropicFallbackBoundary, D as createAnthropicInlineImageBudget, E as applyAnthropicRefusal, I as isAnthropicOAuthApiKey, L as omitFoundryBearerCredentialHeaders, O as normalizeAnthropicInlineContent, R as usesFoundryBearerAuth, T as resolveAnthropicFallbackServingModelCost, _ as toClaudeCodeToolName, a as suppressAnthropicCompaction, b as ANTHROPIC_SERVER_SIDE_FALLBACKS, f as normalizeAnthropicToolCallId, g as resolveOriginalAnthropicToolName, h as reconcileAnthropicToolChoice, k as resolveAnthropicImageMediaType, m as projectAnthropicTools, n as createCompactionCapture, o as applyAnthropicMessageDeltaUsage, p as normalizeAnthropicToolChoice, r as isAnthropicReplayRejection, s as applyAnthropicMessageStartUsage, t as buildAnthropicReplayPlan, v as ANTHROPIC_OMITTED_REASONING_TEXT, w as readAnthropicFallbackBoundary, x as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, y as findActiveAnthropicToolTurnAssistantIndex } from "./anthropic-compaction-replay-CKCDrZJv.mjs";
8
9
  import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
9
- import { A as splitSystemPromptCacheBoundary, d as finalizeTerminalToolCallArguments, g as notifyProviderHttpResponse, j as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking, x as transportAbortError } from "./simple-options-oqsXB6U3.mjs";
10
- import { A as resolveAnthropicImageMediaType, C as readAnthropicFallbackBoundary, D as usesFoundryBearerAuth, E as omitFoundryBearerCredentialHeaders, O as createAnthropicInlineImageBudget, S as applyAnthropicFallbackBoundary, T as applyAnthropicRefusal, _ as ANTHROPIC_OMITTED_REASONING_TEXT, a as applyAnthropicMessageDeltaUsage, b as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, d as normalizeAnthropicToolCallId, f as normalizeAnthropicToolChoice, g as toClaudeCodeToolName, h as resolveOriginalAnthropicToolName, i as suppressAnthropicCompaction, j as applyAnthropicCacheControlToMessages, k as normalizeAnthropicInlineContent, m as reconcileAnthropicToolChoice, n as createCompactionCapture, o as applyAnthropicMessageStartUsage, p as projectAnthropicTools, r as isAnthropicReplayRejection, t as buildAnthropicReplayPlan, v as findActiveAnthropicToolTurnAssistantIndex, w as resolveAnthropicFallbackServingModelCost, y as ANTHROPIC_SERVER_SIDE_FALLBACKS } from "./anthropic-compaction-replay-4Zx7-aCr.mjs";
10
+ import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking, u as splitSystemPromptCacheBoundary } from "./simple-options-rdOPzr7Z.mjs";
11
+ import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-CtuS1Upe.mjs";
12
+ import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
13
+ import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-D8nQWCUo.mjs";
11
14
  import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
12
- import { n as parseStreamingJson, t as parseJsonWithRepair } from "./json-parse-CDnesDM_.mjs";
15
+ import { n as parseJsonWithRepair, r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
13
16
  import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
14
- import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-Bv0FHkd0.mjs";
15
- import { t as transformProviderMessages } from "./provider-transcript-transform--gtf0ZbR.mjs";
17
+ import { t as transformProviderMessages } from "./provider-transcript-transform-WvJmFUAf.mjs";
16
18
  import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
17
19
  import Anthropic from "@anthropic-ai/sdk";
18
20
  import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
@@ -109,22 +111,20 @@ const ANTHROPIC_MESSAGE_EVENTS = /* @__PURE__ */ new Set([
109
111
  ]);
110
112
  async function* iterateAnthropicEvents(response, requireMessageStop = false) {
111
113
  if (!response.body) throw new Error("Attempted to iterate over an Anthropic response with no body");
112
- let sawMessageStart = false;
113
114
  let sawMessageEnd = false;
114
115
  for await (const sse of Stream.rawEvents(response)) {
115
116
  if (sse.event === "error") throw new Error(sse.data);
116
117
  if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) continue;
117
118
  try {
118
119
  const event = parseJsonWithRepair(sse.data);
119
- if (event.type === "message_start") sawMessageStart = true;
120
- else if (event.type === "message_stop") sawMessageEnd = true;
120
+ if (event.type === "message_stop") sawMessageEnd = true;
121
121
  yield event;
122
122
  } catch (error) {
123
123
  if (error instanceof SyntaxError) throw new Error(MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, { cause: error });
124
124
  throw error;
125
125
  }
126
126
  }
127
- if ((sawMessageStart || requireMessageStop) && !sawMessageEnd) throw new Error("Anthropic stream ended before message_stop");
127
+ if (requireMessageStop && !sawMessageEnd) throw new Error("Anthropic stream ended before message_stop");
128
128
  }
129
129
  const streamAnthropic = (model, context, options) => {
130
130
  const stream = new AssistantMessageEventStream();
@@ -205,9 +205,11 @@ const streamAnthropic = (model, context, options) => {
205
205
  });
206
206
  const blocks = output.content;
207
207
  const blockIndexes = /* @__PURE__ */ new Map();
208
+ const toolArgumentPreviewSchedules = /* @__PURE__ */ new WeakMap();
208
209
  const sealedToolCalls = [];
209
210
  const compactionCapture = createCompactionCapture(output, model, requestOptions);
210
- for await (const event of iterateAnthropicEvents(response, refusalBuffer !== void 0)) if (event.type === "message_start") {
211
+ const requireMessageStop = refusalBuffer !== void 0 || model.provider === "anthropic" && isAnthropicPublicEndpoint(model.baseUrl);
212
+ for await (const event of iterateAnthropicEvents(response, requireMessageStop)) if (event.type === "message_start") {
211
213
  output.responseId = event.message.id;
212
214
  output.responseModel = event.message.model;
213
215
  messageStartPromptUsage = applyAnthropicMessageStartUsage(output.usage, event.message.usage);
@@ -316,6 +318,7 @@ const streamAnthropic = (model, context, options) => {
316
318
  };
317
319
  output.content.push(block);
318
320
  blockIndexes.set(event.index, output.content.length - 1);
321
+ toolArgumentPreviewSchedules.set(block, createToolArgumentPreviewSchedule());
319
322
  eventSink.push({
320
323
  type: "toolcall_start",
321
324
  contentIndex: output.content.length - 1,
@@ -354,7 +357,7 @@ const streamAnthropic = (model, context, options) => {
354
357
  const block = index === void 0 ? void 0 : blocks[index];
355
358
  if (index !== void 0 && block?.type === "toolCall") {
356
359
  block.partialJson = (block.partialJson ?? "") + event.delta.partial_json;
357
- block.arguments = parseStreamingJson(block.partialJson);
360
+ if (toolArgumentPreviewSchedules.get(block)?.(block.partialJson.length)) block.arguments = parseStreamingJson(block.partialJson);
358
361
  eventSink.push({
359
362
  type: "toolcall_delta",
360
363
  contentIndex: index,
@@ -395,8 +398,10 @@ const streamAnthropic = (model, context, options) => {
395
398
  });
396
399
  }
397
400
  } else if (event.type === "message_delta") {
398
- if (event.delta.stop_reason) if (event.delta.stop_reason === "refusal") applyAnthropicRefusal(output, event.delta.stop_details, model.provider);
399
- else output.stopReason = mapAnthropicStopReason(event.delta.stop_reason);
401
+ if (event.delta.stop_reason) {
402
+ if (event.delta.stop_reason === "refusal") applyAnthropicRefusal(output, event.delta.stop_details, model.provider);
403
+ else output.stopReason = mapAnthropicStopReason(event.delta.stop_reason);
404
+ }
400
405
  if (event.usage) applyAnthropicMessageDeltaUsage(output.usage, event.usage, messageStartPromptUsage);
401
406
  calculateCost(costModel, output.usage);
402
407
  }
@@ -498,9 +503,6 @@ const streamSimpleAnthropic = (model, context, options) => {
498
503
  thinkingBudgetTokens: thinkingEnabled ? adjusted.thinkingBudget : void 0
499
504
  });
500
505
  };
501
- function isOAuthToken(apiKey) {
502
- return getAiTransportHost().resolveSecretSentinel(apiKey).includes("sk-ant-oat");
503
- }
504
506
  function isAnthropicPublicEndpoint(baseUrl) {
505
507
  if (!baseUrl) return true;
506
508
  try {
@@ -577,7 +579,7 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
577
579
  isOAuthToken: false,
578
580
  serverSideFallback: false
579
581
  };
580
- if (isOAuthToken(apiKey)) return {
582
+ if (isAnthropicOAuthApiKey(apiKey)) return {
581
583
  client: new Anthropic({
582
584
  apiKey: null,
583
585
  authToken: apiKey,
@@ -1,13 +1,35 @@
1
- import { o as resolveClaudeFable5ModelIdentity, s as resolveClaudeModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-BQXQudmA.mjs";
2
- import { i as normalizeOptionalLowercaseString, r as normalizeNullableString } from "./string-coerce-fsri9iCu.mjs";
3
- import { n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
4
- import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
5
- import { a as estimateBase64DecodedBytes } from "./provider-error-C8mBRJDl.mjs";
6
- import { r as asNonNegativeFiniteNumber, s as parseStrictPositiveInteger } from "./number-coercion-H9qHik3g.mjs";
1
+ import { l as resolveClaudeFable5ModelIdentity, p as resolveClaudeOpus5ModelIdentity, u as resolveClaudeModelIdentity } from "./src-C8U7lkoa.mjs";
2
+ import { l as normalizeNullableString, o as isRecord, u as normalizeOptionalLowercaseString } from "./utf16-slice-qz3nsy87.mjs";
3
+ import { n as getAiTransportHost } from "./host-BIaiBURL.mjs";
4
+ import { a as asNonNegativeFiniteNumber, n as estimateBase64DecodedBytes } from "./base64-CEFBpSkN.mjs";
7
5
  import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
8
- import { A as splitSystemPromptCacheBoundary, P as sortPromptCacheToolsByName, j as stripSystemPromptCacheBoundary } from "./simple-options-oqsXB6U3.mjs";
9
- import { a as resolveProviderEndpoint, o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-FEr-jOoZ.mjs";
6
+ import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, u as splitSystemPromptCacheBoundary } from "./simple-options-rdOPzr7Z.mjs";
7
+ import { a as resolveProviderEndpoint, o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-BtZiml7r.mjs";
8
+ import { s as parsePositiveInteger } from "./transport-utils-CtuS1Upe.mjs";
10
9
  import { t as shortHash } from "./hash-CHgqbJmD.mjs";
10
+ //#region packages/ai/src/providers/anthropic-auth-headers.ts
11
+ /** Inspect resolved credential shape for auth routing without exposing its value. */
12
+ function isAnthropicOAuthApiKey(apiKey) {
13
+ return typeof apiKey === "string" && getAiTransportHost().resolveSecretSentinel(apiKey).includes("sk-ant-oat");
14
+ }
15
+ function usesFoundryBearerAuth(model) {
16
+ return model.provider === "microsoft-foundry" && (model.authHeader === true || hasBearerAuthorizationHeader(model.headers));
17
+ }
18
+ function hasBearerAuthorizationHeader(headers) {
19
+ if (!headers) return false;
20
+ return Object.entries(headers).some(([key, value]) => key.toLowerCase() === "authorization" && /^bearer\s+\S+/i.test(value.trim()));
21
+ }
22
+ function omitFoundryBearerCredentialHeaders(headers) {
23
+ if (!headers) return;
24
+ const next = {};
25
+ for (const [key, value] of Object.entries(headers)) {
26
+ const lower = key.toLowerCase();
27
+ if (lower === "authorization" || lower === "x-api-key" || lower === "api-key") continue;
28
+ next[key] = value;
29
+ }
30
+ return Object.keys(next).length > 0 ? next : void 0;
31
+ }
32
+ //#endregion
11
33
  //#region packages/ai/src/transports/anthropic-payload-policy.ts
12
34
  /**
13
35
  * Anthropic-family request payload policy helpers.
@@ -16,10 +38,6 @@ import { t as shortHash } from "./hash-CHgqbJmD.mjs";
16
38
  */
17
39
  const ANTHROPIC_CACHE_CONTROL_LIMIT = 4;
18
40
  const ANTHROPIC_COMPACT_THRESHOLD_MIN = 5e4;
19
- function parsePositiveInteger(value) {
20
- if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
21
- return typeof value === "string" ? parseStrictPositiveInteger(value) : void 0;
22
- }
23
41
  /** Resolve the Anthropic input-token trigger, including the API's minimum. */
24
42
  function resolveAnthropicCompactThreshold(contextWindow, configured) {
25
43
  const configuredThreshold = parsePositiveInteger(configured);
@@ -28,11 +46,11 @@ function resolveAnthropicCompactThreshold(contextWindow, configured) {
28
46
  return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, resolvedContextWindow === void 0 ? ANTHROPIC_COMPACT_THRESHOLD_MIN : Math.floor(resolvedContextWindow * .7));
29
47
  }
30
48
  /** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
31
- function resolveAnthropicServerCompactionPlan(model, extraParams) {
49
+ function resolveAnthropicServerCompactionPlan(model, extraParams, apiKey) {
32
50
  const provider = normalizeOptionalLowercaseString(model.provider);
33
51
  const api = normalizeOptionalLowercaseString(model.api);
34
52
  const endpointClass = resolveProviderEndpoint(model).endpointClass;
35
- const enabled = extraParams?.anthropicServerCompaction === true && provider === "anthropic" && api === "anthropic-messages" && (endpointClass === "default" || endpointClass === "anthropic-public");
53
+ const enabled = extraParams?.anthropicServerCompaction === true && !isAnthropicOAuthApiKey(apiKey) && provider === "anthropic" && api === "anthropic-messages" && (endpointClass === "default" || endpointClass === "anthropic-public");
36
54
  return {
37
55
  enabled,
38
56
  ...enabled ? { threshold: resolveAnthropicCompactThreshold(model.contextWindow, extraParams?.anthropicCompactThreshold) } : {}
@@ -222,7 +240,7 @@ const ANTHROPIC_IMAGE_MEDIA_TYPE_SET = /* @__PURE__ */ new Set([
222
240
  "image/gif",
223
241
  "image/webp"
224
242
  ]);
225
- const ANTHROPIC_INLINE_IMAGES_DECODE_SAFETY_BYTES = 64 * 1024 * 1024;
243
+ const ANTHROPIC_INLINE_IMAGES_DECODE_SAFETY_BYTES = 67108864;
226
244
  function createAnthropicInlineImageBudget() {
227
245
  return { totalBytes: 0 };
228
246
  }
@@ -249,25 +267,6 @@ async function normalizeAnthropicInlineContent(content, budget) {
249
267
  return normalized;
250
268
  }
251
269
  //#endregion
252
- //#region packages/ai/src/providers/anthropic-auth-headers.ts
253
- function usesFoundryBearerAuth(model) {
254
- return model.provider === "microsoft-foundry" && (model.authHeader === true || hasBearerAuthorizationHeader(model.headers));
255
- }
256
- function hasBearerAuthorizationHeader(headers) {
257
- if (!headers) return false;
258
- return Object.entries(headers).some(([key, value]) => key.toLowerCase() === "authorization" && /^bearer\s+\S+/i.test(value.trim()));
259
- }
260
- function omitFoundryBearerCredentialHeaders(headers) {
261
- if (!headers) return;
262
- const next = {};
263
- for (const [key, value] of Object.entries(headers)) {
264
- const lower = key.toLowerCase();
265
- if (lower === "authorization" || lower === "x-api-key" || lower === "api-key") continue;
266
- next[key] = value;
267
- }
268
- return Object.keys(next).length > 0 ? next : void 0;
269
- }
270
- //#endregion
271
270
  //#region packages/ai/src/providers/anthropic-refusal.ts
272
271
  function readAnthropicRefusalDetails(value) {
273
272
  if (!value || typeof value !== "object") return {
@@ -836,4 +835,4 @@ function isAnthropicReplayRejection(error) {
836
835
  return (record.status === 400 || text.startsWith("http 400:")) && (text.includes("compaction") || text.includes("context_management"));
837
836
  }
838
837
  //#endregion
839
- export { resolveAnthropicImageMediaType as A, readAnthropicFallbackBoundary as C, usesFoundryBearerAuth as D, omitFoundryBearerCredentialHeaders as E, resolveAnthropicPayloadPolicy as F, resolveAnthropicServerCompactionPlan as I, applyAnthropicEphemeralCacheControlMarkers as M, applyAnthropicPayloadPolicyToParams as N, createAnthropicInlineImageBudget as O, resolveAnthropicEphemeralCacheControl as P, applyAnthropicFallbackBoundary as S, applyAnthropicRefusal as T, ANTHROPIC_OMITTED_REASONING_TEXT as _, applyAnthropicMessageDeltaUsage as a, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as b, readAnthropicPromptUsageSnapshot as c, normalizeAnthropicToolCallId as d, normalizeAnthropicToolChoice as f, toClaudeCodeToolName as g, resolveOriginalAnthropicToolName as h, suppressAnthropicCompaction as i, applyAnthropicCacheControlToMessages as j, normalizeAnthropicInlineContent as k, readAnthropicUsageTokenCount as l, reconcileAnthropicToolChoice as m, createCompactionCapture as n, applyAnthropicMessageStartUsage as o, projectAnthropicTools as p, isAnthropicReplayRejection as r, readAnthropicCacheWriteUsage as s, buildAnthropicReplayPlan as t, readLastAnthropicIterationUsage as u, findActiveAnthropicToolTurnAssistantIndex as v, resolveAnthropicFallbackServingModelCost as w, CLAUDE_OPUS_FALLBACK_MODEL_COST as x, ANTHROPIC_SERVER_SIDE_FALLBACKS as y };
838
+ export { applyAnthropicCacheControlToMessages as A, applyAnthropicFallbackBoundary as C, createAnthropicInlineImageBudget as D, applyAnthropicRefusal as E, resolveAnthropicServerCompactionPlan as F, isAnthropicOAuthApiKey as I, omitFoundryBearerCredentialHeaders as L, applyAnthropicPayloadPolicyToParams as M, resolveAnthropicEphemeralCacheControl as N, normalizeAnthropicInlineContent as O, resolveAnthropicPayloadPolicy as P, usesFoundryBearerAuth as R, CLAUDE_OPUS_FALLBACK_MODEL_COST as S, resolveAnthropicFallbackServingModelCost as T, toClaudeCodeToolName as _, suppressAnthropicCompaction as a, ANTHROPIC_SERVER_SIDE_FALLBACKS as b, readAnthropicCacheWriteUsage as c, readLastAnthropicIterationUsage as d, normalizeAnthropicToolCallId as f, resolveOriginalAnthropicToolName as g, reconcileAnthropicToolChoice as h, resolveNewestAnthropicCompaction as i, applyAnthropicEphemeralCacheControlMarkers as j, resolveAnthropicImageMediaType as k, readAnthropicPromptUsageSnapshot as l, projectAnthropicTools as m, createCompactionCapture as n, applyAnthropicMessageDeltaUsage as o, normalizeAnthropicToolChoice as p, isAnthropicReplayRejection as r, applyAnthropicMessageStartUsage as s, buildAnthropicReplayPlan as t, readAnthropicUsageTokenCount as u, ANTHROPIC_OMITTED_REASONING_TEXT as v, readAnthropicFallbackBoundary as w, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as x, findActiveAnthropicToolTurnAssistantIndex as y };
@@ -1,4 +1,5 @@
1
- import { D as Model } from "./types-DTAP49HF.mjs";
1
+ import "./index-CefaUGSS.mjs";
2
+ import { D as Model } from "./types-Beemor2E.mjs";
2
3
  //#region packages/ai/src/transports/anthropic-payload-policy.d.ts
3
4
  /** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
4
5
  type AnthropicServiceTier = "auto" | "standard_only";
@@ -32,7 +33,7 @@ declare function resolveAnthropicServerCompactionPlan(model: {
32
33
  api?: unknown;
33
34
  baseUrl?: string;
34
35
  contextWindow?: unknown;
35
- }, extraParams?: Record<string, unknown>): {
36
+ }, extraParams?: Record<string, unknown>, apiKey?: string): {
36
37
  enabled: boolean;
37
38
  threshold?: number;
38
39
  };
@@ -1,4 +1,5 @@
1
- import { D as Model, H as StreamFunction, U as StreamOptions, d as Context, n as Api, s as AssistantMessageEventStreamContract, z as SimpleStreamOptions } from "./types-DTAP49HF.mjs";
1
+ import "./index-CefaUGSS.mjs";
2
+ import { D as Model, J as StreamOptions, W as SimpleStreamOptions, d as Context, n as Api, q as StreamFunction, s as AssistantMessageEventStreamContract } from "./types-Beemor2E.mjs";
2
3
  //#region packages/ai/src/api-registry.d.ts
3
4
  /** Runtime stream adapter signature stored in the API provider registry. */
4
5
  type ApiStreamFunction = (model: Model, context: Context, options?: StreamOptions) => AssistantMessageEventStreamContract;
@@ -1,9 +1,9 @@
1
- import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
2
1
  import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
3
- import { n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
2
+ import { n as getAiTransportHost } from "./host-BIaiBURL.mjs";
4
3
  import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
5
- import { n as buildBaseOptions } from "./simple-options-oqsXB6U3.mjs";
6
- import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-Cvt5MgEm.mjs";
4
+ import { n as buildBaseOptions } from "./simple-options-rdOPzr7Z.mjs";
5
+ import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
6
+ import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-CxgdGBvm.mjs";
7
7
  import { i as resolveAzureDeploymentNameFromMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "./azure-openai-responses-client-compat-C7K7QfUE.mjs";
8
8
  import OpenAI, { AzureOpenAI } from "openai";
9
9
  //#region packages/ai/src/providers/azure-openai-responses.ts
@@ -25,10 +25,11 @@ function resolveDeploymentName(model, options) {
25
25
  */
26
26
  const streamAzureOpenAIResponses = (model, context, options) => {
27
27
  const stream = new AssistantMessageEventStream();
28
+ const output = createResponsesAssistantOutput(model, "azure-openai-responses");
28
29
  runResponsesStreamLifecycle({
29
30
  stream,
30
31
  model,
31
- output: createResponsesAssistantOutput(model, "azure-openai-responses"),
32
+ output,
32
33
  options,
33
34
  resolveRequestModel: (requestModel) => {
34
35
  const { baseUrl } = resolveAzureConfig(requestModel, options);
@@ -68,4 +68,76 @@ function parseStrictNonNegativeInteger(value) {
68
68
  return parsed !== void 0 && parsed >= 0 ? parsed : void 0;
69
69
  }
70
70
  //#endregion
71
- export { parseStrictFiniteNumber as a, resolveTimerTimeoutMs as c, clampTimerTimeoutMs as i, asFiniteNumberInRange as n, parseStrictNonNegativeInteger as o, asNonNegativeFiniteNumber as r, parseStrictPositiveInteger as s, asFiniteNumber as t };
71
+ //#region packages/media-core/src/base64.ts
72
+ /** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
73
+ function estimateBase64DecodedBytes(base64) {
74
+ let effectiveLen = 0;
75
+ for (let i = 0; i < base64.length; i += 1) {
76
+ if (base64.charCodeAt(i) <= 32) continue;
77
+ effectiveLen += 1;
78
+ }
79
+ if (effectiveLen === 0) return 0;
80
+ let padding = 0;
81
+ let end = base64.length - 1;
82
+ while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
83
+ if (end >= 0 && base64[end] === "=") {
84
+ padding = 1;
85
+ end -= 1;
86
+ while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
87
+ if (end >= 0 && base64[end] === "=") padding = 2;
88
+ }
89
+ const estimated = Math.floor(effectiveLen * 3 / 4) - padding;
90
+ return Math.max(0, estimated);
91
+ }
92
+ function isBase64DataChar(code) {
93
+ return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47;
94
+ }
95
+ function base64DataValue(code) {
96
+ if (code >= 65 && code <= 90) return code - 65;
97
+ if (code >= 97 && code <= 122) return code - 97 + 26;
98
+ if (code >= 48 && code <= 57) return code - 48 + 52;
99
+ return code === 43 ? 62 : 63;
100
+ }
101
+ /**
102
+ * Normalizes and validates a base64 string, returning canonical no-whitespace
103
+ * base64 only when the input has valid alphabet, padding, and length.
104
+ */
105
+ function canonicalizeBase64(base64) {
106
+ let out;
107
+ let outLen = 0;
108
+ let padding = 0;
109
+ let sawPadding = false;
110
+ let lastDataCode = 0;
111
+ for (let i = 0; i < base64.length; i += 1) {
112
+ const code = base64.charCodeAt(i);
113
+ if (code <= 32) {
114
+ if (out === void 0) {
115
+ out = Buffer.allocUnsafe(base64.length - 1);
116
+ for (let j = 0; j < i; j += 1) out[j] = base64.charCodeAt(j);
117
+ outLen = i;
118
+ }
119
+ continue;
120
+ }
121
+ if (code === 61) {
122
+ padding += 1;
123
+ if (padding > 2) return;
124
+ sawPadding = true;
125
+ } else if (sawPadding || !isBase64DataChar(code)) return;
126
+ else lastDataCode = code;
127
+ if (out !== void 0) {
128
+ out[outLen] = code;
129
+ outLen += 1;
130
+ }
131
+ }
132
+ const cleanedLength = out === void 0 ? base64.length : outLen;
133
+ if (cleanedLength === 0) return;
134
+ const remainder = cleanedLength % 4;
135
+ if (remainder !== 0 && (sawPadding || remainder === 1)) return;
136
+ const effectivePadding = remainder === 0 ? padding : 4 - remainder;
137
+ const padBitMask = effectivePadding === 2 ? 15 : effectivePadding === 1 ? 3 : 0;
138
+ if (padBitMask !== 0 && (base64DataValue(lastDataCode) & padBitMask) !== 0) return;
139
+ const cleaned = out === void 0 ? base64 : out.subarray(0, outLen).toString("latin1");
140
+ return remainder === 0 ? cleaned : cleaned + "=".repeat(4 - remainder);
141
+ }
142
+ //#endregion
143
+ export { asNonNegativeFiniteNumber as a, parseStrictNonNegativeInteger as c, asFiniteNumberInRange as i, parseStrictPositiveInteger as l, estimateBase64DecodedBytes as n, clampTimerTimeoutMs as o, asFiniteNumber as r, parseStrictFiniteNumber as s, canonicalizeBase64 as t, resolveTimerTimeoutMs as u };
@@ -1,6 +1,5 @@
1
1
  import { a as extractDiagnosticError, i as createAssistantMessageDiagnostic, n as DiagnosticErrorInfo, o as formatThrownValue, r as appendAssistantMessageDiagnostic, t as AssistantMessageDiagnostic } from "./diagnostics-BaTA9eVl.mjs";
2
2
  import { n as ProviderErrorRedactor, r as configureProviderErrorRedactor } from "./provider-error-CzNw4BWX.mjs";
3
-
4
3
  //#region packages/ai/src/utils/credential-redaction.d.ts
5
4
  type DiagnosticMediaField = {
6
5
  kind: "context";
@@ -17,9 +16,9 @@ type DiagnosticProjectionPolicy = {
17
16
  kind: "redacted";
18
17
  }>) => Record<string, unknown>;
19
18
  };
20
- declare function projectDiagnosticValue(value: unknown, policy?: DiagnosticProjectionPolicy, seen?: WeakSet<object>, mediaPayload?: boolean, state?: {
19
+ export declare function projectDiagnosticValue(value: unknown, policy?: DiagnosticProjectionPolicy, seen?: WeakSet<object>, mediaPayload?: boolean, state?: {
21
20
  changed: boolean;
22
21
  nodesRemaining: number;
23
22
  }): unknown;
24
23
  //#endregion
25
- export { AssistantMessageDiagnostic, DiagnosticErrorInfo, type DiagnosticProjectionPolicy, type ProviderErrorRedactor, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue, projectDiagnosticValue };
24
+ export { AssistantMessageDiagnostic, DiagnosticErrorInfo, type DiagnosticProjectionPolicy, type ProviderErrorRedactor, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue };
@@ -1,3 +1,3 @@
1
1
  import { i as formatThrownValue, n as createAssistantMessageDiagnostic, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-COpOtRwq.mjs";
2
- import { r as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-C8mBRJDl.mjs";
2
+ import { r as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-BI8kIViN.mjs";
3
3
  export { appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue, projectDiagnosticValue };
@@ -1,17 +1,4 @@
1
- import { createRequire } from "node:module";
2
- //#region \0rolldown/runtime.js
3
- var __defProp = Object.defineProperty;
4
- var __exportAll = (all, no_symbols) => {
5
- let target = {};
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
- return target;
12
- };
13
- var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
14
- //#endregion
1
+ import { n as __require } from "./rolldown-runtime-BhDjJH2R.mjs";
15
2
  //#region packages/ai/src/env-api-keys.ts
16
3
  let existsSync = null;
17
4
  let homedir = null;
@@ -169,4 +156,4 @@ function getEnvApiKey(provider) {
169
156
  }
170
157
  }
171
158
  //#endregion
172
- export { getEnvApiKey as n, __exportAll as r, findEnvKeys as t };
159
+ export { getEnvApiKey as n, findEnvKeys as t };
@@ -1,5 +1,4 @@
1
- import { a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-DTAP49HF.mjs";
2
-
1
+ import { a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-Beemor2E.mjs";
3
2
  //#region packages/llm-core/src/utils/event-stream.d.ts
4
3
  /** Generic async-iterable event stream with a separately awaited final result. */
5
4
  declare class EventStream<T, R = T> implements AsyncIterable<T> {
@@ -0,0 +1 @@
1
+ import "./event-stream-DcvAPSBe.mjs";
@@ -1,2 +1,3 @@
1
- import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-D91-ohD_.mjs";
1
+ import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-DcvAPSBe.mjs";
2
+ import "./event-stream-pXT3FI6X.mjs";
2
3
  export { AssistantMessageEventStream, EventStream, createAssistantMessageEventStream };
@@ -1,17 +1,18 @@
1
- import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
2
1
  import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
3
- import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-DF_yxOsA.mjs";
4
- import { n as buildBaseOptions } from "./simple-options-oqsXB6U3.mjs";
5
- import { i as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-M1dl64nz.mjs";
2
+ import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-BIaiBURL.mjs";
3
+ import { n as buildBaseOptions } from "./simple-options-rdOPzr7Z.mjs";
4
+ import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
5
+ import { i as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-Bnqni5j3.mjs";
6
6
  import { GoogleGenAI } from "@google/genai";
7
7
  //#region packages/ai/src/providers/google.ts
8
8
  let toolCallCounter = 0;
9
9
  const streamGoogle = (model, context, options) => {
10
10
  const stream = new AssistantMessageEventStream();
11
+ const output = createGoogleAssistantOutput(model, "google-generative-ai");
11
12
  runGoogleGenerateContentLifecycle({
12
13
  stream,
13
14
  model,
14
- output: createGoogleAssistantOutput(model, "google-generative-ai"),
15
+ output,
15
16
  options,
16
17
  createClient: () => {
17
18
  return createClient(model, options?.apiKey || getEnvApiKey(model.provider) || "", options?.headers);
@@ -43,8 +44,9 @@ function createClient(model, apiKey, optionsHeaders) {
43
44
  ...model.headers,
44
45
  ...optionsHeaders
45
46
  });
47
+ const resolvedApiKey = apiKey ? getAiTransportHost().resolveSecretSentinel(apiKey) : void 0;
46
48
  return new GoogleGenAI({
47
- apiKey: apiKey ? getAiTransportHost().resolveSecretSentinel(apiKey) : void 0,
49
+ apiKey: resolvedApiKey,
48
50
  httpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : void 0
49
51
  });
50
52
  }
@@ -1,13 +1,15 @@
1
- import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-BP7HLLZn.mjs";
2
- import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload } from "./host-DF_yxOsA.mjs";
3
- import { P as sortPromptCacheToolsByName, _ as notifyProviderStreamOpened, a as assignTransportErrorDetails, j as stripSystemPromptCacheBoundary, o as coerceTransportToolCallArguments, x as transportAbortError } from "./simple-options-oqsXB6U3.mjs";
1
+ import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-S6binQG-.mjs";
2
+ import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload } from "./host-BIaiBURL.mjs";
3
+ import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName } from "./simple-options-rdOPzr7Z.mjs";
4
+ import { _ as transportAbortError, n as coerceTransportToolCallArguments, p as notifyProviderStreamOpened, t as assignTransportErrorDetails } from "./transport-stream-shared-D8nQWCUo.mjs";
4
5
  import { t as googleFlashSupportsMinimalThinking } from "./google-thinking-level-C-V3tecN.mjs";
5
- import { t as transformProviderMessages } from "./provider-transcript-transform--gtf0ZbR.mjs";
6
+ import { t as transformProviderMessages } from "./provider-transcript-transform-WvJmFUAf.mjs";
6
7
  import { FinishReason, FunctionCallingConfigMode, ThinkingLevel } from "@google/genai";
7
8
  //#region packages/ai/src/providers/google-shared.ts
8
9
  /**
9
10
  * Shared utilities for Google Generative AI and Google Vertex providers.
10
11
  */
12
+ const GOOGLE_MODEL_RESOURCE_PREFIX = /^(?:(?:projects\/[^/]+\/locations\/[^/]+\/)?publishers\/google\/models\/|google\/|models\/)/u;
11
13
  /**
12
14
  * Determines whether a streamed Gemini `Part` should be treated as "thinking".
13
15
  *
@@ -83,6 +85,7 @@ function convertMessages(model, context) {
83
85
  const transformedMessages = transformProviderMessages(context.messages, model, normalizeToolCallId);
84
86
  const requiresToolCallThoughtSignature = model.provider !== "google-gemini-cli" && (isGemini3ProModel(model) || isGemini3FlashModel(model));
85
87
  const pendingToolResultImageTurns = [];
88
+ const sameRouteToolCallIds = /* @__PURE__ */ new Set();
86
89
  let activeToolResultParts;
87
90
  const flushToolResultRun = () => {
88
91
  contents.push(...pendingToolResultImageTurns);
@@ -91,25 +94,26 @@ function convertMessages(model, context) {
91
94
  };
92
95
  for (const msg of transformedMessages) {
93
96
  if (msg.role !== "toolResult") flushToolResultRun();
94
- if (msg.role === "user") if (typeof msg.content === "string") contents.push({
95
- role: "user",
96
- parts: [{ text: sanitizeSurrogates(msg.content) || " " }]
97
- });
98
- else {
99
- const parts = msg.content.map((item) => {
100
- if (item.type === "text") return { text: sanitizeSurrogates(item.text) || " " };
101
- return { inlineData: {
102
- mimeType: item.mimeType,
103
- data: item.data
104
- } };
105
- });
106
- if (parts.length === 0) parts.push({ text: " " });
107
- contents.push({
97
+ if (msg.role === "user") {
98
+ if (typeof msg.content === "string") contents.push({
108
99
  role: "user",
109
- parts
100
+ parts: [{ text: sanitizeSurrogates(msg.content) || " " }]
110
101
  });
111
- }
112
- else if (msg.role === "assistant") {
102
+ else {
103
+ const parts = msg.content.map((item) => {
104
+ if (item.type === "text") return { text: sanitizeSurrogates(item.text) || " " };
105
+ return { inlineData: {
106
+ mimeType: item.mimeType,
107
+ data: item.data
108
+ } };
109
+ });
110
+ if (parts.length === 0) parts.push({ text: " " });
111
+ contents.push({
112
+ role: "user",
113
+ parts
114
+ });
115
+ }
116
+ } else if (msg.role === "assistant") {
113
117
  const parts = [];
114
118
  let sawFunctionCall = false;
115
119
  const isSameProviderAndModel = msg.provider === model.provider && msg.api === model.api && msg.model === model.id;
@@ -130,6 +134,7 @@ function convertMessages(model, context) {
130
134
  });
131
135
  else parts.push({ text: sanitizeSurrogates(block.thinking) });
132
136
  } else if (block.type === "toolCall") {
137
+ if (isSameProviderAndModel && model.provider !== "google-gemini-cli") sameRouteToolCallIds.add(block.id);
133
138
  const args = coerceTransportToolCallArguments(block.arguments);
134
139
  const thoughtSignature = resolveThoughtSignature(isSameProviderAndModel, block.thoughtSignature) ?? (!sawFunctionCall && requiresToolCallThoughtSignature ? "skip_thought_signature_validator" : void 0);
135
140
  sawFunctionCall = true;
@@ -137,7 +142,7 @@ function convertMessages(model, context) {
137
142
  functionCall: {
138
143
  name: block.name,
139
144
  args,
140
- ...requiresToolCallId(model.id) ? { id: block.id } : {}
145
+ ...sameRouteToolCallIds.has(block.id) || requiresToolCallId(model.id) ? { id: block.id } : {}
141
146
  },
142
147
  ...thoughtSignature && { thoughtSignature }
143
148
  };
@@ -160,7 +165,7 @@ function convertMessages(model, context) {
160
165
  mimeType: imageBlock.mimeType,
161
166
  data: imageBlock.data
162
167
  } }));
163
- const includeId = requiresToolCallId(model.id);
168
+ const includeId = sameRouteToolCallIds.has(msg.toolCallId) || requiresToolCallId(model.id);
164
169
  const functionResponsePart = { functionResponse: {
165
170
  name: msg.toolName,
166
171
  response: msg.isError ? { error: responseValue } : { output: responseValue },
@@ -261,7 +266,8 @@ async function runGoogleGenerateContentLifecycle(params) {
261
266
  });
262
267
  } catch (error) {
263
268
  for (const block of output.content) if ("index" in block) delete block.index;
264
- assignTransportErrorDetails(output, options?.signal?.aborted ? transportAbortError(options.signal) : error, options?.signal);
269
+ const failure = options?.signal?.aborted ? transportAbortError(options.signal) : error;
270
+ assignTransportErrorDetails(output, failure, options?.signal);
265
271
  stream.push({
266
272
  type: "error",
267
273
  reason: output.stopReason === "aborted" ? "aborted" : "error",
@@ -410,6 +416,7 @@ function mapStopReason(reason) {
410
416
  case FinishReason.OTHER:
411
417
  case FinishReason.LANGUAGE:
412
418
  case FinishReason.MALFORMED_FUNCTION_CALL:
419
+ case FinishReason.TOO_MANY_TOOL_CALLS:
413
420
  case FinishReason.UNEXPECTED_TOOL_CALL:
414
421
  case FinishReason.NO_IMAGE: return "error";
415
422
  default: throw new Error(`Unhandled stop reason: ${String(reason)}`);
@@ -453,6 +460,8 @@ async function consumeGoogleGenerateContentStream(params) {
453
460
  };
454
461
  for await (const chunk of params.chunks) {
455
462
  params.output.responseId ||= chunk.responseId;
463
+ const responseModel = chunk.modelVersion?.trim();
464
+ if (responseModel && params.model.id.replace(GOOGLE_MODEL_RESOURCE_PREFIX, "") !== responseModel.replace(GOOGLE_MODEL_RESOURCE_PREFIX, "")) params.output.responseModel ||= responseModel;
456
465
  if (chunk.usageMetadata) {
457
466
  for (const field of Object.keys(knownUsage)) {
458
467
  const value = chunk.usageMetadata[field];
@@ -588,7 +597,7 @@ async function consumeGoogleGenerateContentStream(params) {
588
597
  });
589
598
  }
590
599
  }
591
- if (candidate?.finishReason) {
600
+ if (candidate?.finishReason && candidate.finishReason !== FinishReason.FINISH_REASON_UNSPECIFIED) {
592
601
  sawTerminalReason = true;
593
602
  params.output.stopReason = mapStopReason(candidate.finishReason);
594
603
  if (params.output.stopReason === "error") {