@openclaw/ai 2026.8.1-beta.3 → 2026.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-B8KwTtlb.mjs → anthropic-DTGZ4VMY.mjs} +25 -23
- package/dist/{anthropic-compaction-replay-4Zx7-aCr.mjs → anthropic-compaction-replay-CKCDrZJv.mjs} +34 -35
- package/dist/{anthropic-payload-policy-CSx7MoKH.d.mts → anthropic-payload-policy-BTzmNC14.d.mts} +3 -2
- package/dist/{api-registry-DFxSnFqG.d.mts → api-registry-BbUHEKER.d.mts} +2 -1
- package/dist/{azure-openai-responses-Aa4mVcYG.mjs → azure-openai-responses-BmqaDXM1.mjs} +6 -5
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/diagnostics.d.mts +2 -3
- package/dist/diagnostics.mjs +1 -1
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/{event-stream-D91-ohD_.d.mts → event-stream-DcvAPSBe.d.mts} +1 -2
- package/dist/event-stream-pXT3FI6X.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -1
- package/dist/{google-yDRnipeq.mjs → google-CqjVZMwo.mjs} +8 -6
- package/dist/{google-shared-M1dl64nz.mjs → google-shared-Bnqni5j3.mjs} +34 -25
- package/dist/{google-vertex-DCJHM_a5.mjs → google-vertex-D_WREEJi.mjs} +8 -6
- package/dist/{host-DF_yxOsA.mjs → host-BIaiBURL.mjs} +4 -8
- package/dist/{host-DJq_FGcz.d.mts → host-DKFUAmCn.d.mts} +3 -3
- package/dist/index-CefaUGSS.d.mts +111 -0
- package/dist/index.d.mts +9 -10
- package/dist/index.mjs +4 -5
- package/dist/internal/anthropic.d.mts +51 -49
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +2 -3
- package/dist/internal/openai.d.mts +65 -63
- package/dist/internal/openai.mjs +10 -9
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +51 -40
- package/dist/internal/runtime.mjs +9 -9
- package/dist/internal/shared.d.mts +25 -25
- package/dist/internal/shared.mjs +3 -3
- package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
- package/dist/{mistral-D6hRXI7A.mjs → mistral-C24jVd6f.mjs} +34 -32
- package/dist/{openai-chatgpt-responses-C339VIfT.mjs → openai-chatgpt-responses-Czum0oXz.mjs} +38 -20
- package/dist/openai-completions-BfFwac6f.mjs +404 -0
- package/dist/{openai-completions-compat-B0KTleXp.d.mts → openai-completions-compat-SZhi0Lf4.d.mts} +3 -3
- package/dist/openai-completions-stream-DGOvau4J.mjs +1625 -0
- package/dist/{openai-responses-BXEcr-Tp.mjs → openai-responses-BAryVEJM.mjs} +11 -7
- package/dist/openai-responses-compaction-window-DO7yV7az.mjs +686 -0
- package/dist/{openai-responses-contracts-CD75pQ0m.d.mts → openai-responses-contracts-BthRXano.d.mts} +14 -5
- package/dist/{openai-responses-payload-policy-CNGFT9zr.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +1 -0
- package/dist/{openai-responses-prompt-observer-internal-BG-1AsBI.mjs → openai-responses-prompt-observer-internal--R0kZLOZ.mjs} +3 -2
- package/dist/{openai-responses-shared-Cvt5MgEm.mjs → openai-responses-shared-CxgdGBvm.mjs} +332 -1484
- package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
- package/dist/openai-tool-schema-CSMh5e9O.mjs +1697 -0
- package/dist/{provider-error-C8mBRJDl.mjs → provider-error-BI8kIViN.mjs} +14 -88
- package/dist/{provider-options-Cc5ZQ6Aa.d.mts → provider-options-DJd_9euj.d.mts} +13 -4
- package/dist/{provider-transcript-transform--gtf0ZbR.mjs → provider-transcript-transform-WvJmFUAf.mjs} +1 -1
- package/dist/provider-types.d.mts +18 -17
- package/dist/providers.d.mts +5 -6
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-BsUX44Tq.mjs} +30 -20
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-BP7HLLZn.mjs → sanitize-unicode-S6binQG-.mjs} +2 -9
- package/dist/simple-options-rdOPzr7Z.mjs +155 -0
- package/dist/{anthropic-BQXQudmA.mjs → src-C8U7lkoa.mjs} +75 -1
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
- package/dist/string-normalization--fwJ4S2q.mjs +16 -0
- package/dist/{tool-schema-json-projection-FEr-jOoZ.mjs → tool-schema-json-projection-BtZiml7r.mjs} +22 -32
- package/dist/transport-stream-shared-BbG7PThh.d.mts +138 -0
- package/dist/{simple-options-oqsXB6U3.mjs → transport-stream-shared-D8nQWCUo.mjs} +10 -118
- package/dist/{transport-utils-Bv0FHkd0.mjs → transport-utils-CtuS1Upe.mjs} +10 -10
- package/dist/transports.d.mts +130 -189
- package/dist/transports.mjs +227 -1249
- package/dist/{types-DTAP49HF.d.mts → types-Beemor2E.d.mts} +58 -24
- package/dist/types-COdhCX0U.d.mts +1 -0
- package/dist/types.d.mts +6 -5
- package/dist/types.mjs +3 -4
- package/dist/utf16-slice-qz3nsy87.mjs +84 -0
- package/dist/{validation-DYNNrU9u.d.mts → validation-CC6s7Smp.d.mts} +1 -2
- package/dist/{validation-B61OhAio.mjs → validation-CJZtym2g.mjs} +7 -5
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +6 -6
- package/dist/anthropic-BECQCNdF.d.mts +0 -98
- package/dist/event-stream-BVVgDSdq.d.mts +0 -1
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/index-BVVgDSdq.d.mts +0 -1
- package/dist/openai-completions-D88orSJ9.mjs +0 -632
- package/dist/openai-responses-contracts-DvILoqBk.mjs +0 -247
- package/dist/openai-responses-payload-policy-BDo8CQsx.mjs +0 -208
- package/dist/openai-stop-reason-9OONKyAm.mjs +0 -579
- package/dist/openai-tool-projection-CHGLt03m.mjs +0 -426
- package/dist/provider-options-AvldWZt8.mjs +0 -21
- package/dist/record-coerce-DdXsgUd_.mjs +0 -23
- package/dist/src-D2H6yKkH.mjs +0 -2
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
- package/dist/string-coerce-fsri9iCu.mjs +0 -34
- package/dist/types-BVVgDSdq.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
import { n as applyProviderReportedUsageCost, r as calculateCost } from "./sanitize-unicode-BP7HLLZn.mjs";
|
|
2
|
-
import { n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
|
|
3
|
-
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
4
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
5
|
-
import { g as notifyProviderHttpResponse, x as transportAbortError } from "./simple-options-oqsXB6U3.mjs";
|
|
6
|
-
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-FEr-jOoZ.mjs";
|
|
7
|
-
import { t as headersToRecord } from "./headers-B_e4-1J0.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
|
-
const EMPTY_OPENAI_COMPLETIONS_REASONING_BATCH = {
|
|
28
|
-
deltas: [],
|
|
29
|
-
mirroredThinking: [],
|
|
30
|
-
hasThinking: false,
|
|
31
|
-
hasVisibleText: false
|
|
32
|
-
};
|
|
33
|
-
const OPENAI_COMPLETIONS_REASONING_FIELDS = [
|
|
34
|
-
"reasoning_content",
|
|
35
|
-
"reasoning",
|
|
36
|
-
"reasoning_text"
|
|
37
|
-
];
|
|
38
|
-
function appendOpenAICompletionsReasoningDelta(batch, next) {
|
|
39
|
-
if (next.kind === "thinking") batch.hasThinking = true;
|
|
40
|
-
else batch.hasVisibleText = true;
|
|
41
|
-
const previous = batch.deltas[batch.deltas.length - 1];
|
|
42
|
-
if (!previous || previous.kind !== next.kind) {
|
|
43
|
-
batch.deltas.push(next);
|
|
44
|
-
if (next.kind === "thinking") batch.mirroredThinking.push(next.text);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (next.kind === "thinking" && previous.kind === "thinking") {
|
|
48
|
-
if (previous.signature !== next.signature) {
|
|
49
|
-
batch.deltas.push(next);
|
|
50
|
-
batch.mirroredThinking.push(next.text);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
previous.text += next.text;
|
|
54
|
-
batch.mirroredThinking[batch.mirroredThinking.length - 1] += next.text;
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
previous.text += next.text;
|
|
58
|
-
}
|
|
59
|
-
function createOpenAICompletionsReasoningBatch() {
|
|
60
|
-
return {
|
|
61
|
-
deltas: [],
|
|
62
|
-
mirroredThinking: [],
|
|
63
|
-
hasThinking: false,
|
|
64
|
-
hasVisibleText: false
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function readOpenAICompletionsReasoningBatch(delta, visibleReasoningDetailTypes) {
|
|
68
|
-
let batch;
|
|
69
|
-
const reasoningDetails = delta.reasoning_details;
|
|
70
|
-
let usedReasoningThinkingDetails = false;
|
|
71
|
-
if (Array.isArray(reasoningDetails)) for (const item of reasoningDetails) {
|
|
72
|
-
if (!isRecord(item)) continue;
|
|
73
|
-
const detail = item;
|
|
74
|
-
if (typeof detail.text !== "string" || !detail.text) continue;
|
|
75
|
-
if (detail.type === "reasoning.text") {
|
|
76
|
-
usedReasoningThinkingDetails = true;
|
|
77
|
-
batch ??= createOpenAICompletionsReasoningBatch();
|
|
78
|
-
appendOpenAICompletionsReasoningDelta(batch, {
|
|
79
|
-
kind: "thinking",
|
|
80
|
-
signature: "reasoning_details",
|
|
81
|
-
text: detail.text
|
|
82
|
-
});
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (typeof detail.type === "string" && visibleReasoningDetailTypes.has(detail.type)) {
|
|
86
|
-
batch ??= createOpenAICompletionsReasoningBatch();
|
|
87
|
-
appendOpenAICompletionsReasoningDelta(batch, {
|
|
88
|
-
kind: "text",
|
|
89
|
-
text: detail.text,
|
|
90
|
-
source: "reasoning_detail"
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (!usedReasoningThinkingDetails) for (const field of OPENAI_COMPLETIONS_REASONING_FIELDS) {
|
|
95
|
-
const value = delta[field];
|
|
96
|
-
if (typeof value === "string" && value.length > 0) {
|
|
97
|
-
batch ??= createOpenAICompletionsReasoningBatch();
|
|
98
|
-
appendOpenAICompletionsReasoningDelta(batch, {
|
|
99
|
-
kind: "thinking",
|
|
100
|
-
signature: field,
|
|
101
|
-
text: value
|
|
102
|
-
});
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return batch ?? EMPTY_OPENAI_COMPLETIONS_REASONING_BATCH;
|
|
107
|
-
}
|
|
108
|
-
function parseOpenAICompletionsUsage(rawUsage, model, options) {
|
|
109
|
-
const cacheRead = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
|
|
110
|
-
const cacheWrite = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
111
|
-
const input = Math.max(0, (rawUsage.prompt_tokens || 0) - cacheRead - cacheWrite);
|
|
112
|
-
const output = rawUsage.completion_tokens || 0;
|
|
113
|
-
const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens;
|
|
114
|
-
const usage = {
|
|
115
|
-
input,
|
|
116
|
-
output,
|
|
117
|
-
cacheRead,
|
|
118
|
-
cacheWrite,
|
|
119
|
-
...options?.includeReasoningTokens !== false && typeof reasoningTokens === "number" && Number.isFinite(reasoningTokens) ? { reasoningTokens } : {},
|
|
120
|
-
totalTokens: input + output + cacheRead + cacheWrite,
|
|
121
|
-
cost: {
|
|
122
|
-
input: 0,
|
|
123
|
-
output: 0,
|
|
124
|
-
cacheRead: 0,
|
|
125
|
-
cacheWrite: 0,
|
|
126
|
-
total: 0
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
calculateCost(model, usage);
|
|
130
|
-
applyProviderReportedUsageCost(usage, rawUsage.cost);
|
|
131
|
-
return usage;
|
|
132
|
-
}
|
|
133
|
-
function createOpenAIResponseHook(onResponse, response, model) {
|
|
134
|
-
return onResponse ? () => onResponse({
|
|
135
|
-
status: response.status,
|
|
136
|
-
headers: headersToRecord(response.headers)
|
|
137
|
-
}, model) : void 0;
|
|
138
|
-
}
|
|
139
|
-
function createOpenAIProviderAcceptanceHook(options, response, model) {
|
|
140
|
-
return () => notifyProviderHttpResponse({
|
|
141
|
-
options,
|
|
142
|
-
response,
|
|
143
|
-
model
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
function throwIfModelStreamAborted(signal) {
|
|
147
|
-
if (signal?.aborted) throw transportAbortError(signal);
|
|
148
|
-
}
|
|
149
|
-
/** Measure one UTF-8 append without double-counting a surrogate pair split across chunks. */
|
|
150
|
-
function measureUtf8AppendBytes(bufferEndsWithHighSurrogate, chunk) {
|
|
151
|
-
let bytes = Buffer.byteLength(chunk, "utf8");
|
|
152
|
-
if (!chunk) return {
|
|
153
|
-
bytes,
|
|
154
|
-
endsWithHighSurrogate: bufferEndsWithHighSurrogate
|
|
155
|
-
};
|
|
156
|
-
const nextCodeUnit = chunk.charCodeAt(0);
|
|
157
|
-
if (bufferEndsWithHighSurrogate && nextCodeUnit >= 56320 && nextCodeUnit <= 57343) bytes -= 2;
|
|
158
|
-
const finalCodeUnit = chunk.charCodeAt(chunk.length - 1);
|
|
159
|
-
return {
|
|
160
|
-
bytes,
|
|
161
|
-
endsWithHighSurrogate: finalCodeUnit >= 55296 && finalCodeUnit <= 56319
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function createModelStreamCooperativeScheduler(signal) {
|
|
165
|
-
let lastYieldedAt = Date.now();
|
|
166
|
-
let eventsSinceYield = 0;
|
|
167
|
-
return { async afterEvent() {
|
|
168
|
-
throwIfModelStreamAborted(signal);
|
|
169
|
-
eventsSinceYield += 1;
|
|
170
|
-
const now = Date.now();
|
|
171
|
-
if (eventsSinceYield < MODEL_STREAM_COOPERATIVE_YIELD_MAX_EVENTS && now - lastYieldedAt < MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS) return;
|
|
172
|
-
eventsSinceYield = 0;
|
|
173
|
-
lastYieldedAt = now;
|
|
174
|
-
await new Promise((resolve) => {
|
|
175
|
-
setTimeout(resolve, 0);
|
|
176
|
-
});
|
|
177
|
-
throwIfModelStreamAborted(signal);
|
|
178
|
-
} };
|
|
179
|
-
}
|
|
180
|
-
function resolvePromptCacheKey(options, cacheRetention) {
|
|
181
|
-
if (cacheRetention === "none") return;
|
|
182
|
-
return clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId);
|
|
183
|
-
}
|
|
184
|
-
function isOpenAICompletionsThinkingEnabled(effort) {
|
|
185
|
-
const normalized = effort.trim().toLowerCase();
|
|
186
|
-
return normalized !== "off" && normalized !== "none";
|
|
187
|
-
}
|
|
188
|
-
function readOpenAICompletionsContentDeltas(content, topLevelRefusal, mirroredThinking = []) {
|
|
189
|
-
let deltas = readOpenAICompletionsContentPartDeltas(content);
|
|
190
|
-
if (mirroredThinking.length > 0) {
|
|
191
|
-
const structuredThinking = deltas.filter((delta) => delta.kind === "thinking").map((delta) => delta.text);
|
|
192
|
-
const mirrorsCombinedThinking = structuredThinking.length > 1 && mirroredThinking.includes(structuredThinking.join(""));
|
|
193
|
-
deltas = deltas.filter((delta) => delta.kind !== "thinking" || !mirrorsCombinedThinking && !mirroredThinking.includes(delta.text));
|
|
194
|
-
}
|
|
195
|
-
if (typeof topLevelRefusal !== "string" || !topLevelRefusal) return deltas;
|
|
196
|
-
const structuredRefusals = deltas.filter((delta) => delta.kind === "text" && delta.source === "refusal").map((delta) => delta.text);
|
|
197
|
-
if (structuredRefusals.some((refusal) => refusal === topLevelRefusal) || structuredRefusals.length > 1 && structuredRefusals.join("") === topLevelRefusal) return deltas;
|
|
198
|
-
return [...deltas, {
|
|
199
|
-
kind: "text",
|
|
200
|
-
text: topLevelRefusal,
|
|
201
|
-
source: "refusal"
|
|
202
|
-
}];
|
|
203
|
-
}
|
|
204
|
-
function readOpenAICompletionsContentPartDeltas(content) {
|
|
205
|
-
if (typeof content === "string") return content ? [{
|
|
206
|
-
kind: "text",
|
|
207
|
-
text: content
|
|
208
|
-
}] : [];
|
|
209
|
-
if (Array.isArray(content)) return content.flatMap(readOpenAICompletionsContentPartDeltas);
|
|
210
|
-
if (!content || typeof content !== "object") return [];
|
|
211
|
-
const record = content;
|
|
212
|
-
const type = typeof record.type === "string" ? record.type.toLowerCase() : "";
|
|
213
|
-
const extractText = (value) => {
|
|
214
|
-
if (typeof value === "string") return value;
|
|
215
|
-
if (Array.isArray(value)) return value.map(extractText).join("");
|
|
216
|
-
if (value && typeof value === "object") {
|
|
217
|
-
const nested = value;
|
|
218
|
-
return extractText(nested.text ?? nested.content ?? nested.thinking ?? nested.refusal);
|
|
219
|
-
}
|
|
220
|
-
return "";
|
|
221
|
-
};
|
|
222
|
-
const text = extractText(record.text ?? record.content ?? record.thinking ?? record.refusal);
|
|
223
|
-
if (!text) return [];
|
|
224
|
-
if (type.includes("thinking") || type.includes("reasoning")) return [{
|
|
225
|
-
kind: "thinking",
|
|
226
|
-
text
|
|
227
|
-
}];
|
|
228
|
-
if (type === "refusal") return [{
|
|
229
|
-
kind: "text",
|
|
230
|
-
text,
|
|
231
|
-
source: "refusal"
|
|
232
|
-
}];
|
|
233
|
-
if (["text", "output_text"].includes(type) || type.endsWith(".output_text")) return [{
|
|
234
|
-
kind: "text",
|
|
235
|
-
text
|
|
236
|
-
}];
|
|
237
|
-
return [];
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region packages/ai/src/providers/openai-tool-projection.ts
|
|
241
|
-
function unreadableToolDiagnostic(toolIndex) {
|
|
242
|
-
return {
|
|
243
|
-
toolIndex,
|
|
244
|
-
violations: [`tool[${toolIndex}] is unreadable`]
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
/** Snapshots direct/custom tool descriptors before OpenAI payload construction. */
|
|
248
|
-
function projectOpenAITools(tools) {
|
|
249
|
-
let inputToolCount;
|
|
250
|
-
try {
|
|
251
|
-
inputToolCount = tools.length;
|
|
252
|
-
} catch {
|
|
253
|
-
return {
|
|
254
|
-
inputToolCount: 0,
|
|
255
|
-
tools: [],
|
|
256
|
-
diagnostics: [unreadableToolDiagnostic(0)]
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
const projectedTools = [];
|
|
260
|
-
const diagnostics = [];
|
|
261
|
-
for (let toolIndex = 0; toolIndex < inputToolCount; toolIndex += 1) {
|
|
262
|
-
let tool;
|
|
263
|
-
try {
|
|
264
|
-
const candidate = tools[toolIndex];
|
|
265
|
-
if (!candidate) {
|
|
266
|
-
diagnostics.push(unreadableToolDiagnostic(toolIndex));
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
tool = candidate;
|
|
270
|
-
} catch {
|
|
271
|
-
diagnostics.push(unreadableToolDiagnostic(toolIndex));
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
let name;
|
|
275
|
-
try {
|
|
276
|
-
name = tool.name;
|
|
277
|
-
} catch {
|
|
278
|
-
diagnostics.push({
|
|
279
|
-
toolIndex,
|
|
280
|
-
violations: [`tool[${toolIndex}].name is unreadable`]
|
|
281
|
-
});
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (typeof name !== "string" || !name) {
|
|
285
|
-
diagnostics.push({
|
|
286
|
-
toolIndex,
|
|
287
|
-
violations: [`tool[${toolIndex}].name is empty`]
|
|
288
|
-
});
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
let parameters;
|
|
292
|
-
try {
|
|
293
|
-
parameters = tool.parameters;
|
|
294
|
-
} catch {
|
|
295
|
-
diagnostics.push({
|
|
296
|
-
toolIndex,
|
|
297
|
-
toolName: name,
|
|
298
|
-
violations: [`${name}.parameters is unreadable`]
|
|
299
|
-
});
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
const schemaProjection = projectRuntimeToolInputSchema(parameters ?? {}, `${name}.parameters`);
|
|
303
|
-
if (!isRecord(schemaProjection.schema) || schemaProjection.violations.length > 0) {
|
|
304
|
-
diagnostics.push({
|
|
305
|
-
toolIndex,
|
|
306
|
-
toolName: name,
|
|
307
|
-
violations: schemaProjection.violations.length > 0 ? schemaProjection.violations : [`${name}.parameters must be a JSON object schema`]
|
|
308
|
-
});
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
let descriptionValue;
|
|
312
|
-
try {
|
|
313
|
-
descriptionValue = tool.description;
|
|
314
|
-
} catch {}
|
|
315
|
-
const description = typeof descriptionValue === "string" ? descriptionValue : void 0;
|
|
316
|
-
projectedTools.push({
|
|
317
|
-
toolIndex,
|
|
318
|
-
name,
|
|
319
|
-
...description !== void 0 ? { description } : {},
|
|
320
|
-
parameters: schemaProjection.schema
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
return {
|
|
324
|
-
inputToolCount,
|
|
325
|
-
tools: projectedTools,
|
|
326
|
-
diagnostics
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function requireProjectedFunction(name, projection, choiceLabel) {
|
|
330
|
-
if (!projection.tools.some((tool) => tool.name === name)) throw new Error(`${choiceLabel} requested unavailable tool "${name}" after schema conversion`);
|
|
331
|
-
}
|
|
332
|
-
/** Keeps Responses tool choices aligned with surviving function schemas. */
|
|
333
|
-
function reconcileOpenAIResponsesToolChoice(choice, projection) {
|
|
334
|
-
if (choice === "auto") return projection.tools.length > 0 ? choice : void 0;
|
|
335
|
-
if (choice === "required") {
|
|
336
|
-
if (projection.tools.length === 0) throw new Error("OpenAI Responses tool_choice requires a tool, but no tools survived schema conversion");
|
|
337
|
-
return choice;
|
|
338
|
-
}
|
|
339
|
-
if (choice === "none" || !isRecord(choice)) return choice;
|
|
340
|
-
const choiceType = choice.type;
|
|
341
|
-
if (choiceType === "function") {
|
|
342
|
-
const functionName = choice.name;
|
|
343
|
-
if (typeof functionName !== "string") return choice;
|
|
344
|
-
requireProjectedFunction(functionName, projection, "OpenAI Responses tool_choice");
|
|
345
|
-
return {
|
|
346
|
-
type: "function",
|
|
347
|
-
name: functionName
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
if (choiceType !== "allowed_tools") return choice;
|
|
351
|
-
const mode = choice.mode;
|
|
352
|
-
const tools = choice.tools;
|
|
353
|
-
if (mode !== "auto" && mode !== "required" || !Array.isArray(tools)) return choice;
|
|
354
|
-
const normalizedAllowedTools = [];
|
|
355
|
-
for (const tool of tools) {
|
|
356
|
-
if (!isRecord(tool) || tool.type !== "function") {
|
|
357
|
-
normalizedAllowedTools.push(tool);
|
|
358
|
-
continue;
|
|
359
|
-
}
|
|
360
|
-
const functionName = tool.name;
|
|
361
|
-
if (typeof functionName === "string" && projection.tools.some((projectedTool) => projectedTool.name === functionName)) normalizedAllowedTools.push({
|
|
362
|
-
type: "function",
|
|
363
|
-
name: functionName
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
if (normalizedAllowedTools.length === 0) {
|
|
367
|
-
if (mode === "auto") return "none";
|
|
368
|
-
throw new Error("OpenAI Responses tool_choice requires a tool, but no allowed tools survived schema conversion");
|
|
369
|
-
}
|
|
370
|
-
return {
|
|
371
|
-
type: "allowed_tools",
|
|
372
|
-
mode,
|
|
373
|
-
tools: normalizedAllowedTools
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
/** Keeps Chat Completions tool choices aligned with surviving function schemas. */
|
|
377
|
-
function reconcileOpenAICompletionsToolChoice(choice, projection) {
|
|
378
|
-
if (choice === "auto") return projection.tools.length > 0 ? choice : void 0;
|
|
379
|
-
if (choice === "required") {
|
|
380
|
-
if (projection.tools.length === 0) throw new Error("OpenAI Chat Completions tool_choice requires a tool, but no tools survived schema conversion");
|
|
381
|
-
return choice;
|
|
382
|
-
}
|
|
383
|
-
if (choice === "none" || !isRecord(choice)) return choice;
|
|
384
|
-
const choiceType = choice.type;
|
|
385
|
-
if (choiceType === "custom") throw new Error("OpenAI Chat Completions custom tool_choice is unsupported because this adapter emits function tools only");
|
|
386
|
-
if (choiceType === "function") {
|
|
387
|
-
const functionChoice = choice.function;
|
|
388
|
-
if (!isRecord(functionChoice)) return choice;
|
|
389
|
-
const functionName = functionChoice.name;
|
|
390
|
-
if (typeof functionName !== "string") return choice;
|
|
391
|
-
requireProjectedFunction(functionName, projection, "OpenAI Chat Completions tool_choice");
|
|
392
|
-
return {
|
|
393
|
-
type: "function",
|
|
394
|
-
function: { name: functionName }
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
if (choiceType !== "allowed_tools") return choice;
|
|
398
|
-
const allowedConfig = choice.allowed_tools;
|
|
399
|
-
if (!isRecord(allowedConfig)) return choice;
|
|
400
|
-
const mode = allowedConfig.mode;
|
|
401
|
-
const tools = allowedConfig.tools;
|
|
402
|
-
if (mode !== "auto" && mode !== "required" || !Array.isArray(tools)) return choice;
|
|
403
|
-
const normalizedAllowedTools = [];
|
|
404
|
-
for (const tool of tools) {
|
|
405
|
-
if (!isRecord(tool) || tool.type !== "function") continue;
|
|
406
|
-
const functionChoice = tool.function;
|
|
407
|
-
const functionName = isRecord(functionChoice) ? functionChoice.name : void 0;
|
|
408
|
-
if (typeof functionName === "string" && projection.tools.some((projectedTool) => projectedTool.name === functionName)) normalizedAllowedTools.push({
|
|
409
|
-
type: "function",
|
|
410
|
-
function: { name: functionName }
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
if (normalizedAllowedTools.length === 0) {
|
|
414
|
-
if (mode === "auto") return "none";
|
|
415
|
-
throw new Error("OpenAI Chat Completions tool_choice requires a tool, but no allowed tools survived schema conversion");
|
|
416
|
-
}
|
|
417
|
-
return {
|
|
418
|
-
type: "allowed_tools",
|
|
419
|
-
allowed_tools: {
|
|
420
|
-
mode,
|
|
421
|
-
tools: normalizedAllowedTools
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
//#endregion
|
|
426
|
-
export { createModelStreamCooperativeScheduler as a, isOpenAICompletionsThinkingEnabled as c, parseOpenAICompletionsUsage as d, readOpenAICompletionsContentDeltas as f, throwIfModelStreamAborted as h, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP as i, log as l, resolvePromptCacheKey as m, reconcileOpenAICompletionsToolChoice as n, createOpenAIProviderAcceptanceHook as o, readOpenAICompletionsReasoningBatch as p, reconcileOpenAIResponsesToolChoice as r, createOpenAIResponseHook as s, projectOpenAITools as t, measureUtf8AppendBytes as u };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/provider-options.ts
|
|
2
|
-
const CODE_MODE_TOOL_SURFACE_OBSERVER = Symbol("openaiCodeModeToolSurfaceObserver");
|
|
3
|
-
const CODE_MODE_TOOL_SURFACE_COLLECTOR = Symbol("openaiCodeModeToolSurfaceCollector");
|
|
4
|
-
const codeModeToolSurfaceObserver = {
|
|
5
|
-
set(options, observer, collector) {
|
|
6
|
-
Reflect.set(options, CODE_MODE_TOOL_SURFACE_OBSERVER, observer);
|
|
7
|
-
if (collector) Reflect.set(options, CODE_MODE_TOOL_SURFACE_COLLECTOR, collector);
|
|
8
|
-
},
|
|
9
|
-
get(options) {
|
|
10
|
-
if (!options) return;
|
|
11
|
-
const observer = Reflect.get(options, CODE_MODE_TOOL_SURFACE_OBSERVER);
|
|
12
|
-
return typeof observer === "function" ? (observation) => observer(observation) : void 0;
|
|
13
|
-
},
|
|
14
|
-
getCollector(options) {
|
|
15
|
-
if (!options) return;
|
|
16
|
-
const collector = Reflect.get(options, CODE_MODE_TOOL_SURFACE_COLLECTOR);
|
|
17
|
-
return typeof collector === "function" ? (observation) => collector(observation) : void 0;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
export { codeModeToolSurfaceObserver as t };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//#region packages/normalization-core/src/record-coerce.ts
|
|
2
|
-
/** Type guard for non-array object records at browser-safe boundaries. */
|
|
3
|
-
function isRecord(value) {
|
|
4
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
-
}
|
|
6
|
-
/** Returns a non-array record or undefined. */
|
|
7
|
-
function asOptionalRecord(value) {
|
|
8
|
-
return isRecord(value) ? value : void 0;
|
|
9
|
-
}
|
|
10
|
-
/** Returns a non-array record or a fresh ordinary empty record. */
|
|
11
|
-
function asNonArrayRecord(value) {
|
|
12
|
-
return asOptionalRecord(value) ?? {};
|
|
13
|
-
}
|
|
14
|
-
/** Returns a non-array record or null. */
|
|
15
|
-
function asNullableRecord(value) {
|
|
16
|
-
return isRecord(value) ? value : null;
|
|
17
|
-
}
|
|
18
|
-
/** Returns any object-backed record, including arrays, or undefined. */
|
|
19
|
-
function asOptionalObjectRecord(value) {
|
|
20
|
-
return value && typeof value === "object" ? value : void 0;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { isRecord as a, asOptionalRecord as i, asNullableRecord as n, asOptionalObjectRecord as r, asNonArrayRecord as t };
|
package/dist/src-D2H6yKkH.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/utils/stream-first-event-timeout.d.ts
|
|
2
|
-
type StreamStage = "responses" | "completions";
|
|
3
|
-
type FirstStreamEventTimeoutContext = {
|
|
4
|
-
provider?: string;
|
|
5
|
-
api?: string;
|
|
6
|
-
model?: string;
|
|
7
|
-
timeoutMs: number;
|
|
8
|
-
stage?: StreamStage;
|
|
9
|
-
hint?: string;
|
|
10
|
-
abort?: (reason: Error) => void;
|
|
11
|
-
onTimeout?: (reason: Error) => void;
|
|
12
|
-
};
|
|
13
|
-
type FirstStreamEventInternalOptions = {
|
|
14
|
-
firstEventTimeoutMs?: number;
|
|
15
|
-
abortFirstEventStream?: (reason: Error) => void;
|
|
16
|
-
onFirstEventTimeout?: (reason: Error) => void;
|
|
17
|
-
};
|
|
18
|
-
type FirstStreamEventAbortController = {
|
|
19
|
-
signal: AbortSignal;
|
|
20
|
-
abort: (reason: Error) => void;
|
|
21
|
-
dispose: () => void;
|
|
22
|
-
};
|
|
23
|
-
declare function getFirstStreamEventTimeoutMs(options: unknown): number | undefined;
|
|
24
|
-
declare function getFirstStreamEventTimeoutHandler(options: unknown): ((reason: Error) => void) | undefined;
|
|
25
|
-
declare function createFirstStreamEventTimeoutError(context: FirstStreamEventTimeoutContext): Error;
|
|
26
|
-
declare function createFirstStreamEventAbortController(parentSignal?: AbortSignal): FirstStreamEventAbortController;
|
|
27
|
-
declare function withFirstStreamEventTimeout<T>(stream: AsyncIterable<T>, context: FirstStreamEventTimeoutContext): AsyncIterable<T>;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { createFirstStreamEventTimeoutError as a, withFirstStreamEventTimeout as c, createFirstStreamEventAbortController as i, FirstStreamEventInternalOptions as n, getFirstStreamEventTimeoutHandler as o, FirstStreamEventTimeoutContext as r, getFirstStreamEventTimeoutMs as s, FirstStreamEventAbortController as t };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
//#region packages/normalization-core/src/string-coerce.ts
|
|
2
|
-
/** Reads a value only when it is already a string, preserving whitespace. */
|
|
3
|
-
function readStringValue(value) {
|
|
4
|
-
return typeof value === "string" ? value : void 0;
|
|
5
|
-
}
|
|
6
|
-
/** Trims string input and returns null for non-strings or empty strings. */
|
|
7
|
-
function normalizeNullableString(value) {
|
|
8
|
-
if (typeof value !== "string") return null;
|
|
9
|
-
const trimmed = value.trim();
|
|
10
|
-
return trimmed ? trimmed : null;
|
|
11
|
-
}
|
|
12
|
-
/** Trims string input and returns undefined for non-strings or empty strings. */
|
|
13
|
-
function normalizeOptionalString(value) {
|
|
14
|
-
return normalizeNullableString(value) ?? void 0;
|
|
15
|
-
}
|
|
16
|
-
/** Stringifies primitive ids/flags before applying optional string normalization. */
|
|
17
|
-
function normalizeStringifiedOptionalString(value) {
|
|
18
|
-
if (typeof value === "string") return normalizeOptionalString(value);
|
|
19
|
-
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return normalizeOptionalString(String(value));
|
|
20
|
-
}
|
|
21
|
-
/** Lowercases a normalized optional string. */
|
|
22
|
-
function normalizeOptionalLowercaseString(value) {
|
|
23
|
-
return normalizeOptionalString(value)?.toLowerCase();
|
|
24
|
-
}
|
|
25
|
-
/** Lowercases a normalized string or returns an empty string when absent. */
|
|
26
|
-
function normalizeLowercaseStringOrEmpty(value) {
|
|
27
|
-
return normalizeOptionalLowercaseString(value) ?? "";
|
|
28
|
-
}
|
|
29
|
-
/** Type guard for strings that remain non-empty after trimming. */
|
|
30
|
-
function hasNonEmptyString(value) {
|
|
31
|
-
return normalizeOptionalString(value) !== void 0;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
export { normalizeOptionalString as a, normalizeOptionalLowercaseString as i, normalizeLowercaseStringOrEmpty as n, normalizeStringifiedOptionalString as o, normalizeNullableString as r, readStringValue as s, hasNonEmptyString as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//#region packages/normalization-core/src/utf16-slice.ts
|
|
2
|
-
function isHighSurrogate(codeUnit) {
|
|
3
|
-
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
4
|
-
}
|
|
5
|
-
function isLowSurrogate(codeUnit) {
|
|
6
|
-
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
7
|
-
}
|
|
8
|
-
/** Slices a UTF-16 string without returning dangling surrogate halves at either edge. */
|
|
9
|
-
function sliceUtf16Safe(input, start, end) {
|
|
10
|
-
const len = input.length;
|
|
11
|
-
let from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
12
|
-
let to = end === void 0 ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
|
|
13
|
-
if (to <= from) return "";
|
|
14
|
-
if (from > 0 && from < len) {
|
|
15
|
-
if (isLowSurrogate(input.charCodeAt(from)) && isHighSurrogate(input.charCodeAt(from - 1))) from += 1;
|
|
16
|
-
}
|
|
17
|
-
if (to > 0 && to < len) {
|
|
18
|
-
if (isHighSurrogate(input.charCodeAt(to - 1)) && isLowSurrogate(input.charCodeAt(to))) to -= 1;
|
|
19
|
-
}
|
|
20
|
-
return input.slice(from, to);
|
|
21
|
-
}
|
|
22
|
-
/** Truncates a UTF-16 string without cutting a surrogate pair in half. */
|
|
23
|
-
function truncateUtf16Safe(input, maxLen) {
|
|
24
|
-
const limit = Math.max(0, Math.floor(maxLen));
|
|
25
|
-
if (input.length <= limit) return input;
|
|
26
|
-
return sliceUtf16Safe(input, 0, limit);
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
export { truncateUtf16Safe as t };
|