@openclaw/ai 2026.8.1-beta.2 → 2026.8.1
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-B6dLpq5L.mjs → anthropic-Djj7L1rx.mjs} +49 -39
- package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-CY4tkD4V.mjs} +42 -44
- package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-i_5_inWe.d.mts} +4 -2
- package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-C9-wZd_W.d.mts} +2 -1
- package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-Bj3czHNa.mjs} +4 -4
- 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-C988TSLe.d.mts +1 -0
- package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-UhnxHuqt.d.mts} +1 -2
- package/dist/event-stream.d.mts +2 -1
- package/dist/{google-C7h2QzDX.mjs → google-0Ca6TYbw.mjs} +4 -4
- package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-DVfL9COU.mjs} +22 -8
- package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-5dAMxprN.mjs} +4 -4
- package/dist/{host-DTqNc7ad.mjs → host-D51fmkH6.mjs} +40 -33
- package/dist/{host-vWgMMhiJ.d.mts → host-DoPJJ1KD.d.mts} +7 -7
- package/dist/index-N3zr6__t.d.mts +105 -0
- package/dist/index.d.mts +9 -10
- package/dist/index.mjs +2 -3
- package/dist/internal/anthropic.d.mts +57 -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 -8
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +53 -40
- package/dist/internal/runtime.mjs +10 -9
- package/dist/internal/shared.d.mts +37 -23
- package/dist/internal/shared.mjs +4 -4
- package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
- package/dist/{headers-DdOQtGuU.mjs → llm-request-activity-BjtkplhG.mjs} +1 -9
- package/dist/{mistral-CEWoQI_g.mjs → mistral-BCnrI-kV.mjs} +64 -53
- package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-CGBGWSqr.mjs} +45 -20
- package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-BaTuwID7.mjs} +63 -258
- package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-DB7FFq7k.d.mts} +3 -3
- package/dist/openai-completions-stream-Bpns6uNc.mjs +1622 -0
- package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-1GBcQujk.mjs} +8 -6
- package/dist/openai-responses-compaction-window-DwydGZI8.mjs +686 -0
- package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-DgaR3t5T.d.mts} +14 -5
- package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +2 -0
- package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-_nhGTn2b.mjs} +3 -3
- package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-zPmKnhF5.mjs} +345 -1553
- package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
- package/dist/openai-tool-schema-Dgl4H2MU.mjs +1695 -0
- package/dist/{provider-error-BUwEnjXq.mjs → provider-error-jZP5NMTZ.mjs} +3 -82
- package/dist/{provider-options-B96RdNpH.d.mts → provider-options-HvA_slFa.d.mts} +23 -4
- package/dist/provider-transcript-transform-C01bQ5a3.mjs +32 -0
- 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-rnPwX2pg.mjs → reasoning-tag-text-partitioner-CwzKb0bA.mjs} +4 -1
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-DCkltN94.mjs} +1 -2
- package/dist/{simple-options-D58D5Kvw.mjs → simple-options-DKx86yX9.mjs} +42 -4
- package/dist/{anthropic-JsNA5KCu.mjs → src-Bu3FiFAG.mjs} +1 -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-q5d7QX5c.mjs → tool-schema-json-projection-qvTEs5Am.mjs} +17 -8
- package/dist/transport-stream-shared-CT5ycdzn.mjs +342 -0
- package/dist/transport-stream-shared-NjwWNaRY.d.mts +138 -0
- package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-BHx9z8Cl.mjs} +9 -9
- package/dist/transports.d.mts +140 -169
- package/dist/transports.mjs +269 -1262
- package/dist/types-DtGu2d3C.d.mts +1 -0
- package/dist/{types-BHNrPS1l.d.mts → types-h38Azne1.d.mts} +53 -17
- package/dist/types.d.mts +6 -5
- package/dist/types.mjs +1 -2
- package/dist/utf16-slice-qz3nsy87.mjs +84 -0
- package/dist/{validation-DT9SrFn3.d.mts → validation-C68lP2uy.d.mts} +1 -2
- package/dist/validation.d.mts +1 -1
- package/package.json +6 -6
- package/dist/anthropic-SrGtwsJu.d.mts +0 -100
- package/dist/index-BVVgDSdq.d.mts +0 -1
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +0 -253
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +0 -206
- package/dist/openai-stop-reason-BkFkqqK0.mjs +0 -563
- package/dist/openai-tool-projection-CY04OcvQ.mjs +0 -338
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +0 -155
- 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
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { r as createAssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
2
|
+
import { a as asOptionalRecord, n as asNonArrayRecord, r as asNullableRecord } from "./utf16-slice-qz3nsy87.mjs";
|
|
3
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-DCkltN94.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-jZP5NMTZ.mjs";
|
|
5
|
+
//#region packages/ai/src/utils/headers.ts
|
|
6
|
+
/** Converts a Headers object to a plain record for provider request handling. */
|
|
7
|
+
function headersToRecord(headers) {
|
|
8
|
+
const result = {};
|
|
9
|
+
for (const [key, value] of headers.entries()) result[key] = value;
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region packages/ai/src/transports/json-unsafe-integers.ts
|
|
14
|
+
/**
|
|
15
|
+
* JSON parsing helpers that preserve integer literals larger than
|
|
16
|
+
* Number.MAX_SAFE_INTEGER as strings before JSON.parse can round them.
|
|
17
|
+
*/
|
|
18
|
+
const MAX_SAFE_INTEGER_ABS_STR = String(Number.MAX_SAFE_INTEGER);
|
|
19
|
+
function isAsciiDigit(ch) {
|
|
20
|
+
return ch !== void 0 && ch >= "0" && ch <= "9";
|
|
21
|
+
}
|
|
22
|
+
function parseJsonNumberToken(input, start) {
|
|
23
|
+
let idx = start;
|
|
24
|
+
if (input[idx] === "-") idx += 1;
|
|
25
|
+
if (idx >= input.length) return null;
|
|
26
|
+
if (input[idx] === "0") idx += 1;
|
|
27
|
+
else if (isAsciiDigit(input[idx]) && input[idx] !== "0") while (isAsciiDigit(input[idx])) idx += 1;
|
|
28
|
+
else return null;
|
|
29
|
+
let isInteger = true;
|
|
30
|
+
if (input[idx] === ".") {
|
|
31
|
+
isInteger = false;
|
|
32
|
+
idx += 1;
|
|
33
|
+
if (!isAsciiDigit(input[idx])) return null;
|
|
34
|
+
while (isAsciiDigit(input[idx])) idx += 1;
|
|
35
|
+
}
|
|
36
|
+
if (input[idx] === "e" || input[idx] === "E") {
|
|
37
|
+
isInteger = false;
|
|
38
|
+
idx += 1;
|
|
39
|
+
if (input[idx] === "+" || input[idx] === "-") idx += 1;
|
|
40
|
+
if (!isAsciiDigit(input[idx])) return null;
|
|
41
|
+
while (isAsciiDigit(input[idx])) idx += 1;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
token: input.slice(start, idx),
|
|
45
|
+
end: idx,
|
|
46
|
+
isInteger
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function isUnsafeIntegerLiteral(token) {
|
|
50
|
+
const digits = token[0] === "-" ? token.slice(1) : token;
|
|
51
|
+
if (digits.length < MAX_SAFE_INTEGER_ABS_STR.length) return false;
|
|
52
|
+
if (digits.length > MAX_SAFE_INTEGER_ABS_STR.length) return true;
|
|
53
|
+
return digits > MAX_SAFE_INTEGER_ABS_STR;
|
|
54
|
+
}
|
|
55
|
+
/** Quotes integer literals above Number.MAX_SAFE_INTEGER before JSON.parse. */
|
|
56
|
+
function quoteUnsafeIntegerLiterals(input) {
|
|
57
|
+
let out = "";
|
|
58
|
+
let inString = false;
|
|
59
|
+
let escaped = false;
|
|
60
|
+
let idx = 0;
|
|
61
|
+
while (idx < input.length) {
|
|
62
|
+
const ch = input[idx] ?? "";
|
|
63
|
+
if (inString) {
|
|
64
|
+
out += ch;
|
|
65
|
+
if (escaped) escaped = false;
|
|
66
|
+
else if (ch === "\\") escaped = true;
|
|
67
|
+
else if (ch === "\"") inString = false;
|
|
68
|
+
idx += 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (ch === "\"") {
|
|
72
|
+
inString = true;
|
|
73
|
+
out += ch;
|
|
74
|
+
idx += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch === "-" || isAsciiDigit(ch)) {
|
|
78
|
+
const parsed = parseJsonNumberToken(input, idx);
|
|
79
|
+
if (parsed) {
|
|
80
|
+
if (parsed.isInteger && isUnsafeIntegerLiteral(parsed.token)) out += `"${parsed.token}"`;
|
|
81
|
+
else out += parsed.token;
|
|
82
|
+
idx = parsed.end;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
out += ch;
|
|
87
|
+
idx += 1;
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
/** Parses JSON while preserving unsafe integer literals as strings. */
|
|
92
|
+
function parseJsonPreservingUnsafeIntegers(input) {
|
|
93
|
+
return JSON.parse(quoteUnsafeIntegerLiterals(input));
|
|
94
|
+
}
|
|
95
|
+
/** Parses or accepts an object while preserving unsafe integer literals in string input. */
|
|
96
|
+
function parseJsonObjectPreservingUnsafeIntegers(value) {
|
|
97
|
+
if (typeof value === "string") try {
|
|
98
|
+
return asNullableRecord(parseJsonPreservingUnsafeIntegers(value));
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return asNullableRecord(value);
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region packages/ai/src/transports/transport-stream-shared.ts
|
|
106
|
+
const EMPTY_TOOL_RESULT_TEXT = "(no output)";
|
|
107
|
+
const MALFORMED_TOOL_CALL_TERMINAL_ERROR_MESSAGE = "Provider completed tool call with malformed JSON arguments";
|
|
108
|
+
function sanitizeTransportPayloadText(text) {
|
|
109
|
+
if (typeof text !== "string") return "";
|
|
110
|
+
return sanitizeSurrogates(text);
|
|
111
|
+
}
|
|
112
|
+
function sanitizeNonEmptyTransportPayloadText(text, fallback = EMPTY_TOOL_RESULT_TEXT) {
|
|
113
|
+
const sanitized = sanitizeTransportPayloadText(text);
|
|
114
|
+
return sanitized.trim().length > 0 ? sanitized : fallback;
|
|
115
|
+
}
|
|
116
|
+
function coerceTransportToolCallArguments(argumentsValue) {
|
|
117
|
+
const argumentsRecord = asOptionalRecord(argumentsValue);
|
|
118
|
+
if (argumentsRecord) return argumentsRecord;
|
|
119
|
+
if (typeof argumentsValue === "string") try {
|
|
120
|
+
return asNonArrayRecord(JSON.parse(argumentsValue));
|
|
121
|
+
} catch {}
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
/** Admit only complete object-shaped terminal tool arguments; partial parsing is preview-only. */
|
|
125
|
+
function parseTerminalToolCallArguments(value, errorMessage = MALFORMED_TOOL_CALL_TERMINAL_ERROR_MESSAGE) {
|
|
126
|
+
const parsed = parseJsonObjectPreservingUnsafeIntegers(value);
|
|
127
|
+
if (!parsed) throw new Error(errorMessage);
|
|
128
|
+
return parsed;
|
|
129
|
+
}
|
|
130
|
+
/** Validate a complete sibling set before mutating any call into executable state. */
|
|
131
|
+
function finalizeTerminalToolCallArguments(calls, readArguments, errorMessage) {
|
|
132
|
+
const validated = calls.map((call) => [call, parseTerminalToolCallArguments(readArguments(call), errorMessage)]);
|
|
133
|
+
for (const [call, argumentsValue] of validated) call.arguments = argumentsValue;
|
|
134
|
+
}
|
|
135
|
+
function mergeTransportHeaders(...headerSources) {
|
|
136
|
+
const merged = {};
|
|
137
|
+
for (const headers of headerSources) if (headers) Object.assign(merged, headers);
|
|
138
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
139
|
+
}
|
|
140
|
+
function mergeTransportMetadata(payload, metadata) {
|
|
141
|
+
if (!metadata || Object.keys(metadata).length === 0) return payload;
|
|
142
|
+
const existingMetadata = asOptionalRecord(payload.metadata);
|
|
143
|
+
return {
|
|
144
|
+
...payload,
|
|
145
|
+
metadata: {
|
|
146
|
+
...existingMetadata,
|
|
147
|
+
...metadata
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function createEmptyTransportUsage() {
|
|
152
|
+
return {
|
|
153
|
+
input: 0,
|
|
154
|
+
output: 0,
|
|
155
|
+
cacheRead: 0,
|
|
156
|
+
cacheWrite: 0,
|
|
157
|
+
totalTokens: 0,
|
|
158
|
+
cost: {
|
|
159
|
+
input: 0,
|
|
160
|
+
output: 0,
|
|
161
|
+
cacheRead: 0,
|
|
162
|
+
cacheWrite: 0,
|
|
163
|
+
total: 0
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function createWritableTransportEventStream() {
|
|
168
|
+
const eventStream = createAssistantMessageEventStream();
|
|
169
|
+
return {
|
|
170
|
+
eventStream,
|
|
171
|
+
stream: eventStream
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Abort error to surface for an aborted `signal`.
|
|
176
|
+
*
|
|
177
|
+
* Rethrows the caller's abort reason only when it carries a `code`, so that code
|
|
178
|
+
* survives into `errorCode` on the persisted assistant message and consumers can
|
|
179
|
+
* recognize an abort's origin without matching error text. A default
|
|
180
|
+
* `abort()` reason is an uncoded DOMException that carries nothing the synthetic
|
|
181
|
+
* error does not, so it keeps the "Request was aborted" text every transport
|
|
182
|
+
* already emits rather than churning it.
|
|
183
|
+
*/
|
|
184
|
+
function transportAbortError(signal) {
|
|
185
|
+
const reason = signal?.reason;
|
|
186
|
+
return reason instanceof Error && typeof reason.code === "string" ? reason : /* @__PURE__ */ new Error("Request was aborted");
|
|
187
|
+
}
|
|
188
|
+
const providerAcceptanceObserver = Symbol("openclaw.providerAcceptanceObserver");
|
|
189
|
+
function readProviderAcceptanceObserver(options) {
|
|
190
|
+
if (options === null || typeof options !== "object") return;
|
|
191
|
+
const descriptor = Object.getOwnPropertyDescriptor(options, providerAcceptanceObserver);
|
|
192
|
+
const value = descriptor && "value" in descriptor ? descriptor.value : void 0;
|
|
193
|
+
return isProviderAcceptanceObserver(value) ? value : void 0;
|
|
194
|
+
}
|
|
195
|
+
function isProviderAcceptanceObserver(value) {
|
|
196
|
+
return typeof value === "function";
|
|
197
|
+
}
|
|
198
|
+
function writeProviderAcceptanceObserver(options, observer) {
|
|
199
|
+
Object.defineProperty(options, providerAcceptanceObserver, {
|
|
200
|
+
configurable: true,
|
|
201
|
+
enumerable: true,
|
|
202
|
+
value: observer
|
|
203
|
+
});
|
|
204
|
+
return options;
|
|
205
|
+
}
|
|
206
|
+
/** Attach an OpenClaw-internal provider acceptance observer to one model call. */
|
|
207
|
+
function withProviderAcceptanceObserver(options, observer) {
|
|
208
|
+
const existing = readProviderAcceptanceObserver(options);
|
|
209
|
+
return writeProviderAcceptanceObserver(options, existing ? (acceptance) => {
|
|
210
|
+
observer(acceptance);
|
|
211
|
+
existing(acceptance);
|
|
212
|
+
} : observer);
|
|
213
|
+
}
|
|
214
|
+
/** Preserve the private provider acceptance observer when a built-in wrapper rebuilds options. */
|
|
215
|
+
function copyProviderAcceptanceObserver(source, target) {
|
|
216
|
+
const observer = readProviderAcceptanceObserver(source);
|
|
217
|
+
return observer ? writeProviderAcceptanceObserver(target, observer) : target;
|
|
218
|
+
}
|
|
219
|
+
async function awaitProviderLifecycleCallback(callback, signal) {
|
|
220
|
+
if (signal?.aborted) throw transportAbortError(signal);
|
|
221
|
+
if (!callback) return;
|
|
222
|
+
const callbackPromise = Promise.resolve().then(callback);
|
|
223
|
+
if (!signal) {
|
|
224
|
+
await callbackPromise;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
let onAbort;
|
|
228
|
+
try {
|
|
229
|
+
await Promise.race([callbackPromise, new Promise((_resolve, reject) => {
|
|
230
|
+
onAbort = () => reject(transportAbortError(signal));
|
|
231
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
232
|
+
})]);
|
|
233
|
+
} finally {
|
|
234
|
+
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
235
|
+
}
|
|
236
|
+
if (signal.aborted) throw transportAbortError(signal);
|
|
237
|
+
}
|
|
238
|
+
function startProviderStreamCancellation(cancelStream, error) {
|
|
239
|
+
const reason = error instanceof Error ? error : new Error(String(error));
|
|
240
|
+
try {
|
|
241
|
+
Promise.resolve(cancelStream(reason)).catch(() => void 0);
|
|
242
|
+
} catch {}
|
|
243
|
+
}
|
|
244
|
+
async function awaitProviderLifecycleWithCleanup(params) {
|
|
245
|
+
try {
|
|
246
|
+
await params.run();
|
|
247
|
+
} catch (error) {
|
|
248
|
+
startProviderStreamCancellation(params.cancelStream, error);
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** Report observed HTTP metadata; rejected responses use only onResponse. */
|
|
253
|
+
async function notifyProviderHttpMetadata(params) {
|
|
254
|
+
const observer = readProviderAcceptanceObserver(params.options);
|
|
255
|
+
if (!observer && !params.options?.onResponse) return;
|
|
256
|
+
const { status, headers } = params.response;
|
|
257
|
+
const signal = params.signal ?? params.options?.signal;
|
|
258
|
+
const accepted = status >= 200 && status < 300;
|
|
259
|
+
await awaitProviderLifecycleWithCleanup({
|
|
260
|
+
cancelStream: params.cancelStream,
|
|
261
|
+
run: async () => {
|
|
262
|
+
await awaitProviderLifecycleCallback(accepted && observer ? () => observer({
|
|
263
|
+
kind: "http_response",
|
|
264
|
+
status,
|
|
265
|
+
headers
|
|
266
|
+
}) : void 0, signal);
|
|
267
|
+
await awaitProviderLifecycleCallback(params.options?.onResponse ? () => params.options?.onResponse?.({
|
|
268
|
+
status,
|
|
269
|
+
headers
|
|
270
|
+
}, params.model) : void 0, signal);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/** Report a real HTTP response before body consumption. */
|
|
275
|
+
async function notifyProviderHttpResponse(params) {
|
|
276
|
+
await notifyProviderHttpMetadata({
|
|
277
|
+
options: params.options,
|
|
278
|
+
response: {
|
|
279
|
+
status: params.response.status,
|
|
280
|
+
headers: headersToRecord(params.response.headers)
|
|
281
|
+
},
|
|
282
|
+
model: params.model,
|
|
283
|
+
signal: params.signal,
|
|
284
|
+
cancelStream: (reason) => {
|
|
285
|
+
if (params.cancelStream) startProviderStreamCancellation(params.cancelStream, reason);
|
|
286
|
+
return params.response.body?.cancel(reason);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/** Report an accepted SDK stream when the SDK does not expose HTTP metadata. */
|
|
291
|
+
async function notifyProviderStreamOpened(params) {
|
|
292
|
+
const observer = readProviderAcceptanceObserver(params.options);
|
|
293
|
+
if (!observer) return;
|
|
294
|
+
await awaitProviderLifecycleWithCleanup({
|
|
295
|
+
cancelStream: params.cancelStream,
|
|
296
|
+
run: () => awaitProviderLifecycleCallback(() => observer({ kind: "provider_stream_opened" }), params.signal ?? params.options?.signal)
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/** Run a provider-response hook before start/body consumption inside the first-event deadline. */
|
|
300
|
+
function withProviderResponseHook(params) {
|
|
301
|
+
return { async *[Symbol.asyncIterator]() {
|
|
302
|
+
try {
|
|
303
|
+
await awaitProviderLifecycleCallback(params.hook, params.signal);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
params.abort(error instanceof Error ? error : new Error(String(error)));
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
if (params.signal.aborted) throw transportAbortError(params.signal);
|
|
309
|
+
params.onReady?.();
|
|
310
|
+
if (params.stream) yield* params.stream;
|
|
311
|
+
} };
|
|
312
|
+
}
|
|
313
|
+
function finalizeTransportStream(params) {
|
|
314
|
+
const { stream, output, signal } = params;
|
|
315
|
+
if (signal?.aborted) throw transportAbortError(signal);
|
|
316
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
317
|
+
stream.push({
|
|
318
|
+
type: "done",
|
|
319
|
+
reason: output.stopReason,
|
|
320
|
+
message: output
|
|
321
|
+
});
|
|
322
|
+
stream.end();
|
|
323
|
+
}
|
|
324
|
+
/** @deprecated Use projectProviderError. v2026.7.2-beta.5 compatibility; remove after 2026.10. */
|
|
325
|
+
function assignTransportErrorDetails(output, error, signal) {
|
|
326
|
+
const projection = projectProviderError(error, signal);
|
|
327
|
+
Object.assign(output, projection);
|
|
328
|
+
return projection;
|
|
329
|
+
}
|
|
330
|
+
function failTransportStream(params) {
|
|
331
|
+
const { stream, output, signal, error, cleanup } = params;
|
|
332
|
+
cleanup?.();
|
|
333
|
+
const projection = assignTransportErrorDetails(output, error, signal);
|
|
334
|
+
stream.push({
|
|
335
|
+
type: "error",
|
|
336
|
+
reason: projection.stopReason,
|
|
337
|
+
error: output
|
|
338
|
+
});
|
|
339
|
+
stream.end();
|
|
340
|
+
}
|
|
341
|
+
//#endregion
|
|
342
|
+
export { headersToRecord as C, quoteUnsafeIntegerLiterals as S, transportAbortError as _, createWritableTransportEventStream as a, parseJsonObjectPreservingUnsafeIntegers as b, finalizeTransportStream as c, notifyProviderHttpMetadata as d, notifyProviderHttpResponse as f, sanitizeTransportPayloadText as g, sanitizeNonEmptyTransportPayloadText as h, createEmptyTransportUsage as i, mergeTransportHeaders as l, parseTerminalToolCallArguments as m, coerceTransportToolCallArguments as n, failTransportStream as o, notifyProviderStreamOpened as p, copyProviderAcceptanceObserver as r, finalizeTerminalToolCallArguments as s, assignTransportErrorDetails as t, mergeTransportMetadata as u, withProviderAcceptanceObserver as v, parseJsonPreservingUnsafeIntegers as x, withProviderResponseHook as y };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import "./index-N3zr6__t.mjs";
|
|
2
|
+
import { D as Model, L as ProviderResponse, U as StreamOptions, a as AssistantMessage, et as Usage } from "./types-h38Azne1.mjs";
|
|
3
|
+
import { r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-UhnxHuqt.mjs";
|
|
4
|
+
import "./event-stream-C988TSLe.mjs";
|
|
5
|
+
import { t as ProviderErrorProjection } from "./provider-error-CzNw4BWX.mjs";
|
|
6
|
+
//#region packages/ai/src/utils/stream-first-event-timeout.d.ts
|
|
7
|
+
type StreamStage = "responses" | "completions";
|
|
8
|
+
type FirstStreamEventTimeoutContext = {
|
|
9
|
+
provider?: string;
|
|
10
|
+
api?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
timeoutMs: number;
|
|
13
|
+
stage?: StreamStage;
|
|
14
|
+
hint?: string;
|
|
15
|
+
abort?: (reason: Error) => void;
|
|
16
|
+
onTimeout?: (reason: Error) => void;
|
|
17
|
+
};
|
|
18
|
+
type FirstStreamEventInternalOptions = {
|
|
19
|
+
firstEventTimeoutMs?: number;
|
|
20
|
+
abortFirstEventStream?: (reason: Error) => void;
|
|
21
|
+
onFirstEventTimeout?: (reason: Error) => void;
|
|
22
|
+
};
|
|
23
|
+
type FirstStreamEventAbortController = {
|
|
24
|
+
signal: AbortSignal;
|
|
25
|
+
abort: (reason: Error) => void;
|
|
26
|
+
dispose: () => void;
|
|
27
|
+
};
|
|
28
|
+
declare function getFirstStreamEventTimeoutMs(options: unknown): number | undefined;
|
|
29
|
+
declare function getFirstStreamEventTimeoutHandler(options: unknown): ((reason: Error) => void) | undefined;
|
|
30
|
+
declare function createFirstStreamEventTimeoutError(context: FirstStreamEventTimeoutContext): Error;
|
|
31
|
+
declare function createFirstStreamEventAbortController(parentSignal?: AbortSignal): FirstStreamEventAbortController;
|
|
32
|
+
declare function withFirstStreamEventTimeout<T>(stream: AsyncIterable<T>, context: FirstStreamEventTimeoutContext): AsyncIterable<T>;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region packages/ai/src/transports/transport-stream-shared.d.ts
|
|
35
|
+
type ContextUsage = NonNullable<Usage["contextUsage"]>;
|
|
36
|
+
type TransportUsage = {
|
|
37
|
+
input: number;
|
|
38
|
+
output: number;
|
|
39
|
+
cacheRead: number;
|
|
40
|
+
cacheWrite: number;
|
|
41
|
+
contextUsage?: ContextUsage;
|
|
42
|
+
totalTokens: number;
|
|
43
|
+
cost: {
|
|
44
|
+
input: number;
|
|
45
|
+
output: number;
|
|
46
|
+
cacheRead: number;
|
|
47
|
+
cacheWrite: number;
|
|
48
|
+
total: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
type WritableTransportStream = Pick<ReturnType<typeof createAssistantMessageEventStream>, "push" | "end">;
|
|
52
|
+
declare function sanitizeTransportPayloadText(text: string): string;
|
|
53
|
+
declare function sanitizeNonEmptyTransportPayloadText(text: string, fallback?: string): string;
|
|
54
|
+
declare function coerceTransportToolCallArguments(argumentsValue: unknown): Record<string, unknown>;
|
|
55
|
+
/** Admit only complete object-shaped terminal tool arguments; partial parsing is preview-only. */
|
|
56
|
+
declare function parseTerminalToolCallArguments(value: unknown, errorMessage?: string): Record<string, unknown>;
|
|
57
|
+
/** Validate a complete sibling set before mutating any call into executable state. */
|
|
58
|
+
declare function finalizeTerminalToolCallArguments<T extends {
|
|
59
|
+
arguments: Record<string, unknown>;
|
|
60
|
+
}>(calls: readonly T[], readArguments: (call: T) => unknown, errorMessage?: string): void;
|
|
61
|
+
declare function mergeTransportHeaders(...headerSources: Array<Record<string, string> | undefined>): Record<string, string> | undefined;
|
|
62
|
+
declare function mergeTransportMetadata<T extends Record<string, unknown>>(payload: T, metadata?: Record<string, string>): T;
|
|
63
|
+
declare function createEmptyTransportUsage(): TransportUsage;
|
|
64
|
+
declare function createWritableTransportEventStream(): {
|
|
65
|
+
eventStream: AssistantMessageEventStream;
|
|
66
|
+
stream: AssistantMessageEventStream;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Abort error to surface for an aborted `signal`.
|
|
70
|
+
*
|
|
71
|
+
* Rethrows the caller's abort reason only when it carries a `code`, so that code
|
|
72
|
+
* survives into `errorCode` on the persisted assistant message and consumers can
|
|
73
|
+
* recognize an abort's origin without matching error text. A default
|
|
74
|
+
* `abort()` reason is an uncoded DOMException that carries nothing the synthetic
|
|
75
|
+
* error does not, so it keeps the "Request was aborted" text every transport
|
|
76
|
+
* already emits rather than churning it.
|
|
77
|
+
*/
|
|
78
|
+
declare function transportAbortError(signal?: AbortSignal): Error;
|
|
79
|
+
type ProviderAcceptance = {
|
|
80
|
+
kind: "http_response";
|
|
81
|
+
status: number;
|
|
82
|
+
headers: Record<string, string>;
|
|
83
|
+
} | {
|
|
84
|
+
kind: "provider_stream_opened";
|
|
85
|
+
};
|
|
86
|
+
type ProviderAcceptanceObserver = (acceptance: ProviderAcceptance) => void;
|
|
87
|
+
type ProviderAcceptanceOptions = Pick<StreamOptions, "onResponse" | "signal">;
|
|
88
|
+
type ProviderStreamCancel = (reason: Error) => void | Promise<void>;
|
|
89
|
+
/** Attach an OpenClaw-internal provider acceptance observer to one model call. */
|
|
90
|
+
declare function withProviderAcceptanceObserver<T extends object>(options: T, observer: ProviderAcceptanceObserver): T;
|
|
91
|
+
/** Preserve the private provider acceptance observer when a built-in wrapper rebuilds options. */
|
|
92
|
+
declare function copyProviderAcceptanceObserver<T extends object>(source: unknown, target: T): T;
|
|
93
|
+
/** Report observed HTTP metadata; rejected responses use only onResponse. */
|
|
94
|
+
declare function notifyProviderHttpMetadata(params: {
|
|
95
|
+
options?: ProviderAcceptanceOptions;
|
|
96
|
+
response: ProviderResponse;
|
|
97
|
+
model: Model;
|
|
98
|
+
cancelStream: ProviderStreamCancel;
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
}): Promise<void>;
|
|
101
|
+
/** Report a real HTTP response before body consumption. */
|
|
102
|
+
declare function notifyProviderHttpResponse(params: {
|
|
103
|
+
options?: ProviderAcceptanceOptions;
|
|
104
|
+
response: Response;
|
|
105
|
+
model: Model;
|
|
106
|
+
cancelStream?: ProviderStreamCancel;
|
|
107
|
+
signal?: AbortSignal;
|
|
108
|
+
}): Promise<void>;
|
|
109
|
+
/** Report an accepted SDK stream when the SDK does not expose HTTP metadata. */
|
|
110
|
+
declare function notifyProviderStreamOpened(params: {
|
|
111
|
+
options?: Pick<StreamOptions, "signal">;
|
|
112
|
+
cancelStream: ProviderStreamCancel;
|
|
113
|
+
signal?: AbortSignal;
|
|
114
|
+
}): Promise<void>;
|
|
115
|
+
/** Run a provider-response hook before start/body consumption inside the first-event deadline. */
|
|
116
|
+
declare function withProviderResponseHook<T = never>(params: {
|
|
117
|
+
stream?: AsyncIterable<T>;
|
|
118
|
+
signal: AbortSignal;
|
|
119
|
+
abort: (reason: Error) => void;
|
|
120
|
+
hook?: () => void | Promise<void>;
|
|
121
|
+
onReady?: () => void;
|
|
122
|
+
}): AsyncIterable<T>;
|
|
123
|
+
declare function finalizeTransportStream(params: {
|
|
124
|
+
stream: WritableTransportStream;
|
|
125
|
+
output: AssistantMessage;
|
|
126
|
+
signal?: AbortSignal;
|
|
127
|
+
}): void;
|
|
128
|
+
/** @deprecated Use projectProviderError. v2026.7.2-beta.5 compatibility; remove after 2026.10. */
|
|
129
|
+
declare function assignTransportErrorDetails(output: AssistantMessage, error: unknown, signal?: AbortSignal): ProviderErrorProjection;
|
|
130
|
+
declare function failTransportStream(params: {
|
|
131
|
+
stream: WritableTransportStream;
|
|
132
|
+
output: AssistantMessage;
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
error: unknown;
|
|
135
|
+
cleanup?: () => void;
|
|
136
|
+
}): void;
|
|
137
|
+
//#endregion
|
|
138
|
+
export { FirstStreamEventInternalOptions as C, getFirstStreamEventTimeoutHandler as D, createFirstStreamEventTimeoutError as E, getFirstStreamEventTimeoutMs as O, FirstStreamEventAbortController as S, createFirstStreamEventAbortController as T, sanitizeNonEmptyTransportPayloadText as _, copyProviderAcceptanceObserver as a, withProviderAcceptanceObserver as b, failTransportStream as c, mergeTransportHeaders as d, mergeTransportMetadata as f, parseTerminalToolCallArguments as g, notifyProviderStreamOpened as h, coerceTransportToolCallArguments as i, withFirstStreamEventTimeout as k, finalizeTerminalToolCallArguments as l, notifyProviderHttpResponse as m, WritableTransportStream as n, createEmptyTransportUsage as o, notifyProviderHttpMetadata as p, assignTransportErrorDetails as r, createWritableTransportEventStream as s, ProviderAcceptance as t, finalizeTransportStream as u, sanitizeTransportPayloadText as v, FirstStreamEventTimeoutContext as w, withProviderResponseHook as x, transportAbortError as y };
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as getAiTransportHost } from "./host-
|
|
3
|
-
import {
|
|
4
|
-
import { a as parseStrictFiniteNumber, n as asFiniteNumberInRange, o as parseStrictNonNegativeInteger } from "./number-coercion-H9qHik3g.mjs";
|
|
1
|
+
import { d as normalizeOptionalString, t as truncateUtf16Safe } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
+
import { n as getAiTransportHost } from "./host-D51fmkH6.mjs";
|
|
3
|
+
import { c as parseStrictNonNegativeInteger, i as asFiniteNumberInRange, l as parseStrictPositiveInteger, s as parseStrictFiniteNumber } from "./base64-CEFBpSkN.mjs";
|
|
5
4
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
6
5
|
import { createHash } from "node:crypto";
|
|
7
6
|
//#region packages/ai/src/transports/transport-utils.ts
|
|
8
7
|
const MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE = "OpenClaw transport error: malformed_streaming_fragment";
|
|
9
8
|
const NON_LATIN_RE = /[\u2E80-\u9FFF\uA000-\uA4FF\uAC00-\uD7AF\uF900-\uFAFF\uFF01-\uFF60\uFFE0-\uFFE6\u{20000}-\u{2FA1F}]/gu;
|
|
10
9
|
const CJK_SURROGATE_HIGH_RE = /[\uD840-\uD87E][\uDC00-\uDFFF]/g;
|
|
10
|
+
function parsePositiveInteger(value) {
|
|
11
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
|
|
12
|
+
return typeof value === "string" ? parseStrictPositiveInteger(value) : void 0;
|
|
13
|
+
}
|
|
11
14
|
function sha256Hex(value) {
|
|
12
15
|
return createHash("sha256").update(value).digest("hex");
|
|
13
16
|
}
|
|
@@ -22,14 +25,11 @@ function redactIdentifier(value, opts) {
|
|
|
22
25
|
function redactSensitiveText(text, _options) {
|
|
23
26
|
return getAiTransportHost().redactToolPayloadText(text);
|
|
24
27
|
}
|
|
25
|
-
function resolveSecretSentinel(value) {
|
|
26
|
-
return getAiTransportHost().resolveSecretSentinel(value);
|
|
27
|
-
}
|
|
28
28
|
function resolveModelHeaderSentinels(model) {
|
|
29
29
|
if (!model.headers) return model;
|
|
30
30
|
let headers;
|
|
31
31
|
for (const [name, value] of Object.entries(model.headers)) {
|
|
32
|
-
const resolved = resolveSecretSentinel(value);
|
|
32
|
+
const resolved = getAiTransportHost().resolveSecretSentinel(value);
|
|
33
33
|
if (resolved !== value) {
|
|
34
34
|
headers ??= { ...model.headers };
|
|
35
35
|
headers[name] = resolved;
|
|
@@ -135,4 +135,4 @@ async function readResponseTextSnippet(response, options) {
|
|
|
135
135
|
return truncated ? `${collapsed}…` : collapsed;
|
|
136
136
|
}
|
|
137
137
|
//#endregion
|
|
138
|
-
export { isGoogleGemini3FlashModel as a,
|
|
138
|
+
export { isGoogleGemini3FlashModel as a, parseRetryAfterSeconds as c, redactSensitiveText as d, resolveModelHeaderSentinels as f, isCodeModeModelVisibleToolName as i, readResponseTextSnippet as l, supportsModelTools as m, createAbortError as n, isGoogleGemini3ProModel as o, sha256Hex as p, estimateStringChars as r, parsePositiveInteger as s, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE as t, redactIdentifier as u };
|