@openclaw/ai 2026.7.2-beta.7 → 2026.8.1-beta.2
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-CH4UUnZr.mjs → anthropic-B6dLpq5L.mjs} +55 -203
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/anthropic-compaction-replay-8lJNKXOE.mjs +840 -0
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-BP6AWT8j.d.mts} +4 -1
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-uSMZJ3FA.mjs} +26 -5
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CtSg0iTS.mjs → google-C7h2QzDX.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-B0Qr9OR7.mjs} +146 -89
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-Bhc3TjDl.mjs} +11 -7
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/host-DTqNc7ad.mjs +466 -0
- package/dist/{host-B9GUmcra.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +29 -5
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -5
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-CWmpvWYh.mjs → mistral-CEWoQI_g.mjs} +45 -48
- package/dist/number-coercion-H9qHik3g.mjs +71 -0
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +284 -240
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-BPnt4Sml.mjs} +65 -99
- package/dist/{openai-completions-compat-DBWjXoMZ.d.mts → openai-completions-compat-Dt3dcawL.d.mts} +2 -2
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-DhIKtOup.mjs} +18 -41
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/openai-responses-prompt-observer-internal-DgNTYnRY.mjs +46 -0
- package/dist/{openai-responses-stream-internal-Cw5txaGW.mjs → openai-responses-shared-DXIt3iY5.mjs} +1406 -940
- package/dist/{openai-reasoning-compat-YgeLncHw.mjs → openai-stop-reason-BkFkqqK0.mjs} +204 -37
- package/dist/openai-tool-projection-CY04OcvQ.mjs +338 -0
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-D8bB3z9b.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/sanitize-unicode-BYqrYtC_.mjs +90 -0
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +32 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +166 -241
- package/dist/transports.mjs +1979 -1825
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-bzp5k29J.d.mts → types-BHNrPS1l.d.mts} +23 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-B-j7cOYp.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/anthropic-usage-DWU-x8MI.mjs +0 -459
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/host-Dog2WQiR.mjs +0 -369
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +0 -392
- package/dist/openai-tool-projection-OhX64DoP.mjs +0 -215
- package/dist/provider-error-CAEvRjry.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/tool-result-text-CTpIRbYd.mjs +0 -225
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
- package/dist/transport-stream-shared-D81p90xq.mjs +0 -297
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, o as resolveClaudeFable5ModelIdentity, p as supportsClaudeAdaptiveThinking, s as resolveClaudeModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "../
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as streamAnthropic, r as streamSimpleAnthropic } from "../anthropic-
|
|
5
|
-
export { ANTHROPIC_OMITTED_REASONING_TEXT, ANTHROPIC_SERVER_SIDE_FALLBACKS, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, CLAUDE_OPUS_FALLBACK_MODEL_COST, applyAnthropicFallbackBoundary, applyAnthropicRefusal, applyClaudeRequestContract, defaultsClaudeAdaptiveThinking, findActiveAnthropicToolTurnAssistantIndex, omitFoundryBearerCredentialHeaders, prepareClaudeNoPrefillRequestContext, projectAnthropicTools, readAnthropicCacheWriteUsage, readAnthropicFallbackBoundary, readAnthropicPromptUsageSnapshot, readAnthropicUsageTokenCount, readLastAnthropicIterationUsage, reconcileAnthropicToolChoice, requiresClaudeAdaptiveThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAnthropicFallbackServingModelCost, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, resolveModelBoundThinkingReplayMode, resolveOriginalAnthropicToolName, streamAnthropic, streamSimpleAnthropic, supportsClaudeAdaptiveThinking, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, usesClaudeFable5MessagesContract, usesClaudeStreamingRefusalContract, usesFoundryBearerAuth };
|
|
1
|
+
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, o as resolveClaudeFable5ModelIdentity, p as supportsClaudeAdaptiveThinking, s as resolveClaudeModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "../anthropic-JsNA5KCu.mjs";
|
|
2
|
+
import { _ as resolveAnthropicThinkingEffort, b as usesClaudeStreamingRefusalContract, d as ANTHROPIC_CLAUDE_CODE_VERSION, f as applyClaudeRequestContract, g as requiresClaudeAdaptiveThinking, h as prepareClaudeNoPrefillRequestContext, m as mapAnthropicStopReason, p as defaultsClaudeAdaptiveThinking, u as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, v as resolveModelBoundThinkingReplayMode, y as usesClaudeFable5MessagesContract } from "../host-DTqNc7ad.mjs";
|
|
3
|
+
import { C as readAnthropicFallbackBoundary, D as usesFoundryBearerAuth, E as omitFoundryBearerCredentialHeaders, I as resolveAnthropicServerCompactionPlan, S as applyAnthropicFallbackBoundary, T as applyAnthropicRefusal, _ as ANTHROPIC_OMITTED_REASONING_TEXT, a as applyAnthropicMessageDeltaUsage, b as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, c as readAnthropicPromptUsageSnapshot, d as normalizeAnthropicToolCallId, f as normalizeAnthropicToolChoice, g as toClaudeCodeToolName, h as resolveOriginalAnthropicToolName, l as readAnthropicUsageTokenCount, m as reconcileAnthropicToolChoice, o as applyAnthropicMessageStartUsage, p as projectAnthropicTools, s as readAnthropicCacheWriteUsage, u as readLastAnthropicIterationUsage, v as findActiveAnthropicToolTurnAssistantIndex, w as resolveAnthropicFallbackServingModelCost, x as CLAUDE_OPUS_FALLBACK_MODEL_COST, y as ANTHROPIC_SERVER_SIDE_FALLBACKS } from "../anthropic-compaction-replay-8lJNKXOE.mjs";
|
|
4
|
+
import { n as streamAnthropic, r as streamSimpleAnthropic } from "../anthropic-B6dLpq5L.mjs";
|
|
5
|
+
export { ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, ANTHROPIC_CLAUDE_CODE_VERSION, ANTHROPIC_OMITTED_REASONING_TEXT, ANTHROPIC_SERVER_SIDE_FALLBACKS, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, CLAUDE_OPUS_FALLBACK_MODEL_COST, applyAnthropicFallbackBoundary, applyAnthropicMessageDeltaUsage, applyAnthropicMessageStartUsage, applyAnthropicRefusal, applyClaudeRequestContract, defaultsClaudeAdaptiveThinking, findActiveAnthropicToolTurnAssistantIndex, mapAnthropicStopReason, normalizeAnthropicToolCallId, normalizeAnthropicToolChoice, omitFoundryBearerCredentialHeaders, prepareClaudeNoPrefillRequestContext, projectAnthropicTools, readAnthropicCacheWriteUsage, readAnthropicFallbackBoundary, readAnthropicPromptUsageSnapshot, readAnthropicUsageTokenCount, readLastAnthropicIterationUsage, reconcileAnthropicToolChoice, requiresClaudeAdaptiveThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAnthropicFallbackServingModelCost, resolveAnthropicServerCompactionPlan, resolveAnthropicThinkingEffort, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, resolveModelBoundThinkingReplayMode, resolveOriginalAnthropicToolName, streamAnthropic, streamSimpleAnthropic, supportsClaudeAdaptiveThinking, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, toClaudeCodeToolName, usesClaudeFable5MessagesContract, usesClaudeStreamingRefusalContract, usesFoundryBearerAuth };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { t as OPENAI_RESPONSES_APIS } from "../openai-responses-contracts-XpZJxrRG.mjs";
|
|
2
|
+
import { i as resolveOpenAIResponsesServerCompactionPlan } from "../openai-responses-payload-policy-BSs371VM.mjs";
|
|
3
|
+
export { OPENAI_RESPONSES_APIS, resolveOpenAIResponsesServerCompactionPlan };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { i as OPENAI_RESPONSES_APIS } from "../openai-responses-contracts-CyfIkQi5.mjs";
|
|
2
|
+
import { i as resolveOpenAIResponsesServerCompactionPlan } from "../openai-responses-payload-policy-BDxV-W0c.mjs";
|
|
3
|
+
export { OPENAI_RESPONSES_APIS, resolveOpenAIResponsesServerCompactionPlan };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _ as
|
|
3
|
-
import {
|
|
1
|
+
import { $ as Usage, E as Model, R as SimpleStreamOptions, V as StreamFunction, u as Context, z as StopReason } from "../types-BHNrPS1l.mjs";
|
|
2
|
+
import { _ as normalizeOpenAIReasoningEffort, a as OpenAICompletionsOptions, b as supportsOpenAIReasoningEffort, c as OpenAIToolProjection, d as reconcileOpenAIResponsesToolChoice, f as OpenAIApiReasoningEffort, g as isOpenAIGpt56Model, h as isOpenAIGpt55Model, i as BaseOpenAIStreamOptions, l as projectOpenAITools, m as isOpenAIGpt54MiniModel, p as OpenAIReasoningEffort, s as OpenAICompletionsToolChoice, u as reconcileOpenAICompletionsToolChoice, v as resolveOpenAIReasoningEffortForModel, x as supportsOpenAITemperature, y as resolveOpenAISupportedReasoningEfforts } from "../provider-options-B96RdNpH.mjs";
|
|
3
|
+
import { o as ResponsesPromptObservation, s as responsesPromptObserver } from "../openai-responses-contracts-XpZJxrRG.mjs";
|
|
4
|
+
import { t as ResolvedOpenAICompletionsCompat } from "../openai-completions-compat-Dt3dcawL.mjs";
|
|
4
5
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-2uo_1OR1.mjs";
|
|
5
6
|
import OpenAI from "openai";
|
|
6
7
|
import { TSchema } from "typebox";
|
|
@@ -81,7 +82,7 @@ declare const streamOpenAICompletions: StreamFunction<"openai-completions", Open
|
|
|
81
82
|
declare const streamSimpleOpenAICompletions: StreamFunction<"openai-completions", SimpleStreamOptions>;
|
|
82
83
|
//#endregion
|
|
83
84
|
//#region packages/ai/src/providers/openai-responses.d.ts
|
|
84
|
-
interface OpenAIResponsesOptions extends
|
|
85
|
+
interface OpenAIResponsesOptions extends BaseOpenAIStreamOptions {
|
|
85
86
|
reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
86
87
|
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
87
88
|
replayResponsesItemIds?: boolean;
|
|
@@ -223,7 +224,6 @@ type ToolSchemaCompatInput = {
|
|
|
223
224
|
unsupportedToolSchemaKeywords?: unknown;
|
|
224
225
|
omitEmptyArrayItems?: unknown;
|
|
225
226
|
};
|
|
226
|
-
declare function clearOpenAIToolSchemaCacheForTest(): void;
|
|
227
227
|
/** Normalizes a tool parameter schema into the OpenAI strict JSON-schema subset. */
|
|
228
228
|
declare function normalizeStrictOpenAIJsonSchema(schema: unknown, modelCompat?: ToolSchemaCompatInput | null): unknown;
|
|
229
229
|
/** Normalizes tool parameters using strict OpenAI rules only when strict mode is active. */
|
|
@@ -257,4 +257,4 @@ type RuntimeToolInputSchemaProjection = {
|
|
|
257
257
|
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
258
258
|
declare function projectRuntimeToolInputSchema(schema: unknown, path?: string): RuntimeToolInputSchemaProjection;
|
|
259
259
|
//#endregion
|
|
260
|
-
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, AzureResponsesTextContentPart, AzureResponsesTextDeltaEvent, 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, OpenAIApiReasoningEffort, type OpenAICompletionsOptions, OpenAICompletionsToolChoice, OpenAIReasoningEffort, OpenAIResponsesOptions, OpenAIStopReasonResult, OpenAIToolProjection, ResponsesMessageSnapshotCollapse, ResponsesTerminalUsagePayload, ResponsesTextContentPartType, ResponsesTextDeltaEventType, ResponsesToolCallIdentity, ResponsesToolCallState, RuntimeToolInputSchemaJson, RuntimeToolInputSchemaProjection, ToolParameterSchemaOptions, ToolSchemaModelCompat, clampOpenAIPromptCacheKey, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf,
|
|
260
|
+
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, AzureResponsesTextContentPart, AzureResponsesTextDeltaEvent, 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, OpenAIApiReasoningEffort, type OpenAICompletionsOptions, OpenAICompletionsToolChoice, OpenAIReasoningEffort, OpenAIResponsesOptions, OpenAIStopReasonResult, OpenAIToolProjection, ResponsesMessageSnapshotCollapse, type ResponsesPromptObservation, ResponsesTerminalUsagePayload, ResponsesTextContentPartType, ResponsesTextDeltaEventType, ResponsesToolCallIdentity, ResponsesToolCallState, RuntimeToolInputSchemaJson, RuntimeToolInputSchemaProjection, ToolParameterSchemaOptions, ToolSchemaModelCompat, clampOpenAIPromptCacheKey, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, 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, reconcileOpenAICompletionsToolChoice, reconcileOpenAIResponsesToolChoice, resolveAzureDeploymentNameFromMap, resolveOpenAIProjectedToolsStrictToolFlag, resolveOpenAIReasoningEffortForModel, resolveOpenAISupportedReasoningEfforts, resolveResponsesMessageSnapshotCollapse, resolveResponsesTerminalStopReason, resolveUnsupportedToolSchemaKeywords, responsesPromptObserver, shouldOmitEmptyArrayItems, streamOpenAICompletions, streamOpenAIResponses, streamSimpleOpenAICompletions, streamSimpleOpenAIResponses, stripUnsupportedSchemaKeywords, supportsOpenAIReasoningEffort, supportsOpenAITemperature };
|
package/dist/internal/openai.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { S as supportsOpenAITemperature, _ as isOpenAIGpt56Model, b as resolveOpenAISupportedReasoningEfforts, g as isOpenAIGpt55Model, h as isOpenAIGpt54MiniModel, m as responsesPromptObserver, v as normalizeOpenAIReasoningEffort, x as supportsOpenAIReasoningEffort, y as resolveOpenAIReasoningEffortForModel } from "../openai-responses-contracts-CyfIkQi5.mjs";
|
|
1
2
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-mZTCdRPo.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { t as projectRuntimeToolInputSchema } from "../tool-schema-json-projection-q5d7QX5c.mjs";
|
|
4
|
+
import { r as convertMessages, t as mapOpenAIStopReason } from "../openai-stop-reason-BkFkqqK0.mjs";
|
|
5
|
+
import { $ as normalizeOpenAIStrictCompatSchema, A as isAzureResponsesTextDeltaEvent, D as AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, E as AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, J as isStrictOpenAIJsonSchemaCompatible, M as isResponsesTextContentPartType, N as isResponsesTextDeltaEventType, O as OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, P as resolveResponsesMessageSnapshotCollapse, Q as findOpenAIStrictSchemaViolations, T as readResponsesToolCallItemIdentity, X as normalizeStrictOpenAIJsonSchema, Y as normalizeOpenAIStrictToolParameters, Z as resolveOpenAIProjectedToolsStrictToolFlag, at as LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, ct as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, d as resolveResponsesTerminalStopReason, et as extractToolSchemaModelCompat, it as stripUnsupportedSchemaKeywords, j as isAzureResponsesTextDeltaEventType, k as OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, l as mapResponsesTerminalUsage, lt as cleanSchemaForGemini, nt as resolveUnsupportedToolSchemaKeywords, ot as cleanSchemaForLlamacppGbnf, q as findOpenAIStrictToolProjectionDiagnostics, rt as shouldOmitEmptyArrayItems, st as findLlamacppGbnfSchemaViolations, tt as normalizeToolParameterSchema, u as readResponsesReasoningTokens, w as createResponsesToolCallTracker } from "../openai-responses-shared-DXIt3iY5.mjs";
|
|
6
|
+
import { n as reconcileOpenAICompletionsToolChoice, r as reconcileOpenAIResponsesToolChoice, t as projectOpenAITools } from "../openai-tool-projection-CY04OcvQ.mjs";
|
|
6
7
|
import { i as resolveAzureDeploymentNameFromMap, n as isTraditionalAzureOpenAIHost, r as parseAzureDeploymentNameMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "../azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
7
|
-
import { n as streamOpenAICompletions, r as streamSimpleOpenAICompletions } from "../openai-completions-
|
|
8
|
-
import { n as streamOpenAIResponses, r as streamSimpleOpenAIResponses } from "../openai-responses-
|
|
9
|
-
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,
|
|
8
|
+
import { n as streamOpenAICompletions, r as streamSimpleOpenAICompletions } from "../openai-completions-BPnt4Sml.mjs";
|
|
9
|
+
import { n as streamOpenAIResponses, r as streamSimpleOpenAIResponses } from "../openai-responses-DhIKtOup.mjs";
|
|
10
|
+
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, 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, reconcileOpenAICompletionsToolChoice, reconcileOpenAIResponsesToolChoice, resolveAzureDeploymentNameFromMap, resolveOpenAIProjectedToolsStrictToolFlag, resolveOpenAIReasoningEffortForModel, resolveOpenAISupportedReasoningEfforts, resolveResponsesMessageSnapshotCollapse, resolveResponsesTerminalStopReason, resolveUnsupportedToolSchemaKeywords, responsesPromptObserver, shouldOmitEmptyArrayItems, streamOpenAICompletions, streamOpenAIResponses, streamSimpleOpenAICompletions, streamSimpleOpenAIResponses, stripUnsupportedSchemaKeywords, supportsOpenAIReasoningEffort, supportsOpenAITemperature };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as ModelThinkingLevel, E as Model,
|
|
2
|
-
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-
|
|
1
|
+
import { $ as Usage, D as ModelThinkingLevel, E as Model, H as StreamOptions, L as ProviderStreamOptions, R as SimpleStreamOptions, i as AssistantMessage, n as Api, o as AssistantMessageEventStreamContract, u as Context } from "../types-BHNrPS1l.mjs";
|
|
2
|
+
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-k3zTz0cV.mjs";
|
|
3
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
4
4
|
import { a as createFirstStreamEventTimeoutError, c as withFirstStreamEventTimeout, i as createFirstStreamEventAbortController, n as FirstStreamEventInternalOptions, o as getFirstStreamEventTimeoutHandler, r as FirstStreamEventTimeoutContext, s as getFirstStreamEventTimeoutMs, t as FirstStreamEventAbortController } from "../stream-first-event-timeout-DvDeSucC.mjs";
|
|
5
5
|
|
|
@@ -117,6 +117,18 @@ declare function resolveOpenAICodexAccountId(token: string): string | null;
|
|
|
117
117
|
//#region packages/ai/src/utils/overflow.d.ts
|
|
118
118
|
/** Detects DS4-style raw token-count context overflow errors. */
|
|
119
119
|
declare function isConfiguredContextSizeOverflowError(errorMessage: string): boolean;
|
|
120
|
+
declare const CONTEXT_OVERFLOW_PATTERN_SCOPES: {
|
|
121
|
+
readonly "assistant-error": RegExp[];
|
|
122
|
+
readonly "failover-explicit": RegExp[];
|
|
123
|
+
readonly "provider-fallback": RegExp[];
|
|
124
|
+
readonly "failover-hint": readonly [RegExp];
|
|
125
|
+
readonly "context-window-too-small": readonly [RegExp];
|
|
126
|
+
readonly "tpm-rate-limit-hint": readonly [RegExp];
|
|
127
|
+
readonly "rate-limit-hint": readonly [RegExp];
|
|
128
|
+
};
|
|
129
|
+
type ContextOverflowMessageScope = keyof typeof CONTEXT_OVERFLOW_PATTERN_SCOPES;
|
|
130
|
+
/** Match one canonical context-overflow wording scope without applying caller policy. */
|
|
131
|
+
declare function matchesContextOverflowMessage(errorMessage: string, scope: ContextOverflowMessageScope): boolean;
|
|
120
132
|
/**
|
|
121
133
|
* Check if an assistant message represents a context overflow error.
|
|
122
134
|
*
|
|
@@ -134,7 +146,7 @@ declare function isConfiguredContextSizeOverflowError(errorMessage: string): boo
|
|
|
134
146
|
* - Google Gemini: "input token count exceeds the maximum"
|
|
135
147
|
* - xAI (Grok): "maximum prompt length is X but request contains Y"
|
|
136
148
|
* - Groq: "reduce the length of the messages"
|
|
137
|
-
* - Cerebras:
|
|
149
|
+
* - Cerebras: 413 status code (no body)
|
|
138
150
|
* - Mistral: "Prompt contains X tokens ... too large for model with Y maximum context length"
|
|
139
151
|
* - OpenRouter (all backends): "maximum context length is X tokens"
|
|
140
152
|
* - Together AI: "The input (X tokens) is longer than the model's context length (Y tokens)."
|
|
@@ -161,7 +173,7 @@ declare function isConfiguredContextSizeOverflowError(errorMessage: string): boo
|
|
|
161
173
|
* 1. Send a request that exceeds the model's context window
|
|
162
174
|
* 2. Check the errorMessage in the response
|
|
163
175
|
* 3. Create a regex pattern that matches the error
|
|
164
|
-
* 4. The pattern should be added to
|
|
176
|
+
* 4. The pattern should be added to the appropriate canonical scope in this file, or
|
|
165
177
|
* check the errorMessage yourself before calling this function
|
|
166
178
|
*
|
|
167
179
|
* @param message - The assistant message to check
|
|
@@ -221,4 +233,4 @@ type SseByteGuard = {
|
|
|
221
233
|
};
|
|
222
234
|
declare function createSseByteGuard(reader: ReadableStreamDefaultReader<Uint8Array>, opts: ReadSseStreamWithLimitOptions): SseByteGuard;
|
|
223
235
|
//#endregion
|
|
224
|
-
export { FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, OpenAICodexJwtPayload, ReadSseStreamWithLimitOptions, type ReasoningTagTextDelta, type ReasoningTagTextPartitioner, SessionResourceCleanup, SseByteGuard, SseStreamOverflow, applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
236
|
+
export { ContextOverflowMessageScope, FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, OpenAICodexJwtPayload, ReadSseStreamWithLimitOptions, type ReasoningTagTextDelta, type ReasoningTagTextPartitioner, SessionResourceCleanup, SseByteGuard, SseStreamOverflow, applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, matchesContextOverflowMessage, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { n as createApiRegistry, t as createLlmRuntime } from "../stream-CREqxHgU.mjs";
|
|
3
|
-
import { t as sanitizeSurrogates } from "../sanitize-unicode-
|
|
4
|
-
import { c as calculateCost, d as modelsAreEqual, l as clampThinkingLevel, s as applyProviderReportedUsageCost, u as getSupportedThinkingLevels } from "../number-coercion-DvG7SNMg.mjs";
|
|
3
|
+
import { a as getSupportedThinkingLevels, i as clampThinkingLevel, n as applyProviderReportedUsageCost, o as modelsAreEqual, r as calculateCost, t as sanitizeSurrogates } from "../sanitize-unicode-BYqrYtC_.mjs";
|
|
5
4
|
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-DAvyP7qA.mjs";
|
|
6
|
-
import { n as parseStreamingJson, r as repairJson, t as parseJsonWithRepair } from "../json-parse-
|
|
7
|
-
import { n as onLlmRequestActivity, t as
|
|
8
|
-
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-CGDyLWUR.mjs";
|
|
9
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-BBys9hSb.mjs";
|
|
5
|
+
import { n as parseStreamingJson, r as repairJson, t as parseJsonWithRepair } from "../json-parse-CDnesDM_.mjs";
|
|
6
|
+
import { n as notifyLlmRequestActivity, r as onLlmRequestActivity, t as headersToRecord } from "../headers-DdOQtGuU.mjs";
|
|
10
7
|
import { t as shortHash } from "../hash-CHgqbJmD.mjs";
|
|
11
|
-
import { t as
|
|
12
|
-
import {
|
|
8
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-MK28puvq.mjs";
|
|
9
|
+
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-rnPwX2pg.mjs";
|
|
10
|
+
import { n as registerSessionResourceCleanup, t as cleanupSessionResources } from "../session-resources-CkR4WWy1.mjs";
|
|
11
|
+
import { n as resolveOpenAICodexAccountId, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
13
12
|
import { t as createSseByteGuard } from "../streaming-byte-guard-BrbkbwUu.mjs";
|
|
14
13
|
//#region packages/ai/src/internal/default-runtime.ts
|
|
15
14
|
const DEFAULT_RUNTIME_KEY = Symbol.for("openclaw.ai.defaultRuntime");
|
|
@@ -39,69 +38,82 @@ const CONFIGURED_CONTEXT_SIZE_OVERFLOW_RE = /prompt has [\d,]+ tokens?, but the
|
|
|
39
38
|
function isConfiguredContextSizeOverflowError(errorMessage) {
|
|
40
39
|
return CONFIGURED_CONTEXT_SIZE_OVERFLOW_RE.test(errorMessage);
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
41
|
+
const CONTEXT_OVERFLOW_PATTERN_SCOPES = {
|
|
42
|
+
"assistant-error": [
|
|
43
|
+
/prompt is too long/i,
|
|
44
|
+
/request_too_large/i,
|
|
45
|
+
/input length and `?max_tokens`? exceed context limit: [\d,]+ \+ [\d,]+ > [\d,]+/i,
|
|
46
|
+
/input is too long for requested model/i,
|
|
47
|
+
/exceeds the context window/i,
|
|
48
|
+
/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,
|
|
49
|
+
/input token count.*exceeds the maximum/i,
|
|
50
|
+
/maximum prompt length is \d+/i,
|
|
51
|
+
/reduce the length of the messages/i,
|
|
52
|
+
/maximum context length is \d+ tokens/i,
|
|
53
|
+
/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,
|
|
54
|
+
/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,
|
|
55
|
+
/exceeds the limit of \d+/i,
|
|
56
|
+
/exceeds the available context size/i,
|
|
57
|
+
/greater than the context length/i,
|
|
58
|
+
/context window exceeds limit/i,
|
|
59
|
+
/exceeded model token limit/i,
|
|
60
|
+
/tokens? in request more than max tokens? allowed/i,
|
|
61
|
+
/prompt exceeds max(?:imum)? length/i,
|
|
62
|
+
/too large for model with \d+ maximum context length/i,
|
|
63
|
+
CONFIGURED_CONTEXT_SIZE_OVERFLOW_RE,
|
|
64
|
+
/model_context_window_exceeded/i,
|
|
65
|
+
/prompt too long; exceeded (?:max )?context length/i,
|
|
66
|
+
/context[_ ]length[_ ]exceeded/i,
|
|
67
|
+
/too many tokens/i,
|
|
68
|
+
/token limit exceeded/i,
|
|
69
|
+
/^413\s*(?:status code)?\s*\(no body\)/i
|
|
70
|
+
],
|
|
71
|
+
"failover-explicit": [
|
|
72
|
+
/request_too_large/i,
|
|
73
|
+
/context_overflow/i,
|
|
74
|
+
CONFIGURED_CONTEXT_SIZE_OVERFLOW_RE,
|
|
75
|
+
/invalid_argument[\s\S]*maximum number of tokens/i,
|
|
76
|
+
/request exceeds the maximum size/i,
|
|
77
|
+
/context length exceeded/i,
|
|
78
|
+
/maximum context length/i,
|
|
79
|
+
/prompt is too long/i,
|
|
80
|
+
/prompt too long/i,
|
|
81
|
+
/exceeds model context window/i,
|
|
82
|
+
/model token limit/i,
|
|
83
|
+
/input exceeds[\s\S]*maximum number of tokens/i,
|
|
84
|
+
/^(?=[\s\S]*context window)(?=[\s\S]*ran out of (?:room|space))/i,
|
|
85
|
+
/request size exceeds[\s\S]*context window/i,
|
|
86
|
+
/context overflow:/i,
|
|
87
|
+
/exceed context limit/i,
|
|
88
|
+
/exceeds the model'?s maximum context/i,
|
|
89
|
+
/max_tokens[\s\S]*exceed[\s\S]*context/i,
|
|
90
|
+
/input length[\s\S]*exceed[\s\S]*context/i,
|
|
91
|
+
/413[\s\S]*too large/i,
|
|
92
|
+
/context_window_exceeded/i,
|
|
93
|
+
/input length [\d,]+\s+tokens? exceeds the model limit/i,
|
|
94
|
+
/上下文过长|上下文超出|上下文长度超|超出最大上下文|请压缩上下文/
|
|
95
|
+
],
|
|
96
|
+
"provider-fallback": [
|
|
97
|
+
/\binput token count exceeds the maximum number of input tokens\b/i,
|
|
98
|
+
/\binput is too long for this model\b/i,
|
|
99
|
+
/\binput exceeds the maximum number of tokens\b/i,
|
|
100
|
+
/\bollama error:\s*context length exceeded(?:,\s*too many tokens)?\b/i,
|
|
101
|
+
/\btotal tokens?.*exceeds? (?:the )?(?:model(?:'s)? )?(?:max|maximum|limit)/i,
|
|
102
|
+
/\b(?:request|prompt) \(\d[\d,]*\s*tokens?\) exceeds (?:the )?available context size\b/i,
|
|
103
|
+
/\binput (?:is )?too long for (?:the )?model\b/i
|
|
104
|
+
],
|
|
105
|
+
"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],
|
|
106
|
+
"context-window-too-small": [/context window.*(too small|minimum is)/i],
|
|
107
|
+
"tpm-rate-limit-hint": [/\btpm\b|tokens per minute/i],
|
|
108
|
+
"rate-limit-hint": [/rate limit|too many requests|requests per (?:minute|hour|day)|quota|throttl|429\b|tokens per day/i]
|
|
109
|
+
};
|
|
110
|
+
/** Match one canonical context-overflow wording scope without applying caller policy. */
|
|
111
|
+
function matchesContextOverflowMessage(errorMessage, scope) {
|
|
112
|
+
return CONTEXT_OVERFLOW_PATTERN_SCOPES[scope].some((pattern) => pattern.test(errorMessage));
|
|
113
|
+
}
|
|
102
114
|
/**
|
|
103
115
|
* Patterns that indicate non-overflow errors (e.g. rate limiting, server errors).
|
|
104
|
-
* Error messages matching
|
|
116
|
+
* Error messages matching any of these are excluded from overflow detection
|
|
105
117
|
* even if they also match an OVERFLOW_PATTERN.
|
|
106
118
|
*
|
|
107
119
|
* Example: Bedrock formats throttling errors as "ThrottlingException: Too many tokens,
|
|
@@ -135,7 +147,7 @@ function resolveContextInputTokens(message) {
|
|
|
135
147
|
* - Google Gemini: "input token count exceeds the maximum"
|
|
136
148
|
* - xAI (Grok): "maximum prompt length is X but request contains Y"
|
|
137
149
|
* - Groq: "reduce the length of the messages"
|
|
138
|
-
* - Cerebras:
|
|
150
|
+
* - Cerebras: 413 status code (no body)
|
|
139
151
|
* - Mistral: "Prompt contains X tokens ... too large for model with Y maximum context length"
|
|
140
152
|
* - OpenRouter (all backends): "maximum context length is X tokens"
|
|
141
153
|
* - Together AI: "The input (X tokens) is longer than the model's context length (Y tokens)."
|
|
@@ -162,7 +174,7 @@ function resolveContextInputTokens(message) {
|
|
|
162
174
|
* 1. Send a request that exceeds the model's context window
|
|
163
175
|
* 2. Check the errorMessage in the response
|
|
164
176
|
* 3. Create a regex pattern that matches the error
|
|
165
|
-
* 4. The pattern should be added to
|
|
177
|
+
* 4. The pattern should be added to the appropriate canonical scope in this file, or
|
|
166
178
|
* check the errorMessage yourself before calling this function
|
|
167
179
|
*
|
|
168
180
|
* @param message - The assistant message to check
|
|
@@ -172,7 +184,7 @@ function resolveContextInputTokens(message) {
|
|
|
172
184
|
function isContextOverflow(message, contextWindow) {
|
|
173
185
|
if (message.stopReason === "error" && message.errorMessage) {
|
|
174
186
|
const errorMessage = message.errorMessage;
|
|
175
|
-
if (!NON_OVERFLOW_PATTERNS.some((p) => p.test(errorMessage)) &&
|
|
187
|
+
if (!NON_OVERFLOW_PATTERNS.some((p) => p.test(errorMessage)) && matchesContextOverflowMessage(errorMessage, "assistant-error")) return true;
|
|
176
188
|
}
|
|
177
189
|
if (contextWindow && message.stopReason === "stop") {
|
|
178
190
|
const inputTokens = resolveContextInputTokens(message);
|
|
@@ -185,4 +197,4 @@ function isContextOverflow(message, contextWindow) {
|
|
|
185
197
|
return false;
|
|
186
198
|
}
|
|
187
199
|
//#endregion
|
|
188
|
-
export { applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
200
|
+
export { applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, matchesContextOverflowMessage, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as Model,
|
|
1
|
+
import { E as Model, G as ThinkingBudgets, H as StreamOptions, R as SimpleStreamOptions, T as Message, i as AssistantMessage, n as Api, q as ThinkingLevel } from "../types-BHNrPS1l.mjs";
|
|
2
2
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
3
3
|
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-Cwcjv_fx.mjs";
|
|
4
4
|
|
|
@@ -32,11 +32,6 @@ declare function extractToolResultBlockText(block: unknown): string | undefined;
|
|
|
32
32
|
declare function extractToolResultText(blocks: readonly unknown[]): string;
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region packages/ai/src/transcript-transform.d.ts
|
|
35
|
-
/**
|
|
36
|
-
* Normalize tool call ID for cross-provider compatibility.
|
|
37
|
-
* OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.
|
|
38
|
-
* Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).
|
|
39
|
-
*/
|
|
40
35
|
declare function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>, normalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string): Message[];
|
|
41
36
|
//#endregion
|
|
42
37
|
//#region packages/ai/src/utils/system-prompt-cache-boundary.d.ts
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import { i as clampReasoning, n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking } from "../simple-options-9lhRrN73.mjs";
|
|
5
|
-
import "../transform-messages-C8mBqZxF.mjs";
|
|
1
|
+
import { t as sanitizeSurrogates } from "../sanitize-unicode-BYqrYtC_.mjs";
|
|
2
|
+
import { a as describeToolResultMediaPlaceholder, c as hasMediaPayload, i as transformMessages, l as isImageWithMediaPayload, o as extractToolResultBlockText, s as extractToolResultText } from "../host-DTqNc7ad.mjs";
|
|
3
|
+
import { a as SYSTEM_PROMPT_CACHE_BOUNDARY, c as splitSystemPromptCacheBoundary, d as normalizeStructuredPromptSection, f as sortPromptCacheToolsByName, i as clampReasoning, l as stripSystemPromptCacheBoundary, n as buildBaseOptions, o as ensureSystemPromptCacheBoundary, r as clampMaxTokensToModel, s as prependSystemPromptAdditionAfterCacheBoundary, t as adjustMaxTokensForThinking, u as normalizePromptCapabilityIds } from "../simple-options-D58D5Kvw.mjs";
|
|
6
4
|
import { t as inspectTlsCertificateError } from "../tls-certificate-errors-DXSpluKI.mjs";
|
|
7
5
|
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as asNonArrayRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
1
2
|
import { parse } from "partial-json";
|
|
2
3
|
//#region packages/ai/src/utils/json-parse.ts
|
|
3
4
|
const VALID_JSON_ESCAPES = /* @__PURE__ */ new Set([
|
|
@@ -102,9 +103,6 @@ function looksLikeWindowsPathPrefix(prefix) {
|
|
|
102
103
|
const tail = prefix.slice(-160);
|
|
103
104
|
return /(?:^|[^A-Za-z0-9])[A-Za-z]:(?:[\\/][^"\\/:*?<>|\r\n]*)*$/.test(tail);
|
|
104
105
|
}
|
|
105
|
-
function asStreamingJsonRecord(value) {
|
|
106
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
107
|
-
}
|
|
108
106
|
/**
|
|
109
107
|
* Attempts to parse potentially incomplete JSON during streaming.
|
|
110
108
|
* Always returns a valid object, even if the JSON is incomplete.
|
|
@@ -115,13 +113,13 @@ function asStreamingJsonRecord(value) {
|
|
|
115
113
|
function parseStreamingJson(partialJson) {
|
|
116
114
|
if (!partialJson || partialJson.trim() === "") return {};
|
|
117
115
|
try {
|
|
118
|
-
return
|
|
116
|
+
return asNonArrayRecord(parseJsonWithRepair(partialJson));
|
|
119
117
|
} catch {
|
|
120
118
|
try {
|
|
121
|
-
return
|
|
119
|
+
return asNonArrayRecord(parse(partialJson));
|
|
122
120
|
} catch {
|
|
123
121
|
try {
|
|
124
|
-
return
|
|
122
|
+
return asNonArrayRecord(parse(repairJson(partialJson)));
|
|
125
123
|
} catch {
|
|
126
124
|
return {};
|
|
127
125
|
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import { i as
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
6
|
-
import {
|
|
7
|
-
import { n as
|
|
8
|
-
import {
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-BYqrYtC_.mjs";
|
|
4
|
+
import { a as describeToolResultMediaPlaceholder, l as isImageWithMediaPayload, n as getAiTransportHost, s as extractToolResultText } from "./host-DTqNc7ad.mjs";
|
|
5
|
+
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
6
|
+
import { n as projectProviderError } from "./provider-error-BUwEnjXq.mjs";
|
|
7
|
+
import { f as sortPromptCacheToolsByName, l as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-D58D5Kvw.mjs";
|
|
8
|
+
import { n as parseStreamingJson } from "./json-parse-CDnesDM_.mjs";
|
|
9
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import "./transform-messages-C8mBqZxF.mjs";
|
|
10
|
+
import { f as transportAbortError, t as transformProviderMessages } from "./provider-transcript-transform-ePx-Bbfr.mjs";
|
|
12
11
|
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
13
12
|
import { randomUUID } from "node:crypto";
|
|
14
13
|
import { HTTPClient, Mistral } from "@mistralai/mistralai";
|
|
15
14
|
//#region packages/ai/src/providers/mistral.ts
|
|
16
15
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
17
|
-
const MAX_MISTRAL_ERROR_BODY_CHARS = 4e3;
|
|
18
16
|
const MISTRAL_STREAM_BODY_MAX_BYTES = 16 * 1024 * 1024;
|
|
19
17
|
/**
|
|
20
18
|
* Builds a `Fetcher` that wraps the default `fetch` with a 16 MiB byte cap
|
|
@@ -71,7 +69,7 @@ const streamMistral = (model, context, options) => {
|
|
|
71
69
|
httpClient: new HTTPClient({ fetcher: createBoundedMistralFetcher(MISTRAL_STREAM_BODY_MAX_BYTES, getAiTransportHost().buildModelFetch(model) ?? fetch) })
|
|
72
70
|
});
|
|
73
71
|
const normalizeMistralToolCallId = createMistralToolCallIdNormalizer();
|
|
74
|
-
let payload = buildChatPayload(model, context,
|
|
72
|
+
let payload = buildChatPayload(model, context, transformProviderMessages(context.messages, model, (id) => normalizeMistralToolCallId(id)), options);
|
|
75
73
|
const nextPayload = await options?.onPayload?.(payload, model);
|
|
76
74
|
if (nextPayload !== void 0) payload = nextPayload;
|
|
77
75
|
const headers = {
|
|
@@ -97,12 +95,12 @@ const streamMistral = (model, context, options) => {
|
|
|
97
95
|
});
|
|
98
96
|
stream.end();
|
|
99
97
|
} catch (error) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
output
|
|
98
|
+
output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
99
|
+
const terminal = projectProviderError(error, options?.signal);
|
|
100
|
+
Object.assign(output, terminal);
|
|
103
101
|
stream.push({
|
|
104
102
|
type: "error",
|
|
105
|
-
reason:
|
|
103
|
+
reason: terminal.stopReason,
|
|
106
104
|
error: output
|
|
107
105
|
});
|
|
108
106
|
stream.end();
|
|
@@ -179,30 +177,6 @@ function deriveMistralToolCallId(id, attempt) {
|
|
|
179
177
|
const seedBase = normalized || id;
|
|
180
178
|
return shortHash(attempt === 0 ? seedBase : `${seedBase}:${attempt}`).replace(/[^a-zA-Z0-9]/g, "").padEnd(MISTRAL_TOOL_CALL_ID_LENGTH, "0").slice(0, MISTRAL_TOOL_CALL_ID_LENGTH);
|
|
181
179
|
}
|
|
182
|
-
function formatMistralError(error) {
|
|
183
|
-
if (error instanceof Error) {
|
|
184
|
-
const sdkError = error;
|
|
185
|
-
const statusCode = typeof sdkError.statusCode === "number" ? sdkError.statusCode : void 0;
|
|
186
|
-
const bodyText = typeof sdkError.body === "string" ? sdkError.body.trim() : void 0;
|
|
187
|
-
if (statusCode !== void 0 && bodyText) return `Mistral API error (${statusCode}): ${truncateErrorText(bodyText, MAX_MISTRAL_ERROR_BODY_CHARS)}`;
|
|
188
|
-
if (statusCode !== void 0) return `Mistral API error (${statusCode}): ${error.message}`;
|
|
189
|
-
return error.message;
|
|
190
|
-
}
|
|
191
|
-
return safeJsonStringify(error);
|
|
192
|
-
}
|
|
193
|
-
function truncateErrorText(text, maxChars) {
|
|
194
|
-
if (text.length <= maxChars) return text;
|
|
195
|
-
const truncated = truncateUtf16Safe(text, maxChars);
|
|
196
|
-
return `${truncated}... [truncated ${text.length - truncated.length} chars]`;
|
|
197
|
-
}
|
|
198
|
-
function safeJsonStringify(value) {
|
|
199
|
-
try {
|
|
200
|
-
const serialized = JSON.stringify(value);
|
|
201
|
-
return serialized === void 0 ? String(value) : serialized;
|
|
202
|
-
} catch {
|
|
203
|
-
return String(value);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
180
|
function buildChatPayload(model, context, messages, options) {
|
|
207
181
|
const payload = {
|
|
208
182
|
model: model.id,
|
|
@@ -243,6 +217,7 @@ function readMistralCachedPromptTokens(usage, promptTokens) {
|
|
|
243
217
|
}
|
|
244
218
|
async function consumeChatStream(model, output, stream, mistralStream) {
|
|
245
219
|
let currentBlock = null;
|
|
220
|
+
let terminalFinishReason;
|
|
246
221
|
const blocks = output.content;
|
|
247
222
|
const blockIndex = () => blocks.length - 1;
|
|
248
223
|
const toolBlockIdentities = /* @__PURE__ */ new Map();
|
|
@@ -337,7 +312,10 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
337
312
|
}
|
|
338
313
|
const choice = chunk.choices[0];
|
|
339
314
|
if (!choice) continue;
|
|
340
|
-
if (choice.finishReason)
|
|
315
|
+
if (choice.finishReason) {
|
|
316
|
+
terminalFinishReason = choice.finishReason;
|
|
317
|
+
output.stopReason = mapChatStopReason(choice.finishReason);
|
|
318
|
+
}
|
|
341
319
|
const delta = choice.delta;
|
|
342
320
|
if (delta.content !== null && delta.content !== void 0) {
|
|
343
321
|
const contentItems = typeof delta.content === "string" ? [delta.content] : delta.content;
|
|
@@ -484,6 +462,19 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
484
462
|
}
|
|
485
463
|
}
|
|
486
464
|
finishCurrentBlock(currentBlock);
|
|
465
|
+
if (!terminalFinishReason || output.stopReason !== "toolUse") {
|
|
466
|
+
blocks.splice(0, blocks.length, ...blocks.filter((block) => block.type !== "toolCall"));
|
|
467
|
+
if (!terminalFinishReason) throw new Error("Mistral stream ended without a terminal finish reason");
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
for (const index of toolBlockIdentities.keys()) {
|
|
472
|
+
const rawArguments = blocks[index].partialArgs ?? "";
|
|
473
|
+
if (!isRecord(JSON.parse(rawArguments))) throw new Error("Mistral tool-call arguments must be a JSON object");
|
|
474
|
+
}
|
|
475
|
+
} catch {
|
|
476
|
+
throw new Error("Mistral completed tool call has invalid JSON arguments");
|
|
477
|
+
}
|
|
487
478
|
for (const index of toolBlockIdentities.keys()) {
|
|
488
479
|
const block = output.content.at(index);
|
|
489
480
|
if (block?.type !== "toolCall") continue;
|
|
@@ -498,21 +489,27 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
498
489
|
}
|
|
499
490
|
}
|
|
500
491
|
function toFunctionTools(tools) {
|
|
501
|
-
return tools.flatMap((tool) => {
|
|
492
|
+
return sortPromptCacheToolsByName(tools.flatMap((tool) => {
|
|
502
493
|
try {
|
|
494
|
+
const name = tool.name;
|
|
495
|
+
const description = tool.description;
|
|
503
496
|
return {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
497
|
+
name,
|
|
498
|
+
description,
|
|
499
|
+
value: {
|
|
500
|
+
type: "function",
|
|
501
|
+
function: {
|
|
502
|
+
name,
|
|
503
|
+
description,
|
|
504
|
+
parameters: stripSymbolKeys(tool.parameters),
|
|
505
|
+
strict: false
|
|
506
|
+
}
|
|
510
507
|
}
|
|
511
508
|
};
|
|
512
509
|
} catch {
|
|
513
510
|
return [];
|
|
514
511
|
}
|
|
515
|
-
});
|
|
512
|
+
})).map(({ value }) => value);
|
|
516
513
|
}
|
|
517
514
|
function stripSymbolKeys(value) {
|
|
518
515
|
if (Array.isArray(value)) return value.map((item) => stripSymbolKeys(item));
|