@openclaw/ai 2026.9.5 → 2026.9.7

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 (102) hide show
  1. package/dist/{anthropic-COtDvgtt.mjs → anthropic-Cw2pgccz.mjs} +59 -88
  2. package/dist/{anthropic-payload-policy-5Erq1Nzy.d.mts → anthropic-payload-policy-NIPVYXPq.d.mts} +8 -6
  3. package/dist/{anthropic-stream-reducer-BvdYYWL8.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs} +194 -247
  4. package/dist/{api-registry-Ba2Cv-ut.d.mts → api-registry-D-nbmSqr.d.mts} +2 -2
  5. package/dist/{azure-openai-responses-YrgnD583.mjs → azure-openai-responses-BwT3-X8P.mjs} +22 -33
  6. package/dist/{base64-BQOzsvUH.mjs → base64-C1PsYcRQ.mjs} +22 -16
  7. package/dist/{diagnostics-Dm4bisWG.mjs → diagnostics-CJaB6g8J.mjs} +55 -10
  8. package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
  9. package/dist/diagnostics.d.mts +11 -5
  10. package/dist/diagnostics.mjs +4 -4
  11. package/dist/{env-api-keys-bktO00EJ.mjs → env-api-keys-CyX4VKGO.mjs} +7 -5
  12. package/dist/event-stream-CMQfX_yr.d.mts +1 -0
  13. package/dist/{event-stream-CCoa-qSI.d.mts → event-stream-DOPFYVqs.d.mts} +2 -2
  14. package/dist/{event-stream-D8PARQfL.mjs → event-stream-vd9UnCAU.mjs} +10 -0
  15. package/dist/event-stream.d.mts +2 -2
  16. package/dist/event-stream.mjs +1 -1
  17. package/dist/{google-BuhpRO9r.mjs → google-BfapkS_K.mjs} +8 -11
  18. package/dist/google-interactions-DW3iXzjc.mjs +574 -0
  19. package/dist/{google-messages-CyWnYlh0.mjs → google-messages-CtjVtVot.mjs} +35 -71
  20. package/dist/{google-shared-BT5ZeNer.mjs → google-shared-Y2YfotEu.mjs} +43 -47
  21. package/dist/{google-vertex-C7EplRvt.mjs → google-vertex-Dov4kBWu.mjs} +16 -30
  22. package/dist/{host-B4MeUNBc.mjs → host-CHi3X87F.mjs} +64 -189
  23. package/dist/{host-policy-DUnXSx0I.mjs → host-policy-BOAwRg_M.mjs} +2 -14
  24. package/dist/{host-FZ1RA_qD.d.mts → host-rxlNaBwm.d.mts} +9 -3
  25. package/dist/{index-DaF2QbwS.d.mts → index-D6KsSE74.d.mts} +57 -9
  26. package/dist/index.d.mts +7 -7
  27. package/dist/index.mjs +7 -7
  28. package/dist/internal/anthropic.d.mts +13 -8
  29. package/dist/internal/anthropic.mjs +5 -5
  30. package/dist/internal/openai-completions-compat.d.mts +1 -1
  31. package/dist/internal/openai-completions-compat.mjs +1 -1
  32. package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
  33. package/dist/internal/openai-responses-payload-policy.mjs +2 -2
  34. package/dist/internal/openai.d.mts +46 -9
  35. package/dist/internal/openai.mjs +13 -12
  36. package/dist/internal/runtime.d.mts +31 -70
  37. package/dist/internal/runtime.mjs +11 -66
  38. package/dist/internal/shared.d.mts +16 -13
  39. package/dist/internal/shared.mjs +6 -5
  40. package/dist/internal/tool-schema.d.mts +2 -2
  41. package/dist/internal/tool-schema.mjs +2 -2
  42. package/dist/{mistral-moA-mbwl.mjs → mistral-RS6mboC-.mjs} +46 -93
  43. package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
  44. package/dist/{openai-chatgpt-responses-DWID3EFO.mjs → openai-chatgpt-responses-CYbidtrn.mjs} +118 -99
  45. package/dist/{openai-completions-DJ1Vm-CD.mjs → openai-completions-D14ihPYk.mjs} +14 -12
  46. package/dist/{openai-completions-compat-CkwdxTZx.mjs → openai-completions-compat-BOVWBZDn.mjs} +3 -5
  47. package/dist/{openai-completions-compat-JE7gqxb9.d.mts → openai-completions-compat-qJjmqQ71.d.mts} +3 -3
  48. package/dist/{openai-completions-stream-Bu98b0Hv.mjs → openai-completions-stream-CDCuw3DP.mjs} +124 -183
  49. package/dist/{openai-prompt-cache-CJ_xEevu.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
  50. package/dist/{openai-prompt-cache-1wfaIszn.mjs → openai-prompt-cache-D2V7MqR7.mjs} +1 -1
  51. package/dist/{openai-provider-client-DPo0Hmak.mjs → openai-provider-client-CwfsGBbA.mjs} +2 -2
  52. package/dist/{openai-reasoning-effort-NlFZmfEu.mjs → openai-reasoning-effort-ConhwkeX.mjs} +14 -5
  53. package/dist/{openai-responses-BejZzQCP.mjs → openai-responses-CKCBEc2W.mjs} +12 -11
  54. package/dist/openai-responses-compaction-replay-DiYn-gFM.d.mts +12 -0
  55. package/dist/{openai-responses-compaction-window-D6P5oZP5.mjs → openai-responses-compaction-window-UNK1GDpy.mjs} +5 -5
  56. package/dist/{openai-responses-contracts-DWrfMODE.mjs → openai-responses-contracts-CLxnqS9p.mjs} +1 -1
  57. package/dist/{openai-responses-contracts-Dflvrfa8.d.mts → openai-responses-contracts-D1iZ0njF.d.mts} +4 -4
  58. package/dist/{openai-responses-prompt-observer-internal-C15_-OwV.mjs → openai-responses-prompt-observer-internal-iAqLb4tk.mjs} +16 -13
  59. package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +36 -0
  60. package/dist/{openai-responses-shared-CwsziD_m.mjs → openai-responses-shared-DL4ulQn7.mjs} +838 -577
  61. package/dist/{openai-responses-terminal-usage-Dl3J6zrf.d.mts → openai-responses-terminal-usage-BE7lf7nW.d.mts} +2 -2
  62. package/dist/{openai-stop-reason-Drnn_6Qj.mjs → openai-stop-reason-8s70vDXj.mjs} +2 -12
  63. package/dist/{openai-tool-schema-ynZBgqW-.d.mts → openai-tool-schema-a5ysBBga.d.mts} +0 -6
  64. package/dist/{openai-tool-schema-BO8rwyAD.mjs → openai-tool-schema-vsl-cE-n.mjs} +365 -429
  65. package/dist/{openai-transport-params-DQeuAvBl.mjs → openai-transport-params-BwlpzX-2.mjs} +61 -106
  66. package/dist/{positive-integer-DtjCkbue.mjs → positive-integer-CjN5OJbH.mjs} +1 -1
  67. package/dist/{provider-error-DDqw9Qda.mjs → provider-error-CwT_j2v0.mjs} +82 -10
  68. package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
  69. package/dist/{provider-options-DprLsWh9.d.mts → provider-options-Df7ov0K1.d.mts} +6 -4
  70. package/dist/{provider-replay-context-CnUSOwhr.mjs → provider-replay-context-DsyI5jOP.mjs} +1 -1
  71. package/dist/{provider-transcript-transform-BsRAhuWJ.mjs → provider-transcript-transform-JbFbHV8h.mjs} +17 -2
  72. package/dist/{provider-transport-turn-state-CkGToCD2.mjs → provider-transport-turn-state-BheUi_hl.mjs} +1 -1
  73. package/dist/{provider-types-CAKRC7N5.d.mts → provider-types-d4XnoZMd.d.mts} +3 -3
  74. package/dist/provider-types.d.mts +6 -6
  75. package/dist/providers.d.mts +2 -2
  76. package/dist/providers.mjs +15 -11
  77. package/dist/{reasoning-tag-text-partitioner-Dy9IO8Dc.mjs → reasoning-tag-text-partitioner-B6FIIBt6.mjs} +193 -98
  78. package/dist/{record-coerce-DwRYMj3t.mjs → record-coerce-CNDovvft.mjs} +1 -1
  79. package/dist/simple-options-CGAkCwtM.mjs +349 -0
  80. package/dist/{src-DeKjbE8I.mjs → src-H4aXcFuX.mjs} +53 -26
  81. package/dist/{stream-CREqxHgU.mjs → stream-DDsCBgd-.mjs} +1 -7
  82. package/dist/{stream-first-event-timeout-C9ZadkJW.mjs → stream-first-event-timeout-B9o0S4SZ.mjs} +1 -1
  83. package/dist/{tool-schema-json-projection-CD9c_fK8.mjs → tool-schema-json-projection-Ct8SeBeJ.mjs} +63 -23
  84. package/dist/{transport-stream-shared-D-6FQSHm.mjs → transport-stream-shared-Dh5qKJ8e.mjs} +63 -37
  85. package/dist/{transport-stream-shared-BbUkFaHi.d.mts → transport-stream-shared-yYhXa4kX.d.mts} +13 -7
  86. package/dist/{transport-utils-1cyq5Y7x.mjs → transport-utils-C-4bf2Ok.mjs} +3 -4
  87. package/dist/transports.d.mts +37 -33
  88. package/dist/transports.mjs +208 -239
  89. package/dist/types-CB-_vNyI.d.mts +1 -0
  90. package/dist/{types-4_uVs5WH.d.mts → types-CLLR3eB4.d.mts} +5 -1
  91. package/dist/types.d.mts +6 -6
  92. package/dist/types.mjs +5 -5
  93. package/dist/{validation-Dw7cb6BV.mjs → validation-BFZc40Ig.mjs} +80 -54
  94. package/dist/{validation-Ctzu2DhF.d.mts → validation-Cat2wQsc.d.mts} +1 -1
  95. package/dist/validation.d.mts +1 -1
  96. package/dist/validation.mjs +1 -1
  97. package/package.json +6 -6
  98. package/dist/assistant-output-BsEkB-vU.mjs +0 -16
  99. package/dist/event-stream-DmSCpi1T.d.mts +0 -1
  100. package/dist/simple-options-C6cFWj_f.mjs +0 -175
  101. package/dist/types-DkJfb4W3.d.mts +0 -1
  102. package/dist/utf16-slice-CvGodqok.mjs +0 -29
@@ -0,0 +1,349 @@
1
+ import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
2
+ import { O as hasMediaPayload, n as getAiTransportHost } from "./host-CHi3X87F.mjs";
3
+ import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
4
+ import { o as truncateUtf16Safe } from "./provider-error-CwT_j2v0.mjs";
5
+ import { i as copyProviderAcceptanceObserver, j as sanitizeSurrogates } from "./transport-stream-shared-Dh5qKJ8e.mjs";
6
+ //#region packages/ai/src/utils/prompt-cache-stability.ts
7
+ /**
8
+ * Prompt-cache normalization helpers. They keep generated prompt sections
9
+ * deterministic across platform newlines, trailing whitespace, and input
10
+ * ordering.
11
+ */
12
+ /** Canonicalizes provider tool order without relying on host locale settings. */
13
+ function sortPromptCacheToolsByName(tools) {
14
+ const compareText = (left, right) => {
15
+ const leftText = left ?? "";
16
+ const rightText = right ?? "";
17
+ return leftText < rightText ? -1 : leftText > rightText ? 1 : 0;
18
+ };
19
+ return tools.toSorted((left, right) => compareText(left.wireName ?? left.name, right.wireName ?? right.name) || compareText(left.description, right.description));
20
+ }
21
+ /** Normalize structured prompt text before hashing or snapshot comparison. */
22
+ function normalizeStructuredPromptSection(text) {
23
+ return sanitizeSurrogates(text).replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "").trim();
24
+ }
25
+ /** Normalize, de-dupe, and sort capability ids for stable prompt payloads. */
26
+ function normalizePromptCapabilityIds(capabilities) {
27
+ const seen = /* @__PURE__ */ new Set();
28
+ for (const capability of capabilities) {
29
+ const value = normalizeLowercaseStringOrEmpty(normalizeStructuredPromptSection(capability));
30
+ if (value) seen.add(value);
31
+ }
32
+ return [...seen].toSorted((left, right) => left.localeCompare(right));
33
+ }
34
+ //#endregion
35
+ //#region packages/ai/src/utils/system-prompt-cache-boundary.ts
36
+ /**
37
+ * System prompt cache-boundary helpers.
38
+ *
39
+ * Keeps stable prompt prefixes separate from dynamic runtime additions for provider prompt caching.
40
+ */
41
+ const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
42
+ /** Producer-delimited Runtime facts; instructions must remain outside this region. */
43
+ const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY = "\n<!-- OPENCLAW-RELOCATABLE-BOUNDARY -->\n";
44
+ const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END = "\n<!-- /OPENCLAW-RELOCATABLE-BOUNDARY -->";
45
+ function stripSystemPromptCacheBoundary(text) {
46
+ return stripSystemPromptRelocatableBoundary(text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n").replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY.trim(), ""));
47
+ }
48
+ /** Reject ambiguous markers from workspace or hook text instead of moving instructions. */
49
+ function splitSystemPromptRelocatableBoundary(text) {
50
+ const opening = SYSTEM_PROMPT_RELOCATABLE_BOUNDARY.trim();
51
+ const closing = SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END.trim();
52
+ const start = text.indexOf(opening);
53
+ const end = text.indexOf(closing);
54
+ if (start === -1 || end < start || text.includes(opening, start + 38) || text.includes(closing, end + 39)) return;
55
+ return {
56
+ remainingPrompt: [text.slice(0, start).trimEnd(), text.slice(end + 39).trimStart()].filter(Boolean).join("\n"),
57
+ relocatable: text.slice(start + 38, end).trim()
58
+ };
59
+ }
60
+ function ensureSystemPromptCacheBoundary(systemPrompt) {
61
+ if (systemPrompt.trim().length === 0) return systemPrompt;
62
+ return systemPrompt.includes("\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n") ? systemPrompt : `${systemPrompt}${SYSTEM_PROMPT_CACHE_BOUNDARY}`;
63
+ }
64
+ function splitSystemPromptCacheBoundary(text) {
65
+ const boundaryIndex = text.indexOf(SYSTEM_PROMPT_CACHE_BOUNDARY);
66
+ if (boundaryIndex === -1) return;
67
+ return {
68
+ stablePrefix: text.slice(0, boundaryIndex).trimEnd(),
69
+ dynamicSuffix: text.slice(boundaryIndex + 34).trimStart()
70
+ };
71
+ }
72
+ /** Keep explicit cache breakpoints while removing relocation metadata. */
73
+ function stripSystemPromptRelocatableBoundary(text) {
74
+ return text.replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY, "\n").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END, "").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY.trim(), "").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END.trim(), "");
75
+ }
76
+ function prependSystemPromptAdditionAfterCacheBoundary(params) {
77
+ const systemPromptAddition = typeof params.systemPromptAddition === "string" ? normalizeStructuredPromptSection(params.systemPromptAddition) : "";
78
+ if (!systemPromptAddition) return params.systemPrompt;
79
+ if (params.systemPrompt.trim().length === 0) return systemPromptAddition;
80
+ const split = splitSystemPromptCacheBoundary(params.systemPrompt);
81
+ if (!split) return `${systemPromptAddition}\n\n${params.systemPrompt}`;
82
+ const dynamicSuffix = split.dynamicSuffix ? normalizeStructuredPromptSection(split.dynamicSuffix) : "";
83
+ if (!dynamicSuffix) return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}`;
84
+ return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}\n\n${dynamicSuffix}`;
85
+ }
86
+ //#endregion
87
+ //#region packages/ai/src/providers/tool-result-text.ts
88
+ const STRUCTURED_TOOL_RESULT_MAX_CHARS = 8e3;
89
+ const IMAGE_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([
90
+ "image",
91
+ "image_url",
92
+ "input_image"
93
+ ]);
94
+ const AUDIO_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([
95
+ "audio",
96
+ "input_audio",
97
+ "output_audio"
98
+ ]);
99
+ const MEDIA_ONLY_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([...IMAGE_TOOL_RESULT_TYPES, ...AUDIO_TOOL_RESULT_TYPES]);
100
+ const INLINE_DATA_URI_PATTERN = /(^|[^A-Za-z0-9_])data:([a-z][a-z0-9.+-]*\/[a-z0-9.+-]+(?:;[a-z0-9.+-]+=[^,;"'\s]+|;base64)*,[^\s"'<>)]+)/gi;
101
+ const MIME_KEY_CANDIDATES = [
102
+ "mimeType",
103
+ "mime_type",
104
+ "mediaType",
105
+ "media_type",
106
+ "contentType",
107
+ "content_type"
108
+ ];
109
+ const TEXTUAL_MIME_PATTERN = /^(?:text\/|application\/(?:json|ld\+json|x-ndjson|xml|javascript|x-www-form-urlencoded)|[^/]+\/[^+]+\+(?:json|xml)$)/i;
110
+ const OPAQUE_OR_BINARY_FIELD_RE = /^(?:blob|buffer|bytes|encrypted_content|encrypted_stdout)$/i;
111
+ function readMimeType(value) {
112
+ if (!isRecord(value)) return;
113
+ for (const key of MIME_KEY_CANDIDATES) {
114
+ const mimeType = value[key];
115
+ if (typeof mimeType === "string" && mimeType.trim().length > 0) return mimeType;
116
+ }
117
+ }
118
+ function isBinaryMimeType(mimeType) {
119
+ const normalized = mimeType.split(";", 1)[0]?.trim().toLowerCase();
120
+ return normalized ? !TEXTUAL_MIME_PATTERN.test(normalized) : false;
121
+ }
122
+ function describeOmittedValue(value, label) {
123
+ const length = typeof value === "string" ? value.length : JSON.stringify(value)?.length;
124
+ return length ? `[${label} omitted: ${length} chars]` : `[${label} omitted]`;
125
+ }
126
+ function redactInlineDataUris(value) {
127
+ return value.replace(INLINE_DATA_URI_PATTERN, (_match, prefix, uri) => `${prefix}[inline data URI: ${uri.length} chars]`);
128
+ }
129
+ function stringifyStructuredBlock(block) {
130
+ const seen = /* @__PURE__ */ new WeakSet();
131
+ try {
132
+ const host = getAiTransportHost();
133
+ const redactedBlock = host.redactModelVisibleSecrets({ structuredToolResult: block }).structuredToolResult;
134
+ const serialized = JSON.stringify(redactedBlock, function structuredToolResultReplacer(key, value) {
135
+ if (OPAQUE_OR_BINARY_FIELD_RE.test(key)) return `[omitted ${key}]`;
136
+ if (key === "data") {
137
+ const mimeType = readMimeType(this);
138
+ if (mimeType && isBinaryMimeType(mimeType)) return describeOmittedValue(value, "binary data");
139
+ }
140
+ if (typeof value === "bigint") return value.toString();
141
+ if (typeof value === "string") return redactInlineDataUris(host.redactModelVisibleSecrets(value));
142
+ if (typeof value === "function" || typeof value === "symbol" || value === void 0) return;
143
+ if (!value || typeof value !== "object") return value;
144
+ if (seen.has(value)) return "[Circular]";
145
+ seen.add(value);
146
+ return value;
147
+ });
148
+ if (!serialized || serialized === "{}") return;
149
+ return serialized;
150
+ } catch {
151
+ return;
152
+ }
153
+ }
154
+ function truncateStructuredToolText(text) {
155
+ if (text.length <= STRUCTURED_TOOL_RESULT_MAX_CHARS) return text;
156
+ return `${truncateUtf16Safe(text, STRUCTURED_TOOL_RESULT_MAX_CHARS)}\n…(truncated)…`;
157
+ }
158
+ function classifyToolResultMedia(blocks) {
159
+ let hasImage = false;
160
+ let hasAudio = false;
161
+ for (const block of blocks) {
162
+ if (!hasMediaPayload(block) || block.type === "text") continue;
163
+ const type = typeof block.type === "string" ? block.type : void 0;
164
+ const mimeType = readMimeType(block)?.toLowerCase();
165
+ hasImage ||= Boolean(type && IMAGE_TOOL_RESULT_TYPES.has(type) || mimeType?.startsWith("image/"));
166
+ hasAudio ||= Boolean(type && AUDIO_TOOL_RESULT_TYPES.has(type) || mimeType?.startsWith("audio/"));
167
+ }
168
+ return {
169
+ hasImage,
170
+ hasAudio
171
+ };
172
+ }
173
+ function describeToolResultMediaPlaceholder(blocks) {
174
+ const { hasImage, hasAudio } = classifyToolResultMedia(blocks);
175
+ if (hasImage && hasAudio) return "(see attached media)";
176
+ if (hasAudio) return "(see attached audio)";
177
+ return hasImage ? "(see attached image)" : void 0;
178
+ }
179
+ function extractToolResultBlockText(block) {
180
+ if (!block || typeof block !== "object") return;
181
+ const record = block;
182
+ if (typeof record.type === "string" && MEDIA_ONLY_TOOL_RESULT_TYPES.has(record.type)) return;
183
+ if (record.type === "text") {
184
+ const text = typeof record.text === "string" ? record.text : "";
185
+ return text ? sanitizeSurrogates(text) : void 0;
186
+ }
187
+ const structured = stringifyStructuredBlock(record);
188
+ return structured ? sanitizeSurrogates(truncateStructuredToolText(structured)) : void 0;
189
+ }
190
+ function extractToolResultText(blocks, options) {
191
+ const explicitTexts = [];
192
+ const structuredBlocks = [];
193
+ for (const block of blocks) {
194
+ if (!block || typeof block !== "object") continue;
195
+ if (block.type === "text") {
196
+ const text = extractToolResultBlockText(block);
197
+ if (text) explicitTexts.push(text);
198
+ } else structuredBlocks.push(block);
199
+ }
200
+ if (explicitTexts.length > 0 && !options?.includeStructured) return explicitTexts.join("\n");
201
+ const structuredTexts = [];
202
+ for (const block of structuredBlocks) {
203
+ const text = extractToolResultBlockText(block);
204
+ if (text) structuredTexts.push(text);
205
+ }
206
+ if (explicitTexts.length > 0) {
207
+ if (structuredTexts.length > 0) explicitTexts.push(truncateStructuredToolText(structuredTexts.join("\n")));
208
+ return explicitTexts.join("\n");
209
+ }
210
+ return truncateStructuredToolText(structuredTexts.join("\n"));
211
+ }
212
+ /** Describe media that cannot be represented on the target provider wire. */
213
+ function describeUnsupportedToolResultMedia(blocks, support) {
214
+ const { hasImage, hasAudio } = classifyToolResultMedia(blocks);
215
+ const omittedImage = hasImage && !support.images;
216
+ const omittedAudio = hasAudio && !support.audio;
217
+ if (omittedImage && omittedAudio) return "[unsupported tool-result media omitted]";
218
+ if (omittedAudio) return "[unsupported tool-result audio omitted]";
219
+ return omittedImage ? "[unsupported tool-result image omitted]" : void 0;
220
+ }
221
+ function formatToolResultText(params) {
222
+ const body = params.text.trim() ? `${params.text}${params.omittedMediaPlaceholder ? `\n${params.omittedMediaPlaceholder}` : ""}` : params.omittedMediaPlaceholder ?? params.mediaPlaceholder ?? "(no tool output)";
223
+ return `${params.isError ? "[tool error] " : ""}${body}`;
224
+ }
225
+ //#endregion
226
+ //#region packages/ai/src/provider-options.ts
227
+ const CODE_MODE_TOOL_SURFACE_OBSERVER = Symbol("openaiCodeModeToolSurfaceObserver");
228
+ const CODE_MODE_TOOL_SURFACE_COLLECTOR = Symbol("openaiCodeModeToolSurfaceCollector");
229
+ const STRICT_REASONING_TAG_TEXT = Symbol("openaiStrictReasoningTagText");
230
+ function markStrictReasoningTagText(options) {
231
+ Reflect.set(options, STRICT_REASONING_TAG_TEXT, true);
232
+ }
233
+ function isStrictReasoningTagText(options) {
234
+ return options ? Reflect.get(options, STRICT_REASONING_TAG_TEXT) === true : false;
235
+ }
236
+ const codeModeToolSurfaceObserver = {
237
+ set(options, observer, collector) {
238
+ Reflect.set(options, CODE_MODE_TOOL_SURFACE_OBSERVER, observer);
239
+ if (collector) Reflect.set(options, CODE_MODE_TOOL_SURFACE_COLLECTOR, collector);
240
+ },
241
+ get(options) {
242
+ if (!options) return;
243
+ const observer = Reflect.get(options, CODE_MODE_TOOL_SURFACE_OBSERVER);
244
+ return typeof observer === "function" ? (observation) => observer(observation) : void 0;
245
+ },
246
+ getCollector(options) {
247
+ if (!options) return;
248
+ const collector = Reflect.get(options, CODE_MODE_TOOL_SURFACE_COLLECTOR);
249
+ return typeof collector === "function" ? (observation) => collector(observation) : void 0;
250
+ }
251
+ };
252
+ /** Internal output policy for callers that must not recover ambiguous reasoning as visible text. */
253
+ const reasoningTagTextPolicy = {
254
+ markStrict: markStrictReasoningTagText,
255
+ isStrict: isStrictReasoningTagText,
256
+ copy(source, target) {
257
+ if (isStrictReasoningTagText(source)) markStrictReasoningTagText(target);
258
+ }
259
+ };
260
+ //#endregion
261
+ //#region packages/ai/src/transports/model-request-body.ts
262
+ const REQUEST_BODY = Symbol("modelRequestBody");
263
+ /** Call-local state survives option spreads; no payload is cached across requests. */
264
+ function modelRequestBodyState(options, inheritFrom) {
265
+ let state = Reflect.get(options, REQUEST_BODY) ?? (inheritFrom && Reflect.get(inheritFrom, REQUEST_BODY));
266
+ if (!state) state = {};
267
+ Reflect.set(options, REQUEST_BODY, state);
268
+ return state;
269
+ }
270
+ function serializeModelRequestBody(payload) {
271
+ const json = JSON.stringify(payload);
272
+ return {
273
+ body: new TextEncoder().encode(json),
274
+ stream: json !== void 0 && JSON.parse(json)?.stream === true
275
+ };
276
+ }
277
+ const encodedBodyStreams = /* @__PURE__ */ new WeakMap();
278
+ function encodedModelRequestBodyStream(body) {
279
+ return typeof body === "object" && body !== null ? encodedBodyStreams.get(body) : void 0;
280
+ }
281
+ /** SDK RequestOptions.body overrides encoding while the original params retain stream metadata. */
282
+ function prepareModelRequestBody(options) {
283
+ const state = options ? modelRequestBodyState(options) : {};
284
+ state.enabled = true;
285
+ return async (payload) => {
286
+ const encoded = state.encode ? await state.encode(payload) : serializeModelRequestBody(payload);
287
+ state.onBytes?.(encoded.body.byteLength);
288
+ encodedBodyStreams.set(encoded.body, encoded.stream);
289
+ return {
290
+ body: encoded.body,
291
+ headers: { "content-type": "application/json" }
292
+ };
293
+ };
294
+ }
295
+ //#endregion
296
+ //#region packages/ai/src/providers/simple-options.ts
297
+ function buildBaseOptions(model, options, apiKey) {
298
+ const firstEventOptions = options;
299
+ const baseOptions = {
300
+ temperature: options?.temperature,
301
+ ...options?.serviceTier ? { serviceTier: options.serviceTier } : {},
302
+ maxTokens: options?.maxTokens,
303
+ responseFormat: options?.responseFormat,
304
+ stop: options?.stop,
305
+ signal: options?.signal,
306
+ apiKey: apiKey || options?.apiKey,
307
+ transport: options?.transport,
308
+ cacheRetention: options?.cacheRetention,
309
+ sessionId: options?.sessionId,
310
+ promptCacheKey: options?.promptCacheKey,
311
+ headers: options?.headers,
312
+ onPayload: options?.onPayload,
313
+ onResponse: options?.onResponse,
314
+ timeoutMs: options?.timeoutMs,
315
+ firstEventTimeoutMs: firstEventOptions?.firstEventTimeoutMs,
316
+ onFirstEventTimeout: firstEventOptions?.onFirstEventTimeout,
317
+ maxRetryDelayMs: options?.maxRetryDelayMs,
318
+ metadata: options?.metadata
319
+ };
320
+ reasoningTagTextPolicy.copy(options, baseOptions);
321
+ modelRequestBodyState(baseOptions, options);
322
+ return copyProviderAcceptanceObserver(options, baseOptions);
323
+ }
324
+ function clampMaxTokensToModel(model, requestedMaxTokens) {
325
+ return requestedMaxTokens === void 0 ? void 0 : Math.max(1, Math.min(requestedMaxTokens, model.maxTokens ?? requestedMaxTokens));
326
+ }
327
+ function clampReasoning(effort) {
328
+ return effort === "xhigh" ? "high" : effort;
329
+ }
330
+ function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
331
+ const budgets = {
332
+ minimal: 1024,
333
+ low: 2048,
334
+ medium: 8192,
335
+ high: 16384,
336
+ max: 32768,
337
+ ...customBudgets
338
+ };
339
+ const minOutputTokens = 1024;
340
+ let thinkingBudget = budgets[clampReasoning(reasoningLevel)];
341
+ const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
342
+ if (maxTokens <= thinkingBudget) thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
343
+ return {
344
+ maxTokens,
345
+ thinkingBudget
346
+ };
347
+ }
348
+ //#endregion
349
+ export { stripSystemPromptCacheBoundary as C, sortPromptCacheToolsByName as D, normalizeStructuredPromptSection as E, splitSystemPromptRelocatableBoundary as S, normalizePromptCapabilityIds as T, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY as _, encodedModelRequestBodyStream as a, prependSystemPromptAdditionAfterCacheBoundary as b, serializeModelRequestBody as c, describeToolResultMediaPlaceholder as d, describeUnsupportedToolResultMedia as f, SYSTEM_PROMPT_CACHE_BOUNDARY as g, formatToolResultText as h, clampReasoning as i, codeModeToolSurfaceObserver as l, extractToolResultText as m, buildBaseOptions as n, modelRequestBodyState as o, extractToolResultBlockText as p, clampMaxTokensToModel as r, prepareModelRequestBody as s, adjustMaxTokensForThinking as t, reasoningTagTextPolicy as u, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END as v, stripSystemPromptRelocatableBoundary as w, splitSystemPromptCacheBoundary as x, ensureSystemPromptCacheBoundary as y };
@@ -1,4 +1,5 @@
1
- import "./validation-Dw7cb6BV.mjs";
1
+ import "./diagnostics-DzrF1h4J.mjs";
2
+ import "./validation-BFZc40Ig.mjs";
2
3
  //#region packages/llm-core/src/model-contracts/anthropic.ts
3
4
  function normalizeClaudeModelId(modelId) {
4
5
  const normalized = modelId?.trim().toLowerCase() ?? "";
@@ -29,62 +30,88 @@ const CLAUDE_SONNET_5_THINKING_PROFILE = {
29
30
  defaultLevel: "high"
30
31
  };
31
32
  const CLAUDE_OPUS_5_THINKING_PROFILE = CLAUDE_SONNET_5_THINKING_PROFILE;
33
+ const CLAUDE_OPUS_55_THINKING_PROFILE = CLAUDE_FABLE_5_THINKING_PROFILE;
34
+ const CLAUDE_SONNET_55_THINKING_PROFILE = {
35
+ levels: [
36
+ { id: "off" },
37
+ { id: "low" },
38
+ { id: "medium" },
39
+ { id: "high" },
40
+ { id: "xhigh" },
41
+ { id: "max" }
42
+ ],
43
+ defaultLevel: "high"
44
+ };
32
45
  /** Resolve the canonical normalized Claude model id for one runtime model ref. */
33
46
  function resolveClaudeModelIdentity(ref) {
34
47
  const normalized = normalizeClaudeModelId((typeof ref.params?.canonicalModelId === "string" ? ref.params.canonicalModelId : void 0) ?? ref.id);
35
48
  return /(?:^|[-/])(claude-[^/]+)$/.exec(normalized)?.[1] ?? normalized;
36
49
  }
50
+ function matchClaudeModelIdentity(normalized, pattern) {
51
+ const match = pattern.exec(normalized);
52
+ return match ? normalized.slice(match.index + (match[0].startsWith("-") ? 1 : 0)) : void 0;
53
+ }
37
54
  /** Resolve Claude Fable 5 through direct ids, cloud ids, or deployment metadata. */
38
55
  function resolveClaudeFable5ModelIdentity(ref) {
39
- const normalized = resolveClaudeModelIdentity(ref);
40
- const match = /(?:^|-)claude-fable-5(?=$|[^a-z0-9])/.exec(normalized);
41
- if (!match) return;
42
- return normalized.slice((match.index ?? 0) + (match[0].startsWith("-") ? 1 : 0));
56
+ return matchClaudeModelIdentity(resolveClaudeModelIdentity(ref), /(?:^|-)claude-fable-5(?=$|[^a-z0-9])/);
43
57
  }
44
58
  /** Resolve Claude Mythos 5 through direct ids, cloud ids, or deployment metadata. */
45
59
  function resolveClaudeMythos5ModelIdentity(ref) {
46
- const normalized = resolveClaudeModelIdentity(ref);
47
- const match = /(?:^|-)claude-mythos-5(?=$|[^a-z0-9])/.exec(normalized);
48
- if (!match) return;
49
- return normalized.slice((match.index ?? 0) + (match[0].startsWith("-") ? 1 : 0));
60
+ return matchClaudeModelIdentity(resolveClaudeModelIdentity(ref), /(?:^|-)claude-mythos-5(?=$|[^a-z0-9])/);
50
61
  }
51
62
  /**
52
- * Anthropic binds thinking to the conversation prefix starting with Fable 5.1 and
53
- * plans to enforce it on later models. Extend only with live replay proof for the
54
- * new model (Mythos 5.1 is unregistered here and unproven).
63
+ * Opus 5.5, Sonnet 5.5, and Fable 5.1 require append-only runtime context.
64
+ * Extend only with live replay proof (Mythos 5.1 remains unproven).
55
65
  */
56
66
  function bindsClaudeThinkingPrefix(ref) {
57
- return /^claude-fable-5-1(?=$|[^a-z0-9])/.test(resolveClaudeModelIdentity(ref));
67
+ return resolveClaudeOpus55ModelIdentity(ref) !== void 0 || resolveClaudeSonnet55ModelIdentity(ref) !== void 0 || /^claude-fable-5-1(?=$|[^a-z0-9])/.test(resolveClaudeModelIdentity(ref));
58
68
  }
59
69
  /** Return whether a Claude model requires adaptive thinking instead of manual budgets. */
60
70
  function requiresClaudeMandatoryAdaptiveThinking(ref) {
61
71
  const modelId = resolveClaudeModelIdentity(ref);
62
- return resolveClaudeFable5ModelIdentity(ref) !== void 0 || resolveClaudeMythos5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-mythos-preview(?=$|[^a-z0-9])/.test(modelId);
72
+ return resolveClaudeOpus55ModelIdentity(ref) !== void 0 || resolveClaudeFable5ModelIdentity(ref) !== void 0 || resolveClaudeMythos5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-mythos-preview(?=$|[^a-z0-9])/.test(modelId);
63
73
  }
64
- /** Resolve Claude Sonnet 5 through direct ids, cloud ids, or deployment metadata. */
74
+ /** Resolve Claude Sonnet 5 through aliases, direct ids, cloud ids, or deployment metadata. */
65
75
  function resolveClaudeSonnet5ModelIdentity(ref) {
66
76
  const normalized = resolveClaudeModelIdentity(ref);
67
- const match = /(?:^|-)claude-sonnet-5(?=$|[^a-z0-9])/.exec(normalized);
68
- if (!match) return;
69
- return normalized.slice((match.index ?? 0) + (match[0].startsWith("-") ? 1 : 0));
77
+ const sonnet55Identity = resolveClaudeSonnet55ModelIdentity(ref);
78
+ if (sonnet55Identity) return sonnet55Identity;
79
+ if (normalized === "sonnet-5") return "claude-sonnet-5";
80
+ return matchClaudeModelIdentity(normalized, /(?:^|-)claude-sonnet-5(?=$|[^a-z0-9])/);
81
+ }
82
+ /** Resolve the Sonnet 5.5 contract without matching other Sonnet 5 generations. */
83
+ function resolveClaudeSonnet55ModelIdentity(ref) {
84
+ const normalized = resolveClaudeModelIdentity(ref);
85
+ if (normalized === "sonnet" || normalized === "sonnet-5-5") return "claude-sonnet-5-5";
86
+ return /^claude-sonnet-5-5(?=$|[^a-z0-9])/.test(normalized) ? normalized : void 0;
87
+ }
88
+ /** Sonnet 5.5 replaces disabled thinking with between-tool progress updates. */
89
+ function requiresClaudeBetweenToolsThinking(ref) {
90
+ return resolveClaudeSonnet55ModelIdentity(ref) !== void 0;
70
91
  }
71
92
  /** Resolve Claude Opus 5 through aliases, direct ids, cloud ids, or deployment metadata. */
72
93
  function resolveClaudeOpus5ModelIdentity(ref) {
73
94
  const normalized = resolveClaudeModelIdentity(ref);
95
+ const opus55Identity = resolveClaudeOpus55ModelIdentity(ref);
96
+ if (opus55Identity) return opus55Identity;
74
97
  if (normalized === "opus" || normalized === "opus-5") return "claude-opus-5";
75
- const match = /(?:^|-)claude-opus-5(?=$|[^a-z0-9])/.exec(normalized);
76
- if (!match) return;
77
- return normalized.slice((match.index ?? 0) + (match[0].startsWith("-") ? 1 : 0));
98
+ return matchClaudeModelIdentity(normalized, /(?:^|-)claude-opus-5(?=$|[^a-z0-9])/);
99
+ }
100
+ /** Resolve the Opus 5.5 contract without matching other Opus 5 generations. */
101
+ function resolveClaudeOpus55ModelIdentity(ref) {
102
+ const normalized = resolveClaudeModelIdentity(ref);
103
+ if (normalized === "opus" || normalized === "opus-5-5") return "claude-opus-5-5";
104
+ return /^claude-opus-5-5(?=$|[^a-z0-9])/.test(normalized) ? normalized : void 0;
78
105
  }
79
106
  /** Return whether a Claude model supports adaptive thinking. */
80
107
  function supportsClaudeAdaptiveThinking(ref) {
81
108
  const modelId = resolveClaudeModelIdentity(ref);
82
- return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-(?:5|preview)|opus-4-(?:6|7|8)|sonnet-(?:5|4-6))(?=$|[^a-z0-9])/.test(modelId);
109
+ return 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);
83
110
  }
84
111
  /** Return whether a Claude model has a native 1M-token context window. */
85
112
  function supportsClaude1MContext(ref) {
86
113
  const modelId = resolveClaudeModelIdentity(ref);
87
- return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-(?:5|preview)|opus-4-(?:6|7|8)|sonnet-(?:5|4-6))(?=$|[^a-z0-9])/.test(modelId);
114
+ return 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);
88
115
  }
89
116
  /** Return whether a Claude model supports Anthropic's native fast mode. */
90
117
  function supportsClaudeFastMode(ref) {
@@ -94,12 +121,12 @@ function supportsClaudeFastMode(ref) {
94
121
  /** Return whether a Claude model supports native max effort. */
95
122
  function supportsClaudeNativeMaxEffort(ref) {
96
123
  const modelId = resolveClaudeModelIdentity(ref);
97
- return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-5|opus-4-(?:6|7|8)|sonnet-(?:5|4-6))(?=$|[^a-z0-9])/.test(modelId);
124
+ return 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);
98
125
  }
99
126
  /** Return whether a Claude model supports native xhigh effort. */
100
127
  function supportsClaudeNativeXhighEffort(ref) {
101
128
  const modelId = resolveClaudeModelIdentity(ref);
102
- return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-5|opus-4-(?:7|8)|sonnet-5)(?=$|[^a-z0-9])/.test(modelId);
129
+ return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || resolveClaudeSonnet5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-5|opus-4-(?:7|8))(?=$|[^a-z0-9])/.test(modelId);
103
130
  }
104
131
  /** Return whether a Claude model rejects caller-selected sampling parameters. */
105
132
  function requiresClaudeDefaultSampling(ref) {
@@ -192,4 +219,4 @@ function calculateUsageCost(usage, pricing) {
192
219
  return cost;
193
220
  }
194
221
  //#endregion
195
- export { supportsClaudeAdaptiveThinking as _, CLAUDE_OPUS_5_THINKING_PROFILE as a, supportsClaudeNativeXhighEffort as b, requiresClaudeDefaultSampling as c, resolveClaudeModelIdentity as d, resolveClaudeMythos5ModelIdentity as f, supportsClaude1MContext as g, resolveClaudeSonnet5ModelIdentity as h, CLAUDE_FABLE_5_THINKING_PROFILE as i, requiresClaudeMandatoryAdaptiveThinking as l, resolveClaudeOpus5ModelIdentity as m, normalizeModelCostConfig as n, CLAUDE_SONNET_5_THINKING_PROFILE as o, resolveClaudeNativeThinkingLevelMap as p, normalizeResolvedPricing as r, bindsClaudeThinkingPrefix as s, calculateUsageCost as t, resolveClaudeFable5ModelIdentity as u, supportsClaudeFastMode as v, supportsClaudeNativeMaxEffort as y };
222
+ export { supportsClaudeFastMode as C, supportsClaudeAdaptiveThinking as S, supportsClaudeNativeXhighEffort as T, resolveClaudeOpus55ModelIdentity as _, CLAUDE_OPUS_55_THINKING_PROFILE as a, resolveClaudeSonnet5ModelIdentity as b, CLAUDE_SONNET_5_THINKING_PROFILE as c, requiresClaudeDefaultSampling as d, requiresClaudeMandatoryAdaptiveThinking as f, resolveClaudeNativeThinkingLevelMap as g, resolveClaudeMythos5ModelIdentity as h, CLAUDE_FABLE_5_THINKING_PROFILE as i, bindsClaudeThinkingPrefix as l, resolveClaudeModelIdentity as m, normalizeModelCostConfig as n, CLAUDE_OPUS_5_THINKING_PROFILE as o, resolveClaudeFable5ModelIdentity as p, normalizeResolvedPricing as r, CLAUDE_SONNET_55_THINKING_PROFILE as s, calculateUsageCost as t, requiresClaudeBetweenToolsThinking as u, resolveClaudeOpus5ModelIdentity as v, supportsClaudeNativeMaxEffort as w, supportsClaude1MContext as x, resolveClaudeSonnet55ModelIdentity as y };
@@ -5,12 +5,6 @@ function wrapStream(api, stream) {
5
5
  return stream(model, context, options);
6
6
  };
7
7
  }
8
- function wrapStreamSimple(api, streamSimple) {
9
- return (model, context, options) => {
10
- if (model.api !== api) throw new Error(`Mismatched api: ${model.api} expected ${api}`);
11
- return streamSimple(model, context, options);
12
- };
13
- }
14
8
  /** Creates an isolated provider registry for one runtime or tenant. */
15
9
  function createApiRegistry() {
16
10
  const providers = /* @__PURE__ */ new Map();
@@ -19,7 +13,7 @@ function createApiRegistry() {
19
13
  provider: {
20
14
  api: provider.api,
21
15
  stream: wrapStream(provider.api, provider.stream),
22
- streamSimple: wrapStreamSimple(provider.api, provider.streamSimple)
16
+ streamSimple: wrapStream(provider.api, provider.streamSimple)
23
17
  },
24
18
  sourceId
25
19
  });
@@ -1,4 +1,4 @@
1
- import { a as clampTimerTimeoutMs } from "./base64-BQOzsvUH.mjs";
1
+ import { a as clampTimerTimeoutMs } from "./base64-C1PsYcRQ.mjs";
2
2
  //#region packages/ai/src/utils/stream-first-event-timeout.ts
3
3
  function getFirstStreamEventTimeoutMs(options) {
4
4
  return options?.firstEventTimeoutMs;
@@ -1,6 +1,63 @@
1
- import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
1
+ import { 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
+ //#region packages/ai/src/providers/schema-walk.ts
5
+ const SCHEMA_MAP_KEYS = /* @__PURE__ */ new Set([
6
+ "$defs",
7
+ "definitions",
8
+ "dependentSchemas",
9
+ "dependencies",
10
+ "patternProperties",
11
+ "properties"
12
+ ]);
13
+ /** Containers whose value is a single nested schema. */
14
+ const SCHEMA_OBJECT_KEYS = /* @__PURE__ */ new Set([
15
+ "additionalItems",
16
+ "additionalProperties",
17
+ "contains",
18
+ "contentSchema",
19
+ "else",
20
+ "if",
21
+ "items",
22
+ "not",
23
+ "propertyNames",
24
+ "then",
25
+ "unevaluatedItems",
26
+ "unevaluatedProperties"
27
+ ]);
28
+ /** Containers whose value is a list of nested schemas. */
29
+ const SCHEMA_ARRAY_KEYS = /* @__PURE__ */ new Set([
30
+ "allOf",
31
+ "anyOf",
32
+ "items",
33
+ "oneOf",
34
+ "prefixItems"
35
+ ]);
36
+ /** Resume child schema walks on a heap stack, never through recursive yield delegation. */
37
+ function evaluateSchemaWalk(walk) {
38
+ const parents = [];
39
+ let current = walk;
40
+ let value;
41
+ try {
42
+ while (true) {
43
+ const step = current.next(value);
44
+ if (!step.done) {
45
+ parents.push(current);
46
+ current = step.value;
47
+ value = void 0;
48
+ continue;
49
+ }
50
+ value = step.value;
51
+ const parent = parents.pop();
52
+ if (!parent) return value;
53
+ current = parent;
54
+ }
55
+ } finally {
56
+ let parent;
57
+ while (parent = parents.pop()) parent.return(void 0);
58
+ }
59
+ }
60
+ //#endregion
4
61
  //#region packages/ai/src/providers/tool-schema-json-projection.ts
5
62
  function isNonFiniteNumberValue(value) {
6
63
  if (typeof value === "number") return !Number.isFinite(value);
@@ -38,19 +95,10 @@ function serializeToolInputSchema(value, path, captureJson) {
38
95
  isRoot = false;
39
96
  return entry;
40
97
  });
41
- } catch {
42
- return {
43
- schema: {},
44
- violations: [`${path} is not JSON-serializable`]
45
- };
46
- }
47
- if (!text) return {
98
+ } catch {}
99
+ if (!text || nonFiniteNumber.path !== null) return {
48
100
  schema: {},
49
- violations: [`${path} is not JSON-serializable`]
50
- };
51
- if (nonFiniteNumber.path !== null) return {
52
- schema: {},
53
- violations: [`${nonFiniteNumber.path} is not JSON-serializable`]
101
+ violations: [`${text ? nonFiniteNumber.path : path} is not JSON-serializable`]
54
102
  };
55
103
  const schema = JSON.parse(text);
56
104
  captureJson?.(text);
@@ -59,14 +107,6 @@ function serializeToolInputSchema(value, path, captureJson) {
59
107
  violations: []
60
108
  };
61
109
  }
62
- const schemaMapKeywords = /* @__PURE__ */ new Set([
63
- "$defs",
64
- "definitions",
65
- "dependencies",
66
- "dependentSchemas",
67
- "patternProperties",
68
- "properties"
69
- ]);
70
110
  function inspectJsonSchema(schema, path, violations) {
71
111
  if (Array.isArray(schema)) {
72
112
  let index = 0;
@@ -85,7 +125,7 @@ function inspectJsonSchema(schema, path, violations) {
85
125
  if (typeof value === "number" && !Number.isFinite(value)) return false;
86
126
  if (!value || typeof value !== "object") continue;
87
127
  path.push(".", key);
88
- if (schemaMapKeywords.has(key) && isRecord(value)) for (const schemaName of Object.keys(value)) {
128
+ if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const schemaName of Object.keys(value)) {
89
129
  const childSchema = value[schemaName];
90
130
  if (childSchema === void 0) return false;
91
131
  path.push(".", schemaName);
@@ -131,4 +171,4 @@ function projectToolInputSchema(schema, path, captureJson) {
131
171
  };
132
172
  }
133
173
  //#endregion
134
- export { projectRuntimeToolInputSchema as n, prepareRuntimeToolInputSchema as t };
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 };