@openclaw/ai 2026.10.1-beta.2 → 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-CZv6XFER.mjs → anthropic-BAHKgWam.mjs} +30 -59
- package/dist/{anthropic-payload-policy-BhCcgNdm.d.mts → anthropic-payload-policy-DGblkHL5.d.mts} +19 -16
- package/dist/{anthropic-stream-reducer-BQ1tjd7x.mjs → anthropic-stream-reducer-g6w1YVii.mjs} +197 -285
- package/dist/{api-registry-DpU0Rj-I.d.mts → api-registry-BhXXYdRA.d.mts} +2 -2
- package/dist/assistant-message-events-CHMJgbhs.mjs +18 -0
- package/dist/{assistant-output-OLm-Oln0.mjs → assistant-output-CUEeSotf.mjs} +2 -2
- package/dist/{assistant-text-phase-Bl1aDCB7.mjs → assistant-text-phase-BrV8KdFO.mjs} +7 -6
- package/dist/{azure-openai-responses-DH7bd3QT.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-wrnE6MLw.mjs → google-interactions-tjAb1mc5.mjs} +52 -84
- package/dist/{google-messages-BwPPycw6.mjs → google-messages-C-RZzloH.mjs} +25 -35
- package/dist/google-provider-stream-CMImyxbX.mjs +58 -0
- package/dist/{google-shared-Eql1OMPU.mjs → google-shared-OyAtMTZv.mjs} +6 -15
- package/dist/google-vertex-hCxTJea7.mjs +40 -0
- package/dist/{host-BinBeGcQ.d.mts → host-CTDz7LXD.d.mts} +6 -3
- package/dist/{host-DCW52iHe.mjs → host-JWXZWa-c.mjs} +12 -8
- package/dist/{host-policy-B3jc4Rpn.mjs → host-policy-q4Azym9F.mjs} +1 -1
- package/dist/{index-a8e_oKnu.d.mts → index-BYDvopUB.d.mts} +27 -6
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -6
- package/dist/internal/anthropic.d.mts +6 -6
- package/dist/internal/anthropic.mjs +5 -5
- 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 +14 -11
- 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-DSt4vQAO.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-BC2x0Oqx.mjs → openai-chatgpt-responses-OCwckGhY.mjs} +173 -242
- package/dist/{openai-completions-DNyHnXKg.mjs → openai-completions-DOltBUe9.mjs} +7 -6
- package/dist/{openai-completions-compat-BYdYpXhU.d.mts → openai-completions-compat-i-nLZxFy.d.mts} +10 -11
- package/dist/{openai-completions-compat-BdmlhD4u.mjs → openai-completions-compat-pg1q4uNG.mjs} +10 -6
- package/dist/openai-completions-transport-OMrn7gnZ.mjs +3319 -0
- package/dist/{openai-prompt-cache-I8YQTzf8.mjs → openai-prompt-cache-Cr2xKVrS.mjs} +1 -1
- package/dist/{openai-prompt-cache-45-AH_xv.d.mts → openai-prompt-cache-DIPMrMFy.d.mts} +2 -2
- package/dist/{openai-responses-uZ5oWSp7.mjs → openai-responses-BSBJUA19.mjs} +9 -10
- package/dist/{openai-responses-compaction-replay-BClApUIf.d.mts → openai-responses-compaction-replay-B2FE4Nw8.d.mts} +4 -4
- package/dist/{openai-responses-contracts-Br5IIw_h.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-CCg7B6l4.mjs → openai-responses-request-lifecycle-D2IFiI0-.mjs} +39 -4
- package/dist/{openai-responses-shared-C7oVyjED.mjs → openai-responses-shared-DVGhq5xF.mjs} +1036 -327
- package/dist/{openai-responses-terminal-usage-DgImcyJu.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-D5ABCV_l.d.mts → provider-options-CVrXZBtA.d.mts} +3 -2
- package/dist/{provider-transport-turn-state-_M2kLdUE.mjs → provider-transport-turn-state-LuCaTsSO.mjs} +2 -2
- package/dist/{provider-types-F8Mqc9Ma.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-BkKTXxhp.mjs → simple-options-BARFAzk9.mjs} +9 -11
- package/dist/{src-B0NIt2UK.mjs → src-C_wfIUmV.mjs} +35 -10
- package/dist/{stream-DSdzKsDK.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-MLwfi6fq.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-BcAKh2XH.d.mts → transport-stream-shared-BmpzDtdQ.d.mts} +4 -4
- package/dist/{transport-stream-shared-CxXXz_Dd.mjs → transport-stream-shared-DH08b7Il.mjs} +31 -20
- 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 -4
- package/dist/event-stream-DqDQWqiy.d.mts +0 -1
- package/dist/google-1WLOtb8w.mjs +0 -54
- package/dist/google-vertex-0LrlRoO3.mjs +0 -88
- package/dist/openai-completions-transport-DWM2mQDB.mjs +0 -2081
- package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +0 -36
- package/dist/openai-transport-params-JFsnIyto.mjs +0 -735
- package/dist/openai-web-search-tools-Cfu0uLyN.mjs +0 -14
- package/dist/provider-replay-context-C7Bmi84a.mjs +0 -25
- package/dist/types-BuiEBM3u.d.mts +0 -1
package/dist/{openai-chatgpt-responses-BC2x0Oqx.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-CCg7B6l4.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");
|
|
@@ -298,13 +304,8 @@ const RETRYABLE_WEBSOCKET_CLOSE_CODES = /* @__PURE__ */ new Set([
|
|
|
298
304
|
]);
|
|
299
305
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
300
306
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
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.";
|
|
301
308
|
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
302
|
-
function buildRequestSignal(baseSignal, timeoutMs) {
|
|
303
|
-
if (timeoutMs === void 0) return baseSignal;
|
|
304
|
-
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
305
|
-
if (!baseSignal) return timeoutSignal;
|
|
306
|
-
return AbortSignal.any([baseSignal, timeoutSignal]);
|
|
307
|
-
}
|
|
308
309
|
function isRequestTimeoutError(error, callerSignal, requestSignal, timeoutMs) {
|
|
309
310
|
if (timeoutMs === void 0 || callerSignal?.aborted || !requestSignal?.aborted) return false;
|
|
310
311
|
if (!(error instanceof Error)) return false;
|
|
@@ -361,13 +362,41 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
361
362
|
const observePromptEgress = createResponsesPromptEgressObserver(options, context.systemPrompt);
|
|
362
363
|
const sessionId = clampOpenAIPromptCacheKey(options?.sessionId);
|
|
363
364
|
requestTimeoutMs = clampPositiveTimerTimeoutMs(options?.timeoutMs);
|
|
364
|
-
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
|
+
}
|
|
365
370
|
firstEventAbort = createFirstStreamEventAbortController(requestTimeoutSignal);
|
|
366
371
|
activeSignal = firstEventAbort.signal;
|
|
367
372
|
const requestOptions = activeSignal === options?.signal ? options : {
|
|
368
373
|
...options,
|
|
369
374
|
signal: activeSignal
|
|
370
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
|
+
};
|
|
371
400
|
const transport = options?.transport || "auto";
|
|
372
401
|
let websocketAuthority;
|
|
373
402
|
if (!transportHost.requiresManagedTransport(model)) try {
|
|
@@ -389,45 +418,36 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
389
418
|
const websocketDisabledForSession = transport === "auto" && websocketAuthority !== void 0 && hasCodexWebSocketSseFallback(websocketState.sseFallbacks, options?.sessionId, websocketAuthority);
|
|
390
419
|
if (websocketAuthority && !websocketDisabledForSession) {
|
|
391
420
|
let websocketStarted = false;
|
|
392
|
-
let
|
|
393
|
-
let retriedWebSocketConnectionLimit = false;
|
|
421
|
+
let retriedWebSocketRejection = false;
|
|
394
422
|
while (true) {
|
|
395
423
|
const activeAttempt = semanticAttempt;
|
|
424
|
+
const dispatch = {};
|
|
396
425
|
websocketStarted = false;
|
|
397
|
-
websocketRequestSent = 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,
|
|
404
|
-
|
|
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();
|
|
431
|
+
}, requestOptions, processStream, observePromptEgress, activeAttempt.kind, (request) => {
|
|
432
|
+
dispatch.request = request;
|
|
433
|
+
}, options?.signal), activeAttempt, CodexApiError);
|
|
415
434
|
return;
|
|
416
435
|
} catch (error) {
|
|
417
436
|
const aborted = activeSignal?.aborted;
|
|
418
|
-
const nextSemanticAttempt = !aborted &&
|
|
437
|
+
const nextSemanticAttempt = !aborted && dispatch.request && !websocketStarted && error instanceof CodexApiError && isInvalidEncryptedContentError(error) ? await resolveNextResponsesEncryptedContentAttempt(activeAttempt, error, { buildFullHistoryRequest: () => buildBody("full-history") }) : void 0;
|
|
419
438
|
if (nextSemanticAttempt) {
|
|
420
439
|
semanticAttempt = nextSemanticAttempt;
|
|
421
|
-
|
|
440
|
+
retriedWebSocketRejection = false;
|
|
422
441
|
continue;
|
|
423
442
|
}
|
|
424
|
-
const
|
|
425
|
-
if (!aborted &&
|
|
426
|
-
|
|
443
|
+
const reconnectBeforeStart = !websocketStarted && (isWebSocketConnectionLimitReachedError(error) || dispatch.request?.previous_response_id && error instanceof CodexApiError && error.message === WEBSOCKET_REPLAY_REJECTION);
|
|
444
|
+
if (!aborted && reconnectBeforeStart && !retriedWebSocketRejection) {
|
|
445
|
+
retriedWebSocketRejection = true;
|
|
427
446
|
continue;
|
|
428
447
|
}
|
|
429
|
-
|
|
430
|
-
|
|
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, {
|
|
431
451
|
configuredTransport: transport,
|
|
432
452
|
fallbackTransport: transport === "auto" && !websocketStarted ? "sse" : void 0,
|
|
433
453
|
eventsEmitted: websocketStarted,
|
|
@@ -435,7 +455,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
435
455
|
requestBytes: new TextEncoder().encode(JSON.stringify(activeAttempt.request)).byteLength
|
|
436
456
|
}));
|
|
437
457
|
if (transport === "auto" && options?.sessionId) addCodexWebSocketSseFallback(websocketState.sseFallbacks, options.sessionId, websocketAuthority);
|
|
438
|
-
if (websocketStarted || transport !== "auto") throw
|
|
458
|
+
if (websocketStarted || transport !== "auto") throw transportError;
|
|
439
459
|
break;
|
|
440
460
|
}
|
|
441
461
|
}
|
|
@@ -503,7 +523,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
503
523
|
if (!nextSemanticAttempt) throw terminalResponseError;
|
|
504
524
|
semanticAttempt = nextSemanticAttempt;
|
|
505
525
|
}
|
|
506
|
-
|
|
526
|
+
completeStream(await processStream(withProviderResponseHook({
|
|
507
527
|
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response), response.headers, requestOptions),
|
|
508
528
|
signal: firstEventAbort.signal,
|
|
509
529
|
abort: firstEventAbort.abort,
|
|
@@ -512,29 +532,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
512
532
|
type: "start",
|
|
513
533
|
partial: output
|
|
514
534
|
})
|
|
515
|
-
});
|
|
516
|
-
const terminal = await processResponsesStream(hookedResponseStream, output, stream, model, {
|
|
517
|
-
serviceTier: options?.serviceTier,
|
|
518
|
-
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
519
|
-
abortFirstEventStream: firstEventAbort.abort,
|
|
520
|
-
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
521
|
-
signal: options?.signal,
|
|
522
|
-
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
523
|
-
sessionId: options?.sessionId,
|
|
524
|
-
authProfileId: options?.authProfileId
|
|
525
|
-
}),
|
|
526
|
-
resolveServiceTier: resolveCodexServiceTier,
|
|
527
|
-
applyServiceTierPricing: (usage, serviceTier) => applyResponsesServiceTierPricing(usage, serviceTier, model)
|
|
528
|
-
});
|
|
529
|
-
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
530
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
531
|
-
if (terminal && semanticAttempt.kind === "initial") recordResponsesContextUsage(output, model, options, semanticAttempt.request, terminal.output, "provider");
|
|
532
|
-
stream.push({
|
|
533
|
-
type: "done",
|
|
534
|
-
reason: output.stopReason,
|
|
535
|
-
message: output
|
|
536
|
-
});
|
|
537
|
-
stream.end();
|
|
535
|
+
}), options), semanticAttempt, Error);
|
|
538
536
|
} catch (error) {
|
|
539
537
|
await responsesRequestLifecycle.get(options)?.settle().catch(() => void 0);
|
|
540
538
|
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
@@ -708,33 +706,18 @@ async function connectWebSocket(url, headers, signal) {
|
|
|
708
706
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
709
707
|
return;
|
|
710
708
|
}
|
|
711
|
-
const
|
|
712
|
-
if (settled) return;
|
|
713
|
-
settled = true;
|
|
714
|
-
cleanup();
|
|
715
|
-
resolve(socket);
|
|
716
|
-
};
|
|
717
|
-
const onError = (event) => {
|
|
718
|
-
const error = extractWebSocketError(event);
|
|
709
|
+
const settle = (error, aborted = false) => {
|
|
719
710
|
if (settled) return;
|
|
720
711
|
settled = true;
|
|
721
712
|
cleanup();
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const error = extractWebSocketCloseError(event);
|
|
726
|
-
if (settled) return;
|
|
727
|
-
settled = true;
|
|
728
|
-
cleanup();
|
|
729
|
-
reject(error);
|
|
730
|
-
};
|
|
731
|
-
const onAbort = () => {
|
|
732
|
-
if (settled) return;
|
|
733
|
-
settled = true;
|
|
734
|
-
cleanup();
|
|
735
|
-
socket.close(1e3, "aborted");
|
|
736
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
713
|
+
if (aborted) socket.close(1e3, "aborted");
|
|
714
|
+
if (error) reject(error);
|
|
715
|
+
else resolve(socket);
|
|
737
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);
|
|
738
721
|
const cleanup = () => {
|
|
739
722
|
socket.removeEventListener("open", onOpen);
|
|
740
723
|
socket.removeEventListener("error", onError);
|
|
@@ -847,12 +830,15 @@ async function* parseWebSocket(socket, signal) {
|
|
|
847
830
|
pending = null;
|
|
848
831
|
resolve();
|
|
849
832
|
};
|
|
833
|
+
const finish = (error) => {
|
|
834
|
+
if (error) failed = error;
|
|
835
|
+
done = true;
|
|
836
|
+
wake();
|
|
837
|
+
};
|
|
850
838
|
const onMessage = (event) => {
|
|
851
839
|
const data = event && typeof event === "object" && "data" in event ? event.data : void 0;
|
|
852
840
|
if (typeof data !== "string") {
|
|
853
|
-
|
|
854
|
-
done = true;
|
|
855
|
-
wake();
|
|
841
|
+
finish(new CodexProtocolError(MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, { payload: data }));
|
|
856
842
|
return;
|
|
857
843
|
}
|
|
858
844
|
try {
|
|
@@ -865,34 +851,15 @@ async function* parseWebSocket(socket, signal) {
|
|
|
865
851
|
queue.push(parsed);
|
|
866
852
|
wake();
|
|
867
853
|
} catch (cause) {
|
|
868
|
-
|
|
854
|
+
finish(new CodexProtocolError(`Invalid Codex WebSocket JSON: ${formatThrownValue(cause)}`, {
|
|
869
855
|
cause,
|
|
870
856
|
payload: data
|
|
871
|
-
});
|
|
872
|
-
done = true;
|
|
873
|
-
wake();
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
const onError = (event) => {
|
|
877
|
-
failed = extractWebSocketError(event);
|
|
878
|
-
done = true;
|
|
879
|
-
wake();
|
|
880
|
-
};
|
|
881
|
-
const onClose = (event) => {
|
|
882
|
-
if (sawCompletion) {
|
|
883
|
-
done = true;
|
|
884
|
-
wake();
|
|
885
|
-
return;
|
|
857
|
+
}));
|
|
886
858
|
}
|
|
887
|
-
if (!failed) failed = extractWebSocketCloseError(event);
|
|
888
|
-
done = true;
|
|
889
|
-
wake();
|
|
890
|
-
};
|
|
891
|
-
const onAbort = () => {
|
|
892
|
-
failed = /* @__PURE__ */ new Error("Request was aborted");
|
|
893
|
-
done = true;
|
|
894
|
-
wake();
|
|
895
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"));
|
|
896
863
|
socket.addEventListener("message", onMessage);
|
|
897
864
|
socket.addEventListener("error", onError);
|
|
898
865
|
socket.addEventListener("close", onClose);
|
|
@@ -919,58 +886,52 @@ async function* parseWebSocket(socket, signal) {
|
|
|
919
886
|
signal?.removeEventListener("abort", onAbort);
|
|
920
887
|
}
|
|
921
888
|
}
|
|
922
|
-
function
|
|
889
|
+
function serializeRequestContext(body) {
|
|
923
890
|
const { input: _input, previous_response_id: _previousResponseId, ...rest } = body;
|
|
924
|
-
return rest;
|
|
925
|
-
}
|
|
926
|
-
function requestBodiesMatchExceptInput(a, b) {
|
|
927
|
-
return JSON.stringify(requestBodyWithoutInput(a)) === JSON.stringify(requestBodyWithoutInput(b));
|
|
928
|
-
}
|
|
929
|
-
function getCachedWebSocketInputDelta(body, continuation) {
|
|
930
|
-
if (!requestBodiesMatchExceptInput(body, continuation.lastRequestBody)) return;
|
|
931
|
-
const currentInput = body.input ?? [];
|
|
932
|
-
const baseline = [...continuation.lastRequestBody.input ?? [], ...continuation.lastResponseItems];
|
|
933
|
-
if (currentInput.length < baseline.length) return;
|
|
934
|
-
const prefix = currentInput.slice(0, baseline.length);
|
|
935
|
-
if (JSON.stringify(prefix) !== JSON.stringify(baseline)) return;
|
|
936
|
-
return currentInput.slice(baseline.length);
|
|
891
|
+
return JSON.stringify(rest);
|
|
937
892
|
}
|
|
938
893
|
function buildCachedWebSocketRequestBody(entry, body) {
|
|
939
894
|
const continuation = entry.continuation;
|
|
940
895
|
if (!continuation) return body;
|
|
941
|
-
const
|
|
942
|
-
|
|
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)) {
|
|
943
899
|
entry.continuation = void 0;
|
|
944
900
|
return body;
|
|
945
901
|
}
|
|
946
902
|
return {
|
|
947
903
|
...body,
|
|
948
904
|
previous_response_id: continuation.lastResponseId,
|
|
949
|
-
input:
|
|
905
|
+
input: currentInput.slice(baseline.length)
|
|
950
906
|
};
|
|
951
907
|
}
|
|
952
|
-
async function
|
|
953
|
-
let started = false;
|
|
954
|
-
for await (const event of events) {
|
|
955
|
-
if (!started) {
|
|
956
|
-
started = true;
|
|
957
|
-
onFirstProviderEvent();
|
|
958
|
-
onStart();
|
|
959
|
-
await reportStreamOpened();
|
|
960
|
-
stream.push({
|
|
961
|
-
type: "start",
|
|
962
|
-
partial: output
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
yield event;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
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) {
|
|
969
909
|
const { socket, entry, release } = await acquireWebSocket(state, authority, options?.sessionId, options?.signal);
|
|
970
910
|
let keepConnection = true;
|
|
971
911
|
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
972
|
-
const
|
|
973
|
-
|
|
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
|
+
}
|
|
974
935
|
try {
|
|
975
936
|
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
976
937
|
observePromptEgress?.(requestBody, {
|
|
@@ -987,26 +948,8 @@ async function processWebSocketStream(state, authority, body, output, stream, mo
|
|
|
987
948
|
type: "response.create",
|
|
988
949
|
...requestBody
|
|
989
950
|
}));
|
|
990
|
-
onRequestSent?.();
|
|
991
|
-
const terminal = await
|
|
992
|
-
options,
|
|
993
|
-
cancelStream: () => {
|
|
994
|
-
keepConnection = false;
|
|
995
|
-
closeWebSocketSilently(socket);
|
|
996
|
-
}
|
|
997
|
-
}), onStart), output, stream, model, {
|
|
998
|
-
serviceTier: options?.serviceTier,
|
|
999
|
-
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
1000
|
-
abortFirstEventStream,
|
|
1001
|
-
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
1002
|
-
signal: activitySignal ?? options?.signal,
|
|
1003
|
-
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
1004
|
-
sessionId: options?.sessionId,
|
|
1005
|
-
authProfileId: options?.authProfileId
|
|
1006
|
-
}),
|
|
1007
|
-
resolveServiceTier: resolveCodexServiceTier,
|
|
1008
|
-
applyServiceTierPricing: (usage, serviceTier) => applyResponsesServiceTierPricing(usage, serviceTier, model)
|
|
1009
|
-
});
|
|
951
|
+
onRequestSent?.(requestBody);
|
|
952
|
+
const terminal = await processStream(acceptedEvents(), options, activitySignal);
|
|
1010
953
|
if (options?.signal?.aborted) keepConnection = false;
|
|
1011
954
|
else if (useCachedContext && entry && output.responseId) {
|
|
1012
955
|
const responseItems = convertProviderResponsesMessages(model, { messages: [output] }, CODEX_TOOL_CALL_PROVIDERS, {
|
|
@@ -1016,7 +959,7 @@ async function processWebSocketStream(state, authority, body, output, stream, mo
|
|
|
1016
959
|
authProfileId: options?.authProfileId
|
|
1017
960
|
}).filter((item) => item.type !== "function_call_output");
|
|
1018
961
|
entry.continuation = {
|
|
1019
|
-
lastRequestBody:
|
|
962
|
+
lastRequestBody: body,
|
|
1020
963
|
lastResponseId: output.responseId,
|
|
1021
964
|
lastResponseItems: responseItems
|
|
1022
965
|
};
|
|
@@ -1034,9 +977,7 @@ async function readChatGptResponsesErrorTextLimited(response, signal) {
|
|
|
1034
977
|
const reader = response.body?.getReader();
|
|
1035
978
|
if (!reader) return "";
|
|
1036
979
|
const decoder = new TextDecoder();
|
|
1037
|
-
let total = 0;
|
|
1038
980
|
let text = "";
|
|
1039
|
-
let reachedLimit = false;
|
|
1040
981
|
let completed = false;
|
|
1041
982
|
let cancelPromise;
|
|
1042
983
|
const cancel = () => {
|
|
@@ -1049,27 +990,17 @@ async function readChatGptResponsesErrorTextLimited(response, signal) {
|
|
|
1049
990
|
if (signal?.aborted) onAbort();
|
|
1050
991
|
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
1051
992
|
try {
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
}
|
|
1064
|
-
const chunk = value.byteLength > remaining ? value.subarray(0, remaining) : value;
|
|
1065
|
-
total += chunk.byteLength;
|
|
1066
|
-
text += decoder.decode(chunk, { stream: true });
|
|
1067
|
-
if (total >= OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES) {
|
|
1068
|
-
reachedLimit = true;
|
|
1069
|
-
break;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
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();
|
|
1073
1004
|
} finally {
|
|
1074
1005
|
signal?.removeEventListener("abort", onAbort);
|
|
1075
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
|