@openclaw/ai 2026.8.1-beta.1 → 2026.8.1-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 (86) hide show
  1. package/dist/{anthropic-CE-7SkF6.mjs → anthropic-B6dLpq5L.mjs} +37 -22
  2. package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
  3. package/dist/{anthropic-usage-Ma4iX6uG.mjs → anthropic-compaction-replay-8lJNKXOE.mjs} +225 -102
  4. package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
  5. package/dist/{api-registry-EpJoVwM1.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
  6. package/dist/{azure-openai-responses-Cc_kasye.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
  7. package/dist/diagnostics.d.mts +24 -1
  8. package/dist/diagnostics.mjs +2 -1
  9. package/dist/{event-stream-DRmDMRHH.d.mts → event-stream-BP6AWT8j.d.mts} +3 -1
  10. package/dist/{event-stream-CEV9t6da.mjs → event-stream-uSMZJ3FA.mjs} +16 -3
  11. package/dist/event-stream.d.mts +1 -1
  12. package/dist/event-stream.mjs +1 -1
  13. package/dist/{google-CGQu21aw.mjs → google-C7h2QzDX.mjs} +4 -4
  14. package/dist/{google-shared-Cq2UKx1l.mjs → google-shared-B0Qr9OR7.mjs} +9 -18
  15. package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
  16. package/dist/{google-vertex-CusxWzvE.mjs → google-vertex-Bhc3TjDl.mjs} +5 -4
  17. package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
  18. package/dist/{host-Bl7Kgddo.mjs → host-DTqNc7ad.mjs} +227 -168
  19. package/dist/{host-Dn4_SZI2.d.mts → host-vWgMMhiJ.d.mts} +9 -4
  20. package/dist/index.d.mts +6 -6
  21. package/dist/index.mjs +7 -5
  22. package/dist/internal/anthropic.d.mts +13 -5
  23. package/dist/internal/anthropic.mjs +5 -5
  24. package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
  25. package/dist/internal/openai-responses-payload-policy.mjs +3 -0
  26. package/dist/internal/openai.d.mts +6 -6
  27. package/dist/internal/openai.mjs +8 -7
  28. package/dist/internal/runtime.d.mts +17 -5
  29. package/dist/internal/runtime.mjs +85 -73
  30. package/dist/internal/shared.d.mts +1 -6
  31. package/dist/internal/shared.mjs +3 -4
  32. package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
  33. package/dist/{mistral-Dx6VzNjf.mjs → mistral-CEWoQI_g.mjs} +26 -45
  34. package/dist/{number-coercion-1Miyb5MO.mjs → number-coercion-H9qHik3g.mjs} +7 -2
  35. package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
  36. package/dist/{openai-chatgpt-responses-SC9m0FSf.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +225 -144
  37. package/dist/{openai-completions-BaIpl93j.mjs → openai-completions-BPnt4Sml.mjs} +28 -43
  38. package/dist/openai-completions-compat-Dt3dcawL.d.mts +43 -0
  39. package/dist/{openai-responses-Bdx3V_Yu.mjs → openai-responses-DhIKtOup.mjs} +17 -24
  40. package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
  41. package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
  42. package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
  43. package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
  44. package/dist/{openai-responses-prompt-observer-internal-DDZPxRfr.mjs → openai-responses-prompt-observer-internal-DgNTYnRY.mjs} +3 -3
  45. package/dist/{openai-responses-stream-internal-Bl8YyVtF.mjs → openai-responses-shared-DXIt3iY5.mjs} +1211 -908
  46. package/dist/{openai-reasoning-compat-DKebnIBL.mjs → openai-stop-reason-BkFkqqK0.mjs} +198 -172
  47. package/dist/{openai-transport-shared-Cipt7egQ.mjs → openai-tool-projection-CY04OcvQ.mjs} +151 -128
  48. package/dist/provider-error-BUwEnjXq.mjs +429 -0
  49. package/dist/provider-error-CzNw4BWX.d.mts +12 -0
  50. package/dist/{provider-options-C5kYML7i.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
  51. package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
  52. package/dist/provider-types.d.mts +31 -0
  53. package/dist/provider-types.mjs +8 -0
  54. package/dist/providers.d.mts +1 -1
  55. package/dist/providers.mjs +17 -19
  56. package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
  57. package/dist/record-coerce-DdXsgUd_.mjs +23 -0
  58. package/dist/{model-utils-Dau5dlgm.mjs → sanitize-unicode-BYqrYtC_.mjs} +28 -2
  59. package/dist/session-resources-CkR4WWy1.mjs +21 -0
  60. package/dist/simple-options-D58D5Kvw.mjs +117 -0
  61. package/dist/src-D2H6yKkH.mjs +2 -0
  62. package/dist/{stream-first-event-timeout-BIBomOGq.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
  63. package/dist/string-coerce-fsri9iCu.mjs +34 -0
  64. package/dist/{tool-schema-json-projection-B1b-XCn5.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +5 -7
  65. package/dist/transport-utils-DJqkxbhC.mjs +138 -0
  66. package/dist/transports.d.mts +135 -178
  67. package/dist/transports.mjs +1732 -1294
  68. package/dist/types-BDdaOVi2.mjs +6 -0
  69. package/dist/{types-CH7ReIcU.d.mts → types-BHNrPS1l.d.mts} +19 -1
  70. package/dist/types.d.mts +4 -4
  71. package/dist/types.mjs +6 -4
  72. package/dist/utf16-slice-CvGodqok.mjs +29 -0
  73. package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
  74. package/dist/{validation-CcPcuEbR.d.mts → validation-DT9SrFn3.d.mts} +1 -1
  75. package/dist/validation.d.mts +1 -1
  76. package/dist/validation.mjs +1 -1
  77. package/package.json +15 -1
  78. package/dist/headers-B_e4-1J0.mjs +0 -9
  79. package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
  80. package/dist/openai-responses-contracts-BBKBfAqR.d.mts +0 -116
  81. package/dist/openai-responses-shared-CCyMvg7M.mjs +0 -403
  82. package/dist/provider-error-DI0Ts28U.mjs +0 -47
  83. package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
  84. package/dist/tool-result-text-Dvkp2Dus.mjs +0 -274
  85. package/dist/transform-messages-DfjpNXNQ.mjs +0 -2
  86. package/dist/transport-stream-shared-CPNv7A3r.mjs +0 -297
@@ -1,403 +0,0 @@
1
- import { i as transformMessages, n as getAiTransportHost } from "./host-Bl7Kgddo.mjs";
2
- import { r as clampThinkingLevel } from "./model-utils-Dau5dlgm.mjs";
3
- import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
4
- import { a as isImageWithMediaPayload, h as stripSystemPromptCacheBoundary, r as extractToolResultText, t as describeToolResultMediaPlaceholder, v as sortPromptCacheToolsByName } from "./tool-result-text-Dvkp2Dus.mjs";
5
- import { G as normalizeOpenAIStrictToolParameters, U as findOpenAIStrictToolProjectionDiagnostics, ft as supportsOpenAIReasoningEffort, n as processResponsesStream, pt as supportsOpenAITemperature, q as resolveOpenAIProjectedToolsStrictToolFlag, ut as resolveOpenAIReasoningEffortForModel } from "./openai-responses-stream-internal-Bl8YyVtF.mjs";
6
- import { d as transportAbortError } from "./transport-stream-shared-CPNv7A3r.mjs";
7
- import { l as projectOpenAITools } from "./openai-transport-shared-Cipt7egQ.mjs";
8
- import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-BIBomOGq.mjs";
9
- import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
10
- import { t as shortHash } from "./hash-CHgqbJmD.mjs";
11
- import "./transform-messages-DfjpNXNQ.mjs";
12
- import { createHash } from "node:crypto";
13
- //#region packages/ai/src/providers/openai-responses-tools.ts
14
- const LOG_SUBSYSTEM = "llm/openai-responses";
15
- const MAX_STRICT_TOOL_DOWNGRADE_DIAGNOSTIC_KEYS = 64;
16
- const loggedStrictToolDowngradeDiagnosticKeys = /* @__PURE__ */ new Set();
17
- /** Converts and returns the projection used to reconcile tool choices. */
18
- function convertResponsesToolPayload(tools, options) {
19
- const projection = projectOpenAITools(tools);
20
- const strict = resolveResponsesStrictToolFlag(projection, resolveResponsesStrictToolSetting(options), options?.model);
21
- return {
22
- projection,
23
- tools: sortPromptCacheToolsByName(projection.tools).map((tool) => {
24
- const result = {
25
- type: "function",
26
- name: tool.name,
27
- description: tool.description,
28
- parameters: normalizeOpenAIStrictToolParameters(tool.parameters, strict === true, options?.model?.compat)
29
- };
30
- if (strict !== void 0) result.strict = strict;
31
- return result;
32
- })
33
- };
34
- }
35
- function resolveResponsesStrictToolSetting(options) {
36
- if (options?.strict !== void 0) return options.strict;
37
- if (options?.model) return getAiTransportHost().resolveOpenAIStrictToolSetting(options.model, {
38
- transport: "stream",
39
- supportsStrictMode: options.supportsStrictMode
40
- });
41
- return false;
42
- }
43
- function resolveResponsesStrictToolFlag(projection, strictSetting, model) {
44
- const strict = resolveOpenAIProjectedToolsStrictToolFlag(projection, strictSetting);
45
- if (strictSetting === true && strict === false && model) getAiTransportHost().logDebug(LOG_SUBSYSTEM, () => {
46
- const diagnostics = findOpenAIStrictToolProjectionDiagnostics(projection);
47
- if (!shouldLogStrictToolDowngradeDiagnostic(diagnostics, model)) return null;
48
- const sample = diagnostics.slice(0, 5).map((entry) => ({
49
- tool: entry.toolName ?? `tool[${entry.toolIndex}]`,
50
- violations: entry.violations.slice(0, 8)
51
- }));
52
- return {
53
- message: `OpenAI responses tool schema strict mode downgraded to strict=false for ${model.provider ?? "unknown"}/${model.id ?? "unknown"} because ${diagnostics.length} tool schema(s) are not strict-compatible`,
54
- data: {
55
- provider: model.provider,
56
- model: model.id,
57
- incompatibleToolCount: diagnostics.length,
58
- sample
59
- }
60
- };
61
- });
62
- return strict;
63
- }
64
- function shouldLogStrictToolDowngradeDiagnostic(diagnostics, model) {
65
- const key = createHash("sha256").update(JSON.stringify({
66
- provider: model.provider,
67
- model: model.id,
68
- diagnostics: diagnostics.map((entry) => ({
69
- toolIndex: entry.toolIndex,
70
- toolName: entry.toolName ?? null,
71
- violations: entry.violations
72
- }))
73
- })).digest("hex");
74
- if (loggedStrictToolDowngradeDiagnosticKeys.has(key)) return false;
75
- if (loggedStrictToolDowngradeDiagnosticKeys.size >= MAX_STRICT_TOOL_DOWNGRADE_DIAGNOSTIC_KEYS) loggedStrictToolDowngradeDiagnosticKeys.clear();
76
- loggedStrictToolDowngradeDiagnosticKeys.add(key);
77
- return true;
78
- }
79
- //#endregion
80
- //#region packages/ai/src/providers/openai-responses-shared.ts
81
- const EMPTY_TOOL_RESULT_TEXT = "(no output)";
82
- function splitResponsesToolCallId(id) {
83
- const separatorIndex = id.indexOf("|");
84
- return separatorIndex === -1 ? [id, void 0] : [id.slice(0, separatorIndex), id.slice(separatorIndex + 1)];
85
- }
86
- function sanitizeToolResultText(text, fallback) {
87
- const sanitized = sanitizeSurrogates(text);
88
- return sanitized.trim().length > 0 ? sanitized : fallback;
89
- }
90
- function normalizeResponsesReasoningReplayItem(params) {
91
- const next = { ...params.item };
92
- if (!Array.isArray(next.summary)) next.summary = [];
93
- if (!params.replayResponsesItemIds) delete next.id;
94
- return next;
95
- }
96
- function parseTextSignature(signature) {
97
- if (!signature) return;
98
- if (signature.startsWith("{")) try {
99
- const parsed = JSON.parse(signature);
100
- if (parsed.v === 1) {
101
- const id = typeof parsed.id === "string" ? parsed.id : void 0;
102
- const phase = parsed.phase === "commentary" || parsed.phase === "final_answer" ? parsed.phase : void 0;
103
- if (id !== void 0 || phase !== void 0) return {
104
- id,
105
- phase
106
- };
107
- return;
108
- }
109
- } catch {}
110
- return { id: signature };
111
- }
112
- function resolveReplayableResponsesMessageId(params) {
113
- if (!params.textSignatureId) return params.fallbackOrdinal === 0 ? params.fallbackId : `${params.fallbackId}_${params.fallbackOrdinal}`;
114
- return params.previousReplayItemWasReasoning ? params.textSignatureId : void 0;
115
- }
116
- function isResponsesReasoningEffort(effort) {
117
- return effort === "minimal" || effort === "low" || effort === "medium" || effort === "high" || effort === "xhigh" || effort === "max";
118
- }
119
- function convertResponsesMessages(model, context, allowedToolCallProviders, options) {
120
- const messages = [];
121
- const shouldReplayResponsesItemIds = options?.replayResponsesItemIds ?? true;
122
- const normalizeIdPart = (part) => {
123
- const sanitized = part.replace(/[^a-zA-Z0-9_-]/g, "_");
124
- return (sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized).replace(/_+$/, "");
125
- };
126
- const buildForeignResponsesItemId = (itemId) => {
127
- const normalized = `fc_${shortHash(itemId)}`;
128
- return normalized.length > 64 ? normalized.slice(0, 64) : normalized;
129
- };
130
- const normalizeToolCallId = (id, targetModel, source) => {
131
- if (!allowedToolCallProviders.has(model.provider)) return normalizeIdPart(id);
132
- if (!id.includes("|")) return normalizeIdPart(id);
133
- const [callId, itemId = ""] = splitResponsesToolCallId(id);
134
- const normalizedCallId = normalizeIdPart(callId);
135
- let normalizedItemId = source.provider !== model.provider || source.api !== model.api ? buildForeignResponsesItemId(itemId) : normalizeIdPart(itemId);
136
- if (!normalizedItemId.startsWith("fc_")) normalizedItemId = normalizeIdPart(`fc_${normalizedItemId}`);
137
- return `${normalizedCallId}|${normalizedItemId}`;
138
- };
139
- const transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);
140
- if ((options?.includeSystemPrompt ?? true) && context.systemPrompt) {
141
- const compat = model.compat;
142
- const role = model.reasoning && compat?.supportsDeveloperRole !== false ? "developer" : "system";
143
- messages.push({
144
- type: "message",
145
- role,
146
- content: [{
147
- type: "input_text",
148
- text: sanitizeSurrogates(stripSystemPromptCacheBoundary(context.systemPrompt))
149
- }]
150
- });
151
- }
152
- let msgIndex = 0;
153
- for (const msg of transformedMessages) {
154
- if (msg.role === "user") if (typeof msg.content === "string") messages.push({
155
- type: "message",
156
- role: "user",
157
- content: [{
158
- type: "input_text",
159
- text: sanitizeSurrogates(msg.content)
160
- }]
161
- });
162
- else {
163
- const content = msg.content.map((item) => {
164
- if (item.type === "text") return {
165
- type: "input_text",
166
- text: sanitizeSurrogates(item.text)
167
- };
168
- return {
169
- type: "input_image",
170
- detail: "auto",
171
- image_url: `data:${item.mimeType};base64,${item.data}`
172
- };
173
- });
174
- if (content.length === 0) continue;
175
- messages.push({
176
- type: "message",
177
- role: "user",
178
- content
179
- });
180
- }
181
- else if (msg.role === "assistant") {
182
- const output = [];
183
- let textFallbackOrdinal = 0;
184
- const assistantMsg = msg;
185
- let previousReplayItemWasReasoning = false;
186
- const isDifferentModel = assistantMsg.model !== model.id && assistantMsg.provider === model.provider && assistantMsg.api === model.api;
187
- for (const block of msg.content) if (block.type === "thinking") {
188
- if (block.thinkingSignature) {
189
- const reasoningItem = normalizeResponsesReasoningReplayItem({
190
- item: JSON.parse(block.thinkingSignature),
191
- replayResponsesItemIds: shouldReplayResponsesItemIds
192
- });
193
- output.push(reasoningItem);
194
- previousReplayItemWasReasoning = true;
195
- }
196
- } else if (block.type === "text") {
197
- const textBlock = block;
198
- const parsedSignature = parseTextSignature(textBlock.textSignature);
199
- let msgId = shouldReplayResponsesItemIds ? resolveReplayableResponsesMessageId({
200
- textSignatureId: parsedSignature?.id,
201
- fallbackId: `msg_${msgIndex}`,
202
- fallbackOrdinal: textFallbackOrdinal,
203
- previousReplayItemWasReasoning
204
- }) : void 0;
205
- if (!parsedSignature?.id) textFallbackOrdinal += 1;
206
- if (msgId && msgId.length > 64) msgId = `msg_${shortHash(msgId)}`;
207
- const messageItem = {
208
- type: "message",
209
- role: "assistant",
210
- content: [{
211
- type: "output_text",
212
- text: sanitizeSurrogates(textBlock.text),
213
- annotations: []
214
- }],
215
- status: "completed",
216
- ...msgId ? { id: msgId } : {},
217
- phase: parsedSignature?.phase
218
- };
219
- output.push(messageItem);
220
- previousReplayItemWasReasoning = false;
221
- } else if (block.type === "toolCall") {
222
- const toolCall = block;
223
- const [callId, itemIdRaw] = splitResponsesToolCallId(toolCall.id);
224
- let itemId = shouldReplayResponsesItemIds ? itemIdRaw : void 0;
225
- if (shouldReplayResponsesItemIds && isDifferentModel && itemId?.startsWith("fc_")) itemId = void 0;
226
- output.push({
227
- type: "function_call",
228
- ...itemId ? { id: itemId } : {},
229
- call_id: callId,
230
- name: toolCall.name,
231
- arguments: JSON.stringify(toolCall.arguments)
232
- });
233
- previousReplayItemWasReasoning = false;
234
- }
235
- if (output.length === 0) continue;
236
- messages.push(...output);
237
- } else if (msg.role === "toolResult") {
238
- const textResult = extractToolResultText(msg.content);
239
- const sanitizedTextResult = sanitizeSurrogates(textResult);
240
- const hasImages = msg.content.some(isImageWithMediaPayload);
241
- const mediaPlaceholder = describeToolResultMediaPlaceholder(msg.content);
242
- const hasText = sanitizedTextResult.trim().length > 0;
243
- const [callId] = splitResponsesToolCallId(msg.toolCallId);
244
- let output;
245
- if (hasImages && model.input.includes("image")) {
246
- const contentParts = [];
247
- if (hasText) contentParts.push({
248
- type: "input_text",
249
- text: sanitizedTextResult
250
- });
251
- else if (mediaPlaceholder === "(see attached media)") contentParts.push({
252
- type: "input_text",
253
- text: mediaPlaceholder
254
- });
255
- for (const block of msg.content) if (isImageWithMediaPayload(block)) contentParts.push({
256
- type: "input_image",
257
- detail: "auto",
258
- image_url: `data:${block.mimeType};base64,${block.data}`
259
- });
260
- output = contentParts;
261
- } else output = sanitizeToolResultText(textResult, mediaPlaceholder ?? EMPTY_TOOL_RESULT_TEXT);
262
- messages.push({
263
- type: "function_call_output",
264
- call_id: callId,
265
- output
266
- });
267
- }
268
- msgIndex++;
269
- }
270
- return messages;
271
- }
272
- function createResponsesAssistantOutput(model, api = model.api) {
273
- return {
274
- role: "assistant",
275
- content: [],
276
- api,
277
- provider: model.provider,
278
- model: model.id,
279
- usage: {
280
- input: 0,
281
- output: 0,
282
- cacheRead: 0,
283
- cacheWrite: 0,
284
- totalTokens: 0,
285
- cost: {
286
- input: 0,
287
- output: 0,
288
- cacheRead: 0,
289
- cacheWrite: 0,
290
- total: 0
291
- }
292
- },
293
- stopReason: "stop",
294
- timestamp: Date.now()
295
- };
296
- }
297
- function applyResponsesServiceTierPricing(usage, serviceTier, model) {
298
- let multiplier = 1;
299
- if (serviceTier === "flex") multiplier = .5;
300
- else if (serviceTier === "priority") multiplier = model.id === "gpt-5.5" ? 2.5 : 2;
301
- if (multiplier === 1) return;
302
- usage.cost.input *= multiplier;
303
- usage.cost.output *= multiplier;
304
- usage.cost.cacheRead *= multiplier;
305
- usage.cost.cacheWrite *= multiplier;
306
- usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
307
- }
308
- function resolveResponsesReasoningEffort(model, reasoning) {
309
- const clampedReasoning = reasoning ? clampThinkingLevel(model, reasoning) : void 0;
310
- if (!clampedReasoning || clampedReasoning === "off") return;
311
- if (clampedReasoning === "max") return supportsOpenAIReasoningEffort(model, "max") ? "max" : "xhigh";
312
- if (clampedReasoning === "minimal" && model.provider === "openai" && supportsOpenAIReasoningEffort(model, "max")) {
313
- const effort = resolveOpenAIReasoningEffortForModel({
314
- model,
315
- effort: "minimal"
316
- });
317
- return isResponsesReasoningEffort(effort) ? effort : void 0;
318
- }
319
- return clampedReasoning;
320
- }
321
- function applyCommonResponsesParams(params, model, context, options, config) {
322
- if (options?.maxTokens) params.max_output_tokens = Math.max(options.maxTokens, 16);
323
- if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) params.temperature = options.temperature;
324
- if (context.tools) {
325
- const converted = convertResponsesToolPayload(context.tools, { model });
326
- if (converted.tools.length > 0) params.tools = converted.tools;
327
- }
328
- if (!model.reasoning) return;
329
- if (options?.reasoningEffort || options?.reasoningSummary) {
330
- params.reasoning = {
331
- effort: options?.reasoningEffort ? model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort : "medium",
332
- summary: options?.reasoningSummary || "auto"
333
- };
334
- params.include = ["reasoning.encrypted_content"];
335
- } else if ((config?.setDefaultReasoningOff ?? true) && model.thinkingLevelMap?.off !== null) params.reasoning = { effort: model.thinkingLevelMap?.off ?? "none" };
336
- }
337
- function buildResponsesRequestOptions(options) {
338
- return {
339
- ...options?.signal ? { signal: options.signal } : {},
340
- ...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
341
- maxRetries: options?.maxRetries ?? 0
342
- };
343
- }
344
- function cleanStreamingScratchBuffers(output) {
345
- for (const block of output.content) {
346
- delete block.index;
347
- delete block.partialJson;
348
- }
349
- }
350
- async function runResponsesStreamLifecycle(params) {
351
- const { stream, model, output, options } = params;
352
- let firstEventAbort;
353
- try {
354
- const client = params.createClient();
355
- let requestParams = params.buildParams();
356
- const nextParams = await options?.onPayload?.(requestParams, model);
357
- if (nextParams !== void 0) requestParams = nextParams;
358
- firstEventAbort = createFirstStreamEventAbortController(options?.signal);
359
- const { data: openaiStream, response } = await client.responses.create(requestParams, {
360
- ...buildResponsesRequestOptions(options),
361
- signal: firstEventAbort.signal
362
- }).withResponse();
363
- await options?.onResponse?.({
364
- status: response.status,
365
- headers: headersToRecord(response.headers)
366
- }, model);
367
- stream.push({
368
- type: "start",
369
- partial: output
370
- });
371
- const firstEventTimeoutMs = getFirstStreamEventTimeoutMs(options);
372
- const onFirstEventTimeout = getFirstStreamEventTimeoutHandler(options);
373
- await processResponsesStream(openaiStream, output, stream, model, params.processStreamOptions || firstEventTimeoutMs !== void 0 || onFirstEventTimeout !== void 0 ? {
374
- ...params.processStreamOptions,
375
- firstEventTimeoutMs: params.processStreamOptions?.firstEventTimeoutMs ?? firstEventTimeoutMs,
376
- abortFirstEventStream: params.processStreamOptions?.abortFirstEventStream ?? firstEventAbort.abort,
377
- onFirstEventTimeout: params.processStreamOptions?.onFirstEventTimeout ?? onFirstEventTimeout,
378
- signal: params.processStreamOptions?.signal ?? options?.signal
379
- } : void 0);
380
- if (options?.signal?.aborted) throw transportAbortError(options.signal);
381
- if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
382
- stream.push({
383
- type: "done",
384
- reason: output.stopReason,
385
- message: output
386
- });
387
- stream.end();
388
- } catch (error) {
389
- cleanStreamingScratchBuffers(output);
390
- output.stopReason = options?.signal?.aborted ? "aborted" : "error";
391
- output.errorMessage = params.formatError(error);
392
- stream.push({
393
- type: "error",
394
- reason: output.stopReason,
395
- error: output
396
- });
397
- stream.end();
398
- } finally {
399
- firstEventAbort?.dispose();
400
- }
401
- }
402
- //#endregion
403
- export { resolveResponsesReasoningEffort as a, createResponsesAssistantOutput as i, applyResponsesServiceTierPricing as n, runResponsesStreamLifecycle as o, convertResponsesMessages as r, convertResponsesToolPayload as s, applyCommonResponsesParams as t };
@@ -1,47 +0,0 @@
1
- import { o as truncateUtf16Safe } from "./tool-result-text-Dvkp2Dus.mjs";
2
- //#region packages/ai/src/utils/provider-error.ts
3
- const MAX_ERROR_BODY_LENGTH = 4e3;
4
- function stringify(value) {
5
- const seen = /* @__PURE__ */ new WeakSet();
6
- try {
7
- return JSON.stringify(value, (_key, candidate) => {
8
- if (typeof candidate !== "object" || candidate === null) return candidate;
9
- if (seen.has(candidate)) return "[Circular]";
10
- seen.add(candidate);
11
- return candidate;
12
- }) ?? String(value);
13
- } catch {
14
- return String(value);
15
- }
16
- }
17
- function readStatus(error) {
18
- for (const value of [
19
- error.status,
20
- error.statusCode,
21
- error.response?.status,
22
- error.response?.statusCode
23
- ]) if (typeof value === "number" && Number.isFinite(value)) return value;
24
- }
25
- function readBody(error) {
26
- for (const value of [
27
- error.body,
28
- error.error,
29
- error.response?.body,
30
- error.response?.data
31
- ]) {
32
- if (value === void 0 || value === null) continue;
33
- if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) continue;
34
- const body = (typeof value === "string" ? value : stringify(value)).trim();
35
- if (body.length > 0) return body.length <= MAX_ERROR_BODY_LENGTH ? body : `${truncateUtf16Safe(body, MAX_ERROR_BODY_LENGTH)}... [truncated]`;
36
- }
37
- }
38
- function formatProviderError(error) {
39
- if (!(error instanceof Error)) return stringify(error);
40
- const httpError = error;
41
- const status = readStatus(httpError);
42
- const body = readBody(httpError);
43
- if (status === void 0 || body === void 0 || error.message.includes(body)) return error.message;
44
- return `${status}: ${body}`;
45
- }
46
- //#endregion
47
- export { formatProviderError as t };
@@ -1,26 +0,0 @@
1
- //#region packages/ai/src/utils/sanitize-unicode.ts
2
- /**
3
- * Removes unpaired Unicode surrogate characters from a string.
4
- *
5
- * Unpaired surrogates (high surrogates 0xD800-0xDBFF without matching low surrogates 0xDC00-0xDFFF,
6
- * or vice versa) cause JSON serialization errors in many API providers.
7
- *
8
- * Valid emoji and other characters outside the Basic Multilingual Plane use properly paired
9
- * surrogates and will NOT be affected by this function.
10
- *
11
- * @param text - The text to sanitize
12
- * @returns The sanitized text with unpaired surrogates removed
13
- *
14
- * @example
15
- * // Valid emoji (properly paired surrogates) are preserved
16
- * sanitizeSurrogates("Hello 🙈 World") // => "Hello 🙈 World"
17
- *
18
- * // Unpaired high surrogate is removed
19
- * const unpaired = String.fromCharCode(0xD83D); // high surrogate without low
20
- * sanitizeSurrogates(`Text ${unpaired} here`) // => "Text here"
21
- */
22
- function sanitizeSurrogates(text) {
23
- return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "");
24
- }
25
- //#endregion
26
- export { sanitizeSurrogates as t };