@openclaw/ai 2026.9.1-beta.1 → 2026.9.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-DI4PZKKB.mjs → anthropic-BDdqdVLK.mjs} +222 -216
- package/dist/{anthropic-compaction-replay-nhKaCXu6.mjs → anthropic-compaction-replay-DB2FGLQc.mjs} +160 -68
- package/dist/{anthropic-payload-policy-B_0n0enE.d.mts → anthropic-payload-policy-d46X2pR0.d.mts} +28 -4
- package/dist/{api-registry-CTd8NzcD.d.mts → api-registry-DWtPjzyn.d.mts} +2 -2
- package/dist/{azure-openai-responses-D8dI0ekg.mjs → azure-openai-responses-C5bZRfAP.mjs} +12 -9
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/{diagnostics-COpOtRwq.mjs → diagnostics-CPeq9F7y.mjs} +5 -1
- package/dist/diagnostics-DfFyKeX_.mjs +136 -0
- package/dist/{diagnostics-BaTA9eVl.d.mts → diagnostics-DnPnOui6.d.mts} +5 -1
- package/dist/diagnostics.d.mts +8 -3
- package/dist/diagnostics.mjs +4 -3
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/{event-stream-uSMZJ3FA.mjs → event-stream-BgDvQeum.mjs} +3 -9
- package/dist/{event-stream-LiXePESD.d.mts → event-stream-BhT5T1Ay.d.mts} +1 -1
- package/dist/event-stream-zctLx0yr.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-Od-LLdVK.mjs → google-4qeuE8iX.mjs} +9 -7
- package/dist/{google-shared-Bgr9lFPw.mjs → google-shared-CWeG8RIl.mjs} +27 -23
- package/dist/{google-vertex-aerRSXc4.mjs → google-vertex-O9BcnB6X.mjs} +8 -6
- package/dist/{host-D51fmkH6.mjs → host-CEvLw30U.mjs} +54 -9
- package/dist/{host-DsbPMFU6.d.mts → host-DjzGmdZ2.d.mts} +3 -3
- package/dist/index-FnHM2FcI.d.mts +117 -0
- package/dist/index.d.mts +10 -11
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +59 -55
- 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 +66 -64
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +43 -43
- package/dist/internal/runtime.mjs +10 -8
- package/dist/internal/shared.d.mts +25 -25
- package/dist/internal/shared.mjs +95 -4
- package/dist/{mistral-EiHdymeb.mjs → mistral-Tb6oalqH.mjs} +30 -23
- package/dist/{openai-chatgpt-responses-DHpF9o1e.mjs → openai-chatgpt-responses-yUXjPNfu.mjs} +76 -137
- package/dist/{openai-completions-EFPiUGfS.mjs → openai-completions-BIUV3RDT.mjs} +26 -22
- package/dist/{openai-completions-compat-BefmHT26.d.mts → openai-completions-compat-CpjYUArk.d.mts} +5 -5
- package/dist/{openai-completions-stream-DUlGwRMz.mjs → openai-completions-stream-BsrBe3Gg.mjs} +103 -96
- package/dist/openai-prompt-cache-CGnVB74a.mjs +21 -0
- package/dist/openai-prompt-cache-CNoIfHYC.d.mts +16 -0
- package/dist/{openai-responses-BogP8OjX.mjs → openai-responses-CCL41ALM.mjs} +15 -14
- package/dist/openai-responses-compaction-window-BMVHFOtq.mjs +697 -0
- package/dist/{openai-responses-contracts-Dvj_UtPy.d.mts → openai-responses-contracts-rF5DDRNS.d.mts} +23 -6
- 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-Cd4hJG-S.mjs → openai-responses-prompt-observer-internal-D0bhBfgL.mjs} +4 -18
- package/dist/{openai-responses-shared-DJThc6jW.mjs → openai-responses-shared-Bmma_3Qc.mjs} +438 -309
- package/dist/{openai-tool-schema-ho-hIkQf.mjs → openai-tool-schema-_pTAJqKF.mjs} +30 -40
- package/dist/{provider-error-DDOs_Bz0.mjs → provider-error-9TraxGvt.mjs} +20 -92
- package/dist/{provider-options-MdMBLzlU.d.mts → provider-options-Bcc_p-TU.d.mts} +26 -6
- package/dist/provider-replay-context-BuSUaAk5.mjs +21 -0
- package/dist/{provider-transcript-transform-C01bQ5a3.mjs → provider-transcript-transform-BaMbI1hr.mjs} +1 -1
- package/dist/provider-types.d.mts +19 -20
- package/dist/providers.d.mts +6 -6
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-DLCNXki6.mjs} +158 -94
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-DCkltN94.mjs → sanitize-unicode-D6xUvZaS.mjs} +2 -8
- package/dist/{simple-options-CFj7x3J4.mjs → simple-options-BjHCCh4v.mjs} +42 -6
- package/dist/{src-Bu3FiFAG.mjs → src-2qBGKg8O.mjs} +83 -2
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{tool-schema-json-projection-qvTEs5Am.mjs → tool-schema-json-projection-mJhXDcyz.mjs} +21 -31
- package/dist/{transport-stream-shared-ljShVIZB.mjs → transport-stream-shared-CZqMhfIw.mjs} +19 -6
- package/dist/{transport-stream-shared-rvaCyFYt.d.mts → transport-stream-shared-xnaqxmbP.d.mts} +5 -5
- package/dist/{transport-utils-LJ1_rbi-.mjs → transport-utils-7il795_9.mjs} +5 -8
- package/dist/transports.d.mts +121 -85
- package/dist/transports.mjs +747 -464
- package/dist/types-3Lnm-QSJ.d.mts +1 -0
- package/dist/{types-DhLoJbFm.d.mts → types-CJ1-Ht7A.d.mts} +55 -19
- package/dist/types.d.mts +7 -7
- package/dist/types.mjs +5 -5
- package/dist/{validation-Dk7q7NMN.d.mts → validation-AKZBDGQd.d.mts} +1 -1
- 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 +5 -5
- package/dist/anthropic-BECQCNdF.d.mts +0 -98
- package/dist/event-stream-BKp4fOt_.d.mts +0 -1
- package/dist/index-Qbej8io0.d.mts +0 -3
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/openai-responses-contracts-QUY12X0B.mjs +0 -233
- package/dist/openai-responses-payload-policy-D8EdimYe.mjs +0 -204
- package/dist/provider-options-AvldWZt8.mjs +0 -21
- package/dist/tls-certificate-errors-DXSpluKI.mjs +0 -93
- package/dist/types-GiAjXatj.d.mts +0 -1
package/dist/{openai-chatgpt-responses-DHpF9o1e.mjs → openai-chatgpt-responses-yUXjPNfu.mjs}
RENAMED
|
@@ -1,46 +1,23 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { n as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { C as
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { S as supportsOpenAITemperature, m as responsesPromptObserver } from "./openai-responses-contracts-QUY12X0B.mjs";
|
|
1
|
+
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-CEvLw30U.mjs";
|
|
4
|
+
import { r as toErrorObject } from "./diagnostics-DfFyKeX_.mjs";
|
|
5
|
+
import { u as resolveTimerTimeoutMs } from "./base64-CEFBpSkN.mjs";
|
|
6
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
7
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-BjHCCh4v.mjs";
|
|
8
|
+
import { c as parseRetryAfterSeconds, t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-7il795_9.mjs";
|
|
9
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
10
|
+
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-CZqMhfIw.mjs";
|
|
11
|
+
import { B as resolveNextResponsesEncryptedContentAttempt, I as commitResponsesEncryptedContentAttempt, R as isInvalidEncryptedContentError, X as suppressOpenAIResponsesCompaction, a as resolveResponsesReasoningEffort, c as convertResponsesToolPayload, i as createResponsesAssistantOutput, l as processResponsesStream, m as ResponsesStreamFailure, n as applyResponsesServiceTierPricing, o as resolveResponsesRequestReasoningEffort, q as buildOpenAIResponsesReasoningReplayMetadata, r as convertResponsesMessages } from "./openai-responses-shared-Bmma_3Qc.mjs";
|
|
12
|
+
import { C as createOpenAIProviderAcceptanceHook, w as createOpenAIResponseHook } from "./openai-tool-schema-_pTAJqKF.mjs";
|
|
13
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
14
|
+
import { S as responsesPromptObserver, j as supportsOpenAITemperature } from "./openai-responses-compaction-window-BMVHFOtq.mjs";
|
|
15
|
+
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
17
16
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
18
|
-
import "./
|
|
17
|
+
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-D0bhBfgL.mjs";
|
|
19
18
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
20
|
-
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
21
|
-
import { t as inspectTlsCertificateError } from "./tls-certificate-errors-DXSpluKI.mjs";
|
|
22
|
-
//#region packages/ai/src/internal/retry-sleep.ts
|
|
23
|
-
function sleepWithAbort(ms, signal) {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
if (signal?.aborted) {
|
|
26
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const onAbort = () => {
|
|
30
|
-
clearTimeout(timeout);
|
|
31
|
-
signal?.removeEventListener("abort", onAbort);
|
|
32
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
33
|
-
};
|
|
34
|
-
const timeout = setTimeout(() => {
|
|
35
|
-
signal?.removeEventListener("abort", onAbort);
|
|
36
|
-
resolve();
|
|
37
|
-
}, ms);
|
|
38
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
19
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
43
|
-
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES =
|
|
20
|
+
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
44
21
|
var CodexProtocolError = class extends Error {
|
|
45
22
|
constructor(message, options) {
|
|
46
23
|
super(message);
|
|
@@ -104,13 +81,11 @@ function loadNodeOs() {
|
|
|
104
81
|
}
|
|
105
82
|
const os = loadNodeOs();
|
|
106
83
|
const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
107
|
-
const DEFAULT_MAX_RETRIES = 3;
|
|
108
|
-
const BASE_DELAY_MS = 1e3;
|
|
109
84
|
const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
110
85
|
const CODEX_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
|
|
111
86
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
112
87
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
113
|
-
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES =
|
|
88
|
+
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
114
89
|
const CODEX_RESPONSE_STATUSES = /* @__PURE__ */ new Set([
|
|
115
90
|
"completed",
|
|
116
91
|
"incomplete",
|
|
@@ -119,26 +94,6 @@ const CODEX_RESPONSE_STATUSES = /* @__PURE__ */ new Set([
|
|
|
119
94
|
"queued",
|
|
120
95
|
"in_progress"
|
|
121
96
|
]);
|
|
122
|
-
function isRetryableError(status, errorText) {
|
|
123
|
-
if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504) return true;
|
|
124
|
-
return /rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(errorText);
|
|
125
|
-
}
|
|
126
|
-
function resolveHttpRetryDelayMs(response, attempt) {
|
|
127
|
-
const fallbackMs = BASE_DELAY_MS * 2 ** attempt;
|
|
128
|
-
const retryAfterMs = response.headers.get("retry-after-ms");
|
|
129
|
-
if (retryAfterMs) {
|
|
130
|
-
const trimmed = retryAfterMs.trim();
|
|
131
|
-
const millis = Number(trimmed);
|
|
132
|
-
if (/^\d+(?:\.\d+)?$/.test(trimmed) && Number.isFinite(millis)) return clampTimerTimeoutMs(millis, 0) ?? fallbackMs;
|
|
133
|
-
}
|
|
134
|
-
const retryAfter = response.headers.get("retry-after");
|
|
135
|
-
if (!retryAfter) return fallbackMs;
|
|
136
|
-
const trimmed = retryAfter.trim();
|
|
137
|
-
const seconds = Number(trimmed);
|
|
138
|
-
if (/^\d+$/.test(trimmed) && Number.isFinite(seconds)) return clampTimerTimeoutMs(seconds * 1e3, 0) ?? fallbackMs;
|
|
139
|
-
const retryAt = parseRetryAfterHttpDateMs(trimmed);
|
|
140
|
-
return retryAt === void 0 ? fallbackMs : clampTimerTimeoutMs(retryAt - Date.now(), 0) ?? fallbackMs;
|
|
141
|
-
}
|
|
142
97
|
function resolveRequestTimeoutMs(options) {
|
|
143
98
|
const timeoutMs = options?.timeoutMs;
|
|
144
99
|
return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? resolveTimerTimeoutMs(timeoutMs, 1) : void 0;
|
|
@@ -267,7 +222,6 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
267
222
|
}
|
|
268
223
|
}
|
|
269
224
|
let response;
|
|
270
|
-
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
271
225
|
while (true) {
|
|
272
226
|
const activeAttempt = semanticAttempt;
|
|
273
227
|
response = void 0;
|
|
@@ -276,71 +230,55 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
276
230
|
const compressedBody = model.provider === "openai" && !sseHeaders.has("content-encoding") ? compressRequestBodyZstd(bodyJson) : null;
|
|
277
231
|
if (compressedBody) sseHeaders.set("content-encoding", "zstd");
|
|
278
232
|
const sseBody = compressedBody ?? bodyJson;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
body: sseBody,
|
|
292
|
-
signal: activeSignal
|
|
293
|
-
});
|
|
294
|
-
} catch (error) {
|
|
295
|
-
if (error instanceof Error) {
|
|
296
|
-
if (isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0) throw formatRequestTimeoutError(requestTimeoutMs, error);
|
|
297
|
-
if (error.name === "AbortError" || error.message === "Request was aborted") throw new Error("Request was aborted", { cause: error });
|
|
298
|
-
if (error.name === "TimeoutError" && requestTimeoutMs !== void 0) throw new Error(`Request timed out after ${requestTimeoutMs}ms`, { cause: error });
|
|
299
|
-
}
|
|
300
|
-
const tlsCertificateError = inspectTlsCertificateError(error);
|
|
301
|
-
const lastError = toErrorObject(error, String(error));
|
|
302
|
-
if (attempt < maxRetries && !lastError.message.includes("usage limit") && !tlsCertificateError) {
|
|
303
|
-
await sleepWithAbort(BASE_DELAY_MS * 2 ** attempt, activeSignal);
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
throw lastError;
|
|
307
|
-
}
|
|
308
|
-
response = attemptResponse;
|
|
309
|
-
if (attemptResponse.ok) break;
|
|
310
|
-
const hookStream = withFirstStreamEventTimeout(withProviderResponseHook({
|
|
311
|
-
signal: firstEventAbort.signal,
|
|
312
|
-
abort: firstEventAbort.abort,
|
|
313
|
-
hook: createOpenAIResponseHook(options?.onResponse, attemptResponse, model)
|
|
314
|
-
}), {
|
|
315
|
-
provider: model.provider,
|
|
316
|
-
api: model.api,
|
|
317
|
-
model: model.id,
|
|
318
|
-
timeoutMs: getFirstStreamEventTimeoutMs(options) ?? 0,
|
|
319
|
-
stage: "responses",
|
|
320
|
-
abort: firstEventAbort.abort,
|
|
321
|
-
onTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
233
|
+
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
234
|
+
observePromptEgress?.(activeAttempt.request, {
|
|
235
|
+
egress: "native-codex-sse",
|
|
236
|
+
payloadVariant: activeAttempt.kind
|
|
237
|
+
});
|
|
238
|
+
let attemptResponse;
|
|
239
|
+
try {
|
|
240
|
+
attemptResponse = await fetch(resolveCodexUrl(model.baseUrl), {
|
|
241
|
+
method: "POST",
|
|
242
|
+
headers: sseHeaders,
|
|
243
|
+
body: sseBody,
|
|
244
|
+
signal: activeSignal
|
|
322
245
|
});
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
246
|
+
} catch (error) {
|
|
247
|
+
if (error instanceof Error) {
|
|
248
|
+
if (isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0) throw formatRequestTimeoutError(requestTimeoutMs, error);
|
|
249
|
+
if (error.name === "AbortError" || error.message === "Request was aborted") throw new Error("Request was aborted", { cause: error });
|
|
250
|
+
if (error.name === "TimeoutError" && requestTimeoutMs !== void 0) throw new Error(`Request timed out after ${requestTimeoutMs}ms`, { cause: error });
|
|
327
251
|
}
|
|
328
|
-
|
|
329
|
-
terminalResponseError = new CodexApiError(info.friendlyMessage || info.message, { code: info.code });
|
|
330
|
-
break;
|
|
252
|
+
throw toErrorObject(error, String(error));
|
|
331
253
|
}
|
|
332
|
-
|
|
333
|
-
|
|
254
|
+
response = attemptResponse;
|
|
255
|
+
if (attemptResponse.ok) {
|
|
256
|
+
if (!attemptResponse.body) throw new Error("No response body");
|
|
334
257
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
335
258
|
commitSemanticAttempt(activeAttempt);
|
|
336
259
|
break;
|
|
337
260
|
}
|
|
261
|
+
const hookStream = withFirstStreamEventTimeout(withProviderResponseHook({
|
|
262
|
+
signal: firstEventAbort.signal,
|
|
263
|
+
abort: firstEventAbort.abort,
|
|
264
|
+
hook: createOpenAIResponseHook(options?.onResponse, attemptResponse, model)
|
|
265
|
+
}), {
|
|
266
|
+
provider: model.provider,
|
|
267
|
+
api: model.api,
|
|
268
|
+
model: model.id,
|
|
269
|
+
timeoutMs: getFirstStreamEventTimeoutMs(options) ?? 0,
|
|
270
|
+
stage: "responses",
|
|
271
|
+
abort: firstEventAbort.abort,
|
|
272
|
+
onTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
273
|
+
});
|
|
274
|
+
const [errorText] = await Promise.all([readChatGptResponsesErrorTextLimited(attemptResponse, activeSignal), hookStream[Symbol.asyncIterator]().next()]);
|
|
275
|
+
const terminalResponseError = parseErrorResponse(errorText, attemptResponse);
|
|
338
276
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
339
|
-
const nextSemanticAttempt =
|
|
340
|
-
if (!nextSemanticAttempt) throw terminalResponseError
|
|
277
|
+
const nextSemanticAttempt = await resolveNextResponsesEncryptedContentAttempt(activeAttempt, terminalResponseError, { buildFullHistoryRequest: () => buildBody("full-history") });
|
|
278
|
+
if (!nextSemanticAttempt) throw terminalResponseError;
|
|
341
279
|
semanticAttempt = nextSemanticAttempt;
|
|
342
280
|
}
|
|
343
|
-
|
|
281
|
+
const hookedResponseStream = withProviderResponseHook({
|
|
344
282
|
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response)),
|
|
345
283
|
signal: firstEventAbort.signal,
|
|
346
284
|
abort: firstEventAbort.abort,
|
|
@@ -349,7 +287,8 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
349
287
|
type: "start",
|
|
350
288
|
partial: output
|
|
351
289
|
})
|
|
352
|
-
})
|
|
290
|
+
});
|
|
291
|
+
await processResponsesStream(hookedResponseStream, output, stream, model, {
|
|
353
292
|
serviceTier: options?.serviceTier,
|
|
354
293
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
355
294
|
abortFirstEventStream: firstEventAbort.abort,
|
|
@@ -374,7 +313,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
374
313
|
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
375
314
|
const normalizedError = requestTimedOut && requestTimeoutMs !== void 0 ? formatRequestTimeoutError(requestTimeoutMs, error) : error;
|
|
376
315
|
for (const block of output.content) delete block.partialJson;
|
|
377
|
-
const terminal =
|
|
316
|
+
const terminal = assignTransportErrorDetails(output, normalizedError, options?.signal);
|
|
378
317
|
getAiTransportHost().logWarn("openai-transport", "ChatGPT Responses stream terminated", {
|
|
379
318
|
provider: model.provider,
|
|
380
319
|
api: model.api,
|
|
@@ -384,7 +323,6 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
384
323
|
stopReason: terminal.stopReason,
|
|
385
324
|
failureKind: classifyStreamFailure(error, options?.signal, requestTimedOut)
|
|
386
325
|
});
|
|
387
|
-
Object.assign(output, terminal);
|
|
388
326
|
stream.push({
|
|
389
327
|
type: "error",
|
|
390
328
|
reason: terminal.stopReason,
|
|
@@ -436,13 +374,11 @@ function buildRequestBody(model, context, options, replayMode = "checkpoint") {
|
|
|
436
374
|
body.parallel_tool_calls = true;
|
|
437
375
|
}
|
|
438
376
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
};
|
|
445
|
-
}
|
|
377
|
+
const effort = options?.reasoningEffort === void 0 ? void 0 : resolveResponsesRequestReasoningEffort(model, options.reasoningEffort);
|
|
378
|
+
if (effort !== void 0) body.reasoning = {
|
|
379
|
+
effort,
|
|
380
|
+
summary: options?.reasoningSummary ?? "auto"
|
|
381
|
+
};
|
|
446
382
|
return body;
|
|
447
383
|
}
|
|
448
384
|
function resolveCodexServiceTier(responseServiceTier, requestServiceTier) {
|
|
@@ -466,6 +402,7 @@ var CodexApiError = class extends Error {
|
|
|
466
402
|
super(message);
|
|
467
403
|
this.name = "CodexApiError";
|
|
468
404
|
this.code = options?.code;
|
|
405
|
+
this.status = options?.status;
|
|
469
406
|
this.payload = options?.payload;
|
|
470
407
|
this.cause = options?.cause;
|
|
471
408
|
}
|
|
@@ -515,8 +452,8 @@ function normalizeCodexStatus(status) {
|
|
|
515
452
|
return CODEX_RESPONSE_STATUSES.has(status) ? status : void 0;
|
|
516
453
|
}
|
|
517
454
|
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
518
|
-
const SESSION_WEBSOCKET_CACHE_TTL_MS =
|
|
519
|
-
const SESSION_WEBSOCKET_MAX_AGE_MS =
|
|
455
|
+
const SESSION_WEBSOCKET_CACHE_TTL_MS = 3e5;
|
|
456
|
+
const SESSION_WEBSOCKET_MAX_AGE_MS = 33e5;
|
|
520
457
|
const websocketSessionCache = /* @__PURE__ */ new Map();
|
|
521
458
|
const websocketSseFallbackSessions = /* @__PURE__ */ new Set();
|
|
522
459
|
let cachedWebsocket = null;
|
|
@@ -1012,7 +949,8 @@ async function readChatGptResponsesErrorTextLimited(response, signal) {
|
|
|
1012
949
|
}
|
|
1013
950
|
return text;
|
|
1014
951
|
}
|
|
1015
|
-
function
|
|
952
|
+
function parseErrorResponse(raw, response) {
|
|
953
|
+
const { status, statusText } = response;
|
|
1016
954
|
let message = raw || statusText || "Request failed";
|
|
1017
955
|
let friendlyMessage;
|
|
1018
956
|
let code;
|
|
@@ -1028,11 +966,12 @@ function parseErrorResponseText(raw, status, statusText) {
|
|
|
1028
966
|
message = err.message || friendlyMessage || message;
|
|
1029
967
|
}
|
|
1030
968
|
} catch {}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
969
|
+
const retryAfterSeconds = parseRetryAfterSeconds(response.headers);
|
|
970
|
+
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
971
|
+
return new CodexApiError(`${friendlyMessage || message}${retryAfterSuffix}`, {
|
|
972
|
+
code,
|
|
973
|
+
status
|
|
974
|
+
});
|
|
1036
975
|
}
|
|
1037
976
|
function extractOpenAICodexAccountId(token) {
|
|
1038
977
|
const accountId = resolveOpenAICodexAccountId(token);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import { i as clampThinkingLevel } from "./sanitize-unicode-
|
|
4
|
-
import { n as getAiTransportHost } from "./host-
|
|
5
|
-
import { n as
|
|
6
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
3
|
+
import { i as clampThinkingLevel } from "./sanitize-unicode-D6xUvZaS.mjs";
|
|
4
|
+
import { n as getAiTransportHost } from "./host-CEvLw30U.mjs";
|
|
5
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
7
6
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
7
|
+
import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-BjHCCh4v.mjs";
|
|
8
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
9
|
+
import { _ as transportAbortError, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-CZqMhfIw.mjs";
|
|
10
|
+
import { E as tagUnresolvedTextAsCommentary, S as shouldOmitOllamaCompatResponseFormat, _ as hasToolCallHistory, b as resolveOpenAICompletionsCompat, g as convertMessages, h as resolveOpenAIReasoningEffortMap, t as processCompletionsStream, v as finalizeOpenAICompletionsToolCalls, w as clearPendingCommentaryText, x as resolveOpenAICompletionsResponseFormat } from "./openai-completions-stream-BsrBe3Gg.mjs";
|
|
11
|
+
import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-_pTAJqKF.mjs";
|
|
12
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
13
13
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
14
14
|
import OpenAI from "openai";
|
|
15
15
|
//#region packages/ai/src/providers/openai-completions.ts
|
|
@@ -60,7 +60,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
60
60
|
const requestOptions = {
|
|
61
61
|
signal: firstEventAbort.signal,
|
|
62
62
|
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
63
|
-
maxRetries:
|
|
63
|
+
maxRetries: 0
|
|
64
64
|
};
|
|
65
65
|
const { data: openaiStream, response } = await client.chat.completions.create(params, requestOptions).withResponse();
|
|
66
66
|
const hookedOpenAIStream = withProviderResponseHook({
|
|
@@ -125,6 +125,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
125
125
|
provisionalCommentaryTags,
|
|
126
126
|
signal: options?.signal,
|
|
127
127
|
emitReasoning: shouldEmitReasoning,
|
|
128
|
+
strictReasoningTags: reasoningTagTextPolicy.isStrict(options),
|
|
128
129
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
129
130
|
abortFirstEventStream: firstEventAbort.abort,
|
|
130
131
|
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
@@ -143,8 +144,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
143
144
|
});
|
|
144
145
|
stream.end();
|
|
145
146
|
} catch (error) {
|
|
146
|
-
const terminal =
|
|
147
|
-
Object.assign(output, terminal);
|
|
147
|
+
const terminal = assignTransportErrorDetails(output, error, options?.signal);
|
|
148
148
|
finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
|
|
149
149
|
clearPendingCommentaryText(provisionalCommentaryTags);
|
|
150
150
|
tagUnresolvedTextAsCommentary(output);
|
|
@@ -189,11 +189,13 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
189
189
|
});
|
|
190
190
|
Object.assign(headers, copilotHeaders);
|
|
191
191
|
}
|
|
192
|
-
if (sessionId && compat.sessionAffinity !== "none")
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
if (sessionId && compat.sessionAffinity !== "none") {
|
|
193
|
+
if (compat.sessionAffinity === "openrouter") headers["x-session-id"] = sessionId;
|
|
194
|
+
else {
|
|
195
|
+
headers.session_id = sessionId;
|
|
196
|
+
headers["x-client-request-id"] = sessionId;
|
|
197
|
+
headers["x-session-affinity"] = sessionId;
|
|
198
|
+
}
|
|
197
199
|
}
|
|
198
200
|
if (optionsHeaders) Object.assign(headers, optionsHeaders);
|
|
199
201
|
const defaultHeaders = model.provider === "cloudflare-ai-gateway" ? {
|
|
@@ -201,11 +203,13 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
201
203
|
Authorization: headers.Authorization ?? null,
|
|
202
204
|
"cf-aig-authorization": `Bearer ${apiKey}`
|
|
203
205
|
} : headers;
|
|
206
|
+
const baseUrl = isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl;
|
|
204
207
|
return new OpenAI({
|
|
205
208
|
apiKey,
|
|
206
|
-
baseURL: resolveOpenAIClientBaseUrl(model,
|
|
209
|
+
baseURL: resolveOpenAIClientBaseUrl(model, baseUrl),
|
|
207
210
|
dangerouslyAllowBrowser: true,
|
|
208
211
|
defaultHeaders,
|
|
212
|
+
maxRetries: 0,
|
|
209
213
|
fetch: getAiTransportHost().buildModelFetch(model)
|
|
210
214
|
});
|
|
211
215
|
}
|
|
@@ -256,9 +260,9 @@ function buildParams(model, context, options, compat = resolveOpenAICompletionsC
|
|
|
256
260
|
}
|
|
257
261
|
const reasoningEffortMap = resolveOpenAIReasoningEffortMap(model);
|
|
258
262
|
const thinkingLevelMap = model.thinkingLevelMap;
|
|
259
|
-
const reasoningEffort = options?.reasoningEffort === void 0 ? void 0 : reasoningEffortMap[options.reasoningEffort] ?? thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
260
|
-
const reasoningEnabled = reasoningEffort !== void 0 && reasoningEffort !== "none";
|
|
261
263
|
const offReasoningEffort = reasoningEffortMap.off ?? model.thinkingLevelMap?.off;
|
|
264
|
+
const reasoningEffort = options?.reasoningEffort === void 0 ? offReasoningEffort ?? void 0 : reasoningEffortMap[options.reasoningEffort] ?? thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
265
|
+
const reasoningEnabled = reasoningEffort !== void 0 && reasoningEffort !== "none";
|
|
262
266
|
if (compat.thinkingFormat === "zai" && model.reasoning) params.thinking = reasoningEnabled ? {
|
|
263
267
|
type: "enabled",
|
|
264
268
|
clear_thinking: false
|
package/dist/{openai-completions-compat-BefmHT26.d.mts → openai-completions-compat-CpjYUArk.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
3
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-
|
|
1
|
+
import "./index-FnHM2FcI.mjs";
|
|
2
|
+
import { D as Model, j as OpenAICompletionsCompat } from "./types-CJ1-Ht7A.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DjzGmdZ2.mjs";
|
|
4
4
|
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
5
5
|
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
6
6
|
type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";
|
|
@@ -24,7 +24,7 @@ type DetectedOpenAICompletionsCompat = {
|
|
|
24
24
|
capabilities: ProviderRequestCapabilities;
|
|
25
25
|
defaults: OpenAICompletionsCompatDefaults;
|
|
26
26
|
};
|
|
27
|
-
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders"> & {
|
|
27
|
+
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders" | "reasoningEffortMap"> & {
|
|
28
28
|
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
29
29
|
openRouterRouting?: OpenAICompletionsCompat["openRouterRouting"];
|
|
30
30
|
sessionAffinity: OpenAICompletionsSessionAffinity;
|
|
@@ -38,6 +38,6 @@ declare function detectOpenAICompletionsCompat(model: Pick<Model<"openai-complet
|
|
|
38
38
|
} | null;
|
|
39
39
|
}, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): DetectedOpenAICompletionsCompat;
|
|
40
40
|
/** Applies explicit model overrides once on top of the canonical transport defaults. */
|
|
41
|
-
declare function resolveOpenAICompletionsCompat(model: Model<"openai-completions">, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): ResolvedOpenAICompletionsCompat;
|
|
41
|
+
declare function resolveOpenAICompletionsCompat(model: Pick<Model<"openai-completions">, "id" | "provider" | "baseUrl" | "compat">, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): ResolvedOpenAICompletionsCompat;
|
|
42
42
|
//#endregion
|
|
43
43
|
export { detectOpenAICompletionsCompat as n, resolveOpenAICompletionsCompat as r, ResolvedOpenAICompletionsCompat as t };
|