@openclaw/ai 2026.8.1-beta.3 → 2026.8.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-B8KwTtlb.mjs → anthropic-DTGZ4VMY.mjs} +25 -23
- package/dist/{anthropic-compaction-replay-4Zx7-aCr.mjs → anthropic-compaction-replay-CKCDrZJv.mjs} +34 -35
- package/dist/{anthropic-payload-policy-CSx7MoKH.d.mts → anthropic-payload-policy-BTzmNC14.d.mts} +3 -2
- package/dist/{api-registry-DFxSnFqG.d.mts → api-registry-BbUHEKER.d.mts} +2 -1
- package/dist/{azure-openai-responses-Aa4mVcYG.mjs → azure-openai-responses-BmqaDXM1.mjs} +6 -5
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/diagnostics.d.mts +2 -3
- package/dist/diagnostics.mjs +1 -1
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/{event-stream-D91-ohD_.d.mts → event-stream-DcvAPSBe.d.mts} +1 -2
- package/dist/event-stream-pXT3FI6X.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -1
- package/dist/{google-yDRnipeq.mjs → google-CqjVZMwo.mjs} +8 -6
- package/dist/{google-shared-M1dl64nz.mjs → google-shared-Bnqni5j3.mjs} +34 -25
- package/dist/{google-vertex-DCJHM_a5.mjs → google-vertex-D_WREEJi.mjs} +8 -6
- package/dist/{host-DF_yxOsA.mjs → host-BIaiBURL.mjs} +4 -8
- package/dist/{host-DJq_FGcz.d.mts → host-DKFUAmCn.d.mts} +3 -3
- package/dist/index-CefaUGSS.d.mts +111 -0
- package/dist/index.d.mts +9 -10
- package/dist/index.mjs +4 -5
- package/dist/internal/anthropic.d.mts +51 -49
- 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 +65 -63
- package/dist/internal/openai.mjs +10 -9
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +51 -40
- package/dist/internal/runtime.mjs +9 -9
- package/dist/internal/shared.d.mts +25 -25
- package/dist/internal/shared.mjs +3 -3
- package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
- package/dist/{mistral-D6hRXI7A.mjs → mistral-C24jVd6f.mjs} +34 -32
- package/dist/{openai-chatgpt-responses-C339VIfT.mjs → openai-chatgpt-responses-Czum0oXz.mjs} +38 -20
- package/dist/openai-completions-BfFwac6f.mjs +404 -0
- package/dist/{openai-completions-compat-B0KTleXp.d.mts → openai-completions-compat-SZhi0Lf4.d.mts} +3 -3
- package/dist/openai-completions-stream-DGOvau4J.mjs +1625 -0
- package/dist/{openai-responses-BXEcr-Tp.mjs → openai-responses-BAryVEJM.mjs} +11 -7
- package/dist/openai-responses-compaction-window-DO7yV7az.mjs +686 -0
- package/dist/{openai-responses-contracts-CD75pQ0m.d.mts → openai-responses-contracts-BthRXano.d.mts} +14 -5
- 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-BG-1AsBI.mjs → openai-responses-prompt-observer-internal--R0kZLOZ.mjs} +3 -2
- package/dist/{openai-responses-shared-Cvt5MgEm.mjs → openai-responses-shared-CxgdGBvm.mjs} +332 -1484
- package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
- package/dist/openai-tool-schema-CSMh5e9O.mjs +1697 -0
- package/dist/{provider-error-C8mBRJDl.mjs → provider-error-BI8kIViN.mjs} +14 -88
- package/dist/{provider-options-Cc5ZQ6Aa.d.mts → provider-options-DJd_9euj.d.mts} +13 -4
- package/dist/{provider-transcript-transform--gtf0ZbR.mjs → provider-transcript-transform-WvJmFUAf.mjs} +1 -1
- package/dist/provider-types.d.mts +18 -17
- package/dist/providers.d.mts +5 -6
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-BsUX44Tq.mjs} +30 -20
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-BP7HLLZn.mjs → sanitize-unicode-S6binQG-.mjs} +2 -9
- package/dist/simple-options-rdOPzr7Z.mjs +155 -0
- package/dist/{anthropic-BQXQudmA.mjs → src-C8U7lkoa.mjs} +75 -1
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
- package/dist/string-normalization--fwJ4S2q.mjs +16 -0
- package/dist/{tool-schema-json-projection-FEr-jOoZ.mjs → tool-schema-json-projection-BtZiml7r.mjs} +22 -32
- package/dist/transport-stream-shared-BbG7PThh.d.mts +138 -0
- package/dist/{simple-options-oqsXB6U3.mjs → transport-stream-shared-D8nQWCUo.mjs} +10 -118
- package/dist/{transport-utils-Bv0FHkd0.mjs → transport-utils-CtuS1Upe.mjs} +10 -10
- package/dist/transports.d.mts +130 -189
- package/dist/transports.mjs +227 -1249
- package/dist/{types-DTAP49HF.d.mts → types-Beemor2E.d.mts} +58 -24
- package/dist/types-COdhCX0U.d.mts +1 -0
- package/dist/types.d.mts +6 -5
- package/dist/types.mjs +3 -4
- package/dist/utf16-slice-qz3nsy87.mjs +84 -0
- package/dist/{validation-DYNNrU9u.d.mts → validation-CC6s7Smp.d.mts} +1 -2
- 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 +6 -6
- package/dist/anthropic-BECQCNdF.d.mts +0 -98
- package/dist/event-stream-BVVgDSdq.d.mts +0 -1
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/index-BVVgDSdq.d.mts +0 -1
- package/dist/openai-completions-D88orSJ9.mjs +0 -632
- package/dist/openai-responses-contracts-DvILoqBk.mjs +0 -247
- package/dist/openai-responses-payload-policy-BDo8CQsx.mjs +0 -208
- package/dist/openai-stop-reason-9OONKyAm.mjs +0 -579
- package/dist/openai-tool-projection-CHGLt03m.mjs +0 -426
- package/dist/provider-options-AvldWZt8.mjs +0 -21
- package/dist/record-coerce-DdXsgUd_.mjs +0 -23
- package/dist/src-D2H6yKkH.mjs +0 -2
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
- package/dist/string-coerce-fsri9iCu.mjs +0 -34
- package/dist/types-BVVgDSdq.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
4
|
-
import "./number-coercion-H9qHik3g.mjs";
|
|
1
|
+
import { a as asOptionalRecord, f as normalizeStringifiedOptionalString, t as truncateUtf16Safe } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
+
import { n as estimateBase64DecodedBytes } from "./base64-CEFBpSkN.mjs";
|
|
5
3
|
//#region packages/normalization-core/src/balanced-json.ts
|
|
6
4
|
function isJsonOpeningDelimiter(char, openers) {
|
|
7
5
|
return (char === "{" || char === "[") && openers.includes(char);
|
|
8
6
|
}
|
|
9
|
-
|
|
10
|
-
function extractBalancedJsonPrefix(raw, opts = {}) {
|
|
7
|
+
function extractBalancedJsonAt(raw, opts, offset) {
|
|
11
8
|
const openers = opts.openers ?? ["{", "["];
|
|
12
|
-
let start =
|
|
9
|
+
let start = offset;
|
|
13
10
|
while (start < raw.length && !isJsonOpeningDelimiter(raw[start], openers)) start += 1;
|
|
14
11
|
const stack = [];
|
|
15
12
|
let inString = false;
|
|
@@ -37,14 +34,10 @@ function extractBalancedJsonPrefix(raw, opts = {}) {
|
|
|
37
34
|
function extractBalancedJsonFragments(raw, opts = {}) {
|
|
38
35
|
const fragments = [];
|
|
39
36
|
for (let offset = 0; offset < raw.length;) {
|
|
40
|
-
const fragment =
|
|
37
|
+
const fragment = extractBalancedJsonAt(raw, opts, offset);
|
|
41
38
|
if (!fragment) break;
|
|
42
|
-
fragments.push(
|
|
43
|
-
|
|
44
|
-
startIndex: offset + fragment.startIndex,
|
|
45
|
-
endIndex: offset + fragment.endIndex
|
|
46
|
-
});
|
|
47
|
-
offset += fragment.endIndex + 1;
|
|
39
|
+
fragments.push(fragment);
|
|
40
|
+
offset = fragment.endIndex + 1;
|
|
48
41
|
}
|
|
49
42
|
return fragments;
|
|
50
43
|
}
|
|
@@ -85,6 +78,11 @@ function stringifyObjectValue(value, stack, normalizeString) {
|
|
|
85
78
|
return `[${serializedEntries.join(",")}]`;
|
|
86
79
|
}
|
|
87
80
|
const record = value;
|
|
81
|
+
if (normalizeString === preserveString) {
|
|
82
|
+
const fields = [];
|
|
83
|
+
for (const key of Object.keys(record).toSorted()) fields.push(`${JSON.stringify(key)}:${stringifyStableValue(record[key], stack, normalizeString)}`);
|
|
84
|
+
return `{${fields.join(",")}}`;
|
|
85
|
+
}
|
|
88
86
|
const entries = Object.keys(record).map((key) => ({
|
|
89
87
|
key,
|
|
90
88
|
normalizedKey: normalizeString(key)
|
|
@@ -104,78 +102,6 @@ function compareStableStrings(left, right) {
|
|
|
104
102
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
105
103
|
}
|
|
106
104
|
//#endregion
|
|
107
|
-
//#region packages/media-core/src/base64.ts
|
|
108
|
-
/** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
|
|
109
|
-
function estimateBase64DecodedBytes(base64) {
|
|
110
|
-
let effectiveLen = 0;
|
|
111
|
-
for (let i = 0; i < base64.length; i += 1) {
|
|
112
|
-
if (base64.charCodeAt(i) <= 32) continue;
|
|
113
|
-
effectiveLen += 1;
|
|
114
|
-
}
|
|
115
|
-
if (effectiveLen === 0) return 0;
|
|
116
|
-
let padding = 0;
|
|
117
|
-
let end = base64.length - 1;
|
|
118
|
-
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
119
|
-
if (end >= 0 && base64[end] === "=") {
|
|
120
|
-
padding = 1;
|
|
121
|
-
end -= 1;
|
|
122
|
-
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
123
|
-
if (end >= 0 && base64[end] === "=") padding = 2;
|
|
124
|
-
}
|
|
125
|
-
const estimated = Math.floor(effectiveLen * 3 / 4) - padding;
|
|
126
|
-
return Math.max(0, estimated);
|
|
127
|
-
}
|
|
128
|
-
function isBase64DataChar(code) {
|
|
129
|
-
return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47;
|
|
130
|
-
}
|
|
131
|
-
function base64DataValue(code) {
|
|
132
|
-
if (code >= 65 && code <= 90) return code - 65;
|
|
133
|
-
if (code >= 97 && code <= 122) return code - 97 + 26;
|
|
134
|
-
if (code >= 48 && code <= 57) return code - 48 + 52;
|
|
135
|
-
return code === 43 ? 62 : 63;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Normalizes and validates a base64 string, returning canonical no-whitespace
|
|
139
|
-
* base64 only when the input has valid alphabet, padding, and length.
|
|
140
|
-
*/
|
|
141
|
-
function canonicalizeBase64(base64) {
|
|
142
|
-
let out;
|
|
143
|
-
let outLen = 0;
|
|
144
|
-
let padding = 0;
|
|
145
|
-
let sawPadding = false;
|
|
146
|
-
let lastDataCode = 0;
|
|
147
|
-
for (let i = 0; i < base64.length; i += 1) {
|
|
148
|
-
const code = base64.charCodeAt(i);
|
|
149
|
-
if (code <= 32) {
|
|
150
|
-
if (out === void 0) {
|
|
151
|
-
out = Buffer.allocUnsafe(base64.length - 1);
|
|
152
|
-
for (let j = 0; j < i; j += 1) out[j] = base64.charCodeAt(j);
|
|
153
|
-
outLen = i;
|
|
154
|
-
}
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
if (code === 61) {
|
|
158
|
-
padding += 1;
|
|
159
|
-
if (padding > 2) return;
|
|
160
|
-
sawPadding = true;
|
|
161
|
-
} else if (sawPadding || !isBase64DataChar(code)) return;
|
|
162
|
-
else lastDataCode = code;
|
|
163
|
-
if (out !== void 0) {
|
|
164
|
-
out[outLen] = code;
|
|
165
|
-
outLen += 1;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const cleanedLength = out === void 0 ? base64.length : outLen;
|
|
169
|
-
if (cleanedLength === 0) return;
|
|
170
|
-
const remainder = cleanedLength % 4;
|
|
171
|
-
if (remainder !== 0 && (sawPadding || remainder === 1)) return;
|
|
172
|
-
const effectivePadding = remainder === 0 ? padding : 4 - remainder;
|
|
173
|
-
const padBitMask = effectivePadding === 2 ? 15 : effectivePadding === 1 ? 3 : 0;
|
|
174
|
-
if (padBitMask !== 0 && (base64DataValue(lastDataCode) & padBitMask) !== 0) return;
|
|
175
|
-
const cleaned = out === void 0 ? base64 : out.subarray(0, outLen).toString("latin1");
|
|
176
|
-
return remainder === 0 ? cleaned : cleaned + "=".repeat(4 - remainder);
|
|
177
|
-
}
|
|
178
|
-
//#endregion
|
|
179
105
|
//#region packages/ai/src/utils/credential-redaction.ts
|
|
180
106
|
const NON_CREDENTIAL_FIELD_NAMES = /* @__PURE__ */ new Set([
|
|
181
107
|
"passwordfile",
|
|
@@ -198,7 +124,7 @@ const CREDENTIAL_HEADER_RE = /\b((?:[A-Za-z][A-Za-z0-9_.-]*[_.-])?(?:api[_.-]?ke
|
|
|
198
124
|
const LOOSE_QUOTED_CREDENTIAL_PAIR_RE = /\b((?!(?:api|endpoint|method|model|provider|status|type)=)[A-Za-z][A-Za-z0-9_.-]{0,64})=(["'])([A-Za-z0-9+/._~%=-]{16,})\2/giu;
|
|
199
125
|
const LOOSE_CREDENTIAL_PAIR_RE = /\b((?!(?:api|endpoint|method|model|provider|status|type)=)[A-Za-z][A-Za-z0-9_.-]{0,64})=([A-Za-z0-9+/._~%=-]{16,})(?=[;&#'"\s]|$)/giu;
|
|
200
126
|
const MEDIA_DATA_URL_RE = /data:(?:audio|image|video)\/[a-z0-9.+-]+(?:;[^,;\s]+)*;base64,[ \t]*(?:\r?\n[ \t]*)?[a-z0-9+/_=-]+(?:[ \t]*\r?\n[ \t]*[a-z0-9+/_=-]+)*/giu;
|
|
201
|
-
const MAX_DIAGNOSTIC_JSON_LENGTH =
|
|
127
|
+
const MAX_DIAGNOSTIC_JSON_LENGTH = 16384;
|
|
202
128
|
const PLAIN_BRACKET_TAG_RE = /^\[[A-Za-z0-9][A-Za-z0-9 _.-]*\]$/u;
|
|
203
129
|
const JSON_ARRAY_START_RE = /\[\s*(?:[{"\d\]-]|true\b|false\b|null\b)/u;
|
|
204
130
|
const MALFORMED_JSON_RE = /\{|(?:"[^"]+"|\b(?:b64_json|data|(?:input|output)?(?:audio|image|video)[\w-]*))\s*:/iu;
|
|
@@ -421,4 +347,4 @@ function projectProviderError(error, signal) {
|
|
|
421
347
|
}
|
|
422
348
|
}
|
|
423
349
|
//#endregion
|
|
424
|
-
export {
|
|
350
|
+
export { stableStringify as i, projectProviderError as n, projectDiagnosticValue as r, configureProviderErrorRedactor as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as StreamOptions } from "./types-Beemor2E.mjs";
|
|
2
|
+
import "./types-COdhCX0U.mjs";
|
|
2
3
|
import OpenAI from "openai";
|
|
3
4
|
import Anthropic from "@anthropic-ai/sdk";
|
|
4
5
|
import { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
|
|
5
|
-
|
|
6
6
|
//#region packages/ai/src/providers/openai-reasoning-effort.d.ts
|
|
7
7
|
type OpenAIReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
8
8
|
type OpenAIApiReasoningEffort = OpenAIReasoningEffort | (string & {});
|
|
@@ -82,11 +82,19 @@ type CodeModeToolSurfaceObservation = {
|
|
|
82
82
|
afterToolIdentities: readonly string[];
|
|
83
83
|
};
|
|
84
84
|
type CodeModeToolSurfaceObserver = (observation: CodeModeToolSurfaceObservation) => void;
|
|
85
|
+
declare function markStrictReasoningTagText(options: object): void;
|
|
86
|
+
declare function isStrictReasoningTagText(options: object | undefined): boolean;
|
|
85
87
|
declare const codeModeToolSurfaceObserver: {
|
|
86
88
|
set(options: object, observer: CodeModeToolSurfaceObserver, collector?: CodeModeToolSurfaceObserver): void;
|
|
87
89
|
get(options: object | undefined): CodeModeToolSurfaceObserver | undefined;
|
|
88
90
|
getCollector(options: object | undefined): CodeModeToolSurfaceObserver | undefined;
|
|
89
91
|
};
|
|
92
|
+
/** Internal output policy for callers that must not recover ambiguous reasoning as visible text. */
|
|
93
|
+
declare const reasoningTagTextPolicy: {
|
|
94
|
+
markStrict: typeof markStrictReasoningTagText;
|
|
95
|
+
isStrict: typeof isStrictReasoningTagText;
|
|
96
|
+
copy(source: object | undefined, target: object): void;
|
|
97
|
+
};
|
|
90
98
|
type AnthropicEffort = "low" | "medium" | "high" | "xhigh" | "max";
|
|
91
99
|
type AnthropicThinkingDisplay = "summarized" | "omitted";
|
|
92
100
|
/** Provider options shared by the Anthropic provider and canonical transport. */
|
|
@@ -142,7 +150,8 @@ type BaseOpenAIStreamOptions = StreamOptions & {
|
|
|
142
150
|
topP?: number;
|
|
143
151
|
authProfileId?: string;
|
|
144
152
|
firstEventTimeoutMs?: number;
|
|
145
|
-
onFirstEventTimeout?: (reason: Error) => void;
|
|
153
|
+
onFirstEventTimeout?: (reason: Error) => void;
|
|
154
|
+
/** Internal owner notification after a server rejects a persisted compaction checkpoint. */
|
|
146
155
|
onCompactionRejected?: (checkpoint: OpenAIResponsesCompactionRejection) => void;
|
|
147
156
|
openclawCodeModeToolSurface?: boolean;
|
|
148
157
|
openclawCodeModeAllowedHostedToolTypes?: Set<string>;
|
|
@@ -157,4 +166,4 @@ type OpenAICompletionsOptions = BaseOpenAIStreamOptions & {
|
|
|
157
166
|
reasoningEffort?: OpenAIReasoningEffort;
|
|
158
167
|
};
|
|
159
168
|
//#endregion
|
|
160
|
-
export {
|
|
169
|
+
export { supportsOpenAIReasoningEffort as C, resolveOpenAISupportedReasoningEfforts as S, isOpenAIGpt54MiniModel as _, CodeModeToolSurfaceObservation as a, normalizeOpenAIReasoningEffort as b, codeModeToolSurfaceObserver as c, OpenAIToolProjection as d, projectOpenAITools as f, OpenAIReasoningEffort as g, OpenAIApiReasoningEffort as h, BaseOpenAIStreamOptions as i, reasoningTagTextPolicy as l, reconcileOpenAIResponsesToolChoice as m, AnthropicOptions as n, OpenAICompletionsOptions as o, reconcileOpenAICompletionsToolChoice as p, AnthropicThinkingDisplay as r, OpenAIResponsesCompactionRejection as s, AnthropicEffort as t, OpenAICompletionsToolChoice as u, isOpenAIGpt55Model as v, supportsOpenAITemperature as w, resolveOpenAIReasoningEffortForModel as x, isOpenAIGpt56Model as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as transformMessages } from "./host-
|
|
1
|
+
import { i as transformMessages } from "./host-BIaiBURL.mjs";
|
|
2
2
|
//#region packages/ai/src/provider-transcript-transform.ts
|
|
3
3
|
const IMAGE_OMISSION = "(image omitted: model does not support images)";
|
|
4
4
|
const VIDEO_OMISSION = "(video omitted: provider does not support video input)";
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { _ as supportsClaudeAdaptiveThinking, a as CLAUDE_FABLE_5_THINKING_PROFILE, b as supportsClaudeNativeXhighEffort, c as requiresClaudeDefaultSampling, d as resolveClaudeModelIdentity, f as resolveClaudeMythos5ModelIdentity, g as supportsClaude1MContext, h as resolveClaudeSonnet5ModelIdentity, i as normalizeResolvedPricing, l as requiresClaudeMandatoryAdaptiveThinking, m as resolveClaudeOpus5ModelIdentity, n as calculateUsageCost, o as CLAUDE_OPUS_5_THINKING_PROFILE, p as resolveClaudeNativeThinkingLevelMap, r as normalizeModelCostConfig, s as CLAUDE_SONNET_5_THINKING_PROFILE, t as index_d_exports, u as resolveClaudeFable5ModelIdentity, v as supportsClaudeFastMode, y as supportsClaudeNativeMaxEffort } from "./index-CefaUGSS.mjs";
|
|
2
2
|
import { a as extractDiagnosticError, i as createAssistantMessageDiagnostic, n as DiagnosticErrorInfo, o as formatThrownValue, r as appendAssistantMessageDiagnostic, t as AssistantMessageDiagnostic } from "./diagnostics-BaTA9eVl.mjs";
|
|
3
|
-
import { $ as
|
|
4
|
-
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
5
|
-
import { n as validateToolCall, t as validateToolArguments } from "./validation-
|
|
3
|
+
import { $ as ThinkingLevel, A as ModelThinkingLevel, B as ProviderResponse, C as KnownImagesApi, D as Model, F as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, G as StopReason, H as RawModelCostConfig, I as PricingTier, J as StreamOptions, K as StreamFn, L as Provider, M as OpenAIResponsesCompat, N as OpenRouterRouting, O as ModelCostConfig, P as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, Q as ThinkingContent, R as ProviderImagesOptions, S as KnownApi, T as MaybePromise, U as RawPricingTier, W as SimpleStreamOptions, X as TextSignatureV1, Y as TextContent, Z as ThinkingBudgets, _ as ImagesModel, a as AssistantMessage, at as Usage, b as ImagesProvider, c as AssistantMessageEventStreamLike, ct as VercelGatewayRouting, d as Context, et as ThinkingLevelMap, f as ImageContent, g as ImagesInputContent, h as ImagesFunction, i as AssistantImages, it as Transport, j as OpenAICompletionsCompat, k as ModelCostRates, l as CacheRetention, m as ImagesContext, n as Api, nt as ToolCall, o as AssistantMessageEvent, ot as UserMessage, p as ImagesApi, r as AssistantDeliveryTtsFacts, rt as ToolResultMessage, s as AssistantMessageEventStreamContract, st as ValidateToolArgumentsFn, t as AnthropicMessagesCompat, tt as Tool, u as CompleteSimpleFn, v as ImagesOptions, w as KnownImagesProvider, x as ImagesStopReason, y as ImagesOutputContent, z as ProviderReplayState } from "./types-Beemor2E.mjs";
|
|
4
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-DcvAPSBe.mjs";
|
|
5
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-CC6s7Smp.mjs";
|
|
6
|
+
import "./types-COdhCX0U.mjs";
|
|
6
7
|
//#region packages/ai/src/provider-types.d.ts
|
|
7
|
-
declare const PROVIDER_CONTEXT_HANDOFF: unique symbol;
|
|
8
|
-
type VideoContent = Omit<ImageContent, "type"> & {
|
|
8
|
+
export declare const PROVIDER_CONTEXT_HANDOFF: unique symbol;
|
|
9
|
+
export type VideoContent = Omit<ImageContent, "type"> & {
|
|
9
10
|
type: "video";
|
|
10
11
|
};
|
|
11
|
-
type MediaContent = ImageContent | VideoContent;
|
|
12
|
-
type ModelInputContent = TextContent | MediaContent;
|
|
13
|
-
type ProviderUserMessage = Omit<UserMessage, "content"> & {
|
|
12
|
+
export type MediaContent = ImageContent | VideoContent;
|
|
13
|
+
export type ModelInputContent = TextContent | MediaContent;
|
|
14
|
+
export type ProviderUserMessage = Omit<UserMessage, "content"> & {
|
|
14
15
|
content: string | ModelInputContent[];
|
|
15
16
|
};
|
|
16
|
-
type ProviderMessage = ProviderUserMessage | AssistantMessage | ToolResultMessage;
|
|
17
|
-
type ProviderContext = Omit<Context, "messages"> & {
|
|
17
|
+
export type ProviderMessage = ProviderUserMessage | AssistantMessage | ToolResultMessage;
|
|
18
|
+
export type ProviderContext = Omit<Context, "messages"> & {
|
|
18
19
|
messages: ProviderMessage[];
|
|
19
20
|
};
|
|
20
|
-
type ProviderModel<TApi extends Api = Api> = Omit<Model<TApi>, "input"> & {
|
|
21
|
+
export type ProviderModel<TApi extends Api = Api> = Omit<Model<TApi>, "input"> & {
|
|
21
22
|
input: ModelInputContent["type"][];
|
|
22
23
|
};
|
|
23
|
-
type ProviderContextHandoff = () => Promise<ProviderContext>;
|
|
24
|
-
type ProviderStreamOptions = StreamOptions & {
|
|
24
|
+
export type ProviderContextHandoff = () => Promise<ProviderContext>;
|
|
25
|
+
export type ProviderStreamOptions = StreamOptions & {
|
|
25
26
|
[PROVIDER_CONTEXT_HANDOFF]?: ProviderContextHandoff;
|
|
26
27
|
};
|
|
27
|
-
type ProviderStreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = ProviderStreamOptions> = (model: ProviderModel<TApi>, context: ProviderContext, options?: TOptions) => AssistantMessageEventStreamContract;
|
|
28
|
+
export type ProviderStreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = ProviderStreamOptions> = (model: ProviderModel<TApi>, context: ProviderContext, options?: TOptions) => AssistantMessageEventStreamContract;
|
|
28
29
|
/** Resolves provider-only context without widening the canonical call contract. */
|
|
29
|
-
declare function resolveProviderContext(context: Context | ProviderContext, options?: ProviderStreamOptions): Promise<ProviderContext>;
|
|
30
|
+
export declare function resolveProviderContext(context: Context | ProviderContext, options?: ProviderStreamOptions): Promise<ProviderContext>;
|
|
30
31
|
//#endregion
|
|
31
|
-
export {
|
|
32
|
+
export type { 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, ProviderContext as Context, DiagnosticErrorInfo, EventStream, ImageContent, ImagesApi, ImagesContext, ImagesFunction, ImagesInputContent, ImagesModel, ImagesOptions, ImagesOutputContent, ImagesProvider, ImagesStopReason, KnownApi, KnownImagesApi, KnownImagesProvider, MaybePromise, ProviderMessage as Message, ProviderModel as Model, ModelCostConfig, ModelCostRates, ModelThinkingLevel, OpenAICompletionsCompat, OpenAIResponsesCompat, OpenRouterRouting, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, PricingTier, Provider, ProviderImagesOptions, ProviderReplayState, ProviderResponse, ProviderStreamFunction as StreamFunction, RawModelCostConfig, RawPricingTier, SimpleStreamOptions, StopReason, StreamFn, StreamOptions, TextContent, TextSignatureV1, ThinkingBudgets, ThinkingContent, ThinkingLevel, ThinkingLevelMap, Tool, ToolCall, ToolResultMessage, Transport, Usage, UserMessage, ValidateToolArgumentsFn, VercelGatewayRouting, appendAssistantMessageDiagnostic, calculateUsageCost, createAssistantMessageDiagnostic, createAssistantMessageEventStream, extractDiagnosticError, formatThrownValue, normalizeModelCostConfig, normalizeResolvedPricing, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
package/dist/providers.d.mts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { n as ApiRegistry } from "./api-registry-
|
|
1
|
+
import { n as ApiRegistry } from "./api-registry-BbUHEKER.mjs";
|
|
2
2
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-2uo_1OR1.mjs";
|
|
3
|
-
|
|
4
3
|
//#region packages/ai/src/providers/register-builtins.d.ts
|
|
5
4
|
/** Source id used for built-in API provider registrations. */
|
|
6
|
-
declare const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
|
|
5
|
+
export declare const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
|
|
7
6
|
/** Registers every built-in API provider in one runtime registry. */
|
|
8
|
-
declare function registerBuiltInApiProviders(registry: ApiRegistry): void;
|
|
7
|
+
export declare function registerBuiltInApiProviders(registry: ApiRegistry): void;
|
|
9
8
|
/** Restores the built-in provider registry state for tests. */
|
|
10
|
-
declare function resetApiProviders(registry: ApiRegistry): void;
|
|
9
|
+
export declare function resetApiProviders(registry: ApiRegistry): void;
|
|
11
10
|
//#endregion
|
|
12
|
-
export {
|
|
11
|
+
export { OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH, clampOpenAIPromptCacheKey };
|
package/dist/providers.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
2
|
-
import { n as projectProviderError } from "./provider-error-
|
|
2
|
+
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
3
3
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
4
4
|
//#region packages/ai/src/providers/register-builtins.ts
|
|
5
5
|
/** Source id used for built-in API provider registrations. */
|
|
@@ -62,35 +62,35 @@ function createLazyRegistration(api, importModule, select) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
const registerBuiltIns = [
|
|
65
|
-
createLazyRegistration("anthropic-messages", () => import("./anthropic-
|
|
65
|
+
createLazyRegistration("anthropic-messages", () => import("./anthropic-DTGZ4VMY.mjs").then((n) => n.t), (module) => ({
|
|
66
66
|
stream: module.streamAnthropic,
|
|
67
67
|
streamSimple: module.streamSimpleAnthropic
|
|
68
68
|
})),
|
|
69
|
-
createLazyRegistration("openai-completions", () => import("./openai-completions-
|
|
69
|
+
createLazyRegistration("openai-completions", () => import("./openai-completions-BfFwac6f.mjs").then((n) => n.t), (module) => ({
|
|
70
70
|
stream: module.streamOpenAICompletions,
|
|
71
71
|
streamSimple: module.streamSimpleOpenAICompletions
|
|
72
72
|
})),
|
|
73
|
-
createLazyRegistration("mistral-conversations", () => import("./mistral-
|
|
73
|
+
createLazyRegistration("mistral-conversations", () => import("./mistral-C24jVd6f.mjs"), (module) => ({
|
|
74
74
|
stream: module.streamMistral,
|
|
75
75
|
streamSimple: module.streamSimpleMistral
|
|
76
76
|
})),
|
|
77
|
-
createLazyRegistration("openai-responses", () => import("./openai-responses-
|
|
77
|
+
createLazyRegistration("openai-responses", () => import("./openai-responses-BAryVEJM.mjs").then((n) => n.t), (module) => ({
|
|
78
78
|
stream: module.streamOpenAIResponses,
|
|
79
79
|
streamSimple: module.streamSimpleOpenAIResponses
|
|
80
80
|
})),
|
|
81
|
-
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-
|
|
81
|
+
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-BmqaDXM1.mjs"), (module) => ({
|
|
82
82
|
stream: module.streamAzureOpenAIResponses,
|
|
83
83
|
streamSimple: module.streamSimpleAzureOpenAIResponses
|
|
84
84
|
})),
|
|
85
|
-
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-
|
|
85
|
+
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-Czum0oXz.mjs"), (module) => ({
|
|
86
86
|
stream: module.streamOpenAICodexResponses,
|
|
87
87
|
streamSimple: module.streamSimpleOpenAICodexResponses
|
|
88
88
|
})),
|
|
89
|
-
createLazyRegistration("google-generative-ai", () => import("./google-
|
|
89
|
+
createLazyRegistration("google-generative-ai", () => import("./google-CqjVZMwo.mjs"), (module) => ({
|
|
90
90
|
stream: module.streamGoogle,
|
|
91
91
|
streamSimple: module.streamSimpleGoogle
|
|
92
92
|
})),
|
|
93
|
-
createLazyRegistration("google-vertex", () => import("./google-vertex-
|
|
93
|
+
createLazyRegistration("google-vertex", () => import("./google-vertex-D_WREEJi.mjs"), (module) => ({
|
|
94
94
|
stream: module.streamGoogleVertex,
|
|
95
95
|
streamSimple: module.streamSimpleGoogleVertex
|
|
96
96
|
}))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
2
|
//#region node_modules/mdast-util-to-string/lib/index.js
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {import('mdast').Nodes} Nodes
|
|
@@ -5375,7 +5375,9 @@ function factoryLabel(effects, ok, nok, type, markerType, stringType) {
|
|
|
5375
5375
|
* @type {State}
|
|
5376
5376
|
*/
|
|
5377
5377
|
function atBreak(code) {
|
|
5378
|
-
if (size > 999 || code === null || code === 91 || code === 93 && !seen ||
|
|
5378
|
+
if (size > 999 || code === null || code === 91 || code === 93 && !seen ||
|
|
5379
|
+
/* c8 ignore next 3 */
|
|
5380
|
+
code === 94 && !size && "_hiddenFootnoteSupport" in self.parser.constructs) return nok(code);
|
|
5379
5381
|
if (code === 93) {
|
|
5380
5382
|
effects.exit(stringType);
|
|
5381
5383
|
effects.enter(markerType);
|
|
@@ -9867,8 +9869,10 @@ function compiler(options) {
|
|
|
9867
9869
|
/** @type {Array<number>} */
|
|
9868
9870
|
const listStack = [];
|
|
9869
9871
|
let index = -1;
|
|
9870
|
-
while (++index < events.length) if (events[index][1].type === "listOrdered" || events[index][1].type === "listUnordered")
|
|
9871
|
-
|
|
9872
|
+
while (++index < events.length) if (events[index][1].type === "listOrdered" || events[index][1].type === "listUnordered") {
|
|
9873
|
+
if (events[index][0] === "enter") listStack.push(index);
|
|
9874
|
+
else index = prepareList(events, listStack.pop(), index);
|
|
9875
|
+
}
|
|
9872
9876
|
index = -1;
|
|
9873
9877
|
while (++index < events.length) {
|
|
9874
9878
|
const handler = config[events[index][0]];
|
|
@@ -10058,8 +10062,10 @@ function compiler(options) {
|
|
|
10058
10062
|
start: token.start,
|
|
10059
10063
|
end: token.end
|
|
10060
10064
|
}) + "): it’s not open");
|
|
10061
|
-
else if (open[0].type !== token.type)
|
|
10062
|
-
|
|
10065
|
+
else if (open[0].type !== token.type) {
|
|
10066
|
+
if (onExitError) onExitError.call(this, token, open[0]);
|
|
10067
|
+
else (open[1] || defaultOnError).call(this, token, open[0]);
|
|
10068
|
+
}
|
|
10063
10069
|
node.position.end = point(token.end);
|
|
10064
10070
|
}
|
|
10065
10071
|
/**
|
|
@@ -11416,19 +11422,21 @@ function resolveTable(events, context) {
|
|
|
11416
11422
|
}
|
|
11417
11423
|
cell[2] = index;
|
|
11418
11424
|
}
|
|
11419
|
-
} else if (token.type === "tableCellDivider")
|
|
11420
|
-
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
|
|
11425
|
+
} else if (token.type === "tableCellDivider") {
|
|
11426
|
+
if (inFirstCellAwaitingPipe) inFirstCellAwaitingPipe = false;
|
|
11427
|
+
else {
|
|
11428
|
+
if (lastCell[1] !== 0) {
|
|
11429
|
+
cell[0] = cell[1];
|
|
11430
|
+
currentCell = flushCell(map, context, lastCell, rowKind, void 0, currentCell);
|
|
11431
|
+
}
|
|
11432
|
+
lastCell = cell;
|
|
11433
|
+
cell = [
|
|
11434
|
+
lastCell[1],
|
|
11435
|
+
index,
|
|
11436
|
+
0,
|
|
11437
|
+
0
|
|
11438
|
+
];
|
|
11424
11439
|
}
|
|
11425
|
-
lastCell = cell;
|
|
11426
|
-
cell = [
|
|
11427
|
-
lastCell[1],
|
|
11428
|
-
index,
|
|
11429
|
-
0,
|
|
11430
|
-
0
|
|
11431
|
-
];
|
|
11432
11440
|
}
|
|
11433
11441
|
} else if (token.type === "tableHead") {
|
|
11434
11442
|
afterHeadAwaitingFirstBodyRow = true;
|
|
@@ -11821,8 +11829,10 @@ function reduceReasoningText(text, codeSpans, state, options) {
|
|
|
11821
11829
|
append(text.slice(cursor));
|
|
11822
11830
|
if (options.final && state.depth > 0 && state.pending) {
|
|
11823
11831
|
const pending = state.pending;
|
|
11824
|
-
if (!pending.containsPrivate)
|
|
11825
|
-
|
|
11832
|
+
if (!pending.containsPrivate) {
|
|
11833
|
+
if (options.mode === "static-preserve" || options.mode === "static-strict" && !pending.visibleBefore && !pending.protectedClose || options.mode === "visible" && !pending.protectedClose) emit("text", options.mode === "visible" && pending.visibleBefore ? pending.openTag + pending.content : pending.content);
|
|
11834
|
+
else emit("thinking", pending.content);
|
|
11835
|
+
}
|
|
11826
11836
|
state.depth = 0;
|
|
11827
11837
|
state.pending = void 0;
|
|
11828
11838
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __exportAll = (all, no_symbols) => {
|
|
5
|
+
let target = {};
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
14
|
+
//#endregion
|
|
15
|
+
export { __require as n, __exportAll as t };
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./src-D2H6yKkH.mjs";
|
|
1
|
+
import { c as requiresClaudeMandatoryAdaptiveThinking, f as resolveClaudeNativeThinkingLevelMap, t as calculateUsageCost } from "./src-C8U7lkoa.mjs";
|
|
3
2
|
//#region packages/ai/src/model-utils.ts
|
|
4
3
|
/** Calculates and stores model cost fields from token usage and per-million pricing. */
|
|
5
4
|
function calculateCost(model, usage) {
|
|
6
|
-
|
|
7
|
-
const cacheWrite5m = usage.cacheWrite - cacheWrite1h;
|
|
8
|
-
usage.cost.input = model.cost.input / 1e6 * usage.input;
|
|
9
|
-
usage.cost.output = model.cost.output / 1e6 * usage.output;
|
|
10
|
-
usage.cost.cacheRead = model.cost.cacheRead / 1e6 * usage.cacheRead;
|
|
11
|
-
usage.cost.cacheWrite = (model.cost.cacheWrite * cacheWrite5m + model.cost.input * 2 * cacheWrite1h) / 1e6;
|
|
12
|
-
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
5
|
+
Object.assign(usage.cost, calculateUsageCost(usage, model.cost));
|
|
13
6
|
return usage.cost;
|
|
14
7
|
}
|
|
15
8
|
/** Replaces the catalog estimate when the provider reports an authoritative billed total. */
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { c as normalizeLowercaseStringOrEmpty } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-S6binQG-.mjs";
|
|
3
|
+
import { r as copyProviderAcceptanceObserver } from "./transport-stream-shared-D8nQWCUo.mjs";
|
|
4
|
+
//#region packages/ai/src/utils/prompt-cache-stability.ts
|
|
5
|
+
/**
|
|
6
|
+
* Prompt-cache normalization helpers. They keep generated prompt sections
|
|
7
|
+
* deterministic across platform newlines, trailing whitespace, and input
|
|
8
|
+
* ordering.
|
|
9
|
+
*/
|
|
10
|
+
/** Canonicalizes provider tool order without relying on host locale settings. */
|
|
11
|
+
function sortPromptCacheToolsByName(tools) {
|
|
12
|
+
const compareText = (left, right) => {
|
|
13
|
+
const leftText = left ?? "";
|
|
14
|
+
const rightText = right ?? "";
|
|
15
|
+
return leftText < rightText ? -1 : leftText > rightText ? 1 : 0;
|
|
16
|
+
};
|
|
17
|
+
return tools.toSorted((left, right) => compareText(left.wireName ?? left.name, right.wireName ?? right.name) || compareText(left.description, right.description));
|
|
18
|
+
}
|
|
19
|
+
/** Normalize structured prompt text before hashing or snapshot comparison. */
|
|
20
|
+
function normalizeStructuredPromptSection(text) {
|
|
21
|
+
return sanitizeSurrogates(text).replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "").trim();
|
|
22
|
+
}
|
|
23
|
+
/** Normalize, de-dupe, and sort capability ids for stable prompt payloads. */
|
|
24
|
+
function normalizePromptCapabilityIds(capabilities) {
|
|
25
|
+
const seen = /* @__PURE__ */ new Set();
|
|
26
|
+
const normalized = [];
|
|
27
|
+
for (const capability of capabilities) {
|
|
28
|
+
const value = normalizeLowercaseStringOrEmpty(normalizeStructuredPromptSection(capability));
|
|
29
|
+
if (!value || seen.has(value)) continue;
|
|
30
|
+
seen.add(value);
|
|
31
|
+
normalized.push(value);
|
|
32
|
+
}
|
|
33
|
+
return normalized.toSorted((left, right) => left.localeCompare(right));
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region packages/ai/src/utils/system-prompt-cache-boundary.ts
|
|
37
|
+
/**
|
|
38
|
+
* System prompt cache-boundary helpers.
|
|
39
|
+
*
|
|
40
|
+
* Keeps stable prompt prefixes separate from dynamic runtime additions for provider prompt caching.
|
|
41
|
+
*/
|
|
42
|
+
const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
43
|
+
function stripSystemPromptCacheBoundary(text) {
|
|
44
|
+
return text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n");
|
|
45
|
+
}
|
|
46
|
+
function ensureSystemPromptCacheBoundary(systemPrompt) {
|
|
47
|
+
if (systemPrompt.trim().length === 0) return systemPrompt;
|
|
48
|
+
return systemPrompt.includes("\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n") ? systemPrompt : `${systemPrompt}${SYSTEM_PROMPT_CACHE_BOUNDARY}`;
|
|
49
|
+
}
|
|
50
|
+
function splitSystemPromptCacheBoundary(text) {
|
|
51
|
+
const boundaryIndex = text.indexOf(SYSTEM_PROMPT_CACHE_BOUNDARY);
|
|
52
|
+
if (boundaryIndex === -1) return;
|
|
53
|
+
return {
|
|
54
|
+
stablePrefix: text.slice(0, boundaryIndex).trimEnd(),
|
|
55
|
+
dynamicSuffix: text.slice(boundaryIndex + 34).trimStart()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function prependSystemPromptAdditionAfterCacheBoundary(params) {
|
|
59
|
+
const systemPromptAddition = typeof params.systemPromptAddition === "string" ? normalizeStructuredPromptSection(params.systemPromptAddition) : "";
|
|
60
|
+
if (!systemPromptAddition) return params.systemPrompt;
|
|
61
|
+
if (params.systemPrompt.trim().length === 0) return systemPromptAddition;
|
|
62
|
+
const split = splitSystemPromptCacheBoundary(params.systemPrompt);
|
|
63
|
+
if (!split) return `${systemPromptAddition}\n\n${params.systemPrompt}`;
|
|
64
|
+
const dynamicSuffix = split.dynamicSuffix ? normalizeStructuredPromptSection(split.dynamicSuffix) : "";
|
|
65
|
+
if (!dynamicSuffix) return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}`;
|
|
66
|
+
return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}\n\n${dynamicSuffix}`;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region packages/ai/src/provider-options.ts
|
|
70
|
+
const CODE_MODE_TOOL_SURFACE_OBSERVER = Symbol("openaiCodeModeToolSurfaceObserver");
|
|
71
|
+
const CODE_MODE_TOOL_SURFACE_COLLECTOR = Symbol("openaiCodeModeToolSurfaceCollector");
|
|
72
|
+
const STRICT_REASONING_TAG_TEXT = Symbol("openaiStrictReasoningTagText");
|
|
73
|
+
function markStrictReasoningTagText(options) {
|
|
74
|
+
Reflect.set(options, STRICT_REASONING_TAG_TEXT, true);
|
|
75
|
+
}
|
|
76
|
+
function isStrictReasoningTagText(options) {
|
|
77
|
+
return options ? Reflect.get(options, STRICT_REASONING_TAG_TEXT) === true : false;
|
|
78
|
+
}
|
|
79
|
+
const codeModeToolSurfaceObserver = {
|
|
80
|
+
set(options, observer, collector) {
|
|
81
|
+
Reflect.set(options, CODE_MODE_TOOL_SURFACE_OBSERVER, observer);
|
|
82
|
+
if (collector) Reflect.set(options, CODE_MODE_TOOL_SURFACE_COLLECTOR, collector);
|
|
83
|
+
},
|
|
84
|
+
get(options) {
|
|
85
|
+
if (!options) return;
|
|
86
|
+
const observer = Reflect.get(options, CODE_MODE_TOOL_SURFACE_OBSERVER);
|
|
87
|
+
return typeof observer === "function" ? (observation) => observer(observation) : void 0;
|
|
88
|
+
},
|
|
89
|
+
getCollector(options) {
|
|
90
|
+
if (!options) return;
|
|
91
|
+
const collector = Reflect.get(options, CODE_MODE_TOOL_SURFACE_COLLECTOR);
|
|
92
|
+
return typeof collector === "function" ? (observation) => collector(observation) : void 0;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/** Internal output policy for callers that must not recover ambiguous reasoning as visible text. */
|
|
96
|
+
const reasoningTagTextPolicy = {
|
|
97
|
+
markStrict: markStrictReasoningTagText,
|
|
98
|
+
isStrict: isStrictReasoningTagText,
|
|
99
|
+
copy(source, target) {
|
|
100
|
+
if (isStrictReasoningTagText(source)) markStrictReasoningTagText(target);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region packages/ai/src/providers/simple-options.ts
|
|
105
|
+
function buildBaseOptions(model, options, apiKey) {
|
|
106
|
+
const firstEventOptions = options;
|
|
107
|
+
const baseOptions = {
|
|
108
|
+
temperature: options?.temperature,
|
|
109
|
+
maxTokens: options?.maxTokens,
|
|
110
|
+
stop: options?.stop,
|
|
111
|
+
signal: options?.signal,
|
|
112
|
+
apiKey: apiKey || options?.apiKey,
|
|
113
|
+
transport: options?.transport,
|
|
114
|
+
cacheRetention: options?.cacheRetention,
|
|
115
|
+
sessionId: options?.sessionId,
|
|
116
|
+
promptCacheKey: options?.promptCacheKey,
|
|
117
|
+
headers: options?.headers,
|
|
118
|
+
onPayload: options?.onPayload,
|
|
119
|
+
onResponse: options?.onResponse,
|
|
120
|
+
timeoutMs: options?.timeoutMs,
|
|
121
|
+
firstEventTimeoutMs: firstEventOptions?.firstEventTimeoutMs,
|
|
122
|
+
onFirstEventTimeout: firstEventOptions?.onFirstEventTimeout,
|
|
123
|
+
maxRetries: options?.maxRetries,
|
|
124
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
125
|
+
metadata: options?.metadata
|
|
126
|
+
};
|
|
127
|
+
reasoningTagTextPolicy.copy(options, baseOptions);
|
|
128
|
+
return copyProviderAcceptanceObserver(options, baseOptions);
|
|
129
|
+
}
|
|
130
|
+
function clampMaxTokensToModel(model, requestedMaxTokens) {
|
|
131
|
+
return requestedMaxTokens === void 0 ? void 0 : Math.max(1, Math.min(requestedMaxTokens, model.maxTokens));
|
|
132
|
+
}
|
|
133
|
+
function clampReasoning(effort) {
|
|
134
|
+
return effort === "xhigh" ? "high" : effort;
|
|
135
|
+
}
|
|
136
|
+
function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
|
|
137
|
+
const budgets = {
|
|
138
|
+
minimal: 1024,
|
|
139
|
+
low: 2048,
|
|
140
|
+
medium: 8192,
|
|
141
|
+
high: 16384,
|
|
142
|
+
max: 32768,
|
|
143
|
+
...customBudgets
|
|
144
|
+
};
|
|
145
|
+
const minOutputTokens = 1024;
|
|
146
|
+
let thinkingBudget = budgets[clampReasoning(reasoningLevel)];
|
|
147
|
+
const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
|
|
148
|
+
if (maxTokens <= thinkingBudget) thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
|
|
149
|
+
return {
|
|
150
|
+
maxTokens,
|
|
151
|
+
thinkingBudget
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
export { codeModeToolSurfaceObserver as a, ensureSystemPromptCacheBoundary as c, stripSystemPromptCacheBoundary as d, normalizePromptCapabilityIds as f, clampReasoning as i, prependSystemPromptAdditionAfterCacheBoundary as l, sortPromptCacheToolsByName as m, buildBaseOptions as n, reasoningTagTextPolicy as o, normalizeStructuredPromptSection as p, clampMaxTokensToModel as r, SYSTEM_PROMPT_CACHE_BOUNDARY as s, adjustMaxTokensForThinking as t, splitSystemPromptCacheBoundary as u };
|