@openclaw/ai 2026.7.2-beta.3 → 2026.7.2-beta.5
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/README.md +6 -5
- package/dist/{anthropic-D7SyZQ5v.mjs → anthropic-CQVj3le6.mjs} +174 -33
- package/dist/{index-BoTnz8cv.d.mts → anthropic-SrGtwsJu.d.mts} +27 -1
- package/dist/{api-registry-DXBIXISf.d.mts → api-registry-DlMgPR39.d.mts} +1 -2
- package/dist/{azure-openai-responses-BkZgyZ3I.mjs → azure-openai-responses-DIYgsqFM.mjs} +7 -11
- package/dist/{env-api-keys-DnhYpc27.mjs → env-api-keys-DrgeBuva.mjs} +1 -1
- package/dist/error-coercion-DgxlWC0n.mjs +15 -0
- package/dist/{event-stream-BPemFrFW.d.mts → event-stream-YjaPW20U.d.mts} +1 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → github-copilot-headers-BCoBNmL7.mjs} +48 -1
- package/dist/{google-C_biGbV7.mjs → google-f-A8xrae.mjs} +4 -4
- package/dist/{google-shared-BK-NoHl8.mjs → google-shared-J6qvYINH.mjs} +5 -4
- package/dist/{google-vertex-CvdzF1U7.mjs → google-vertex-D3yMVXIY.mjs} +3 -3
- package/dist/host-B9GUmcra.d.mts +173 -0
- package/dist/host-XYGZcgO8.mjs +98 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.d.mts +7 -50
- package/dist/index.mjs +3 -3
- package/dist/internal/anthropic.d.mts +15 -11
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai.d.mts +3 -280
- package/dist/internal/openai.mjs +5 -7
- package/dist/internal/runtime.d.mts +13 -34
- package/dist/internal/runtime.mjs +19 -11
- package/dist/internal/shared.d.mts +13 -8
- package/dist/internal/shared.mjs +2 -2
- package/dist/{mistral-BdrQmDWp.mjs → mistral-CKV-TOQj.mjs} +7 -6
- package/dist/number-coercion-DvG7SNMg.mjs +129 -0
- package/dist/openai-BPor_3WI.d.mts +358 -0
- package/dist/{openai-responses-shared-CwnGU0KW.mjs → openai-D3PD6PE-.mjs} +1890 -705
- package/dist/{openai-chatgpt-responses-DP63Qt01.mjs → openai-chatgpt-responses-CedIj0hk.mjs} +54 -58
- package/dist/{openai-completions-zLDfebnN.mjs → openai-completions-CiSutyu0.mjs} +459 -104
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +7 -0
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +12 -0
- package/dist/prompt-cache-stability-Cwcjv_fx.d.mts +13 -0
- package/dist/{provider-error-LMfTEkfO.mjs → provider-error-apVOZI6G.mjs} +9 -2
- package/dist/providers.d.mts +3 -2
- package/dist/providers.mjs +10 -9
- package/dist/{transform-messages-eb6lxDLB.mjs → shared-CdjNZd35.mjs} +273 -161
- package/dist/{src-CXno1H5g.mjs → src-QkygScBs.mjs} +23 -4
- package/dist/stream-first-event-timeout-C3OgBjIk.mjs +12294 -0
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +29 -0
- package/dist/transport-stream-shared-BbMELSI4.mjs +297 -0
- package/dist/transports.d.mts +593 -0
- package/dist/transports.mjs +4069 -0
- package/dist/{types-CYORveZ7.d.mts → types-bzp5k29J.d.mts} +8 -0
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +2 -2
- package/dist/{validation-BX8euiDv.d.mts → validation-B-j7cOYp.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +36 -11
- package/dist/azure-openai-responses-client-compat-C7K7QfUE.mjs +0 -62
- package/dist/github-copilot-headers-BsH5cqGj.mjs +0 -48
- package/dist/host-4t713IeR.mjs +0 -37
- package/dist/model-utils-1GiZ2_rr.mjs +0 -64
- package/dist/openai-responses-ClspWt4I.mjs +0 -136
- package/dist/openai-tool-projection-WHf2nuOI.mjs +0 -200
- package/dist/reasoning-tag-text-partitioner-BlVe67g6.mjs +0 -400
- package/dist/stream-first-event-timeout-RjWszj8c.mjs +0 -106
- package/npm-shrinkwrap.json +0 -645
package/dist/{openai-chatgpt-responses-DP63Qt01.mjs → openai-chatgpt-responses-CedIj0hk.mjs}
RENAMED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
1
|
+
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-COpOtRwq.mjs";
|
|
3
3
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
4
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { a as clampOpenAIPromptCacheKey } from "./openai-tool-projection-WHf2nuOI.mjs";
|
|
4
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-XYGZcgO8.mjs";
|
|
5
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
6
|
+
import { A as buildBaseOptions, o as stripSystemPromptCacheBoundary, t as inspectTlsCertificateError } from "./shared-CdjNZd35.mjs";
|
|
7
|
+
import { t as toErrorObject } from "./error-coercion-DgxlWC0n.mjs";
|
|
8
|
+
import { n as clampTimerTimeoutMs, o as resolveTimerTimeoutMs } from "./number-coercion-DvG7SNMg.mjs";
|
|
10
9
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
10
|
+
import { d as transportAbortError } from "./transport-stream-shared-BbMELSI4.mjs";
|
|
11
|
+
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
11
12
|
import { i as registerSessionResourceCleanup, n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-DhAAzLkj.mjs";
|
|
13
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-C3OgBjIk.mjs";
|
|
12
14
|
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
15
|
+
import { _t as supportsOpenAITemperature, a as convertResponsesMessages, l as convertResponsesToolPayload, s as resolveResponsesReasoningEffort, y as processResponsesStream } from "./openai-D3PD6PE-.mjs";
|
|
13
16
|
//#region packages/ai/src/internal/retry-sleep.ts
|
|
14
17
|
function sleepWithAbort(ms, signal) {
|
|
15
18
|
return new Promise((resolve, reject) => {
|
|
@@ -58,6 +61,22 @@ function isRetryableError(status, errorText) {
|
|
|
58
61
|
if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504) return true;
|
|
59
62
|
return /rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(errorText);
|
|
60
63
|
}
|
|
64
|
+
function resolveHttpRetryDelayMs(response, attempt) {
|
|
65
|
+
const fallbackMs = BASE_DELAY_MS * 2 ** attempt;
|
|
66
|
+
const retryAfterMs = response.headers.get("retry-after-ms");
|
|
67
|
+
if (retryAfterMs) {
|
|
68
|
+
const trimmed = retryAfterMs.trim();
|
|
69
|
+
const millis = Number(trimmed);
|
|
70
|
+
if (/^\d+(?:\.\d+)?$/.test(trimmed) && Number.isFinite(millis)) return clampTimerTimeoutMs(millis, 0) ?? fallbackMs;
|
|
71
|
+
}
|
|
72
|
+
const retryAfter = response.headers.get("retry-after");
|
|
73
|
+
if (!retryAfter) return fallbackMs;
|
|
74
|
+
const trimmed = retryAfter.trim();
|
|
75
|
+
const seconds = Number(trimmed);
|
|
76
|
+
if (/^\d+$/.test(trimmed) && Number.isFinite(seconds)) return clampTimerTimeoutMs(seconds * 1e3, 0) ?? fallbackMs;
|
|
77
|
+
const retryAt = parseRetryAfterHttpDateMs(trimmed);
|
|
78
|
+
return retryAt === void 0 ? fallbackMs : clampTimerTimeoutMs(retryAt - Date.now(), 0) ?? fallbackMs;
|
|
79
|
+
}
|
|
61
80
|
function resolveRequestTimeoutMs(options) {
|
|
62
81
|
const timeoutMs = options?.timeoutMs;
|
|
63
82
|
return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? resolveTimerTimeoutMs(timeoutMs, 1) : void 0;
|
|
@@ -151,7 +170,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
151
170
|
await processWebSocketStream(resolveCodexWebSocketUrl(model.baseUrl), body, websocketHeaders, output, stream, model, () => {
|
|
152
171
|
websocketStarted = true;
|
|
153
172
|
}, requestOptions, firstEventAbort.abort);
|
|
154
|
-
if (activeSignal?.aborted) throw
|
|
173
|
+
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
155
174
|
stream.push({
|
|
156
175
|
type: "done",
|
|
157
176
|
reason: output.stopReason,
|
|
@@ -187,60 +206,43 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
187
206
|
let lastError;
|
|
188
207
|
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
189
208
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
190
|
-
if (activeSignal?.aborted) throw
|
|
209
|
+
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
210
|
+
let attemptResponse;
|
|
211
|
+
let errorText;
|
|
191
212
|
try {
|
|
192
|
-
|
|
213
|
+
attemptResponse = await fetch(resolveCodexUrl(model.baseUrl), {
|
|
193
214
|
method: "POST",
|
|
194
215
|
headers: sseHeaders,
|
|
195
216
|
body: sseBody,
|
|
196
217
|
signal: activeSignal
|
|
197
218
|
});
|
|
219
|
+
response = attemptResponse;
|
|
198
220
|
await options?.onResponse?.({
|
|
199
|
-
status:
|
|
200
|
-
headers: headersToRecord(
|
|
221
|
+
status: attemptResponse.status,
|
|
222
|
+
headers: headersToRecord(attemptResponse.headers)
|
|
201
223
|
}, model);
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
if (attempt < maxRetries && isRetryableError(response.status, errorText)) {
|
|
205
|
-
let delayMs = BASE_DELAY_MS * 2 ** attempt;
|
|
206
|
-
const retryAfterMs = response.headers.get("retry-after-ms");
|
|
207
|
-
if (retryAfterMs !== null) {
|
|
208
|
-
const trimmedRetryAfterMs = retryAfterMs.trim();
|
|
209
|
-
const millis = Number(trimmedRetryAfterMs);
|
|
210
|
-
if (/^\d+(?:\.\d+)?$/.test(trimmedRetryAfterMs) && Number.isFinite(millis)) delayMs = clampTimerTimeoutMs(millis, 0) ?? delayMs;
|
|
211
|
-
} else {
|
|
212
|
-
const retryAfter = response.headers.get("retry-after");
|
|
213
|
-
if (retryAfter) {
|
|
214
|
-
const trimmedRetryAfter = retryAfter.trim();
|
|
215
|
-
const seconds = Number(trimmedRetryAfter);
|
|
216
|
-
if (/^\d+$/.test(trimmedRetryAfter) && Number.isFinite(seconds)) delayMs = clampTimerTimeoutMs(seconds * 1e3, 0) ?? delayMs;
|
|
217
|
-
else {
|
|
218
|
-
const retryAt = parseRetryAfterHttpDateMs(trimmedRetryAfter);
|
|
219
|
-
if (retryAt !== void 0) delayMs = clampTimerTimeoutMs(retryAt - Date.now(), 0) ?? delayMs;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
await sleepWithAbort(delayMs, activeSignal);
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
const info = await parseErrorResponse(new Response(errorText, {
|
|
227
|
-
status: response.status,
|
|
228
|
-
statusText: response.statusText
|
|
229
|
-
}));
|
|
230
|
-
throw new Error(info.friendlyMessage || info.message);
|
|
224
|
+
if (attemptResponse.ok) break;
|
|
225
|
+
errorText = await readChatGptResponsesErrorTextLimited(attemptResponse);
|
|
231
226
|
} catch (error) {
|
|
232
227
|
if (error instanceof Error) {
|
|
233
228
|
if (isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0) throw formatRequestTimeoutError(requestTimeoutMs, error);
|
|
234
229
|
if (error.name === "AbortError" || error.message === "Request was aborted") throw new Error("Request was aborted", { cause: error });
|
|
235
230
|
if (error.name === "TimeoutError" && requestTimeoutMs !== void 0) throw new Error(`Request timed out after ${requestTimeoutMs}ms`, { cause: error });
|
|
236
231
|
}
|
|
237
|
-
|
|
238
|
-
|
|
232
|
+
const tlsCertificateError = inspectTlsCertificateError(error);
|
|
233
|
+
lastError = toErrorObject(error, String(error));
|
|
234
|
+
if (attempt < maxRetries && !lastError.message.includes("usage limit") && !tlsCertificateError) {
|
|
239
235
|
await sleepWithAbort(BASE_DELAY_MS * 2 ** attempt, activeSignal);
|
|
240
236
|
continue;
|
|
241
237
|
}
|
|
242
238
|
throw lastError;
|
|
243
239
|
}
|
|
240
|
+
if (attempt < maxRetries && isRetryableError(attemptResponse.status, errorText)) {
|
|
241
|
+
await sleepWithAbort(resolveHttpRetryDelayMs(attemptResponse, attempt), activeSignal);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const info = parseErrorResponseText(errorText, attemptResponse.status, attemptResponse.statusText);
|
|
245
|
+
throw new Error(info.friendlyMessage || info.message);
|
|
244
246
|
}
|
|
245
247
|
if (!response?.ok) throw lastError ?? /* @__PURE__ */ new Error("Failed after retries");
|
|
246
248
|
if (!response.body) throw new Error("No response body");
|
|
@@ -249,7 +251,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
249
251
|
partial: output
|
|
250
252
|
});
|
|
251
253
|
await processStream(response, output, stream, model, options, firstEventAbort.abort);
|
|
252
|
-
if (activeSignal?.aborted) throw
|
|
254
|
+
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
253
255
|
stream.push({
|
|
254
256
|
type: "done",
|
|
255
257
|
reason: output.stopReason,
|
|
@@ -359,6 +361,7 @@ async function processStream(response, output, stream, model, options, abortFirs
|
|
|
359
361
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
360
362
|
abortFirstEventStream,
|
|
361
363
|
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
364
|
+
signal: options?.signal,
|
|
362
365
|
resolveServiceTier: resolveCodexServiceTier,
|
|
363
366
|
applyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model)
|
|
364
367
|
});
|
|
@@ -796,7 +799,7 @@ async function* parseWebSocket(socket, signal) {
|
|
|
796
799
|
signal?.addEventListener("abort", onAbort);
|
|
797
800
|
try {
|
|
798
801
|
while (true) {
|
|
799
|
-
if (signal?.aborted) throw
|
|
802
|
+
if (signal?.aborted) throw transportAbortError(signal);
|
|
800
803
|
const next = queue.shift();
|
|
801
804
|
if (next !== void 0) {
|
|
802
805
|
yield next;
|
|
@@ -807,7 +810,7 @@ async function* parseWebSocket(socket, signal) {
|
|
|
807
810
|
pending = resolve;
|
|
808
811
|
});
|
|
809
812
|
}
|
|
810
|
-
if (failed) throw
|
|
813
|
+
if (failed) throw toErrorObject(failed, "Non-Error thrown");
|
|
811
814
|
if (!sawCompletion) throw new Error("WebSocket stream closed before response.completed");
|
|
812
815
|
} finally {
|
|
813
816
|
socket.removeEventListener("message", onMessage);
|
|
@@ -869,7 +872,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
869
872
|
const fullBody = body;
|
|
870
873
|
const requestBody = useCachedContext && entry ? buildCachedWebSocketRequestBody(entry, fullBody) : fullBody;
|
|
871
874
|
try {
|
|
872
|
-
if (options?.signal?.aborted) throw
|
|
875
|
+
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
873
876
|
socket.send(JSON.stringify({
|
|
874
877
|
type: "response.create",
|
|
875
878
|
...requestBody
|
|
@@ -879,6 +882,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
879
882
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
880
883
|
abortFirstEventStream,
|
|
881
884
|
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
885
|
+
signal: options?.signal,
|
|
882
886
|
resolveServiceTier: resolveCodexServiceTier,
|
|
883
887
|
applyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model)
|
|
884
888
|
});
|
|
@@ -936,15 +940,14 @@ async function readChatGptResponsesErrorTextLimited(response) {
|
|
|
936
940
|
}
|
|
937
941
|
return text;
|
|
938
942
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
let message = raw || response.statusText || "Request failed";
|
|
943
|
+
function parseErrorResponseText(raw, status, statusText) {
|
|
944
|
+
let message = raw || statusText || "Request failed";
|
|
942
945
|
let friendlyMessage;
|
|
943
946
|
try {
|
|
944
947
|
const err = JSON.parse(raw)?.error;
|
|
945
948
|
if (err) {
|
|
946
949
|
const code = err.code || err.type || "";
|
|
947
|
-
if (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code) ||
|
|
950
|
+
if (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code) || status === 429) {
|
|
948
951
|
const plan = err.plan_type ? ` (${err.plan_type.toLowerCase()} plan)` : "";
|
|
949
952
|
const mins = err.resets_at ? Math.max(0, Math.round((err.resets_at * 1e3 - Date.now()) / 6e4)) : void 0;
|
|
950
953
|
friendlyMessage = `You have hit your ChatGPT usage limit${plan}.${mins !== void 0 ? ` Try again in ~${mins} min.` : ""}`.trim();
|
|
@@ -1003,12 +1006,5 @@ function buildWebSocketHeaders(initHeaders, additionalHeaders, accountId, token,
|
|
|
1003
1006
|
headers.set("session_id", requestId);
|
|
1004
1007
|
return headers;
|
|
1005
1008
|
}
|
|
1006
|
-
function toLintErrorObject(value, fallbackMessage) {
|
|
1007
|
-
if (value instanceof Error) return value;
|
|
1008
|
-
if (typeof value === "string") return new Error(value);
|
|
1009
|
-
const error = new Error(fallbackMessage, { cause: value });
|
|
1010
|
-
if (typeof value === "object" && value !== null || typeof value === "function") Object.assign(error, value);
|
|
1011
|
-
return error;
|
|
1012
|
-
}
|
|
1013
1009
|
//#endregion
|
|
1014
1010
|
export { closeOpenAICodexWebSocketSessions, extractOpenAICodexAccountId, parseSSEForTest, resetOpenAICodexWebSocketStateForTest, streamOpenAICodexResponses, streamSimpleOpenAICodexResponses };
|