@openclaw/ai 2026.9.3 → 2026.9.5
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 +1 -1
- package/dist/{anthropic-CZy5U0NY.mjs → anthropic-COtDvgtt.mjs} +16 -16
- package/dist/{anthropic-payload-policy-wuRCb6MH.d.mts → anthropic-payload-policy-5Erq1Nzy.d.mts} +3 -3
- package/dist/{anthropic-stream-reducer-B_yo_7pf.mjs → anthropic-stream-reducer-BvdYYWL8.mjs} +56 -47
- package/dist/{api-registry-CB1-1oQ2.d.mts → api-registry-Ba2Cv-ut.d.mts} +2 -2
- package/dist/{assistant-output-iqnlJCV2.mjs → assistant-output-BsEkB-vU.mjs} +1 -1
- package/dist/{azure-openai-responses-Crpa40QR.mjs → azure-openai-responses-YrgnD583.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-BQOzsvUH.mjs} +4 -4
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-dV98PqIy.mjs → diagnostics-Dm4bisWG.mjs} +89 -2
- package/dist/diagnostics.d.mts +4 -23
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-C1Z2piyk.d.mts → event-stream-CCoa-qSI.d.mts} +1 -1
- package/dist/event-stream-DmSCpi1T.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-BDPriaVe.mjs → google-BuhpRO9r.mjs} +7 -10
- package/dist/{google-messages-CVn9eFpF.mjs → google-messages-CyWnYlh0.mjs} +3 -4
- package/dist/{google-shared-BedY23XS.mjs → google-shared-BT5ZeNer.mjs} +13 -13
- package/dist/{google-vertex-DMz8XQCn.mjs → google-vertex-C7EplRvt.mjs} +5 -8
- package/dist/{host-CWuF-sS3.mjs → host-B4MeUNBc.mjs} +145 -12
- package/dist/{host-DK3wmS3e.d.mts → host-FZ1RA_qD.d.mts} +7 -3
- package/dist/{host-policy-CAopLRKA.mjs → host-policy-DUnXSx0I.mjs} +1 -1
- package/dist/{index-CQ6LTHw8.d.mts → index-DaF2QbwS.d.mts} +5 -10
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +6 -7
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-completions-compat.d.mts +2 -0
- package/dist/internal/openai-completions-compat.mjs +2 -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 +10 -53
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/runtime.d.mts +43 -10
- package/dist/internal/runtime.mjs +5 -11
- package/dist/internal/shared.d.mts +35 -5
- package/dist/internal/shared.mjs +4 -4
- package/dist/internal/tool-schema.d.mts +3 -3
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral--m-Jm6VZ.mjs → mistral-moA-mbwl.mjs} +9 -16
- package/dist/{openai-chatgpt-responses-nDZccFW-.mjs → openai-chatgpt-responses-DWID3EFO.mjs} +76 -33
- package/dist/{openai-completions-KuoZyx0d.mjs → openai-completions-DJ1Vm-CD.mjs} +12 -13
- package/dist/{openai-prompt-cache-BI0rkM-5.mjs → openai-completions-compat-CkwdxTZx.mjs} +5 -50
- package/dist/{openai-completions-compat-CXn3T1we.d.mts → openai-completions-compat-JE7gqxb9.d.mts} +4 -4
- package/dist/{openai-completions-stream-BQk3SkLD.mjs → openai-completions-stream-Bu98b0Hv.mjs} +128 -99
- package/dist/openai-prompt-cache-1wfaIszn.mjs +46 -0
- package/dist/{openai-prompt-cache-rrutvqxq.d.mts → openai-prompt-cache-CJ_xEevu.d.mts} +2 -2
- package/dist/{openai-provider-client-ha_WxTyj.mjs → openai-provider-client-DPo0Hmak.mjs} +2 -2
- package/dist/{openai-reasoning-effort-BK7FbcLT.mjs → openai-reasoning-effort-NlFZmfEu.mjs} +87 -19
- package/dist/{openai-responses-D99dOzKI.mjs → openai-responses-BejZzQCP.mjs} +9 -13
- package/dist/{openai-responses-compaction-window-D5jbzCi3.mjs → openai-responses-compaction-window-D6P5oZP5.mjs} +21 -140
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-contracts-B55afwRo.d.mts → openai-responses-contracts-Dflvrfa8.d.mts} +10 -39
- package/dist/{openai-responses-payload-policy-rLRPsSmB.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +5 -3
- package/dist/openai-responses-prompt-observer-internal-C15_-OwV.mjs +195 -0
- package/dist/{openai-responses-shared-ZyQEzS5i.mjs → openai-responses-shared-CwsziD_m.mjs} +390 -183
- package/dist/openai-responses-terminal-usage-Dl3J6zrf.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-BO8rwyAD.mjs} +92 -68
- package/dist/{openai-transport-params-DNasp2fU.mjs → openai-transport-params-DQeuAvBl.mjs} +162 -51
- package/dist/positive-integer-DtjCkbue.mjs +8 -0
- package/dist/{provider-error-C6TbKiey.mjs → provider-error-DDqw9Qda.mjs} +140 -36
- package/dist/{provider-options-BXr9Ec83.d.mts → provider-options-DprLsWh9.d.mts} +9 -6
- package/dist/{provider-replay-context-BuSUaAk5.mjs → provider-replay-context-CnUSOwhr.mjs} +1 -1
- package/dist/{provider-transcript-transform-pPmUIwKt.mjs → provider-transcript-transform-BsRAhuWJ.mjs} +1 -1
- package/dist/provider-transport-turn-state-CkGToCD2.mjs +42 -0
- package/dist/{provider-types-CAV0Og3m.d.mts → provider-types-CAKRC7N5.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -7
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-BQBi4B9d.mjs → reasoning-tag-text-partitioner-Dy9IO8Dc.mjs} +15 -14
- package/dist/{session-affinity-CCH7eYdB.mjs → session-affinity-Bcunsn4I.mjs} +5 -2
- package/dist/{simple-options-tcKOqnpF.mjs → simple-options-C6cFWj_f.mjs} +26 -5
- package/dist/{src-B2Q_6G8V.mjs → src-DeKjbE8I.mjs} +3 -6
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-C9ZadkJW.mjs} +1 -1
- package/dist/{string-normalization-CmLIasuf.mjs → string-normalization-J9ZiLfGO.mjs} +13 -1
- package/dist/tool-schema-json-projection-CD9c_fK8.mjs +134 -0
- package/dist/{transport-stream-shared-DOxpGJ-H.d.mts → transport-stream-shared-BbUkFaHi.d.mts} +20 -36
- package/dist/{transport-stream-shared-Cu3ZPhNW.mjs → transport-stream-shared-D-6FQSHm.mjs} +223 -11
- package/dist/{transport-utils-CCooe-cr.mjs → transport-utils-1cyq5Y7x.mjs} +4 -7
- package/dist/transports.d.mts +51 -165
- package/dist/transports.mjs +172 -507
- package/dist/{types-Dy1q0CSu.d.mts → types-4_uVs5WH.d.mts} +49 -3
- package/dist/types-DkJfb4W3.d.mts +1 -0
- package/dist/types-LFWwv0cF.mjs +8 -0
- package/dist/types.d.mts +6 -7
- package/dist/types.mjs +4 -4
- package/dist/{validation-CaFUZN9B.d.mts → validation-Ctzu2DhF.d.mts} +1 -1
- package/dist/{validation-BDzVDnTs.mjs → validation-Dw7cb6BV.mjs} +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +10 -5
- package/dist/diagnostics-DnPnOui6.d.mts +0 -29
- package/dist/event-stream-I_GlBsuZ.d.mts +0 -1
- package/dist/hash-CHgqbJmD.mjs +0 -16
- package/dist/json-parse-Dw_hnxsA.mjs +0 -146
- package/dist/openai-responses-prompt-observer-internal-tApyTLVu.mjs +0 -32
- package/dist/sanitize-unicode-Bb-v9meu.mjs +0 -83
- package/dist/tool-schema-json-projection-ClptDdAO.mjs +0 -82
- package/dist/types-BADKjDBI.d.mts +0 -1
- package/dist/types-BDdaOVi2.mjs +0 -6
package/dist/{openai-chatgpt-responses-nDZccFW-.mjs → openai-chatgpt-responses-DWID3EFO.mjs}
RENAMED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { u as supportsOpenAITemperature } from "./openai-reasoning-effort-NlFZmfEu.mjs";
|
|
4
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-B4MeUNBc.mjs";
|
|
5
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-1wfaIszn.mjs";
|
|
6
|
+
import { m as toErrorObject, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, p as extractErrorCodeOrErrno } from "./diagnostics-Dm4bisWG.mjs";
|
|
7
|
+
import { s as resolveTimerTimeoutMs } from "./base64-BQOzsvUH.mjs";
|
|
8
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-1cyq5Y7x.mjs";
|
|
8
9
|
import { parseRetryAfterHeadersSeconds } from "./internal/retry-after.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { m as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-C6cFWj_f.mjs";
|
|
11
|
+
import { S as createResponseModelTracker, b as createOpenAIProviderAcceptanceHook, g as resolveOpenAISimpleReasoningEffort, h as resolveOpenAIRequestReasoning, x as createOpenAIResponseHook } from "./openai-transport-params-DQeuAvBl.mjs";
|
|
11
12
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
12
|
-
import {
|
|
13
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { J as buildOpenAIResponsesReasoningReplayMetadata, L as commitResponsesEncryptedContentAttempt, Q as suppressOpenAIResponsesCompaction, V as resolveNextResponsesEncryptedContentAttempt, a as resolveResponsesReasoningEffort, h as ResponsesStreamFailure, i as createResponsesAssistantOutput, l as convertResponsesToolPayload, n as applyResponsesServiceTierPricing, o as resolveResponsesRequestReasoningEffort, r as convertResponsesMessages, u as processResponsesStream, z as isInvalidEncryptedContentError } from "./openai-responses-shared-ZyQEzS5i.mjs";
|
|
13
|
+
import { O as headersToRecord, b as withProviderResponseHook, m as notifyProviderStreamOpened, n as assignTransportErrorDetails, v as transportAbortError } from "./transport-stream-shared-D-6FQSHm.mjs";
|
|
14
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-C9ZadkJW.mjs";
|
|
15
|
+
import { h as responsesPromptObserver } from "./openai-responses-contracts-DWrfMODE.mjs";
|
|
16
|
+
import { A as resolveNextResponsesEncryptedContentAttempt, E as commitResponsesEncryptedContentAttempt, K as buildOpenAIResponsesReasoningReplayMetadata, O as isInvalidEncryptedContentError, X as suppressOpenAIResponsesCompaction, c as processResponsesStream, i as createResponsesAssistantOutput, j as recordResponsesContextUsage, n as applyResponsesServiceTierPricing, o as convertResponsesToolPayload, r as convertResponsesMessages, u as ResponsesStreamFailure } from "./openai-responses-shared-CwsziD_m.mjs";
|
|
17
17
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
18
18
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
19
|
-
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
19
|
+
import { i as resolveOpenAIResponsesTextFormat, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-C15_-OwV.mjs";
|
|
20
20
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
21
21
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
22
22
|
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
@@ -45,9 +45,9 @@ async function* parseOpenAIChatGptResponsesSse(response) {
|
|
|
45
45
|
while (true) {
|
|
46
46
|
const searchable = !done && buffer.endsWith("\r") && !buffer.endsWith("\r\r") && !buffer.endsWith("\n\r") ? buffer.slice(0, -1) : buffer;
|
|
47
47
|
const boundary = /(?:\r\n|\r(?!\n)|\n)(?:\r\n|\r(?!\n)|\n)/.exec(searchable);
|
|
48
|
-
if (!boundary) break;
|
|
49
|
-
const chunk = buffer.slice(0, boundary.index);
|
|
50
|
-
buffer = buffer.slice(boundary.index + boundary[0].length);
|
|
48
|
+
if (!boundary && (!done || buffer.length === 0)) break;
|
|
49
|
+
const chunk = boundary ? buffer.slice(0, boundary.index) : buffer;
|
|
50
|
+
buffer = boundary ? buffer.slice(boundary.index + boundary[0].length) : "";
|
|
51
51
|
const dataLines = chunk.split(/\r\n|\r|\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim());
|
|
52
52
|
if (dataLines.length > 0) {
|
|
53
53
|
const data = dataLines.join("\n").trim();
|
|
@@ -191,7 +191,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
191
191
|
websocketStarted = false;
|
|
192
192
|
websocketRequestSent = false;
|
|
193
193
|
try {
|
|
194
|
-
await processWebSocketStream(resolveCodexWebSocketUrl(model.baseUrl), activeAttempt.request, websocketHeaders, output, stream, model, () => {
|
|
194
|
+
const terminal = await processWebSocketStream(resolveCodexWebSocketUrl(model.baseUrl), activeAttempt.request, websocketHeaders, output, stream, model, () => {
|
|
195
195
|
websocketStarted = true;
|
|
196
196
|
}, () => {
|
|
197
197
|
commitSemanticAttempt(activeAttempt);
|
|
@@ -200,6 +200,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
200
200
|
}, options?.signal);
|
|
201
201
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
202
202
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new CodexApiError(output.errorMessage ?? "An unknown error occurred");
|
|
203
|
+
if (terminal && activeAttempt.kind === "initial") recordResponsesContextUsage(output, model, options, activeAttempt.request, terminal.output, "provider");
|
|
203
204
|
stream.push({
|
|
204
205
|
type: "done",
|
|
205
206
|
reason: output.stopReason,
|
|
@@ -292,7 +293,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
292
293
|
semanticAttempt = nextSemanticAttempt;
|
|
293
294
|
}
|
|
294
295
|
const hookedResponseStream = withProviderResponseHook({
|
|
295
|
-
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response)),
|
|
296
|
+
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response), response.headers),
|
|
296
297
|
signal: firstEventAbort.signal,
|
|
297
298
|
abort: firstEventAbort.abort,
|
|
298
299
|
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
@@ -301,7 +302,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
301
302
|
partial: output
|
|
302
303
|
})
|
|
303
304
|
});
|
|
304
|
-
await processResponsesStream(hookedResponseStream, output, stream, model, {
|
|
305
|
+
const terminal = await processResponsesStream(hookedResponseStream, output, stream, model, {
|
|
305
306
|
serviceTier: options?.serviceTier,
|
|
306
307
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
307
308
|
abortFirstEventStream: firstEventAbort.abort,
|
|
@@ -316,6 +317,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
316
317
|
});
|
|
317
318
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
318
319
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
320
|
+
if (terminal && semanticAttempt.kind === "initial") recordResponsesContextUsage(output, model, options, semanticAttempt.request, terminal.output, "provider");
|
|
319
321
|
stream.push({
|
|
320
322
|
type: "done",
|
|
321
323
|
reason: output.stopReason,
|
|
@@ -326,6 +328,15 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
326
328
|
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
327
329
|
const normalizedError = requestTimedOut && requestTimeoutMs !== void 0 ? formatRequestTimeoutError(requestTimeoutMs, error) : error;
|
|
328
330
|
for (const block of output.content) delete block.partialJson;
|
|
331
|
+
const providerRefusal = readCodexProviderRefusal(normalizedError);
|
|
332
|
+
if (providerRefusal) appendAssistantMessageDiagnostic(output, {
|
|
333
|
+
type: "provider_refusal",
|
|
334
|
+
timestamp: Date.now(),
|
|
335
|
+
details: {
|
|
336
|
+
provider: "openai",
|
|
337
|
+
category: providerRefusal.category
|
|
338
|
+
}
|
|
339
|
+
});
|
|
329
340
|
const terminal = assignTransportErrorDetails(output, normalizedError, options?.signal);
|
|
330
341
|
getAiTransportHost().logWarn("openai-transport", "ChatGPT Responses stream terminated", {
|
|
331
342
|
provider: model.provider,
|
|
@@ -354,7 +365,7 @@ const streamSimpleOpenAICodexResponses = (model, context, options) => {
|
|
|
354
365
|
const resolvedOptions = {
|
|
355
366
|
...buildBaseOptions(model, options, apiKey),
|
|
356
367
|
authProfileId: options?.authProfileId,
|
|
357
|
-
reasoningEffort:
|
|
368
|
+
reasoningEffort: resolveOpenAISimpleReasoningEffort(model, options?.reasoning)
|
|
358
369
|
};
|
|
359
370
|
responsesPromptObserver.copy(options, resolvedOptions);
|
|
360
371
|
return streamOpenAICodexResponses(model, context, resolvedOptions);
|
|
@@ -377,20 +388,24 @@ function buildRequestBody(model, context, options, replayMode = "checkpoint") {
|
|
|
377
388
|
include: ["reasoning.encrypted_content"],
|
|
378
389
|
prompt_cache_key: options?.cacheRetention === "none" ? void 0 : clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId)
|
|
379
390
|
};
|
|
391
|
+
if (options?.responseFormat !== void 0) body.text = {
|
|
392
|
+
...body.text,
|
|
393
|
+
format: resolveOpenAIResponsesTextFormat(options.responseFormat)
|
|
394
|
+
};
|
|
380
395
|
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) body.temperature = options.temperature;
|
|
381
396
|
if (options?.serviceTier !== void 0) body.service_tier = options.serviceTier;
|
|
382
397
|
if (context.tools) {
|
|
383
|
-
const tools = convertResponsesToolPayload(context.tools, { strict:
|
|
398
|
+
const tools = convertResponsesToolPayload(context.tools, { strict: false });
|
|
384
399
|
if (tools.length > 0) {
|
|
385
400
|
body.tools = tools;
|
|
386
401
|
body.tool_choice = "auto";
|
|
387
402
|
body.parallel_tool_calls = true;
|
|
388
403
|
}
|
|
389
404
|
}
|
|
390
|
-
const effort = options?.reasoningEffort === void 0 ? void 0 :
|
|
405
|
+
const effort = options?.reasoningEffort === void 0 ? void 0 : resolveOpenAIRequestReasoning(model, options.reasoningEffort).effort;
|
|
391
406
|
if (effort !== void 0) body.reasoning = {
|
|
392
407
|
effort,
|
|
393
|
-
summary: options?.reasoningSummary ?? "auto"
|
|
408
|
+
...effort === "none" ? {} : { summary: options?.reasoningSummary ?? "auto" }
|
|
394
409
|
};
|
|
395
410
|
return body;
|
|
396
411
|
}
|
|
@@ -410,6 +425,29 @@ function resolveCodexWebSocketUrl(baseUrl) {
|
|
|
410
425
|
if (url.protocol === "http:") url.protocol = "ws:";
|
|
411
426
|
return url.toString();
|
|
412
427
|
}
|
|
428
|
+
function isJsonRecord(value) {
|
|
429
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Structured refusal code carried by the OpenAI Responses transport. Every
|
|
433
|
+
* terminal Responses path preserves it: a non-OK HTTP body parsed by
|
|
434
|
+
* {@link parseErrorResponse}, an SSE/WebSocket `error` event mapped by
|
|
435
|
+
* {@link extractCodexEventError}, and a `response.failed` event normalized into
|
|
436
|
+
* {@link ResponsesStreamFailure}. Only the app-server surface carries the
|
|
437
|
+
* `codexErrorInfo` discriminator, so both shapes must be read here.
|
|
438
|
+
*/
|
|
439
|
+
const RESPONSES_CYBER_POLICY_ERROR_CODE = "cyber_policy";
|
|
440
|
+
function readCodexProviderRefusal(error) {
|
|
441
|
+
if (error instanceof ResponsesStreamFailure) return error.code === RESPONSES_CYBER_POLICY_ERROR_CODE ? { category: "cyber" } : void 0;
|
|
442
|
+
if (!(error instanceof CodexApiError)) return;
|
|
443
|
+
if (error.code === RESPONSES_CYBER_POLICY_ERROR_CODE) return { category: "cyber" };
|
|
444
|
+
const payload = error.payload;
|
|
445
|
+
const nested = isJsonRecord(payload?.error) ? payload.error : void 0;
|
|
446
|
+
const codexErrorInfo = payload?.codexErrorInfo ?? nested?.codexErrorInfo;
|
|
447
|
+
if (codexErrorInfo === "cyberPolicy") return { category: "cyber" };
|
|
448
|
+
if (codexErrorInfo === "misalignmentPolicyViolation") return { category: "misalignment" };
|
|
449
|
+
return (typeof payload?.message === "string" ? payload.message : typeof nested?.message === "string" ? nested.message : "").startsWith("This content was flagged for possible biological risk.") ? { category: "bio" } : void 0;
|
|
450
|
+
}
|
|
413
451
|
var CodexApiError = class extends Error {
|
|
414
452
|
constructor(message, options) {
|
|
415
453
|
super(message);
|
|
@@ -433,8 +471,11 @@ function extractCodexEventError(event) {
|
|
|
433
471
|
message: typeof event.message === "string" ? event.message : typeof nested?.message === "string" ? nested.message : void 0
|
|
434
472
|
};
|
|
435
473
|
}
|
|
436
|
-
async function* mapCodexEvents(events) {
|
|
474
|
+
async function* mapCodexEvents(events, initialResponseHeaders) {
|
|
475
|
+
const responseModelTracker = createResponseModelTracker();
|
|
476
|
+
responseModelTracker.begin(initialResponseHeaders);
|
|
437
477
|
for await (const event of events) {
|
|
478
|
+
responseModelTracker.observeEvent(event);
|
|
438
479
|
const type = typeof event.type === "string" ? event.type : void 0;
|
|
439
480
|
if (!type) continue;
|
|
440
481
|
if (type === "error") {
|
|
@@ -448,7 +489,8 @@ async function* mapCodexEvents(events) {
|
|
|
448
489
|
const response = event.response;
|
|
449
490
|
const normalizedResponse = response ? {
|
|
450
491
|
...response,
|
|
451
|
-
status: normalizeCodexStatus(response.status)
|
|
492
|
+
status: normalizeCodexStatus(response.status),
|
|
493
|
+
model: responseModelTracker.resolve()
|
|
452
494
|
} : response;
|
|
453
495
|
yield {
|
|
454
496
|
...event,
|
|
@@ -615,11 +657,7 @@ async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
|
615
657
|
const socket = await connectWebSocket(url, headers, signal);
|
|
616
658
|
return {
|
|
617
659
|
socket,
|
|
618
|
-
release: (
|
|
619
|
-
if (keep === false) {
|
|
620
|
-
closeWebSocketSilently(socket);
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
660
|
+
release: () => {
|
|
623
661
|
closeWebSocketSilently(socket);
|
|
624
662
|
}
|
|
625
663
|
};
|
|
@@ -869,7 +907,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
869
907
|
...requestBody
|
|
870
908
|
}));
|
|
871
909
|
onRequestSent?.();
|
|
872
|
-
await processResponsesStream(startWebSocketOutputOnFirstEvent(mapCodexEvents(parseWebSocket(socket, options?.signal)), output, stream, onFirstProviderEvent, () => notifyProviderStreamOpened({
|
|
910
|
+
const terminal = await processResponsesStream(startWebSocketOutputOnFirstEvent(mapCodexEvents(parseWebSocket(socket, options?.signal)), output, stream, onFirstProviderEvent, () => notifyProviderStreamOpened({
|
|
873
911
|
options,
|
|
874
912
|
cancelStream: () => {
|
|
875
913
|
keepConnection = false;
|
|
@@ -902,6 +940,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
902
940
|
lastResponseItems: responseItems
|
|
903
941
|
};
|
|
904
942
|
}
|
|
943
|
+
return terminal;
|
|
905
944
|
} catch (error) {
|
|
906
945
|
if (entry) entry.continuation = void 0;
|
|
907
946
|
keepConnection = false;
|
|
@@ -964,8 +1003,11 @@ function parseErrorResponse(raw, response) {
|
|
|
964
1003
|
let message = raw || statusText || "Request failed";
|
|
965
1004
|
let friendlyMessage;
|
|
966
1005
|
let code;
|
|
1006
|
+
let payload;
|
|
967
1007
|
try {
|
|
968
|
-
const
|
|
1008
|
+
const parsed = JSON.parse(raw);
|
|
1009
|
+
payload = isJsonRecord(parsed) ? parsed : void 0;
|
|
1010
|
+
const err = parsed?.error;
|
|
969
1011
|
if (err) {
|
|
970
1012
|
code = err.code || err.type || void 0;
|
|
971
1013
|
if (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code ?? "") || status === 429) {
|
|
@@ -980,7 +1022,8 @@ function parseErrorResponse(raw, response) {
|
|
|
980
1022
|
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
981
1023
|
return new CodexApiError(`${friendlyMessage || message}${retryAfterSuffix}`, {
|
|
982
1024
|
code,
|
|
983
|
-
status
|
|
1025
|
+
status,
|
|
1026
|
+
payload
|
|
984
1027
|
});
|
|
985
1028
|
}
|
|
986
1029
|
function extractOpenAICodexAccountId(token) {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { M as clampThinkingLevel } from "./host-B4MeUNBc.mjs";
|
|
4
|
+
import { i as resolveOpenAICompletionsCompat } from "./openai-completions-compat-CkwdxTZx.mjs";
|
|
5
5
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
|
-
import { n as buildBaseOptions, o as reasoningTagTextPolicy } from "./simple-options-
|
|
7
|
-
import {
|
|
6
|
+
import { n as buildBaseOptions, o as reasoningTagTextPolicy } from "./simple-options-C6cFWj_f.mjs";
|
|
7
|
+
import { C as isOpenAICompletionsThinkingEnabled, b as createOpenAIProviderAcceptanceHook } from "./openai-transport-params-DQeuAvBl.mjs";
|
|
8
8
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { b as withProviderResponseHook, n as assignTransportErrorDetails, v as transportAbortError } from "./transport-stream-shared-D-6FQSHm.mjs";
|
|
10
10
|
import { a as tagUnresolvedTextAsCommentary, t as clearPendingCommentaryText } from "./assistant-text-phase-C20rxWwP.mjs";
|
|
11
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
12
|
-
import { t as
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
11
|
+
import { t as createAssistantOutput } from "./assistant-output-BsEkB-vU.mjs";
|
|
12
|
+
import { a as convertMessages, i as buildOpenAICompletionsRequest, s as finalizeOpenAICompletionsToolCalls, t as processCompletionsStream } from "./openai-completions-stream-Bu98b0Hv.mjs";
|
|
13
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-C9ZadkJW.mjs";
|
|
14
|
+
import { n as resolveProviderSimpleCompletionHeaders } from "./provider-transport-turn-state-CkGToCD2.mjs";
|
|
15
15
|
import { n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-B37TB3rB.mjs";
|
|
16
|
-
import { t as createOpenAIProviderClient } from "./openai-provider-client-
|
|
16
|
+
import { t as createOpenAIProviderClient } from "./openai-provider-client-DPo0Hmak.mjs";
|
|
17
17
|
//#region packages/ai/src/providers/openai-completions.ts
|
|
18
18
|
var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
19
19
|
convertMessages: () => convertMessages,
|
|
@@ -32,7 +32,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
32
32
|
const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
|
|
33
33
|
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
34
34
|
const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
|
|
35
|
-
const client = createClient(model, context, apiKey,
|
|
35
|
+
const client = createClient(model, context, apiKey, resolveProviderSimpleCompletionHeaders(model, options), cacheSessionId, compat);
|
|
36
36
|
let params = buildOpenAICompletionsRequest(model, context, options, {
|
|
37
37
|
mode: "direct",
|
|
38
38
|
compat,
|
|
@@ -154,11 +154,10 @@ const streamSimpleOpenAICompletions = (model, context, options) => {
|
|
|
154
154
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
155
155
|
const base = buildBaseOptions(model, options, apiKey);
|
|
156
156
|
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
157
|
-
const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning === "max" ? "xhigh" : clampedReasoning;
|
|
158
157
|
const toolChoice = options?.toolChoice;
|
|
159
158
|
return streamOpenAICompletions(model, context, {
|
|
160
159
|
...base,
|
|
161
|
-
reasoningEffort,
|
|
160
|
+
reasoningEffort: clampedReasoning,
|
|
162
161
|
toolChoice
|
|
163
162
|
});
|
|
164
163
|
};
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
2
|
-
import { a as resolveProviderRequestCapabilities } from "./host-policy-
|
|
3
|
-
//#region packages/normalization-core/src/code-points.ts
|
|
4
|
-
/** Truncates to a nonnegative code-point budget; grapheme clusters may be split. */
|
|
5
|
-
function truncateCodePoints(text, maxCodePoints) {
|
|
6
|
-
const limit = Math.max(0, Math.trunc(maxCodePoints) || 0);
|
|
7
|
-
if (text.length <= limit) return text;
|
|
8
|
-
const prefix = [];
|
|
9
|
-
for (const codePoint of text) {
|
|
10
|
-
if (prefix.length >= limit) break;
|
|
11
|
-
prefix.push(codePoint);
|
|
12
|
-
}
|
|
13
|
-
return prefix.join("");
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
2
|
+
import { a as resolveProviderRequestCapabilities } from "./host-policy-DUnXSx0I.mjs";
|
|
16
3
|
//#region packages/ai/src/providers/openai-response-format.ts
|
|
17
4
|
const JSON_SCHEMA_RESPONSE_FORMAT_NAME = "openclaw_response";
|
|
18
5
|
const OLLAMA_CLOUD_ORIGIN = "https://ollama.com";
|
|
@@ -127,9 +114,6 @@ function resolveOpenAICompletionsCompatDefaults(input) {
|
|
|
127
114
|
supportsLongCacheRetention: !isModelStudioLike && provider !== "cloudflare-workers-ai" && provider !== "cloudflare-ai-gateway" && knownProviderFamily !== "together" && !input.baseUrl?.includes("api.cloudflare.com") && !input.baseUrl?.includes("gateway.ai.cloudflare.com") && !input.baseUrl?.includes("api.together.ai") && !input.baseUrl?.includes("api.together.xyz")
|
|
128
115
|
};
|
|
129
116
|
}
|
|
130
|
-
function resolveOpenAICompletionsCompatDefaultsFromCapabilities(input) {
|
|
131
|
-
return resolveOpenAICompletionsCompatDefaults(input);
|
|
132
|
-
}
|
|
133
117
|
/** Detects endpoint capabilities and defaults for an OpenAI-completions model. */
|
|
134
118
|
function detectOpenAICompletionsCompat(model, resolveCapabilities) {
|
|
135
119
|
const capabilities = (resolveCapabilities ?? ((input) => resolveProviderRequestCapabilities(input, model)))({
|
|
@@ -143,7 +127,7 @@ function detectOpenAICompletionsCompat(model, resolveCapabilities) {
|
|
|
143
127
|
});
|
|
144
128
|
return {
|
|
145
129
|
capabilities,
|
|
146
|
-
defaults:
|
|
130
|
+
defaults: resolveOpenAICompletionsCompatDefaults({
|
|
147
131
|
provider: model.provider,
|
|
148
132
|
modelId: model.id,
|
|
149
133
|
baseUrl: model.baseUrl,
|
|
@@ -164,6 +148,8 @@ function resolveOpenAICompletionsCompat(model, resolveCapabilities) {
|
|
|
164
148
|
supportsStore: configured?.supportsStore ?? defaults.supportsStore,
|
|
165
149
|
supportsDeveloperRole: configured?.supportsDeveloperRole ?? defaults.supportsDeveloperRole,
|
|
166
150
|
supportsReasoningEffort: configured?.supportsReasoningEffort ?? defaults.supportsReasoningEffort,
|
|
151
|
+
supportedReasoningEfforts: configured?.supportedReasoningEfforts,
|
|
152
|
+
reasoningEffortMap: configured?.reasoningEffortMap,
|
|
167
153
|
supportsUsageInStreaming: configured?.supportsUsageInStreaming ?? defaults.supportsUsageInStreaming,
|
|
168
154
|
maxTokensField: configured?.maxTokensField ?? defaults.maxTokensField,
|
|
169
155
|
requiresToolResultName: configured?.requiresToolResultName ?? false,
|
|
@@ -186,35 +172,4 @@ function resolveOpenAICompletionsCompat(model, resolveCapabilities) {
|
|
|
186
172
|
};
|
|
187
173
|
}
|
|
188
174
|
//#endregion
|
|
189
|
-
|
|
190
|
-
const EXTENDED_RETENTION_MODELS = /* @__PURE__ */ new Set([
|
|
191
|
-
"gpt-5.5",
|
|
192
|
-
"gpt-5.5-pro",
|
|
193
|
-
"gpt-5.4",
|
|
194
|
-
"gpt-5.2",
|
|
195
|
-
"gpt-5.1-codex-max",
|
|
196
|
-
"gpt-5.1",
|
|
197
|
-
"gpt-5.1-codex",
|
|
198
|
-
"gpt-5.1-codex-mini",
|
|
199
|
-
"gpt-5.1-chat-latest",
|
|
200
|
-
"gpt-5",
|
|
201
|
-
"gpt-5-codex",
|
|
202
|
-
"gpt-4.1"
|
|
203
|
-
]);
|
|
204
|
-
/** Selects documented lifetime fields shared by Responses and Chat Completions. */
|
|
205
|
-
function resolveOpenAIPromptCacheParams(model, cacheRetention, compat) {
|
|
206
|
-
if (cacheRetention !== "long" || !compat.supportsPromptCacheKey || !compat.supportsLongCacheRetention) return {};
|
|
207
|
-
const version = /^gpt-(\d+)(?:\.(\d+))?(?:-|$)/.exec(model.id);
|
|
208
|
-
if (version && (Number(version[1]) > 5 || Number(version[1]) === 5 && Number(version[2]) >= 6)) return { prompt_cache_options: { ttl: "30m" } };
|
|
209
|
-
const modelId = model.id.replace(/-\d{4}-\d{2}-\d{2}$/, "");
|
|
210
|
-
return !isNativeOpenAIEndpoint(model) || EXTENDED_RETENTION_MODELS.has(modelId) ? { prompt_cache_retention: "24h" } : {};
|
|
211
|
-
}
|
|
212
|
-
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
213
|
-
const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
214
|
-
/** Truncates a prompt cache key by Unicode code point count. */
|
|
215
|
-
function clampOpenAIPromptCacheKey(key) {
|
|
216
|
-
if (key === void 0) return;
|
|
217
|
-
return truncateCodePoints(key, 64);
|
|
218
|
-
}
|
|
219
|
-
//#endregion
|
|
220
|
-
export { isNativeOpenAIEndpoint as a, resolveOpenAIPromptCacheKeySupport as c, shouldOmitOllamaCompatResponseFormat as d, detectOpenAICompletionsCompat as i, usesNativeOpenAICodexResponsesBackend as l, clampOpenAIPromptCacheKey as n, isOpenAICodexResponsesModel as o, resolveOpenAIPromptCacheParams as r, resolveOpenAICompletionsCompat as s, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH as t, resolveOpenAICompletionsResponseFormat as u };
|
|
175
|
+
export { resolveOpenAIPromptCacheKeySupport as a, shouldOmitOllamaCompatResponseFormat as c, resolveOpenAICompletionsCompat as i, isNativeOpenAIEndpoint as n, usesNativeOpenAICodexResponsesBackend as o, isOpenAICodexResponsesModel as r, resolveOpenAICompletionsResponseFormat as s, detectOpenAICompletionsCompat as t };
|
package/dist/{openai-completions-compat-CXn3T1we.d.mts → openai-completions-compat-JE7gqxb9.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-DaF2QbwS.mjs";
|
|
2
|
+
import { M as OpenAICompletionsCompat, O as Model } from "./types-4_uVs5WH.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-FZ1RA_qD.mjs";
|
|
4
4
|
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
5
5
|
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
6
6
|
type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";
|
|
@@ -24,7 +24,7 @@ type DetectedOpenAICompletionsCompat = {
|
|
|
24
24
|
capabilities: ProviderRequestCapabilities;
|
|
25
25
|
defaults: OpenAICompletionsCompatDefaults;
|
|
26
26
|
};
|
|
27
|
-
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders" | "reasoningEffortMap"> & {
|
|
27
|
+
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders" | "reasoningEffortMap" | "supportedReasoningEfforts"> & Pick<OpenAICompletionsCompat, "reasoningEffortMap" | "supportedReasoningEfforts"> & {
|
|
28
28
|
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
29
29
|
openRouterRouting?: OpenAICompletionsCompat["openRouterRouting"];
|
|
30
30
|
sessionAffinity: OpenAICompletionsSessionAffinity;
|