@openclaw/ai 2026.9.3 → 2026.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{anthropic-CZy5U0NY.mjs → anthropic-COtDvgtt.mjs} +16 -16
- package/dist/{anthropic-payload-policy-wuRCb6MH.d.mts → anthropic-payload-policy-5Erq1Nzy.d.mts} +3 -3
- package/dist/{anthropic-stream-reducer-B_yo_7pf.mjs → anthropic-stream-reducer-BvdYYWL8.mjs} +56 -47
- package/dist/{api-registry-CB1-1oQ2.d.mts → api-registry-Ba2Cv-ut.d.mts} +2 -2
- package/dist/{assistant-output-iqnlJCV2.mjs → assistant-output-BsEkB-vU.mjs} +1 -1
- package/dist/{azure-openai-responses-Crpa40QR.mjs → azure-openai-responses-YrgnD583.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-BQOzsvUH.mjs} +4 -4
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-dV98PqIy.mjs → diagnostics-Dm4bisWG.mjs} +89 -2
- package/dist/diagnostics.d.mts +4 -23
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-C1Z2piyk.d.mts → event-stream-CCoa-qSI.d.mts} +1 -1
- package/dist/event-stream-DmSCpi1T.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-BDPriaVe.mjs → google-BuhpRO9r.mjs} +7 -10
- package/dist/{google-messages-CVn9eFpF.mjs → google-messages-CyWnYlh0.mjs} +3 -4
- package/dist/{google-shared-BedY23XS.mjs → google-shared-BT5ZeNer.mjs} +13 -13
- package/dist/{google-vertex-DMz8XQCn.mjs → google-vertex-C7EplRvt.mjs} +5 -8
- package/dist/{host-CWuF-sS3.mjs → host-B4MeUNBc.mjs} +145 -12
- package/dist/{host-DK3wmS3e.d.mts → host-FZ1RA_qD.d.mts} +7 -3
- package/dist/{host-policy-CAopLRKA.mjs → host-policy-DUnXSx0I.mjs} +1 -1
- package/dist/{index-CQ6LTHw8.d.mts → index-DaF2QbwS.d.mts} +5 -10
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +6 -7
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-completions-compat.d.mts +2 -0
- package/dist/internal/openai-completions-compat.mjs +2 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +3 -2
- package/dist/internal/openai.d.mts +10 -53
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/runtime.d.mts +43 -10
- package/dist/internal/runtime.mjs +5 -11
- package/dist/internal/shared.d.mts +35 -5
- package/dist/internal/shared.mjs +4 -4
- package/dist/internal/tool-schema.d.mts +3 -3
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral--m-Jm6VZ.mjs → mistral-moA-mbwl.mjs} +9 -16
- package/dist/{openai-chatgpt-responses-nDZccFW-.mjs → openai-chatgpt-responses-DWID3EFO.mjs} +76 -33
- package/dist/{openai-completions-KuoZyx0d.mjs → openai-completions-DJ1Vm-CD.mjs} +12 -13
- package/dist/{openai-prompt-cache-BI0rkM-5.mjs → openai-completions-compat-CkwdxTZx.mjs} +5 -50
- package/dist/{openai-completions-compat-CXn3T1we.d.mts → openai-completions-compat-JE7gqxb9.d.mts} +4 -4
- package/dist/{openai-completions-stream-BQk3SkLD.mjs → openai-completions-stream-Bu98b0Hv.mjs} +128 -99
- package/dist/openai-prompt-cache-1wfaIszn.mjs +46 -0
- package/dist/{openai-prompt-cache-rrutvqxq.d.mts → openai-prompt-cache-CJ_xEevu.d.mts} +2 -2
- package/dist/{openai-provider-client-ha_WxTyj.mjs → openai-provider-client-DPo0Hmak.mjs} +2 -2
- package/dist/{openai-reasoning-effort-BK7FbcLT.mjs → openai-reasoning-effort-NlFZmfEu.mjs} +87 -19
- package/dist/{openai-responses-D99dOzKI.mjs → openai-responses-BejZzQCP.mjs} +9 -13
- package/dist/{openai-responses-compaction-window-D5jbzCi3.mjs → openai-responses-compaction-window-D6P5oZP5.mjs} +21 -140
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-contracts-B55afwRo.d.mts → openai-responses-contracts-Dflvrfa8.d.mts} +10 -39
- package/dist/{openai-responses-payload-policy-rLRPsSmB.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +5 -3
- package/dist/openai-responses-prompt-observer-internal-C15_-OwV.mjs +195 -0
- package/dist/{openai-responses-shared-ZyQEzS5i.mjs → openai-responses-shared-CwsziD_m.mjs} +390 -183
- package/dist/openai-responses-terminal-usage-Dl3J6zrf.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-BO8rwyAD.mjs} +92 -68
- package/dist/{openai-transport-params-DNasp2fU.mjs → openai-transport-params-DQeuAvBl.mjs} +162 -51
- package/dist/positive-integer-DtjCkbue.mjs +8 -0
- package/dist/{provider-error-C6TbKiey.mjs → provider-error-DDqw9Qda.mjs} +140 -36
- package/dist/{provider-options-BXr9Ec83.d.mts → provider-options-DprLsWh9.d.mts} +9 -6
- package/dist/{provider-replay-context-BuSUaAk5.mjs → provider-replay-context-CnUSOwhr.mjs} +1 -1
- package/dist/{provider-transcript-transform-pPmUIwKt.mjs → provider-transcript-transform-BsRAhuWJ.mjs} +1 -1
- package/dist/provider-transport-turn-state-CkGToCD2.mjs +42 -0
- package/dist/{provider-types-CAV0Og3m.d.mts → provider-types-CAKRC7N5.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -7
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-BQBi4B9d.mjs → reasoning-tag-text-partitioner-Dy9IO8Dc.mjs} +15 -14
- package/dist/{session-affinity-CCH7eYdB.mjs → session-affinity-Bcunsn4I.mjs} +5 -2
- package/dist/{simple-options-tcKOqnpF.mjs → simple-options-C6cFWj_f.mjs} +26 -5
- package/dist/{src-B2Q_6G8V.mjs → src-DeKjbE8I.mjs} +3 -6
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-C9ZadkJW.mjs} +1 -1
- package/dist/{string-normalization-CmLIasuf.mjs → string-normalization-J9ZiLfGO.mjs} +13 -1
- package/dist/tool-schema-json-projection-CD9c_fK8.mjs +134 -0
- package/dist/{transport-stream-shared-DOxpGJ-H.d.mts → transport-stream-shared-BbUkFaHi.d.mts} +20 -36
- package/dist/{transport-stream-shared-Cu3ZPhNW.mjs → transport-stream-shared-D-6FQSHm.mjs} +223 -11
- package/dist/{transport-utils-CCooe-cr.mjs → transport-utils-1cyq5Y7x.mjs} +4 -7
- package/dist/transports.d.mts +51 -165
- package/dist/transports.mjs +172 -507
- package/dist/{types-Dy1q0CSu.d.mts → types-4_uVs5WH.d.mts} +49 -3
- package/dist/types-DkJfb4W3.d.mts +1 -0
- package/dist/types-LFWwv0cF.mjs +8 -0
- package/dist/types.d.mts +6 -7
- package/dist/types.mjs +4 -4
- package/dist/{validation-CaFUZN9B.d.mts → validation-Ctzu2DhF.d.mts} +1 -1
- package/dist/{validation-BDzVDnTs.mjs → validation-Dw7cb6BV.mjs} +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +10 -5
- package/dist/diagnostics-DnPnOui6.d.mts +0 -29
- package/dist/event-stream-I_GlBsuZ.d.mts +0 -1
- package/dist/hash-CHgqbJmD.mjs +0 -16
- package/dist/json-parse-Dw_hnxsA.mjs +0 -146
- package/dist/openai-responses-prompt-observer-internal-tApyTLVu.mjs +0 -32
- package/dist/sanitize-unicode-Bb-v9meu.mjs +0 -83
- package/dist/tool-schema-json-projection-ClptDdAO.mjs +0 -82
- package/dist/types-BADKjDBI.d.mts +0 -1
- package/dist/types-BDdaOVi2.mjs +0 -6
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { t as AssistantMessageDiagnostic } from "./diagnostics-DnPnOui6.mjs";
|
|
2
1
|
import { TSchema } from "typebox";
|
|
3
2
|
//#region packages/llm-core/src/model-data.d.ts
|
|
4
3
|
declare const MODEL_DATA_THINKING_FORMATS: readonly ["openai", "openrouter", "deepseek", "together", "qwen", "qwen-chat-template", "zai"];
|
|
@@ -59,6 +58,34 @@ type ModelRoutingPercentiles = {
|
|
|
59
58
|
p99?: number;
|
|
60
59
|
};
|
|
61
60
|
//#endregion
|
|
61
|
+
//#region packages/llm-core/src/utils/diagnostics.d.ts
|
|
62
|
+
interface DiagnosticErrorInfo {
|
|
63
|
+
name?: string;
|
|
64
|
+
message: string;
|
|
65
|
+
stack?: string;
|
|
66
|
+
code?: string | number;
|
|
67
|
+
}
|
|
68
|
+
interface AssistantMessageDiagnostic {
|
|
69
|
+
type: string;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
error?: DiagnosticErrorInfo;
|
|
72
|
+
details?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/** True when the provider explicitly refused the request payload. */
|
|
75
|
+
declare function isProviderRefusalAssistantError(message: {
|
|
76
|
+
diagnostics?: AssistantMessageDiagnostic[];
|
|
77
|
+
} | null | undefined): boolean;
|
|
78
|
+
/** Formats arbitrary thrown values into diagnostic-safe text. */
|
|
79
|
+
declare function formatThrownValue(value: unknown): string;
|
|
80
|
+
/** Extracts serializable diagnostic error fields from Error and non-Error throws. */
|
|
81
|
+
declare function extractDiagnosticError(error: unknown): DiagnosticErrorInfo;
|
|
82
|
+
/** Creates a timestamped assistant-message diagnostic entry. */
|
|
83
|
+
declare function createAssistantMessageDiagnostic(type: string, error: unknown, details?: Record<string, unknown>): AssistantMessageDiagnostic;
|
|
84
|
+
/** Appends a diagnostic while preserving existing message diagnostics. */
|
|
85
|
+
declare function appendAssistantMessageDiagnostic(message: {
|
|
86
|
+
diagnostics?: AssistantMessageDiagnostic[];
|
|
87
|
+
}, diagnostic: AssistantMessageDiagnostic): void;
|
|
88
|
+
//#endregion
|
|
62
89
|
//#region packages/llm-core/src/types.d.ts
|
|
63
90
|
/** Provider API families with first-class request/stream adapters in OpenClaw. */
|
|
64
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";
|
|
@@ -241,6 +268,8 @@ interface ImagesOptions {
|
|
|
241
268
|
type ProviderImagesOptions = ImagesOptions & Record<string, unknown>;
|
|
242
269
|
/** Unified text options used by simple completion helpers. */
|
|
243
270
|
interface SimpleStreamOptions extends StreamOptions {
|
|
271
|
+
/** Optional processing tier; only providers supporting these tiers apply it. */
|
|
272
|
+
serviceTier?: "default" | "priority";
|
|
244
273
|
reasoning?: ModelThinkingLevel;
|
|
245
274
|
/** Custom token budgets for thinking levels (token-based providers only) */
|
|
246
275
|
thinkingBudgets?: ThinkingBudgets;
|
|
@@ -350,6 +379,8 @@ type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
|
|
|
350
379
|
/** Stable error codes for provider outcomes that cannot be replayed safely. */
|
|
351
380
|
declare const PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE = "PROVIDER_POST_DISPATCH_AMBIGUITY";
|
|
352
381
|
declare const PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE = "PROVIDER_FAILURE_WITH_OUTPUT";
|
|
382
|
+
/** Pre-dispatch argument rejection; callers still enforce output and effect guards. */
|
|
383
|
+
declare const MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE = "malformed_tool_call_arguments";
|
|
353
384
|
/** User turn in a text-model conversation. */
|
|
354
385
|
interface UserMessage {
|
|
355
386
|
role: "user";
|
|
@@ -395,6 +426,8 @@ interface AssistantMessage {
|
|
|
395
426
|
diagnostics?: AssistantMessageDiagnostic[];
|
|
396
427
|
usage: Usage;
|
|
397
428
|
stopReason: StopReason;
|
|
429
|
+
/** A completed provider response can explicitly request another inference with false. */
|
|
430
|
+
endTurn?: boolean;
|
|
398
431
|
errorMessage?: string;
|
|
399
432
|
errorCode?: string;
|
|
400
433
|
errorType?: string;
|
|
@@ -538,6 +571,8 @@ interface OpenAICompletionsCompat {
|
|
|
538
571
|
supportsDeveloperRole?: boolean;
|
|
539
572
|
/** Whether the provider supports `reasoning_effort`. Default: auto-detected from URL. */
|
|
540
573
|
supportsReasoningEffort?: boolean;
|
|
574
|
+
/** Provider-native reasoning efforts accepted by the model. Overrides known model defaults. */
|
|
575
|
+
supportedReasoningEfforts?: string[];
|
|
541
576
|
/** Per-level reasoning effort overrides, e.g. map "off" to "low" for models that cannot disable thinking. */
|
|
542
577
|
reasoningEffortMap?: Record<string, string>;
|
|
543
578
|
/** Whether the provider supports `stream_options: { include_usage: true }` for token usage in streaming responses. Default: true. */
|
|
@@ -581,6 +616,8 @@ interface OpenAIResponsesCompat {
|
|
|
581
616
|
supportsReasoningEffort?: boolean;
|
|
582
617
|
/** Provider-native reasoning efforts accepted by the model. Overrides known model defaults. */
|
|
583
618
|
supportedReasoningEfforts?: string[];
|
|
619
|
+
/** Per-level reasoning effort overrides, e.g. map "off" to "low" for models that cannot disable thinking. */
|
|
620
|
+
reasoningEffortMap?: Record<string, string>;
|
|
584
621
|
/** Whether the model accepts the `temperature` parameter. Default: true. */
|
|
585
622
|
supportsTemperature?: boolean;
|
|
586
623
|
/** Whether to send the OpenAI `session_id` cache-affinity header from `options.sessionId` when caching is enabled. Default: true. */
|
|
@@ -589,6 +626,15 @@ interface OpenAIResponsesCompat {
|
|
|
589
626
|
supportsLongCacheRetention?: boolean;
|
|
590
627
|
/** Whether the provider honors top-level `instructions`. Defaults to true only for verified native routes (OpenAI, xAI); every other route defaults to false and embeds the system prompt in `input` unless set true here after verifying against that endpoint. */
|
|
591
628
|
supportsInstructions?: boolean;
|
|
629
|
+
/**
|
|
630
|
+
* Explicit opt-in for HTTP continuation (client-side delta + `previous_response_id`)
|
|
631
|
+
* on a custom/proxy OpenAI-Responses-compatible endpoint. A native `api.openai.com`
|
|
632
|
+
* connection is eligible by default; a custom endpoint carries no trust signal of
|
|
633
|
+
* its own, so this is the only path to eligibility there — set it once you've
|
|
634
|
+
* verified the backend correctly resolves `previous_response_id` and persists
|
|
635
|
+
* `store: true` turns. Default: false.
|
|
636
|
+
*/
|
|
637
|
+
supportsResponsesContinuation?: boolean;
|
|
592
638
|
}
|
|
593
639
|
/** Compatibility settings for Anthropic Messages-compatible APIs. */
|
|
594
640
|
interface AnthropicMessagesCompat {
|
|
@@ -695,7 +741,7 @@ interface Model<TApi extends Api = Api> {
|
|
|
695
741
|
/** Sends runtime credentials as Authorization: Bearer instead of provider-specific key headers. */
|
|
696
742
|
authHeader?: boolean;
|
|
697
743
|
/** Compatibility overrides for OpenAI-compatible APIs. If not set, auto-detected from baseUrl. */
|
|
698
|
-
compat?: TApi extends "openai-completions" ? OpenAICompletionsCompat : TApi extends "openai-responses" | "azure-openai-responses" | "openai-codex-responses" ? OpenAIResponsesCompat : TApi extends "anthropic-messages" ? AnthropicMessagesCompat : never;
|
|
744
|
+
compat?: TApi extends "openai-completions" ? OpenAICompletionsCompat : TApi extends "openai-responses" | "azure-openai-responses" | "openai-chatgpt-responses" | "openai-codex-responses" ? OpenAIResponsesCompat : TApi extends "anthropic-messages" ? AnthropicMessagesCompat : never;
|
|
699
745
|
/** Provider-documented media input limits used by attachment preprocessing. */
|
|
700
746
|
mediaInput?: ModelDataMediaInputConfig;
|
|
701
747
|
}
|
|
@@ -708,4 +754,4 @@ type StreamFn = (model: Model, context: Context, options?: SimpleStreamOptions)
|
|
|
708
754
|
type CompleteSimpleFn = (model: Model, context: Pick<Context, "systemPrompt" | "messages">, options?: SimpleStreamOptions) => Promise<AssistantMessage>;
|
|
709
755
|
type ValidateToolArgumentsFn = (tool: Tool, toolCall: ToolCall) => unknown;
|
|
710
756
|
//#endregion
|
|
711
|
-
export {
|
|
757
|
+
export { ThinkingContent as $, ModelCostRates as A, ProviderReplayState as B, KnownImagesApi as C, Message as D, MaybePromise as E, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE as F, SimpleStreamOptions as G, ProviderStreamOptions as H, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE as I, StreamFunction as J, StopReason as K, PricingTier as L, OpenAICompletionsCompat as M, OpenAIResponsesCompat as N, Model as O, OpenRouterRouting as P, ThinkingBudgets as Q, Provider as R, KnownApi as S, MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE as T, RawModelCostConfig as U, ProviderResponse as V, RawPricingTier as W, TextContent as X, StreamOptions as Y, TextSignatureV1 as Z, ImagesModel as _, ModelDataThinkingFormat as _t, AssistantMessage as a, Transport as at, ImagesProvider as b, AssistantMessageEventStreamLike as c, ValidateToolArgumentsFn as ct, Context as d, DiagnosticErrorInfo as dt, ThinkingLevel as et, ImageContent as f, appendAssistantMessageDiagnostic as ft, ImagesInputContent as g, isProviderRefusalAssistantError as gt, ImagesFunction as h, formatThrownValue as ht, AssistantImages as i, ToolResultMessage as it, ModelThinkingLevel as j, ModelCostConfig as k, CacheRetention as l, VercelGatewayRouting as lt, ImagesContext as m, extractDiagnosticError as mt, Api as n, Tool as nt, AssistantMessageEvent as o, Usage as ot, ImagesApi as p, createAssistantMessageDiagnostic as pt, StreamFn as q, AssistantDeliveryTtsFacts as r, ToolCall as rt, AssistantMessageEventStreamContract as s, UserMessage as st, AnthropicMessagesCompat as t, ThinkingLevelMap as tt, CompleteSimpleFn as u, AssistantMessageDiagnostic as ut, ImagesOptions as v, KnownImagesProvider as w, ImagesStopReason as x, ImagesOutputContent as y, ProviderImagesOptions as z };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./index-DaF2QbwS.mjs";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region packages/llm-core/src/types.ts
|
|
2
|
+
/** Stable error codes for provider outcomes that cannot be replayed safely. */
|
|
3
|
+
const PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE = "PROVIDER_POST_DISPATCH_AMBIGUITY";
|
|
4
|
+
const PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE = "PROVIDER_FAILURE_WITH_OUTPUT";
|
|
5
|
+
/** Pre-dispatch argument rejection; callers still enforce output and effect guards. */
|
|
6
|
+
const MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE = "malformed_tool_call_arguments";
|
|
7
|
+
//#endregion
|
|
8
|
+
export { PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE as n, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE as r, MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE as t };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { _ as supportsClaude1MContext, a as CLAUDE_FABLE_5_THINKING_PROFILE, b as supportsClaudeNativeMaxEffort, c as bindsClaudeThinkingPrefix, d as resolveClaudeFable5ModelIdentity, f as resolveClaudeModelIdentity, g as resolveClaudeSonnet5ModelIdentity, h as resolveClaudeOpus5ModelIdentity, i as normalizeResolvedPricing, l as requiresClaudeDefaultSampling, m as resolveClaudeNativeThinkingLevelMap, n as calculateUsageCost, o as CLAUDE_OPUS_5_THINKING_PROFILE, p as resolveClaudeMythos5ModelIdentity, r as normalizeModelCostConfig, s as CLAUDE_SONNET_5_THINKING_PROFILE, u as requiresClaudeMandatoryAdaptiveThinking, v as supportsClaudeAdaptiveThinking, x as supportsClaudeNativeXhighEffort, y as supportsClaudeFastMode } from "./index-
|
|
2
|
-
import { $ as
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
export { AnthropicMessagesCompat, Api, AssistantDeliveryTtsFacts, AssistantImages, AssistantMessage, AssistantMessageDiagnostic, AssistantMessageEvent, AssistantMessageEventStream, AssistantMessageEventStreamContract, AssistantMessageEventStreamLike, CLAUDE_FABLE_5_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, MaybePromise, Message, Model, ModelCostConfig, ModelCostRates, ModelThinkingLevel, OpenAICompletionsCompat, OpenAIResponsesCompat, OpenRouterRouting, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, PricingTier, Provider, ProviderImagesOptions, 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, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
1
|
+
import { _ as supportsClaude1MContext, a as CLAUDE_FABLE_5_THINKING_PROFILE, b as supportsClaudeNativeMaxEffort, c as bindsClaudeThinkingPrefix, d as resolveClaudeFable5ModelIdentity, f as resolveClaudeModelIdentity, g as resolveClaudeSonnet5ModelIdentity, h as resolveClaudeOpus5ModelIdentity, i as normalizeResolvedPricing, l as requiresClaudeDefaultSampling, m as resolveClaudeNativeThinkingLevelMap, n as calculateUsageCost, o as CLAUDE_OPUS_5_THINKING_PROFILE, p as resolveClaudeMythos5ModelIdentity, r as normalizeModelCostConfig, s as CLAUDE_SONNET_5_THINKING_PROFILE, u as requiresClaudeMandatoryAdaptiveThinking, v as supportsClaudeAdaptiveThinking, x as supportsClaudeNativeXhighEffort, y as supportsClaudeFastMode } from "./index-DaF2QbwS.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-4_uVs5WH.mjs";
|
|
3
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-CCoa-qSI.mjs";
|
|
4
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-Ctzu2DhF.mjs";
|
|
5
|
+
import "./types-DkJfb4W3.mjs";
|
|
6
|
+
export { AnthropicMessagesCompat, Api, AssistantDeliveryTtsFacts, AssistantImages, AssistantMessage, AssistantMessageDiagnostic, AssistantMessageEvent, AssistantMessageEventStream, AssistantMessageEventStreamContract, AssistantMessageEventStreamLike, CLAUDE_FABLE_5_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, 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, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
package/dist/types.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as supportsClaudeAdaptiveThinking, a as CLAUDE_OPUS_5_THINKING_PROFILE, b as supportsClaudeNativeXhighEffort, c as requiresClaudeDefaultSampling, d as resolveClaudeModelIdentity, f as resolveClaudeMythos5ModelIdentity, g as supportsClaude1MContext, h as resolveClaudeSonnet5ModelIdentity, i as CLAUDE_FABLE_5_THINKING_PROFILE, l as requiresClaudeMandatoryAdaptiveThinking, m as resolveClaudeOpus5ModelIdentity, n as normalizeModelCostConfig, o as CLAUDE_SONNET_5_THINKING_PROFILE, p as resolveClaudeNativeThinkingLevelMap, r as normalizeResolvedPricing, s as bindsClaudeThinkingPrefix, t as calculateUsageCost, u as resolveClaudeFable5ModelIdentity, v as supportsClaudeFastMode, y as supportsClaudeNativeMaxEffort } from "./src-
|
|
2
|
-
import { n as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, t as
|
|
1
|
+
import { _ as supportsClaudeAdaptiveThinking, a as CLAUDE_OPUS_5_THINKING_PROFILE, b as supportsClaudeNativeXhighEffort, c as requiresClaudeDefaultSampling, d as resolveClaudeModelIdentity, f as resolveClaudeMythos5ModelIdentity, g as supportsClaude1MContext, h as resolveClaudeSonnet5ModelIdentity, i as CLAUDE_FABLE_5_THINKING_PROFILE, l as requiresClaudeMandatoryAdaptiveThinking, m as resolveClaudeOpus5ModelIdentity, n as normalizeModelCostConfig, o as CLAUDE_SONNET_5_THINKING_PROFILE, p as resolveClaudeNativeThinkingLevelMap, r as normalizeResolvedPricing, s as bindsClaudeThinkingPrefix, t as calculateUsageCost, u as resolveClaudeFable5ModelIdentity, v as supportsClaudeFastMode, y as supportsClaudeNativeMaxEffort } from "./src-DeKjbE8I.mjs";
|
|
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, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
4
4
|
import { i as createAssistantMessageEventStream, n as EventStream, t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
5
|
-
import { n as validateToolCall, t as validateToolArguments } from "./validation-
|
|
6
|
-
export { AssistantMessageEventStream, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, EventStream, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, appendAssistantMessageDiagnostic, bindsClaudeThinkingPrefix, calculateUsageCost, createAssistantMessageDiagnostic, createAssistantMessageEventStream, extractDiagnosticError, formatThrownValue, isProviderRefusalAssistantError, normalizeModelCostConfig, normalizeResolvedPricing, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
5
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-Dw7cb6BV.mjs";
|
|
6
|
+
export { AssistantMessageEventStream, CLAUDE_FABLE_5_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, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nt as
|
|
1
|
+
import { nt as Tool, rt as ToolCall } from "./types-4_uVs5WH.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;
|
|
@@ -142,6 +142,7 @@ function coerceWithJsonSchema(value, schema) {
|
|
|
142
142
|
const schemaTypes = getSchemaTypes(schema);
|
|
143
143
|
const matchesUnionMember = schemaTypes.length > 1 && schemaTypes.some((schemaType) => matchesJsonType(nextValue, schemaType));
|
|
144
144
|
if (schemaTypes.length > 0 && !matchesUnionMember) for (const schemaType of schemaTypes) {
|
|
145
|
+
if (schemaType === "null" && nextValue !== null && schemaTypes.length > 1) continue;
|
|
145
146
|
const candidate = coercePrimitiveByType(nextValue, schemaType);
|
|
146
147
|
if (candidate !== nextValue) {
|
|
147
148
|
nextValue = candidate;
|
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-Ctzu2DhF.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-Dw7cb6BV.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.5",
|
|
4
4
|
"description": "Reusable model provider adapters and streaming runtime from OpenClaw",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -86,6 +86,11 @@
|
|
|
86
86
|
"import": "./dist/internal/openai.mjs",
|
|
87
87
|
"default": "./dist/internal/openai.mjs"
|
|
88
88
|
},
|
|
89
|
+
"./internal/openai-completions-compat": {
|
|
90
|
+
"types": "./dist/internal/openai-completions-compat.d.mts",
|
|
91
|
+
"import": "./dist/internal/openai-completions-compat.mjs",
|
|
92
|
+
"default": "./dist/internal/openai-completions-compat.mjs"
|
|
93
|
+
},
|
|
89
94
|
"./internal/openai-responses-payload-policy": {
|
|
90
95
|
"types": "./dist/internal/openai-responses-payload-policy.d.mts",
|
|
91
96
|
"import": "./dist/internal/openai-responses-payload-policy.mjs",
|
|
@@ -113,12 +118,12 @@
|
|
|
113
118
|
}
|
|
114
119
|
},
|
|
115
120
|
"dependencies": {
|
|
116
|
-
"@anthropic-ai/sdk": "0.
|
|
117
|
-
"@google/genai": "2.
|
|
121
|
+
"@anthropic-ai/sdk": "0.124.0",
|
|
122
|
+
"@google/genai": "2.21.0",
|
|
118
123
|
"@mistralai/mistralai": "2.6.4",
|
|
119
|
-
"openai": "7.
|
|
124
|
+
"openai": "7.12.1",
|
|
120
125
|
"partial-json": "0.1.7",
|
|
121
|
-
"typebox": "1.3.
|
|
126
|
+
"typebox": "1.3.30"
|
|
122
127
|
},
|
|
123
128
|
"devDependencies": {
|
|
124
129
|
"@openclaw/model-catalog-core": "0.0.0-private",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//#region packages/llm-core/src/utils/diagnostics.d.ts
|
|
2
|
-
interface DiagnosticErrorInfo {
|
|
3
|
-
name?: string;
|
|
4
|
-
message: string;
|
|
5
|
-
stack?: string;
|
|
6
|
-
code?: string | number;
|
|
7
|
-
}
|
|
8
|
-
interface AssistantMessageDiagnostic {
|
|
9
|
-
type: string;
|
|
10
|
-
timestamp: number;
|
|
11
|
-
error?: DiagnosticErrorInfo;
|
|
12
|
-
details?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
/** True when the provider explicitly refused the request payload. */
|
|
15
|
-
declare function isProviderRefusalAssistantError(message: {
|
|
16
|
-
diagnostics?: AssistantMessageDiagnostic[];
|
|
17
|
-
} | null | undefined): boolean;
|
|
18
|
-
/** Formats arbitrary thrown values into diagnostic-safe text. */
|
|
19
|
-
declare function formatThrownValue(value: unknown): string;
|
|
20
|
-
/** Extracts serializable diagnostic error fields from Error and non-Error throws. */
|
|
21
|
-
declare function extractDiagnosticError(error: unknown): DiagnosticErrorInfo;
|
|
22
|
-
/** Creates a timestamped assistant-message diagnostic entry. */
|
|
23
|
-
declare function createAssistantMessageDiagnostic(type: string, error: unknown, details?: Record<string, unknown>): AssistantMessageDiagnostic;
|
|
24
|
-
/** Appends a diagnostic while preserving existing message diagnostics. */
|
|
25
|
-
declare function appendAssistantMessageDiagnostic(message: {
|
|
26
|
-
diagnostics?: AssistantMessageDiagnostic[];
|
|
27
|
-
}, diagnostic: AssistantMessageDiagnostic): void;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { extractDiagnosticError as a, createAssistantMessageDiagnostic as i, DiagnosticErrorInfo as n, formatThrownValue as o, appendAssistantMessageDiagnostic as r, isProviderRefusalAssistantError as s, AssistantMessageDiagnostic as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./event-stream-C1Z2piyk.mjs";
|
package/dist/hash-CHgqbJmD.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/utils/hash.ts
|
|
2
|
-
/** Fast deterministic hash to shorten long strings */
|
|
3
|
-
function shortHash(str) {
|
|
4
|
-
let h1 = 3735928559;
|
|
5
|
-
let h2 = 1103547991;
|
|
6
|
-
for (let i = 0; i < str.length; i++) {
|
|
7
|
-
const ch = str.charCodeAt(i);
|
|
8
|
-
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
9
|
-
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
10
|
-
}
|
|
11
|
-
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
12
|
-
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
13
|
-
return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
export { shortHash as t };
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { t as asNonArrayRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
2
|
-
import { parse } from "partial-json";
|
|
3
|
-
//#region packages/ai/src/utils/json-parse.ts
|
|
4
|
-
const VALID_JSON_ESCAPES = /* @__PURE__ */ new Set([
|
|
5
|
-
"\"",
|
|
6
|
-
"\\",
|
|
7
|
-
"/",
|
|
8
|
-
"b",
|
|
9
|
-
"f",
|
|
10
|
-
"n",
|
|
11
|
-
"r",
|
|
12
|
-
"t",
|
|
13
|
-
"u"
|
|
14
|
-
]);
|
|
15
|
-
const JSON_CONTROL_ESCAPES = /* @__PURE__ */ new Set([
|
|
16
|
-
"b",
|
|
17
|
-
"f",
|
|
18
|
-
"n",
|
|
19
|
-
"r",
|
|
20
|
-
"t"
|
|
21
|
-
]);
|
|
22
|
-
function isControlCharacter(char) {
|
|
23
|
-
const codePoint = char.codePointAt(0);
|
|
24
|
-
return codePoint !== void 0 && codePoint >= 0 && codePoint <= 31;
|
|
25
|
-
}
|
|
26
|
-
function escapeControlCharacter(char) {
|
|
27
|
-
switch (char) {
|
|
28
|
-
case "\b": return "\\b";
|
|
29
|
-
case "\f": return "\\f";
|
|
30
|
-
case "\n": return "\\n";
|
|
31
|
-
case "\r": return "\\r";
|
|
32
|
-
case " ": return "\\t";
|
|
33
|
-
default: return `\\u${char.codePointAt(0)?.toString(16).padStart(4, "0") ?? "0000"}`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Repairs malformed JSON string literals by:
|
|
38
|
-
* - escaping raw control characters inside strings
|
|
39
|
-
* - doubling backslashes before invalid escape characters
|
|
40
|
-
*/
|
|
41
|
-
function repairJson(json) {
|
|
42
|
-
let repaired = "";
|
|
43
|
-
let inString = false;
|
|
44
|
-
let stringValuePrefix = "";
|
|
45
|
-
for (let index = 0; index < json.length; index++) {
|
|
46
|
-
const char = json.charAt(index);
|
|
47
|
-
if (!inString) {
|
|
48
|
-
repaired += char;
|
|
49
|
-
if (char === "\"") {
|
|
50
|
-
inString = true;
|
|
51
|
-
stringValuePrefix = "";
|
|
52
|
-
}
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (char === "\"") {
|
|
56
|
-
repaired += char;
|
|
57
|
-
inString = false;
|
|
58
|
-
stringValuePrefix = "";
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (char === "\\") {
|
|
62
|
-
const nextChar = json.charAt(index + 1);
|
|
63
|
-
if (!nextChar) {
|
|
64
|
-
repaired += "\\\\";
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (nextChar === "u") {
|
|
68
|
-
const unicodeDigits = json.slice(index + 2, index + 6);
|
|
69
|
-
if (/^[0-9a-fA-F]{4}$/.test(unicodeDigits)) {
|
|
70
|
-
repaired += `\\u${unicodeDigits}`;
|
|
71
|
-
stringValuePrefix += `\\u${unicodeDigits}`;
|
|
72
|
-
index += 5;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
repaired += "\\\\";
|
|
76
|
-
stringValuePrefix += "\\";
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (JSON_CONTROL_ESCAPES.has(nextChar) && looksLikeWindowsPathPrefix(stringValuePrefix)) {
|
|
80
|
-
repaired += "\\\\";
|
|
81
|
-
stringValuePrefix += "\\";
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (VALID_JSON_ESCAPES.has(nextChar)) {
|
|
85
|
-
repaired += `\\${nextChar}`;
|
|
86
|
-
stringValuePrefix += nextChar === "\\" ? "\\" : `\\${nextChar}`;
|
|
87
|
-
index += 1;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
repaired += "\\\\";
|
|
91
|
-
stringValuePrefix += "\\";
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
repaired += isControlCharacter(char) ? escapeControlCharacter(char) : char;
|
|
95
|
-
stringValuePrefix += char;
|
|
96
|
-
}
|
|
97
|
-
return repaired;
|
|
98
|
-
}
|
|
99
|
-
function parseJsonWithRepair(json) {
|
|
100
|
-
return JSON.parse(repairJson(json));
|
|
101
|
-
}
|
|
102
|
-
function looksLikeWindowsPathPrefix(prefix) {
|
|
103
|
-
const tail = prefix.slice(-160);
|
|
104
|
-
return /(?:^|[^A-Za-z0-9])[A-Za-z]:(?:[\\/][^"\\/:*?<>|\r\n]*)*$/.test(tail);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Attempts to parse potentially incomplete JSON during streaming.
|
|
108
|
-
* Always returns a valid object, even if the JSON is incomplete.
|
|
109
|
-
*
|
|
110
|
-
* @param partialJson The partial JSON string from streaming
|
|
111
|
-
* @returns Parsed object or empty object if parsing fails
|
|
112
|
-
*/
|
|
113
|
-
function parseStreamingJson(partialJson) {
|
|
114
|
-
if (!partialJson || partialJson.trim() === "") return {};
|
|
115
|
-
try {
|
|
116
|
-
return asNonArrayRecord(parseJsonWithRepair(partialJson));
|
|
117
|
-
} catch {
|
|
118
|
-
try {
|
|
119
|
-
return asNonArrayRecord(parse(partialJson));
|
|
120
|
-
} catch {
|
|
121
|
-
try {
|
|
122
|
-
return asNonArrayRecord(parse(repairJson(partialJson)));
|
|
123
|
-
} catch {
|
|
124
|
-
return {};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const TOOL_ARGUMENT_PREVIEW_FIRST_CHECKPOINT_CHARS = 512;
|
|
130
|
-
/**
|
|
131
|
-
* Streamed tool-call arguments are preview-only; the terminal parse re-reads
|
|
132
|
-
* the full buffer authoritatively at content_block_stop. Reparsing every delta
|
|
133
|
-
* scans an ever-growing buffer and makes assembly quadratic in the argument
|
|
134
|
-
* size, so refresh previews on a geometric length schedule instead — bounded
|
|
135
|
-
* staleness, linear total parse work.
|
|
136
|
-
*/
|
|
137
|
-
function createToolArgumentPreviewSchedule() {
|
|
138
|
-
let nextCheckpointChars = TOOL_ARGUMENT_PREVIEW_FIRST_CHECKPOINT_CHARS;
|
|
139
|
-
return (accumulatedChars) => {
|
|
140
|
-
if (accumulatedChars < nextCheckpointChars) return false;
|
|
141
|
-
nextCheckpointChars = accumulatedChars * 2;
|
|
142
|
-
return true;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
146
|
-
export { repairJson as i, parseJsonWithRepair as n, parseStreamingJson as r, createToolArgumentPreviewSchedule as t };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { d as stripSystemPromptCacheBoundary } from "./simple-options-tcKOqnpF.mjs";
|
|
2
|
-
import { g as sanitizeTransportPayloadText } from "./transport-stream-shared-Cu3ZPhNW.mjs";
|
|
3
|
-
import { S as responsesPromptObserver } from "./openai-responses-compaction-window-D5jbzCi3.mjs";
|
|
4
|
-
//#region packages/ai/src/transports/openai-responses-prompt-observer-internal.ts
|
|
5
|
-
function readFinalResponsesPrompt(request) {
|
|
6
|
-
if (typeof request.instructions === "string") return ["instructions", request.instructions];
|
|
7
|
-
const message = (Array.isArray(request.input) ? request.input : []).find((item) => {
|
|
8
|
-
const role = item.role;
|
|
9
|
-
return role === "developer" || role === "system";
|
|
10
|
-
});
|
|
11
|
-
if (!message) return ["missing", ""];
|
|
12
|
-
const content = message.content;
|
|
13
|
-
const observedPrompt = typeof content === "string" ? content : Array.isArray(content) ? content.flatMap((part) => part.type === "input_text" ? [part.text] : []).join("") : "";
|
|
14
|
-
return [message.role === "developer" ? "input.developer" : "input.system", observedPrompt];
|
|
15
|
-
}
|
|
16
|
-
function createResponsesPromptEgressObserver(options, assembledPrompt) {
|
|
17
|
-
const observer = options ? responsesPromptObserver.get(options) : void 0;
|
|
18
|
-
if (!observer) return;
|
|
19
|
-
const expectedPrompt = sanitizeTransportPayloadText(stripSystemPromptCacheBoundary(assembledPrompt ?? ""));
|
|
20
|
-
return (request, metadata) => {
|
|
21
|
-
const [promptSource, observedPrompt] = readFinalResponsesPrompt(request);
|
|
22
|
-
observer({
|
|
23
|
-
...metadata,
|
|
24
|
-
promptSource,
|
|
25
|
-
expectedChars: expectedPrompt.length,
|
|
26
|
-
observedChars: observedPrompt.length,
|
|
27
|
-
matchesAssembledPrompt: promptSource !== "missing" && observedPrompt === expectedPrompt
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { createResponsesPromptEgressObserver as t };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { l as requiresClaudeMandatoryAdaptiveThinking, p as resolveClaudeNativeThinkingLevelMap, t as calculateUsageCost } from "./src-B2Q_6G8V.mjs";
|
|
2
|
-
//#region packages/ai/src/model-utils.ts
|
|
3
|
-
/** Calculates and stores model cost fields from token usage and per-million pricing. */
|
|
4
|
-
function calculateCost(model, usage) {
|
|
5
|
-
Object.assign(usage.cost, calculateUsageCost(usage, model.cost));
|
|
6
|
-
return usage.cost;
|
|
7
|
-
}
|
|
8
|
-
/** Replaces the catalog estimate when the provider reports an authoritative billed total. */
|
|
9
|
-
function applyProviderReportedUsageCost(usage, reportedCost) {
|
|
10
|
-
if (typeof reportedCost !== "number" || !Number.isFinite(reportedCost) || reportedCost < 0) return;
|
|
11
|
-
usage.cost.total = reportedCost;
|
|
12
|
-
usage.cost.totalOrigin = "provider-billed";
|
|
13
|
-
}
|
|
14
|
-
const EXTENDED_THINKING_LEVELS = [
|
|
15
|
-
"off",
|
|
16
|
-
"minimal",
|
|
17
|
-
"low",
|
|
18
|
-
"medium",
|
|
19
|
-
"high",
|
|
20
|
-
"xhigh",
|
|
21
|
-
"max"
|
|
22
|
-
];
|
|
23
|
-
function resolveThinkingLevelMap(model) {
|
|
24
|
-
return model.api === "anthropic-messages" ? resolveClaudeNativeThinkingLevelMap(model) ?? model.thinkingLevelMap : model.thinkingLevelMap;
|
|
25
|
-
}
|
|
26
|
-
/** Returns thinking levels exposed by a reasoning-capable model. */
|
|
27
|
-
function getSupportedThinkingLevels(model) {
|
|
28
|
-
const mandatoryAdaptiveContract = model.api === "anthropic-messages" && requiresClaudeMandatoryAdaptiveThinking(model);
|
|
29
|
-
if (!model.reasoning && !mandatoryAdaptiveContract) return ["off"];
|
|
30
|
-
const thinkingLevelMap = resolveThinkingLevelMap(model);
|
|
31
|
-
return EXTENDED_THINKING_LEVELS.filter((level) => {
|
|
32
|
-
const mapped = thinkingLevelMap?.[level];
|
|
33
|
-
if (mapped === null) return false;
|
|
34
|
-
if (level === "xhigh" || level === "max") return mapped !== void 0;
|
|
35
|
-
return true;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/** Clamps a requested thinking level to the closest supported level for a model. */
|
|
39
|
-
function clampThinkingLevel(model, level) {
|
|
40
|
-
const availableLevels = getSupportedThinkingLevels(model);
|
|
41
|
-
if (availableLevels.includes(level)) return level;
|
|
42
|
-
const requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);
|
|
43
|
-
if (requestedIndex === -1) return availableLevels[0] ?? "off";
|
|
44
|
-
const thinkingLevelMap = resolveThinkingLevelMap(model);
|
|
45
|
-
if ((level === "xhigh" || level === "max") && thinkingLevelMap?.[level] === null) {
|
|
46
|
-
for (const candidate of EXTENDED_THINKING_LEVELS.slice(0, requestedIndex).toReversed()) if (availableLevels.includes(candidate)) return candidate;
|
|
47
|
-
}
|
|
48
|
-
for (const candidate of EXTENDED_THINKING_LEVELS.slice(requestedIndex)) if (availableLevels.includes(candidate)) return candidate;
|
|
49
|
-
for (const candidate of EXTENDED_THINKING_LEVELS.slice(0, requestedIndex).toReversed()) if (availableLevels.includes(candidate)) return candidate;
|
|
50
|
-
return availableLevels[0] ?? "off";
|
|
51
|
-
}
|
|
52
|
-
/** Compares model identity by provider and id. */
|
|
53
|
-
function modelsAreEqual(a, b) {
|
|
54
|
-
if (!a || !b) return false;
|
|
55
|
-
return a.id === b.id && a.provider === b.provider;
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region packages/ai/src/utils/sanitize-unicode.ts
|
|
59
|
-
/**
|
|
60
|
-
* Removes unpaired Unicode surrogate characters from a string.
|
|
61
|
-
*
|
|
62
|
-
* Unpaired surrogates (high surrogates 0xD800-0xDBFF without matching low surrogates 0xDC00-0xDFFF,
|
|
63
|
-
* or vice versa) cause JSON serialization errors in many API providers.
|
|
64
|
-
*
|
|
65
|
-
* Valid emoji and other characters outside the Basic Multilingual Plane use properly paired
|
|
66
|
-
* surrogates and will NOT be affected by this function.
|
|
67
|
-
*
|
|
68
|
-
* @param text - The text to sanitize
|
|
69
|
-
* @returns The sanitized text with unpaired surrogates removed
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* // Valid emoji (properly paired surrogates) are preserved
|
|
73
|
-
* sanitizeSurrogates("Hello 🙈 World") // => "Hello 🙈 World"
|
|
74
|
-
*
|
|
75
|
-
* // Unpaired high surrogate is removed
|
|
76
|
-
* const unpaired = String.fromCharCode(0xD83D); // high surrogate without low
|
|
77
|
-
* sanitizeSurrogates(`Text ${unpaired} here`) // => "Text here"
|
|
78
|
-
*/
|
|
79
|
-
function sanitizeSurrogates(text) {
|
|
80
|
-
return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "");
|
|
81
|
-
}
|
|
82
|
-
//#endregion
|
|
83
|
-
export { getSupportedThinkingLevels as a, clampThinkingLevel as i, applyProviderReportedUsageCost as n, modelsAreEqual as o, calculateCost as r, sanitizeSurrogates as t };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
2
|
-
import { types } from "node:util";
|
|
3
|
-
//#region packages/ai/src/providers/tool-schema-json-projection.ts
|
|
4
|
-
function isNonFiniteNumberValue(value) {
|
|
5
|
-
if (typeof value === "number") return !Number.isFinite(value);
|
|
6
|
-
if (value === null || typeof value !== "object" || !types.isNumberObject(value)) return false;
|
|
7
|
-
return !Number.isFinite(Number.prototype.valueOf.call(value));
|
|
8
|
-
}
|
|
9
|
-
function serializeToolInputSchema(value, path) {
|
|
10
|
-
const nonFiniteNumber = { path: null };
|
|
11
|
-
const paths = /* @__PURE__ */ new WeakMap();
|
|
12
|
-
let isRoot = true;
|
|
13
|
-
let text;
|
|
14
|
-
try {
|
|
15
|
-
text = JSON.stringify(value, function(key, entry) {
|
|
16
|
-
const invalidNumber = nonFiniteNumber.path === null && isNonFiniteNumberValue(entry);
|
|
17
|
-
if (invalidNumber || entry && typeof entry === "object") {
|
|
18
|
-
const holderPath = paths.get(this);
|
|
19
|
-
const entryPath = isRoot ? path : holderPath === void 0 ? `${path}.${key}` : Array.isArray(this) ? `${holderPath}[${key}]` : `${holderPath}.${key}`;
|
|
20
|
-
if (invalidNumber) nonFiniteNumber.path = entryPath;
|
|
21
|
-
else paths.set(entry, entryPath);
|
|
22
|
-
}
|
|
23
|
-
isRoot = false;
|
|
24
|
-
return entry;
|
|
25
|
-
});
|
|
26
|
-
} catch {
|
|
27
|
-
return {
|
|
28
|
-
schema: {},
|
|
29
|
-
violations: [`${path} is not JSON-serializable`]
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (!text) return {
|
|
33
|
-
schema: {},
|
|
34
|
-
violations: [`${path} is not JSON-serializable`]
|
|
35
|
-
};
|
|
36
|
-
if (nonFiniteNumber.path !== null) return {
|
|
37
|
-
schema: {},
|
|
38
|
-
violations: [`${nonFiniteNumber.path} is not JSON-serializable`]
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
schema: JSON.parse(text),
|
|
42
|
-
violations: []
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
const schemaMapKeywords = /* @__PURE__ */ new Set([
|
|
46
|
-
"$defs",
|
|
47
|
-
"definitions",
|
|
48
|
-
"dependencies",
|
|
49
|
-
"dependentSchemas",
|
|
50
|
-
"patternProperties",
|
|
51
|
-
"properties"
|
|
52
|
-
]);
|
|
53
|
-
function inspectJsonSchema(schema, path, violations) {
|
|
54
|
-
if (Array.isArray(schema)) return schema.every((entry, index) => inspectJsonSchema(entry, `${path}[${index}]`, violations));
|
|
55
|
-
if (!isRecord(schema)) return typeof schema !== "number" || Number.isFinite(schema);
|
|
56
|
-
for (const key of ["$dynamicRef", "$dynamicAnchor"]) if (key in schema) violations.push(`${path}.${key}`);
|
|
57
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
58
|
-
if (typeof value === "number" && !Number.isFinite(value)) return false;
|
|
59
|
-
if (!value || typeof value !== "object") continue;
|
|
60
|
-
if (schemaMapKeywords.has(key) && isRecord(value)) {
|
|
61
|
-
for (const [schemaName, childSchema] of Object.entries(value)) if (!inspectJsonSchema(childSchema, `${path}.${key}.${schemaName}`, violations)) return false;
|
|
62
|
-
} else if (!inspectJsonSchema(value, `${path}.${key}`, violations)) return false;
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
67
|
-
function projectRuntimeToolInputSchema(schema, path = "parameters") {
|
|
68
|
-
const projection = serializeToolInputSchema(schema, path);
|
|
69
|
-
const violations = [...projection.violations];
|
|
70
|
-
if (!isRecord(projection.schema)) violations.push(`${path} must be a JSON object schema`);
|
|
71
|
-
else if (projection.schema.type !== void 0 && projection.schema.type !== "object") violations.push(`${path}.type must be "object"`);
|
|
72
|
-
if (!inspectJsonSchema(projection.schema, path, violations)) return {
|
|
73
|
-
schema: {},
|
|
74
|
-
violations: [`${path} is not a JSON value`]
|
|
75
|
-
};
|
|
76
|
-
return {
|
|
77
|
-
schema: projection.schema,
|
|
78
|
-
violations
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
export { projectRuntimeToolInputSchema as t };
|