@openclaw/ai 2026.9.1 → 2026.9.3
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 +3 -2
- package/dist/anthropic-CZy5U0NY.mjs +376 -0
- package/dist/anthropic-payload-policy-wuRCb6MH.d.mts +85 -0
- package/dist/anthropic-stream-reducer-B_yo_7pf.mjs +1669 -0
- package/dist/{api-registry-Cs6HGNqY.d.mts → api-registry-CB1-1oQ2.d.mts} +2 -2
- package/dist/assistant-output-iqnlJCV2.mjs +16 -0
- package/dist/assistant-text-phase-C20rxWwP.mjs +55 -0
- package/dist/{azure-openai-responses-CN4Fy5zV.mjs → azure-openai-responses-Crpa40QR.mjs} +5 -5
- package/dist/{base64-CEFBpSkN.mjs → base64-D-su8YVo.mjs} +1 -27
- package/dist/{diagnostics-KhXK-QJI.mjs → diagnostics-dV98PqIy.mjs} +96 -21
- package/dist/diagnostics.d.mts +3 -1
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-vK_7r3bj.d.mts → event-stream-C1Z2piyk.d.mts} +11 -3
- package/dist/{event-stream-uSMZJ3FA.mjs → event-stream-D8PARQfL.mjs} +48 -10
- package/dist/event-stream-I_GlBsuZ.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-headers-NCJtz9i0.mjs → github-copilot-headers-B37TB3rB.mjs} +3 -10
- package/dist/github-copilot-request-facts-BTEBMeOv.mjs +16 -0
- package/dist/{google-CC-nrwXg.mjs → google-BDPriaVe.mjs} +10 -10
- package/dist/google-messages-CVn9eFpF.mjs +449 -0
- package/dist/google-shared-BedY23XS.mjs +185 -0
- package/dist/{google-vertex-DCr0pyzQ.mjs → google-vertex-DMz8XQCn.mjs} +7 -6
- package/dist/{host-BIaiBURL.mjs → host-CWuF-sS3.mjs} +84 -34
- package/dist/{host-BztR4tQj.d.mts → host-DK3wmS3e.d.mts} +3 -3
- package/dist/host-policy-CAopLRKA.mjs +37 -0
- package/dist/{index-AfaxKT8w.d.mts → index-CQ6LTHw8.d.mts} +11 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +14 -11
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/google-model-family.d.mts +5 -0
- package/dist/internal/google-model-family.mjs +15 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +1 -1
- package/dist/internal/openai.d.mts +8 -103
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -4
- package/dist/internal/retry-after.mjs +57 -8
- package/dist/internal/runtime.d.mts +7 -6
- package/dist/internal/runtime.mjs +8 -7
- package/dist/internal/shared.d.mts +14 -3
- package/dist/internal/shared.mjs +6 -4
- package/dist/internal/tool-schema.d.mts +63 -0
- package/dist/internal/tool-schema.mjs +3 -0
- package/dist/{json-parse-BuAJEbdW.mjs → json-parse-Dw_hnxsA.mjs} +1 -1
- package/dist/{mistral-B7etBd_H.mjs → mistral--m-Jm6VZ.mjs} +16 -38
- package/dist/model-transport-url-DKocrEsb.d.mts +28 -0
- package/dist/{openai-chatgpt-responses-BAJ4gq3i.mjs → openai-chatgpt-responses-nDZccFW-.mjs} +62 -54
- package/dist/openai-completions-KuoZyx0d.mjs +187 -0
- package/dist/{openai-completions-compat-4IjSBpr6.d.mts → openai-completions-compat-CXn3T1we.d.mts} +26 -4
- package/dist/{openai-completions-stream-DZjwK8vp.mjs → openai-completions-stream-BQk3SkLD.mjs} +621 -451
- package/dist/openai-prompt-cache-BI0rkM-5.mjs +220 -0
- package/dist/openai-prompt-cache-rrutvqxq.d.mts +16 -0
- package/dist/openai-provider-client-ha_WxTyj.mjs +24 -0
- package/dist/openai-reasoning-effort-BK7FbcLT.mjs +167 -0
- package/dist/{openai-responses-BEUlxfDu.mjs → openai-responses-D99dOzKI.mjs} +14 -32
- package/dist/{openai-responses-compaction-window-DO7yV7az.mjs → openai-responses-compaction-window-D5jbzCi3.mjs} +7 -159
- package/dist/{openai-responses-contracts-bPzSN_Ba.d.mts → openai-responses-contracts-B55afwRo.d.mts} +12 -4
- package/dist/{openai-responses-prompt-observer-internal-C7x4IK7r.mjs → openai-responses-prompt-observer-internal-tApyTLVu.mjs} +3 -3
- package/dist/{openai-responses-shared-DiAdpNAM.mjs → openai-responses-shared-ZyQEzS5i.mjs} +217 -212
- package/dist/openai-tool-projection-793cE3QX.d.mts +37 -0
- package/dist/{openai-tool-schema-BMiHFH36.mjs → openai-tool-schema-CzjyYXun.mjs} +53 -583
- package/dist/openai-tool-schema-ynZBgqW-.d.mts +38 -0
- package/dist/openai-transport-params-DNasp2fU.mjs +674 -0
- package/dist/{provider-error-B6EGq6gg.mjs → provider-error-C6TbKiey.mjs} +29 -13
- package/dist/{provider-options-CxFPtvh7.d.mts → provider-options-BXr9Ec83.d.mts} +19 -42
- package/dist/provider-replay-context-BuSUaAk5.mjs +21 -0
- package/dist/{provider-transcript-transform-WvJmFUAf.mjs → provider-transcript-transform-pPmUIwKt.mjs} +1 -1
- package/dist/provider-types-CAV0Og3m.d.mts +29 -0
- package/dist/provider-types.d.mts +6 -31
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-C-4uedDb.mjs → reasoning-tag-text-partitioner-BQBi4B9d.mjs} +90 -35
- package/dist/record-coerce-DwRYMj3t.mjs +32 -0
- package/dist/retry-after-CdCURCVg.d.mts +15 -0
- package/dist/{sanitize-unicode-S6binQG-.mjs → sanitize-unicode-Bb-v9meu.mjs} +1 -1
- package/dist/session-affinity-CCH7eYdB.mjs +20 -0
- package/dist/{simple-options-0PLDyJ-d.mjs → simple-options-tcKOqnpF.mjs} +3 -3
- package/dist/{src-C8U7lkoa.mjs → src-B2Q_6G8V.mjs} +10 -2
- package/dist/{stream-first-event-timeout-DcNjoFQE.mjs → stream-first-event-timeout-2hfrquuz.mjs} +1 -1
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{string-normalization--fwJ4S2q.mjs → string-normalization-CmLIasuf.mjs} +1 -1
- package/dist/{tool-schema-json-projection-BtZiml7r.mjs → tool-schema-json-projection-ClptDdAO.mjs} +2 -38
- package/dist/{transport-stream-shared-CytPVLIg.mjs → transport-stream-shared-Cu3ZPhNW.mjs} +5 -5
- package/dist/{transport-stream-shared-BrvFTkoO.d.mts → transport-stream-shared-DOxpGJ-H.d.mts} +4 -4
- package/dist/transport-utils-CCooe-cr.mjs +121 -0
- package/dist/transports.d.mts +114 -41
- package/dist/transports.mjs +796 -1596
- package/dist/types-BADKjDBI.d.mts +1 -0
- package/dist/{types-DbrhszyQ.d.mts → types-Dy1q0CSu.d.mts} +101 -64
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-CJZtym2g.mjs → validation-BDzVDnTs.mjs} +9 -1
- package/dist/{validation-BOwtcl9X.d.mts → validation-CaFUZN9B.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +14 -4
- package/dist/anthropic-compaction-replay-OMJZ0uyo.mjs +0 -838
- package/dist/anthropic-hk7F7ptG.mjs +0 -883
- package/dist/anthropic-payload-policy-DBT1itQ-.d.mts +0 -51
- package/dist/event-stream-DeDhbCc5.d.mts +0 -1
- package/dist/google-shared-CjPY0hZM.mjs +0 -634
- package/dist/google-thinking-level-C-V3tecN.mjs +0 -9
- package/dist/openai-completions-D0QZ0AyB.mjs +0 -403
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/transport-utils-CtuS1Upe.mjs +0 -138
- package/dist/types-B5EFUmXs.d.mts +0 -1
- package/dist/utf16-slice-qz3nsy87.mjs +0 -84
package/dist/{openai-chatgpt-responses-BAJ4gq3i.mjs → openai-chatgpt-responses-nDZccFW-.mjs}
RENAMED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
-
import {
|
|
5
|
-
import { u as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-CWuF-sS3.mjs";
|
|
4
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-BI0rkM-5.mjs";
|
|
5
|
+
import { l as extractErrorCodeOrErrno, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, u as toErrorObject } from "./diagnostics-dV98PqIy.mjs";
|
|
6
|
+
import { s as resolveTimerTimeoutMs } from "./base64-D-su8YVo.mjs";
|
|
7
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-CCooe-cr.mjs";
|
|
8
|
+
import { parseRetryAfterHeadersSeconds } from "./internal/retry-after.mjs";
|
|
9
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-tcKOqnpF.mjs";
|
|
10
|
+
import { _ as createOpenAIProviderAcceptanceHook, v as createOpenAIResponseHook } from "./openai-transport-params-DNasp2fU.mjs";
|
|
9
11
|
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-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-Cu3ZPhNW.mjs";
|
|
13
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-2hfrquuz.mjs";
|
|
14
|
+
import { l as supportsOpenAITemperature } from "./openai-reasoning-effort-BK7FbcLT.mjs";
|
|
15
|
+
import { S as responsesPromptObserver } from "./openai-responses-compaction-window-D5jbzCi3.mjs";
|
|
16
|
+
import { J as buildOpenAIResponsesReasoningReplayMetadata, L as commitResponsesEncryptedContentAttempt, Q as suppressOpenAIResponsesCompaction, V as resolveNextResponsesEncryptedContentAttempt, a as resolveResponsesReasoningEffort, h as ResponsesStreamFailure, i as createResponsesAssistantOutput, l as convertResponsesToolPayload, n as applyResponsesServiceTierPricing, o as resolveResponsesRequestReasoningEffort, r as convertResponsesMessages, u as processResponsesStream, z as isInvalidEncryptedContentError } from "./openai-responses-shared-ZyQEzS5i.mjs";
|
|
15
17
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
16
18
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
17
|
-
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
19
|
+
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-tApyTLVu.mjs";
|
|
18
20
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
19
21
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
20
22
|
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
@@ -83,6 +85,17 @@ const os = loadNodeOs();
|
|
|
83
85
|
const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
84
86
|
const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
85
87
|
const CODEX_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
|
|
88
|
+
const WEBSOCKET_TRANSPORT_ERROR_CODE = "ERR_WEBSOCKET_TRANSPORT";
|
|
89
|
+
const RETRYABLE_WEBSOCKET_CLOSE_CODES = /* @__PURE__ */ new Set([
|
|
90
|
+
1001,
|
|
91
|
+
1005,
|
|
92
|
+
1006,
|
|
93
|
+
1011,
|
|
94
|
+
1012,
|
|
95
|
+
1013,
|
|
96
|
+
1014,
|
|
97
|
+
1015
|
|
98
|
+
]);
|
|
86
99
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
87
100
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
88
101
|
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
@@ -184,7 +197,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
184
197
|
commitSemanticAttempt(activeAttempt);
|
|
185
198
|
}, requestOptions, firstEventAbort.abort, observePromptEgress, activeAttempt.kind, () => {
|
|
186
199
|
websocketRequestSent = true;
|
|
187
|
-
});
|
|
200
|
+
}, options?.signal);
|
|
188
201
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
189
202
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new CodexApiError(output.errorMessage ?? "An unknown error occurred");
|
|
190
203
|
stream.push({
|
|
@@ -272,10 +285,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
272
285
|
onTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
273
286
|
});
|
|
274
287
|
const [errorText] = await Promise.all([readChatGptResponsesErrorTextLimited(attemptResponse, activeSignal), hookStream[Symbol.asyncIterator]().next()]);
|
|
275
|
-
const
|
|
276
|
-
const retryAfterSeconds = parseRetryAfterSeconds(attemptResponse.headers);
|
|
277
|
-
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
278
|
-
const terminalResponseError = new CodexApiError(`${info.friendlyMessage || info.message}${retryAfterSuffix}`, { code: info.code });
|
|
288
|
+
const terminalResponseError = parseErrorResponse(errorText, attemptResponse);
|
|
279
289
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
280
290
|
const nextSemanticAttempt = await resolveNextResponsesEncryptedContentAttempt(activeAttempt, terminalResponseError, { buildFullHistoryRequest: () => buildBody("full-history") });
|
|
281
291
|
if (!nextSemanticAttempt) throw terminalResponseError;
|
|
@@ -370,20 +380,18 @@ function buildRequestBody(model, context, options, replayMode = "checkpoint") {
|
|
|
370
380
|
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) body.temperature = options.temperature;
|
|
371
381
|
if (options?.serviceTier !== void 0) body.service_tier = options.serviceTier;
|
|
372
382
|
if (context.tools) {
|
|
373
|
-
const
|
|
374
|
-
if (
|
|
375
|
-
body.tools =
|
|
383
|
+
const tools = convertResponsesToolPayload(context.tools, { strict: null });
|
|
384
|
+
if (tools.length > 0) {
|
|
385
|
+
body.tools = tools;
|
|
376
386
|
body.tool_choice = "auto";
|
|
377
387
|
body.parallel_tool_calls = true;
|
|
378
388
|
}
|
|
379
389
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
};
|
|
386
|
-
}
|
|
390
|
+
const effort = options?.reasoningEffort === void 0 ? void 0 : resolveResponsesRequestReasoningEffort(model, options.reasoningEffort);
|
|
391
|
+
if (effort !== void 0) body.reasoning = {
|
|
392
|
+
effort,
|
|
393
|
+
summary: options?.reasoningSummary ?? "auto"
|
|
394
|
+
};
|
|
387
395
|
return body;
|
|
388
396
|
}
|
|
389
397
|
function resolveCodexServiceTier(responseServiceTier, requestServiceTier) {
|
|
@@ -407,6 +415,7 @@ var CodexApiError = class extends Error {
|
|
|
407
415
|
super(message);
|
|
408
416
|
this.name = "CodexApiError";
|
|
409
417
|
this.code = options?.code;
|
|
418
|
+
this.status = options?.status;
|
|
410
419
|
this.payload = options?.payload;
|
|
411
420
|
this.cause = options?.cause;
|
|
412
421
|
}
|
|
@@ -507,15 +516,9 @@ async function getWebSocketConstructor() {
|
|
|
507
516
|
if (typeof ctor !== "function") return null;
|
|
508
517
|
return ctor;
|
|
509
518
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
this.name = "WebSocketCloseError";
|
|
514
|
-
this.code = options?.code;
|
|
515
|
-
this.reason = options?.reason;
|
|
516
|
-
this.wasClean = options?.wasClean;
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
+
function createWebSocketTransportError(message, cause) {
|
|
520
|
+
return Object.assign(new Error(message, cause ? { cause } : void 0), { code: extractErrorCodeOrErrno(cause) ?? WEBSOCKET_TRANSPORT_ERROR_CODE });
|
|
521
|
+
}
|
|
519
522
|
function getWebSocketReadyState(socket) {
|
|
520
523
|
const readyState = socket.readyState;
|
|
521
524
|
return typeof readyState === "number" ? readyState : void 0;
|
|
@@ -688,15 +691,15 @@ async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
|
688
691
|
function extractWebSocketError(event) {
|
|
689
692
|
if (event && typeof event === "object") {
|
|
690
693
|
const message = "message" in event ? event.message : void 0;
|
|
691
|
-
if (typeof message === "string" && message.length > 0) return new Error(message);
|
|
692
694
|
const nestedError = "error" in event ? event.error : void 0;
|
|
693
|
-
|
|
694
|
-
if (nestedError
|
|
695
|
-
const
|
|
696
|
-
|
|
695
|
+
const eventMessage = typeof message === "string" && message.length > 0 ? message : void 0;
|
|
696
|
+
if (nestedError !== void 0) {
|
|
697
|
+
const cause = toErrorObject(nestedError, eventMessage ?? "WebSocket error");
|
|
698
|
+
return createWebSocketTransportError(eventMessage ?? (cause.message || "WebSocket error"), cause);
|
|
697
699
|
}
|
|
700
|
+
if (eventMessage) return createWebSocketTransportError(eventMessage);
|
|
698
701
|
}
|
|
699
|
-
return
|
|
702
|
+
return createWebSocketTransportError("WebSocket error");
|
|
700
703
|
}
|
|
701
704
|
function extractWebSocketCloseError(event) {
|
|
702
705
|
if (event && typeof event === "object") {
|
|
@@ -706,13 +709,16 @@ function extractWebSocketCloseError(event) {
|
|
|
706
709
|
const codeText = typeof code === "number" ? ` ${code}` : "";
|
|
707
710
|
let reasonText = typeof reason === "string" && reason.length > 0 ? ` ${reason}` : "";
|
|
708
711
|
if (!reasonText && code === WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE) reasonText = " message too big";
|
|
709
|
-
|
|
710
|
-
|
|
712
|
+
const message = `WebSocket closed${codeText}${reasonText}`;
|
|
713
|
+
const error = typeof code === "number" && RETRYABLE_WEBSOCKET_CLOSE_CODES.has(code) ? createWebSocketTransportError(message) : Object.assign(new Error(message), { code: WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE });
|
|
714
|
+
return Object.assign(error, {
|
|
715
|
+
name: "WebSocketCloseError",
|
|
716
|
+
closeCode: typeof code === "number" ? code : void 0,
|
|
711
717
|
reason: typeof reason === "string" && reason.length > 0 ? reason : void 0,
|
|
712
718
|
wasClean: typeof wasClean === "boolean" ? wasClean : void 0
|
|
713
719
|
});
|
|
714
720
|
}
|
|
715
|
-
return
|
|
721
|
+
return createWebSocketTransportError("WebSocket closed");
|
|
716
722
|
}
|
|
717
723
|
async function* parseWebSocket(socket, signal) {
|
|
718
724
|
const queue = [];
|
|
@@ -846,7 +852,7 @@ async function* startWebSocketOutputOnFirstEvent(events, output, stream, onFirst
|
|
|
846
852
|
yield event;
|
|
847
853
|
}
|
|
848
854
|
}
|
|
849
|
-
async function processWebSocketStream(url, body, headers, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent) {
|
|
855
|
+
async function processWebSocketStream(url, body, headers, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent, activitySignal) {
|
|
850
856
|
const { socket, entry, release } = await acquireWebSocket(url, headers, options?.sessionId, options?.signal);
|
|
851
857
|
let keepConnection = true;
|
|
852
858
|
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
@@ -874,7 +880,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
874
880
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
875
881
|
abortFirstEventStream,
|
|
876
882
|
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
877
|
-
signal: options?.signal,
|
|
883
|
+
signal: activitySignal ?? options?.signal,
|
|
878
884
|
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
879
885
|
sessionId: options?.sessionId,
|
|
880
886
|
authProfileId: options?.authProfileId
|
|
@@ -953,7 +959,8 @@ async function readChatGptResponsesErrorTextLimited(response, signal) {
|
|
|
953
959
|
}
|
|
954
960
|
return text;
|
|
955
961
|
}
|
|
956
|
-
function
|
|
962
|
+
function parseErrorResponse(raw, response) {
|
|
963
|
+
const { status, statusText } = response;
|
|
957
964
|
let message = raw || statusText || "Request failed";
|
|
958
965
|
let friendlyMessage;
|
|
959
966
|
let code;
|
|
@@ -969,11 +976,12 @@ function parseErrorResponseText(raw, status, statusText) {
|
|
|
969
976
|
message = err.message || friendlyMessage || message;
|
|
970
977
|
}
|
|
971
978
|
} catch {}
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
979
|
+
const retryAfterSeconds = parseRetryAfterHeadersSeconds(response.headers);
|
|
980
|
+
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
981
|
+
return new CodexApiError(`${friendlyMessage || message}${retryAfterSuffix}`, {
|
|
982
|
+
code,
|
|
983
|
+
status
|
|
984
|
+
});
|
|
977
985
|
}
|
|
978
986
|
function extractOpenAICodexAccountId(token) {
|
|
979
987
|
const accountId = resolveOpenAICodexAccountId(token);
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
3
|
+
import { i as clampThinkingLevel } from "./sanitize-unicode-Bb-v9meu.mjs";
|
|
4
|
+
import { s as resolveOpenAICompletionsCompat } from "./openai-prompt-cache-BI0rkM-5.mjs";
|
|
5
|
+
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
|
+
import { n as buildBaseOptions, o as reasoningTagTextPolicy } from "./simple-options-tcKOqnpF.mjs";
|
|
7
|
+
import { _ as createOpenAIProviderAcceptanceHook, y as isOpenAICompletionsThinkingEnabled } from "./openai-transport-params-DNasp2fU.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-Cu3ZPhNW.mjs";
|
|
10
|
+
import { a as tagUnresolvedTextAsCommentary, t as clearPendingCommentaryText } from "./assistant-text-phase-C20rxWwP.mjs";
|
|
11
|
+
import { t as createAssistantOutput } from "./assistant-output-iqnlJCV2.mjs";
|
|
12
|
+
import { t as resolveOpencodeSessionHeaders } from "./session-affinity-CCH7eYdB.mjs";
|
|
13
|
+
import { a as convertMessages, i as buildOpenAICompletionsRequest, s as finalizeOpenAICompletionsToolCalls, t as processCompletionsStream } from "./openai-completions-stream-BQk3SkLD.mjs";
|
|
14
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-2hfrquuz.mjs";
|
|
15
|
+
import { n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-B37TB3rB.mjs";
|
|
16
|
+
import { t as createOpenAIProviderClient } from "./openai-provider-client-ha_WxTyj.mjs";
|
|
17
|
+
//#region packages/ai/src/providers/openai-completions.ts
|
|
18
|
+
var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
+
convertMessages: () => convertMessages,
|
|
20
|
+
streamOpenAICompletions: () => streamOpenAICompletions,
|
|
21
|
+
streamSimpleOpenAICompletions: () => streamSimpleOpenAICompletions
|
|
22
|
+
});
|
|
23
|
+
const streamOpenAICompletions = (model, context, options) => {
|
|
24
|
+
const stream = new AssistantMessageEventStream();
|
|
25
|
+
(async () => {
|
|
26
|
+
const output = createAssistantOutput(model);
|
|
27
|
+
const provisionalCommentaryTags = /* @__PURE__ */ new Map();
|
|
28
|
+
let firstEventAbort;
|
|
29
|
+
try {
|
|
30
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
31
|
+
const compat = resolveOpenAICompletionsCompat(model);
|
|
32
|
+
const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
|
|
33
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
34
|
+
const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
|
|
35
|
+
const client = createClient(model, context, apiKey, resolveOpencodeSessionHeaders(model, options), cacheSessionId, compat);
|
|
36
|
+
let params = buildOpenAICompletionsRequest(model, context, options, {
|
|
37
|
+
mode: "direct",
|
|
38
|
+
compat,
|
|
39
|
+
cacheRetention
|
|
40
|
+
});
|
|
41
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
42
|
+
if (nextParams !== void 0) params = nextParams;
|
|
43
|
+
firstEventAbort = createFirstStreamEventAbortController(options?.signal);
|
|
44
|
+
const requestOptions = {
|
|
45
|
+
signal: firstEventAbort.signal,
|
|
46
|
+
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
47
|
+
maxRetries: 0
|
|
48
|
+
};
|
|
49
|
+
const { data: openaiStream, response } = await client.chat.completions.create(params, requestOptions).withResponse();
|
|
50
|
+
const hookedOpenAIStream = withProviderResponseHook({
|
|
51
|
+
stream: openaiStream,
|
|
52
|
+
signal: firstEventAbort.signal,
|
|
53
|
+
abort: firstEventAbort.abort,
|
|
54
|
+
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
55
|
+
onReady: () => stream.push({
|
|
56
|
+
type: "start",
|
|
57
|
+
partial: output
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
const finishedBlocks = /* @__PURE__ */ new Set();
|
|
61
|
+
const contentIndices = /* @__PURE__ */ new WeakMap();
|
|
62
|
+
let openTextBlock;
|
|
63
|
+
let openThinkingBlock;
|
|
64
|
+
const finishBlock = (block) => {
|
|
65
|
+
const contentIndex = contentIndices.get(block);
|
|
66
|
+
if (contentIndex === void 0 || finishedBlocks.has(block)) return;
|
|
67
|
+
finishedBlocks.add(block);
|
|
68
|
+
if (block.type === "text") {
|
|
69
|
+
openTextBlock = void 0;
|
|
70
|
+
stream.push({
|
|
71
|
+
type: "text_end",
|
|
72
|
+
contentIndex,
|
|
73
|
+
content: block.text,
|
|
74
|
+
partial: output
|
|
75
|
+
});
|
|
76
|
+
} else if (block.type === "thinking") {
|
|
77
|
+
openThinkingBlock = void 0;
|
|
78
|
+
stream.push({
|
|
79
|
+
type: "thinking_end",
|
|
80
|
+
contentIndex,
|
|
81
|
+
content: block.thinking,
|
|
82
|
+
partial: output
|
|
83
|
+
});
|
|
84
|
+
} else if (block.type === "toolCall") stream.push({
|
|
85
|
+
type: "toolcall_end",
|
|
86
|
+
contentIndex,
|
|
87
|
+
toolCall: block,
|
|
88
|
+
partial: output
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const directEventStream = { push(event) {
|
|
92
|
+
if (event.type === "text_start" || event.type === "thinking_start" || event.type === "toolcall_start") {
|
|
93
|
+
const block = output.content[event.contentIndex];
|
|
94
|
+
if (block) {
|
|
95
|
+
contentIndices.set(block, event.contentIndex);
|
|
96
|
+
if (block.type === "text") openTextBlock = block;
|
|
97
|
+
else if (block.type === "thinking") openThinkingBlock = block;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
stream.push(event);
|
|
101
|
+
} };
|
|
102
|
+
try {
|
|
103
|
+
await processCompletionsStream(hookedOpenAIStream, output, model, directEventStream, {
|
|
104
|
+
mode: "direct",
|
|
105
|
+
beforeContentBlock(nextType) {
|
|
106
|
+
if (openThinkingBlock) finishBlock(openThinkingBlock);
|
|
107
|
+
if (openTextBlock && nextType !== "toolCall") finishBlock(openTextBlock);
|
|
108
|
+
},
|
|
109
|
+
provisionalCommentaryTags,
|
|
110
|
+
signal: options?.signal,
|
|
111
|
+
emitReasoning: shouldEmitReasoning,
|
|
112
|
+
strictReasoningTags: reasoningTagTextPolicy.isStrict(options),
|
|
113
|
+
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
114
|
+
abortFirstEventStream: firstEventAbort.abort,
|
|
115
|
+
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
116
|
+
});
|
|
117
|
+
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
118
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
|
|
119
|
+
} catch (error) {
|
|
120
|
+
for (const block of output.content) if (block.type !== "toolCall") finishBlock(block);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
for (const block of output.content) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
|
|
124
|
+
stream.push({
|
|
125
|
+
type: "done",
|
|
126
|
+
reason: output.stopReason,
|
|
127
|
+
message: output
|
|
128
|
+
});
|
|
129
|
+
stream.end();
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const terminal = assignTransportErrorDetails(output, error, options?.signal);
|
|
132
|
+
finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
|
|
133
|
+
clearPendingCommentaryText(provisionalCommentaryTags);
|
|
134
|
+
tagUnresolvedTextAsCommentary(output);
|
|
135
|
+
for (const block of output.content) {
|
|
136
|
+
delete block.index;
|
|
137
|
+
delete block.partialArgs;
|
|
138
|
+
delete block.streamIndex;
|
|
139
|
+
}
|
|
140
|
+
stream.push({
|
|
141
|
+
type: "error",
|
|
142
|
+
reason: terminal.stopReason,
|
|
143
|
+
error: output
|
|
144
|
+
});
|
|
145
|
+
stream.end();
|
|
146
|
+
} finally {
|
|
147
|
+
firstEventAbort?.dispose();
|
|
148
|
+
}
|
|
149
|
+
})();
|
|
150
|
+
return stream;
|
|
151
|
+
};
|
|
152
|
+
const streamSimpleOpenAICompletions = (model, context, options) => {
|
|
153
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
154
|
+
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
155
|
+
const base = buildBaseOptions(model, options, apiKey);
|
|
156
|
+
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
157
|
+
const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning === "max" ? "xhigh" : clampedReasoning;
|
|
158
|
+
const toolChoice = options?.toolChoice;
|
|
159
|
+
return streamOpenAICompletions(model, context, {
|
|
160
|
+
...base,
|
|
161
|
+
reasoningEffort,
|
|
162
|
+
toolChoice
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
function createClient(model, context, apiKey, optionsHeaders, sessionId, compat = resolveOpenAICompletionsCompat(model)) {
|
|
166
|
+
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
167
|
+
const headers = { ...model.headers };
|
|
168
|
+
if (model.provider === "github-copilot") {
|
|
169
|
+
const hasImages = hasCopilotVisionInput(context.messages);
|
|
170
|
+
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
171
|
+
messages: context.messages,
|
|
172
|
+
hasImages
|
|
173
|
+
});
|
|
174
|
+
Object.assign(headers, copilotHeaders);
|
|
175
|
+
}
|
|
176
|
+
if (sessionId && compat.sessionAffinity !== "none") {
|
|
177
|
+
if (compat.sessionAffinity === "openrouter") headers["x-session-id"] = sessionId;
|
|
178
|
+
else {
|
|
179
|
+
headers.session_id = sessionId;
|
|
180
|
+
headers["x-client-request-id"] = sessionId;
|
|
181
|
+
headers["x-session-affinity"] = sessionId;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return createOpenAIProviderClient(model, apiKey, headers, optionsHeaders);
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
export { streamOpenAICompletions as n, streamSimpleOpenAICompletions as r, openai_completions_exports as t };
|
package/dist/{openai-completions-compat-4IjSBpr6.d.mts → openai-completions-compat-CXn3T1we.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model, j as OpenAICompletionsCompat } from "./types-
|
|
3
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-
|
|
1
|
+
import "./index-CQ6LTHw8.mjs";
|
|
2
|
+
import { D as Model, j as OpenAICompletionsCompat } from "./types-Dy1q0CSu.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DK3wmS3e.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";
|
|
@@ -30,7 +30,29 @@ type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "
|
|
|
30
30
|
sessionAffinity: OpenAICompletionsSessionAffinity;
|
|
31
31
|
visibleReasoningDetailTypes: string[];
|
|
32
32
|
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
33
|
+
configuredSupportsLongCacheRetention?: boolean;
|
|
33
34
|
};
|
|
35
|
+
/** Native OpenAI defaults never apply to a configured proxy endpoint. */
|
|
36
|
+
declare function isNativeOpenAIEndpoint(model: {
|
|
37
|
+
provider?: string;
|
|
38
|
+
baseUrl?: string;
|
|
39
|
+
}): boolean;
|
|
40
|
+
declare function isOpenAICodexResponsesModel(model: {
|
|
41
|
+
provider?: string;
|
|
42
|
+
api?: string;
|
|
43
|
+
baseUrl?: string;
|
|
44
|
+
}): boolean;
|
|
45
|
+
declare function usesNativeOpenAICodexResponsesBackend(model: {
|
|
46
|
+
provider?: string;
|
|
47
|
+
api?: string;
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
}): boolean;
|
|
50
|
+
declare function resolveOpenAIPromptCacheKeySupport(model: {
|
|
51
|
+
api?: string;
|
|
52
|
+
provider?: string;
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
compat?: Pick<OpenAICompletionsCompat, "supportsPromptCacheKey" | "supportsLongCacheRetention"> | null;
|
|
55
|
+
}): boolean;
|
|
34
56
|
/** Detects endpoint capabilities and defaults for an OpenAI-completions model. */
|
|
35
57
|
declare function detectOpenAICompletionsCompat(model: Pick<Model<"openai-completions">, "provider" | "baseUrl" | "id"> & {
|
|
36
58
|
compat?: {
|
|
@@ -40,4 +62,4 @@ declare function detectOpenAICompletionsCompat(model: Pick<Model<"openai-complet
|
|
|
40
62
|
/** Applies explicit model overrides once on top of the canonical transport defaults. */
|
|
41
63
|
declare function resolveOpenAICompletionsCompat(model: Pick<Model<"openai-completions">, "id" | "provider" | "baseUrl" | "compat">, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): ResolvedOpenAICompletionsCompat;
|
|
42
64
|
//#endregion
|
|
43
|
-
export { detectOpenAICompletionsCompat as n,
|
|
65
|
+
export { resolveOpenAICompletionsCompat as a, isOpenAICodexResponsesModel as i, detectOpenAICompletionsCompat as n, resolveOpenAIPromptCacheKeySupport as o, isNativeOpenAIEndpoint as r, usesNativeOpenAICodexResponsesBackend as s, ResolvedOpenAICompletionsCompat as t };
|