@openclaw/ai 2026.10.2 → 2026.10.5-beta.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 (108) hide show
  1. package/README.md +6 -0
  2. package/dist/{anthropic-C4qygbtf.mjs → anthropic-BalhAzs-.mjs} +33 -63
  3. package/dist/{anthropic-payload-policy-DD7vzpxE.d.mts → anthropic-payload-policy-DGblkHL5.d.mts} +19 -19
  4. package/dist/{anthropic-stream-reducer-CWyWE21W.mjs → anthropic-stream-reducer-DkKeXXx4.mjs} +215 -297
  5. package/dist/{api-registry-B3rC2qu3.d.mts → api-registry-BhXXYdRA.d.mts} +2 -2
  6. package/dist/assistant-message-events-CHMJgbhs.mjs +18 -0
  7. package/dist/{assistant-output-D5762GPH.mjs → assistant-output-BuhRpLeD.mjs} +2 -2
  8. package/dist/{assistant-text-phase-DVZOxbuR.mjs → assistant-text-phase-Bn1hbvK9.mjs} +7 -6
  9. package/dist/{azure-openai-responses-DO-Fv8ha.mjs → azure-openai-responses-DfT9Ndd8.mjs} +8 -9
  10. package/dist/{credential-redaction-BKv49aiv.d.mts → credential-redaction-BHxruEH6.d.mts} +3 -1
  11. package/dist/{diagnostics-Caj-4RBA.mjs → diagnostics-tQasYct1.mjs} +10 -3
  12. package/dist/diagnostics.d.mts +7 -7
  13. package/dist/diagnostics.mjs +3 -3
  14. package/dist/{env-api-keys-CyX4VKGO.mjs → env-api-keys-CrxwdylR.mjs} +24 -35
  15. package/dist/event-stream-6UNs-AhN.d.mts +1 -0
  16. package/dist/{event-stream-DrRM_90c.d.mts → event-stream-BcqWLo_u.d.mts} +1 -1
  17. package/dist/{event-stream-C5AbCAaZ.mjs → event-stream-X2gmsUWv.mjs} +5 -8
  18. package/dist/event-stream.d.mts +2 -2
  19. package/dist/event-stream.mjs +1 -1
  20. package/dist/{google-interactions-DNXzPPwQ.mjs → google-interactions-9SSqsJg9.mjs} +52 -84
  21. package/dist/{google-messages-l7wgIF5I.mjs → google-messages-DsB7fmoQ.mjs} +26 -35
  22. package/dist/google-provider-stream-CcEI2-MC.mjs +58 -0
  23. package/dist/google-sYI2wnY6.mjs +20 -0
  24. package/dist/{google-shared-V8jogVPq.mjs → google-shared-zGR0QUyS.mjs} +6 -15
  25. package/dist/google-vertex-Dw_abY1w.mjs +40 -0
  26. package/dist/{host-u3o8XiAp.mjs → host-Bf3NjYNj.mjs} +3 -2
  27. package/dist/{host-DiPhRjrc.d.mts → host-CTDz7LXD.d.mts} +6 -3
  28. package/dist/{host-policy-BwhNNGQR.mjs → host-policy-BzZluO6_.mjs} +1 -1
  29. package/dist/{index-D27wAoOr.d.mts → index-BYDvopUB.d.mts} +8 -7
  30. package/dist/index.d.mts +7 -7
  31. package/dist/index.mjs +7 -6
  32. package/dist/internal/anthropic.d.mts +5 -5
  33. package/dist/internal/anthropic.mjs +4 -4
  34. package/dist/internal/openai-completions-compat.d.mts +1 -1
  35. package/dist/internal/openai-completions-compat.mjs +1 -1
  36. package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
  37. package/dist/internal/openai-responses-payload-policy.mjs +2 -3
  38. package/dist/internal/openai.d.mts +9 -9
  39. package/dist/internal/openai.mjs +9 -11
  40. package/dist/internal/runtime.d.mts +31 -13
  41. package/dist/internal/runtime.mjs +10 -13
  42. package/dist/internal/shared.d.mts +5 -5
  43. package/dist/internal/shared.mjs +6 -7
  44. package/dist/internal/tool-schema.mjs +2 -2
  45. package/dist/{llm-request-activity-D8f_oxHj.mjs → llm-request-activity-CfMuh5cC.mjs} +2 -2
  46. package/dist/{mistral-cnoBDSIg.mjs → mistral-dCDCR5ur.mjs} +71 -146
  47. package/dist/{model-transport-url-C5f59L3Y.d.mts → model-transport-url-BrsjjdjR.d.mts} +5 -1
  48. package/dist/{number-coercion-V8-BhME4.mjs → number-coercion-C3hztWoY.mjs} +5 -4
  49. package/dist/{openai-chatgpt-responses-CHdn8YJ_.mjs → openai-chatgpt-responses-V4iP0dv5.mjs} +118 -194
  50. package/dist/{openai-completions-BZfHIaZ7.mjs → openai-completions-BY-kr5IS.mjs} +7 -6
  51. package/dist/{openai-completions-compat-GMN8A0fm.mjs → openai-completions-compat-CYX18uDk.mjs} +10 -6
  52. package/dist/{openai-completions-compat-BgPg1BRs.d.mts → openai-completions-compat-i-nLZxFy.d.mts} +10 -11
  53. package/dist/{openai-completions-transport-CuoQfnKV.mjs → openai-completions-transport-v38m71Oq.mjs} +1449 -294
  54. package/dist/{openai-prompt-cache-CFviG_D4.d.mts → openai-prompt-cache-DIPMrMFy.d.mts} +2 -2
  55. package/dist/{openai-prompt-cache-BK6E2g4Q.mjs → openai-prompt-cache-r93BJhjm.mjs} +1 -1
  56. package/dist/{openai-responses-BhAZFsL9.mjs → openai-responses-D5oiAUOG.mjs} +9 -10
  57. package/dist/{openai-responses-compaction-replay-BBNo098-.d.mts → openai-responses-compaction-replay-B2FE4Nw8.d.mts} +4 -4
  58. package/dist/{openai-responses-contracts-D5yVZBp-.d.mts → openai-responses-contracts-DKqMJ1Ct.d.mts} +9 -4
  59. package/dist/{openai-responses-contracts-BKu8O7l4.mjs → openai-responses-contracts-DlKMMTxK.mjs} +26 -6
  60. package/dist/{openai-responses-compaction-window-tA4QkU0o.mjs → openai-responses-endpoint-CinGh4VZ.mjs} +17 -7
  61. package/dist/{openai-responses-payload-policy-s1apQlZZ.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +2 -4
  62. package/dist/{openai-responses-prompt-observer-internal-CefUzh8M.mjs → openai-responses-request-lifecycle-NSIJo9jY.mjs} +39 -4
  63. package/dist/{openai-responses-shared-CKNmC3vC.mjs → openai-responses-shared-D-aDYAkJ.mjs} +1037 -328
  64. package/dist/{openai-responses-terminal-usage-CempLedn.d.mts → openai-responses-terminal-usage-BygjiAdi.d.mts} +2 -2
  65. package/dist/{openai-tool-schema-BIrI0mrA.mjs → openai-tool-schema-DDPXsvJP.mjs} +220 -400
  66. package/dist/{positive-integer-CwLi8LUL.mjs → positive-integer-CqWjqSi9.mjs} +1 -1
  67. package/dist/{provider-error-DQBE1bUQ.mjs → provider-error-CF9GWCs2.mjs} +5 -3
  68. package/dist/{provider-options-CkieKvNJ.d.mts → provider-options-CVrXZBtA.d.mts} +6 -10
  69. package/dist/{provider-transport-turn-state-BX6TfCyW.mjs → provider-transport-turn-state-BOpxgm-J.mjs} +2 -2
  70. package/dist/{provider-types-v3bmqsfg.d.mts → provider-types-CHtRx0dI.d.mts} +3 -3
  71. package/dist/provider-types.d.mts +6 -6
  72. package/dist/providers.d.mts +2 -2
  73. package/dist/providers.mjs +12 -12
  74. package/dist/{reasoning-tag-text-partitioner-Ju9VpUGl.mjs → reasoning-tag-text-partitioner-CpOy9-IQ.mjs} +374 -235
  75. package/dist/{required-api-key-D4kn3252.mjs → required-api-key-CFJvcFy_.mjs} +1 -1
  76. package/dist/{simple-options-7QuSKriJ.mjs → simple-options-BAu4B54D.mjs} +9 -11
  77. package/dist/{src-VWy9E7DZ.mjs → src-C44MKrW5.mjs} +20 -9
  78. package/dist/{stream-DFaRxi2D.mjs → stream-Dd8DwRFL.mjs} +12 -21
  79. package/dist/{stream-first-event-timeout-D9ZmL_s9.mjs → stream-first-event-timeout-Dc42hKv6.mjs} +8 -21
  80. package/dist/{streaming-byte-guard-CC-HMn_u.mjs → streaming-byte-guard-DBXr1XYn.mjs} +16 -1
  81. package/dist/{string-normalization-PN10hf6d.mjs → string-normalization-I3ux50s9.mjs} +1 -1
  82. package/dist/{text-signature-D_vRrx-z.mjs → text-signature-Drb4Erb8.mjs} +32 -5
  83. package/dist/{tool-schema-json-projection-Ct8SeBeJ.mjs → tool-schema-json-projection-B8sG1I9v.mjs} +29 -23
  84. package/dist/{transport-stream-shared-DW-7-qLR.d.mts → transport-stream-shared-BmpzDtdQ.d.mts} +4 -4
  85. package/dist/{transport-stream-shared-CCR7hSW0.mjs → transport-stream-shared-CWGOuLcA.mjs} +8 -16
  86. package/dist/transports.d.mts +34 -23
  87. package/dist/transports.mjs +76 -1235
  88. package/dist/{types-DvzmWW8J.d.mts → types-Bd2T86VJ.d.mts} +5 -23
  89. package/dist/types-Kdfw_04V.d.mts +1 -0
  90. package/dist/types.d.mts +6 -6
  91. package/dist/types.mjs +5 -4
  92. package/dist/{validation-B3lQt_VE.d.mts → validation-DdGB1yy3.d.mts} +1 -1
  93. package/dist/{validation-DbqlIfDn.mjs → validation-ZX_sPVV0.mjs} +3 -9
  94. package/dist/validation.d.mts +1 -1
  95. package/dist/validation.mjs +1 -1
  96. package/package.json +4 -9
  97. package/dist/env-api-keys-BR0MUYYD.d.mts +0 -17
  98. package/dist/event-stream-DqDQWqiy.d.mts +0 -1
  99. package/dist/google-B2g_Xn4d.mjs +0 -54
  100. package/dist/google-vertex-_khoip47.mjs +0 -88
  101. package/dist/internal/env-api-keys.d.mts +0 -2
  102. package/dist/internal/env-api-keys.mjs +0 -2
  103. package/dist/openai-responses-endpoint-TV0y50fb.mjs +0 -11
  104. package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +0 -36
  105. package/dist/openai-transport-params-D7JMUPjf.mjs +0 -735
  106. package/dist/openai-web-search-tools-Cfu0uLyN.mjs +0 -14
  107. package/dist/provider-replay-context-CO_Eplnc.mjs +0 -25
  108. package/dist/types-UlNana-2.d.mts +0 -1
@@ -1,4 +1,4 @@
1
- import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
1
+ import { n as getEnvApiKey } from "./env-api-keys-CrxwdylR.mjs";
2
2
  //#region packages/ai/src/utils/required-api-key.ts
3
3
  function requireApiKey(provider, apiKey) {
4
4
  const resolved = apiKey || getEnvApiKey(provider);
@@ -1,9 +1,9 @@
1
1
  import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
2
2
  import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-CtgOVOSv.mjs";
3
- import { M as hasMediaPayload, r as getAiTransportHost } from "./host-u3o8XiAp.mjs";
4
- import { g as responsesServiceTierObserver } from "./openai-responses-contracts-BKu8O7l4.mjs";
5
- import { o as truncateUtf16Safe } from "./provider-error-DQBE1bUQ.mjs";
6
- import { P as sanitizeSurrogates, i as copyProviderAcceptanceObserver } from "./transport-stream-shared-CCR7hSW0.mjs";
3
+ import { M as hasMediaPayload, r as getAiTransportHost } from "./host-Bf3NjYNj.mjs";
4
+ import { g as responsesServiceTierObserver } from "./openai-responses-contracts-DlKMMTxK.mjs";
5
+ import { s as truncateUtf16Safe } from "./provider-error-CF9GWCs2.mjs";
6
+ import { P as sanitizeSurrogates, i as copyProviderAcceptanceObserver } from "./transport-stream-shared-CWGOuLcA.mjs";
7
7
  //#region packages/ai/src/utils/prompt-cache-stability.ts
8
8
  /**
9
9
  * Prompt-cache normalization helpers. They keep generated prompt sections
@@ -114,10 +114,6 @@ function isBinaryMimeType(mimeType) {
114
114
  const normalized = mimeType.split(";", 1)[0]?.trim().toLowerCase();
115
115
  return normalized ? !TEXTUAL_MIME_PATTERN.test(normalized) : false;
116
116
  }
117
- function describeOmittedValue(value, label) {
118
- const length = typeof value === "string" ? value.length : JSON.stringify(value)?.length;
119
- return length ? `[${label} omitted: ${length} chars]` : `[${label} omitted]`;
120
- }
121
117
  function redactInlineDataUris(value) {
122
118
  return value.replace(INLINE_DATA_URI_PATTERN, (_match, prefix, uri) => `${prefix}[inline data URI: ${uri.length} chars]`);
123
119
  }
@@ -130,7 +126,10 @@ function stringifyStructuredBlock(block) {
130
126
  if (OPAQUE_OR_BINARY_FIELD_RE.test(key)) return `[omitted ${key}]`;
131
127
  if (key === "data") {
132
128
  const mimeType = readMimeType(this);
133
- if (mimeType && isBinaryMimeType(mimeType)) return describeOmittedValue(value, "binary data");
129
+ if (mimeType && isBinaryMimeType(mimeType)) {
130
+ const length = typeof value === "string" ? value.length : JSON.stringify(value)?.length;
131
+ return length ? `[binary data omitted: ${length} chars]` : "[binary data omitted]";
132
+ }
134
133
  }
135
134
  if (typeof value === "bigint") return value.toString();
136
135
  if (typeof value === "string") return redactInlineDataUris(host.redactModelVisibleSecrets(value));
@@ -257,8 +256,7 @@ const reasoningTagTextPolicy = {
257
256
  const REQUEST_BODY = Symbol("modelRequestBody");
258
257
  /** Call-local state survives option spreads; no payload is cached across requests. */
259
258
  function modelRequestBodyState(options, inheritFrom) {
260
- let state = Reflect.get(options, REQUEST_BODY) ?? (inheritFrom && Reflect.get(inheritFrom, REQUEST_BODY));
261
- if (!state) state = {};
259
+ const state = Reflect.get(options, REQUEST_BODY) ?? (inheritFrom && Reflect.get(inheritFrom, REQUEST_BODY)) ?? {};
262
260
  Reflect.set(options, REQUEST_BODY, state);
263
261
  return state;
264
262
  }
@@ -1,6 +1,12 @@
1
1
  import "./diagnostics-DzrF1h4J.mjs";
2
- import "./validation-DbqlIfDn.mjs";
2
+ import "./validation-ZX_sPVV0.mjs";
3
3
  //#region packages/llm-core/src/model-contracts/anthropic.ts
4
+ function readListedClaudeCapability(ref, capability) {
5
+ const listed = ref.params?.claudeCapabilities;
6
+ if (typeof listed !== "object" || listed === null) return;
7
+ const value = Reflect.get(listed, capability);
8
+ return typeof value === "boolean" ? value : void 0;
9
+ }
4
10
  function normalizeClaudeModelId(modelId) {
5
11
  const normalized = modelId?.trim().toLowerCase() ?? "";
6
12
  return (normalized.startsWith("anthropic/") ? normalized.slice(10) : normalized).replace(/[._\s]+/g, "-");
@@ -82,6 +88,8 @@ function supportsClaudeInHistorySystemMessages(ref) {
82
88
  }
83
89
  /** Return whether a Claude model requires adaptive thinking instead of manual budgets. */
84
90
  function requiresClaudeMandatoryAdaptiveThinking(ref) {
91
+ const disabledThinking = readListedClaudeCapability(ref, "disabledThinking");
92
+ if (disabledThinking !== void 0) return !disabledThinking && !requiresClaudeBetweenToolsThinking(ref) && supportsClaudeAdaptiveThinking(ref);
85
93
  const modelId = resolveClaudeModelIdentity(ref);
86
94
  return resolveClaudeOpus55ModelIdentity(ref) !== void 0 || resolveClaudeFable5ModelIdentity(ref) !== void 0 || resolveClaudeMythos5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-mythos-preview(?=$|[^a-z0-9])/.test(modelId);
87
95
  }
@@ -117,18 +125,17 @@ function resolveClaudeOpus55ModelIdentity(ref) {
117
125
  if (normalized === "opus" || normalized === "opus-5-5") return "claude-opus-5-5";
118
126
  return /^claude-opus-5-5(?=$|[^a-z0-9])/.test(normalized) ? normalized : void 0;
119
127
  }
120
- /** Return whether a Claude model supports adaptive thinking. */
121
- function supportsClaudeAdaptiveThinking(ref) {
128
+ function supportsClaudeAdaptiveThinkingById(ref) {
122
129
  const modelId = resolveClaudeModelIdentity(ref);
123
130
  return resolveClaudeHaiku55ModelIdentity(ref) !== void 0 || resolveClaudeOpus5ModelIdentity(ref) !== void 0 || resolveClaudeSonnet5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-(?:5|preview)|opus-4-(?:6|7|8)|sonnet-4-6)(?=$|[^a-z0-9])/.test(modelId);
124
131
  }
132
+ /** Return whether a Claude model supports adaptive thinking. */
133
+ function supportsClaudeAdaptiveThinking(ref) {
134
+ return readListedClaudeCapability(ref, "adaptiveThinking") ?? supportsClaudeAdaptiveThinkingById(ref);
135
+ }
125
136
  /** Return whether a Claude model has a native 1M-token context window. */
126
137
  function supportsClaude1MContext(ref) {
127
- return supportsClaudeAdaptiveThinking(ref);
128
- }
129
- /** Return whether Anthropic documents threshold compaction (`compact_20260112`) for a Claude model. */
130
- function supportsClaudeServerCompaction(ref) {
131
- return supportsClaudeAdaptiveThinking(ref);
138
+ return supportsClaudeAdaptiveThinkingById(ref);
132
139
  }
133
140
  /** Return whether a Claude model supports Anthropic's native fast mode. */
134
141
  function supportsClaudeFastMode(ref) {
@@ -137,11 +144,15 @@ function supportsClaudeFastMode(ref) {
137
144
  }
138
145
  /** Return whether a Claude model supports native max effort. */
139
146
  function supportsClaudeNativeMaxEffort(ref) {
147
+ const listed = readListedClaudeCapability(ref, "maxEffort");
148
+ if (listed !== void 0) return listed;
140
149
  const modelId = resolveClaudeModelIdentity(ref);
141
150
  return resolveClaudeHaiku55ModelIdentity(ref) !== void 0 || resolveClaudeOpus5ModelIdentity(ref) !== void 0 || resolveClaudeSonnet5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-5|opus-4-(?:6|7|8)|sonnet-4-6)(?=$|[^a-z0-9])/.test(modelId);
142
151
  }
143
152
  /** Return whether a Claude model supports native xhigh effort. */
144
153
  function supportsClaudeNativeXhighEffort(ref) {
154
+ const listed = readListedClaudeCapability(ref, "xhighEffort");
155
+ if (listed !== void 0) return listed;
145
156
  const modelId = resolveClaudeModelIdentity(ref);
146
157
  return resolveClaudeHaiku55ModelIdentity(ref) !== void 0 || resolveClaudeOpus5ModelIdentity(ref) !== void 0 || resolveClaudeSonnet5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-5|opus-4-(?:7|8))(?=$|[^a-z0-9])/.test(modelId);
147
158
  }
@@ -236,4 +247,4 @@ function calculateUsageCost(usage, pricing) {
236
247
  return cost;
237
248
  }
238
249
  //#endregion
239
- export { supportsClaude1MContext as C, supportsClaudeNativeMaxEffort as D, supportsClaudeInHistorySystemMessages as E, supportsClaudeNativeXhighEffort as O, resolveClaudeSonnet5ModelIdentity as S, supportsClaudeFastMode as T, resolveClaudeMythos5ModelIdentity as _, CLAUDE_HAIKU_55_THINKING_PROFILE as a, resolveClaudeOpus5ModelIdentity as b, CLAUDE_SONNET_55_THINKING_PROFILE as c, requiresClaudeBetweenToolsThinking as d, requiresClaudeDefaultSampling as f, resolveClaudeModelIdentity as g, resolveClaudeHaiku55ModelIdentity as h, CLAUDE_FABLE_5_THINKING_PROFILE as i, supportsClaudeServerCompaction as k, CLAUDE_SONNET_5_THINKING_PROFILE as l, resolveClaudeFable5ModelIdentity as m, normalizeModelCostConfig as n, CLAUDE_OPUS_55_THINKING_PROFILE as o, requiresClaudeMandatoryAdaptiveThinking as p, normalizeResolvedPricing as r, CLAUDE_OPUS_5_THINKING_PROFILE as s, calculateUsageCost as t, bindsClaudeThinkingPrefix as u, resolveClaudeNativeThinkingLevelMap as v, supportsClaudeAdaptiveThinking as w, resolveClaudeSonnet55ModelIdentity as x, resolveClaudeOpus55ModelIdentity as y };
250
+ export { supportsClaude1MContext as C, supportsClaudeNativeMaxEffort as D, supportsClaudeInHistorySystemMessages as E, supportsClaudeNativeXhighEffort as O, resolveClaudeSonnet5ModelIdentity as S, supportsClaudeFastMode as T, resolveClaudeMythos5ModelIdentity as _, CLAUDE_HAIKU_55_THINKING_PROFILE as a, resolveClaudeOpus5ModelIdentity as b, CLAUDE_SONNET_55_THINKING_PROFILE as c, requiresClaudeBetweenToolsThinking as d, requiresClaudeDefaultSampling as f, resolveClaudeModelIdentity as g, resolveClaudeHaiku55ModelIdentity as h, CLAUDE_FABLE_5_THINKING_PROFILE as i, CLAUDE_SONNET_5_THINKING_PROFILE as l, resolveClaudeFable5ModelIdentity as m, normalizeModelCostConfig as n, CLAUDE_OPUS_55_THINKING_PROFILE as o, requiresClaudeMandatoryAdaptiveThinking as p, normalizeResolvedPricing as r, CLAUDE_OPUS_5_THINKING_PROFILE as s, calculateUsageCost as t, bindsClaudeThinkingPrefix as u, resolveClaudeNativeThinkingLevelMap as v, supportsClaudeAdaptiveThinking as w, resolveClaudeSonnet55ModelIdentity as x, resolveClaudeOpus55ModelIdentity as y };
@@ -1,5 +1,5 @@
1
- import { i as bindAssistantMessageEventStream, o as getEventStreamCompletion } from "./event-stream-C5AbCAaZ.mjs";
2
- import { i as getDefaultAiTransportHost, n as createAiTransportHost, o as runWithAiTransportHost, s as supportsScopedAiTransportHosts } from "./host-u3o8XiAp.mjs";
1
+ import { i as bindAssistantMessageEventStream, o as getEventStreamCompletion } from "./event-stream-X2gmsUWv.mjs";
2
+ import { i as getDefaultAiTransportHost, n as createAiTransportHost, o as runWithAiTransportHost, s as supportsScopedAiTransportHosts } from "./host-Bf3NjYNj.mjs";
3
3
  import { i as registerSessionResourceCleanupObserver, t as cleanupSessionResources } from "./session-resources-D1wgDQ8C.mjs";
4
4
  //#region packages/ai/src/api-registry.ts
5
5
  function wrapStream(api, stream) {
@@ -47,6 +47,9 @@ function trackDefaultHostSessions(sessions) {
47
47
  defaultHostSessionReferences.add(reference);
48
48
  defaultHostSessionFinalizer.register(sessions, reference, reference);
49
49
  }
50
+ function selectDefaultHostSessions(sessions, sessionId) {
51
+ return sessionId ? [[sessionId, sessions.get(sessionId)]] : sessions;
52
+ }
50
53
  registerSessionResourceCleanupObserver((sessionId, owner) => {
51
54
  for (const reference of defaultHostSessionReferences) {
52
55
  const sessions = reference.deref();
@@ -59,12 +62,7 @@ registerSessionResourceCleanupObserver((sessionId, owner) => {
59
62
  else owners.clear();
60
63
  return owners.size === 0;
61
64
  };
62
- if (sessionId) {
63
- const owners = sessions.get(sessionId);
64
- if (owners && pruneOwners(owners)) sessions.delete(sessionId);
65
- continue;
66
- }
67
- for (const [ownedSessionId, owners] of sessions) if (pruneOwners(owners)) sessions.delete(ownedSessionId);
65
+ for (const [ownedSessionId, owners] of selectDefaultHostSessions(sessions, sessionId)) if (owners && pruneOwners(owners)) sessions.delete(ownedSessionId);
68
66
  }
69
67
  });
70
68
  function retainUnscopedStreamLifetime(stream, runWithHost) {
@@ -90,7 +88,6 @@ function retainUnscopedStreamLifetime(stream, runWithHost) {
90
88
  const bufferWaiters = /* @__PURE__ */ new Set();
91
89
  let bufferError;
92
90
  let resultPromise;
93
- const wrapIterationError = (error) => new Error("Stream iteration failed", { cause: error });
94
91
  const notifyBufferWaiters = () => {
95
92
  for (const resolve of bufferWaiters) resolve();
96
93
  bufferWaiters.clear();
@@ -103,13 +100,11 @@ function retainUnscopedStreamLifetime(stream, runWithHost) {
103
100
  } catch (error) {
104
101
  providerResult = Promise.reject(new Error("Stream result failed", { cause: error }));
105
102
  }
106
- providerResult.then(() => {
103
+ const settleResult = () => {
107
104
  resultSettled = true;
108
105
  releaseIfSettled();
109
- }, () => {
110
- resultSettled = true;
111
- releaseIfSettled();
112
- });
106
+ };
107
+ providerResult.then(settleResult, settleResult);
113
108
  resultPromise = providerResult;
114
109
  }
115
110
  return resultPromise;
@@ -124,7 +119,7 @@ function retainUnscopedStreamLifetime(stream, runWithHost) {
124
119
  notifyBufferWaiters();
125
120
  }
126
121
  } catch (error) {
127
- bufferError = wrapIterationError(error);
122
+ bufferError = new Error("Stream iteration failed", { cause: error });
128
123
  } finally {
129
124
  bufferSettled = true;
130
125
  notifyBufferWaiters();
@@ -202,11 +197,8 @@ function createRuntime(registry, transportHost) {
202
197
  if (completion) {
203
198
  if (!supportsScopedAiTransportHosts()) {
204
199
  let producerSettled = false;
205
- const observedCompletion = completion.then(() => {
206
- producerSettled = true;
207
- }, (error) => {
200
+ const observedCompletion = completion.finally(() => {
208
201
  producerSettled = true;
209
- throw error;
210
202
  });
211
203
  runWithStreamHost(() => observedCompletion);
212
204
  const result = runWithStreamHost(() => started.result());
@@ -240,8 +232,7 @@ function createRuntime(registry, transportHost) {
240
232
  }
241
233
  const usedHosts = /* @__PURE__ */ new Set();
242
234
  if (!explicitHost) {
243
- if (sessionId) for (const host of defaultHostsBySession.get(sessionId) ?? []) usedHosts.add(host);
244
- else for (const owners of defaultHostsBySession.values()) for (const host of owners) usedHosts.add(host);
235
+ for (const [, owners] of selectDefaultHostSessions(defaultHostsBySession, sessionId)) for (const host of owners ?? []) usedHosts.add(host);
245
236
  usedHosts.add(getDefaultAiTransportHost());
246
237
  }
247
238
  const hosts = explicitHost ? [explicitHost] : [...usedHosts];
@@ -1,4 +1,4 @@
1
- import { i as clampTimerTimeoutMs } from "./number-coercion-V8-BhME4.mjs";
1
+ import { a as clampTimerTimeoutMs } from "./number-coercion-C3hztWoY.mjs";
2
2
  //#region packages/ai/src/utils/stream-first-event-timeout.ts
3
3
  function getFirstStreamEventTimeoutMs(options) {
4
4
  return options?.firstEventTimeoutMs;
@@ -46,14 +46,8 @@ function withFirstStreamEventTimeout(stream, context) {
46
46
  const iterator = stream[Symbol.asyncIterator]();
47
47
  let timer;
48
48
  let completed = false;
49
- const clear = () => {
50
- if (timer) {
51
- clearTimeout(timer);
52
- timer = void 0;
53
- }
54
- };
55
49
  try {
56
- const first = await new Promise((resolve, reject) => {
50
+ let next = await new Promise((resolve, reject) => {
57
51
  timer = setTimeout(() => {
58
52
  const timeoutError = createFirstStreamEventTimeoutError(timeoutContext);
59
53
  timeoutContext.onTimeout?.(timeoutError);
@@ -62,22 +56,15 @@ function withFirstStreamEventTimeout(stream, context) {
62
56
  }, timeoutMs);
63
57
  timer.unref?.();
64
58
  iterator.next().then(resolve, reject);
65
- }).finally(clear);
66
- if (first.done) {
67
- completed = true;
68
- return;
69
- }
70
- yield first.value;
71
- for (;;) {
72
- const next = await iterator.next();
73
- if (next.done) {
74
- completed = true;
75
- return;
76
- }
59
+ }).finally(() => {
60
+ if (timer) clearTimeout(timer);
61
+ });
62
+ while (!next.done) {
77
63
  yield next.value;
64
+ next = await iterator.next();
78
65
  }
66
+ completed = true;
79
67
  } finally {
80
- clear();
81
68
  if (!completed) iterator.return?.().catch(() => void 0);
82
69
  }
83
70
  } };
@@ -41,5 +41,20 @@ function createSseByteGuard(reader, opts) {
41
41
  cancelled: () => cancelledFlag
42
42
  };
43
43
  }
44
+ /** Lazily bound an SDK response while preserving upstream cancellation. */
45
+ function boundResponseBody(response, options) {
46
+ if (!response.body || typeof response.body.getReader !== "function") return response;
47
+ const guard = createSseByteGuard(response.body.getReader(), options);
48
+ return new Response(new ReadableStream({
49
+ async pull(controller) {
50
+ const { done, value } = await guard.read();
51
+ if (done) controller.close();
52
+ else controller.enqueue(value);
53
+ },
54
+ async cancel(reason) {
55
+ await guard.cancel(reason);
56
+ }
57
+ }), response);
58
+ }
44
59
  //#endregion
45
- export { createSseByteGuard as t };
60
+ export { createSseByteGuard as n, boundResponseBody as t };
@@ -2,7 +2,7 @@ import { a as normalizeOptionalString } from "./string-coerce-CtgOVOSv.mjs";
2
2
  //#region packages/normalization-core/src/string-normalization.ts
3
3
  /** Coerces entries to strings, trims them, and drops empty results. */
4
4
  function normalizeStringEntries(list) {
5
- return (list ?? []).map((entry) => normalizeOptionalString(String(entry)) ?? "").filter(Boolean);
5
+ return (list ?? []).map((entry) => String(entry).trim()).filter(Boolean);
6
6
  }
7
7
  /** Returns first-seen unique values while preserving insertion order. */
8
8
  function uniqueValues(values) {
@@ -1,8 +1,9 @@
1
- import { r as getAiTransportHost } from "./host-u3o8XiAp.mjs";
2
- import { o as truncateUtf16Safe } from "./provider-error-DQBE1bUQ.mjs";
1
+ import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
2
+ import { r as getAiTransportHost } from "./host-Bf3NjYNj.mjs";
3
+ import { s as truncateUtf16Safe } from "./provider-error-CF9GWCs2.mjs";
3
4
  import "./internal/retry-after.mjs";
4
- import { N as raceWithTimeout } from "./transport-stream-shared-CCR7hSW0.mjs";
5
- import "./positive-integer-CwLi8LUL.mjs";
5
+ import { A as shortHash, N as raceWithTimeout } from "./transport-stream-shared-CWGOuLcA.mjs";
6
+ import "./positive-integer-CqWjqSi9.mjs";
6
7
  //#region packages/normalization-core/src/response-bytes.ts
7
8
  async function consumeResponseBytes(options) {
8
9
  let size = 0;
@@ -31,6 +32,10 @@ async function consumeResponseBytes(options) {
31
32
  const MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE = "OpenClaw transport error: malformed_streaming_fragment";
32
33
  const NON_LATIN_RE = /[\u2E80-\u9FFF\uA000-\uA4FF\uAC00-\uD7AF\uF900-\uFAFF\uFF01-\uFF60\uFFE0-\uFFE6\u{20000}-\u{2FA1F}]/gu;
33
34
  const CJK_SURROGATE_HIGH_RE = /[\uD840-\uD87E][\uDC00-\uDFFF]/g;
35
+ /** Keep provider payloads out of parse errors without replacing unrelated failures. */
36
+ function streamFragmentError(cause, ErrorType = Error) {
37
+ return cause instanceof SyntaxError ? new ErrorType(MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, { cause }) : cause;
38
+ }
34
39
  function redactSensitiveText(text) {
35
40
  return getAiTransportHost().redactToolPayloadText(text);
36
41
  }
@@ -105,6 +110,28 @@ async function readResponseTextSnippet(response, options) {
105
110
  return truncated ? `${collapsed}…` : collapsed;
106
111
  }
107
112
  //#endregion
113
+ //#region packages/ai/src/transports/provider-replay-context.ts
114
+ function isProviderReplayContext(value) {
115
+ return isRecord(value) && typeof value.provider === "string" && typeof value.api === "string" && typeof value.model === "string" && (value.baseUrlHash === void 0 || typeof value.baseUrlHash === "string") && (value.sessionHash === void 0 || typeof value.sessionHash === "string") && (value.authProfileHash === void 0 || typeof value.authProfileHash === "string");
116
+ }
117
+ function hashReplayContextValue(value) {
118
+ const normalized = value?.trim();
119
+ return normalized ? shortHash(normalized) : void 0;
120
+ }
121
+ function buildProviderReplayContext(model, options) {
122
+ return {
123
+ provider: model.provider,
124
+ api: model.api,
125
+ model: model.id,
126
+ baseUrlHash: hashReplayContextValue(model.baseUrl),
127
+ sessionHash: hashReplayContextValue(options?.sessionId),
128
+ authProfileHash: hashReplayContextValue(options?.authProfileId)
129
+ };
130
+ }
131
+ function providerReplayContextMatches(state, context) {
132
+ return state.provider === context.provider && state.api === context.api && state.model === context.model && state.baseUrlHash === context.baseUrlHash && state.sessionHash === context.sessionHash && state.authProfileHash === context.authProfileHash;
133
+ }
134
+ //#endregion
108
135
  //#region packages/ai/src/utils/text-signature.ts
109
136
  function encodeTextSignatureV1(id, phase) {
110
137
  return JSON.stringify({
@@ -114,4 +141,4 @@ function encodeTextSignatureV1(id, phase) {
114
141
  });
115
142
  }
116
143
  //#endregion
117
- export { readResponseTextSnippet as a, supportsModelTools as c, isCodeModeModelVisibleToolName as i, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE as n, redactSensitiveText as o, estimateStringChars as r, resolveModelHeaderSentinels as s, encodeTextSignatureV1 as t };
144
+ export { MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE as a, readResponseTextSnippet as c, streamFragmentError as d, supportsModelTools as f, providerReplayContextMatches as i, redactSensitiveText as l, buildProviderReplayContext as n, estimateStringChars as o, consumeResponseBytes as p, isProviderReplayContext as r, isCodeModeModelVisibleToolName as s, encodeTextSignatureV1 as t, resolveModelHeaderSentinels as u };
@@ -1,4 +1,4 @@
1
- import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
1
+ import { a as asRecord, o as isRecord } from "./record-coerce-CNDovvft.mjs";
2
2
  import { t as expectDefined } from "./expect-lbe3Hgrh.mjs";
3
3
  import { types } from "node:util";
4
4
  //#region packages/ai/src/providers/schema-walk.ts
@@ -33,6 +33,22 @@ const SCHEMA_ARRAY_KEYS = /* @__PURE__ */ new Set([
33
33
  "oneOf",
34
34
  "prefixItems"
35
35
  ]);
36
+ const SCHEMA_NESTED_KEYS = new Set([...SCHEMA_OBJECT_KEYS, ...SCHEMA_ARRAY_KEYS].toSorted());
37
+ function* walkSchemaArray(schemas, visit, result = []) {
38
+ result.length = schemas.length;
39
+ for (let index = 0; index < result.length; index += 1) if (index in schemas) result[index] = yield visit(schemas[index]);
40
+ return result;
41
+ }
42
+ function* walkSchemaValue(schema, ancestors, visitObject) {
43
+ if (!schema || typeof schema !== "object") return schema;
44
+ if (ancestors.has(schema)) throw new TypeError("Tool schema contains a circular reference.");
45
+ ancestors.add(schema);
46
+ try {
47
+ return yield Array.isArray(schema) ? walkSchemaArray(schema, (entry) => walkSchemaValue(entry, ancestors, visitObject)) : visitObject(asRecord(schema));
48
+ } finally {
49
+ ancestors.delete(schema);
50
+ }
51
+ }
36
52
  /** Resume child schema walks on a heap stack, never through recursive yield delegation. */
37
53
  function evaluateSchemaWalk(walk) {
38
54
  const parents = [];
@@ -64,7 +80,7 @@ function isNonFiniteNumberValue(value) {
64
80
  if (value === null || typeof value !== "object" || !types.isNumberObject(value)) return false;
65
81
  return !Number.isFinite(Number.prototype.valueOf.call(value));
66
82
  }
67
- function serializeToolInputSchema(value, path, captureJson) {
83
+ function projectToolInputSchema(value, path, captureJson) {
68
84
  const nonFiniteNumber = { path: null };
69
85
  const ancestors = [];
70
86
  const pathLengths = [];
@@ -102,9 +118,16 @@ function serializeToolInputSchema(value, path, captureJson) {
102
118
  };
103
119
  const schema = JSON.parse(text);
104
120
  captureJson?.(text);
121
+ const violations = [];
122
+ if (!isRecord(schema)) violations.push(`${path} must be a JSON object schema`);
123
+ else if (schema.type !== void 0 && schema.type !== "object") violations.push(`${path}.type must be "object"`);
124
+ if (!inspectJsonSchema(schema, [path], violations)) return {
125
+ schema: {},
126
+ violations: [`${path} is not a JSON value`]
127
+ };
105
128
  return {
106
129
  schema,
107
- violations: []
130
+ violations
108
131
  };
109
132
  }
110
133
  function inspectJsonSchema(schema, path, violations) {
@@ -120,14 +143,11 @@ function inspectJsonSchema(schema, path, violations) {
120
143
  }
121
144
  if (!isRecord(schema)) return typeof schema !== "number" || Number.isFinite(schema);
122
145
  for (const key of ["$dynamicRef", "$dynamicAnchor"]) if (key in schema) violations.push(`${path.join("")}.${key}`);
123
- for (const key of Object.keys(schema)) {
124
- const value = schema[key];
146
+ for (const [key, value] of Object.entries(schema)) {
125
147
  if (typeof value === "number" && !Number.isFinite(value)) return false;
126
148
  if (!value || typeof value !== "object") continue;
127
149
  path.push(".", key);
128
- if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const schemaName of Object.keys(value)) {
129
- const childSchema = value[schemaName];
130
- if (childSchema === void 0) return false;
150
+ if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const [schemaName, childSchema] of Object.entries(value)) {
131
151
  path.push(".", schemaName);
132
152
  const valid = inspectJsonSchema(childSchema, path, violations);
133
153
  path.length -= 2;
@@ -156,19 +176,5 @@ function prepareRuntimeToolInputSchema(schema, path) {
156
176
  } } : {}
157
177
  };
158
178
  }
159
- function projectToolInputSchema(schema, path, captureJson) {
160
- const projection = serializeToolInputSchema(schema, path, captureJson);
161
- const violations = [...projection.violations];
162
- if (!isRecord(projection.schema)) violations.push(`${path} must be a JSON object schema`);
163
- else if (projection.schema.type !== void 0 && projection.schema.type !== "object") violations.push(`${path}.type must be "object"`);
164
- if (!inspectJsonSchema(projection.schema, [path], violations)) return {
165
- schema: {},
166
- violations: [`${path} is not a JSON value`]
167
- };
168
- return {
169
- schema: projection.schema,
170
- violations
171
- };
172
- }
173
179
  //#endregion
174
- export { SCHEMA_OBJECT_KEYS as a, SCHEMA_MAP_KEYS as i, projectRuntimeToolInputSchema as n, evaluateSchemaWalk as o, SCHEMA_ARRAY_KEYS as r, prepareRuntimeToolInputSchema as t };
180
+ export { SCHEMA_NESTED_KEYS as a, walkSchemaArray as c, SCHEMA_MAP_KEYS as i, walkSchemaValue as l, projectRuntimeToolInputSchema as n, SCHEMA_OBJECT_KEYS as o, SCHEMA_ARRAY_KEYS as r, evaluateSchemaWalk as s, prepareRuntimeToolInputSchema as t };
@@ -1,7 +1,7 @@
1
- import "./index-D27wAoOr.mjs";
2
- import { H as ProviderResponse, a as AssistantMessage, k as Model, nt as StreamOptions, pt as Usage } from "./types-DvzmWW8J.mjs";
3
- import { r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-DrRM_90c.mjs";
4
- import "./event-stream-DqDQWqiy.mjs";
1
+ import "./index-BYDvopUB.mjs";
2
+ import { H as ProviderResponse, a as AssistantMessage, k as Model, nt as StreamOptions, pt as Usage } from "./types-Bd2T86VJ.mjs";
3
+ import { r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-BcqWLo_u.mjs";
4
+ import "./event-stream-6UNs-AhN.mjs";
5
5
  import { t as ProviderErrorProjection } from "./provider-error-xumb1V3F.mjs";
6
6
  //#region packages/ai/src/transports/transport-stream-shared.d.ts
7
7
  type TransportUsage = Pick<Usage, "input" | "output" | "cacheRead" | "cacheWrite" | "contextUsage" | "totalTokens"> & {
@@ -1,9 +1,9 @@
1
1
  import { n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-DzrF1h4J.mjs";
2
- import { a as createAssistantMessageEventStream } from "./event-stream-C5AbCAaZ.mjs";
2
+ import { a as createAssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
3
3
  import { i as asOptionalRecord, n as asNullableRecord, t as asNonArrayRecord } from "./record-coerce-CNDovvft.mjs";
4
- import { E as headersToRecord, r as getAiTransportHost } from "./host-u3o8XiAp.mjs";
5
- import { i as projectDiagnosticValue, n as projectProviderError } from "./provider-error-DQBE1bUQ.mjs";
6
- import { c as isTransientNetworkError } from "./diagnostics-Caj-4RBA.mjs";
4
+ import { E as headersToRecord, r as getAiTransportHost } from "./host-Bf3NjYNj.mjs";
5
+ import { a as projectDiagnosticValue, n as projectProviderError } from "./provider-error-CF9GWCs2.mjs";
6
+ import { l as isTransientNetworkError } from "./diagnostics-tQasYct1.mjs";
7
7
  import { t as createZeroUsage } from "./usage-CJH5D6Ea.mjs";
8
8
  import { parse } from "partial-json";
9
9
  //#region packages/ai/src/utils/sanitize-unicode.ts
@@ -208,7 +208,7 @@ function shortHash(str) {
208
208
  }
209
209
  //#endregion
210
210
  //#region packages/ai/src/utils/json-parse.ts
211
- const VALID_JSON_ESCAPES = /* @__PURE__ */ new Set([
211
+ const SIMPLE_JSON_ESCAPES = /* @__PURE__ */ new Set([
212
212
  "\"",
213
213
  "\\",
214
214
  "/",
@@ -216,8 +216,7 @@ const VALID_JSON_ESCAPES = /* @__PURE__ */ new Set([
216
216
  "f",
217
217
  "n",
218
218
  "r",
219
- "t",
220
- "u"
219
+ "t"
221
220
  ]);
222
221
  const JSON_CONTROL_ESCAPES = /* @__PURE__ */ new Set([
223
222
  "b",
@@ -226,10 +225,6 @@ const JSON_CONTROL_ESCAPES = /* @__PURE__ */ new Set([
226
225
  "r",
227
226
  "t"
228
227
  ]);
229
- function isControlCharacter(char) {
230
- const codePoint = char.codePointAt(0);
231
- return codePoint !== void 0 && codePoint >= 0 && codePoint <= 31;
232
- }
233
228
  /**
234
229
  * Repairs malformed JSON string literals by:
235
230
  * - escaping raw control characters inside strings
@@ -276,9 +271,6 @@ function repairJson(json, options) {
276
271
  index += 5;
277
272
  continue;
278
273
  }
279
- repaired += "\\\\";
280
- stringValuePrefix += "\\";
281
- continue;
282
274
  }
283
275
  if (!preserveValidControlEscapes && JSON_CONTROL_ESCAPES.has(nextChar)) {
284
276
  stringValuePrefix = stringValuePrefix.slice(-160);
@@ -288,7 +280,7 @@ function repairJson(json, options) {
288
280
  continue;
289
281
  }
290
282
  }
291
- if (VALID_JSON_ESCAPES.has(nextChar)) {
283
+ if (SIMPLE_JSON_ESCAPES.has(nextChar)) {
292
284
  repaired += `\\${nextChar}`;
293
285
  stringValuePrefix += nextChar === "\\" ? "\\" : `\\${nextChar}`;
294
286
  index += 1;
@@ -298,7 +290,7 @@ function repairJson(json, options) {
298
290
  stringValuePrefix += "\\";
299
291
  continue;
300
292
  }
301
- repaired += isControlCharacter(char) ? JSON.stringify(char).slice(1, -1) : char;
293
+ repaired += char.charCodeAt(0) <= 31 ? JSON.stringify(char).slice(1, -1) : char;
302
294
  stringValuePrefix += char;
303
295
  }
304
296
  return repaired;