@openclaw/ai 2026.8.1-beta.1 → 2026.8.1-beta.3
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-CE-7SkF6.mjs → anthropic-B8KwTtlb.mjs} +62 -37
- package/dist/{anthropic-SrGtwsJu.d.mts → anthropic-BECQCNdF.d.mts} +0 -2
- package/dist/{src-QkygScBs.mjs → anthropic-BQXQudmA.mjs} +0 -2
- package/dist/{anthropic-usage-Ma4iX6uG.mjs → anthropic-compaction-replay-4Zx7-aCr.mjs} +225 -103
- package/dist/anthropic-payload-policy-CSx7MoKH.d.mts +50 -0
- package/dist/{api-registry-EpJoVwM1.d.mts → api-registry-DFxSnFqG.d.mts} +1 -1
- package/dist/{azure-openai-responses-Cc_kasye.mjs → azure-openai-responses-Aa4mVcYG.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/event-stream-BVVgDSdq.d.mts +1 -0
- package/dist/{event-stream-DRmDMRHH.d.mts → event-stream-D91-ohD_.d.mts} +3 -1
- package/dist/{event-stream-CEV9t6da.mjs → event-stream-uSMZJ3FA.mjs} +16 -3
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-shared-Cq2UKx1l.mjs → google-shared-M1dl64nz.mjs} +17 -19
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-CusxWzvE.mjs → google-vertex-DCJHM_a5.mjs} +5 -4
- package/dist/{google-CGQu21aw.mjs → google-yDRnipeq.mjs} +4 -4
- package/dist/host-DF_yxOsA.mjs +477 -0
- package/dist/{host-Dn4_SZI2.d.mts → host-DJq_FGcz.d.mts} +13 -8
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +21 -7
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +9 -7
- package/dist/internal/runtime.d.mts +19 -5
- package/dist/internal/runtime.mjs +85 -72
- package/dist/internal/shared.d.mts +17 -8
- package/dist/internal/shared.mjs +4 -5
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-Dx6VzNjf.mjs → mistral-D6hRXI7A.mjs} +67 -72
- package/dist/{number-coercion-1Miyb5MO.mjs → number-coercion-H9qHik3g.mjs} +7 -2
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-SC9m0FSf.mjs → openai-chatgpt-responses-C339VIfT.mjs} +235 -146
- package/dist/{openai-completions-BaIpl93j.mjs → openai-completions-D88orSJ9.mjs} +88 -67
- package/dist/openai-completions-compat-B0KTleXp.d.mts +43 -0
- package/dist/{openai-responses-Bdx3V_Yu.mjs → openai-responses-BXEcr-Tp.mjs} +17 -24
- package/dist/openai-responses-contracts-CD75pQ0m.d.mts +68 -0
- package/dist/openai-responses-contracts-DvILoqBk.mjs +247 -0
- package/dist/openai-responses-payload-policy-BDo8CQsx.mjs +208 -0
- package/dist/openai-responses-payload-policy-CNGFT9zr.d.mts +41 -0
- package/dist/{openai-responses-prompt-observer-internal-DDZPxRfr.mjs → openai-responses-prompt-observer-internal-BG-1AsBI.mjs} +2 -3
- package/dist/{openai-responses-stream-internal-Bl8YyVtF.mjs → openai-responses-shared-Cvt5MgEm.mjs} +1287 -1039
- package/dist/{openai-reasoning-compat-DKebnIBL.mjs → openai-stop-reason-9OONKyAm.mjs} +222 -180
- package/dist/{openai-transport-shared-Cipt7egQ.mjs → openai-tool-projection-CHGLt03m.mjs} +239 -128
- package/dist/provider-error-C8mBRJDl.mjs +424 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/provider-options-AvldWZt8.mjs +21 -0
- package/dist/{provider-options-C5kYML7i.d.mts → provider-options-Cc5ZQ6Aa.d.mts} +19 -3
- package/dist/provider-transcript-transform--gtf0ZbR.mjs +32 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-5ygO2rZc.mjs} +17 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/{model-utils-Dau5dlgm.mjs → sanitize-unicode-BP7HLLZn.mjs} +28 -2
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-oqsXB6U3.mjs +450 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BIBomOGq.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-B1b-XCn5.mjs → tool-schema-json-projection-FEr-jOoZ.mjs} +20 -13
- package/dist/transport-utils-Bv0FHkd0.mjs +138 -0
- package/dist/transports.d.mts +199 -209
- package/dist/transports.mjs +1842 -1364
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-CH7ReIcU.d.mts → types-DTAP49HF.d.mts} +35 -2
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-CcPcuEbR.d.mts → validation-DYNNrU9u.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/host-Bl7Kgddo.mjs +0 -407
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-contracts-BBKBfAqR.d.mts +0 -116
- package/dist/openai-responses-shared-CCyMvg7M.mjs +0 -403
- package/dist/provider-error-DI0Ts28U.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/tool-result-text-Dvkp2Dus.mjs +0 -274
- package/dist/transform-messages-DfjpNXNQ.mjs +0 -2
- package/dist/transport-stream-shared-CPNv7A3r.mjs +0 -297
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { n as parseStreamingJson } from "./json-parse-
|
|
8
|
-
import { d as transportAbortError } from "./transport-stream-shared-CPNv7A3r.mjs";
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-BP7HLLZn.mjs";
|
|
4
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
|
|
5
|
+
import { n as projectProviderError } from "./provider-error-C8mBRJDl.mjs";
|
|
6
|
+
import { P as sortPromptCacheToolsByName, d as finalizeTerminalToolCallArguments, g as notifyProviderHttpResponse, j as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, x as transportAbortError } from "./simple-options-oqsXB6U3.mjs";
|
|
7
|
+
import { n as parseStreamingJson } from "./json-parse-CDnesDM_.mjs";
|
|
9
8
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
-
import "./
|
|
9
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform--gtf0ZbR.mjs";
|
|
11
10
|
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
12
11
|
import { randomUUID } from "node:crypto";
|
|
13
12
|
import { HTTPClient, Mistral } from "@mistralai/mistralai";
|
|
14
13
|
//#region packages/ai/src/providers/mistral.ts
|
|
15
14
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
16
|
-
const MAX_MISTRAL_ERROR_BODY_CHARS = 4e3;
|
|
17
15
|
const MISTRAL_STREAM_BODY_MAX_BYTES = 16 * 1024 * 1024;
|
|
18
16
|
/**
|
|
19
17
|
* Builds a `Fetcher` that wraps the default `fetch` with a 16 MiB byte cap
|
|
@@ -64,13 +62,28 @@ const streamMistral = (model, context, options) => {
|
|
|
64
62
|
try {
|
|
65
63
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
66
64
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
65
|
+
const boundedFetcher = createBoundedMistralFetcher(MISTRAL_STREAM_BODY_MAX_BYTES, getAiTransportHost().buildModelFetch(model) ?? fetch);
|
|
66
|
+
let mistralResponse;
|
|
67
|
+
let reportedResponse;
|
|
68
|
+
const httpClient = new HTTPClient({ fetcher: boundedFetcher });
|
|
69
|
+
httpClient.addHook("response", async (response) => {
|
|
70
|
+
mistralResponse = response;
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
await notifyProviderHttpResponse({
|
|
73
|
+
options,
|
|
74
|
+
response,
|
|
75
|
+
model
|
|
76
|
+
});
|
|
77
|
+
reportedResponse = response;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
67
80
|
const mistral = new Mistral({
|
|
68
81
|
apiKey,
|
|
69
82
|
serverURL: model.baseUrl,
|
|
70
|
-
httpClient
|
|
83
|
+
httpClient
|
|
71
84
|
});
|
|
72
85
|
const normalizeMistralToolCallId = createMistralToolCallIdNormalizer();
|
|
73
|
-
let payload = buildChatPayload(model, context,
|
|
86
|
+
let payload = buildChatPayload(model, context, transformProviderMessages(context.messages, model, (id) => normalizeMistralToolCallId(id)), options);
|
|
74
87
|
const nextPayload = await options?.onPayload?.(payload, model);
|
|
75
88
|
if (nextPayload !== void 0) payload = nextPayload;
|
|
76
89
|
const headers = {
|
|
@@ -82,6 +95,12 @@ const streamMistral = (model, context, options) => {
|
|
|
82
95
|
headers,
|
|
83
96
|
signal: options?.signal
|
|
84
97
|
});
|
|
98
|
+
if (mistralResponse && mistralResponse !== reportedResponse) await notifyProviderHttpResponse({
|
|
99
|
+
options,
|
|
100
|
+
response: mistralResponse,
|
|
101
|
+
model,
|
|
102
|
+
cancelStream: (reason) => mistralStream.cancel(reason)
|
|
103
|
+
});
|
|
85
104
|
stream.push({
|
|
86
105
|
type: "start",
|
|
87
106
|
partial: output
|
|
@@ -97,11 +116,11 @@ const streamMistral = (model, context, options) => {
|
|
|
97
116
|
stream.end();
|
|
98
117
|
} catch (error) {
|
|
99
118
|
output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
100
|
-
|
|
101
|
-
output
|
|
119
|
+
const terminal = projectProviderError(error, options?.signal);
|
|
120
|
+
Object.assign(output, terminal);
|
|
102
121
|
stream.push({
|
|
103
122
|
type: "error",
|
|
104
|
-
reason:
|
|
123
|
+
reason: terminal.stopReason,
|
|
105
124
|
error: output
|
|
106
125
|
});
|
|
107
126
|
stream.end();
|
|
@@ -178,30 +197,6 @@ function deriveMistralToolCallId(id, attempt) {
|
|
|
178
197
|
const seedBase = normalized || id;
|
|
179
198
|
return shortHash(attempt === 0 ? seedBase : `${seedBase}:${attempt}`).replace(/[^a-zA-Z0-9]/g, "").padEnd(MISTRAL_TOOL_CALL_ID_LENGTH, "0").slice(0, MISTRAL_TOOL_CALL_ID_LENGTH);
|
|
180
199
|
}
|
|
181
|
-
function formatMistralError(error) {
|
|
182
|
-
if (error instanceof Error) {
|
|
183
|
-
const sdkError = error;
|
|
184
|
-
const statusCode = typeof sdkError.statusCode === "number" ? sdkError.statusCode : void 0;
|
|
185
|
-
const bodyText = typeof sdkError.body === "string" ? sdkError.body.trim() : void 0;
|
|
186
|
-
if (statusCode !== void 0 && bodyText) return `Mistral API error (${statusCode}): ${truncateErrorText(bodyText, MAX_MISTRAL_ERROR_BODY_CHARS)}`;
|
|
187
|
-
if (statusCode !== void 0) return `Mistral API error (${statusCode}): ${error.message}`;
|
|
188
|
-
return error.message;
|
|
189
|
-
}
|
|
190
|
-
return safeJsonStringify(error);
|
|
191
|
-
}
|
|
192
|
-
function truncateErrorText(text, maxChars) {
|
|
193
|
-
if (text.length <= maxChars) return text;
|
|
194
|
-
const truncated = truncateUtf16Safe(text, maxChars);
|
|
195
|
-
return `${truncated}... [truncated ${text.length - truncated.length} chars]`;
|
|
196
|
-
}
|
|
197
|
-
function safeJsonStringify(value) {
|
|
198
|
-
try {
|
|
199
|
-
const serialized = JSON.stringify(value);
|
|
200
|
-
return serialized === void 0 ? String(value) : serialized;
|
|
201
|
-
} catch {
|
|
202
|
-
return String(value);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
200
|
function buildChatPayload(model, context, messages, options) {
|
|
206
201
|
const payload = {
|
|
207
202
|
model: model.id,
|
|
@@ -492,43 +487,46 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
492
487
|
if (!terminalFinishReason) throw new Error("Mistral stream ended without a terminal finish reason");
|
|
493
488
|
return;
|
|
494
489
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
503
|
-
for (const
|
|
504
|
-
|
|
505
|
-
if (block?.type !== "toolCall") continue;
|
|
506
|
-
const toolBlock = block;
|
|
507
|
-
delete toolBlock.partialArgs;
|
|
490
|
+
const completedToolCalls = [...toolBlockIdentities.keys()].flatMap((contentIndex) => {
|
|
491
|
+
const block = blocks[contentIndex];
|
|
492
|
+
return block?.type === "toolCall" ? [{
|
|
493
|
+
block,
|
|
494
|
+
contentIndex
|
|
495
|
+
}] : [];
|
|
496
|
+
});
|
|
497
|
+
finalizeTerminalToolCallArguments(completedToolCalls.map(({ block }) => block), (block) => block.partialArgs ?? "", "Mistral completed tool call has invalid JSON arguments");
|
|
498
|
+
for (const { block, contentIndex } of completedToolCalls) {
|
|
499
|
+
delete block.partialArgs;
|
|
508
500
|
stream.push({
|
|
509
501
|
type: "toolcall_end",
|
|
510
|
-
contentIndex
|
|
511
|
-
toolCall:
|
|
502
|
+
contentIndex,
|
|
503
|
+
toolCall: block,
|
|
512
504
|
partial: output
|
|
513
505
|
});
|
|
514
506
|
}
|
|
515
507
|
}
|
|
516
508
|
function toFunctionTools(tools) {
|
|
517
|
-
return tools.flatMap((tool) => {
|
|
509
|
+
return sortPromptCacheToolsByName(tools.flatMap((tool) => {
|
|
518
510
|
try {
|
|
511
|
+
const name = tool.name;
|
|
512
|
+
const description = tool.description;
|
|
519
513
|
return {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
514
|
+
name,
|
|
515
|
+
description,
|
|
516
|
+
value: {
|
|
517
|
+
type: "function",
|
|
518
|
+
function: {
|
|
519
|
+
name,
|
|
520
|
+
description,
|
|
521
|
+
parameters: stripSymbolKeys(tool.parameters),
|
|
522
|
+
strict: false
|
|
523
|
+
}
|
|
526
524
|
}
|
|
527
525
|
};
|
|
528
526
|
} catch {
|
|
529
527
|
return [];
|
|
530
528
|
}
|
|
531
|
-
});
|
|
529
|
+
})).map(({ value }) => value);
|
|
532
530
|
}
|
|
533
531
|
function stripSymbolKeys(value) {
|
|
534
532
|
if (Array.isArray(value)) return value.map((item) => stripSymbolKeys(item));
|
|
@@ -611,7 +609,14 @@ function toChatMessages(messages, supportsImages) {
|
|
|
611
609
|
continue;
|
|
612
610
|
}
|
|
613
611
|
const toolContent = [];
|
|
614
|
-
const
|
|
612
|
+
const textResult = extractToolResultText(msg.content);
|
|
613
|
+
const mediaPlaceholder = describeToolResultMediaPlaceholder(msg.content);
|
|
614
|
+
const toolText = formatToolResultText({
|
|
615
|
+
text: textResult,
|
|
616
|
+
mediaPlaceholder,
|
|
617
|
+
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,
|
|
618
|
+
isError: msg.isError
|
|
619
|
+
});
|
|
615
620
|
toolContent.push({
|
|
616
621
|
type: "text",
|
|
617
622
|
text: toolText
|
|
@@ -633,16 +638,6 @@ function toChatMessages(messages, supportsImages) {
|
|
|
633
638
|
}
|
|
634
639
|
return result;
|
|
635
640
|
}
|
|
636
|
-
function buildToolResultText(text, mediaPlaceholder, hasImages, supportsImages, isError) {
|
|
637
|
-
const trimmed = text.trim();
|
|
638
|
-
const errorPrefix = isError ? "[tool error] " : "";
|
|
639
|
-
if (trimmed.length > 0) return `${errorPrefix}${trimmed}${hasImages && !supportsImages ? "\n[tool image omitted: model does not support images]" : ""}`;
|
|
640
|
-
if (mediaPlaceholder) {
|
|
641
|
-
if (!hasImages || supportsImages) return `${errorPrefix}${mediaPlaceholder}`;
|
|
642
|
-
return `${errorPrefix}${mediaPlaceholder === "(see attached media)" ? "(media omitted: model does not support images)" : "(image omitted: model does not support images)"}`;
|
|
643
|
-
}
|
|
644
|
-
return isError ? "[tool error] (no tool output)" : "(no tool output)";
|
|
645
|
-
}
|
|
646
641
|
function usesReasoningEffort(model) {
|
|
647
642
|
return model.id === "mistral-small-2603" || model.id === "mistral-small-latest" || model.id === "mistral-medium-3-5";
|
|
648
643
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
//#region packages/normalization-core/src/number-coercion.ts
|
|
2
2
|
/** Returns a number only when the input is already finite. */
|
|
3
3
|
function asFiniteNumber(value) {
|
|
4
|
-
return
|
|
4
|
+
return Number.isFinite(value) ? value : void 0;
|
|
5
|
+
}
|
|
6
|
+
/** Returns a finite number only when it is zero or greater. */
|
|
7
|
+
function asNonNegativeFiniteNumber(value) {
|
|
8
|
+
const number = asFiniteNumber(value);
|
|
9
|
+
return number && number < 0 ? void 0 : number;
|
|
5
10
|
}
|
|
6
11
|
/** Returns a finite number only when it satisfies the supplied inclusive/exclusive bounds. */
|
|
7
12
|
function asFiniteNumberInRange(value, range) {
|
|
@@ -63,4 +68,4 @@ function parseStrictNonNegativeInteger(value) {
|
|
|
63
68
|
return parsed !== void 0 && parsed >= 0 ? parsed : void 0;
|
|
64
69
|
}
|
|
65
70
|
//#endregion
|
|
66
|
-
export {
|
|
71
|
+
export { parseStrictFiniteNumber as a, resolveTimerTimeoutMs as c, clampTimerTimeoutMs as i, asFiniteNumberInRange as n, parseStrictNonNegativeInteger as o, asNonNegativeFiniteNumber as r, parseStrictPositiveInteger as s, asFiniteNumber as t };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region packages/ai/src/utils/oauth/openai-chatgpt-jwt.ts
|
|
2
|
+
const OPENAI_CODEX_AUTH_CLAIM = "https://api.openai.com/auth";
|
|
3
|
+
function decodeOpenAICodexJwtPayload(token) {
|
|
4
|
+
const parts = token.split(".");
|
|
5
|
+
if (parts.length !== 3) return null;
|
|
6
|
+
try {
|
|
7
|
+
const decoded = Buffer.from(parts[1] ?? "", "base64url").toString("utf8");
|
|
8
|
+
const parsed = JSON.parse(decoded);
|
|
9
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function resolveOpenAICodexAccountId(token) {
|
|
15
|
+
const accountId = decodeOpenAICodexJwtPayload(token)?.[OPENAI_CODEX_AUTH_CLAIM]?.chatgpt_account_id;
|
|
16
|
+
return typeof accountId === "string" && accountId.length > 0 ? accountId : null;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { resolveOpenAICodexAccountId as n, decodeOpenAICodexJwtPayload as t };
|