@openclaw/ai 2026.9.6 → 2026.9.7
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-DZQ_7gD1.mjs → anthropic-Cw2pgccz.mjs} +37 -66
- package/dist/{anthropic-payload-policy-DyfwikYJ.d.mts → anthropic-payload-policy-NIPVYXPq.d.mts} +7 -5
- package/dist/{anthropic-stream-reducer-D6ZI1wwj.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs} +192 -261
- package/dist/{api-registry-C2T3lTV7.d.mts → api-registry-D-nbmSqr.d.mts} +2 -2
- package/dist/{azure-openai-responses-DS86GYzq.mjs → azure-openai-responses-BwT3-X8P.mjs} +22 -33
- package/dist/{base64-CPmadnUf.mjs → base64-C1PsYcRQ.mjs} +15 -9
- package/dist/{diagnostics-CH8j2wIG.mjs → diagnostics-CJaB6g8J.mjs} +3 -3
- package/dist/diagnostics.d.mts +4 -4
- package/dist/diagnostics.mjs +2 -2
- package/dist/{env-api-keys-bktO00EJ.mjs → env-api-keys-CyX4VKGO.mjs} +7 -5
- package/dist/event-stream-CMQfX_yr.d.mts +1 -0
- package/dist/{event-stream-CjnIZZst.d.mts → event-stream-DOPFYVqs.d.mts} +2 -2
- package/dist/{event-stream-D8PARQfL.mjs → event-stream-vd9UnCAU.mjs} +10 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-BZJFjhuC.mjs → google-BfapkS_K.mjs} +8 -11
- package/dist/google-interactions-DW3iXzjc.mjs +574 -0
- package/dist/{google-messages-DB7GKkDk.mjs → google-messages-CtjVtVot.mjs} +35 -71
- package/dist/{google-shared-Bok4I6zB.mjs → google-shared-Y2YfotEu.mjs} +43 -47
- package/dist/{google-vertex-3eVNR2qW.mjs → google-vertex-Dov4kBWu.mjs} +16 -30
- package/dist/{host-yTvBrYM2.mjs → host-CHi3X87F.mjs} +29 -188
- package/dist/{host-policy-DZO3oPPk.mjs → host-policy-BOAwRg_M.mjs} +2 -14
- package/dist/{host-DH-Z-LDb.d.mts → host-rxlNaBwm.d.mts} +9 -3
- package/dist/{index-C25RT6bP.d.mts → index-D6KsSE74.d.mts} +28 -8
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +8 -7
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +31 -8
- package/dist/internal/openai.mjs +13 -13
- package/dist/internal/runtime.d.mts +31 -70
- package/dist/internal/runtime.mjs +10 -65
- package/dist/internal/shared.d.mts +14 -12
- package/dist/internal/shared.mjs +5 -4
- package/dist/internal/tool-schema.d.mts +1 -1
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-C_13dVBn.mjs → mistral-RS6mboC-.mjs} +46 -93
- package/dist/{openai-chatgpt-responses-sTxPl4zM.mjs → openai-chatgpt-responses-CYbidtrn.mjs} +26 -30
- package/dist/{openai-completions-BO6D_hrB.mjs → openai-completions-D14ihPYk.mjs} +14 -12
- package/dist/{openai-completions-compat-CUollwl6.mjs → openai-completions-compat-BOVWBZDn.mjs} +3 -5
- package/dist/{openai-completions-compat-DfJG1wSO.d.mts → openai-completions-compat-qJjmqQ71.d.mts} +3 -3
- package/dist/{openai-completions-stream-BpuJ0ZOA.mjs → openai-completions-stream-CDCuw3DP.mjs} +101 -173
- package/dist/{openai-prompt-cache-C4RHdN4n.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
- package/dist/{openai-prompt-cache-CjV_2IRI.mjs → openai-prompt-cache-D2V7MqR7.mjs} +1 -1
- package/dist/{openai-provider-client-BP8J1aeg.mjs → openai-provider-client-CwfsGBbA.mjs} +2 -2
- package/dist/{openai-reasoning-effort-ash8dPrd.mjs → openai-reasoning-effort-ConhwkeX.mjs} +2 -1
- package/dist/{openai-responses-BJ_IEoMU.mjs → openai-responses-CKCBEc2W.mjs} +12 -11
- package/dist/openai-responses-compaction-replay-DiYn-gFM.d.mts +12 -0
- package/dist/{openai-responses-compaction-window-BiNCT0bS.mjs → openai-responses-compaction-window-UNK1GDpy.mjs} +5 -5
- package/dist/{openai-responses-contracts-DWrfMODE.mjs → openai-responses-contracts-CLxnqS9p.mjs} +1 -1
- package/dist/{openai-responses-contracts-B1ENJFpI.d.mts → openai-responses-contracts-D1iZ0njF.d.mts} +4 -4
- package/dist/{openai-responses-prompt-observer-internal-DPHWgbBH.mjs → openai-responses-prompt-observer-internal-iAqLb4tk.mjs} +12 -12
- package/dist/{openai-responses-request-lifecycle-DFuyO1pQ.mjs → openai-responses-request-lifecycle-Fsag-IGZ.mjs} +1 -1
- package/dist/{openai-responses-shared-DvSqtJ6_.mjs → openai-responses-shared-DL4ulQn7.mjs} +312 -122
- package/dist/{openai-responses-terminal-usage-BNFbvY9f.d.mts → openai-responses-terminal-usage-BE7lf7nW.d.mts} +2 -2
- package/dist/{openai-stop-reason-Drnn_6Qj.mjs → openai-stop-reason-8s70vDXj.mjs} +2 -12
- package/dist/{openai-tool-schema-ynZBgqW-.d.mts → openai-tool-schema-a5ysBBga.d.mts} +0 -6
- package/dist/{openai-tool-schema-D4BMcj2D.mjs → openai-tool-schema-vsl-cE-n.mjs} +243 -383
- package/dist/{openai-transport-params-DZKOTSfH.mjs → openai-transport-params-BwlpzX-2.mjs} +60 -105
- package/dist/{positive-integer-BiUxrd71.mjs → positive-integer-CjN5OJbH.mjs} +1 -1
- package/dist/{provider-error-CRhW7lkJ.mjs → provider-error-CwT_j2v0.mjs} +43 -4
- package/dist/{provider-options-DZYq53lj.d.mts → provider-options-Df7ov0K1.d.mts} +2 -2
- package/dist/{provider-replay-context-DPr3w20a.mjs → provider-replay-context-DsyI5jOP.mjs} +1 -1
- package/dist/{provider-transcript-transform-BTocjCRs.mjs → provider-transcript-transform-JbFbHV8h.mjs} +17 -2
- package/dist/{provider-transport-turn-state-lrXEFkYr.mjs → provider-transport-turn-state-BheUi_hl.mjs} +1 -1
- package/dist/{provider-types-w1rEqrGP.d.mts → provider-types-d4XnoZMd.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +15 -11
- package/dist/{reasoning-tag-text-partitioner-Di38crhI.mjs → reasoning-tag-text-partitioner-B6FIIBt6.mjs} +47 -71
- package/dist/{record-coerce-DwRYMj3t.mjs → record-coerce-CNDovvft.mjs} +1 -1
- package/dist/simple-options-CGAkCwtM.mjs +349 -0
- package/dist/{src-DwGYYyZp.mjs → src-H4aXcFuX.mjs} +43 -25
- package/dist/{stream-CREqxHgU.mjs → stream-DDsCBgd-.mjs} +1 -7
- package/dist/{stream-first-event-timeout-BeptfRL6.mjs → stream-first-event-timeout-B9o0S4SZ.mjs} +1 -1
- package/dist/{tool-schema-json-projection-CD9c_fK8.mjs → tool-schema-json-projection-Ct8SeBeJ.mjs} +63 -23
- package/dist/{transport-stream-shared-B5RioB_Q.mjs → transport-stream-shared-Dh5qKJ8e.mjs} +62 -28
- package/dist/{transport-stream-shared-B7Z9oCYg.d.mts → transport-stream-shared-yYhXa4kX.d.mts} +12 -6
- package/dist/{transport-utils-03Qi0CN2.mjs → transport-utils-C-4bf2Ok.mjs} +3 -4
- package/dist/transports.d.mts +36 -32
- package/dist/transports.mjs +160 -216
- package/dist/types-CB-_vNyI.d.mts +1 -0
- package/dist/{types-qZFbaDbK.d.mts → types-CLLR3eB4.d.mts} +3 -1
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/{validation-Dw7cb6BV.mjs → validation-BFZc40Ig.mjs} +80 -54
- package/dist/{validation-DhQhmt6t.d.mts → validation-Cat2wQsc.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +5 -5
- package/dist/assistant-output-DM1JBNs1.mjs +0 -16
- package/dist/event-stream-C0nsgbj2.d.mts +0 -1
- package/dist/simple-options-np1XPuhm.mjs +0 -175
- package/dist/types-DTvddOfm.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./index-D6KsSE74.mjs";
|
|
@@ -88,7 +88,7 @@ declare function appendAssistantMessageDiagnostic(message: {
|
|
|
88
88
|
//#endregion
|
|
89
89
|
//#region packages/llm-core/src/types.d.ts
|
|
90
90
|
/** Provider API families with first-class request/stream adapters in OpenClaw. */
|
|
91
|
-
type KnownApi = "openai-completions" | "mistral-conversations" | "openai-responses" | "azure-openai-responses" | "openai-chatgpt-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-vertex";
|
|
91
|
+
type KnownApi = "openai-completions" | "mistral-conversations" | "openai-responses" | "azure-openai-responses" | "openai-chatgpt-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-interactions" | "google-vertex";
|
|
92
92
|
/** Provider API id; custom providers can use ids outside the built-in set. */
|
|
93
93
|
type Api = KnownApi | (string & {});
|
|
94
94
|
/** Image-generation API families with first-class adapters in OpenClaw. */
|
|
@@ -392,6 +392,8 @@ interface UserMessage {
|
|
|
392
392
|
* carriers are stable prompt-cache anchors.
|
|
393
393
|
*/
|
|
394
394
|
runtimeContextCarrier?: boolean;
|
|
395
|
+
/** Explicit replay-policy retention decision; absent preserves model-derived behavior. */
|
|
396
|
+
runtimeContextCarrierRetained?: boolean;
|
|
395
397
|
}
|
|
396
398
|
/** Assistant turn, including provider identity and final stop state. */
|
|
397
399
|
type AssistantDeliveryTtsFacts = {
|
package/dist/types.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as supportsClaudeFastMode, S as
|
|
2
|
-
import { $ as ThinkingContent, A as ModelCostRates, B as ProviderReplayState, C as KnownImagesApi, D as Message, E as MaybePromise, F as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, G as SimpleStreamOptions, H as ProviderStreamOptions, I as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, J as StreamFunction, K as StopReason, L as PricingTier, M as OpenAICompletionsCompat, N as OpenAIResponsesCompat, O as Model, P as OpenRouterRouting, Q as ThinkingBudgets, R as Provider, S as KnownApi, T as MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE, U as RawModelCostConfig, V as ProviderResponse, W as RawPricingTier, X as TextContent, Y as StreamOptions, Z as TextSignatureV1, _ as ImagesModel, a as AssistantMessage, at as Transport, b as ImagesProvider, c as AssistantMessageEventStreamLike, ct as ValidateToolArgumentsFn, d as Context, dt as DiagnosticErrorInfo, et as ThinkingLevel, f as ImageContent, ft as appendAssistantMessageDiagnostic, g as ImagesInputContent, gt as isProviderRefusalAssistantError, h as ImagesFunction, ht as formatThrownValue, i as AssistantImages, it as ToolResultMessage, j as ModelThinkingLevel, k as ModelCostConfig, l as CacheRetention, lt as VercelGatewayRouting, m as ImagesContext, mt as extractDiagnosticError, n as Api, nt as Tool, o as AssistantMessageEvent, ot as Usage, p as ImagesApi, pt as createAssistantMessageDiagnostic, q as StreamFn, r as AssistantDeliveryTtsFacts, rt as ToolCall, s as AssistantMessageEventStreamContract, st as UserMessage, t as AnthropicMessagesCompat, tt as ThinkingLevelMap, u as CompleteSimpleFn, ut as AssistantMessageDiagnostic, v as ImagesOptions, w as KnownImagesProvider, x as ImagesStopReason, y as ImagesOutputContent, z as ProviderImagesOptions } from "./types-
|
|
3
|
-
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import { n as validateToolCall, t as validateToolArguments } from "./validation-
|
|
5
|
-
import "./types-
|
|
6
|
-
export { AnthropicMessagesCompat, Api, AssistantDeliveryTtsFacts, AssistantImages, AssistantMessage, AssistantMessageDiagnostic, AssistantMessageEvent, AssistantMessageEventStream, AssistantMessageEventStreamContract, AssistantMessageEventStreamLike, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_55_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, CacheRetention, CompleteSimpleFn, Context, DiagnosticErrorInfo, EventStream, ImageContent, ImagesApi, ImagesContext, ImagesFunction, ImagesInputContent, ImagesModel, ImagesOptions, ImagesOutputContent, ImagesProvider, ImagesStopReason, KnownApi, KnownImagesApi, KnownImagesProvider, MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE, MaybePromise, Message, Model, ModelCostConfig, ModelCostRates, ModelThinkingLevel, OpenAICompletionsCompat, OpenAIResponsesCompat, OpenRouterRouting, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, PricingTier, Provider, ProviderImagesOptions, type ProviderRefusalReview, ProviderReplayState, ProviderResponse, ProviderStreamOptions, RawModelCostConfig, RawPricingTier, SimpleStreamOptions, StopReason, StreamFn, StreamFunction, StreamOptions, TextContent, TextSignatureV1, ThinkingBudgets, ThinkingContent, ThinkingLevel, ThinkingLevelMap, Tool, ToolCall, ToolResultMessage, Transport, Usage, UserMessage, ValidateToolArgumentsFn, VercelGatewayRouting, appendAssistantMessageDiagnostic, bindsClaudeThinkingPrefix, calculateUsageCost, createAssistantMessageDiagnostic, createAssistantMessageEventStream, extractDiagnosticError, formatThrownValue, isProviderRefusalAssistantError, normalizeModelCostConfig, normalizeResolvedPricing, readProviderRefusalReview, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus55ModelIdentity, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
1
|
+
import { C as resolveClaudeSonnet5ModelIdentity, D as supportsClaudeNativeMaxEffort, E as supportsClaudeFastMode, O as supportsClaudeNativeXhighEffort, S as resolveClaudeSonnet55ModelIdentity, T as supportsClaudeAdaptiveThinking, _ as resolveClaudeModelIdentity, a as ProviderRefusalReview, b as resolveClaudeOpus55ModelIdentity, c as CLAUDE_OPUS_55_THINKING_PROFILE, d as CLAUDE_SONNET_5_THINKING_PROFILE, f as bindsClaudeThinkingPrefix, g as resolveClaudeFable5ModelIdentity, h as requiresClaudeMandatoryAdaptiveThinking, i as normalizeResolvedPricing, l as CLAUDE_OPUS_5_THINKING_PROFILE, m as requiresClaudeDefaultSampling, n as calculateUsageCost, o as readProviderRefusalReview, p as requiresClaudeBetweenToolsThinking, r as normalizeModelCostConfig, s as CLAUDE_FABLE_5_THINKING_PROFILE, u as CLAUDE_SONNET_55_THINKING_PROFILE, v as resolveClaudeMythos5ModelIdentity, w as supportsClaude1MContext, x as resolveClaudeOpus5ModelIdentity, y as resolveClaudeNativeThinkingLevelMap } from "./index-D6KsSE74.mjs";
|
|
2
|
+
import { $ as ThinkingContent, A as ModelCostRates, B as ProviderReplayState, C as KnownImagesApi, D as Message, E as MaybePromise, F as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, G as SimpleStreamOptions, H as ProviderStreamOptions, I as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, J as StreamFunction, K as StopReason, L as PricingTier, M as OpenAICompletionsCompat, N as OpenAIResponsesCompat, O as Model, P as OpenRouterRouting, Q as ThinkingBudgets, R as Provider, S as KnownApi, T as MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE, U as RawModelCostConfig, V as ProviderResponse, W as RawPricingTier, X as TextContent, Y as StreamOptions, Z as TextSignatureV1, _ as ImagesModel, a as AssistantMessage, at as Transport, b as ImagesProvider, c as AssistantMessageEventStreamLike, ct as ValidateToolArgumentsFn, d as Context, dt as DiagnosticErrorInfo, et as ThinkingLevel, f as ImageContent, ft as appendAssistantMessageDiagnostic, g as ImagesInputContent, gt as isProviderRefusalAssistantError, h as ImagesFunction, ht as formatThrownValue, i as AssistantImages, it as ToolResultMessage, j as ModelThinkingLevel, k as ModelCostConfig, l as CacheRetention, lt as VercelGatewayRouting, m as ImagesContext, mt as extractDiagnosticError, n as Api, nt as Tool, o as AssistantMessageEvent, ot as Usage, p as ImagesApi, pt as createAssistantMessageDiagnostic, q as StreamFn, r as AssistantDeliveryTtsFacts, rt as ToolCall, s as AssistantMessageEventStreamContract, st as UserMessage, t as AnthropicMessagesCompat, tt as ThinkingLevelMap, u as CompleteSimpleFn, ut as AssistantMessageDiagnostic, v as ImagesOptions, w as KnownImagesProvider, x as ImagesStopReason, y as ImagesOutputContent, z as ProviderImagesOptions } from "./types-CLLR3eB4.mjs";
|
|
3
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-DOPFYVqs.mjs";
|
|
4
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-Cat2wQsc.mjs";
|
|
5
|
+
import "./types-CB-_vNyI.mjs";
|
|
6
|
+
export { AnthropicMessagesCompat, Api, AssistantDeliveryTtsFacts, AssistantImages, AssistantMessage, AssistantMessageDiagnostic, AssistantMessageEvent, AssistantMessageEventStream, AssistantMessageEventStreamContract, AssistantMessageEventStreamLike, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_55_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_55_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, CacheRetention, CompleteSimpleFn, Context, DiagnosticErrorInfo, EventStream, ImageContent, ImagesApi, ImagesContext, ImagesFunction, ImagesInputContent, ImagesModel, ImagesOptions, ImagesOutputContent, ImagesProvider, ImagesStopReason, KnownApi, KnownImagesApi, KnownImagesProvider, MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE, MaybePromise, Message, Model, ModelCostConfig, ModelCostRates, ModelThinkingLevel, OpenAICompletionsCompat, OpenAIResponsesCompat, OpenRouterRouting, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, PricingTier, Provider, ProviderImagesOptions, type ProviderRefusalReview, ProviderReplayState, ProviderResponse, ProviderStreamOptions, RawModelCostConfig, RawPricingTier, SimpleStreamOptions, StopReason, StreamFn, StreamFunction, StreamOptions, TextContent, TextSignatureV1, ThinkingBudgets, ThinkingContent, ThinkingLevel, ThinkingLevelMap, Tool, ToolCall, ToolResultMessage, Transport, Usage, UserMessage, ValidateToolArgumentsFn, VercelGatewayRouting, appendAssistantMessageDiagnostic, bindsClaudeThinkingPrefix, calculateUsageCost, createAssistantMessageDiagnostic, createAssistantMessageEventStream, extractDiagnosticError, formatThrownValue, isProviderRefusalAssistantError, normalizeModelCostConfig, normalizeResolvedPricing, readProviderRefusalReview, requiresClaudeBetweenToolsThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus55ModelIdentity, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet55ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
package/dist/types.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as supportsClaudeNativeXhighEffort, _ as
|
|
1
|
+
import { C as supportsClaudeFastMode, S as supportsClaudeAdaptiveThinking, T as supportsClaudeNativeXhighEffort, _ as resolveClaudeOpus55ModelIdentity, a as CLAUDE_OPUS_55_THINKING_PROFILE, b as resolveClaudeSonnet5ModelIdentity, c as CLAUDE_SONNET_5_THINKING_PROFILE, d as requiresClaudeDefaultSampling, f as requiresClaudeMandatoryAdaptiveThinking, g as resolveClaudeNativeThinkingLevelMap, h as resolveClaudeMythos5ModelIdentity, i as CLAUDE_FABLE_5_THINKING_PROFILE, l as bindsClaudeThinkingPrefix, m as resolveClaudeModelIdentity, n as normalizeModelCostConfig, o as CLAUDE_OPUS_5_THINKING_PROFILE, p as resolveClaudeFable5ModelIdentity, r as normalizeResolvedPricing, s as CLAUDE_SONNET_55_THINKING_PROFILE, t as calculateUsageCost, u as requiresClaudeBetweenToolsThinking, v as resolveClaudeOpus5ModelIdentity, w as supportsClaudeNativeMaxEffort, x as supportsClaude1MContext, y as resolveClaudeSonnet55ModelIdentity } from "./src-H4aXcFuX.mjs";
|
|
2
2
|
import { n as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, r as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, t as MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE } from "./types-LFWwv0cF.mjs";
|
|
3
3
|
import { a as isProviderRefusalAssistantError, i as formatThrownValue, n as createAssistantMessageDiagnostic, o as readProviderRefusalReview, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-DzrF1h4J.mjs";
|
|
4
|
-
import { i as createAssistantMessageEventStream, n as EventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
5
|
-
import { n as validateToolCall, t as validateToolArguments } from "./validation-
|
|
6
|
-
export { AssistantMessageEventStream, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_55_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, EventStream, MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, appendAssistantMessageDiagnostic, bindsClaudeThinkingPrefix, calculateUsageCost, createAssistantMessageDiagnostic, createAssistantMessageEventStream, extractDiagnosticError, formatThrownValue, isProviderRefusalAssistantError, normalizeModelCostConfig, normalizeResolvedPricing, readProviderRefusalReview, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus55ModelIdentity, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
4
|
+
import { i as createAssistantMessageEventStream, n as EventStream, t as AssistantMessageEventStream } from "./event-stream-vd9UnCAU.mjs";
|
|
5
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-BFZc40Ig.mjs";
|
|
6
|
+
export { AssistantMessageEventStream, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_55_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_55_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, EventStream, MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, appendAssistantMessageDiagnostic, bindsClaudeThinkingPrefix, calculateUsageCost, createAssistantMessageDiagnostic, createAssistantMessageEventStream, extractDiagnosticError, formatThrownValue, isProviderRefusalAssistantError, normalizeModelCostConfig, normalizeResolvedPricing, readProviderRefusalReview, requiresClaudeBetweenToolsThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus55ModelIdentity, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet55ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Compile } from "typebox/compile";
|
|
2
|
+
import { Pointer } from "typebox/schema";
|
|
2
3
|
//#region packages/llm-core/src/validation.ts
|
|
3
4
|
const validatorCache = /* @__PURE__ */ new WeakMap();
|
|
4
5
|
/** Maximum string length accepted for schema-gated JSON coercion. */
|
|
@@ -9,7 +10,32 @@ function isObjectBackedRecord(value) {
|
|
|
9
10
|
function isJsonSchemaObject(value) {
|
|
10
11
|
return isObjectBackedRecord(value);
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function hasSchemaScope(schema) {
|
|
14
|
+
return [
|
|
15
|
+
"$id",
|
|
16
|
+
"id",
|
|
17
|
+
"$defs",
|
|
18
|
+
"definitions"
|
|
19
|
+
].some((key) => key in schema);
|
|
20
|
+
}
|
|
21
|
+
function resolveRootSchemaRef(schema, root) {
|
|
22
|
+
const match = typeof schema.$ref === "string" ? schema.$ref.match(/^#\/(\$defs|definitions)\/([^/]+)$/) : null;
|
|
23
|
+
const encodedName = match?.[2];
|
|
24
|
+
if (!root || !match || encodedName === void 0 || hasSchemaScope(schema)) return;
|
|
25
|
+
const table = match[1] === "$defs" ? root.$defs : root.definitions;
|
|
26
|
+
const name = encodedName.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
27
|
+
const target = table && Object.hasOwn(table, name) ? table[name] : void 0;
|
|
28
|
+
return isJsonSchemaObject(target) && !hasSchemaScope(target) ? target : void 0;
|
|
29
|
+
}
|
|
30
|
+
function getSchemaTypes(initialSchema, root) {
|
|
31
|
+
let schema = initialSchema;
|
|
32
|
+
const seen = /* @__PURE__ */ new Set();
|
|
33
|
+
while (schema.type === void 0 && !seen.has(schema)) {
|
|
34
|
+
seen.add(schema);
|
|
35
|
+
const target = resolveRootSchemaRef(schema, root);
|
|
36
|
+
if (!target) break;
|
|
37
|
+
schema = target;
|
|
38
|
+
}
|
|
13
39
|
if (typeof schema.type === "string") return [schema.type];
|
|
14
40
|
if (Array.isArray(schema.type)) return schema.type.filter((type) => typeof type === "string");
|
|
15
41
|
return [];
|
|
@@ -36,14 +62,10 @@ function parseJsonNumberString(value) {
|
|
|
36
62
|
const parsed = Number(trimmed);
|
|
37
63
|
return Number.isFinite(parsed) ? parsed : void 0;
|
|
38
64
|
}
|
|
39
|
-
function
|
|
40
|
-
const parsed = parseJsonNumberString(value);
|
|
41
|
-
return parsed !== void 0 && Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
42
|
-
}
|
|
43
|
-
function getSubSchemaValidator(schema) {
|
|
65
|
+
function getSubSchemaValidator(schema, root) {
|
|
44
66
|
if (!isValidatorSchema(schema)) return;
|
|
45
67
|
try {
|
|
46
|
-
return getValidator(schema);
|
|
68
|
+
return getValidator(schema, hasSchemaScope(schema) ? void 0 : root);
|
|
47
69
|
} catch {
|
|
48
70
|
return;
|
|
49
71
|
}
|
|
@@ -51,18 +73,11 @@ function getSubSchemaValidator(schema) {
|
|
|
51
73
|
function coercePrimitiveByType(value, type) {
|
|
52
74
|
switch (type) {
|
|
53
75
|
case "number":
|
|
54
|
-
if (value === null) return 0;
|
|
55
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
56
|
-
const parsed = parseJsonNumberString(value);
|
|
57
|
-
if (parsed !== void 0) return parsed;
|
|
58
|
-
}
|
|
59
|
-
if (typeof value === "boolean") return value ? 1 : 0;
|
|
60
|
-
return value;
|
|
61
76
|
case "integer":
|
|
62
77
|
if (value === null) return 0;
|
|
63
|
-
if (typeof value === "string"
|
|
64
|
-
const parsed =
|
|
65
|
-
if (parsed !== void 0) return parsed;
|
|
78
|
+
if (typeof value === "string") {
|
|
79
|
+
const parsed = parseJsonNumberString(value);
|
|
80
|
+
if (parsed !== void 0 && (type === "number" || Number.isSafeInteger(parsed))) return parsed;
|
|
66
81
|
}
|
|
67
82
|
if (typeof value === "boolean") return value ? 1 : 0;
|
|
68
83
|
return value;
|
|
@@ -82,15 +97,10 @@ function coercePrimitiveByType(value, type) {
|
|
|
82
97
|
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
83
98
|
return value;
|
|
84
99
|
case "array":
|
|
85
|
-
if (typeof value === "string" && value.trim() !== "" && value.length <= MAX_JSON_COERCE_LENGTH) try {
|
|
86
|
-
const parsed = JSON.parse(value);
|
|
87
|
-
if (Array.isArray(parsed)) return parsed;
|
|
88
|
-
} catch {}
|
|
89
|
-
return value;
|
|
90
100
|
case "object":
|
|
91
101
|
if (typeof value === "string" && value.trim() !== "" && value.length <= MAX_JSON_COERCE_LENGTH) try {
|
|
92
102
|
const parsed = JSON.parse(value);
|
|
93
|
-
if (
|
|
103
|
+
if (matchesJsonType(parsed, type)) return parsed;
|
|
94
104
|
} catch {}
|
|
95
105
|
return value;
|
|
96
106
|
case "null":
|
|
@@ -99,47 +109,56 @@ function coercePrimitiveByType(value, type) {
|
|
|
99
109
|
default: return value;
|
|
100
110
|
}
|
|
101
111
|
}
|
|
102
|
-
function applySchemaObjectCoercion(value, schema) {
|
|
112
|
+
function applySchemaObjectCoercion(value, schema, root) {
|
|
103
113
|
const properties = schema.properties;
|
|
104
|
-
const
|
|
114
|
+
const propertyKeys = properties ? Object.keys(properties) : [];
|
|
105
115
|
if (properties) {
|
|
106
|
-
for (const [key, propertySchema] of Object.entries(properties)) if (key in value) value[key] = coerceWithJsonSchema(value[key], propertySchema);
|
|
116
|
+
for (const [key, propertySchema] of Object.entries(properties)) if (key in value) value[key] = coerceWithJsonSchema(value[key], propertySchema, root);
|
|
107
117
|
}
|
|
108
118
|
if (schema.additionalProperties && isJsonSchemaObject(schema.additionalProperties)) {
|
|
109
|
-
|
|
119
|
+
const definedKeys = new Set(propertyKeys);
|
|
120
|
+
for (const [key, propertyValue] of Object.entries(value)) if (!definedKeys.has(key)) value[key] = coerceWithJsonSchema(propertyValue, schema.additionalProperties, root);
|
|
110
121
|
}
|
|
111
122
|
}
|
|
112
|
-
function applySchemaArrayCoercion(value, schema) {
|
|
123
|
+
function applySchemaArrayCoercion(value, schema, root) {
|
|
113
124
|
if (Array.isArray(schema.items)) {
|
|
114
125
|
for (let index = 0; index < value.length; index++) {
|
|
115
126
|
const itemSchema = schema.items[index];
|
|
116
|
-
if (itemSchema) value[index] = coerceWithJsonSchema(value[index], itemSchema);
|
|
127
|
+
if (itemSchema) value[index] = coerceWithJsonSchema(value[index], itemSchema, root);
|
|
117
128
|
}
|
|
118
129
|
return;
|
|
119
130
|
}
|
|
120
|
-
if (isJsonSchemaObject(schema.items)) for (let index = 0; index < value.length; index++) value[index] = coerceWithJsonSchema(value[index], schema.items);
|
|
131
|
+
if (isJsonSchemaObject(schema.items)) for (let index = 0; index < value.length; index++) value[index] = coerceWithJsonSchema(value[index], schema.items, root);
|
|
121
132
|
}
|
|
122
|
-
function coerceWithUnionSchema(value, schemas) {
|
|
133
|
+
function coerceWithUnionSchema(value, schemas, root, refs) {
|
|
123
134
|
if (value === null) {
|
|
124
|
-
for (const schema of schemas) if (getSchemaTypes(schema).includes("null")) {
|
|
125
|
-
const validator = getSubSchemaValidator(schema);
|
|
135
|
+
for (const schema of schemas) if (getSchemaTypes(schema, root).includes("null")) {
|
|
136
|
+
const validator = getSubSchemaValidator(schema, root);
|
|
126
137
|
if (!validator || validator.Check(value)) return value;
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
140
|
for (const schema of schemas) {
|
|
130
|
-
const types = getSchemaTypes(schema);
|
|
141
|
+
const types = getSchemaTypes(schema, root);
|
|
131
142
|
if (value !== null && types.length === 1 && types[0] === "null") continue;
|
|
132
|
-
const coerced = coerceWithJsonSchema(structuredClone(value), schema);
|
|
133
|
-
if (getSubSchemaValidator(schema)?.Check(coerced)) return coerced;
|
|
143
|
+
const coerced = coerceWithJsonSchema(structuredClone(value), schema, root, refs);
|
|
144
|
+
if (getSubSchemaValidator(schema, root)?.Check(coerced)) return coerced;
|
|
134
145
|
}
|
|
135
146
|
return value;
|
|
136
147
|
}
|
|
137
|
-
function coerceWithJsonSchema(value, schema) {
|
|
148
|
+
function coerceWithJsonSchema(value, schema, contextRoot, refs) {
|
|
149
|
+
if (!isJsonSchemaObject(schema)) return value;
|
|
150
|
+
const root = "$id" in schema || "id" in schema || schema !== contextRoot && hasSchemaScope(schema) ? void 0 : contextRoot;
|
|
138
151
|
let nextValue = value;
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
const target = resolveRootSchemaRef(schema, root);
|
|
153
|
+
if (target && !refs?.has(target)) {
|
|
154
|
+
const nextRefs = new Set(refs);
|
|
155
|
+
nextRefs.add(target);
|
|
156
|
+
nextValue = coerceWithJsonSchema(nextValue, target, root, nextRefs);
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(schema.allOf)) for (const nested of schema.allOf) nextValue = coerceWithJsonSchema(nextValue, nested, root, refs);
|
|
159
|
+
if (Array.isArray(schema.anyOf)) nextValue = coerceWithUnionSchema(nextValue, schema.anyOf, root, refs);
|
|
160
|
+
if (Array.isArray(schema.oneOf)) nextValue = coerceWithUnionSchema(nextValue, schema.oneOf, root, refs);
|
|
161
|
+
const schemaTypes = getSchemaTypes(schema, root);
|
|
143
162
|
const matchesUnionMember = schemaTypes.length > 1 && schemaTypes.some((schemaType) => matchesJsonType(nextValue, schemaType));
|
|
144
163
|
if (schemaTypes.length > 0 && !matchesUnionMember) for (const schemaType of schemaTypes) {
|
|
145
164
|
if (schemaType === "null" && nextValue !== null && schemaTypes.length > 1) continue;
|
|
@@ -149,27 +168,34 @@ function coerceWithJsonSchema(value, schema) {
|
|
|
149
168
|
break;
|
|
150
169
|
}
|
|
151
170
|
}
|
|
152
|
-
if (schemaTypes.includes("object") && isObjectBackedRecord(nextValue) && !Array.isArray(nextValue)) applySchemaObjectCoercion(nextValue, schema);
|
|
153
|
-
if (schemaTypes.includes("array") && Array.isArray(nextValue)) applySchemaArrayCoercion(nextValue, schema);
|
|
171
|
+
if (schemaTypes.includes("object") && isObjectBackedRecord(nextValue) && !Array.isArray(nextValue)) applySchemaObjectCoercion(nextValue, schema, root);
|
|
172
|
+
if (schemaTypes.includes("array") && Array.isArray(nextValue)) applySchemaArrayCoercion(nextValue, schema, root);
|
|
154
173
|
return nextValue;
|
|
155
174
|
}
|
|
156
|
-
function getValidator(schema) {
|
|
157
|
-
const
|
|
158
|
-
|
|
175
|
+
function getValidator(schema, root) {
|
|
176
|
+
const scope = root ?? schema;
|
|
177
|
+
let validators = validatorCache.get(scope);
|
|
178
|
+
const cached = validators?.get(schema);
|
|
159
179
|
if (cached) return cached;
|
|
160
|
-
const validator = Compile(schema
|
|
161
|
-
|
|
180
|
+
const validator = Compile(root && root !== schema ? {
|
|
181
|
+
$defs: root.$defs,
|
|
182
|
+
definitions: root.definitions,
|
|
183
|
+
allOf: [schema]
|
|
184
|
+
} : schema);
|
|
185
|
+
if (!validators) {
|
|
186
|
+
validators = /* @__PURE__ */ new WeakMap();
|
|
187
|
+
validatorCache.set(scope, validators);
|
|
188
|
+
}
|
|
189
|
+
validators.set(schema, validator);
|
|
162
190
|
return validator;
|
|
163
191
|
}
|
|
164
192
|
function formatValidationPath(error) {
|
|
193
|
+
const path = Pointer.Indices(error.instancePath).join(".").replace(/\//g, ".");
|
|
165
194
|
if (error.keyword === "required") {
|
|
166
195
|
const requiredProperty = error.params.requiredProperties?.[0];
|
|
167
|
-
if (requiredProperty) {
|
|
168
|
-
const basePath = error.instancePath.replace(/^\//, "").replace(/\//g, ".");
|
|
169
|
-
return basePath ? `${basePath}.${requiredProperty}` : requiredProperty;
|
|
170
|
-
}
|
|
196
|
+
if (requiredProperty) return path ? `${path}.${requiredProperty}` : requiredProperty;
|
|
171
197
|
}
|
|
172
|
-
return
|
|
198
|
+
return path || "root";
|
|
173
199
|
}
|
|
174
200
|
/** Finds the target tool and validates/coerces a model-emitted tool call. */
|
|
175
201
|
function validateToolCall(tools, toolCall) {
|
|
@@ -187,7 +213,7 @@ function validateToolArguments(tool, toolCall) {
|
|
|
187
213
|
const args = structuredClone(toolCall.arguments);
|
|
188
214
|
const validator = getValidator(tool.parameters);
|
|
189
215
|
if (isJsonSchemaObject(tool.parameters)) {
|
|
190
|
-
const coerced = coerceWithJsonSchema(args, tool.parameters);
|
|
216
|
+
const coerced = coerceWithJsonSchema(args, tool.parameters, tool.parameters);
|
|
191
217
|
if (coerced !== args) {
|
|
192
218
|
if (isObjectBackedRecord(args) && isObjectBackedRecord(coerced)) {
|
|
193
219
|
for (const key of Object.keys(args)) delete args[key];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nt as Tool, rt as ToolCall } from "./types-
|
|
1
|
+
import { nt as Tool, rt as ToolCall } from "./types-CLLR3eB4.mjs";
|
|
2
2
|
//#region packages/llm-core/src/validation.d.ts
|
|
3
3
|
/** Finds the target tool and validates/coerces a model-emitted tool call. */
|
|
4
4
|
declare function validateToolCall(tools: Tool[], toolCall: ToolCall): unknown;
|
package/dist/validation.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as validateToolCall, t as validateToolArguments } from "./validation-
|
|
1
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-Cat2wQsc.mjs";
|
|
2
2
|
export { validateToolArguments, validateToolCall };
|
package/dist/validation.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as validateToolCall, t as validateToolArguments } from "./validation-
|
|
1
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-BFZc40Ig.mjs";
|
|
2
2
|
export { validateToolArguments, validateToolCall };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/ai",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.7",
|
|
4
4
|
"description": "Reusable model provider adapters and streaming runtime from OpenClaw",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -118,12 +118,12 @@
|
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
120
|
"dependencies": {
|
|
121
|
-
"@anthropic-ai/sdk": "0.
|
|
122
|
-
"@google/genai": "2.
|
|
121
|
+
"@anthropic-ai/sdk": "0.127.0",
|
|
122
|
+
"@google/genai": "2.23.0",
|
|
123
123
|
"@mistralai/mistralai": "2.7.0",
|
|
124
|
-
"openai": "7.
|
|
124
|
+
"openai": "7.20.0",
|
|
125
125
|
"partial-json": "0.1.7",
|
|
126
|
-
"typebox": "1.3.
|
|
126
|
+
"typebox": "1.3.34"
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
129
|
"@openclaw/model-catalog-core": "0.0.0-private",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { a as createEmptyTransportUsage } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
2
|
-
//#region packages/ai/src/transports/assistant-output.ts
|
|
3
|
-
function createAssistantOutput(model, api = model.api) {
|
|
4
|
-
return {
|
|
5
|
-
role: "assistant",
|
|
6
|
-
content: [],
|
|
7
|
-
api,
|
|
8
|
-
provider: model.provider,
|
|
9
|
-
model: model.id,
|
|
10
|
-
usage: createEmptyTransportUsage(),
|
|
11
|
-
stopReason: "stop",
|
|
12
|
-
timestamp: Date.now()
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
export { createAssistantOutput as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./event-stream-CjnIZZst.mjs";
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
-
import { v as sanitizeSurrogates } from "./host-yTvBrYM2.mjs";
|
|
3
|
-
import { i as copyProviderAcceptanceObserver } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
4
|
-
//#region packages/ai/src/utils/prompt-cache-stability.ts
|
|
5
|
-
/**
|
|
6
|
-
* Prompt-cache normalization helpers. They keep generated prompt sections
|
|
7
|
-
* deterministic across platform newlines, trailing whitespace, and input
|
|
8
|
-
* ordering.
|
|
9
|
-
*/
|
|
10
|
-
/** Canonicalizes provider tool order without relying on host locale settings. */
|
|
11
|
-
function sortPromptCacheToolsByName(tools) {
|
|
12
|
-
const compareText = (left, right) => {
|
|
13
|
-
const leftText = left ?? "";
|
|
14
|
-
const rightText = right ?? "";
|
|
15
|
-
return leftText < rightText ? -1 : leftText > rightText ? 1 : 0;
|
|
16
|
-
};
|
|
17
|
-
return tools.toSorted((left, right) => compareText(left.wireName ?? left.name, right.wireName ?? right.name) || compareText(left.description, right.description));
|
|
18
|
-
}
|
|
19
|
-
/** Normalize structured prompt text before hashing or snapshot comparison. */
|
|
20
|
-
function normalizeStructuredPromptSection(text) {
|
|
21
|
-
return sanitizeSurrogates(text).replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "").trim();
|
|
22
|
-
}
|
|
23
|
-
/** Normalize, de-dupe, and sort capability ids for stable prompt payloads. */
|
|
24
|
-
function normalizePromptCapabilityIds(capabilities) {
|
|
25
|
-
const seen = /* @__PURE__ */ new Set();
|
|
26
|
-
const normalized = [];
|
|
27
|
-
for (const capability of capabilities) {
|
|
28
|
-
const value = normalizeLowercaseStringOrEmpty(normalizeStructuredPromptSection(capability));
|
|
29
|
-
if (!value || seen.has(value)) continue;
|
|
30
|
-
seen.add(value);
|
|
31
|
-
normalized.push(value);
|
|
32
|
-
}
|
|
33
|
-
return normalized.toSorted((left, right) => left.localeCompare(right));
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region packages/ai/src/utils/system-prompt-cache-boundary.ts
|
|
37
|
-
/**
|
|
38
|
-
* System prompt cache-boundary helpers.
|
|
39
|
-
*
|
|
40
|
-
* Keeps stable prompt prefixes separate from dynamic runtime additions for provider prompt caching.
|
|
41
|
-
*/
|
|
42
|
-
const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
43
|
-
/** Producer-delimited Runtime facts; instructions must remain outside this region. */
|
|
44
|
-
const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY = "\n<!-- OPENCLAW-RELOCATABLE-BOUNDARY -->\n";
|
|
45
|
-
const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END = "\n<!-- /OPENCLAW-RELOCATABLE-BOUNDARY -->";
|
|
46
|
-
function stripSystemPromptCacheBoundary(text) {
|
|
47
|
-
return stripSystemPromptRelocatableBoundary(text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n").replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY.trim(), ""));
|
|
48
|
-
}
|
|
49
|
-
/** Reject ambiguous markers from workspace or hook text instead of moving instructions. */
|
|
50
|
-
function splitSystemPromptRelocatableBoundary(text) {
|
|
51
|
-
const opening = SYSTEM_PROMPT_RELOCATABLE_BOUNDARY.trim();
|
|
52
|
-
const closing = SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END.trim();
|
|
53
|
-
const start = text.indexOf(opening);
|
|
54
|
-
const end = text.indexOf(closing);
|
|
55
|
-
if (start === -1 || end < start || text.includes(opening, start + 38) || text.includes(closing, end + 39)) return;
|
|
56
|
-
return {
|
|
57
|
-
remainingPrompt: [text.slice(0, start).trimEnd(), text.slice(end + 39).trimStart()].filter(Boolean).join("\n"),
|
|
58
|
-
relocatable: text.slice(start + 38, end).trim()
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function ensureSystemPromptCacheBoundary(systemPrompt) {
|
|
62
|
-
if (systemPrompt.trim().length === 0) return systemPrompt;
|
|
63
|
-
return systemPrompt.includes("\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n") ? systemPrompt : `${systemPrompt}${SYSTEM_PROMPT_CACHE_BOUNDARY}`;
|
|
64
|
-
}
|
|
65
|
-
function splitSystemPromptCacheBoundary(text) {
|
|
66
|
-
const boundaryIndex = text.indexOf(SYSTEM_PROMPT_CACHE_BOUNDARY);
|
|
67
|
-
if (boundaryIndex === -1) return;
|
|
68
|
-
return {
|
|
69
|
-
stablePrefix: text.slice(0, boundaryIndex).trimEnd(),
|
|
70
|
-
dynamicSuffix: text.slice(boundaryIndex + 34).trimStart()
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/** Keep explicit cache breakpoints while removing relocation metadata. */
|
|
74
|
-
function stripSystemPromptRelocatableBoundary(text) {
|
|
75
|
-
return text.replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY, "\n").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END, "").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY.trim(), "").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END.trim(), "");
|
|
76
|
-
}
|
|
77
|
-
function prependSystemPromptAdditionAfterCacheBoundary(params) {
|
|
78
|
-
const systemPromptAddition = typeof params.systemPromptAddition === "string" ? normalizeStructuredPromptSection(params.systemPromptAddition) : "";
|
|
79
|
-
if (!systemPromptAddition) return params.systemPrompt;
|
|
80
|
-
if (params.systemPrompt.trim().length === 0) return systemPromptAddition;
|
|
81
|
-
const split = splitSystemPromptCacheBoundary(params.systemPrompt);
|
|
82
|
-
if (!split) return `${systemPromptAddition}\n\n${params.systemPrompt}`;
|
|
83
|
-
const dynamicSuffix = split.dynamicSuffix ? normalizeStructuredPromptSection(split.dynamicSuffix) : "";
|
|
84
|
-
if (!dynamicSuffix) return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}`;
|
|
85
|
-
return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}\n\n${dynamicSuffix}`;
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region packages/ai/src/provider-options.ts
|
|
89
|
-
const CODE_MODE_TOOL_SURFACE_OBSERVER = Symbol("openaiCodeModeToolSurfaceObserver");
|
|
90
|
-
const CODE_MODE_TOOL_SURFACE_COLLECTOR = Symbol("openaiCodeModeToolSurfaceCollector");
|
|
91
|
-
const STRICT_REASONING_TAG_TEXT = Symbol("openaiStrictReasoningTagText");
|
|
92
|
-
function markStrictReasoningTagText(options) {
|
|
93
|
-
Reflect.set(options, STRICT_REASONING_TAG_TEXT, true);
|
|
94
|
-
}
|
|
95
|
-
function isStrictReasoningTagText(options) {
|
|
96
|
-
return options ? Reflect.get(options, STRICT_REASONING_TAG_TEXT) === true : false;
|
|
97
|
-
}
|
|
98
|
-
const codeModeToolSurfaceObserver = {
|
|
99
|
-
set(options, observer, collector) {
|
|
100
|
-
Reflect.set(options, CODE_MODE_TOOL_SURFACE_OBSERVER, observer);
|
|
101
|
-
if (collector) Reflect.set(options, CODE_MODE_TOOL_SURFACE_COLLECTOR, collector);
|
|
102
|
-
},
|
|
103
|
-
get(options) {
|
|
104
|
-
if (!options) return;
|
|
105
|
-
const observer = Reflect.get(options, CODE_MODE_TOOL_SURFACE_OBSERVER);
|
|
106
|
-
return typeof observer === "function" ? (observation) => observer(observation) : void 0;
|
|
107
|
-
},
|
|
108
|
-
getCollector(options) {
|
|
109
|
-
if (!options) return;
|
|
110
|
-
const collector = Reflect.get(options, CODE_MODE_TOOL_SURFACE_COLLECTOR);
|
|
111
|
-
return typeof collector === "function" ? (observation) => collector(observation) : void 0;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
/** Internal output policy for callers that must not recover ambiguous reasoning as visible text. */
|
|
115
|
-
const reasoningTagTextPolicy = {
|
|
116
|
-
markStrict: markStrictReasoningTagText,
|
|
117
|
-
isStrict: isStrictReasoningTagText,
|
|
118
|
-
copy(source, target) {
|
|
119
|
-
if (isStrictReasoningTagText(source)) markStrictReasoningTagText(target);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region packages/ai/src/providers/simple-options.ts
|
|
124
|
-
function buildBaseOptions(model, options, apiKey) {
|
|
125
|
-
const firstEventOptions = options;
|
|
126
|
-
const baseOptions = {
|
|
127
|
-
temperature: options?.temperature,
|
|
128
|
-
...options?.serviceTier ? { serviceTier: options.serviceTier } : {},
|
|
129
|
-
maxTokens: options?.maxTokens,
|
|
130
|
-
responseFormat: options?.responseFormat,
|
|
131
|
-
stop: options?.stop,
|
|
132
|
-
signal: options?.signal,
|
|
133
|
-
apiKey: apiKey || options?.apiKey,
|
|
134
|
-
transport: options?.transport,
|
|
135
|
-
cacheRetention: options?.cacheRetention,
|
|
136
|
-
sessionId: options?.sessionId,
|
|
137
|
-
promptCacheKey: options?.promptCacheKey,
|
|
138
|
-
headers: options?.headers,
|
|
139
|
-
onPayload: options?.onPayload,
|
|
140
|
-
onResponse: options?.onResponse,
|
|
141
|
-
timeoutMs: options?.timeoutMs,
|
|
142
|
-
firstEventTimeoutMs: firstEventOptions?.firstEventTimeoutMs,
|
|
143
|
-
onFirstEventTimeout: firstEventOptions?.onFirstEventTimeout,
|
|
144
|
-
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
145
|
-
metadata: options?.metadata
|
|
146
|
-
};
|
|
147
|
-
reasoningTagTextPolicy.copy(options, baseOptions);
|
|
148
|
-
return copyProviderAcceptanceObserver(options, baseOptions);
|
|
149
|
-
}
|
|
150
|
-
function clampMaxTokensToModel(model, requestedMaxTokens) {
|
|
151
|
-
return requestedMaxTokens === void 0 ? void 0 : Math.max(1, Math.min(requestedMaxTokens, model.maxTokens ?? requestedMaxTokens));
|
|
152
|
-
}
|
|
153
|
-
function clampReasoning(effort) {
|
|
154
|
-
return effort === "xhigh" ? "high" : effort;
|
|
155
|
-
}
|
|
156
|
-
function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
|
|
157
|
-
const budgets = {
|
|
158
|
-
minimal: 1024,
|
|
159
|
-
low: 2048,
|
|
160
|
-
medium: 8192,
|
|
161
|
-
high: 16384,
|
|
162
|
-
max: 32768,
|
|
163
|
-
...customBudgets
|
|
164
|
-
};
|
|
165
|
-
const minOutputTokens = 1024;
|
|
166
|
-
let thinkingBudget = budgets[clampReasoning(reasoningLevel)];
|
|
167
|
-
const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
|
|
168
|
-
if (maxTokens <= thinkingBudget) thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
|
|
169
|
-
return {
|
|
170
|
-
maxTokens,
|
|
171
|
-
thinkingBudget
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
//#endregion
|
|
175
|
-
export { normalizeStructuredPromptSection as _, codeModeToolSurfaceObserver as a, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY as c, prependSystemPromptAdditionAfterCacheBoundary as d, splitSystemPromptCacheBoundary as f, normalizePromptCapabilityIds as g, stripSystemPromptRelocatableBoundary as h, clampReasoning as i, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END as l, stripSystemPromptCacheBoundary as m, buildBaseOptions as n, reasoningTagTextPolicy as o, splitSystemPromptRelocatableBoundary as p, clampMaxTokensToModel as r, SYSTEM_PROMPT_CACHE_BOUNDARY as s, adjustMaxTokensForThinking as t, ensureSystemPromptCacheBoundary as u, sortPromptCacheToolsByName as v };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./index-C25RT6bP.mjs";
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//#region packages/normalization-core/src/utf16-slice.ts
|
|
2
|
-
function isHighSurrogate(codeUnit) {
|
|
3
|
-
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
4
|
-
}
|
|
5
|
-
function isLowSurrogate(codeUnit) {
|
|
6
|
-
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
7
|
-
}
|
|
8
|
-
/** Slices a UTF-16 string without returning dangling surrogate halves at either edge. */
|
|
9
|
-
function sliceUtf16Safe(input, start, end) {
|
|
10
|
-
const len = input.length;
|
|
11
|
-
let from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
12
|
-
let to = end === void 0 ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
|
|
13
|
-
if (to <= from) return "";
|
|
14
|
-
if (from > 0 && from < len) {
|
|
15
|
-
if (isLowSurrogate(input.charCodeAt(from)) && isHighSurrogate(input.charCodeAt(from - 1))) from += 1;
|
|
16
|
-
}
|
|
17
|
-
if (to > 0 && to < len) {
|
|
18
|
-
if (isHighSurrogate(input.charCodeAt(to - 1)) && isLowSurrogate(input.charCodeAt(to))) to -= 1;
|
|
19
|
-
}
|
|
20
|
-
return input.slice(from, to);
|
|
21
|
-
}
|
|
22
|
-
/** Truncates a UTF-16 string without cutting a surrogate pair in half. */
|
|
23
|
-
function truncateUtf16Safe(input, maxLen) {
|
|
24
|
-
const limit = Math.max(0, Math.floor(maxLen));
|
|
25
|
-
if (input.length <= limit) return input;
|
|
26
|
-
return sliceUtf16Safe(input, 0, limit);
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
export { truncateUtf16Safe as t };
|