@openclaw/ai 2026.8.1-beta.2 → 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-B6dLpq5L.mjs → anthropic-B8KwTtlb.mjs} +37 -27
- package/dist/{anthropic-SrGtwsJu.d.mts → anthropic-BECQCNdF.d.mts} +0 -2
- package/dist/{anthropic-JsNA5KCu.mjs → anthropic-BQXQudmA.mjs} +0 -1
- package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-4Zx7-aCr.mjs} +14 -15
- package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-CSx7MoKH.d.mts} +2 -1
- package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-DFxSnFqG.d.mts} +1 -1
- package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-Aa4mVcYG.mjs} +3 -3
- package/dist/diagnostics.mjs +1 -1
- package/dist/event-stream-BVVgDSdq.d.mts +1 -0
- package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-D91-ohD_.d.mts} +1 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-M1dl64nz.mjs} +12 -5
- package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-DCJHM_a5.mjs} +3 -3
- package/dist/{google-C7h2QzDX.mjs → google-yDRnipeq.mjs} +3 -3
- package/dist/headers-B_e4-1J0.mjs +9 -0
- package/dist/{host-DTqNc7ad.mjs → host-DF_yxOsA.mjs} +40 -29
- package/dist/{host-vWgMMhiJ.d.mts → host-DJq_FGcz.d.mts} +6 -6
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +2 -2
- package/dist/internal/anthropic.d.mts +11 -5
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +5 -5
- package/dist/internal/openai.mjs +9 -8
- package/dist/internal/runtime.d.mts +4 -2
- package/dist/internal/runtime.mjs +4 -3
- package/dist/internal/shared.d.mts +17 -3
- package/dist/internal/shared.mjs +4 -4
- package/dist/{headers-DdOQtGuU.mjs → llm-request-activity-BjtkplhG.mjs} +1 -9
- package/dist/{mistral-CEWoQI_g.mjs → mistral-D6hRXI7A.mjs} +47 -33
- package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-C339VIfT.mjs} +23 -15
- package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-D88orSJ9.mjs} +71 -35
- package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-B0KTleXp.d.mts} +2 -2
- package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-BXEcr-Tp.mjs} +4 -4
- package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-CD75pQ0m.d.mts} +2 -2
- package/dist/{openai-responses-contracts-CyfIkQi5.mjs → openai-responses-contracts-DvILoqBk.mjs} +3 -9
- package/dist/{openai-responses-payload-policy-BDxV-W0c.mjs → openai-responses-payload-policy-BDo8CQsx.mjs} +4 -2
- package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-CNGFT9zr.d.mts} +1 -0
- package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-BG-1AsBI.mjs} +2 -3
- package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-Cvt5MgEm.mjs} +81 -136
- package/dist/{openai-stop-reason-BkFkqqK0.mjs → openai-stop-reason-9OONKyAm.mjs} +47 -31
- package/dist/{openai-tool-projection-CY04OcvQ.mjs → openai-tool-projection-CHGLt03m.mjs} +94 -6
- package/dist/{provider-error-BUwEnjXq.mjs → provider-error-C8mBRJDl.mjs} +19 -24
- package/dist/provider-options-AvldWZt8.mjs +21 -0
- package/dist/{provider-options-B96RdNpH.d.mts → provider-options-Cc5ZQ6Aa.d.mts} +12 -2
- package/dist/provider-transcript-transform--gtf0ZbR.mjs +32 -0
- package/dist/provider-types.d.mts +5 -5
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-rnPwX2pg.mjs → reasoning-tag-text-partitioner-5ygO2rZc.mjs} +3 -0
- package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-BP7HLLZn.mjs} +1 -1
- package/dist/simple-options-oqsXB6U3.mjs +450 -0
- package/dist/{tool-schema-json-projection-q5d7QX5c.mjs → tool-schema-json-projection-FEr-jOoZ.mjs} +16 -7
- package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-Bv0FHkd0.mjs} +1 -1
- package/dist/transports.d.mts +77 -44
- package/dist/transports.mjs +207 -167
- package/dist/{types-BHNrPS1l.d.mts → types-DTAP49HF.d.mts} +17 -2
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +1 -1
- package/dist/{validation-DT9SrFn3.d.mts → validation-DYNNrU9u.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +1 -1
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +0 -155
- package/dist/simple-options-D58D5Kvw.mjs +0 -117
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { r as createAssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
2
|
+
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
3
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-BP7HLLZn.mjs";
|
|
4
|
+
import { i as asOptionalRecord, n as asNullableRecord, t as asNonArrayRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
5
|
+
import { n as projectProviderError } from "./provider-error-C8mBRJDl.mjs";
|
|
6
|
+
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
7
|
+
//#region packages/ai/src/utils/prompt-cache-stability.ts
|
|
8
|
+
/**
|
|
9
|
+
* Prompt-cache normalization helpers. They keep generated prompt sections
|
|
10
|
+
* deterministic across platform newlines, trailing whitespace, and input
|
|
11
|
+
* ordering.
|
|
12
|
+
*/
|
|
13
|
+
/** Canonicalizes provider tool order without relying on host locale settings. */
|
|
14
|
+
function sortPromptCacheToolsByName(tools) {
|
|
15
|
+
const compareText = (left, right) => {
|
|
16
|
+
const leftText = left ?? "";
|
|
17
|
+
const rightText = right ?? "";
|
|
18
|
+
return leftText < rightText ? -1 : leftText > rightText ? 1 : 0;
|
|
19
|
+
};
|
|
20
|
+
return tools.toSorted((left, right) => compareText(left.wireName ?? left.name, right.wireName ?? right.name) || compareText(left.description, right.description));
|
|
21
|
+
}
|
|
22
|
+
/** Normalize structured prompt text before hashing or snapshot comparison. */
|
|
23
|
+
function normalizeStructuredPromptSection(text) {
|
|
24
|
+
return sanitizeSurrogates(text).replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "").trim();
|
|
25
|
+
}
|
|
26
|
+
/** Normalize, de-dupe, and sort capability ids for stable prompt payloads. */
|
|
27
|
+
function normalizePromptCapabilityIds(capabilities) {
|
|
28
|
+
const seen = /* @__PURE__ */ new Set();
|
|
29
|
+
const normalized = [];
|
|
30
|
+
for (const capability of capabilities) {
|
|
31
|
+
const value = normalizeLowercaseStringOrEmpty(normalizeStructuredPromptSection(capability));
|
|
32
|
+
if (!value || seen.has(value)) continue;
|
|
33
|
+
seen.add(value);
|
|
34
|
+
normalized.push(value);
|
|
35
|
+
}
|
|
36
|
+
return normalized.toSorted((left, right) => left.localeCompare(right));
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region packages/ai/src/utils/system-prompt-cache-boundary.ts
|
|
40
|
+
/**
|
|
41
|
+
* System prompt cache-boundary helpers.
|
|
42
|
+
*
|
|
43
|
+
* Keeps stable prompt prefixes separate from dynamic runtime additions for provider prompt caching.
|
|
44
|
+
*/
|
|
45
|
+
const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
46
|
+
function stripSystemPromptCacheBoundary(text) {
|
|
47
|
+
return text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n");
|
|
48
|
+
}
|
|
49
|
+
function ensureSystemPromptCacheBoundary(systemPrompt) {
|
|
50
|
+
if (systemPrompt.trim().length === 0) return systemPrompt;
|
|
51
|
+
return systemPrompt.includes("\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n") ? systemPrompt : `${systemPrompt}${SYSTEM_PROMPT_CACHE_BOUNDARY}`;
|
|
52
|
+
}
|
|
53
|
+
function splitSystemPromptCacheBoundary(text) {
|
|
54
|
+
const boundaryIndex = text.indexOf(SYSTEM_PROMPT_CACHE_BOUNDARY);
|
|
55
|
+
if (boundaryIndex === -1) return;
|
|
56
|
+
return {
|
|
57
|
+
stablePrefix: text.slice(0, boundaryIndex).trimEnd(),
|
|
58
|
+
dynamicSuffix: text.slice(boundaryIndex + 34).trimStart()
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function prependSystemPromptAdditionAfterCacheBoundary(params) {
|
|
62
|
+
const systemPromptAddition = typeof params.systemPromptAddition === "string" ? normalizeStructuredPromptSection(params.systemPromptAddition) : "";
|
|
63
|
+
if (!systemPromptAddition) return params.systemPrompt;
|
|
64
|
+
if (params.systemPrompt.trim().length === 0) return systemPromptAddition;
|
|
65
|
+
const split = splitSystemPromptCacheBoundary(params.systemPrompt);
|
|
66
|
+
if (!split) return `${systemPromptAddition}\n\n${params.systemPrompt}`;
|
|
67
|
+
const dynamicSuffix = split.dynamicSuffix ? normalizeStructuredPromptSection(split.dynamicSuffix) : "";
|
|
68
|
+
if (!dynamicSuffix) return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}`;
|
|
69
|
+
return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}\n\n${dynamicSuffix}`;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region packages/ai/src/transports/json-unsafe-integers.ts
|
|
73
|
+
/**
|
|
74
|
+
* JSON parsing helpers that preserve integer literals larger than
|
|
75
|
+
* Number.MAX_SAFE_INTEGER as strings before JSON.parse can round them.
|
|
76
|
+
*/
|
|
77
|
+
const MAX_SAFE_INTEGER_ABS_STR = String(Number.MAX_SAFE_INTEGER);
|
|
78
|
+
function isAsciiDigit(ch) {
|
|
79
|
+
return ch !== void 0 && ch >= "0" && ch <= "9";
|
|
80
|
+
}
|
|
81
|
+
function parseJsonNumberToken(input, start) {
|
|
82
|
+
let idx = start;
|
|
83
|
+
if (input[idx] === "-") idx += 1;
|
|
84
|
+
if (idx >= input.length) return null;
|
|
85
|
+
if (input[idx] === "0") idx += 1;
|
|
86
|
+
else if (isAsciiDigit(input[idx]) && input[idx] !== "0") while (isAsciiDigit(input[idx])) idx += 1;
|
|
87
|
+
else return null;
|
|
88
|
+
let isInteger = true;
|
|
89
|
+
if (input[idx] === ".") {
|
|
90
|
+
isInteger = false;
|
|
91
|
+
idx += 1;
|
|
92
|
+
if (!isAsciiDigit(input[idx])) return null;
|
|
93
|
+
while (isAsciiDigit(input[idx])) idx += 1;
|
|
94
|
+
}
|
|
95
|
+
if (input[idx] === "e" || input[idx] === "E") {
|
|
96
|
+
isInteger = false;
|
|
97
|
+
idx += 1;
|
|
98
|
+
if (input[idx] === "+" || input[idx] === "-") idx += 1;
|
|
99
|
+
if (!isAsciiDigit(input[idx])) return null;
|
|
100
|
+
while (isAsciiDigit(input[idx])) idx += 1;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
token: input.slice(start, idx),
|
|
104
|
+
end: idx,
|
|
105
|
+
isInteger
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function isUnsafeIntegerLiteral(token) {
|
|
109
|
+
const digits = token[0] === "-" ? token.slice(1) : token;
|
|
110
|
+
if (digits.length < MAX_SAFE_INTEGER_ABS_STR.length) return false;
|
|
111
|
+
if (digits.length > MAX_SAFE_INTEGER_ABS_STR.length) return true;
|
|
112
|
+
return digits > MAX_SAFE_INTEGER_ABS_STR;
|
|
113
|
+
}
|
|
114
|
+
/** Quotes integer literals above Number.MAX_SAFE_INTEGER before JSON.parse. */
|
|
115
|
+
function quoteUnsafeIntegerLiterals(input) {
|
|
116
|
+
let out = "";
|
|
117
|
+
let inString = false;
|
|
118
|
+
let escaped = false;
|
|
119
|
+
let idx = 0;
|
|
120
|
+
while (idx < input.length) {
|
|
121
|
+
const ch = input[idx] ?? "";
|
|
122
|
+
if (inString) {
|
|
123
|
+
out += ch;
|
|
124
|
+
if (escaped) escaped = false;
|
|
125
|
+
else if (ch === "\\") escaped = true;
|
|
126
|
+
else if (ch === "\"") inString = false;
|
|
127
|
+
idx += 1;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (ch === "\"") {
|
|
131
|
+
inString = true;
|
|
132
|
+
out += ch;
|
|
133
|
+
idx += 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (ch === "-" || isAsciiDigit(ch)) {
|
|
137
|
+
const parsed = parseJsonNumberToken(input, idx);
|
|
138
|
+
if (parsed) {
|
|
139
|
+
if (parsed.isInteger && isUnsafeIntegerLiteral(parsed.token)) out += `"${parsed.token}"`;
|
|
140
|
+
else out += parsed.token;
|
|
141
|
+
idx = parsed.end;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
out += ch;
|
|
146
|
+
idx += 1;
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/** Parses JSON while preserving unsafe integer literals as strings. */
|
|
151
|
+
function parseJsonPreservingUnsafeIntegers(input) {
|
|
152
|
+
return JSON.parse(quoteUnsafeIntegerLiterals(input));
|
|
153
|
+
}
|
|
154
|
+
/** Parses or accepts an object while preserving unsafe integer literals in string input. */
|
|
155
|
+
function parseJsonObjectPreservingUnsafeIntegers(value) {
|
|
156
|
+
if (typeof value === "string") try {
|
|
157
|
+
return asNullableRecord(parseJsonPreservingUnsafeIntegers(value));
|
|
158
|
+
} catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
return asNullableRecord(value);
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region packages/ai/src/transports/transport-stream-shared.ts
|
|
165
|
+
const EMPTY_TOOL_RESULT_TEXT = "(no output)";
|
|
166
|
+
const MALFORMED_TOOL_CALL_TERMINAL_ERROR_MESSAGE = "Provider completed tool call with malformed JSON arguments";
|
|
167
|
+
function sanitizeTransportPayloadText(text) {
|
|
168
|
+
if (typeof text !== "string") return "";
|
|
169
|
+
return sanitizeSurrogates(text);
|
|
170
|
+
}
|
|
171
|
+
function sanitizeNonEmptyTransportPayloadText(text, fallback = EMPTY_TOOL_RESULT_TEXT) {
|
|
172
|
+
const sanitized = sanitizeTransportPayloadText(text);
|
|
173
|
+
return sanitized.trim().length > 0 ? sanitized : fallback;
|
|
174
|
+
}
|
|
175
|
+
function coerceTransportToolCallArguments(argumentsValue) {
|
|
176
|
+
const argumentsRecord = asOptionalRecord(argumentsValue);
|
|
177
|
+
if (argumentsRecord) return argumentsRecord;
|
|
178
|
+
if (typeof argumentsValue === "string") try {
|
|
179
|
+
return asNonArrayRecord(JSON.parse(argumentsValue));
|
|
180
|
+
} catch {}
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
/** Admit only complete object-shaped terminal tool arguments; partial parsing is preview-only. */
|
|
184
|
+
function parseTerminalToolCallArguments(value, errorMessage = MALFORMED_TOOL_CALL_TERMINAL_ERROR_MESSAGE) {
|
|
185
|
+
const parsed = parseJsonObjectPreservingUnsafeIntegers(value);
|
|
186
|
+
if (!parsed) throw new Error(errorMessage);
|
|
187
|
+
return parsed;
|
|
188
|
+
}
|
|
189
|
+
/** Validate a complete sibling set before mutating any call into executable state. */
|
|
190
|
+
function finalizeTerminalToolCallArguments(calls, readArguments, errorMessage) {
|
|
191
|
+
const validated = calls.map((call) => [call, parseTerminalToolCallArguments(readArguments(call), errorMessage)]);
|
|
192
|
+
for (const [call, argumentsValue] of validated) call.arguments = argumentsValue;
|
|
193
|
+
}
|
|
194
|
+
function mergeTransportHeaders(...headerSources) {
|
|
195
|
+
const merged = {};
|
|
196
|
+
for (const headers of headerSources) if (headers) Object.assign(merged, headers);
|
|
197
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
198
|
+
}
|
|
199
|
+
function mergeTransportMetadata(payload, metadata) {
|
|
200
|
+
if (!metadata || Object.keys(metadata).length === 0) return payload;
|
|
201
|
+
const existingMetadata = asOptionalRecord(payload.metadata);
|
|
202
|
+
return {
|
|
203
|
+
...payload,
|
|
204
|
+
metadata: {
|
|
205
|
+
...existingMetadata,
|
|
206
|
+
...metadata
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function createEmptyTransportUsage() {
|
|
211
|
+
return {
|
|
212
|
+
input: 0,
|
|
213
|
+
output: 0,
|
|
214
|
+
cacheRead: 0,
|
|
215
|
+
cacheWrite: 0,
|
|
216
|
+
totalTokens: 0,
|
|
217
|
+
cost: {
|
|
218
|
+
input: 0,
|
|
219
|
+
output: 0,
|
|
220
|
+
cacheRead: 0,
|
|
221
|
+
cacheWrite: 0,
|
|
222
|
+
total: 0
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function createWritableTransportEventStream() {
|
|
227
|
+
const eventStream = createAssistantMessageEventStream();
|
|
228
|
+
return {
|
|
229
|
+
eventStream,
|
|
230
|
+
stream: eventStream
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Abort error to surface for an aborted `signal`.
|
|
235
|
+
*
|
|
236
|
+
* Rethrows the caller's abort reason only when it carries a `code`, so that code
|
|
237
|
+
* survives into `errorCode` on the persisted assistant message and consumers can
|
|
238
|
+
* recognize an abort's origin without matching error text. A default
|
|
239
|
+
* `abort()` reason is an uncoded DOMException that carries nothing the synthetic
|
|
240
|
+
* error does not, so it keeps the "Request was aborted" text every transport
|
|
241
|
+
* already emits rather than churning it.
|
|
242
|
+
*/
|
|
243
|
+
function transportAbortError(signal) {
|
|
244
|
+
const reason = signal?.reason;
|
|
245
|
+
return reason instanceof Error && typeof reason.code === "string" ? reason : /* @__PURE__ */ new Error("Request was aborted");
|
|
246
|
+
}
|
|
247
|
+
const providerAcceptanceObserver = Symbol("openclaw.providerAcceptanceObserver");
|
|
248
|
+
function readProviderAcceptanceObserver(options) {
|
|
249
|
+
if (options === null || typeof options !== "object") return;
|
|
250
|
+
const descriptor = Object.getOwnPropertyDescriptor(options, providerAcceptanceObserver);
|
|
251
|
+
const value = descriptor && "value" in descriptor ? descriptor.value : void 0;
|
|
252
|
+
return isProviderAcceptanceObserver(value) ? value : void 0;
|
|
253
|
+
}
|
|
254
|
+
function isProviderAcceptanceObserver(value) {
|
|
255
|
+
return typeof value === "function";
|
|
256
|
+
}
|
|
257
|
+
function writeProviderAcceptanceObserver(options, observer) {
|
|
258
|
+
Object.defineProperty(options, providerAcceptanceObserver, {
|
|
259
|
+
configurable: true,
|
|
260
|
+
enumerable: true,
|
|
261
|
+
value: observer
|
|
262
|
+
});
|
|
263
|
+
return options;
|
|
264
|
+
}
|
|
265
|
+
/** Attach an OpenClaw-internal provider acceptance observer to one model call. */
|
|
266
|
+
function withProviderAcceptanceObserver(options, observer) {
|
|
267
|
+
const existing = readProviderAcceptanceObserver(options);
|
|
268
|
+
return writeProviderAcceptanceObserver(options, existing ? (acceptance) => {
|
|
269
|
+
observer(acceptance);
|
|
270
|
+
existing(acceptance);
|
|
271
|
+
} : observer);
|
|
272
|
+
}
|
|
273
|
+
/** Preserve the private provider acceptance observer when a built-in wrapper rebuilds options. */
|
|
274
|
+
function copyProviderAcceptanceObserver(source, target) {
|
|
275
|
+
const observer = readProviderAcceptanceObserver(source);
|
|
276
|
+
return observer ? writeProviderAcceptanceObserver(target, observer) : target;
|
|
277
|
+
}
|
|
278
|
+
async function awaitProviderLifecycleCallback(callback, signal) {
|
|
279
|
+
if (signal?.aborted) throw transportAbortError(signal);
|
|
280
|
+
if (!callback) return;
|
|
281
|
+
const callbackPromise = Promise.resolve().then(callback);
|
|
282
|
+
if (!signal) {
|
|
283
|
+
await callbackPromise;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
let onAbort;
|
|
287
|
+
try {
|
|
288
|
+
await Promise.race([callbackPromise, new Promise((_resolve, reject) => {
|
|
289
|
+
onAbort = () => reject(transportAbortError(signal));
|
|
290
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
291
|
+
})]);
|
|
292
|
+
} finally {
|
|
293
|
+
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
294
|
+
}
|
|
295
|
+
if (signal.aborted) throw transportAbortError(signal);
|
|
296
|
+
}
|
|
297
|
+
function startProviderStreamCancellation(cancelStream, error) {
|
|
298
|
+
const reason = error instanceof Error ? error : new Error(String(error));
|
|
299
|
+
try {
|
|
300
|
+
Promise.resolve(cancelStream(reason)).catch(() => void 0);
|
|
301
|
+
} catch {}
|
|
302
|
+
}
|
|
303
|
+
async function awaitProviderLifecycleWithCleanup(params) {
|
|
304
|
+
try {
|
|
305
|
+
await params.run();
|
|
306
|
+
} catch (error) {
|
|
307
|
+
startProviderStreamCancellation(params.cancelStream, error);
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/** Report observed HTTP metadata; rejected responses use only onResponse. */
|
|
312
|
+
async function notifyProviderHttpMetadata(params) {
|
|
313
|
+
const observer = readProviderAcceptanceObserver(params.options);
|
|
314
|
+
if (!observer && !params.options?.onResponse) return;
|
|
315
|
+
const { status, headers } = params.response;
|
|
316
|
+
const signal = params.signal ?? params.options?.signal;
|
|
317
|
+
const accepted = status >= 200 && status < 300;
|
|
318
|
+
await awaitProviderLifecycleWithCleanup({
|
|
319
|
+
cancelStream: params.cancelStream,
|
|
320
|
+
run: async () => {
|
|
321
|
+
await awaitProviderLifecycleCallback(accepted && observer ? () => observer({
|
|
322
|
+
kind: "http_response",
|
|
323
|
+
status,
|
|
324
|
+
headers
|
|
325
|
+
}) : void 0, signal);
|
|
326
|
+
await awaitProviderLifecycleCallback(params.options?.onResponse ? () => params.options?.onResponse?.({
|
|
327
|
+
status,
|
|
328
|
+
headers
|
|
329
|
+
}, params.model) : void 0, signal);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/** Report a real HTTP response before body consumption. */
|
|
334
|
+
async function notifyProviderHttpResponse(params) {
|
|
335
|
+
await notifyProviderHttpMetadata({
|
|
336
|
+
options: params.options,
|
|
337
|
+
response: {
|
|
338
|
+
status: params.response.status,
|
|
339
|
+
headers: headersToRecord(params.response.headers)
|
|
340
|
+
},
|
|
341
|
+
model: params.model,
|
|
342
|
+
signal: params.signal,
|
|
343
|
+
cancelStream: (reason) => {
|
|
344
|
+
if (params.cancelStream) startProviderStreamCancellation(params.cancelStream, reason);
|
|
345
|
+
return params.response.body?.cancel(reason);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
/** Report an accepted SDK stream when the SDK does not expose HTTP metadata. */
|
|
350
|
+
async function notifyProviderStreamOpened(params) {
|
|
351
|
+
const observer = readProviderAcceptanceObserver(params.options);
|
|
352
|
+
if (!observer) return;
|
|
353
|
+
await awaitProviderLifecycleWithCleanup({
|
|
354
|
+
cancelStream: params.cancelStream,
|
|
355
|
+
run: () => awaitProviderLifecycleCallback(() => observer({ kind: "provider_stream_opened" }), params.signal ?? params.options?.signal)
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
/** Run a provider-response hook before start/body consumption inside the first-event deadline. */
|
|
359
|
+
function withProviderResponseHook(params) {
|
|
360
|
+
return { async *[Symbol.asyncIterator]() {
|
|
361
|
+
try {
|
|
362
|
+
await awaitProviderLifecycleCallback(params.hook, params.signal);
|
|
363
|
+
} catch (error) {
|
|
364
|
+
params.abort(error instanceof Error ? error : new Error(String(error)));
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
if (params.signal.aborted) throw transportAbortError(params.signal);
|
|
368
|
+
params.onReady?.();
|
|
369
|
+
if (params.stream) yield* params.stream;
|
|
370
|
+
} };
|
|
371
|
+
}
|
|
372
|
+
function finalizeTransportStream(params) {
|
|
373
|
+
const { stream, output, signal } = params;
|
|
374
|
+
if (signal?.aborted) throw transportAbortError(signal);
|
|
375
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
376
|
+
stream.push({
|
|
377
|
+
type: "done",
|
|
378
|
+
reason: output.stopReason,
|
|
379
|
+
message: output
|
|
380
|
+
});
|
|
381
|
+
stream.end();
|
|
382
|
+
}
|
|
383
|
+
/** @deprecated Use projectProviderError. v2026.7.2-beta.5 compatibility; remove after 2026.10. */
|
|
384
|
+
function assignTransportErrorDetails(output, error, signal) {
|
|
385
|
+
const projection = projectProviderError(error, signal);
|
|
386
|
+
Object.assign(output, projection);
|
|
387
|
+
return projection;
|
|
388
|
+
}
|
|
389
|
+
function failTransportStream(params) {
|
|
390
|
+
const { stream, output, signal, error, cleanup } = params;
|
|
391
|
+
cleanup?.();
|
|
392
|
+
const projection = assignTransportErrorDetails(output, error, signal);
|
|
393
|
+
stream.push({
|
|
394
|
+
type: "error",
|
|
395
|
+
reason: projection.stopReason,
|
|
396
|
+
error: output
|
|
397
|
+
});
|
|
398
|
+
stream.end();
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region packages/ai/src/providers/simple-options.ts
|
|
402
|
+
function buildBaseOptions(model, options, apiKey) {
|
|
403
|
+
const firstEventOptions = options;
|
|
404
|
+
return copyProviderAcceptanceObserver(options, {
|
|
405
|
+
temperature: options?.temperature,
|
|
406
|
+
maxTokens: options?.maxTokens,
|
|
407
|
+
stop: options?.stop,
|
|
408
|
+
signal: options?.signal,
|
|
409
|
+
apiKey: apiKey || options?.apiKey,
|
|
410
|
+
transport: options?.transport,
|
|
411
|
+
cacheRetention: options?.cacheRetention,
|
|
412
|
+
sessionId: options?.sessionId,
|
|
413
|
+
promptCacheKey: options?.promptCacheKey,
|
|
414
|
+
headers: options?.headers,
|
|
415
|
+
onPayload: options?.onPayload,
|
|
416
|
+
onResponse: options?.onResponse,
|
|
417
|
+
timeoutMs: options?.timeoutMs,
|
|
418
|
+
firstEventTimeoutMs: firstEventOptions?.firstEventTimeoutMs,
|
|
419
|
+
onFirstEventTimeout: firstEventOptions?.onFirstEventTimeout,
|
|
420
|
+
maxRetries: options?.maxRetries,
|
|
421
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
422
|
+
metadata: options?.metadata
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
function clampMaxTokensToModel(model, requestedMaxTokens) {
|
|
426
|
+
return requestedMaxTokens === void 0 ? void 0 : Math.max(1, Math.min(requestedMaxTokens, model.maxTokens));
|
|
427
|
+
}
|
|
428
|
+
function clampReasoning(effort) {
|
|
429
|
+
return effort === "xhigh" ? "high" : effort;
|
|
430
|
+
}
|
|
431
|
+
function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
|
|
432
|
+
const budgets = {
|
|
433
|
+
minimal: 1024,
|
|
434
|
+
low: 2048,
|
|
435
|
+
medium: 8192,
|
|
436
|
+
high: 16384,
|
|
437
|
+
max: 32768,
|
|
438
|
+
...customBudgets
|
|
439
|
+
};
|
|
440
|
+
const minOutputTokens = 1024;
|
|
441
|
+
let thinkingBudget = budgets[clampReasoning(reasoningLevel)];
|
|
442
|
+
const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
|
|
443
|
+
if (maxTokens <= thinkingBudget) thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
|
|
444
|
+
return {
|
|
445
|
+
maxTokens,
|
|
446
|
+
thinkingBudget
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
450
|
+
export { splitSystemPromptCacheBoundary as A, withProviderResponseHook as C, SYSTEM_PROMPT_CACHE_BOUNDARY as D, quoteUnsafeIntegerLiterals as E, normalizePromptCapabilityIds as M, normalizeStructuredPromptSection as N, ensureSystemPromptCacheBoundary as O, sortPromptCacheToolsByName as P, withProviderAcceptanceObserver as S, parseJsonPreservingUnsafeIntegers as T, notifyProviderStreamOpened as _, assignTransportErrorDetails as a, sanitizeTransportPayloadText as b, createEmptyTransportUsage as c, finalizeTerminalToolCallArguments as d, finalizeTransportStream as f, notifyProviderHttpResponse as g, notifyProviderHttpMetadata as h, clampReasoning as i, stripSystemPromptCacheBoundary as j, prependSystemPromptAdditionAfterCacheBoundary as k, createWritableTransportEventStream as l, mergeTransportMetadata as m, buildBaseOptions as n, coerceTransportToolCallArguments as o, mergeTransportHeaders as p, clampMaxTokensToModel as r, copyProviderAcceptanceObserver as s, adjustMaxTokensForThinking as t, failTransportStream as u, parseTerminalToolCallArguments as v, parseJsonObjectPreservingUnsafeIntegers as w, transportAbortError as x, sanitizeNonEmptyTransportPayloadText as y };
|
package/dist/{tool-schema-json-projection-q5d7QX5c.mjs → tool-schema-json-projection-FEr-jOoZ.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getAiTransportHost } from "./host-
|
|
1
|
+
import { n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
|
|
2
2
|
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
3
3
|
import { types } from "node:util";
|
|
4
4
|
//#region packages/ai/src/transports/host-policy.ts
|
|
@@ -8,14 +8,23 @@ function buildGuardedModelFetch(model, timeoutMs, options) {
|
|
|
8
8
|
if (timeoutMs !== void 0) return host.buildModelFetch(model, timeoutMs) ?? globalThis.fetch;
|
|
9
9
|
return host.buildModelFetch(model) ?? globalThis.fetch;
|
|
10
10
|
}
|
|
11
|
-
function resolveProviderEndpoint(
|
|
12
|
-
return { endpointClass: getAiTransportHost().
|
|
11
|
+
function resolveProviderEndpoint(model) {
|
|
12
|
+
return { endpointClass: getAiTransportHost().resolveProviderRequestCapabilities({
|
|
13
|
+
baseUrl: model.baseUrl,
|
|
14
|
+
model
|
|
15
|
+
}).endpointClass };
|
|
13
16
|
}
|
|
14
|
-
function resolveProviderRequestCapabilities(input) {
|
|
15
|
-
return getAiTransportHost().resolveProviderRequestCapabilities(
|
|
17
|
+
function resolveProviderRequestCapabilities(input, model) {
|
|
18
|
+
return getAiTransportHost().resolveProviderRequestCapabilities({
|
|
19
|
+
...input,
|
|
20
|
+
model
|
|
21
|
+
});
|
|
16
22
|
}
|
|
17
|
-
function resolveProviderRequestPolicyConfig(input) {
|
|
18
|
-
return { headers: getAiTransportHost().resolveProviderRequestHeaders(
|
|
23
|
+
function resolveProviderRequestPolicyConfig(model, input) {
|
|
24
|
+
return { headers: getAiTransportHost().resolveProviderRequestHeaders({
|
|
25
|
+
...input,
|
|
26
|
+
model
|
|
27
|
+
}) };
|
|
19
28
|
}
|
|
20
29
|
function resolveModelRequestTimeoutMs(model, timeoutMs) {
|
|
21
30
|
return timeoutMs ?? getAiTransportHost().resolveModelRequestTimeoutMs(model);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as normalizeOptionalString } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
-
import { n as getAiTransportHost } from "./host-
|
|
2
|
+
import { n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
|
|
3
3
|
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
4
4
|
import { a as parseStrictFiniteNumber, n as asFiniteNumberInRange, o as parseStrictNonNegativeInteger } from "./number-coercion-H9qHik3g.mjs";
|
|
5
5
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|