@openclaw/ai 2026.10.1 → 2026.10.5-beta.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/README.md +6 -0
- package/dist/{anthropic-BDfXKgF1.mjs → anthropic-BAHKgWam.mjs} +30 -59
- package/dist/{anthropic-payload-policy-BZUAchqb.d.mts → anthropic-payload-policy-DGblkHL5.d.mts} +19 -16
- package/dist/{anthropic-stream-reducer-DHt9uFWX.mjs → anthropic-stream-reducer-g6w1YVii.mjs} +195 -283
- package/dist/{api-registry-DcEP_o4h.d.mts → api-registry-BhXXYdRA.d.mts} +2 -2
- package/dist/assistant-message-events-CHMJgbhs.mjs +18 -0
- package/dist/{assistant-output-mJ9cL4Qg.mjs → assistant-output-CUEeSotf.mjs} +2 -2
- package/dist/{assistant-text-phase-DAv1BdTm.mjs → assistant-text-phase-BrV8KdFO.mjs} +7 -6
- package/dist/{azure-openai-responses-gn9hMf8x.mjs → azure-openai-responses-C7qBuR23.mjs} +8 -9
- package/dist/{credential-redaction-BKv49aiv.d.mts → credential-redaction-BHxruEH6.d.mts} +3 -1
- package/dist/{diagnostics-Caj-4RBA.mjs → diagnostics-tQasYct1.mjs} +10 -3
- package/dist/diagnostics.d.mts +7 -7
- package/dist/diagnostics.mjs +3 -3
- package/dist/{env-api-keys-CyX4VKGO.mjs → env-api-keys-CrxwdylR.mjs} +24 -35
- package/dist/event-stream-6UNs-AhN.d.mts +1 -0
- package/dist/{event-stream-DrRM_90c.d.mts → event-stream-BcqWLo_u.d.mts} +1 -1
- package/dist/{event-stream-C5AbCAaZ.mjs → event-stream-X2gmsUWv.mjs} +5 -8
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/google-Boz2QcpK.mjs +20 -0
- package/dist/{google-interactions-DXu4IYGb.mjs → google-interactions-tjAb1mc5.mjs} +52 -84
- package/dist/{google-messages-Bmheetdg.mjs → google-messages-C-RZzloH.mjs} +25 -35
- package/dist/google-provider-stream-CMImyxbX.mjs +58 -0
- package/dist/{google-shared-DE_ddfsC.mjs → google-shared-OyAtMTZv.mjs} +6 -15
- package/dist/google-vertex-hCxTJea7.mjs +40 -0
- package/dist/{host-BjIYEjwT.d.mts → host-CTDz7LXD.d.mts} +6 -3
- package/dist/{host-JpNulOOs.mjs → host-JWXZWa-c.mjs} +3 -2
- package/dist/{host-policy-CC5H0iRZ.mjs → host-policy-q4Azym9F.mjs} +1 -1
- package/dist/{index-DJrNQnKw.d.mts → index-BYDvopUB.d.mts} +8 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -6
- package/dist/internal/anthropic.d.mts +5 -5
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +8 -1
- package/dist/internal/openai-responses-payload-policy.mjs +3 -3
- package/dist/internal/openai.d.mts +9 -9
- package/dist/internal/openai.mjs +9 -11
- package/dist/internal/runtime.d.mts +31 -13
- package/dist/internal/runtime.mjs +10 -13
- package/dist/internal/shared.d.mts +5 -5
- package/dist/internal/shared.mjs +6 -7
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{llm-request-activity-D8f_oxHj.mjs → llm-request-activity-CfMuh5cC.mjs} +2 -2
- package/dist/{mistral-1Bnbneg1.mjs → mistral-DUveP4hF.mjs} +71 -146
- package/dist/{model-transport-url-C5f59L3Y.d.mts → model-transport-url-BrsjjdjR.d.mts} +5 -1
- package/dist/{number-coercion-V8-BhME4.mjs → number-coercion-C3hztWoY.mjs} +5 -4
- package/dist/{openai-chatgpt-responses-CB1JwNFF.mjs → openai-chatgpt-responses-OCwckGhY.mjs} +164 -234
- package/dist/{openai-completions-BPadHHKe.mjs → openai-completions-DOltBUe9.mjs} +7 -6
- package/dist/{openai-completions-compat-CJ0ktmGy.d.mts → openai-completions-compat-i-nLZxFy.d.mts} +10 -11
- package/dist/{openai-completions-compat-D7hWYB0G.mjs → openai-completions-compat-pg1q4uNG.mjs} +10 -6
- package/dist/{openai-completions-transport-DITBEALX.mjs → openai-completions-transport-OMrn7gnZ.mjs} +1429 -294
- package/dist/{openai-prompt-cache-Dj8qeOHT.mjs → openai-prompt-cache-Cr2xKVrS.mjs} +1 -1
- package/dist/{openai-prompt-cache-C-Q1Ksfs.d.mts → openai-prompt-cache-DIPMrMFy.d.mts} +2 -2
- package/dist/{openai-responses-1_TvcWI3.mjs → openai-responses-BSBJUA19.mjs} +9 -10
- package/dist/{openai-responses-compaction-replay-BB2SWdsx.d.mts → openai-responses-compaction-replay-B2FE4Nw8.d.mts} +4 -4
- package/dist/{openai-responses-contracts-sAvdqNjS.d.mts → openai-responses-contracts-DKqMJ1Ct.d.mts} +9 -4
- package/dist/{openai-responses-contracts-BKu8O7l4.mjs → openai-responses-contracts-DlKMMTxK.mjs} +26 -6
- package/dist/{openai-responses-compaction-window-m878aVpU.mjs → openai-responses-endpoint-CinGh4VZ.mjs} +14 -4
- package/dist/{openai-responses-prompt-observer-internal-CbH84xIS.mjs → openai-responses-request-lifecycle-D2IFiI0-.mjs} +39 -4
- package/dist/{openai-responses-shared-TCJRAoMW.mjs → openai-responses-shared-DVGhq5xF.mjs} +1036 -327
- package/dist/{openai-responses-terminal-usage-BVvyXZ8u.d.mts → openai-responses-terminal-usage-BygjiAdi.d.mts} +2 -2
- package/dist/{openai-tool-schema-DYNePiF8.mjs → openai-tool-schema-DDPXsvJP.mjs} +236 -399
- package/dist/{positive-integer-CwLi8LUL.mjs → positive-integer-CqWjqSi9.mjs} +1 -1
- package/dist/{provider-error-DQBE1bUQ.mjs → provider-error-CF9GWCs2.mjs} +5 -3
- package/dist/{provider-options-Dk4PeQV3.d.mts → provider-options-CVrXZBtA.d.mts} +3 -2
- package/dist/{provider-transport-turn-state-8c_Nj2NS.mjs → provider-transport-turn-state-LuCaTsSO.mjs} +2 -2
- package/dist/{provider-types-De8PRdR0.d.mts → provider-types-CHtRx0dI.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +12 -12
- package/dist/{reasoning-tag-text-partitioner-Ju9VpUGl.mjs → reasoning-tag-text-partitioner-0-Rsezog.mjs} +13 -12
- package/dist/{required-api-key-D4kn3252.mjs → required-api-key-CFJvcFy_.mjs} +1 -1
- package/dist/{simple-options-wW3117Fu.mjs → simple-options-BARFAzk9.mjs} +9 -11
- package/dist/{src-DWJq14pn.mjs → src-C_wfIUmV.mjs} +19 -4
- package/dist/{stream-CElngO8h.mjs → stream-DwrETW0_.mjs} +12 -21
- package/dist/{stream-first-event-timeout-D9ZmL_s9.mjs → stream-first-event-timeout-Dc42hKv6.mjs} +8 -21
- package/dist/{streaming-byte-guard-CC-HMn_u.mjs → streaming-byte-guard-DBXr1XYn.mjs} +16 -1
- package/dist/{string-normalization-PN10hf6d.mjs → string-normalization-I3ux50s9.mjs} +1 -1
- package/dist/{text-signature-rOn31nxc.mjs → text-signature-B_MB6U_9.mjs} +32 -5
- package/dist/{tool-schema-json-projection-Ct8SeBeJ.mjs → tool-schema-json-projection-B8sG1I9v.mjs} +29 -23
- package/dist/{transport-stream-shared-CAxkgOSj.d.mts → transport-stream-shared-BmpzDtdQ.d.mts} +4 -4
- package/dist/{transport-stream-shared-C5TAc3U_.mjs → transport-stream-shared-DH08b7Il.mjs} +8 -16
- package/dist/transports.d.mts +33 -22
- package/dist/transports.mjs +73 -1234
- package/dist/{types-DvzmWW8J.d.mts → types-Bd2T86VJ.d.mts} +5 -23
- package/dist/types-Kdfw_04V.d.mts +1 -0
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +5 -4
- package/dist/{validation-B3lQt_VE.d.mts → validation-DdGB1yy3.d.mts} +1 -1
- package/dist/{validation-DbqlIfDn.mjs → validation-opC2pjk9.mjs} +2 -3
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +4 -9
- package/dist/env-api-keys-BR0MUYYD.d.mts +0 -17
- package/dist/event-stream-DqDQWqiy.d.mts +0 -1
- package/dist/google-CyMz2jF_.mjs +0 -54
- package/dist/google-vertex-BEW0OQIA.mjs +0 -88
- package/dist/internal/env-api-keys.d.mts +0 -2
- package/dist/internal/env-api-keys.mjs +0 -2
- package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +0 -36
- package/dist/openai-transport-params-ildrm49s.mjs +0 -735
- package/dist/openai-web-search-tools-Cfu0uLyN.mjs +0 -14
- package/dist/provider-replay-context-ywPKKLjL.mjs +0 -25
- package/dist/types-Dlz-8qcy.d.mts +0 -1
package/dist/{openai-chatgpt-responses-CB1JwNFF.mjs → openai-chatgpt-responses-OCwckGhY.mjs}
RENAMED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-DzrF1h4J.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
3
3
|
import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { E as headersToRecord, a as resolveAiTransportHeaderSentinels, r as getAiTransportHost } from "./host-
|
|
6
|
-
import {
|
|
4
|
+
import { i as clampPositiveTimerTimeoutMs } from "./number-coercion-C3hztWoY.mjs";
|
|
5
|
+
import { E as headersToRecord, a as resolveAiTransportHeaderSentinels, r as getAiTransportHost } from "./host-JWXZWa-c.mjs";
|
|
6
|
+
import { h as responsesPromptObserver, k as supportsOpenAITemperature } from "./openai-responses-contracts-DlKMMTxK.mjs";
|
|
7
7
|
import { r as registerSessionResourceCleanup } from "./session-resources-D1wgDQ8C.mjs";
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import "./provider-error-CF9GWCs2.mjs";
|
|
9
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-Cr2xKVrS.mjs";
|
|
10
|
+
import { s as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, v as extractErrorCodeOrErrno, y as toErrorObject } from "./diagnostics-tQasYct1.mjs";
|
|
11
|
+
import { a as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, d as streamFragmentError, p as consumeResponseBytes } from "./text-signature-B_MB6U_9.mjs";
|
|
11
12
|
import { parseRetryAfterHeadersSeconds } from "./internal/retry-after.mjs";
|
|
12
|
-
import { c as resolveOpenAIResponsesTextFormat } from "./openai-completions-compat-
|
|
13
|
-
import { n as buildManagedModelFetch } from "./host-policy-
|
|
14
|
-
import { S as withProviderResponseHook, b as transportAbortError, h as notifyProviderStreamOpened, n as assignTransportErrorDetails } from "./transport-stream-shared-
|
|
15
|
-
import { C as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-
|
|
16
|
-
import {
|
|
17
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
18
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-
|
|
19
|
-
import {
|
|
20
|
-
import { t as
|
|
21
|
-
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-CbH84xIS.mjs";
|
|
22
|
-
import { n as withResponsesRequestAcceptance, t as responsesRequestLifecycle } from "./openai-responses-request-lifecycle-Fsag-IGZ.mjs";
|
|
23
|
-
import { t as requireApiKey } from "./required-api-key-D4kn3252.mjs";
|
|
13
|
+
import { c as resolveOpenAIResponsesTextFormat } from "./openai-completions-compat-pg1q4uNG.mjs";
|
|
14
|
+
import { n as buildManagedModelFetch } from "./host-policy-q4Azym9F.mjs";
|
|
15
|
+
import { S as withProviderResponseHook, b as transportAbortError, h as notifyProviderStreamOpened, n as assignTransportErrorDetails } from "./transport-stream-shared-DH08b7Il.mjs";
|
|
16
|
+
import { C as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-BARFAzk9.mjs";
|
|
17
|
+
import { Dt as createResponseModelTracker, E as ResponsesStreamFailure, Et as createOpenAIResponseHook, F as convertProviderResponsesMessages, S as isInvalidEncryptedContentError, T as resolveNextResponsesEncryptedContentAttempt, Tt as createOpenAIProviderAcceptanceHook, _t as resolveOpenAISimpleReasoningEffort, at as suppressOpenAIResponsesCompaction, b as commitResponsesEncryptedContentAttempt, gt as resolveOpenAIRequestReasoning, i as convertResponsesToolPayload, j as recordResponsesContextUsage, n as applyResponsesServiceTierPricing, nt as buildOpenAIResponsesReasoningReplayMetadata, o as readOpenAIMisalignmentReview, s as processResponsesStream } from "./openai-responses-shared-DVGhq5xF.mjs";
|
|
18
|
+
import { t as createAssistantOutput } from "./assistant-output-CUEeSotf.mjs";
|
|
19
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-Dc42hKv6.mjs";
|
|
20
|
+
import { n as withResponsesRequestAcceptance, r as createResponsesPromptEgressObserver, t as responsesRequestLifecycle } from "./openai-responses-request-lifecycle-D2IFiI0-.mjs";
|
|
21
|
+
import { t as requireApiKey } from "./required-api-key-CFJvcFy_.mjs";
|
|
24
22
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
25
23
|
//#region packages/ai/src/providers/openai-chatgpt-responses-events.ts
|
|
26
24
|
var CodexApiError = class extends Error {
|
|
@@ -35,9 +33,10 @@ var CodexApiError = class extends Error {
|
|
|
35
33
|
};
|
|
36
34
|
function extractCodexEventError(event) {
|
|
37
35
|
const nested = isRecord(event.error) ? event.error : void 0;
|
|
36
|
+
const read = (field) => typeof event[field] === "string" ? event[field] : typeof nested?.[field] === "string" ? nested[field] : void 0;
|
|
38
37
|
return {
|
|
39
|
-
code:
|
|
40
|
-
message:
|
|
38
|
+
code: read("code"),
|
|
39
|
+
message: read("message")
|
|
41
40
|
};
|
|
42
41
|
}
|
|
43
42
|
async function* mapCodexEvents(events, initialResponseHeaders, options) {
|
|
@@ -84,7 +83,7 @@ function normalizeCodexStatus(status) {
|
|
|
84
83
|
}
|
|
85
84
|
//#endregion
|
|
86
85
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
87
|
-
const
|
|
86
|
+
const OPENAI_CHATGPT_RESPONSES_SSE_FRAME_MAX_BYTES = 16777216;
|
|
88
87
|
var CodexProtocolError = class extends Error {
|
|
89
88
|
constructor(message, options) {
|
|
90
89
|
super(message);
|
|
@@ -96,44 +95,52 @@ var CodexProtocolError = class extends Error {
|
|
|
96
95
|
async function* parseOpenAIChatGptResponsesSse(response) {
|
|
97
96
|
if (!response.body) return;
|
|
98
97
|
const reader = response.body.getReader();
|
|
99
|
-
const guard = createSseByteGuard(reader, {
|
|
100
|
-
maxBytes: OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES,
|
|
101
|
-
onOverflow: ({ size, maxBytes }) => /* @__PURE__ */ new Error(`OpenAI ChatGPT Responses success body exceeded ${maxBytes} bytes (received ${size})`)
|
|
102
|
-
});
|
|
103
98
|
const decoder = new TextDecoder();
|
|
104
|
-
let buffer =
|
|
99
|
+
let buffer = /* @__PURE__ */ new Uint8Array(1024);
|
|
100
|
+
let size = 0;
|
|
101
|
+
let lineEmpty = true;
|
|
102
|
+
let skipLf = false;
|
|
103
|
+
let cancelReason;
|
|
105
104
|
try {
|
|
106
105
|
while (true) {
|
|
107
|
-
const { done, value } = await
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
event = JSON.parse(data);
|
|
123
|
-
} catch (cause) {
|
|
124
|
-
if (!(cause instanceof SyntaxError)) throw cause;
|
|
125
|
-
throw new CodexProtocolError(MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, { cause });
|
|
126
|
-
}
|
|
127
|
-
yield event;
|
|
106
|
+
const { done, value } = await reader.read();
|
|
107
|
+
for (let index = 0; index < (value?.length ?? 0) + (done ? 1 : 0); index++) {
|
|
108
|
+
const byte = value?.[index];
|
|
109
|
+
if (byte !== void 0) {
|
|
110
|
+
const crlf = skipLf && byte === 10;
|
|
111
|
+
skipLf = byte === 13;
|
|
112
|
+
const lineEnding = byte === 10 || byte === 13;
|
|
113
|
+
const boundary = !crlf && lineEnding && lineEmpty;
|
|
114
|
+
lineEmpty = lineEnding;
|
|
115
|
+
if (crlf && size === 0) continue;
|
|
116
|
+
if (size >= OPENAI_CHATGPT_RESPONSES_SSE_FRAME_MAX_BYTES) throw new Error(`OpenAI ChatGPT Responses SSE frame exceeded ${OPENAI_CHATGPT_RESPONSES_SSE_FRAME_MAX_BYTES} bytes`);
|
|
117
|
+
if (size === buffer.length) {
|
|
118
|
+
const grown = new Uint8Array(Math.min(buffer.length * 2, OPENAI_CHATGPT_RESPONSES_SSE_FRAME_MAX_BYTES));
|
|
119
|
+
grown.set(buffer);
|
|
120
|
+
buffer = grown;
|
|
128
121
|
}
|
|
122
|
+
buffer[size++] = byte;
|
|
123
|
+
if (!boundary) continue;
|
|
129
124
|
}
|
|
125
|
+
const chunk = decoder.decode(buffer.subarray(0, size), { stream: !done });
|
|
126
|
+
size = 0;
|
|
127
|
+
const data = chunk.split(/\r\n|\r|\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).join("\n").trim();
|
|
128
|
+
if (!data || data === "[DONE]") continue;
|
|
129
|
+
let event;
|
|
130
|
+
try {
|
|
131
|
+
event = JSON.parse(data);
|
|
132
|
+
} catch (cause) {
|
|
133
|
+
throw streamFragmentError(cause, CodexProtocolError);
|
|
134
|
+
}
|
|
135
|
+
yield event;
|
|
130
136
|
}
|
|
131
137
|
if (done) break;
|
|
132
138
|
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
cancelReason = error;
|
|
141
|
+
throw error;
|
|
133
142
|
} finally {
|
|
134
|
-
|
|
135
|
-
await guard.cancel();
|
|
136
|
-
} catch {}
|
|
143
|
+
reader.cancel(cancelReason).catch(() => void 0);
|
|
137
144
|
try {
|
|
138
145
|
reader.releaseLock();
|
|
139
146
|
} catch {}
|
|
@@ -155,17 +162,16 @@ function resolveCodexWebSocketUrl(baseUrl) {
|
|
|
155
162
|
//#endregion
|
|
156
163
|
//#region packages/ai/src/providers/openai-chatgpt-responses-websocket-authority.ts
|
|
157
164
|
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
158
|
-
function
|
|
165
|
+
function resolveCodexWebSocketAuthority(params) {
|
|
166
|
+
if (params.transport === "sse") return;
|
|
167
|
+
const headers = params.headers();
|
|
159
168
|
return {
|
|
160
|
-
transportHost,
|
|
161
|
-
url: resolveCodexWebSocketUrl(baseUrl),
|
|
169
|
+
transportHost: params.transportHost,
|
|
170
|
+
url: resolveCodexWebSocketUrl(params.baseUrl),
|
|
162
171
|
headers,
|
|
163
172
|
normalizedHeaders: Array.from(headers.entries()).filter(([name]) => name !== "traceparent")
|
|
164
173
|
};
|
|
165
174
|
}
|
|
166
|
-
function resolveCodexWebSocketAuthority(params) {
|
|
167
|
-
return params.transport === "sse" ? void 0 : createCodexWebSocketAuthority(params.transportHost, params.baseUrl, params.headers());
|
|
168
|
-
}
|
|
169
175
|
function buildCodexWebSocketHeaders(baseHeaders, requestId) {
|
|
170
176
|
baseHeaders.delete("accept");
|
|
171
177
|
baseHeaders.delete("content-type");
|
|
@@ -300,12 +306,6 @@ const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
|
300
306
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
301
307
|
const WEBSOCKET_REPLAY_REJECTION = "Codex error: Persisted response contains hosted-tool, compaction, or unverifiable hidden reasoning state that Rustponses cannot replay. Start a new response or use the Python Responses service for this continuation.";
|
|
302
308
|
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
303
|
-
function buildRequestSignal(baseSignal, timeoutMs) {
|
|
304
|
-
if (timeoutMs === void 0) return baseSignal;
|
|
305
|
-
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
306
|
-
if (!baseSignal) return timeoutSignal;
|
|
307
|
-
return AbortSignal.any([baseSignal, timeoutSignal]);
|
|
308
|
-
}
|
|
309
309
|
function isRequestTimeoutError(error, callerSignal, requestSignal, timeoutMs) {
|
|
310
310
|
if (timeoutMs === void 0 || callerSignal?.aborted || !requestSignal?.aborted) return false;
|
|
311
311
|
if (!(error instanceof Error)) return false;
|
|
@@ -362,13 +362,41 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
362
362
|
const observePromptEgress = createResponsesPromptEgressObserver(options, context.systemPrompt);
|
|
363
363
|
const sessionId = clampOpenAIPromptCacheKey(options?.sessionId);
|
|
364
364
|
requestTimeoutMs = clampPositiveTimerTimeoutMs(options?.timeoutMs);
|
|
365
|
-
requestTimeoutSignal =
|
|
365
|
+
requestTimeoutSignal = options?.signal;
|
|
366
|
+
if (requestTimeoutMs !== void 0) {
|
|
367
|
+
const timeoutSignal = AbortSignal.timeout(requestTimeoutMs);
|
|
368
|
+
requestTimeoutSignal = options?.signal ? AbortSignal.any([options.signal, timeoutSignal]) : timeoutSignal;
|
|
369
|
+
}
|
|
366
370
|
firstEventAbort = createFirstStreamEventAbortController(requestTimeoutSignal);
|
|
367
371
|
activeSignal = firstEventAbort.signal;
|
|
368
372
|
const requestOptions = activeSignal === options?.signal ? options : {
|
|
369
373
|
...options,
|
|
370
374
|
signal: activeSignal
|
|
371
375
|
};
|
|
376
|
+
const processStream = (events, streamOptions, activitySignal) => processResponsesStream(events, output, stream, model, {
|
|
377
|
+
serviceTier: streamOptions?.serviceTier,
|
|
378
|
+
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(streamOptions),
|
|
379
|
+
abortFirstEventStream: firstEventAbort?.abort,
|
|
380
|
+
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(streamOptions),
|
|
381
|
+
signal: activitySignal ?? streamOptions?.signal,
|
|
382
|
+
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
383
|
+
sessionId: streamOptions?.sessionId,
|
|
384
|
+
authProfileId: streamOptions?.authProfileId
|
|
385
|
+
}),
|
|
386
|
+
resolveServiceTier: resolveCodexServiceTier,
|
|
387
|
+
applyServiceTierPricing: (usage, serviceTier) => applyResponsesServiceTierPricing(usage, serviceTier, model)
|
|
388
|
+
});
|
|
389
|
+
const completeStream = (terminal, attempt, ErrorType) => {
|
|
390
|
+
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
391
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new ErrorType(output.errorMessage ?? "An unknown error occurred");
|
|
392
|
+
if (terminal && attempt.kind === "initial") recordResponsesContextUsage(output, model, options, attempt.request, terminal.output, "provider");
|
|
393
|
+
stream.push({
|
|
394
|
+
type: "done",
|
|
395
|
+
reason: output.stopReason,
|
|
396
|
+
message: output
|
|
397
|
+
});
|
|
398
|
+
stream.end();
|
|
399
|
+
};
|
|
372
400
|
const transport = options?.transport || "auto";
|
|
373
401
|
let websocketAuthority;
|
|
374
402
|
if (!transportHost.requiresManagedTransport(model)) try {
|
|
@@ -396,22 +424,13 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
396
424
|
const dispatch = {};
|
|
397
425
|
websocketStarted = false;
|
|
398
426
|
try {
|
|
399
|
-
|
|
427
|
+
completeStream(await processWebSocketStream(websocketState, websocketAuthority, activeAttempt.request, output, stream, model, () => {
|
|
400
428
|
websocketStarted = true;
|
|
401
429
|
}, () => {
|
|
402
430
|
commitSemanticAttempt(activeAttempt);
|
|
403
|
-
}, requestOptions,
|
|
431
|
+
}, requestOptions, processStream, observePromptEgress, activeAttempt.kind, (request) => {
|
|
404
432
|
dispatch.request = request;
|
|
405
|
-
}, options?.signal);
|
|
406
|
-
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
407
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new CodexApiError(output.errorMessage ?? "An unknown error occurred");
|
|
408
|
-
if (terminal && activeAttempt.kind === "initial") recordResponsesContextUsage(output, model, options, activeAttempt.request, terminal.output, "provider");
|
|
409
|
-
stream.push({
|
|
410
|
-
type: "done",
|
|
411
|
-
reason: output.stopReason,
|
|
412
|
-
message: output
|
|
413
|
-
});
|
|
414
|
-
stream.end();
|
|
433
|
+
}, options?.signal), activeAttempt, CodexApiError);
|
|
415
434
|
return;
|
|
416
435
|
} catch (error) {
|
|
417
436
|
const aborted = activeSignal?.aborted;
|
|
@@ -421,14 +440,14 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
421
440
|
retriedWebSocketRejection = false;
|
|
422
441
|
continue;
|
|
423
442
|
}
|
|
424
|
-
const
|
|
425
|
-
const reconnectBeforeStart = connectionLimitBeforeStart || !websocketStarted && dispatch.request?.previous_response_id && error instanceof CodexApiError && error.message === WEBSOCKET_REPLAY_REJECTION;
|
|
443
|
+
const reconnectBeforeStart = !websocketStarted && (isWebSocketConnectionLimitReachedError(error) || dispatch.request?.previous_response_id && error instanceof CodexApiError && error.message === WEBSOCKET_REPLAY_REJECTION);
|
|
426
444
|
if (!aborted && reconnectBeforeStart && !retriedWebSocketRejection) {
|
|
427
445
|
retriedWebSocketRejection = true;
|
|
428
446
|
continue;
|
|
429
447
|
}
|
|
430
|
-
|
|
431
|
-
|
|
448
|
+
const transportError = isWebSocketConnectionLimitReachedError(error) ? Object.assign(new Error(error.message, { cause: error }), { code: WEBSOCKET_TRANSPORT_ERROR_CODE }) : error;
|
|
449
|
+
if (aborted || isCodexNonTransportError(transportError)) throw transportError;
|
|
450
|
+
appendAssistantMessageDiagnostic(output, createAssistantMessageDiagnostic("provider_transport_failure", transportError, {
|
|
432
451
|
configuredTransport: transport,
|
|
433
452
|
fallbackTransport: transport === "auto" && !websocketStarted ? "sse" : void 0,
|
|
434
453
|
eventsEmitted: websocketStarted,
|
|
@@ -436,7 +455,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
436
455
|
requestBytes: new TextEncoder().encode(JSON.stringify(activeAttempt.request)).byteLength
|
|
437
456
|
}));
|
|
438
457
|
if (transport === "auto" && options?.sessionId) addCodexWebSocketSseFallback(websocketState.sseFallbacks, options.sessionId, websocketAuthority);
|
|
439
|
-
if (websocketStarted || transport !== "auto") throw
|
|
458
|
+
if (websocketStarted || transport !== "auto") throw transportError;
|
|
440
459
|
break;
|
|
441
460
|
}
|
|
442
461
|
}
|
|
@@ -504,7 +523,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
504
523
|
if (!nextSemanticAttempt) throw terminalResponseError;
|
|
505
524
|
semanticAttempt = nextSemanticAttempt;
|
|
506
525
|
}
|
|
507
|
-
|
|
526
|
+
completeStream(await processStream(withProviderResponseHook({
|
|
508
527
|
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response), response.headers, requestOptions),
|
|
509
528
|
signal: firstEventAbort.signal,
|
|
510
529
|
abort: firstEventAbort.abort,
|
|
@@ -513,29 +532,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
513
532
|
type: "start",
|
|
514
533
|
partial: output
|
|
515
534
|
})
|
|
516
|
-
});
|
|
517
|
-
const terminal = await processResponsesStream(hookedResponseStream, output, stream, model, {
|
|
518
|
-
serviceTier: options?.serviceTier,
|
|
519
|
-
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
520
|
-
abortFirstEventStream: firstEventAbort.abort,
|
|
521
|
-
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
522
|
-
signal: options?.signal,
|
|
523
|
-
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
524
|
-
sessionId: options?.sessionId,
|
|
525
|
-
authProfileId: options?.authProfileId
|
|
526
|
-
}),
|
|
527
|
-
resolveServiceTier: resolveCodexServiceTier,
|
|
528
|
-
applyServiceTierPricing: (usage, serviceTier) => applyResponsesServiceTierPricing(usage, serviceTier, model)
|
|
529
|
-
});
|
|
530
|
-
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
531
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
532
|
-
if (terminal && semanticAttempt.kind === "initial") recordResponsesContextUsage(output, model, options, semanticAttempt.request, terminal.output, "provider");
|
|
533
|
-
stream.push({
|
|
534
|
-
type: "done",
|
|
535
|
-
reason: output.stopReason,
|
|
536
|
-
message: output
|
|
537
|
-
});
|
|
538
|
-
stream.end();
|
|
535
|
+
}), options), semanticAttempt, Error);
|
|
539
536
|
} catch (error) {
|
|
540
537
|
await responsesRequestLifecycle.get(options)?.settle().catch(() => void 0);
|
|
541
538
|
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
@@ -709,33 +706,18 @@ async function connectWebSocket(url, headers, signal) {
|
|
|
709
706
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
710
707
|
return;
|
|
711
708
|
}
|
|
712
|
-
const
|
|
713
|
-
if (settled) return;
|
|
714
|
-
settled = true;
|
|
715
|
-
cleanup();
|
|
716
|
-
resolve(socket);
|
|
717
|
-
};
|
|
718
|
-
const onError = (event) => {
|
|
719
|
-
const error = extractWebSocketError(event);
|
|
709
|
+
const settle = (error, aborted = false) => {
|
|
720
710
|
if (settled) return;
|
|
721
711
|
settled = true;
|
|
722
712
|
cleanup();
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
const error = extractWebSocketCloseError(event);
|
|
727
|
-
if (settled) return;
|
|
728
|
-
settled = true;
|
|
729
|
-
cleanup();
|
|
730
|
-
reject(error);
|
|
731
|
-
};
|
|
732
|
-
const onAbort = () => {
|
|
733
|
-
if (settled) return;
|
|
734
|
-
settled = true;
|
|
735
|
-
cleanup();
|
|
736
|
-
socket.close(1e3, "aborted");
|
|
737
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
713
|
+
if (aborted) socket.close(1e3, "aborted");
|
|
714
|
+
if (error) reject(error);
|
|
715
|
+
else resolve(socket);
|
|
738
716
|
};
|
|
717
|
+
const onOpen = () => settle();
|
|
718
|
+
const onError = (event) => settle(extractWebSocketError(event));
|
|
719
|
+
const onClose = (event) => settle(extractWebSocketCloseError(event));
|
|
720
|
+
const onAbort = () => settle(/* @__PURE__ */ new Error("Request was aborted"), true);
|
|
739
721
|
const cleanup = () => {
|
|
740
722
|
socket.removeEventListener("open", onOpen);
|
|
741
723
|
socket.removeEventListener("error", onError);
|
|
@@ -848,12 +830,15 @@ async function* parseWebSocket(socket, signal) {
|
|
|
848
830
|
pending = null;
|
|
849
831
|
resolve();
|
|
850
832
|
};
|
|
833
|
+
const finish = (error) => {
|
|
834
|
+
if (error) failed = error;
|
|
835
|
+
done = true;
|
|
836
|
+
wake();
|
|
837
|
+
};
|
|
851
838
|
const onMessage = (event) => {
|
|
852
839
|
const data = event && typeof event === "object" && "data" in event ? event.data : void 0;
|
|
853
840
|
if (typeof data !== "string") {
|
|
854
|
-
|
|
855
|
-
done = true;
|
|
856
|
-
wake();
|
|
841
|
+
finish(new CodexProtocolError(MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, { payload: data }));
|
|
857
842
|
return;
|
|
858
843
|
}
|
|
859
844
|
try {
|
|
@@ -866,34 +851,15 @@ async function* parseWebSocket(socket, signal) {
|
|
|
866
851
|
queue.push(parsed);
|
|
867
852
|
wake();
|
|
868
853
|
} catch (cause) {
|
|
869
|
-
|
|
854
|
+
finish(new CodexProtocolError(`Invalid Codex WebSocket JSON: ${formatThrownValue(cause)}`, {
|
|
870
855
|
cause,
|
|
871
856
|
payload: data
|
|
872
|
-
});
|
|
873
|
-
done = true;
|
|
874
|
-
wake();
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
const onError = (event) => {
|
|
878
|
-
failed = extractWebSocketError(event);
|
|
879
|
-
done = true;
|
|
880
|
-
wake();
|
|
881
|
-
};
|
|
882
|
-
const onClose = (event) => {
|
|
883
|
-
if (sawCompletion) {
|
|
884
|
-
done = true;
|
|
885
|
-
wake();
|
|
886
|
-
return;
|
|
857
|
+
}));
|
|
887
858
|
}
|
|
888
|
-
if (!failed) failed = extractWebSocketCloseError(event);
|
|
889
|
-
done = true;
|
|
890
|
-
wake();
|
|
891
|
-
};
|
|
892
|
-
const onAbort = () => {
|
|
893
|
-
failed = /* @__PURE__ */ new Error("Request was aborted");
|
|
894
|
-
done = true;
|
|
895
|
-
wake();
|
|
896
859
|
};
|
|
860
|
+
const onError = (event) => finish(extractWebSocketError(event));
|
|
861
|
+
const onClose = (event) => finish(!sawCompletion && !failed ? extractWebSocketCloseError(event) : void 0);
|
|
862
|
+
const onAbort = () => finish(/* @__PURE__ */ new Error("Request was aborted"));
|
|
897
863
|
socket.addEventListener("message", onMessage);
|
|
898
864
|
socket.addEventListener("error", onError);
|
|
899
865
|
socket.addEventListener("close", onClose);
|
|
@@ -920,58 +886,52 @@ async function* parseWebSocket(socket, signal) {
|
|
|
920
886
|
signal?.removeEventListener("abort", onAbort);
|
|
921
887
|
}
|
|
922
888
|
}
|
|
923
|
-
function
|
|
889
|
+
function serializeRequestContext(body) {
|
|
924
890
|
const { input: _input, previous_response_id: _previousResponseId, ...rest } = body;
|
|
925
|
-
return rest;
|
|
926
|
-
}
|
|
927
|
-
function requestBodiesMatchExceptInput(a, b) {
|
|
928
|
-
return JSON.stringify(requestBodyWithoutInput(a)) === JSON.stringify(requestBodyWithoutInput(b));
|
|
929
|
-
}
|
|
930
|
-
function getCachedWebSocketInputDelta(body, continuation) {
|
|
931
|
-
if (!requestBodiesMatchExceptInput(body, continuation.lastRequestBody)) return;
|
|
932
|
-
const currentInput = body.input ?? [];
|
|
933
|
-
const baseline = [...continuation.lastRequestBody.input ?? [], ...continuation.lastResponseItems];
|
|
934
|
-
if (currentInput.length < baseline.length) return;
|
|
935
|
-
const prefix = currentInput.slice(0, baseline.length);
|
|
936
|
-
if (JSON.stringify(prefix) !== JSON.stringify(baseline)) return;
|
|
937
|
-
return currentInput.slice(baseline.length);
|
|
891
|
+
return JSON.stringify(rest);
|
|
938
892
|
}
|
|
939
893
|
function buildCachedWebSocketRequestBody(entry, body) {
|
|
940
894
|
const continuation = entry.continuation;
|
|
941
895
|
if (!continuation) return body;
|
|
942
|
-
const
|
|
943
|
-
|
|
896
|
+
const currentInput = body.input ?? [];
|
|
897
|
+
const baseline = [...continuation.lastRequestBody.input ?? [], ...continuation.lastResponseItems];
|
|
898
|
+
if (!continuation.lastResponseId || serializeRequestContext(body) !== serializeRequestContext(continuation.lastRequestBody) || currentInput.length < baseline.length || JSON.stringify(currentInput.slice(0, baseline.length)) !== JSON.stringify(baseline)) {
|
|
944
899
|
entry.continuation = void 0;
|
|
945
900
|
return body;
|
|
946
901
|
}
|
|
947
902
|
return {
|
|
948
903
|
...body,
|
|
949
904
|
previous_response_id: continuation.lastResponseId,
|
|
950
|
-
input:
|
|
905
|
+
input: currentInput.slice(baseline.length)
|
|
951
906
|
};
|
|
952
907
|
}
|
|
953
|
-
async function
|
|
954
|
-
let started = false;
|
|
955
|
-
for await (const event of events) {
|
|
956
|
-
if (!started) {
|
|
957
|
-
started = true;
|
|
958
|
-
onFirstProviderEvent();
|
|
959
|
-
onStart();
|
|
960
|
-
await reportStreamOpened();
|
|
961
|
-
stream.push({
|
|
962
|
-
type: "start",
|
|
963
|
-
partial: output
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
yield event;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
async function processWebSocketStream(state, authority, body, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent, activitySignal) {
|
|
908
|
+
async function processWebSocketStream(state, authority, body, output, stream, model, onFirstProviderEvent, onStart, options, processStream, observePromptEgress, payloadVariant = "initial", onRequestSent, activitySignal) {
|
|
970
909
|
const { socket, entry, release } = await acquireWebSocket(state, authority, options?.sessionId, options?.signal);
|
|
971
910
|
let keepConnection = true;
|
|
972
911
|
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
973
|
-
const
|
|
974
|
-
|
|
912
|
+
const requestBody = useCachedContext && entry ? buildCachedWebSocketRequestBody(entry, body) : body;
|
|
913
|
+
async function* acceptedEvents() {
|
|
914
|
+
let started = false;
|
|
915
|
+
for await (const event of mapCodexEvents(parseWebSocket(socket, options?.signal), void 0, options)) {
|
|
916
|
+
if (!started) {
|
|
917
|
+
started = true;
|
|
918
|
+
onFirstProviderEvent();
|
|
919
|
+
onStart();
|
|
920
|
+
await notifyProviderStreamOpened({
|
|
921
|
+
options,
|
|
922
|
+
cancelStream: () => {
|
|
923
|
+
keepConnection = false;
|
|
924
|
+
closeWebSocketSilently(socket);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
stream.push({
|
|
928
|
+
type: "start",
|
|
929
|
+
partial: output
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
yield event;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
975
935
|
try {
|
|
976
936
|
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
977
937
|
observePromptEgress?.(requestBody, {
|
|
@@ -989,25 +949,7 @@ async function processWebSocketStream(state, authority, body, output, stream, mo
|
|
|
989
949
|
...requestBody
|
|
990
950
|
}));
|
|
991
951
|
onRequestSent?.(requestBody);
|
|
992
|
-
const terminal = await
|
|
993
|
-
options,
|
|
994
|
-
cancelStream: () => {
|
|
995
|
-
keepConnection = false;
|
|
996
|
-
closeWebSocketSilently(socket);
|
|
997
|
-
}
|
|
998
|
-
}), onStart), output, stream, model, {
|
|
999
|
-
serviceTier: options?.serviceTier,
|
|
1000
|
-
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
1001
|
-
abortFirstEventStream,
|
|
1002
|
-
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
1003
|
-
signal: activitySignal ?? options?.signal,
|
|
1004
|
-
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
1005
|
-
sessionId: options?.sessionId,
|
|
1006
|
-
authProfileId: options?.authProfileId
|
|
1007
|
-
}),
|
|
1008
|
-
resolveServiceTier: resolveCodexServiceTier,
|
|
1009
|
-
applyServiceTierPricing: (usage, serviceTier) => applyResponsesServiceTierPricing(usage, serviceTier, model)
|
|
1010
|
-
});
|
|
952
|
+
const terminal = await processStream(acceptedEvents(), options, activitySignal);
|
|
1011
953
|
if (options?.signal?.aborted) keepConnection = false;
|
|
1012
954
|
else if (useCachedContext && entry && output.responseId) {
|
|
1013
955
|
const responseItems = convertProviderResponsesMessages(model, { messages: [output] }, CODEX_TOOL_CALL_PROVIDERS, {
|
|
@@ -1017,7 +959,7 @@ async function processWebSocketStream(state, authority, body, output, stream, mo
|
|
|
1017
959
|
authProfileId: options?.authProfileId
|
|
1018
960
|
}).filter((item) => item.type !== "function_call_output");
|
|
1019
961
|
entry.continuation = {
|
|
1020
|
-
lastRequestBody:
|
|
962
|
+
lastRequestBody: body,
|
|
1021
963
|
lastResponseId: output.responseId,
|
|
1022
964
|
lastResponseItems: responseItems
|
|
1023
965
|
};
|
|
@@ -1035,9 +977,7 @@ async function readChatGptResponsesErrorTextLimited(response, signal) {
|
|
|
1035
977
|
const reader = response.body?.getReader();
|
|
1036
978
|
if (!reader) return "";
|
|
1037
979
|
const decoder = new TextDecoder();
|
|
1038
|
-
let total = 0;
|
|
1039
980
|
let text = "";
|
|
1040
|
-
let reachedLimit = false;
|
|
1041
981
|
let completed = false;
|
|
1042
982
|
let cancelPromise;
|
|
1043
983
|
const cancel = () => {
|
|
@@ -1050,27 +990,17 @@ async function readChatGptResponsesErrorTextLimited(response, signal) {
|
|
|
1050
990
|
if (signal?.aborted) onAbort();
|
|
1051
991
|
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
1052
992
|
try {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
}
|
|
1065
|
-
const chunk = value.byteLength > remaining ? value.subarray(0, remaining) : value;
|
|
1066
|
-
total += chunk.byteLength;
|
|
1067
|
-
text += decoder.decode(chunk, { stream: true });
|
|
1068
|
-
if (total >= OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES) {
|
|
1069
|
-
reachedLimit = true;
|
|
1070
|
-
break;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
if (!reachedLimit) text += decoder.decode();
|
|
993
|
+
const { truncated } = await consumeResponseBytes({
|
|
994
|
+
maxBytes: OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES,
|
|
995
|
+
stopAtLimit: true,
|
|
996
|
+
read: () => reader.read(),
|
|
997
|
+
onChunk: (chunk) => {
|
|
998
|
+
text += decoder.decode(chunk, { stream: true });
|
|
999
|
+
},
|
|
1000
|
+
onLimit: () => {}
|
|
1001
|
+
});
|
|
1002
|
+
completed = !truncated;
|
|
1003
|
+
if (completed) text += decoder.decode();
|
|
1074
1004
|
} finally {
|
|
1075
1005
|
signal?.removeEventListener("abort", onAbort);
|
|
1076
1006
|
if (!completed) await cancel();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
-
import { k as clampThinkingLevel } from "./host-
|
|
3
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
4
|
-
import {
|
|
5
|
-
import { t as requireApiKey } from "./required-api-key-
|
|
2
|
+
import { k as clampThinkingLevel } from "./host-JWXZWa-c.mjs";
|
|
3
|
+
import { n as buildBaseOptions } from "./simple-options-BARFAzk9.mjs";
|
|
4
|
+
import { c as convertMessages, n as streamOpenAICompletionsRequest } from "./openai-completions-transport-OMrn7gnZ.mjs";
|
|
5
|
+
import { t as requireApiKey } from "./required-api-key-CFJvcFy_.mjs";
|
|
6
6
|
//#region packages/ai/src/providers/openai-completions.ts
|
|
7
7
|
var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
8
8
|
convertMessages: () => convertMessages,
|
|
@@ -14,11 +14,12 @@ const streamSimpleOpenAICompletions = (model, context, options) => {
|
|
|
14
14
|
const apiKey = requireApiKey(model.provider, options?.apiKey);
|
|
15
15
|
const base = buildBaseOptions(model, options, apiKey);
|
|
16
16
|
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
17
|
-
const
|
|
17
|
+
const completionsOptions = options;
|
|
18
18
|
return streamOpenAICompletions(model, context, {
|
|
19
19
|
...base,
|
|
20
20
|
reasoningEffort: clampedReasoning,
|
|
21
|
-
toolChoice
|
|
21
|
+
toolChoice: completionsOptions?.toolChoice,
|
|
22
|
+
streaming: completionsOptions?.streaming
|
|
22
23
|
});
|
|
23
24
|
};
|
|
24
25
|
//#endregion
|