@openclaw/ai 2026.8.2 → 2026.9.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/dist/{anthropic-compaction-replay-CKCDrZJv.mjs → anthropic-compaction-replay-OMJZ0uyo.mjs} +5 -5
- package/dist/{anthropic-DTGZ4VMY.mjs → anthropic-hk7F7ptG.mjs} +16 -13
- package/dist/{anthropic-payload-policy-BTzmNC14.d.mts → anthropic-payload-policy-DBT1itQ-.d.mts} +2 -2
- package/dist/{api-registry-BbUHEKER.d.mts → api-registry-Cs6HGNqY.d.mts} +2 -2
- package/dist/{azure-openai-responses-BmqaDXM1.mjs → azure-openai-responses-CN4Fy5zV.mjs} +6 -4
- package/dist/{diagnostics-COpOtRwq.mjs → diagnostics-CPeq9F7y.mjs} +5 -1
- package/dist/{diagnostics-BaTA9eVl.d.mts → diagnostics-DnPnOui6.d.mts} +5 -1
- package/dist/diagnostics-KhXK-QJI.mjs +136 -0
- package/dist/diagnostics.d.mts +7 -2
- package/dist/diagnostics.mjs +4 -3
- package/dist/event-stream-DeDhbCc5.d.mts +1 -0
- package/dist/{event-stream-DcvAPSBe.d.mts → event-stream-vK_7r3bj.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/{google-CqjVZMwo.mjs → google-CC-nrwXg.mjs} +2 -2
- package/dist/{google-shared-Bnqni5j3.mjs → google-shared-CjPY0hZM.mjs} +2 -2
- package/dist/{google-vertex-D_WREEJi.mjs → google-vertex-DCr0pyzQ.mjs} +2 -2
- package/dist/{host-DKFUAmCn.d.mts → host-BztR4tQj.d.mts} +3 -3
- package/dist/{index-CefaUGSS.d.mts → index-AfaxKT8w.d.mts} +5 -5
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +2 -2
- package/dist/internal/anthropic.d.mts +8 -8
- package/dist/internal/anthropic.mjs +2 -2
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai.d.mts +5 -5
- package/dist/internal/openai.mjs +6 -6
- package/dist/internal/runtime.d.mts +5 -5
- package/dist/internal/runtime.mjs +6 -4
- package/dist/internal/shared.d.mts +2 -2
- package/dist/internal/shared.mjs +93 -2
- package/dist/{mistral-C24jVd6f.mjs → mistral-B7etBd_H.mjs} +5 -6
- package/dist/{openai-chatgpt-responses-Czum0oXz.mjs → openai-chatgpt-responses-BAJ4gq3i.mjs} +51 -111
- package/dist/{openai-completions-BfFwac6f.mjs → openai-completions-D0QZ0AyB.mjs} +9 -10
- package/dist/{openai-completions-compat-SZhi0Lf4.d.mts → openai-completions-compat-4IjSBpr6.d.mts} +5 -5
- package/dist/{openai-completions-stream-DGOvau4J.mjs → openai-completions-stream-DZjwK8vp.mjs} +14 -11
- package/dist/{openai-responses-BAryVEJM.mjs → openai-responses-BEUlxfDu.mjs} +4 -3
- package/dist/{openai-responses-contracts-BthRXano.d.mts → openai-responses-contracts-bPzSN_Ba.d.mts} +3 -3
- package/dist/{openai-responses-prompt-observer-internal--R0kZLOZ.mjs → openai-responses-prompt-observer-internal-C7x4IK7r.mjs} +3 -17
- package/dist/{openai-responses-shared-CxgdGBvm.mjs → openai-responses-shared-DiAdpNAM.mjs} +82 -89
- package/dist/{openai-tool-schema-CSMh5e9O.mjs → openai-tool-schema-BMiHFH36.mjs} +1 -1
- package/dist/{provider-error-BI8kIViN.mjs → provider-error-B6EGq6gg.mjs} +1 -0
- package/dist/{provider-options-DJd_9euj.d.mts → provider-options-CxFPtvh7.d.mts} +2 -2
- package/dist/provider-types.d.mts +7 -7
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-BsUX44Tq.mjs → reasoning-tag-text-partitioner-C-4uedDb.mjs} +63 -57
- package/dist/{simple-options-rdOPzr7Z.mjs → simple-options-0PLDyJ-d.mjs} +1 -2
- package/dist/{transport-stream-shared-BbG7PThh.d.mts → transport-stream-shared-BrvFTkoO.d.mts} +5 -5
- package/dist/{transport-stream-shared-D8nQWCUo.mjs → transport-stream-shared-CytPVLIg.mjs} +17 -4
- package/dist/transports.d.mts +11 -11
- package/dist/transports.mjs +26 -30
- package/dist/types-B5EFUmXs.d.mts +1 -0
- package/dist/{types-Beemor2E.d.mts → types-DbrhszyQ.d.mts} +3 -6
- package/dist/types.d.mts +7 -7
- package/dist/types.mjs +2 -2
- package/dist/{validation-CC6s7Smp.d.mts → validation-BOwtcl9X.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +1 -1
- package/dist/event-stream-pXT3FI6X.d.mts +0 -1
- package/dist/tls-certificate-errors-DXSpluKI.mjs +0 -93
- package/dist/types-COdhCX0U.d.mts +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { D as Model, G as StopReason, W as SimpleStreamOptions, at as Usage, d as Context, q as StreamFunction } from "../types-
|
|
2
|
-
import { C as supportsOpenAIReasoningEffort, S as resolveOpenAISupportedReasoningEfforts, _ as isOpenAIGpt54MiniModel, a as CodeModeToolSurfaceObservation, b as normalizeOpenAIReasoningEffort, c as codeModeToolSurfaceObserver, d as OpenAIToolProjection, f as projectOpenAITools, g as OpenAIReasoningEffort, h as OpenAIApiReasoningEffort, i as BaseOpenAIStreamOptions, l as reasoningTagTextPolicy, m as reconcileOpenAIResponsesToolChoice, o as OpenAICompletionsOptions, p as reconcileOpenAICompletionsToolChoice, u as OpenAICompletionsToolChoice, v as isOpenAIGpt55Model, w as supportsOpenAITemperature, x as resolveOpenAIReasoningEffortForModel, y as isOpenAIGpt56Model } from "../provider-options-
|
|
3
|
-
import "../types-
|
|
4
|
-
import { o as ResponsesPromptObservation, s as responsesPromptObserver } from "../openai-responses-contracts-
|
|
5
|
-
import { t as ResolvedOpenAICompletionsCompat } from "../openai-completions-compat-
|
|
1
|
+
import { D as Model, G as StopReason, W as SimpleStreamOptions, at as Usage, d as Context, q as StreamFunction } from "../types-DbrhszyQ.mjs";
|
|
2
|
+
import { C as supportsOpenAIReasoningEffort, S as resolveOpenAISupportedReasoningEfforts, _ as isOpenAIGpt54MiniModel, a as CodeModeToolSurfaceObservation, b as normalizeOpenAIReasoningEffort, c as codeModeToolSurfaceObserver, d as OpenAIToolProjection, f as projectOpenAITools, g as OpenAIReasoningEffort, h as OpenAIApiReasoningEffort, i as BaseOpenAIStreamOptions, l as reasoningTagTextPolicy, m as reconcileOpenAIResponsesToolChoice, o as OpenAICompletionsOptions, p as reconcileOpenAICompletionsToolChoice, u as OpenAICompletionsToolChoice, v as isOpenAIGpt55Model, w as supportsOpenAITemperature, x as resolveOpenAIReasoningEffortForModel, y as isOpenAIGpt56Model } from "../provider-options-CxFPtvh7.mjs";
|
|
3
|
+
import "../types-B5EFUmXs.mjs";
|
|
4
|
+
import { o as ResponsesPromptObservation, s as responsesPromptObserver } from "../openai-responses-contracts-bPzSN_Ba.mjs";
|
|
5
|
+
import { t as ResolvedOpenAICompletionsCompat } from "../openai-completions-compat-4IjSBpr6.mjs";
|
|
6
6
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-2uo_1OR1.mjs";
|
|
7
7
|
import OpenAI from "openai";
|
|
8
8
|
import { TSchema } from "typebox";
|
package/dist/internal/openai.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-mZTCdRPo.mjs";
|
|
2
|
-
import { a as codeModeToolSurfaceObserver, o as reasoningTagTextPolicy } from "../simple-options-
|
|
2
|
+
import { a as codeModeToolSurfaceObserver, o as reasoningTagTextPolicy } from "../simple-options-0PLDyJ-d.mjs";
|
|
3
3
|
import { t as projectRuntimeToolInputSchema } from "../tool-schema-json-projection-BtZiml7r.mjs";
|
|
4
|
-
import { g as convertMessages } from "../openai-completions-stream-
|
|
5
|
-
import { A as isAzureResponsesTextDeltaEvent, D as AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, E as AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, M as isResponsesTextContentPartType, N as isResponsesTextDeltaEventType, O as OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, P as resolveResponsesMessageSnapshotCollapse, T as readResponsesToolCallItemIdentity, d as resolveResponsesTerminalStopReason, j as isAzureResponsesTextDeltaEventType, k as OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, l as mapResponsesTerminalUsage, u as readResponsesReasoningTokens, w as createResponsesToolCallTracker } from "../openai-responses-shared-
|
|
6
|
-
import { _ as cleanSchemaForGemini, a as resolveOpenAIProjectedToolsStrictToolFlag, b as reconcileOpenAIResponsesToolChoice, c as extractToolSchemaModelCompat, d as shouldOmitEmptyArrayItems, f as stripUnsupportedSchemaKeywords, g as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, h as findLlamacppGbnfSchemaViolations, i as normalizeStrictOpenAIJsonSchema, l as normalizeToolParameterSchema, m as cleanSchemaForLlamacppGbnf, n as isStrictOpenAIJsonSchemaCompatible, o as findOpenAIStrictSchemaViolations, p as LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, r as normalizeOpenAIStrictToolParameters, s as normalizeOpenAIStrictCompatSchema, t as findOpenAIStrictToolProjectionDiagnostics, u as resolveUnsupportedToolSchemaKeywords, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "../openai-tool-schema-
|
|
4
|
+
import { g as convertMessages } from "../openai-completions-stream-DZjwK8vp.mjs";
|
|
5
|
+
import { A as isAzureResponsesTextDeltaEvent, D as AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, E as AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, M as isResponsesTextContentPartType, N as isResponsesTextDeltaEventType, O as OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, P as resolveResponsesMessageSnapshotCollapse, T as readResponsesToolCallItemIdentity, d as resolveResponsesTerminalStopReason, j as isAzureResponsesTextDeltaEventType, k as OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, l as mapResponsesTerminalUsage, u as readResponsesReasoningTokens, w as createResponsesToolCallTracker } from "../openai-responses-shared-DiAdpNAM.mjs";
|
|
6
|
+
import { _ as cleanSchemaForGemini, a as resolveOpenAIProjectedToolsStrictToolFlag, b as reconcileOpenAIResponsesToolChoice, c as extractToolSchemaModelCompat, d as shouldOmitEmptyArrayItems, f as stripUnsupportedSchemaKeywords, g as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, h as findLlamacppGbnfSchemaViolations, i as normalizeStrictOpenAIJsonSchema, l as normalizeToolParameterSchema, m as cleanSchemaForLlamacppGbnf, n as isStrictOpenAIJsonSchemaCompatible, o as findOpenAIStrictSchemaViolations, p as LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, r as normalizeOpenAIStrictToolParameters, s as normalizeOpenAIStrictCompatSchema, t as findOpenAIStrictToolProjectionDiagnostics, u as resolveUnsupportedToolSchemaKeywords, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "../openai-tool-schema-BMiHFH36.mjs";
|
|
7
7
|
import { A as supportsOpenAITemperature, C as isOpenAIGpt54MiniModel, D as resolveOpenAIReasoningEffortForModel, E as normalizeOpenAIReasoningEffort, O as resolveOpenAISupportedReasoningEfforts, S as responsesPromptObserver, T as isOpenAIGpt56Model, k as supportsOpenAIReasoningEffort, w as isOpenAIGpt55Model } from "../openai-responses-compaction-window-DO7yV7az.mjs";
|
|
8
8
|
import { t as mapOpenAIStopReason } from "../openai-stop-reason-Drnn_6Qj.mjs";
|
|
9
9
|
import { i as resolveAzureDeploymentNameFromMap, n as isTraditionalAzureOpenAIHost, r as parseAzureDeploymentNameMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "../azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
10
|
-
import { n as streamOpenAICompletions, r as streamSimpleOpenAICompletions } from "../openai-completions-
|
|
11
|
-
import { n as streamOpenAIResponses, r as streamSimpleOpenAIResponses } from "../openai-responses-
|
|
10
|
+
import { n as streamOpenAICompletions, r as streamSimpleOpenAICompletions } from "../openai-completions-D0QZ0AyB.mjs";
|
|
11
|
+
import { n as streamOpenAIResponses, r as streamSimpleOpenAIResponses } from "../openai-responses-BEUlxfDu.mjs";
|
|
12
12
|
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, clampOpenAIPromptCacheKey, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, codeModeToolSurfaceObserver, convertMessages, createResponsesToolCallTracker, extractToolSchemaModelCompat, findLlamacppGbnfSchemaViolations, findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, isAzureResponsesTextDeltaEvent, isAzureResponsesTextDeltaEventType, isOpenAICompatibleAzureResponsesBaseUrl, isOpenAIGpt54MiniModel, isOpenAIGpt55Model, isOpenAIGpt56Model, isResponsesTextContentPartType, isResponsesTextDeltaEventType, isStrictOpenAIJsonSchemaCompatible, isTraditionalAzureOpenAIHost, mapOpenAIStopReason, mapResponsesTerminalUsage, normalizeOpenAIReasoningEffort, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, parseAzureDeploymentNameMap, projectOpenAITools, projectRuntimeToolInputSchema, readResponsesReasoningTokens, readResponsesToolCallItemIdentity, reasoningTagTextPolicy, reconcileOpenAICompletionsToolChoice, reconcileOpenAIResponsesToolChoice, resolveAzureDeploymentNameFromMap, resolveOpenAIProjectedToolsStrictToolFlag, resolveOpenAIReasoningEffortForModel, resolveOpenAISupportedReasoningEfforts, resolveResponsesMessageSnapshotCollapse, resolveResponsesTerminalStopReason, resolveUnsupportedToolSchemaKeywords, responsesPromptObserver, shouldOmitEmptyArrayItems, streamOpenAICompletions, streamOpenAIResponses, streamSimpleOpenAICompletions, streamSimpleOpenAIResponses, stripUnsupportedSchemaKeywords, supportsOpenAIReasoningEffort, supportsOpenAITemperature };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import { A as ModelThinkingLevel, D as Model, J as StreamOptions, V as ProviderStreamOptions, W as SimpleStreamOptions, a as AssistantMessage, at as Usage, d as Context, n as Api, s as AssistantMessageEventStreamContract } from "../types-
|
|
3
|
-
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-
|
|
4
|
-
import "../types-
|
|
1
|
+
import "../index-AfaxKT8w.mjs";
|
|
2
|
+
import { A as ModelThinkingLevel, D as Model, J as StreamOptions, V as ProviderStreamOptions, W as SimpleStreamOptions, a as AssistantMessage, at as Usage, d as Context, n as Api, s as AssistantMessageEventStreamContract } from "../types-DbrhszyQ.mjs";
|
|
3
|
+
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-Cs6HGNqY.mjs";
|
|
4
|
+
import "../types-B5EFUmXs.mjs";
|
|
5
5
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
6
|
-
import { C as FirstStreamEventInternalOptions, D as getFirstStreamEventTimeoutHandler, E as createFirstStreamEventTimeoutError, O as getFirstStreamEventTimeoutMs, S as FirstStreamEventAbortController, T as createFirstStreamEventAbortController, g as parseTerminalToolCallArguments, k as withFirstStreamEventTimeout, w as FirstStreamEventTimeoutContext } from "../transport-stream-shared-
|
|
6
|
+
import { C as FirstStreamEventInternalOptions, D as getFirstStreamEventTimeoutHandler, E as createFirstStreamEventTimeoutError, O as getFirstStreamEventTimeoutMs, S as FirstStreamEventAbortController, T as createFirstStreamEventAbortController, g as parseTerminalToolCallArguments, k as withFirstStreamEventTimeout, w as FirstStreamEventTimeoutContext } from "../transport-stream-shared-BrvFTkoO.mjs";
|
|
7
7
|
//#region packages/ai/src/internal/default-runtime.d.ts
|
|
8
8
|
export declare const defaultApiRegistry: {
|
|
9
9
|
registerApiProvider: <TApi extends Api, TOptions extends StreamOptions>(provider: ApiProvider<TApi, TOptions>, sourceId?: string) => void;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { a as isProviderRefusalAssistantError } from "../diagnostics-CPeq9F7y.mjs";
|
|
1
2
|
import { n as createApiRegistry, t as createLlmRuntime } from "../stream-CREqxHgU.mjs";
|
|
2
3
|
import { a as getSupportedThinkingLevels, i as clampThinkingLevel, n as applyProviderReportedUsageCost, o as modelsAreEqual, r as calculateCost, t as sanitizeSurrogates } from "../sanitize-unicode-S6binQG-.mjs";
|
|
3
4
|
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-bktO00EJ.mjs";
|
|
4
|
-
import { C as headersToRecord, m as parseTerminalToolCallArguments } from "../transport-stream-shared-
|
|
5
|
+
import { C as headersToRecord, m as parseTerminalToolCallArguments } from "../transport-stream-shared-CytPVLIg.mjs";
|
|
5
6
|
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-DAvyP7qA.mjs";
|
|
6
7
|
import { i as repairJson, n as parseJsonWithRepair, r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "../json-parse-BuAJEbdW.mjs";
|
|
7
8
|
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-BjtkplhG.mjs";
|
|
8
9
|
import { t as shortHash } from "../hash-CHgqbJmD.mjs";
|
|
9
10
|
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-DcNjoFQE.mjs";
|
|
10
|
-
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-
|
|
11
|
+
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-C-4uedDb.mjs";
|
|
11
12
|
import { t as createSseByteGuard } from "../streaming-byte-guard-CC-HMn_u.mjs";
|
|
12
13
|
import { n as registerSessionResourceCleanup, t as cleanupSessionResources } from "../session-resources-CkR4WWy1.mjs";
|
|
13
14
|
import { n as resolveOpenAICodexAccountId, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
@@ -54,7 +55,7 @@ const CONTEXT_OVERFLOW_PATTERN_SCOPES = {
|
|
|
54
55
|
/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,
|
|
55
56
|
/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,
|
|
56
57
|
/exceeds the limit of \d+/i,
|
|
57
|
-
/exceeds the available context size/i,
|
|
58
|
+
/(?:exceeds the available context size|context size has been exceeded)/i,
|
|
58
59
|
/greater than the context length/i,
|
|
59
60
|
/context window exceeds limit/i,
|
|
60
61
|
/exceeded model token limit/i,
|
|
@@ -100,7 +101,7 @@ const CONTEXT_OVERFLOW_PATTERN_SCOPES = {
|
|
|
100
101
|
/\binput exceeds the maximum number of tokens\b/i,
|
|
101
102
|
/\bollama error:\s*context length exceeded(?:,\s*too many tokens)?\b/i,
|
|
102
103
|
/\btotal tokens?.*exceeds? (?:the )?(?:model(?:'s)? )?(?:max|maximum|limit)/i,
|
|
103
|
-
/\b(?:request|prompt) \(\d[\d,]*\s*tokens?\) exceeds (?:the )?available context size\b/i,
|
|
104
|
+
/\b(?:(?:request|prompt) \(\d[\d,]*\s*tokens?\) exceeds (?:the )?available context size|context size has been exceeded)\b/i,
|
|
104
105
|
/\binput (?:is )?too long for (?:the )?model\b/i
|
|
105
106
|
],
|
|
106
107
|
"failover-hint": [/context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|prompt.*(too (?:large|long)|exceed|over|limit|max(?:imum)?)|(?:request|input).*(?:context|window|length|token).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i],
|
|
@@ -183,6 +184,7 @@ function resolveContextInputTokens(message) {
|
|
|
183
184
|
* @returns true if the message indicates a context overflow
|
|
184
185
|
*/
|
|
185
186
|
function isContextOverflow(message, contextWindow) {
|
|
187
|
+
if (isProviderRefusalAssistantError(message)) return false;
|
|
186
188
|
if (message.stopReason === "error" && message.errorMessage) {
|
|
187
189
|
const errorMessage = message.errorMessage;
|
|
188
190
|
if (!NON_OVERFLOW_PATTERNS.some((p) => p.test(errorMessage)) && matchesContextOverflowMessage(errorMessage, "assistant-error")) return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as ThinkingLevel, D as Model, E as Message, J as StreamOptions, W as SimpleStreamOptions, Z as ThinkingBudgets, a as AssistantMessage, n as Api } from "../types-
|
|
2
|
-
import "../types-
|
|
1
|
+
import { $ as ThinkingLevel, D as Model, E as Message, J as StreamOptions, W as SimpleStreamOptions, Z as ThinkingBudgets, a as AssistantMessage, n as Api } from "../types-DbrhszyQ.mjs";
|
|
2
|
+
import "../types-B5EFUmXs.mjs";
|
|
3
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
4
4
|
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-Cwcjv_fx.mjs";
|
|
5
5
|
//#region packages/ai/src/providers/simple-options.d.ts
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,5 +1,96 @@
|
|
|
1
1
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-S6binQG-.mjs";
|
|
2
2
|
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, i as transformMessages, l as formatToolResultText, o as describeUnsupportedToolResultMedia, s as extractToolResultBlockText, u as hasMediaPayload } from "../host-BIaiBURL.mjs";
|
|
3
|
-
import { c as ensureSystemPromptCacheBoundary, d as stripSystemPromptCacheBoundary, f as normalizePromptCapabilityIds, i as clampReasoning, l as prependSystemPromptAdditionAfterCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, p as normalizeStructuredPromptSection, r as clampMaxTokensToModel, s as SYSTEM_PROMPT_CACHE_BOUNDARY, t as adjustMaxTokensForThinking, u as splitSystemPromptCacheBoundary } from "../simple-options-
|
|
4
|
-
|
|
3
|
+
import { c as ensureSystemPromptCacheBoundary, d as stripSystemPromptCacheBoundary, f as normalizePromptCapabilityIds, i as clampReasoning, l as prependSystemPromptAdditionAfterCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, p as normalizeStructuredPromptSection, r as clampMaxTokensToModel, s as SYSTEM_PROMPT_CACHE_BOUNDARY, t as adjustMaxTokensForThinking, u as splitSystemPromptCacheBoundary } from "../simple-options-0PLDyJ-d.mjs";
|
|
4
|
+
//#region packages/ai/src/utils/tls-certificate-errors.ts
|
|
5
|
+
const HOSTNAME_MISMATCH_CODES = /* @__PURE__ */ new Set(["ERR_TLS_CERT_ALTNAME_INVALID", "HOSTNAME_MISMATCH"]);
|
|
6
|
+
const CERTIFICATE_INVALID_CODES = /* @__PURE__ */ new Set([
|
|
7
|
+
"CERT_CHAIN_TOO_LONG",
|
|
8
|
+
"CERT_HAS_EXPIRED",
|
|
9
|
+
"CERT_NOT_YET_VALID",
|
|
10
|
+
"CERT_REJECTED",
|
|
11
|
+
"CERT_REVOKED",
|
|
12
|
+
"CERT_SIGNATURE_FAILURE",
|
|
13
|
+
"CERT_UNTRUSTED",
|
|
14
|
+
"CRL_HAS_EXPIRED",
|
|
15
|
+
"CRL_NOT_YET_VALID",
|
|
16
|
+
"CRL_SIGNATURE_FAILURE",
|
|
17
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
18
|
+
"ERROR_IN_CERT_NOT_AFTER_FIELD",
|
|
19
|
+
"ERROR_IN_CERT_NOT_BEFORE_FIELD",
|
|
20
|
+
"ERROR_IN_CRL_LAST_UPDATE_FIELD",
|
|
21
|
+
"ERROR_IN_CRL_NEXT_UPDATE_FIELD",
|
|
22
|
+
"INVALID_CA",
|
|
23
|
+
"INVALID_PURPOSE",
|
|
24
|
+
"PATH_LENGTH_EXCEEDED",
|
|
25
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
26
|
+
"UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY",
|
|
27
|
+
"UNABLE_TO_DECRYPT_CERT_SIGNATURE",
|
|
28
|
+
"UNABLE_TO_DECRYPT_CRL_SIGNATURE",
|
|
29
|
+
"UNABLE_TO_GET_CRL",
|
|
30
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
31
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
32
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE"
|
|
33
|
+
]);
|
|
34
|
+
const HOSTNAME_MISMATCH_PATTERNS = [
|
|
35
|
+
/hostname\/ip does not match certificate(?:'s)? altnames/i,
|
|
36
|
+
/hostname mismatch/i,
|
|
37
|
+
/host: .+ is not in the cert(?:ificate)?(?:'s)? altnames/i
|
|
38
|
+
];
|
|
39
|
+
const CERTIFICATE_INVALID_PATTERNS = [
|
|
40
|
+
/certificate has expired/i,
|
|
41
|
+
/certificate is not yet valid/i,
|
|
42
|
+
/self[- ]signed certificate/i,
|
|
43
|
+
/unable to get local issuer certificate/i,
|
|
44
|
+
/unable to verify the first certificate/i
|
|
45
|
+
];
|
|
46
|
+
const MAX_TLS_ERROR_DEPTH = 8;
|
|
47
|
+
function classifyCode(code) {
|
|
48
|
+
if (HOSTNAME_MISMATCH_CODES.has(code)) return "hostname_mismatch";
|
|
49
|
+
return CERTIFICATE_INVALID_CODES.has(code) ? "certificate_invalid" : null;
|
|
50
|
+
}
|
|
51
|
+
function classifyMessage(message) {
|
|
52
|
+
if (HOSTNAME_MISMATCH_PATTERNS.some((pattern) => pattern.test(message))) return "hostname_mismatch";
|
|
53
|
+
return CERTIFICATE_INVALID_PATTERNS.some((pattern) => pattern.test(message)) ? "certificate_invalid" : null;
|
|
54
|
+
}
|
|
55
|
+
function inspectTlsCertificateErrorInternal(error, seen, depth) {
|
|
56
|
+
if (depth > MAX_TLS_ERROR_DEPTH) return null;
|
|
57
|
+
if (typeof error === "string") {
|
|
58
|
+
const kind = classifyMessage(error);
|
|
59
|
+
return kind ? {
|
|
60
|
+
kind,
|
|
61
|
+
message: error
|
|
62
|
+
} : null;
|
|
63
|
+
}
|
|
64
|
+
if (!error || typeof error !== "object" || seen.has(error)) return null;
|
|
65
|
+
seen.add(error);
|
|
66
|
+
const candidate = error;
|
|
67
|
+
const code = typeof candidate.code === "string" ? candidate.code.trim().toUpperCase() : void 0;
|
|
68
|
+
const message = typeof candidate.message === "string" && candidate.message.trim() ? candidate.message : void 0;
|
|
69
|
+
const codeKind = code ? classifyCode(code) : null;
|
|
70
|
+
if (code && codeKind) return {
|
|
71
|
+
kind: codeKind,
|
|
72
|
+
code,
|
|
73
|
+
message: message ?? code
|
|
74
|
+
};
|
|
75
|
+
const nestedErrors = Array.isArray(candidate.errors) ? candidate.errors : [];
|
|
76
|
+
for (const nested of [
|
|
77
|
+
candidate.cause,
|
|
78
|
+
candidate.error,
|
|
79
|
+
...nestedErrors
|
|
80
|
+
]) {
|
|
81
|
+
if (nested === void 0 || nested === error) continue;
|
|
82
|
+
const details = inspectTlsCertificateErrorInternal(nested, seen, depth + 1);
|
|
83
|
+
if (details) return details;
|
|
84
|
+
}
|
|
85
|
+
const messageKind = message ? classifyMessage(message) : null;
|
|
86
|
+
return messageKind && message ? {
|
|
87
|
+
kind: messageKind,
|
|
88
|
+
message
|
|
89
|
+
} : null;
|
|
90
|
+
}
|
|
91
|
+
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
92
|
+
function inspectTlsCertificateError(error) {
|
|
93
|
+
return inspectTlsCertificateErrorInternal(error, /* @__PURE__ */ new Set(), 0);
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
5
96
|
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, describeUnsupportedToolResultMedia, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, formatToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
2
2
|
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-S6binQG-.mjs";
|
|
3
3
|
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-BIaiBURL.mjs";
|
|
4
|
-
import { n as
|
|
5
|
-
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-rdOPzr7Z.mjs";
|
|
4
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-0PLDyJ-d.mjs";
|
|
6
5
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
7
|
-
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-
|
|
6
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments, t as assignTransportErrorDetails } from "./transport-stream-shared-CytPVLIg.mjs";
|
|
8
7
|
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
9
8
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
9
|
import { t as transformProviderMessages } from "./provider-transcript-transform-WvJmFUAf.mjs";
|
|
@@ -84,7 +83,8 @@ const streamMistral = (model, context, options) => {
|
|
|
84
83
|
const chat = new Chat({
|
|
85
84
|
apiKey,
|
|
86
85
|
serverURL: model.baseUrl,
|
|
87
|
-
httpClient
|
|
86
|
+
httpClient,
|
|
87
|
+
retryConfig: { strategy: "none" }
|
|
88
88
|
});
|
|
89
89
|
const normalizeMistralToolCallId = createMistralToolCallIdNormalizer();
|
|
90
90
|
let payload = buildChatPayload(model, context, transformProviderMessages(context.messages, model, (id) => normalizeMistralToolCallId(id)), options);
|
|
@@ -119,9 +119,8 @@ const streamMistral = (model, context, options) => {
|
|
|
119
119
|
});
|
|
120
120
|
stream.end();
|
|
121
121
|
} catch (error) {
|
|
122
|
+
const terminal = assignTransportErrorDetails(output, error, options?.signal);
|
|
122
123
|
output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
123
|
-
const terminal = projectProviderError(error, options?.signal);
|
|
124
|
-
Object.assign(output, terminal);
|
|
125
124
|
stream.push({
|
|
126
125
|
type: "error",
|
|
127
126
|
reason: terminal.stopReason,
|
package/dist/{openai-chatgpt-responses-Czum0oXz.mjs → openai-chatgpt-responses-BAJ4gq3i.mjs}
RENAMED
|
@@ -1,44 +1,21 @@
|
|
|
1
|
-
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-
|
|
1
|
+
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
3
|
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-BIaiBURL.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { o as clampTimerTimeoutMs, u as resolveTimerTimeoutMs } from "./base64-CEFBpSkN.mjs";
|
|
4
|
+
import { r as toErrorObject } from "./diagnostics-KhXK-QJI.mjs";
|
|
5
|
+
import { u as resolveTimerTimeoutMs } from "./base64-CEFBpSkN.mjs";
|
|
7
6
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
8
|
-
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-
|
|
9
|
-
import {
|
|
10
|
-
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-CtuS1Upe.mjs";
|
|
7
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-0PLDyJ-d.mjs";
|
|
8
|
+
import { c as parseRetryAfterSeconds, t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-CtuS1Upe.mjs";
|
|
11
9
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
12
|
-
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, y as withProviderResponseHook } from "./transport-stream-shared-
|
|
13
|
-
import { F as commitResponsesEncryptedContentAttempt, L as isInvalidEncryptedContentError, W as buildOpenAIResponsesReasoningReplayMetadata, a as resolveResponsesReasoningEffort, c as processResponsesStream, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, q as suppressOpenAIResponsesCompaction, r as convertResponsesMessages, s as convertResponsesToolPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-
|
|
14
|
-
import { C as createOpenAIProviderAcceptanceHook, w as createOpenAIResponseHook } from "./openai-tool-schema-
|
|
10
|
+
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-CytPVLIg.mjs";
|
|
11
|
+
import { F as commitResponsesEncryptedContentAttempt, L as isInvalidEncryptedContentError, W as buildOpenAIResponsesReasoningReplayMetadata, a as resolveResponsesReasoningEffort, c as processResponsesStream, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, q as suppressOpenAIResponsesCompaction, r as convertResponsesMessages, s as convertResponsesToolPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-DiAdpNAM.mjs";
|
|
12
|
+
import { C as createOpenAIProviderAcceptanceHook, w as createOpenAIResponseHook } from "./openai-tool-schema-BMiHFH36.mjs";
|
|
15
13
|
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
16
14
|
import { A as supportsOpenAITemperature, S as responsesPromptObserver } from "./openai-responses-compaction-window-DO7yV7az.mjs";
|
|
17
15
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
18
16
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
19
|
-
import "./
|
|
17
|
+
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-C7x4IK7r.mjs";
|
|
20
18
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
21
|
-
import { t as inspectTlsCertificateError } from "./tls-certificate-errors-DXSpluKI.mjs";
|
|
22
|
-
//#region packages/ai/src/internal/retry-sleep.ts
|
|
23
|
-
function sleepWithAbort(ms, signal) {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
if (signal?.aborted) {
|
|
26
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const onAbort = () => {
|
|
30
|
-
clearTimeout(timeout);
|
|
31
|
-
signal?.removeEventListener("abort", onAbort);
|
|
32
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
33
|
-
};
|
|
34
|
-
const timeout = setTimeout(() => {
|
|
35
|
-
signal?.removeEventListener("abort", onAbort);
|
|
36
|
-
resolve();
|
|
37
|
-
}, ms);
|
|
38
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
19
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
43
20
|
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
44
21
|
var CodexProtocolError = class extends Error {
|
|
@@ -104,8 +81,6 @@ function loadNodeOs() {
|
|
|
104
81
|
}
|
|
105
82
|
const os = loadNodeOs();
|
|
106
83
|
const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
107
|
-
const DEFAULT_MAX_RETRIES = 3;
|
|
108
|
-
const BASE_DELAY_MS = 1e3;
|
|
109
84
|
const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
110
85
|
const CODEX_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
|
|
111
86
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
@@ -119,26 +94,6 @@ const CODEX_RESPONSE_STATUSES = /* @__PURE__ */ new Set([
|
|
|
119
94
|
"queued",
|
|
120
95
|
"in_progress"
|
|
121
96
|
]);
|
|
122
|
-
function isRetryableError(status, errorText) {
|
|
123
|
-
if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504) return true;
|
|
124
|
-
return /rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(errorText);
|
|
125
|
-
}
|
|
126
|
-
function resolveHttpRetryDelayMs(response, attempt) {
|
|
127
|
-
const fallbackMs = BASE_DELAY_MS * 2 ** attempt;
|
|
128
|
-
const retryAfterMs = response.headers.get("retry-after-ms");
|
|
129
|
-
if (retryAfterMs) {
|
|
130
|
-
const trimmed = retryAfterMs.trim();
|
|
131
|
-
const millis = Number(trimmed);
|
|
132
|
-
if (/^\d+(?:\.\d+)?$/.test(trimmed) && Number.isFinite(millis)) return clampTimerTimeoutMs(millis, 0) ?? fallbackMs;
|
|
133
|
-
}
|
|
134
|
-
const retryAfter = response.headers.get("retry-after");
|
|
135
|
-
if (!retryAfter) return fallbackMs;
|
|
136
|
-
const trimmed = retryAfter.trim();
|
|
137
|
-
const seconds = Number(trimmed);
|
|
138
|
-
if (/^\d+$/.test(trimmed) && Number.isFinite(seconds)) return clampTimerTimeoutMs(seconds * 1e3, 0) ?? fallbackMs;
|
|
139
|
-
const retryAt = parseRetryAfterHttpDateMs(trimmed);
|
|
140
|
-
return retryAt === void 0 ? fallbackMs : clampTimerTimeoutMs(retryAt - Date.now(), 0) ?? fallbackMs;
|
|
141
|
-
}
|
|
142
97
|
function resolveRequestTimeoutMs(options) {
|
|
143
98
|
const timeoutMs = options?.timeoutMs;
|
|
144
99
|
return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? resolveTimerTimeoutMs(timeoutMs, 1) : void 0;
|
|
@@ -267,7 +222,6 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
267
222
|
}
|
|
268
223
|
}
|
|
269
224
|
let response;
|
|
270
|
-
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
271
225
|
while (true) {
|
|
272
226
|
const activeAttempt = semanticAttempt;
|
|
273
227
|
response = void 0;
|
|
@@ -276,68 +230,55 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
276
230
|
const compressedBody = model.provider === "openai" && !sseHeaders.has("content-encoding") ? compressRequestBodyZstd(bodyJson) : null;
|
|
277
231
|
if (compressedBody) sseHeaders.set("content-encoding", "zstd");
|
|
278
232
|
const sseBody = compressedBody ?? bodyJson;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
body: sseBody,
|
|
292
|
-
signal: activeSignal
|
|
293
|
-
});
|
|
294
|
-
} catch (error) {
|
|
295
|
-
if (error instanceof Error) {
|
|
296
|
-
if (isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0) throw formatRequestTimeoutError(requestTimeoutMs, error);
|
|
297
|
-
if (error.name === "AbortError" || error.message === "Request was aborted") throw new Error("Request was aborted", { cause: error });
|
|
298
|
-
if (error.name === "TimeoutError" && requestTimeoutMs !== void 0) throw new Error(`Request timed out after ${requestTimeoutMs}ms`, { cause: error });
|
|
299
|
-
}
|
|
300
|
-
const tlsCertificateError = inspectTlsCertificateError(error);
|
|
301
|
-
const lastError = toErrorObject(error, String(error));
|
|
302
|
-
if (attempt < maxRetries && !lastError.message.includes("usage limit") && !tlsCertificateError) {
|
|
303
|
-
await sleepWithAbort(BASE_DELAY_MS * 2 ** attempt, activeSignal);
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
throw lastError;
|
|
307
|
-
}
|
|
308
|
-
response = attemptResponse;
|
|
309
|
-
if (attemptResponse.ok) break;
|
|
310
|
-
const hookStream = withFirstStreamEventTimeout(withProviderResponseHook({
|
|
311
|
-
signal: firstEventAbort.signal,
|
|
312
|
-
abort: firstEventAbort.abort,
|
|
313
|
-
hook: createOpenAIResponseHook(options?.onResponse, attemptResponse, model)
|
|
314
|
-
}), {
|
|
315
|
-
provider: model.provider,
|
|
316
|
-
api: model.api,
|
|
317
|
-
model: model.id,
|
|
318
|
-
timeoutMs: getFirstStreamEventTimeoutMs(options) ?? 0,
|
|
319
|
-
stage: "responses",
|
|
320
|
-
abort: firstEventAbort.abort,
|
|
321
|
-
onTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
233
|
+
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
234
|
+
observePromptEgress?.(activeAttempt.request, {
|
|
235
|
+
egress: "native-codex-sse",
|
|
236
|
+
payloadVariant: activeAttempt.kind
|
|
237
|
+
});
|
|
238
|
+
let attemptResponse;
|
|
239
|
+
try {
|
|
240
|
+
attemptResponse = await fetch(resolveCodexUrl(model.baseUrl), {
|
|
241
|
+
method: "POST",
|
|
242
|
+
headers: sseHeaders,
|
|
243
|
+
body: sseBody,
|
|
244
|
+
signal: activeSignal
|
|
322
245
|
});
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
246
|
+
} catch (error) {
|
|
247
|
+
if (error instanceof Error) {
|
|
248
|
+
if (isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0) throw formatRequestTimeoutError(requestTimeoutMs, error);
|
|
249
|
+
if (error.name === "AbortError" || error.message === "Request was aborted") throw new Error("Request was aborted", { cause: error });
|
|
250
|
+
if (error.name === "TimeoutError" && requestTimeoutMs !== void 0) throw new Error(`Request timed out after ${requestTimeoutMs}ms`, { cause: error });
|
|
327
251
|
}
|
|
328
|
-
|
|
329
|
-
terminalResponseError = new CodexApiError(info.friendlyMessage || info.message, { code: info.code });
|
|
330
|
-
break;
|
|
252
|
+
throw toErrorObject(error, String(error));
|
|
331
253
|
}
|
|
332
|
-
|
|
333
|
-
|
|
254
|
+
response = attemptResponse;
|
|
255
|
+
if (attemptResponse.ok) {
|
|
256
|
+
if (!attemptResponse.body) throw new Error("No response body");
|
|
334
257
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
335
258
|
commitSemanticAttempt(activeAttempt);
|
|
336
259
|
break;
|
|
337
260
|
}
|
|
261
|
+
const hookStream = withFirstStreamEventTimeout(withProviderResponseHook({
|
|
262
|
+
signal: firstEventAbort.signal,
|
|
263
|
+
abort: firstEventAbort.abort,
|
|
264
|
+
hook: createOpenAIResponseHook(options?.onResponse, attemptResponse, model)
|
|
265
|
+
}), {
|
|
266
|
+
provider: model.provider,
|
|
267
|
+
api: model.api,
|
|
268
|
+
model: model.id,
|
|
269
|
+
timeoutMs: getFirstStreamEventTimeoutMs(options) ?? 0,
|
|
270
|
+
stage: "responses",
|
|
271
|
+
abort: firstEventAbort.abort,
|
|
272
|
+
onTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
273
|
+
});
|
|
274
|
+
const [errorText] = await Promise.all([readChatGptResponsesErrorTextLimited(attemptResponse, activeSignal), hookStream[Symbol.asyncIterator]().next()]);
|
|
275
|
+
const info = parseErrorResponseText(errorText, attemptResponse.status, attemptResponse.statusText);
|
|
276
|
+
const retryAfterSeconds = parseRetryAfterSeconds(attemptResponse.headers);
|
|
277
|
+
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
278
|
+
const terminalResponseError = new CodexApiError(`${info.friendlyMessage || info.message}${retryAfterSuffix}`, { code: info.code });
|
|
338
279
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
339
|
-
const nextSemanticAttempt =
|
|
340
|
-
if (!nextSemanticAttempt) throw terminalResponseError
|
|
280
|
+
const nextSemanticAttempt = await resolveNextResponsesEncryptedContentAttempt(activeAttempt, terminalResponseError, { buildFullHistoryRequest: () => buildBody("full-history") });
|
|
281
|
+
if (!nextSemanticAttempt) throw terminalResponseError;
|
|
341
282
|
semanticAttempt = nextSemanticAttempt;
|
|
342
283
|
}
|
|
343
284
|
const hookedResponseStream = withProviderResponseHook({
|
|
@@ -375,7 +316,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
375
316
|
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
376
317
|
const normalizedError = requestTimedOut && requestTimeoutMs !== void 0 ? formatRequestTimeoutError(requestTimeoutMs, error) : error;
|
|
377
318
|
for (const block of output.content) delete block.partialJson;
|
|
378
|
-
const terminal =
|
|
319
|
+
const terminal = assignTransportErrorDetails(output, normalizedError, options?.signal);
|
|
379
320
|
getAiTransportHost().logWarn("openai-transport", "ChatGPT Responses stream terminated", {
|
|
380
321
|
provider: model.provider,
|
|
381
322
|
api: model.api,
|
|
@@ -385,7 +326,6 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
385
326
|
stopReason: terminal.stopReason,
|
|
386
327
|
failureKind: classifyStreamFailure(error, options?.signal, requestTimedOut)
|
|
387
328
|
});
|
|
388
|
-
Object.assign(output, terminal);
|
|
389
329
|
stream.push({
|
|
390
330
|
type: "error",
|
|
391
331
|
reason: terminal.stopReason,
|
|
@@ -2,14 +2,13 @@ import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
3
|
import { i as clampThinkingLevel } from "./sanitize-unicode-S6binQG-.mjs";
|
|
4
4
|
import { n as getAiTransportHost } from "./host-BIaiBURL.mjs";
|
|
5
|
-
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
6
5
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
7
6
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
8
|
-
import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-
|
|
7
|
+
import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-0PLDyJ-d.mjs";
|
|
9
8
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
10
|
-
import { _ as transportAbortError, y as withProviderResponseHook } from "./transport-stream-shared-
|
|
11
|
-
import { E as tagUnresolvedTextAsCommentary, S as shouldOmitOllamaCompatResponseFormat, _ as hasToolCallHistory, b as resolveOpenAICompletionsCompat, g as convertMessages, h as resolveOpenAIReasoningEffortMap, t as processCompletionsStream, v as finalizeOpenAICompletionsToolCalls, w as clearPendingCommentaryText, x as resolveOpenAICompletionsResponseFormat } from "./openai-completions-stream-
|
|
12
|
-
import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-
|
|
9
|
+
import { _ as transportAbortError, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-CytPVLIg.mjs";
|
|
10
|
+
import { E as tagUnresolvedTextAsCommentary, S as shouldOmitOllamaCompatResponseFormat, _ as hasToolCallHistory, b as resolveOpenAICompletionsCompat, g as convertMessages, h as resolveOpenAIReasoningEffortMap, t as processCompletionsStream, v as finalizeOpenAICompletionsToolCalls, w as clearPendingCommentaryText, x as resolveOpenAICompletionsResponseFormat } from "./openai-completions-stream-DZjwK8vp.mjs";
|
|
11
|
+
import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-BMiHFH36.mjs";
|
|
13
12
|
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
14
13
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
15
14
|
import OpenAI from "openai";
|
|
@@ -61,7 +60,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
61
60
|
const requestOptions = {
|
|
62
61
|
signal: firstEventAbort.signal,
|
|
63
62
|
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
64
|
-
maxRetries:
|
|
63
|
+
maxRetries: 0
|
|
65
64
|
};
|
|
66
65
|
const { data: openaiStream, response } = await client.chat.completions.create(params, requestOptions).withResponse();
|
|
67
66
|
const hookedOpenAIStream = withProviderResponseHook({
|
|
@@ -145,8 +144,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
145
144
|
});
|
|
146
145
|
stream.end();
|
|
147
146
|
} catch (error) {
|
|
148
|
-
const terminal =
|
|
149
|
-
Object.assign(output, terminal);
|
|
147
|
+
const terminal = assignTransportErrorDetails(output, error, options?.signal);
|
|
150
148
|
finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
|
|
151
149
|
clearPendingCommentaryText(provisionalCommentaryTags);
|
|
152
150
|
tagUnresolvedTextAsCommentary(output);
|
|
@@ -211,6 +209,7 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
211
209
|
baseURL: resolveOpenAIClientBaseUrl(model, baseUrl),
|
|
212
210
|
dangerouslyAllowBrowser: true,
|
|
213
211
|
defaultHeaders,
|
|
212
|
+
maxRetries: 0,
|
|
214
213
|
fetch: getAiTransportHost().buildModelFetch(model)
|
|
215
214
|
});
|
|
216
215
|
}
|
|
@@ -261,9 +260,9 @@ function buildParams(model, context, options, compat = resolveOpenAICompletionsC
|
|
|
261
260
|
}
|
|
262
261
|
const reasoningEffortMap = resolveOpenAIReasoningEffortMap(model);
|
|
263
262
|
const thinkingLevelMap = model.thinkingLevelMap;
|
|
264
|
-
const reasoningEffort = options?.reasoningEffort === void 0 ? void 0 : reasoningEffortMap[options.reasoningEffort] ?? thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
265
|
-
const reasoningEnabled = reasoningEffort !== void 0 && reasoningEffort !== "none";
|
|
266
263
|
const offReasoningEffort = reasoningEffortMap.off ?? model.thinkingLevelMap?.off;
|
|
264
|
+
const reasoningEffort = options?.reasoningEffort === void 0 ? offReasoningEffort ?? void 0 : reasoningEffortMap[options.reasoningEffort] ?? thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
265
|
+
const reasoningEnabled = reasoningEffort !== void 0 && reasoningEffort !== "none";
|
|
267
266
|
if (compat.thinkingFormat === "zai" && model.reasoning) params.thinking = reasoningEnabled ? {
|
|
268
267
|
type: "enabled",
|
|
269
268
|
clear_thinking: false
|
package/dist/{openai-completions-compat-SZhi0Lf4.d.mts → openai-completions-compat-4IjSBpr6.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model, j as OpenAICompletionsCompat } from "./types-
|
|
3
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-
|
|
1
|
+
import "./index-AfaxKT8w.mjs";
|
|
2
|
+
import { D as Model, j as OpenAICompletionsCompat } from "./types-DbrhszyQ.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-BztR4tQj.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"> & {
|
|
27
|
+
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders" | "reasoningEffortMap"> & {
|
|
28
28
|
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
29
29
|
openRouterRouting?: OpenAICompletionsCompat["openRouterRouting"];
|
|
30
30
|
sessionAffinity: OpenAICompletionsSessionAffinity;
|
|
@@ -38,6 +38,6 @@ declare function detectOpenAICompletionsCompat(model: Pick<Model<"openai-complet
|
|
|
38
38
|
} | null;
|
|
39
39
|
}, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): DetectedOpenAICompletionsCompat;
|
|
40
40
|
/** Applies explicit model overrides once on top of the canonical transport defaults. */
|
|
41
|
-
declare function resolveOpenAICompletionsCompat(model: Model<"openai-completions">, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): ResolvedOpenAICompletionsCompat;
|
|
41
|
+
declare function resolveOpenAICompletionsCompat(model: Pick<Model<"openai-completions">, "id" | "provider" | "baseUrl" | "compat">, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): ResolvedOpenAICompletionsCompat;
|
|
42
42
|
//#endregion
|
|
43
43
|
export { detectOpenAICompletionsCompat as n, resolveOpenAICompletionsCompat as r, ResolvedOpenAICompletionsCompat as t };
|