@openclaw/ai 2026.9.1-beta.1 → 2026.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-DI4PZKKB.mjs → anthropic-BDdqdVLK.mjs} +222 -216
- package/dist/{anthropic-compaction-replay-nhKaCXu6.mjs → anthropic-compaction-replay-DB2FGLQc.mjs} +160 -68
- package/dist/{anthropic-payload-policy-B_0n0enE.d.mts → anthropic-payload-policy-d46X2pR0.d.mts} +28 -4
- package/dist/{api-registry-CTd8NzcD.d.mts → api-registry-DWtPjzyn.d.mts} +2 -2
- package/dist/{azure-openai-responses-D8dI0ekg.mjs → azure-openai-responses-C5bZRfAP.mjs} +12 -9
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/{diagnostics-COpOtRwq.mjs → diagnostics-CPeq9F7y.mjs} +5 -1
- package/dist/diagnostics-DfFyKeX_.mjs +136 -0
- package/dist/{diagnostics-BaTA9eVl.d.mts → diagnostics-DnPnOui6.d.mts} +5 -1
- package/dist/diagnostics.d.mts +8 -3
- package/dist/diagnostics.mjs +4 -3
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/{event-stream-uSMZJ3FA.mjs → event-stream-BgDvQeum.mjs} +3 -9
- package/dist/{event-stream-LiXePESD.d.mts → event-stream-BhT5T1Ay.d.mts} +1 -1
- package/dist/event-stream-zctLx0yr.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-Od-LLdVK.mjs → google-4qeuE8iX.mjs} +9 -7
- package/dist/{google-shared-Bgr9lFPw.mjs → google-shared-CWeG8RIl.mjs} +27 -23
- package/dist/{google-vertex-aerRSXc4.mjs → google-vertex-O9BcnB6X.mjs} +8 -6
- package/dist/{host-D51fmkH6.mjs → host-CEvLw30U.mjs} +54 -9
- package/dist/{host-DsbPMFU6.d.mts → host-DjzGmdZ2.d.mts} +3 -3
- package/dist/index-FnHM2FcI.d.mts +117 -0
- package/dist/index.d.mts +10 -11
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +59 -55
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +2 -3
- package/dist/internal/openai.d.mts +66 -64
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +43 -43
- package/dist/internal/runtime.mjs +10 -8
- package/dist/internal/shared.d.mts +25 -25
- package/dist/internal/shared.mjs +95 -4
- package/dist/{mistral-EiHdymeb.mjs → mistral-Tb6oalqH.mjs} +30 -23
- package/dist/{openai-chatgpt-responses-DHpF9o1e.mjs → openai-chatgpt-responses-yUXjPNfu.mjs} +76 -137
- package/dist/{openai-completions-EFPiUGfS.mjs → openai-completions-BIUV3RDT.mjs} +26 -22
- package/dist/{openai-completions-compat-BefmHT26.d.mts → openai-completions-compat-CpjYUArk.d.mts} +5 -5
- package/dist/{openai-completions-stream-DUlGwRMz.mjs → openai-completions-stream-BsrBe3Gg.mjs} +103 -96
- package/dist/openai-prompt-cache-CGnVB74a.mjs +21 -0
- package/dist/openai-prompt-cache-CNoIfHYC.d.mts +16 -0
- package/dist/{openai-responses-BogP8OjX.mjs → openai-responses-CCL41ALM.mjs} +15 -14
- package/dist/openai-responses-compaction-window-BMVHFOtq.mjs +697 -0
- package/dist/{openai-responses-contracts-Dvj_UtPy.d.mts → openai-responses-contracts-rF5DDRNS.d.mts} +23 -6
- package/dist/{openai-responses-payload-policy-CNGFT9zr.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +1 -0
- package/dist/{openai-responses-prompt-observer-internal-Cd4hJG-S.mjs → openai-responses-prompt-observer-internal-D0bhBfgL.mjs} +4 -18
- package/dist/{openai-responses-shared-DJThc6jW.mjs → openai-responses-shared-Bmma_3Qc.mjs} +438 -309
- package/dist/{openai-tool-schema-ho-hIkQf.mjs → openai-tool-schema-_pTAJqKF.mjs} +30 -40
- package/dist/{provider-error-DDOs_Bz0.mjs → provider-error-9TraxGvt.mjs} +20 -92
- package/dist/{provider-options-MdMBLzlU.d.mts → provider-options-Bcc_p-TU.d.mts} +26 -6
- package/dist/provider-replay-context-BuSUaAk5.mjs +21 -0
- package/dist/{provider-transcript-transform-C01bQ5a3.mjs → provider-transcript-transform-BaMbI1hr.mjs} +1 -1
- package/dist/provider-types.d.mts +19 -20
- package/dist/providers.d.mts +6 -6
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-DLCNXki6.mjs} +158 -94
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-DCkltN94.mjs → sanitize-unicode-D6xUvZaS.mjs} +2 -8
- package/dist/{simple-options-CFj7x3J4.mjs → simple-options-BjHCCh4v.mjs} +42 -6
- package/dist/{src-Bu3FiFAG.mjs → src-2qBGKg8O.mjs} +83 -2
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{tool-schema-json-projection-qvTEs5Am.mjs → tool-schema-json-projection-mJhXDcyz.mjs} +21 -31
- package/dist/{transport-stream-shared-ljShVIZB.mjs → transport-stream-shared-CZqMhfIw.mjs} +19 -6
- package/dist/{transport-stream-shared-rvaCyFYt.d.mts → transport-stream-shared-xnaqxmbP.d.mts} +5 -5
- package/dist/{transport-utils-LJ1_rbi-.mjs → transport-utils-7il795_9.mjs} +5 -8
- package/dist/transports.d.mts +121 -85
- package/dist/transports.mjs +747 -464
- package/dist/types-3Lnm-QSJ.d.mts +1 -0
- package/dist/{types-DhLoJbFm.d.mts → types-CJ1-Ht7A.d.mts} +55 -19
- package/dist/types.d.mts +7 -7
- package/dist/types.mjs +5 -5
- package/dist/{validation-Dk7q7NMN.d.mts → validation-AKZBDGQd.d.mts} +1 -1
- package/dist/{validation-B61OhAio.mjs → validation-CJZtym2g.mjs} +7 -5
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +5 -5
- package/dist/anthropic-BECQCNdF.d.mts +0 -98
- package/dist/event-stream-BKp4fOt_.d.mts +0 -1
- package/dist/index-Qbej8io0.d.mts +0 -3
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/openai-responses-contracts-QUY12X0B.mjs +0 -233
- package/dist/openai-responses-payload-policy-D8EdimYe.mjs +0 -204
- package/dist/provider-options-AvldWZt8.mjs +0 -21
- package/dist/tls-certificate-errors-DXSpluKI.mjs +0 -93
- package/dist/types-GiAjXatj.d.mts +0 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as isProviderRefusalAssistantError } from "../diagnostics-CPeq9F7y.mjs";
|
|
2
2
|
import { n as createApiRegistry, t as createLlmRuntime } from "../stream-CREqxHgU.mjs";
|
|
3
|
-
import { a as getSupportedThinkingLevels, i as clampThinkingLevel, n as applyProviderReportedUsageCost, o as modelsAreEqual, r as calculateCost, t as sanitizeSurrogates } from "../sanitize-unicode-
|
|
4
|
-
import {
|
|
3
|
+
import { a as getSupportedThinkingLevels, i as clampThinkingLevel, n as applyProviderReportedUsageCost, o as modelsAreEqual, r as calculateCost, t as sanitizeSurrogates } from "../sanitize-unicode-D6xUvZaS.mjs";
|
|
4
|
+
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-DLCNXki6.mjs";
|
|
5
|
+
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-bktO00EJ.mjs";
|
|
6
|
+
import { C as headersToRecord, m as parseTerminalToolCallArguments } from "../transport-stream-shared-CZqMhfIw.mjs";
|
|
5
7
|
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-DAvyP7qA.mjs";
|
|
6
8
|
import { i as repairJson, n as parseJsonWithRepair, r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "../json-parse-BuAJEbdW.mjs";
|
|
7
9
|
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-BjtkplhG.mjs";
|
|
8
10
|
import { t as shortHash } from "../hash-CHgqbJmD.mjs";
|
|
9
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-
|
|
10
|
-
import { t as
|
|
11
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-DcNjoFQE.mjs";
|
|
12
|
+
import { t as createSseByteGuard } from "../streaming-byte-guard-CC-HMn_u.mjs";
|
|
11
13
|
import { n as registerSessionResourceCleanup, t as cleanupSessionResources } from "../session-resources-CkR4WWy1.mjs";
|
|
12
14
|
import { n as resolveOpenAICodexAccountId, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
13
|
-
import { t as createSseByteGuard } from "../streaming-byte-guard-CC-HMn_u.mjs";
|
|
14
15
|
//#region packages/ai/src/internal/default-runtime.ts
|
|
15
16
|
const DEFAULT_RUNTIME_KEY = Symbol.for("openclaw.ai.defaultRuntime");
|
|
16
17
|
function resolveDefaultRuntime() {
|
|
@@ -54,7 +55,7 @@ const CONTEXT_OVERFLOW_PATTERN_SCOPES = {
|
|
|
54
55
|
/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,
|
|
55
56
|
/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,
|
|
56
57
|
/exceeds the limit of \d+/i,
|
|
57
|
-
/exceeds the available context size/i,
|
|
58
|
+
/(?:exceeds the available context size|context size has been exceeded)/i,
|
|
58
59
|
/greater than the context length/i,
|
|
59
60
|
/context window exceeds limit/i,
|
|
60
61
|
/exceeded model token limit/i,
|
|
@@ -100,7 +101,7 @@ const CONTEXT_OVERFLOW_PATTERN_SCOPES = {
|
|
|
100
101
|
/\binput exceeds the maximum number of tokens\b/i,
|
|
101
102
|
/\bollama error:\s*context length exceeded(?:,\s*too many tokens)?\b/i,
|
|
102
103
|
/\btotal tokens?.*exceeds? (?:the )?(?:model(?:'s)? )?(?:max|maximum|limit)/i,
|
|
103
|
-
/\b(?:request|prompt) \(\d[\d,]*\s*tokens?\) exceeds (?:the )?available context size\b/i,
|
|
104
|
+
/\b(?:(?:request|prompt) \(\d[\d,]*\s*tokens?\) exceeds (?:the )?available context size|context size has been exceeded)\b/i,
|
|
104
105
|
/\binput (?:is )?too long for (?:the )?model\b/i
|
|
105
106
|
],
|
|
106
107
|
"failover-hint": [/context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|prompt.*(too (?:large|long)|exceed|over|limit|max(?:imum)?)|(?:request|input).*(?:context|window|length|token).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i],
|
|
@@ -183,6 +184,7 @@ function resolveContextInputTokens(message) {
|
|
|
183
184
|
* @returns true if the message indicates a context overflow
|
|
184
185
|
*/
|
|
185
186
|
function isContextOverflow(message, contextWindow) {
|
|
187
|
+
if (isProviderRefusalAssistantError(message)) return false;
|
|
186
188
|
if (message.stopReason === "error" && message.errorMessage) {
|
|
187
189
|
const errorMessage = message.errorMessage;
|
|
188
190
|
if (!NON_OVERFLOW_PATTERNS.some((p) => p.test(errorMessage)) && matchesContextOverflowMessage(errorMessage, "assistant-error")) return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as Model, E as Message, J as
|
|
2
|
-
import "../types-
|
|
1
|
+
import { $ as ThinkingLevel, D as Model, E as Message, J as StreamOptions, W as SimpleStreamOptions, Z as ThinkingBudgets, a as AssistantMessage, n as Api } from "../types-CJ1-Ht7A.mjs";
|
|
2
|
+
import "../types-3Lnm-QSJ.mjs";
|
|
3
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
4
4
|
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-Cwcjv_fx.mjs";
|
|
5
5
|
//#region packages/ai/src/providers/simple-options.d.ts
|
|
@@ -7,29 +7,29 @@ type FirstEventStreamOptions = {
|
|
|
7
7
|
firstEventTimeoutMs?: number;
|
|
8
8
|
onFirstEventTimeout?: (reason: Error) => void;
|
|
9
9
|
};
|
|
10
|
-
declare function buildBaseOptions(model: Model, options?: SimpleStreamOptions, apiKey?: string): StreamOptions & FirstEventStreamOptions;
|
|
11
|
-
declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number): number;
|
|
12
|
-
declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number | undefined): number | undefined;
|
|
13
|
-
declare function clampReasoning(effort: ThinkingLevel): Exclude<ThinkingLevel, "xhigh">;
|
|
14
|
-
declare function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, "xhigh"> | undefined;
|
|
15
|
-
declare function adjustMaxTokensForThinking(baseMaxTokens: number | undefined, modelMaxTokens: number, reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): {
|
|
10
|
+
export declare function buildBaseOptions(model: Model, options?: SimpleStreamOptions, apiKey?: string): StreamOptions & FirstEventStreamOptions;
|
|
11
|
+
export declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number): number;
|
|
12
|
+
export declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number | undefined): number | undefined;
|
|
13
|
+
export declare function clampReasoning(effort: ThinkingLevel): Exclude<ThinkingLevel, "xhigh">;
|
|
14
|
+
export declare function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, "xhigh"> | undefined;
|
|
15
|
+
export declare function adjustMaxTokensForThinking(baseMaxTokens: number | undefined, modelMaxTokens: number, reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): {
|
|
16
16
|
maxTokens: number;
|
|
17
17
|
thinkingBudget: number;
|
|
18
18
|
};
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region packages/ai/src/providers/tool-result-text.d.ts
|
|
21
21
|
/** Media metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
22
|
-
declare function hasMediaPayload(block: unknown): block is Record<string, unknown> & {
|
|
22
|
+
export declare function hasMediaPayload(block: unknown): block is Record<string, unknown> & {
|
|
23
23
|
data: string;
|
|
24
24
|
};
|
|
25
25
|
/** Image metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
26
|
-
declare function isImageWithMediaPayload<T>(block: T): block is T & {
|
|
26
|
+
export declare function isImageWithMediaPayload<T>(block: T): block is T & {
|
|
27
27
|
type: "image";
|
|
28
28
|
data: string;
|
|
29
29
|
};
|
|
30
|
-
declare function describeToolResultMediaPlaceholder(blocks: readonly unknown[]): string | undefined;
|
|
31
|
-
declare function extractToolResultBlockText(block: unknown): string | undefined;
|
|
32
|
-
declare function extractToolResultText(blocks: readonly unknown[], options?: {
|
|
30
|
+
export declare function describeToolResultMediaPlaceholder(blocks: readonly unknown[]): string | undefined;
|
|
31
|
+
export declare function extractToolResultBlockText(block: unknown): string | undefined;
|
|
32
|
+
export declare function extractToolResultText(blocks: readonly unknown[], options?: {
|
|
33
33
|
includeStructured?: boolean;
|
|
34
34
|
}): string;
|
|
35
35
|
type ToolResultMediaSupport = {
|
|
@@ -37,8 +37,8 @@ type ToolResultMediaSupport = {
|
|
|
37
37
|
audio: boolean;
|
|
38
38
|
};
|
|
39
39
|
/** Describe media that cannot be represented on the target provider wire. */
|
|
40
|
-
declare function describeUnsupportedToolResultMedia(blocks: readonly unknown[], support: ToolResultMediaSupport): string | undefined;
|
|
41
|
-
declare function formatToolResultText(params: {
|
|
40
|
+
export declare function describeUnsupportedToolResultMedia(blocks: readonly unknown[], support: ToolResultMediaSupport): string | undefined;
|
|
41
|
+
export declare function formatToolResultText(params: {
|
|
42
42
|
text: string;
|
|
43
43
|
mediaPlaceholder?: string;
|
|
44
44
|
omittedMediaPlaceholder?: string;
|
|
@@ -46,29 +46,29 @@ declare function formatToolResultText(params: {
|
|
|
46
46
|
}): string;
|
|
47
47
|
//#endregion
|
|
48
48
|
//#region packages/ai/src/transcript-transform.d.ts
|
|
49
|
-
declare function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>, normalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string): Message[];
|
|
49
|
+
export declare function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>, normalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string): Message[];
|
|
50
50
|
//#endregion
|
|
51
51
|
//#region packages/ai/src/utils/system-prompt-cache-boundary.d.ts
|
|
52
|
-
declare const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
53
|
-
declare function stripSystemPromptCacheBoundary(text: string): string;
|
|
54
|
-
declare function ensureSystemPromptCacheBoundary(systemPrompt: string): string;
|
|
55
|
-
declare function splitSystemPromptCacheBoundary(text: string): {
|
|
52
|
+
export declare const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
53
|
+
export declare function stripSystemPromptCacheBoundary(text: string): string;
|
|
54
|
+
export declare function ensureSystemPromptCacheBoundary(systemPrompt: string): string;
|
|
55
|
+
export declare function splitSystemPromptCacheBoundary(text: string): {
|
|
56
56
|
stablePrefix: string;
|
|
57
57
|
dynamicSuffix: string;
|
|
58
58
|
} | undefined;
|
|
59
|
-
declare function prependSystemPromptAdditionAfterCacheBoundary(params: {
|
|
59
|
+
export declare function prependSystemPromptAdditionAfterCacheBoundary(params: {
|
|
60
60
|
systemPrompt: string;
|
|
61
61
|
systemPromptAddition?: string;
|
|
62
62
|
}): string;
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region packages/ai/src/utils/tls-certificate-errors.d.ts
|
|
65
|
-
type TlsCertificateErrorKind = "certificate_invalid" | "hostname_mismatch";
|
|
66
|
-
type TlsCertificateErrorDetails = {
|
|
65
|
+
export type TlsCertificateErrorKind = "certificate_invalid" | "hostname_mismatch";
|
|
66
|
+
export type TlsCertificateErrorDetails = {
|
|
67
67
|
kind: TlsCertificateErrorKind;
|
|
68
68
|
code?: string;
|
|
69
69
|
message: string;
|
|
70
70
|
};
|
|
71
71
|
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
72
|
-
declare function inspectTlsCertificateError(error: unknown): TlsCertificateErrorDetails | null;
|
|
72
|
+
export declare function inspectTlsCertificateError(error: unknown): TlsCertificateErrorDetails | null;
|
|
73
73
|
//#endregion
|
|
74
|
-
export {
|
|
74
|
+
export { normalizePromptCapabilityIds, normalizeStructuredPromptSection, sanitizeSurrogates, sortPromptCacheToolsByName };
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,5 +1,96 @@
|
|
|
1
|
-
import { t as sanitizeSurrogates } from "../sanitize-unicode-
|
|
2
|
-
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, i as transformMessages, l as formatToolResultText, o as describeUnsupportedToolResultMedia, s as extractToolResultBlockText, u as hasMediaPayload } from "../host-
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { t as sanitizeSurrogates } from "../sanitize-unicode-D6xUvZaS.mjs";
|
|
2
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, i as transformMessages, l as formatToolResultText, o as describeUnsupportedToolResultMedia, s as extractToolResultBlockText, u as hasMediaPayload } from "../host-CEvLw30U.mjs";
|
|
3
|
+
import { c as ensureSystemPromptCacheBoundary, d as stripSystemPromptCacheBoundary, f as normalizePromptCapabilityIds, i as clampReasoning, l as prependSystemPromptAdditionAfterCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, p as normalizeStructuredPromptSection, r as clampMaxTokensToModel, s as SYSTEM_PROMPT_CACHE_BOUNDARY, t as adjustMaxTokensForThinking, u as splitSystemPromptCacheBoundary } from "../simple-options-BjHCCh4v.mjs";
|
|
4
|
+
//#region packages/ai/src/utils/tls-certificate-errors.ts
|
|
5
|
+
const HOSTNAME_MISMATCH_CODES = /* @__PURE__ */ new Set(["ERR_TLS_CERT_ALTNAME_INVALID", "HOSTNAME_MISMATCH"]);
|
|
6
|
+
const CERTIFICATE_INVALID_CODES = /* @__PURE__ */ new Set([
|
|
7
|
+
"CERT_CHAIN_TOO_LONG",
|
|
8
|
+
"CERT_HAS_EXPIRED",
|
|
9
|
+
"CERT_NOT_YET_VALID",
|
|
10
|
+
"CERT_REJECTED",
|
|
11
|
+
"CERT_REVOKED",
|
|
12
|
+
"CERT_SIGNATURE_FAILURE",
|
|
13
|
+
"CERT_UNTRUSTED",
|
|
14
|
+
"CRL_HAS_EXPIRED",
|
|
15
|
+
"CRL_NOT_YET_VALID",
|
|
16
|
+
"CRL_SIGNATURE_FAILURE",
|
|
17
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
18
|
+
"ERROR_IN_CERT_NOT_AFTER_FIELD",
|
|
19
|
+
"ERROR_IN_CERT_NOT_BEFORE_FIELD",
|
|
20
|
+
"ERROR_IN_CRL_LAST_UPDATE_FIELD",
|
|
21
|
+
"ERROR_IN_CRL_NEXT_UPDATE_FIELD",
|
|
22
|
+
"INVALID_CA",
|
|
23
|
+
"INVALID_PURPOSE",
|
|
24
|
+
"PATH_LENGTH_EXCEEDED",
|
|
25
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
26
|
+
"UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY",
|
|
27
|
+
"UNABLE_TO_DECRYPT_CERT_SIGNATURE",
|
|
28
|
+
"UNABLE_TO_DECRYPT_CRL_SIGNATURE",
|
|
29
|
+
"UNABLE_TO_GET_CRL",
|
|
30
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
31
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
32
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE"
|
|
33
|
+
]);
|
|
34
|
+
const HOSTNAME_MISMATCH_PATTERNS = [
|
|
35
|
+
/hostname\/ip does not match certificate(?:'s)? altnames/i,
|
|
36
|
+
/hostname mismatch/i,
|
|
37
|
+
/host: .+ is not in the cert(?:ificate)?(?:'s)? altnames/i
|
|
38
|
+
];
|
|
39
|
+
const CERTIFICATE_INVALID_PATTERNS = [
|
|
40
|
+
/certificate has expired/i,
|
|
41
|
+
/certificate is not yet valid/i,
|
|
42
|
+
/self[- ]signed certificate/i,
|
|
43
|
+
/unable to get local issuer certificate/i,
|
|
44
|
+
/unable to verify the first certificate/i
|
|
45
|
+
];
|
|
46
|
+
const MAX_TLS_ERROR_DEPTH = 8;
|
|
47
|
+
function classifyCode(code) {
|
|
48
|
+
if (HOSTNAME_MISMATCH_CODES.has(code)) return "hostname_mismatch";
|
|
49
|
+
return CERTIFICATE_INVALID_CODES.has(code) ? "certificate_invalid" : null;
|
|
50
|
+
}
|
|
51
|
+
function classifyMessage(message) {
|
|
52
|
+
if (HOSTNAME_MISMATCH_PATTERNS.some((pattern) => pattern.test(message))) return "hostname_mismatch";
|
|
53
|
+
return CERTIFICATE_INVALID_PATTERNS.some((pattern) => pattern.test(message)) ? "certificate_invalid" : null;
|
|
54
|
+
}
|
|
55
|
+
function inspectTlsCertificateErrorInternal(error, seen, depth) {
|
|
56
|
+
if (depth > MAX_TLS_ERROR_DEPTH) return null;
|
|
57
|
+
if (typeof error === "string") {
|
|
58
|
+
const kind = classifyMessage(error);
|
|
59
|
+
return kind ? {
|
|
60
|
+
kind,
|
|
61
|
+
message: error
|
|
62
|
+
} : null;
|
|
63
|
+
}
|
|
64
|
+
if (!error || typeof error !== "object" || seen.has(error)) return null;
|
|
65
|
+
seen.add(error);
|
|
66
|
+
const candidate = error;
|
|
67
|
+
const code = typeof candidate.code === "string" ? candidate.code.trim().toUpperCase() : void 0;
|
|
68
|
+
const message = typeof candidate.message === "string" && candidate.message.trim() ? candidate.message : void 0;
|
|
69
|
+
const codeKind = code ? classifyCode(code) : null;
|
|
70
|
+
if (code && codeKind) return {
|
|
71
|
+
kind: codeKind,
|
|
72
|
+
code,
|
|
73
|
+
message: message ?? code
|
|
74
|
+
};
|
|
75
|
+
const nestedErrors = Array.isArray(candidate.errors) ? candidate.errors : [];
|
|
76
|
+
for (const nested of [
|
|
77
|
+
candidate.cause,
|
|
78
|
+
candidate.error,
|
|
79
|
+
...nestedErrors
|
|
80
|
+
]) {
|
|
81
|
+
if (nested === void 0 || nested === error) continue;
|
|
82
|
+
const details = inspectTlsCertificateErrorInternal(nested, seen, depth + 1);
|
|
83
|
+
if (details) return details;
|
|
84
|
+
}
|
|
85
|
+
const messageKind = message ? classifyMessage(message) : null;
|
|
86
|
+
return messageKind && message ? {
|
|
87
|
+
kind: messageKind,
|
|
88
|
+
message
|
|
89
|
+
} : null;
|
|
90
|
+
}
|
|
91
|
+
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
92
|
+
function inspectTlsCertificateError(error) {
|
|
93
|
+
return inspectTlsCertificateErrorInternal(error, /* @__PURE__ */ new Set(), 0);
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
5
96
|
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, describeUnsupportedToolResultMedia, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, formatToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
7
|
-
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-ljShVIZB.mjs";
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
2
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-D6xUvZaS.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-CEvLw30U.mjs";
|
|
4
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-BjHCCh4v.mjs";
|
|
5
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
6
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments, t as assignTransportErrorDetails } from "./transport-stream-shared-CZqMhfIw.mjs";
|
|
8
7
|
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
8
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
9
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
10
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BaMbI1hr.mjs";
|
|
11
11
|
import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
|
|
12
12
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
14
|
-
import { HTTPClient
|
|
14
|
+
import { HTTPClient } from "@mistralai/mistralai/lib/http";
|
|
15
|
+
import { Chat } from "@mistralai/mistralai/sdk/chat";
|
|
15
16
|
//#region packages/ai/src/providers/mistral.ts
|
|
16
17
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
17
|
-
const MISTRAL_STREAM_BODY_MAX_BYTES =
|
|
18
|
+
const MISTRAL_STREAM_BODY_MAX_BYTES = 16777216;
|
|
18
19
|
/**
|
|
19
20
|
* Builds a `Fetcher` that wraps the default `fetch` with a 16 MiB byte cap
|
|
20
21
|
* on streamed response bodies. The wrapped `Response.body` exposes a
|
|
@@ -30,7 +31,8 @@ function createBoundedMistralFetcher(maxBytes = MISTRAL_STREAM_BODY_MAX_BYTES, u
|
|
|
30
31
|
return async (input, init) => {
|
|
31
32
|
const response = init == null ? await upstreamFetch(input) : await upstreamFetch(input, init);
|
|
32
33
|
if (!response.body || typeof response.body.getReader !== "function") return response;
|
|
33
|
-
const
|
|
34
|
+
const reader = response.body.getReader();
|
|
35
|
+
const guard = createSseByteGuard(reader, {
|
|
34
36
|
maxBytes,
|
|
35
37
|
onOverflow: ({ size, maxBytes: cap }) => /* @__PURE__ */ new Error(`mistral: stream body exceeds ${cap} bytes (got ${size})`)
|
|
36
38
|
});
|
|
@@ -79,10 +81,11 @@ const streamMistral = (model, context, options) => {
|
|
|
79
81
|
reportedResponse = response;
|
|
80
82
|
}
|
|
81
83
|
});
|
|
82
|
-
const
|
|
84
|
+
const chat = new Chat({
|
|
83
85
|
apiKey,
|
|
84
86
|
serverURL: model.baseUrl,
|
|
85
|
-
httpClient
|
|
87
|
+
httpClient,
|
|
88
|
+
retryConfig: { strategy: "none" }
|
|
86
89
|
});
|
|
87
90
|
const normalizeMistralToolCallId = createMistralToolCallIdNormalizer();
|
|
88
91
|
let payload = buildChatPayload(model, context, transformProviderMessages(context.messages, model, (id) => normalizeMistralToolCallId(id)), options);
|
|
@@ -93,7 +96,7 @@ const streamMistral = (model, context, options) => {
|
|
|
93
96
|
...options?.headers
|
|
94
97
|
};
|
|
95
98
|
if (resolveMistralPromptCacheKey(options) && options?.sessionId) headers["x-affinity"] ||= options.sessionId;
|
|
96
|
-
const mistralStream = await
|
|
99
|
+
const mistralStream = await chat.stream(payload, {
|
|
97
100
|
headers,
|
|
98
101
|
signal: options?.signal
|
|
99
102
|
});
|
|
@@ -107,7 +110,7 @@ const streamMistral = (model, context, options) => {
|
|
|
107
110
|
type: "start",
|
|
108
111
|
partial: output
|
|
109
112
|
});
|
|
110
|
-
await consumeChatStream(model, output, stream, mistralStream);
|
|
113
|
+
await consumeChatStream(model, output, stream, mistralStream, options?.signal);
|
|
111
114
|
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
112
115
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
113
116
|
stream.push({
|
|
@@ -117,9 +120,8 @@ const streamMistral = (model, context, options) => {
|
|
|
117
120
|
});
|
|
118
121
|
stream.end();
|
|
119
122
|
} catch (error) {
|
|
123
|
+
const terminal = assignTransportErrorDetails(output, error, options?.signal);
|
|
120
124
|
output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
121
|
-
const terminal = projectProviderError(error, options?.signal);
|
|
122
|
-
Object.assign(output, terminal);
|
|
123
125
|
stream.push({
|
|
124
126
|
type: "error",
|
|
125
127
|
reason: terminal.stopReason,
|
|
@@ -197,7 +199,8 @@ function deriveMistralToolCallId(id, attempt) {
|
|
|
197
199
|
const normalized = id.replace(/[^a-zA-Z0-9]/g, "");
|
|
198
200
|
if (attempt === 0 && normalized.length === MISTRAL_TOOL_CALL_ID_LENGTH) return normalized;
|
|
199
201
|
const seedBase = normalized || id;
|
|
200
|
-
|
|
202
|
+
const seed = attempt === 0 ? seedBase : `${seedBase}:${attempt}`;
|
|
203
|
+
return shortHash(seed).replace(/[^a-zA-Z0-9]/g, "").padEnd(MISTRAL_TOOL_CALL_ID_LENGTH, "0").slice(0, MISTRAL_TOOL_CALL_ID_LENGTH);
|
|
201
204
|
}
|
|
202
205
|
function buildChatPayload(model, context, messages, options) {
|
|
203
206
|
const payload = {
|
|
@@ -237,7 +240,7 @@ function readMistralCachedPromptTokens(usage, promptTokens) {
|
|
|
237
240
|
const rawCachedTokens = record.promptTokensDetails?.cachedTokens ?? record.prompt_tokens_details?.cached_tokens ?? record.cachedTokens ?? record.cached_tokens;
|
|
238
241
|
return Math.min(promptTokens, Math.max(0, typeof rawCachedTokens === "number" && Number.isFinite(rawCachedTokens) ? rawCachedTokens : 0));
|
|
239
242
|
}
|
|
240
|
-
async function consumeChatStream(model, output, stream, mistralStream) {
|
|
243
|
+
async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
241
244
|
let currentBlock = null;
|
|
242
245
|
let terminalFinishReason;
|
|
243
246
|
const blocks = output.content;
|
|
@@ -321,6 +324,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
321
324
|
});
|
|
322
325
|
};
|
|
323
326
|
for await (const event of mistralStream) {
|
|
327
|
+
notifyLlmRequestActivity(signal);
|
|
324
328
|
const chunk = event.data;
|
|
325
329
|
output.responseId ||= chunk.id;
|
|
326
330
|
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
|
|
@@ -371,7 +375,8 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
371
375
|
continue;
|
|
372
376
|
}
|
|
373
377
|
if (item.type === "thinking") {
|
|
374
|
-
const
|
|
378
|
+
const deltaText = item.thinking.map((part) => "text" in part ? part.text : "").filter((text) => text.length > 0).join("");
|
|
379
|
+
const thinkingDelta = sanitizeSurrogates(deltaText);
|
|
375
380
|
if (!thinkingDelta) continue;
|
|
376
381
|
if (!currentBlock || currentBlock.type !== "thinking") {
|
|
377
382
|
finishCurrentBlock(currentBlock);
|
|
@@ -513,7 +518,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
513
518
|
}
|
|
514
519
|
}
|
|
515
520
|
function toFunctionTools(tools) {
|
|
516
|
-
|
|
521
|
+
const converted = tools.flatMap((tool) => {
|
|
517
522
|
try {
|
|
518
523
|
const name = tool.name;
|
|
519
524
|
const description = tool.description;
|
|
@@ -533,7 +538,8 @@ function toFunctionTools(tools) {
|
|
|
533
538
|
} catch {
|
|
534
539
|
return [];
|
|
535
540
|
}
|
|
536
|
-
})
|
|
541
|
+
});
|
|
542
|
+
return sortPromptCacheToolsByName(converted).map(({ value }) => value);
|
|
537
543
|
}
|
|
538
544
|
function stripSymbolKeys(value) {
|
|
539
545
|
if (Array.isArray(value)) return value.map((item) => stripSymbolKeys(item));
|
|
@@ -618,10 +624,11 @@ function toChatMessages(messages, supportsImages) {
|
|
|
618
624
|
const toolContent = [];
|
|
619
625
|
const textResult = extractToolResultText(msg.content);
|
|
620
626
|
const mediaPlaceholder = describeToolResultMediaPlaceholder(msg.content);
|
|
627
|
+
const omittedMediaPlaceholder = msg.content.some(isImageWithMediaPayload) && !supportsImages ? textResult.trim() ? "[tool image omitted: model does not support images]" : mediaPlaceholder === "(see attached media)" ? "(media omitted: model does not support images)" : "(image omitted: model does not support images)" : void 0;
|
|
621
628
|
const toolText = formatToolResultText({
|
|
622
629
|
text: textResult,
|
|
623
630
|
mediaPlaceholder,
|
|
624
|
-
omittedMediaPlaceholder
|
|
631
|
+
omittedMediaPlaceholder,
|
|
625
632
|
isError: msg.isError
|
|
626
633
|
});
|
|
627
634
|
toolContent.push({
|