@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.
- package/dist/{anthropic-CE-7SkF6.mjs → anthropic-B6dLpq5L.mjs} +37 -22
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/{anthropic-usage-Ma4iX6uG.mjs → anthropic-compaction-replay-8lJNKXOE.mjs} +225 -102
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-EpJoVwM1.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-Cc_kasye.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-DRmDMRHH.d.mts → event-stream-BP6AWT8j.d.mts} +3 -1
- package/dist/{event-stream-CEV9t6da.mjs → event-stream-uSMZJ3FA.mjs} +16 -3
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CGQu21aw.mjs → google-C7h2QzDX.mjs} +4 -4
- package/dist/{google-shared-Cq2UKx1l.mjs → google-shared-B0Qr9OR7.mjs} +9 -18
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-CusxWzvE.mjs → google-vertex-Bhc3TjDl.mjs} +5 -4
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/{host-Bl7Kgddo.mjs → host-DTqNc7ad.mjs} +227 -168
- package/dist/{host-Dn4_SZI2.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +13 -5
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -4
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-Dx6VzNjf.mjs → mistral-CEWoQI_g.mjs} +26 -45
- package/dist/{number-coercion-1Miyb5MO.mjs → number-coercion-H9qHik3g.mjs} +7 -2
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-SC9m0FSf.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +225 -144
- package/dist/{openai-completions-BaIpl93j.mjs → openai-completions-BPnt4Sml.mjs} +28 -43
- package/dist/openai-completions-compat-Dt3dcawL.d.mts +43 -0
- package/dist/{openai-responses-Bdx3V_Yu.mjs → openai-responses-DhIKtOup.mjs} +17 -24
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/{openai-responses-prompt-observer-internal-DDZPxRfr.mjs → openai-responses-prompt-observer-internal-DgNTYnRY.mjs} +3 -3
- package/dist/{openai-responses-stream-internal-Bl8YyVtF.mjs → openai-responses-shared-DXIt3iY5.mjs} +1211 -908
- package/dist/{openai-reasoning-compat-DKebnIBL.mjs → openai-stop-reason-BkFkqqK0.mjs} +198 -172
- package/dist/{openai-transport-shared-Cipt7egQ.mjs → openai-tool-projection-CY04OcvQ.mjs} +151 -128
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-C5kYML7i.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/{model-utils-Dau5dlgm.mjs → sanitize-unicode-BYqrYtC_.mjs} +28 -2
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BIBomOGq.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-B1b-XCn5.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +5 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +135 -178
- package/dist/transports.mjs +1732 -1294
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-CH7ReIcU.d.mts → types-BHNrPS1l.d.mts} +19 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-CcPcuEbR.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-contracts-BBKBfAqR.d.mts +0 -116
- package/dist/openai-responses-shared-CCyMvg7M.mjs +0 -403
- package/dist/provider-error-DI0Ts28U.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/tool-result-text-Dvkp2Dus.mjs +0 -274
- package/dist/transform-messages-DfjpNXNQ.mjs +0 -2
- package/dist/transport-stream-shared-CPNv7A3r.mjs +0 -297
|
@@ -1,8 +1,154 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
1
|
+
import { n as applyProviderReportedUsageCost, r as calculateCost } from "./sanitize-unicode-BYqrYtC_.mjs";
|
|
2
|
+
import { n as getAiTransportHost } from "./host-DTqNc7ad.mjs";
|
|
3
|
+
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
3
4
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
4
|
-
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-
|
|
5
|
-
import {
|
|
5
|
+
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-q5d7QX5c.mjs";
|
|
6
|
+
import { t as headersToRecord } from "./headers-DdOQtGuU.mjs";
|
|
7
|
+
import { f as transportAbortError } from "./provider-transcript-transform-ePx-Bbfr.mjs";
|
|
8
|
+
//#region packages/ai/src/transports/openai-transport-shared.ts
|
|
9
|
+
/** Shared options, usage shape, cache identity, ordering, and stream scheduling for OpenAI APIs. */
|
|
10
|
+
const MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS = 12;
|
|
11
|
+
const MODEL_STREAM_COOPERATIVE_YIELD_MAX_EVENTS = 64;
|
|
12
|
+
const GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP = "skip_thought_signature_validator";
|
|
13
|
+
const log = {
|
|
14
|
+
debug(message, data) {
|
|
15
|
+
getAiTransportHost().logDebug("openai-transport", () => ({
|
|
16
|
+
message,
|
|
17
|
+
data
|
|
18
|
+
}));
|
|
19
|
+
},
|
|
20
|
+
info(message, data) {
|
|
21
|
+
getAiTransportHost().logInfo("openai-transport", message, data);
|
|
22
|
+
},
|
|
23
|
+
warn(message, data) {
|
|
24
|
+
getAiTransportHost().logWarn("openai-transport", message, data);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function parseOpenAICompletionsUsage(rawUsage, model, options) {
|
|
28
|
+
const cacheRead = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
|
|
29
|
+
const cacheWrite = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
30
|
+
const input = Math.max(0, (rawUsage.prompt_tokens || 0) - cacheRead - cacheWrite);
|
|
31
|
+
const output = rawUsage.completion_tokens || 0;
|
|
32
|
+
const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens;
|
|
33
|
+
const usage = {
|
|
34
|
+
input,
|
|
35
|
+
output,
|
|
36
|
+
cacheRead,
|
|
37
|
+
cacheWrite,
|
|
38
|
+
...options?.includeReasoningTokens !== false && typeof reasoningTokens === "number" && Number.isFinite(reasoningTokens) ? { reasoningTokens } : {},
|
|
39
|
+
totalTokens: input + output + cacheRead + cacheWrite,
|
|
40
|
+
cost: {
|
|
41
|
+
input: 0,
|
|
42
|
+
output: 0,
|
|
43
|
+
cacheRead: 0,
|
|
44
|
+
cacheWrite: 0,
|
|
45
|
+
total: 0
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
calculateCost(model, usage);
|
|
49
|
+
applyProviderReportedUsageCost(usage, rawUsage.cost);
|
|
50
|
+
return usage;
|
|
51
|
+
}
|
|
52
|
+
function createOpenAIResponseHook(onResponse, response, model) {
|
|
53
|
+
return onResponse ? () => onResponse({
|
|
54
|
+
status: response.status,
|
|
55
|
+
headers: headersToRecord(response.headers)
|
|
56
|
+
}, model) : void 0;
|
|
57
|
+
}
|
|
58
|
+
function throwIfModelStreamAborted(signal) {
|
|
59
|
+
if (signal?.aborted) throw transportAbortError(signal);
|
|
60
|
+
}
|
|
61
|
+
/** Measure one UTF-8 append without double-counting a surrogate pair split across chunks. */
|
|
62
|
+
function measureUtf8AppendBytes(bufferEndsWithHighSurrogate, chunk) {
|
|
63
|
+
let bytes = Buffer.byteLength(chunk, "utf8");
|
|
64
|
+
if (!chunk) return {
|
|
65
|
+
bytes,
|
|
66
|
+
endsWithHighSurrogate: bufferEndsWithHighSurrogate
|
|
67
|
+
};
|
|
68
|
+
const nextCodeUnit = chunk.charCodeAt(0);
|
|
69
|
+
if (bufferEndsWithHighSurrogate && nextCodeUnit >= 56320 && nextCodeUnit <= 57343) bytes -= 2;
|
|
70
|
+
const finalCodeUnit = chunk.charCodeAt(chunk.length - 1);
|
|
71
|
+
return {
|
|
72
|
+
bytes,
|
|
73
|
+
endsWithHighSurrogate: finalCodeUnit >= 55296 && finalCodeUnit <= 56319
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function createModelStreamCooperativeScheduler(signal) {
|
|
77
|
+
let lastYieldedAt = Date.now();
|
|
78
|
+
let eventsSinceYield = 0;
|
|
79
|
+
return { async afterEvent() {
|
|
80
|
+
throwIfModelStreamAborted(signal);
|
|
81
|
+
eventsSinceYield += 1;
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
if (eventsSinceYield < MODEL_STREAM_COOPERATIVE_YIELD_MAX_EVENTS && now - lastYieldedAt < MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS) return;
|
|
84
|
+
eventsSinceYield = 0;
|
|
85
|
+
lastYieldedAt = now;
|
|
86
|
+
await new Promise((resolve) => {
|
|
87
|
+
setTimeout(resolve, 0);
|
|
88
|
+
});
|
|
89
|
+
throwIfModelStreamAborted(signal);
|
|
90
|
+
} };
|
|
91
|
+
}
|
|
92
|
+
function resolvePromptCacheKey(options, cacheRetention) {
|
|
93
|
+
if (cacheRetention === "none") return;
|
|
94
|
+
return clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId);
|
|
95
|
+
}
|
|
96
|
+
function isOpenAICompletionsThinkingEnabled(effort) {
|
|
97
|
+
const normalized = effort.trim().toLowerCase();
|
|
98
|
+
return normalized !== "off" && normalized !== "none";
|
|
99
|
+
}
|
|
100
|
+
function readOpenAICompletionsContentDeltas(content, topLevelRefusal, mirroredThinking = []) {
|
|
101
|
+
let deltas = readOpenAICompletionsContentPartDeltas(content);
|
|
102
|
+
if (mirroredThinking.length > 0) {
|
|
103
|
+
const structuredThinking = deltas.filter((delta) => delta.kind === "thinking").map((delta) => delta.text);
|
|
104
|
+
const mirrorsCombinedThinking = structuredThinking.length > 1 && mirroredThinking.includes(structuredThinking.join(""));
|
|
105
|
+
deltas = deltas.filter((delta) => delta.kind !== "thinking" || !mirrorsCombinedThinking && !mirroredThinking.includes(delta.text));
|
|
106
|
+
}
|
|
107
|
+
if (typeof topLevelRefusal !== "string" || !topLevelRefusal) return deltas;
|
|
108
|
+
const structuredRefusals = deltas.filter((delta) => delta.kind === "text" && delta.source === "refusal").map((delta) => delta.text);
|
|
109
|
+
if (structuredRefusals.some((refusal) => refusal === topLevelRefusal) || structuredRefusals.length > 1 && structuredRefusals.join("") === topLevelRefusal) return deltas;
|
|
110
|
+
return [...deltas, {
|
|
111
|
+
kind: "text",
|
|
112
|
+
text: topLevelRefusal,
|
|
113
|
+
source: "refusal"
|
|
114
|
+
}];
|
|
115
|
+
}
|
|
116
|
+
function readOpenAICompletionsContentPartDeltas(content) {
|
|
117
|
+
if (typeof content === "string") return content ? [{
|
|
118
|
+
kind: "text",
|
|
119
|
+
text: content
|
|
120
|
+
}] : [];
|
|
121
|
+
if (Array.isArray(content)) return content.flatMap(readOpenAICompletionsContentPartDeltas);
|
|
122
|
+
if (!content || typeof content !== "object") return [];
|
|
123
|
+
const record = content;
|
|
124
|
+
const type = typeof record.type === "string" ? record.type.toLowerCase() : "";
|
|
125
|
+
const extractText = (value) => {
|
|
126
|
+
if (typeof value === "string") return value;
|
|
127
|
+
if (Array.isArray(value)) return value.map(extractText).join("");
|
|
128
|
+
if (value && typeof value === "object") {
|
|
129
|
+
const nested = value;
|
|
130
|
+
return extractText(nested.text ?? nested.content ?? nested.thinking ?? nested.refusal);
|
|
131
|
+
}
|
|
132
|
+
return "";
|
|
133
|
+
};
|
|
134
|
+
const text = extractText(record.text ?? record.content ?? record.thinking ?? record.refusal);
|
|
135
|
+
if (!text) return [];
|
|
136
|
+
if (type.includes("thinking") || type.includes("reasoning")) return [{
|
|
137
|
+
kind: "thinking",
|
|
138
|
+
text
|
|
139
|
+
}];
|
|
140
|
+
if (type === "refusal") return [{
|
|
141
|
+
kind: "text",
|
|
142
|
+
text,
|
|
143
|
+
source: "refusal"
|
|
144
|
+
}];
|
|
145
|
+
if (["text", "output_text"].includes(type) || type.endsWith(".output_text")) return [{
|
|
146
|
+
kind: "text",
|
|
147
|
+
text
|
|
148
|
+
}];
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
6
152
|
//#region packages/ai/src/providers/openai-tool-projection.ts
|
|
7
153
|
function unreadableToolDiagnostic(toolIndex) {
|
|
8
154
|
return {
|
|
@@ -189,127 +335,4 @@ function reconcileOpenAICompletionsToolChoice(choice, projection) {
|
|
|
189
335
|
};
|
|
190
336
|
}
|
|
191
337
|
//#endregion
|
|
192
|
-
|
|
193
|
-
/** Shared options, usage shape, cache identity, ordering, and stream scheduling for OpenAI APIs. */
|
|
194
|
-
const MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS = 12;
|
|
195
|
-
const MODEL_STREAM_COOPERATIVE_YIELD_MAX_EVENTS = 64;
|
|
196
|
-
const GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP = "skip_thought_signature_validator";
|
|
197
|
-
const log = {
|
|
198
|
-
debug(message, data) {
|
|
199
|
-
getAiTransportHost().logDebug("openai-transport", () => ({
|
|
200
|
-
message,
|
|
201
|
-
data
|
|
202
|
-
}));
|
|
203
|
-
},
|
|
204
|
-
info(message, data) {
|
|
205
|
-
getAiTransportHost().logInfo("openai-transport", message, data);
|
|
206
|
-
},
|
|
207
|
-
warn(message, data) {
|
|
208
|
-
getAiTransportHost().logWarn("openai-transport", message, data);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
function parseOpenAICompletionsUsage(rawUsage, model, options) {
|
|
212
|
-
const cacheRead = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
|
|
213
|
-
const cacheWrite = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
214
|
-
const input = Math.max(0, (rawUsage.prompt_tokens || 0) - cacheRead - cacheWrite);
|
|
215
|
-
const output = rawUsage.completion_tokens || 0;
|
|
216
|
-
const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens;
|
|
217
|
-
const usage = {
|
|
218
|
-
input,
|
|
219
|
-
output,
|
|
220
|
-
cacheRead,
|
|
221
|
-
cacheWrite,
|
|
222
|
-
...options?.includeReasoningTokens !== false && typeof reasoningTokens === "number" && Number.isFinite(reasoningTokens) ? { reasoningTokens } : {},
|
|
223
|
-
totalTokens: input + output + cacheRead + cacheWrite,
|
|
224
|
-
cost: {
|
|
225
|
-
input: 0,
|
|
226
|
-
output: 0,
|
|
227
|
-
cacheRead: 0,
|
|
228
|
-
cacheWrite: 0,
|
|
229
|
-
total: 0
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
calculateCost(model, usage);
|
|
233
|
-
applyProviderReportedUsageCost(usage, rawUsage.cost);
|
|
234
|
-
return usage;
|
|
235
|
-
}
|
|
236
|
-
function throwIfModelStreamAborted(signal) {
|
|
237
|
-
if (signal?.aborted) throw transportAbortError(signal);
|
|
238
|
-
}
|
|
239
|
-
function createModelStreamCooperativeScheduler(signal) {
|
|
240
|
-
let lastYieldedAt = Date.now();
|
|
241
|
-
let eventsSinceYield = 0;
|
|
242
|
-
return { async afterEvent() {
|
|
243
|
-
throwIfModelStreamAborted(signal);
|
|
244
|
-
eventsSinceYield += 1;
|
|
245
|
-
const now = Date.now();
|
|
246
|
-
if (eventsSinceYield < MODEL_STREAM_COOPERATIVE_YIELD_MAX_EVENTS && now - lastYieldedAt < MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS) return;
|
|
247
|
-
eventsSinceYield = 0;
|
|
248
|
-
lastYieldedAt = now;
|
|
249
|
-
await new Promise((resolve) => {
|
|
250
|
-
setTimeout(resolve, 0);
|
|
251
|
-
});
|
|
252
|
-
throwIfModelStreamAborted(signal);
|
|
253
|
-
} };
|
|
254
|
-
}
|
|
255
|
-
function resolvePromptCacheKey(options, cacheRetention) {
|
|
256
|
-
if (cacheRetention === "none") return;
|
|
257
|
-
return clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId);
|
|
258
|
-
}
|
|
259
|
-
function isOpenAICompletionsThinkingEnabled(effort) {
|
|
260
|
-
const normalized = effort.trim().toLowerCase();
|
|
261
|
-
return normalized !== "off" && normalized !== "none";
|
|
262
|
-
}
|
|
263
|
-
function readOpenAICompletionsContentDeltas(content, topLevelRefusal, mirroredThinking = []) {
|
|
264
|
-
let deltas = readOpenAICompletionsContentPartDeltas(content);
|
|
265
|
-
if (mirroredThinking.length > 0) {
|
|
266
|
-
const structuredThinking = deltas.filter((delta) => delta.kind === "thinking").map((delta) => delta.text);
|
|
267
|
-
const mirrorsCombinedThinking = structuredThinking.length > 1 && mirroredThinking.includes(structuredThinking.join(""));
|
|
268
|
-
deltas = deltas.filter((delta) => delta.kind !== "thinking" || !mirrorsCombinedThinking && !mirroredThinking.includes(delta.text));
|
|
269
|
-
}
|
|
270
|
-
if (typeof topLevelRefusal !== "string" || !topLevelRefusal) return deltas;
|
|
271
|
-
const structuredRefusals = deltas.filter((delta) => delta.kind === "text" && delta.source === "refusal").map((delta) => delta.text);
|
|
272
|
-
if (structuredRefusals.some((refusal) => refusal === topLevelRefusal) || structuredRefusals.length > 1 && structuredRefusals.join("") === topLevelRefusal) return deltas;
|
|
273
|
-
return [...deltas, {
|
|
274
|
-
kind: "text",
|
|
275
|
-
text: topLevelRefusal,
|
|
276
|
-
source: "refusal"
|
|
277
|
-
}];
|
|
278
|
-
}
|
|
279
|
-
function readOpenAICompletionsContentPartDeltas(content) {
|
|
280
|
-
if (typeof content === "string") return content ? [{
|
|
281
|
-
kind: "text",
|
|
282
|
-
text: content
|
|
283
|
-
}] : [];
|
|
284
|
-
if (Array.isArray(content)) return content.flatMap(readOpenAICompletionsContentPartDeltas);
|
|
285
|
-
if (!content || typeof content !== "object") return [];
|
|
286
|
-
const record = content;
|
|
287
|
-
const type = typeof record.type === "string" ? record.type.toLowerCase() : "";
|
|
288
|
-
const extractText = (value) => {
|
|
289
|
-
if (typeof value === "string") return value;
|
|
290
|
-
if (Array.isArray(value)) return value.map(extractText).join("");
|
|
291
|
-
if (value && typeof value === "object") {
|
|
292
|
-
const nested = value;
|
|
293
|
-
return extractText(nested.text ?? nested.content ?? nested.thinking ?? nested.refusal);
|
|
294
|
-
}
|
|
295
|
-
return "";
|
|
296
|
-
};
|
|
297
|
-
const text = extractText(record.text ?? record.content ?? record.thinking ?? record.refusal);
|
|
298
|
-
if (!text) return [];
|
|
299
|
-
if (type.includes("thinking") || type.includes("reasoning")) return [{
|
|
300
|
-
kind: "thinking",
|
|
301
|
-
text
|
|
302
|
-
}];
|
|
303
|
-
if (type === "refusal") return [{
|
|
304
|
-
kind: "text",
|
|
305
|
-
text,
|
|
306
|
-
source: "refusal"
|
|
307
|
-
}];
|
|
308
|
-
if (["text", "output_text"].includes(type) || type.endsWith(".output_text")) return [{
|
|
309
|
-
kind: "text",
|
|
310
|
-
text
|
|
311
|
-
}];
|
|
312
|
-
return [];
|
|
313
|
-
}
|
|
314
|
-
//#endregion
|
|
315
|
-
export { parseOpenAICompletionsUsage as a, throwIfModelStreamAborted as c, reconcileOpenAIResponsesToolChoice as d, log as i, projectOpenAITools as l, createModelStreamCooperativeScheduler as n, readOpenAICompletionsContentDeltas as o, isOpenAICompletionsThinkingEnabled as r, resolvePromptCacheKey as s, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP as t, reconcileOpenAICompletionsToolChoice as u };
|
|
338
|
+
export { createModelStreamCooperativeScheduler as a, log as c, readOpenAICompletionsContentDeltas as d, resolvePromptCacheKey as f, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP as i, measureUtf8AppendBytes as l, reconcileOpenAICompletionsToolChoice as n, createOpenAIResponseHook as o, throwIfModelStreamAborted as p, reconcileOpenAIResponsesToolChoice as r, isOpenAICompletionsThinkingEnabled as s, projectOpenAITools as t, parseOpenAICompletionsUsage as u };
|