@openclaw/ai 2026.9.2 → 2026.9.4
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-C4Qu4H0Z.mjs +377 -0
- package/dist/{anthropic-payload-policy-d46X2pR0.d.mts → anthropic-payload-policy-BZ8umAbk.d.mts} +16 -6
- package/dist/{anthropic-compaction-replay-DB2FGLQc.mjs → anthropic-stream-reducer-CILWF7JD.mjs} +931 -184
- package/dist/{api-registry-DWtPjzyn.d.mts → api-registry-ByUwIR0e.d.mts} +2 -2
- package/dist/assistant-output-tLt4H-iQ.mjs +16 -0
- package/dist/assistant-text-phase-C20rxWwP.mjs +55 -0
- package/dist/{azure-openai-responses-C5bZRfAP.mjs → azure-openai-responses-BAlqlKKc.mjs} +5 -5
- package/dist/{base64-CEFBpSkN.mjs → base64-D-su8YVo.mjs} +1 -27
- package/dist/{diagnostics-DfFyKeX_.mjs → diagnostics-QuErwCIl.mjs} +96 -21
- package/dist/diagnostics.d.mts +3 -1
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-BhT5T1Ay.d.mts → event-stream-Bt5Y4Pav.d.mts} +11 -3
- package/dist/event-stream-C3WGFsum.d.mts +1 -0
- package/dist/{event-stream-BgDvQeum.mjs → event-stream-D8PARQfL.mjs} +45 -1
- 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-4qeuE8iX.mjs → google-DPBAOaOW.mjs} +10 -10
- package/dist/google-messages-6JkpHrhJ.mjs +448 -0
- package/dist/google-shared-BvBeW9aq.mjs +185 -0
- package/dist/{google-vertex-O9BcnB6X.mjs → google-vertex-k-TMCAYD.mjs} +7 -6
- package/dist/{host-DjzGmdZ2.d.mts → host-4atIX-2V.d.mts} +5 -3
- package/dist/{host-CEvLw30U.mjs → host-B8YfDGd4.mjs} +181 -41
- package/dist/host-policy-Zcg_cNz8.mjs +37 -0
- package/dist/{index-FnHM2FcI.d.mts → index-DdD3qerf.d.mts} +4 -4
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -6
- package/dist/internal/anthropic.d.mts +7 -7
- package/dist/internal/anthropic.mjs +4 -4
- 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 +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +3 -2
- package/dist/internal/openai.d.mts +8 -103
- package/dist/internal/openai.mjs +9 -10
- package/dist/internal/retry-after.d.mts +2 -4
- package/dist/internal/retry-after.mjs +57 -8
- package/dist/internal/runtime.d.mts +43 -7
- package/dist/internal/runtime.mjs +6 -7
- package/dist/internal/shared.d.mts +43 -3
- package/dist/internal/shared.mjs +5 -4
- package/dist/internal/tool-schema.d.mts +63 -0
- package/dist/internal/tool-schema.mjs +3 -0
- package/dist/{mistral-Tb6oalqH.mjs → mistral-CxUZ1jUb.mjs} +10 -37
- package/dist/model-transport-url-DKocrEsb.d.mts +28 -0
- package/dist/{openai-chatgpt-responses-yUXjPNfu.mjs → openai-chatgpt-responses-CgO6kZfo.mjs} +50 -41
- package/dist/{openai-completions-compat-CpjYUArk.d.mts → openai-completions-compat-eHgh5UPE.d.mts} +26 -4
- package/dist/{openai-completions-stream-BsrBe3Gg.mjs → openai-completions-stream-Da2vvl-S.mjs} +654 -453
- package/dist/openai-completions-yJuk7eis.mjs +187 -0
- package/dist/openai-prompt-cache-B4eYo2-I.d.mts +16 -0
- package/dist/openai-prompt-cache-Bds-n_9Q.mjs +220 -0
- package/dist/openai-provider-client-S2gCrM2Z.mjs +24 -0
- package/dist/{openai-responses-CCL41ALM.mjs → openai-responses-DaYwH05E.mjs} +14 -29
- package/dist/{openai-responses-compaction-window-BMVHFOtq.mjs → openai-responses-compaction-window-CIhBAkkq.mjs} +6 -246
- package/dist/{openai-responses-contracts-rF5DDRNS.d.mts → openai-responses-contracts-BjBAqAg_.d.mts} +5 -38
- package/dist/openai-responses-contracts-DDOHA62Y.mjs +245 -0
- package/dist/{openai-responses-prompt-observer-internal-D0bhBfgL.mjs → openai-responses-prompt-observer-internal-f8J7wpsk.mjs} +3 -3
- package/dist/{openai-responses-shared-Bmma_3Qc.mjs → openai-responses-shared-B8RdBPCv.mjs} +47 -118
- package/dist/openai-tool-projection-793cE3QX.d.mts +37 -0
- package/dist/{openai-tool-schema-_pTAJqKF.mjs → openai-tool-schema-CzjyYXun.mjs} +38 -556
- package/dist/openai-tool-schema-ynZBgqW-.d.mts +38 -0
- package/dist/openai-transport-params-9aPuV5YY.mjs +675 -0
- package/dist/positive-integer-41zhOdcV.mjs +8 -0
- package/dist/{provider-error-9TraxGvt.mjs → provider-error-BA-v_tKd.mjs} +70 -11
- package/dist/{provider-options-Bcc_p-TU.d.mts → provider-options-Ceqv1OKk.d.mts} +4 -39
- package/dist/{provider-replay-context-BuSUaAk5.mjs → provider-replay-context-CJ_YvcEW.mjs} +1 -1
- package/dist/{provider-transcript-transform-BaMbI1hr.mjs → provider-transcript-transform-V5YzU9zh.mjs} +1 -1
- package/dist/provider-transport-turn-state-D5EXOFL2.mjs +42 -0
- package/dist/provider-types-CVjKjsuq.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-DLCNXki6.mjs → reasoning-tag-text-partitioner-BcR5pztD.mjs} +19 -19
- package/dist/record-coerce-DwRYMj3t.mjs +32 -0
- package/dist/retry-after-CdCURCVg.d.mts +15 -0
- package/dist/session-affinity-Bcunsn4I.mjs +23 -0
- package/dist/{simple-options-BjHCCh4v.mjs → simple-options-BQbb4yQL.mjs} +24 -5
- package/dist/src-DDmEryvj.mjs +2 -0
- 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-mJhXDcyz.mjs → tool-schema-json-projection-ClptDdAO.mjs} +2 -38
- package/dist/{transport-stream-shared-xnaqxmbP.d.mts → transport-stream-shared-DNvmoWnv.d.mts} +20 -36
- package/dist/{transport-stream-shared-CZqMhfIw.mjs → transport-stream-shared-zHll9BxO.mjs} +225 -13
- package/dist/transport-utils-zrYjICLZ.mjs +118 -0
- package/dist/transports.d.mts +137 -193
- package/dist/transports.mjs +204 -1334
- package/dist/types-DlfwzH3T.d.mts +1 -0
- package/dist/types-LFWwv0cF.mjs +8 -0
- package/dist/{types-CJ1-Ht7A.d.mts → types-Ntv5z2g2.d.mts} +74 -57
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +6 -5
- package/dist/{src-2qBGKg8O.mjs → usage-cost-BNWbbXav.mjs} +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-AKZBDGQd.d.mts → validation-B0t_G2H6.d.mts} +1 -1
- package/dist/{validation-CJZtym2g.mjs → validation-BDzVDnTs.mjs} +9 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +13 -3
- package/dist/anthropic-BDdqdVLK.mjs +0 -886
- package/dist/event-stream-zctLx0yr.d.mts +0 -1
- package/dist/google-shared-CWeG8RIl.mjs +0 -636
- package/dist/google-thinking-level-C-V3tecN.mjs +0 -9
- package/dist/hash-CHgqbJmD.mjs +0 -16
- package/dist/json-parse-BuAJEbdW.mjs +0 -146
- package/dist/openai-completions-BIUV3RDT.mjs +0 -403
- package/dist/openai-prompt-cache-CGnVB74a.mjs +0 -21
- package/dist/openai-prompt-cache-CNoIfHYC.d.mts +0 -16
- package/dist/sanitize-unicode-D6xUvZaS.mjs +0 -83
- package/dist/transport-utils-7il795_9.mjs +0 -138
- package/dist/types-3Lnm-QSJ.d.mts +0 -1
- package/dist/types-BDdaOVi2.mjs +0 -6
- package/dist/utf16-slice-qz3nsy87.mjs +0 -84
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-BjHCCh4v.mjs";
|
|
1
|
+
import { r as appendAssistantThinking, t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
+
import { M as clampThinkingLevel, _ as isImageWithMediaPayload, d as describeToolResultMediaPlaceholder, h as formatToolResultText, j as calculateCost, m as extractToolResultText, n as getAiTransportHost, v as sanitizeSurrogates } from "./host-B8YfDGd4.mjs";
|
|
3
|
+
import { m as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, v as sortPromptCacheToolsByName } from "./simple-options-BQbb4yQL.mjs";
|
|
5
4
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
5
|
+
import { E as parseStreamingJson, c as finalizeTerminalToolCallArguments, k as shortHash, n as assignTransportErrorDetails, p as notifyProviderHttpResponse, v as transportAbortError, w as createToolArgumentPreviewSchedule } from "./transport-stream-shared-zHll9BxO.mjs";
|
|
8
6
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
9
|
-
import { t as
|
|
10
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
7
|
+
import { t as createAssistantOutput } from "./assistant-output-tLt4H-iQ.mjs";
|
|
8
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-V5YzU9zh.mjs";
|
|
11
9
|
import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
|
|
12
10
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
13
11
|
import { randomUUID } from "node:crypto";
|
|
@@ -62,7 +60,7 @@ function createBoundedMistralFetcher(maxBytes = MISTRAL_STREAM_BODY_MAX_BYTES, u
|
|
|
62
60
|
const streamMistral = (model, context, options) => {
|
|
63
61
|
const stream = new AssistantMessageEventStream();
|
|
64
62
|
(async () => {
|
|
65
|
-
const output =
|
|
63
|
+
const output = createAssistantOutput(model);
|
|
66
64
|
try {
|
|
67
65
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
68
66
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
@@ -151,31 +149,6 @@ const streamSimpleMistral = (model, context, options) => {
|
|
|
151
149
|
reasoningEffort: shouldUseReasoning && usesReasoningEffort(model) ? mapReasoningEffort(model, reasoning) : void 0
|
|
152
150
|
});
|
|
153
151
|
};
|
|
154
|
-
function createOutput(model) {
|
|
155
|
-
return {
|
|
156
|
-
role: "assistant",
|
|
157
|
-
content: [],
|
|
158
|
-
api: model.api,
|
|
159
|
-
provider: model.provider,
|
|
160
|
-
model: model.id,
|
|
161
|
-
usage: {
|
|
162
|
-
input: 0,
|
|
163
|
-
output: 0,
|
|
164
|
-
cacheRead: 0,
|
|
165
|
-
cacheWrite: 0,
|
|
166
|
-
totalTokens: 0,
|
|
167
|
-
cost: {
|
|
168
|
-
input: 0,
|
|
169
|
-
output: 0,
|
|
170
|
-
cacheRead: 0,
|
|
171
|
-
cacheWrite: 0,
|
|
172
|
-
total: 0
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
stopReason: "stop",
|
|
176
|
-
timestamp: Date.now()
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
152
|
function createMistralToolCallIdNormalizer() {
|
|
180
153
|
const idMap = /* @__PURE__ */ new Map();
|
|
181
154
|
const reverseMap = /* @__PURE__ */ new Map();
|
|
@@ -271,7 +244,6 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
271
244
|
const toolCallIndex = params.index;
|
|
272
245
|
const idCandidates = explicitId ? findIdentityCandidates((identity) => identity.explicitIds.has(explicitId), params.usedContentIndexes) : /* @__PURE__ */ new Set();
|
|
273
246
|
const nameCandidates = functionName ? findIdentityCandidates((identity) => identity.functionNames.has(functionName), params.usedContentIndexes) : /* @__PURE__ */ new Set();
|
|
274
|
-
const indexCandidates = toolCallIndex === void 0 ? /* @__PURE__ */ new Set() : findIdentityCandidates((identity) => identity.indexes.has(toolCallIndex), params.usedContentIndexes);
|
|
275
247
|
if (idCandidates.size > 0) {
|
|
276
248
|
let candidates = idCandidates;
|
|
277
249
|
if (nameCandidates.size > 0) candidates = intersectCandidates(candidates, nameCandidates);
|
|
@@ -292,6 +264,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
292
264
|
if (indexCompatibleCandidates.size === 0) return;
|
|
293
265
|
return requireSingleCandidate(indexCompatibleCandidates);
|
|
294
266
|
}
|
|
267
|
+
const indexCandidates = toolCallIndex === void 0 ? /* @__PURE__ */ new Set() : findIdentityCandidates((identity) => identity.indexes.has(toolCallIndex), params.usedContentIndexes);
|
|
295
268
|
if (functionName) {
|
|
296
269
|
const namelessCandidates = new Set([...indexCandidates].filter((contentIndex) => {
|
|
297
270
|
const identity = toolBlockIdentities.get(contentIndex);
|
|
@@ -375,7 +348,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
375
348
|
continue;
|
|
376
349
|
}
|
|
377
350
|
if (item.type === "thinking") {
|
|
378
|
-
const deltaText = item.thinking.map((part) => "text" in part ? part.text : "").
|
|
351
|
+
const deltaText = item.thinking.map((part) => "text" in part ? part.text : "").join("");
|
|
379
352
|
const thinkingDelta = sanitizeSurrogates(deltaText);
|
|
380
353
|
if (!thinkingDelta) continue;
|
|
381
354
|
if (!currentBlock || currentBlock.type !== "thinking") {
|
|
@@ -391,7 +364,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
391
364
|
partial: output
|
|
392
365
|
});
|
|
393
366
|
}
|
|
394
|
-
currentBlock
|
|
367
|
+
appendAssistantThinking(currentBlock, thinkingDelta);
|
|
395
368
|
stream.push({
|
|
396
369
|
type: "thinking_delta",
|
|
397
370
|
contentIndex: blockIndex(),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region packages/ai/src/transports/model-transport-debug.d.ts
|
|
2
|
+
type SubsystemLogger = {
|
|
3
|
+
info(message: string): void;
|
|
4
|
+
debug(message: string): void;
|
|
5
|
+
};
|
|
6
|
+
type ModelTransportDebugEnv = NodeJS.ProcessEnv;
|
|
7
|
+
/** Payload debug detail levels accepted by `OPENCLAW_DEBUG_MODEL_PAYLOAD`. */
|
|
8
|
+
type ModelPayloadDebugMode = "off" | "summary" | "tools" | "full-redacted";
|
|
9
|
+
/** SSE debug detail levels accepted by `OPENCLAW_DEBUG_SSE`. */
|
|
10
|
+
type ModelSseDebugMode = "off" | "events" | "peek";
|
|
11
|
+
/** Resolves model payload debug verbosity from `OPENCLAW_DEBUG_MODEL_PAYLOAD`. */
|
|
12
|
+
declare function resolveModelPayloadDebugMode(env?: ModelTransportDebugEnv): ModelPayloadDebugMode;
|
|
13
|
+
/** Resolves SSE stream debug verbosity from `OPENCLAW_DEBUG_SSE`. */
|
|
14
|
+
declare function resolveModelSseDebugMode(env?: ModelTransportDebugEnv): ModelSseDebugMode;
|
|
15
|
+
/** Emits model-fetch metadata at info level by default; other diagnostics require debug env. */
|
|
16
|
+
declare function emitModelTransportDebug(log: SubsystemLogger, message: string): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region packages/ai/src/transports/model-transport-url.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* Debug formatting helpers for model transport endpoints.
|
|
21
|
+
* Keeps logs useful without exposing credentials, request params, or fragments.
|
|
22
|
+
*/
|
|
23
|
+
/** Return a sanitized URL suitable for logs and diagnostics. */
|
|
24
|
+
declare function formatModelTransportDebugUrl(rawUrl: string): string;
|
|
25
|
+
/** Format a configured base URL for debug output, or the implicit default. */
|
|
26
|
+
declare function formatModelTransportDebugBaseUrl(rawUrl: string | undefined): string;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { resolveModelSseDebugMode as a, resolveModelPayloadDebugMode as i, formatModelTransportDebugUrl as n, emitModelTransportDebug as r, formatModelTransportDebugBaseUrl as t };
|
package/dist/{openai-chatgpt-responses-yUXjPNfu.mjs → openai-chatgpt-responses-CgO6kZfo.mjs}
RENAMED
|
@@ -1,20 +1,21 @@
|
|
|
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-B8YfDGd4.mjs";
|
|
4
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-Bds-n_9Q.mjs";
|
|
5
|
+
import { l as extractErrorCodeOrErrno, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, u as toErrorObject } from "./diagnostics-QuErwCIl.mjs";
|
|
6
|
+
import { s as resolveTimerTimeoutMs } from "./base64-D-su8YVo.mjs";
|
|
7
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-zrYjICLZ.mjs";
|
|
8
|
+
import { parseRetryAfterHeadersSeconds } from "./internal/retry-after.mjs";
|
|
9
|
+
import { m as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-BQbb4yQL.mjs";
|
|
10
|
+
import { _ as createOpenAIProviderAcceptanceHook, v as createOpenAIResponseHook } from "./openai-transport-params-9aPuV5YY.mjs";
|
|
9
11
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { C as
|
|
13
|
-
import { a as
|
|
14
|
-
import { S as responsesPromptObserver, j as supportsOpenAITemperature } from "./openai-responses-compaction-window-BMVHFOtq.mjs";
|
|
12
|
+
import { O as headersToRecord, b as withProviderResponseHook, m as notifyProviderStreamOpened, n as assignTransportErrorDetails, v as transportAbortError } from "./transport-stream-shared-zHll9BxO.mjs";
|
|
13
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-2hfrquuz.mjs";
|
|
14
|
+
import { C as supportsOpenAITemperature, m as responsesPromptObserver } from "./openai-responses-contracts-DDOHA62Y.mjs";
|
|
15
|
+
import { F as resolveNextResponsesEncryptedContentAttempt, H as buildOpenAIResponsesReasoningReplayMetadata, K as suppressOpenAIResponsesCompaction, N as isInvalidEncryptedContentError, a as resolveResponsesReasoningEffort, h as ResponsesStreamFailure, i as createResponsesAssistantOutput, j as commitResponsesEncryptedContentAttempt, l as convertResponsesToolPayload, n as applyResponsesServiceTierPricing, o as resolveResponsesRequestReasoningEffort, r as convertResponsesMessages, u as processResponsesStream } from "./openai-responses-shared-B8RdBPCv.mjs";
|
|
15
16
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
16
17
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
17
|
-
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
18
|
+
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-f8J7wpsk.mjs";
|
|
18
19
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
19
20
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
20
21
|
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
@@ -43,9 +44,9 @@ async function* parseOpenAIChatGptResponsesSse(response) {
|
|
|
43
44
|
while (true) {
|
|
44
45
|
const searchable = !done && buffer.endsWith("\r") && !buffer.endsWith("\r\r") && !buffer.endsWith("\n\r") ? buffer.slice(0, -1) : buffer;
|
|
45
46
|
const boundary = /(?:\r\n|\r(?!\n)|\n)(?:\r\n|\r(?!\n)|\n)/.exec(searchable);
|
|
46
|
-
if (!boundary) break;
|
|
47
|
-
const chunk = buffer.slice(0, boundary.index);
|
|
48
|
-
buffer = buffer.slice(boundary.index + boundary[0].length);
|
|
47
|
+
if (!boundary && (!done || buffer.length === 0)) break;
|
|
48
|
+
const chunk = boundary ? buffer.slice(0, boundary.index) : buffer;
|
|
49
|
+
buffer = boundary ? buffer.slice(boundary.index + boundary[0].length) : "";
|
|
49
50
|
const dataLines = chunk.split(/\r\n|\r|\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim());
|
|
50
51
|
if (dataLines.length > 0) {
|
|
51
52
|
const data = dataLines.join("\n").trim();
|
|
@@ -83,6 +84,17 @@ const os = loadNodeOs();
|
|
|
83
84
|
const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
84
85
|
const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
85
86
|
const CODEX_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
|
|
87
|
+
const WEBSOCKET_TRANSPORT_ERROR_CODE = "ERR_WEBSOCKET_TRANSPORT";
|
|
88
|
+
const RETRYABLE_WEBSOCKET_CLOSE_CODES = /* @__PURE__ */ new Set([
|
|
89
|
+
1001,
|
|
90
|
+
1005,
|
|
91
|
+
1006,
|
|
92
|
+
1011,
|
|
93
|
+
1012,
|
|
94
|
+
1013,
|
|
95
|
+
1014,
|
|
96
|
+
1015
|
|
97
|
+
]);
|
|
86
98
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
87
99
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
88
100
|
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
@@ -184,7 +196,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
184
196
|
commitSemanticAttempt(activeAttempt);
|
|
185
197
|
}, requestOptions, firstEventAbort.abort, observePromptEgress, activeAttempt.kind, () => {
|
|
186
198
|
websocketRequestSent = true;
|
|
187
|
-
});
|
|
199
|
+
}, options?.signal);
|
|
188
200
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
189
201
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new CodexApiError(output.errorMessage ?? "An unknown error occurred");
|
|
190
202
|
stream.push({
|
|
@@ -367,9 +379,9 @@ function buildRequestBody(model, context, options, replayMode = "checkpoint") {
|
|
|
367
379
|
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) body.temperature = options.temperature;
|
|
368
380
|
if (options?.serviceTier !== void 0) body.service_tier = options.serviceTier;
|
|
369
381
|
if (context.tools) {
|
|
370
|
-
const
|
|
371
|
-
if (
|
|
372
|
-
body.tools =
|
|
382
|
+
const tools = convertResponsesToolPayload(context.tools, { strict: null });
|
|
383
|
+
if (tools.length > 0) {
|
|
384
|
+
body.tools = tools;
|
|
373
385
|
body.tool_choice = "auto";
|
|
374
386
|
body.parallel_tool_calls = true;
|
|
375
387
|
}
|
|
@@ -503,15 +515,9 @@ async function getWebSocketConstructor() {
|
|
|
503
515
|
if (typeof ctor !== "function") return null;
|
|
504
516
|
return ctor;
|
|
505
517
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
this.name = "WebSocketCloseError";
|
|
510
|
-
this.code = options?.code;
|
|
511
|
-
this.reason = options?.reason;
|
|
512
|
-
this.wasClean = options?.wasClean;
|
|
513
|
-
}
|
|
514
|
-
};
|
|
518
|
+
function createWebSocketTransportError(message, cause) {
|
|
519
|
+
return Object.assign(new Error(message, cause ? { cause } : void 0), { code: extractErrorCodeOrErrno(cause) ?? WEBSOCKET_TRANSPORT_ERROR_CODE });
|
|
520
|
+
}
|
|
515
521
|
function getWebSocketReadyState(socket) {
|
|
516
522
|
const readyState = socket.readyState;
|
|
517
523
|
return typeof readyState === "number" ? readyState : void 0;
|
|
@@ -684,15 +690,15 @@ async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
|
684
690
|
function extractWebSocketError(event) {
|
|
685
691
|
if (event && typeof event === "object") {
|
|
686
692
|
const message = "message" in event ? event.message : void 0;
|
|
687
|
-
if (typeof message === "string" && message.length > 0) return new Error(message);
|
|
688
693
|
const nestedError = "error" in event ? event.error : void 0;
|
|
689
|
-
|
|
690
|
-
if (nestedError
|
|
691
|
-
const
|
|
692
|
-
|
|
694
|
+
const eventMessage = typeof message === "string" && message.length > 0 ? message : void 0;
|
|
695
|
+
if (nestedError !== void 0) {
|
|
696
|
+
const cause = toErrorObject(nestedError, eventMessage ?? "WebSocket error");
|
|
697
|
+
return createWebSocketTransportError(eventMessage ?? (cause.message || "WebSocket error"), cause);
|
|
693
698
|
}
|
|
699
|
+
if (eventMessage) return createWebSocketTransportError(eventMessage);
|
|
694
700
|
}
|
|
695
|
-
return
|
|
701
|
+
return createWebSocketTransportError("WebSocket error");
|
|
696
702
|
}
|
|
697
703
|
function extractWebSocketCloseError(event) {
|
|
698
704
|
if (event && typeof event === "object") {
|
|
@@ -702,13 +708,16 @@ function extractWebSocketCloseError(event) {
|
|
|
702
708
|
const codeText = typeof code === "number" ? ` ${code}` : "";
|
|
703
709
|
let reasonText = typeof reason === "string" && reason.length > 0 ? ` ${reason}` : "";
|
|
704
710
|
if (!reasonText && code === WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE) reasonText = " message too big";
|
|
705
|
-
|
|
706
|
-
|
|
711
|
+
const message = `WebSocket closed${codeText}${reasonText}`;
|
|
712
|
+
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 });
|
|
713
|
+
return Object.assign(error, {
|
|
714
|
+
name: "WebSocketCloseError",
|
|
715
|
+
closeCode: typeof code === "number" ? code : void 0,
|
|
707
716
|
reason: typeof reason === "string" && reason.length > 0 ? reason : void 0,
|
|
708
717
|
wasClean: typeof wasClean === "boolean" ? wasClean : void 0
|
|
709
718
|
});
|
|
710
719
|
}
|
|
711
|
-
return
|
|
720
|
+
return createWebSocketTransportError("WebSocket closed");
|
|
712
721
|
}
|
|
713
722
|
async function* parseWebSocket(socket, signal) {
|
|
714
723
|
const queue = [];
|
|
@@ -842,7 +851,7 @@ async function* startWebSocketOutputOnFirstEvent(events, output, stream, onFirst
|
|
|
842
851
|
yield event;
|
|
843
852
|
}
|
|
844
853
|
}
|
|
845
|
-
async function processWebSocketStream(url, body, headers, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent) {
|
|
854
|
+
async function processWebSocketStream(url, body, headers, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent, activitySignal) {
|
|
846
855
|
const { socket, entry, release } = await acquireWebSocket(url, headers, options?.sessionId, options?.signal);
|
|
847
856
|
let keepConnection = true;
|
|
848
857
|
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
@@ -870,7 +879,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
870
879
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
871
880
|
abortFirstEventStream,
|
|
872
881
|
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
873
|
-
signal: options?.signal,
|
|
882
|
+
signal: activitySignal ?? options?.signal,
|
|
874
883
|
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
875
884
|
sessionId: options?.sessionId,
|
|
876
885
|
authProfileId: options?.authProfileId
|
|
@@ -966,7 +975,7 @@ function parseErrorResponse(raw, response) {
|
|
|
966
975
|
message = err.message || friendlyMessage || message;
|
|
967
976
|
}
|
|
968
977
|
} catch {}
|
|
969
|
-
const retryAfterSeconds =
|
|
978
|
+
const retryAfterSeconds = parseRetryAfterHeadersSeconds(response.headers);
|
|
970
979
|
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
971
980
|
return new CodexApiError(`${friendlyMessage || message}${retryAfterSuffix}`, {
|
|
972
981
|
code,
|
package/dist/{openai-completions-compat-CpjYUArk.d.mts → openai-completions-compat-eHgh5UPE.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import {
|
|
3
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-
|
|
1
|
+
import "./index-DdD3qerf.mjs";
|
|
2
|
+
import { M as OpenAICompletionsCompat, O as Model } from "./types-Ntv5z2g2.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-4atIX-2V.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 };
|