@openclaw/ai 2026.7.2-beta.7 → 2026.8.1-beta.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-CH4UUnZr.mjs → anthropic-B6dLpq5L.mjs} +55 -203
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/anthropic-compaction-replay-8lJNKXOE.mjs +840 -0
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-BP6AWT8j.d.mts} +4 -1
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-uSMZJ3FA.mjs} +26 -5
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CtSg0iTS.mjs → google-C7h2QzDX.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-B0Qr9OR7.mjs} +146 -89
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-Bhc3TjDl.mjs} +11 -7
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/host-DTqNc7ad.mjs +466 -0
- package/dist/{host-B9GUmcra.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +29 -5
- 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 +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -5
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-CWmpvWYh.mjs → mistral-CEWoQI_g.mjs} +45 -48
- package/dist/number-coercion-H9qHik3g.mjs +71 -0
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +284 -240
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-BPnt4Sml.mjs} +65 -99
- package/dist/{openai-completions-compat-DBWjXoMZ.d.mts → openai-completions-compat-Dt3dcawL.d.mts} +2 -2
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-DhIKtOup.mjs} +18 -41
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/openai-responses-prompt-observer-internal-DgNTYnRY.mjs +46 -0
- package/dist/{openai-responses-stream-internal-Cw5txaGW.mjs → openai-responses-shared-DXIt3iY5.mjs} +1406 -940
- package/dist/{openai-reasoning-compat-YgeLncHw.mjs → openai-stop-reason-BkFkqqK0.mjs} +204 -37
- package/dist/openai-tool-projection-CY04OcvQ.mjs +338 -0
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-D8bB3z9b.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -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-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/sanitize-unicode-BYqrYtC_.mjs +90 -0
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +32 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +166 -241
- package/dist/transports.mjs +1979 -1825
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-bzp5k29J.d.mts → types-BHNrPS1l.d.mts} +23 -1
- package/dist/types.d.mts +4 -4
- 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-B-j7cOYp.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/anthropic-usage-DWU-x8MI.mjs +0 -459
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/host-Dog2WQiR.mjs +0 -369
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +0 -392
- package/dist/openai-tool-projection-OhX64DoP.mjs +0 -215
- package/dist/provider-error-CAEvRjry.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/tool-result-text-CTpIRbYd.mjs +0 -225
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
- package/dist/transport-stream-shared-D81p90xq.mjs +0 -297
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, o as resolveClaudeFable5ModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-JsNA5KCu.mjs";
|
|
2
|
+
import "./src-D2H6yKkH.mjs";
|
|
3
|
+
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
4
|
+
import { i as clampThinkingLevel, t as sanitizeSurrogates } from "./sanitize-unicode-BYqrYtC_.mjs";
|
|
5
|
+
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
6
|
+
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
7
|
+
//#region packages/ai/src/providers/anthropic-model-contract.ts
|
|
8
|
+
const ANTHROPIC_CLAUDE_CODE_VERSION = "2.1.75";
|
|
9
|
+
const ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK = `x-anthropic-billing-header: cc_version=${ANTHROPIC_CLAUDE_CODE_VERSION}; cc_entrypoint=sdk-cli;`;
|
|
10
|
+
function normalizeModelId(modelId) {
|
|
11
|
+
const normalized = normalizeLowercaseStringOrEmpty(modelId);
|
|
12
|
+
return (normalized.startsWith("anthropic/") ? normalized.slice(10) : normalized).replace(/[._\s]+/g, "-");
|
|
13
|
+
}
|
|
14
|
+
function normalizeApi(api) {
|
|
15
|
+
const normalized = normalizeLowercaseStringOrEmpty(api);
|
|
16
|
+
return normalized === "openclaw-anthropic-messages-transport" ? "anthropic-messages" : normalized;
|
|
17
|
+
}
|
|
18
|
+
function hasConcreteResponseModel(ref) {
|
|
19
|
+
const responseModelId = normalizeModelId(ref.responseModelId);
|
|
20
|
+
return responseModelId.length > 0 && responseModelId !== normalizeModelId(ref.modelId);
|
|
21
|
+
}
|
|
22
|
+
function usesClaudeFable5MessagesContract(model) {
|
|
23
|
+
return normalizeApi(model.api) === "anthropic-messages" && resolveClaudeFable5ModelIdentity(model) !== void 0;
|
|
24
|
+
}
|
|
25
|
+
/** Return whether streamed output must wait for the terminal refusal decision. */
|
|
26
|
+
function usesClaudeStreamingRefusalContract(model) {
|
|
27
|
+
if (normalizeApi(model.api) !== "anthropic-messages") return false;
|
|
28
|
+
return resolveClaudeFable5ModelIdentity(model) !== void 0 || resolveClaudeMythos5ModelIdentity(model) !== void 0 || resolveClaudeOpus5ModelIdentity(model) !== void 0 || resolveClaudeSonnet5ModelIdentity(model) !== void 0;
|
|
29
|
+
}
|
|
30
|
+
function requiresClaudeAdaptiveThinking(model) {
|
|
31
|
+
if (normalizeApi(model.api) !== "anthropic-messages") return false;
|
|
32
|
+
return requiresClaudeMandatoryAdaptiveThinking(model);
|
|
33
|
+
}
|
|
34
|
+
/** Return whether omitted thinking should default to adaptive/high. */
|
|
35
|
+
function defaultsClaudeAdaptiveThinking(model) {
|
|
36
|
+
return requiresClaudeAdaptiveThinking(model) || normalizeApi(model.api) === "anthropic-messages" && (resolveClaudeOpus5ModelIdentity(model) !== void 0 || resolveClaudeSonnet5ModelIdentity(model) !== void 0);
|
|
37
|
+
}
|
|
38
|
+
/** Resolve provider-native effort once for direct and managed Claude requests. */
|
|
39
|
+
function resolveAnthropicThinkingEffort(model, level) {
|
|
40
|
+
const requestedLevel = level;
|
|
41
|
+
const thinkingLevelMap = resolveClaudeNativeThinkingLevelMap(model);
|
|
42
|
+
const clampModel = {
|
|
43
|
+
...model,
|
|
44
|
+
...typeof model.params?.canonicalModelId === "string" ? { reasoning: true } : {},
|
|
45
|
+
...thinkingLevelMap ? { thinkingLevelMap } : {}
|
|
46
|
+
};
|
|
47
|
+
const resolvedLevel = requestedLevel ? clampThinkingLevel(clampModel, requestedLevel) : void 0;
|
|
48
|
+
const mapped = resolvedLevel ? thinkingLevelMap?.[resolvedLevel] : void 0;
|
|
49
|
+
if (typeof mapped === "string") return mapped;
|
|
50
|
+
switch (resolvedLevel) {
|
|
51
|
+
case "off":
|
|
52
|
+
case "minimal":
|
|
53
|
+
case "low": return "low";
|
|
54
|
+
case "medium": return "medium";
|
|
55
|
+
case "xhigh": return supportsClaudeNativeXhighEffort(model) ? "xhigh" : "high";
|
|
56
|
+
case "max": return supportsClaudeNativeMaxEffort(model) ? "max" : "high";
|
|
57
|
+
default: return "high";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Normalize Anthropic and Anthropic-compatible terminal reasons identically. */
|
|
61
|
+
function mapAnthropicStopReason(reason) {
|
|
62
|
+
switch (reason) {
|
|
63
|
+
case "end_turn":
|
|
64
|
+
case "pause_turn":
|
|
65
|
+
case "compaction":
|
|
66
|
+
case "stop_sequence": return "stop";
|
|
67
|
+
case "max_tokens": return "length";
|
|
68
|
+
case "tool_use": return "toolUse";
|
|
69
|
+
case "refusal":
|
|
70
|
+
case "sensitive": return "error";
|
|
71
|
+
default: throw new Error(`Unhandled stop reason: ${String(reason)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Remove unsupported assistant prefills while preserving completed tool-use turns. */
|
|
75
|
+
function prepareClaudeNoPrefillRequestContext(model, context) {
|
|
76
|
+
if (!resolveClaudeOpus5ModelIdentity(model) && !resolveClaudeSonnet5ModelIdentity(model)) return context;
|
|
77
|
+
let end = context.messages.length;
|
|
78
|
+
while (end > 0) {
|
|
79
|
+
const message = context.messages[end - 1];
|
|
80
|
+
if (message?.role !== "assistant" || Array.isArray(message.content) && message.content.some((block) => block.type === "toolCall")) break;
|
|
81
|
+
end -= 1;
|
|
82
|
+
}
|
|
83
|
+
return end === context.messages.length ? context : {
|
|
84
|
+
...context,
|
|
85
|
+
messages: context.messages.slice(0, end)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function applyClaudeRequestContract(params, model) {
|
|
89
|
+
if (normalizeApi(model.api) !== "anthropic-messages") return;
|
|
90
|
+
const opus5 = resolveClaudeOpus5ModelIdentity(model) !== void 0;
|
|
91
|
+
const sonnet5 = resolveClaudeSonnet5ModelIdentity(model) !== void 0;
|
|
92
|
+
if (!requiresClaudeDefaultSampling(model) && !opus5 && !sonnet5) return;
|
|
93
|
+
delete params.temperature;
|
|
94
|
+
delete params.top_p;
|
|
95
|
+
delete params.top_k;
|
|
96
|
+
if (opus5 || sonnet5) delete params.service_tier;
|
|
97
|
+
}
|
|
98
|
+
function resolveReplayModelBoundIdentity(ref) {
|
|
99
|
+
if (normalizeApi(ref.api) !== "anthropic-messages") return;
|
|
100
|
+
const modelRef = hasConcreteResponseModel(ref) ? { id: ref.responseModelId } : {
|
|
101
|
+
id: ref.modelId,
|
|
102
|
+
params: ref.modelParams
|
|
103
|
+
};
|
|
104
|
+
const fableIdentity = resolveClaudeFable5ModelIdentity(modelRef);
|
|
105
|
+
if (fableIdentity) return `fable:${fableIdentity}`;
|
|
106
|
+
const mythosIdentity = resolveClaudeMythos5ModelIdentity(modelRef);
|
|
107
|
+
if (mythosIdentity) return `mythos:${mythosIdentity}`;
|
|
108
|
+
const opusIdentity = resolveClaudeOpus5ModelIdentity(modelRef);
|
|
109
|
+
if (opusIdentity) return `opus:${opusIdentity}`;
|
|
110
|
+
const sonnetIdentity = resolveClaudeSonnet5ModelIdentity(modelRef);
|
|
111
|
+
return sonnetIdentity ? `sonnet:${sonnetIdentity}` : void 0;
|
|
112
|
+
}
|
|
113
|
+
function resolveModelBoundThinkingReplayMode(params) {
|
|
114
|
+
const sourceApi = normalizeApi(params.source.api);
|
|
115
|
+
const targetApi = normalizeApi(params.target.api);
|
|
116
|
+
const sourceIdentity = resolveReplayModelBoundIdentity(params.source);
|
|
117
|
+
const targetIdentity = resolveReplayModelBoundIdentity(params.target);
|
|
118
|
+
const sameRoute = normalizeLowercaseStringOrEmpty(params.source.provider) === normalizeLowercaseStringOrEmpty(params.target.provider) && sourceApi === targetApi && normalizeModelId(params.source.modelId) === normalizeModelId(params.target.modelId);
|
|
119
|
+
if (!sourceIdentity && !targetIdentity) return "default";
|
|
120
|
+
if (!sourceIdentity && !hasConcreteResponseModel(params.source) && targetIdentity && sameRoute) return "preserve";
|
|
121
|
+
return sourceApi === targetApi && sourceIdentity === targetIdentity ? "preserve" : "drop";
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region packages/ai/src/providers/tool-result-text.ts
|
|
125
|
+
const PROVIDER_TOOL_RESULT_MAX_CHARS = 8e3;
|
|
126
|
+
const IMAGE_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([
|
|
127
|
+
"image",
|
|
128
|
+
"image_url",
|
|
129
|
+
"input_image"
|
|
130
|
+
]);
|
|
131
|
+
const AUDIO_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([
|
|
132
|
+
"audio",
|
|
133
|
+
"input_audio",
|
|
134
|
+
"output_audio"
|
|
135
|
+
]);
|
|
136
|
+
const MEDIA_ONLY_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([...IMAGE_TOOL_RESULT_TYPES, ...AUDIO_TOOL_RESULT_TYPES]);
|
|
137
|
+
const INLINE_DATA_URI_PATTERN = /(^|[^A-Za-z0-9_])data:([a-z][a-z0-9.+-]*\/[a-z0-9.+-]+(?:;[a-z0-9.+-]+=[^,;"'\s]+|;base64)*,[^\s"'<>)]+)/gi;
|
|
138
|
+
const MIME_KEY_CANDIDATES = [
|
|
139
|
+
"mimeType",
|
|
140
|
+
"mime_type",
|
|
141
|
+
"mediaType",
|
|
142
|
+
"media_type",
|
|
143
|
+
"contentType",
|
|
144
|
+
"content_type"
|
|
145
|
+
];
|
|
146
|
+
const TEXTUAL_MIME_PATTERN = /^(?:text\/|application\/(?:json|ld\+json|x-ndjson|xml|javascript|x-www-form-urlencoded)|[^/]+\/[^+]+\+(?:json|xml)$)/i;
|
|
147
|
+
const OPAQUE_OR_BINARY_FIELD_RE = /^(?:blob|buffer|bytes|encrypted_content|encrypted_stdout)$/i;
|
|
148
|
+
function readMimeType(value) {
|
|
149
|
+
if (!isRecord(value)) return;
|
|
150
|
+
for (const key of MIME_KEY_CANDIDATES) {
|
|
151
|
+
const mimeType = value[key];
|
|
152
|
+
if (typeof mimeType === "string" && mimeType.trim().length > 0) return mimeType;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function isBinaryMimeType(mimeType) {
|
|
156
|
+
const normalized = mimeType.split(";", 1)[0]?.trim().toLowerCase();
|
|
157
|
+
return normalized ? !TEXTUAL_MIME_PATTERN.test(normalized) : false;
|
|
158
|
+
}
|
|
159
|
+
function describeOmittedValue(value, label) {
|
|
160
|
+
const length = typeof value === "string" ? value.length : JSON.stringify(value)?.length;
|
|
161
|
+
return length ? `[${label} omitted: ${length} chars]` : `[${label} omitted]`;
|
|
162
|
+
}
|
|
163
|
+
function redactInlineDataUris(value) {
|
|
164
|
+
return value.replace(INLINE_DATA_URI_PATTERN, (_match, prefix, uri) => `${prefix}[inline data URI: ${uri.length} chars]`);
|
|
165
|
+
}
|
|
166
|
+
function redactStructuredTextValue(value) {
|
|
167
|
+
const host = getAiTransportHost();
|
|
168
|
+
const redacted = host.redactToolPayloadText(value);
|
|
169
|
+
const trimmed = redacted.trim();
|
|
170
|
+
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return redacted;
|
|
171
|
+
try {
|
|
172
|
+
const redactedWrapper = host.redactSecrets({ structuredTextValue: JSON.parse(redacted) });
|
|
173
|
+
return JSON.stringify(redactedWrapper.structuredTextValue);
|
|
174
|
+
} catch {
|
|
175
|
+
return redacted;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function stringifyStructuredBlock(block) {
|
|
179
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
180
|
+
try {
|
|
181
|
+
const redactedBlock = getAiTransportHost().redactSecrets({ structuredToolResult: block }).structuredToolResult;
|
|
182
|
+
const serialized = JSON.stringify(redactedBlock, function structuredToolResultReplacer(key, value) {
|
|
183
|
+
if (OPAQUE_OR_BINARY_FIELD_RE.test(key)) return `[omitted ${key}]`;
|
|
184
|
+
if (key === "data") {
|
|
185
|
+
const mimeType = readMimeType(this);
|
|
186
|
+
if (mimeType && isBinaryMimeType(mimeType)) return describeOmittedValue(value, "binary data");
|
|
187
|
+
}
|
|
188
|
+
if (typeof value === "bigint") return value.toString();
|
|
189
|
+
if (typeof value === "string") return redactInlineDataUris(redactStructuredTextValue(value));
|
|
190
|
+
if (typeof value === "function" || typeof value === "symbol" || value === void 0) return;
|
|
191
|
+
if (!value || typeof value !== "object") return value;
|
|
192
|
+
if (seen.has(value)) return "[Circular]";
|
|
193
|
+
seen.add(value);
|
|
194
|
+
return value;
|
|
195
|
+
});
|
|
196
|
+
if (!serialized || serialized === "{}") return;
|
|
197
|
+
return serialized;
|
|
198
|
+
} catch {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function truncateProviderToolText(text) {
|
|
203
|
+
if (text.length <= PROVIDER_TOOL_RESULT_MAX_CHARS) return text;
|
|
204
|
+
return `${truncateUtf16Safe(text, PROVIDER_TOOL_RESULT_MAX_CHARS)}\n…(truncated)…`;
|
|
205
|
+
}
|
|
206
|
+
/** Media metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
207
|
+
function hasMediaPayload(block) {
|
|
208
|
+
return isRecord(block) && typeof block.data === "string" && block.data.trim().length > 0;
|
|
209
|
+
}
|
|
210
|
+
/** Image metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
211
|
+
function isImageWithMediaPayload(block) {
|
|
212
|
+
return isRecord(block) && block.type === "image" && hasMediaPayload(block);
|
|
213
|
+
}
|
|
214
|
+
function describeToolResultMediaPlaceholder(blocks) {
|
|
215
|
+
let hasImage = false;
|
|
216
|
+
let hasAudio = false;
|
|
217
|
+
for (const block of blocks) {
|
|
218
|
+
if (!hasMediaPayload(block)) continue;
|
|
219
|
+
const record = block;
|
|
220
|
+
const type = typeof record.type === "string" ? record.type : void 0;
|
|
221
|
+
const mimeType = readMimeType(record);
|
|
222
|
+
if (type && IMAGE_TOOL_RESULT_TYPES.has(type) || mimeType?.toLowerCase().startsWith("image/")) hasImage = true;
|
|
223
|
+
if (type && AUDIO_TOOL_RESULT_TYPES.has(type) || mimeType?.toLowerCase().startsWith("audio/")) hasAudio = true;
|
|
224
|
+
}
|
|
225
|
+
if (hasImage && hasAudio) return "(see attached media)";
|
|
226
|
+
if (hasAudio) return "(see attached audio)";
|
|
227
|
+
if (hasImage) return "(see attached image)";
|
|
228
|
+
}
|
|
229
|
+
function extractToolResultBlockText(block) {
|
|
230
|
+
if (!block || typeof block !== "object") return;
|
|
231
|
+
const record = block;
|
|
232
|
+
if (typeof record.type === "string" && MEDIA_ONLY_TOOL_RESULT_TYPES.has(record.type)) return;
|
|
233
|
+
if (record.type === "text") {
|
|
234
|
+
const text = typeof record.text === "string" ? record.text : "";
|
|
235
|
+
return text ? sanitizeSurrogates(text) : void 0;
|
|
236
|
+
}
|
|
237
|
+
const structured = stringifyStructuredBlock(record);
|
|
238
|
+
return structured ? sanitizeSurrogates(truncateProviderToolText(structured)) : void 0;
|
|
239
|
+
}
|
|
240
|
+
function extractToolResultText(blocks) {
|
|
241
|
+
const explicitTexts = [];
|
|
242
|
+
const structuredTexts = [];
|
|
243
|
+
for (const block of blocks) {
|
|
244
|
+
const text = extractToolResultBlockText(block);
|
|
245
|
+
if (!text) continue;
|
|
246
|
+
if (block.type === "text") explicitTexts.push(text);
|
|
247
|
+
else structuredTexts.push(text);
|
|
248
|
+
}
|
|
249
|
+
if (explicitTexts.length > 0) return sanitizeSurrogates(explicitTexts.join("\n"));
|
|
250
|
+
return sanitizeSurrogates(truncateProviderToolText(structuredTexts.join("\n")));
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region packages/ai/src/transcript-transform.ts
|
|
254
|
+
const NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
|
|
255
|
+
const NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
|
|
256
|
+
function replaceImagesWithPlaceholder(content, placeholder) {
|
|
257
|
+
const result = [];
|
|
258
|
+
for (const block of content) {
|
|
259
|
+
if (block.type !== "image") {
|
|
260
|
+
result.push(block);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const previous = result.at(-1);
|
|
264
|
+
const repeated = previous?.type === "text" && previous.text === placeholder;
|
|
265
|
+
if (isImageWithMediaPayload(block) && !repeated) result.push({
|
|
266
|
+
type: "text",
|
|
267
|
+
text: placeholder
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
function downgradeUnsupportedImages(messages, model) {
|
|
273
|
+
if (model.input.includes("image")) return messages;
|
|
274
|
+
return messages.map((message) => {
|
|
275
|
+
if (message.role === "assistant" || typeof message.content === "string") return message;
|
|
276
|
+
const placeholder = message.role === "user" ? NON_VISION_USER_IMAGE_PLACEHOLDER : NON_VISION_TOOL_IMAGE_PLACEHOLDER;
|
|
277
|
+
return {
|
|
278
|
+
...message,
|
|
279
|
+
content: replaceImagesWithPlaceholder(message.content, placeholder)
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function transformAssistant(message, model, toolCallIdMap, normalizeToolCallId) {
|
|
284
|
+
const replayMode = resolveModelBoundThinkingReplayMode({
|
|
285
|
+
source: {
|
|
286
|
+
provider: message.provider,
|
|
287
|
+
api: message.api,
|
|
288
|
+
modelId: message.model,
|
|
289
|
+
responseModelId: message.responseModel
|
|
290
|
+
},
|
|
291
|
+
target: {
|
|
292
|
+
provider: model.provider,
|
|
293
|
+
api: model.api,
|
|
294
|
+
modelId: model.id,
|
|
295
|
+
modelParams: model.params
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
const sameModel = replayMode === "preserve" || message.provider === model.provider && message.api === model.api && message.model === model.id;
|
|
299
|
+
const content = (typeof message.content === "string" ? [{
|
|
300
|
+
type: "text",
|
|
301
|
+
text: message.content
|
|
302
|
+
}] : message.content).flatMap((block) => {
|
|
303
|
+
if (block.type === "thinking") {
|
|
304
|
+
if (replayMode === "drop") return [];
|
|
305
|
+
if (block.redacted) return sameModel ? block : [];
|
|
306
|
+
if (sameModel && block.thinkingSignature) return block;
|
|
307
|
+
if (!block.thinking?.trim()) return [];
|
|
308
|
+
return sameModel ? block : {
|
|
309
|
+
type: "text",
|
|
310
|
+
text: block.thinking
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
if (block.type === "text") return sameModel ? block : {
|
|
314
|
+
type: "text",
|
|
315
|
+
text: block.text
|
|
316
|
+
};
|
|
317
|
+
const { thoughtSignature: _, ...unsigned } = block;
|
|
318
|
+
const trimmedId = block.id.trim();
|
|
319
|
+
if (sameModel) return trimmedId === block.id ? block : Object.assign({}, block, { id: trimmedId });
|
|
320
|
+
const id = normalizeToolCallId?.(trimmedId, model, message) ?? trimmedId;
|
|
321
|
+
if (id !== trimmedId) toolCallIdMap.set(trimmedId, id);
|
|
322
|
+
return id === block.id ? unsigned : Object.assign({}, unsigned, { id });
|
|
323
|
+
});
|
|
324
|
+
return {
|
|
325
|
+
...message,
|
|
326
|
+
content
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function transformMessages(messages, model, normalizeToolCallId) {
|
|
330
|
+
const toolCallIdMap = /* @__PURE__ */ new Map();
|
|
331
|
+
const transformed = downgradeUnsupportedImages(messages.map((message) => message.content == null ? Object.assign({}, message, { content: [] }) : message), model).map((message) => {
|
|
332
|
+
if (message.role === "assistant") return transformAssistant(message, model, toolCallIdMap, normalizeToolCallId);
|
|
333
|
+
if (message.role !== "toolResult") return message;
|
|
334
|
+
const trimmedId = message.toolCallId.trim();
|
|
335
|
+
const toolCallId = toolCallIdMap.get(trimmedId) ?? trimmedId;
|
|
336
|
+
return toolCallId === message.toolCallId ? message : Object.assign({}, message, { toolCallId });
|
|
337
|
+
});
|
|
338
|
+
const result = [];
|
|
339
|
+
let pendingToolCalls = [];
|
|
340
|
+
let existingToolResultIds = /* @__PURE__ */ new Set();
|
|
341
|
+
const flushToolCalls = () => {
|
|
342
|
+
for (const call of pendingToolCalls) if (!existingToolResultIds.has(call.id)) result.push({
|
|
343
|
+
role: "toolResult",
|
|
344
|
+
toolCallId: call.id,
|
|
345
|
+
toolName: call.name,
|
|
346
|
+
content: [{
|
|
347
|
+
type: "text",
|
|
348
|
+
text: "No result provided"
|
|
349
|
+
}],
|
|
350
|
+
isError: true,
|
|
351
|
+
timestamp: Date.now()
|
|
352
|
+
});
|
|
353
|
+
pendingToolCalls = [];
|
|
354
|
+
existingToolResultIds = /* @__PURE__ */ new Set();
|
|
355
|
+
};
|
|
356
|
+
for (const message of transformed) {
|
|
357
|
+
if (message.role === "assistant") {
|
|
358
|
+
flushToolCalls();
|
|
359
|
+
if (message.stopReason === "error" || message.stopReason === "aborted") continue;
|
|
360
|
+
pendingToolCalls = message.content.filter((block) => block.type === "toolCall");
|
|
361
|
+
} else if (message.role === "toolResult") existingToolResultIds.add(message.toolCallId);
|
|
362
|
+
else flushToolCalls();
|
|
363
|
+
result.push(message);
|
|
364
|
+
}
|
|
365
|
+
flushToolCalls();
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region packages/ai/src/host.ts
|
|
370
|
+
const MAX_PENDING_CUSTOM_API_REGISTRATIONS = 32;
|
|
371
|
+
const pendingCustomApiRegistrations = [];
|
|
372
|
+
function queueCustomApiRegistration(registry, api, streamFn) {
|
|
373
|
+
const existing = pendingCustomApiRegistrations.find((registration) => registration.registry === registry && registration.api === api);
|
|
374
|
+
if (existing) {
|
|
375
|
+
existing.streamFn = streamFn;
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
if (pendingCustomApiRegistrations.length >= MAX_PENDING_CUSTOM_API_REGISTRATIONS) throw new Error("Too many custom transport APIs were registered before host configuration");
|
|
379
|
+
pendingCustomApiRegistrations.push({
|
|
380
|
+
registry,
|
|
381
|
+
api,
|
|
382
|
+
streamFn
|
|
383
|
+
});
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
const inertAiTransportHost = {
|
|
387
|
+
buildModelFetch: () => void 0,
|
|
388
|
+
resolveSecretSentinel: (value) => value,
|
|
389
|
+
redactSecrets: (value) => value,
|
|
390
|
+
redactToolPayloadText: (text) => text,
|
|
391
|
+
normalizeAnthropicInlineContentBlocks: async (content) => [...content],
|
|
392
|
+
resolveOpenAIStrictToolSetting: (_model, options) => options?.supportsStrictMode ? false : void 0,
|
|
393
|
+
plugin: {
|
|
394
|
+
resolveProviderStream: () => void 0,
|
|
395
|
+
resolveTransportTurnState: () => void 0,
|
|
396
|
+
wrapSimpleCompletionStream: () => void 0,
|
|
397
|
+
createAnthropicVertexStream: () => {
|
|
398
|
+
throw new Error("Anthropic Vertex transport is not configured by the embedding host");
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
buildCopilotDynamicHeaders: () => ({}),
|
|
402
|
+
resolveProviderEndpointClass: () => "default",
|
|
403
|
+
resolveProviderRequestCapabilities: () => ({
|
|
404
|
+
endpointClass: "default",
|
|
405
|
+
knownProviderFamily: "",
|
|
406
|
+
supportsNativeStreamingUsageCompat: false,
|
|
407
|
+
supportsOpenAICompletionsStreamingUsageCompat: false,
|
|
408
|
+
usesExplicitProxyLikeEndpoint: false,
|
|
409
|
+
allowsAnthropicServiceTier: false
|
|
410
|
+
}),
|
|
411
|
+
resolveProviderRequestHeaders: ({ providerHeaders, callerHeaders, precedence }) => ({
|
|
412
|
+
...precedence === "caller-wins" ? providerHeaders : callerHeaders,
|
|
413
|
+
...precedence === "caller-wins" ? callerHeaders : providerHeaders
|
|
414
|
+
}),
|
|
415
|
+
resolveModelRequestTimeoutMs: () => void 0,
|
|
416
|
+
requiresManagedTransport: () => false,
|
|
417
|
+
inheritManagedTransport: (_source, target) => target,
|
|
418
|
+
transformTransportMessages: (messages, model, normalizeToolCallId) => transformMessages(messages, model, normalizeToolCallId),
|
|
419
|
+
registerCustomApi: queueCustomApiRegistration,
|
|
420
|
+
logDebug: () => {},
|
|
421
|
+
logInfo: () => {},
|
|
422
|
+
logWarn: () => {}
|
|
423
|
+
};
|
|
424
|
+
let activeAiTransportHost = inertAiTransportHost;
|
|
425
|
+
/** Installs host implementations for the transport policy ports. */
|
|
426
|
+
function configureAiTransportHost(host) {
|
|
427
|
+
activeAiTransportHost = {
|
|
428
|
+
...inertAiTransportHost,
|
|
429
|
+
...host,
|
|
430
|
+
normalizeAnthropicInlineContentBlocks: host.normalizeAnthropicInlineContentBlocks ?? inertAiTransportHost.normalizeAnthropicInlineContentBlocks,
|
|
431
|
+
plugin: {
|
|
432
|
+
...inertAiTransportHost.plugin,
|
|
433
|
+
...host.plugin
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const transportHost = activeAiTransportHost;
|
|
437
|
+
if (transportHost.registerCustomApi === inertAiTransportHost.registerCustomApi || pendingCustomApiRegistrations.length === 0) return;
|
|
438
|
+
const pending = pendingCustomApiRegistrations.splice(0);
|
|
439
|
+
for (const [index, registration] of pending.entries()) try {
|
|
440
|
+
transportHost.registerCustomApi(registration.registry, registration.api, registration.streamFn);
|
|
441
|
+
} catch (error) {
|
|
442
|
+
pendingCustomApiRegistrations.unshift(...pending.slice(index));
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/** Returns the active transport host (inert defaults unless configured). */
|
|
447
|
+
function getAiTransportHost() {
|
|
448
|
+
return activeAiTransportHost;
|
|
449
|
+
}
|
|
450
|
+
/** Resolves sentinel substrings in custom headers at a no-fetch adapter boundary. */
|
|
451
|
+
function resolveAiTransportHeaderSentinels(headers) {
|
|
452
|
+
if (!headers) return;
|
|
453
|
+
const host = getAiTransportHost();
|
|
454
|
+
let resolvedHeaders;
|
|
455
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
456
|
+
if (value === null) continue;
|
|
457
|
+
const resolved = host.resolveSecretSentinel(value);
|
|
458
|
+
if (resolved !== value) {
|
|
459
|
+
resolvedHeaders ??= { ...headers };
|
|
460
|
+
resolvedHeaders[name] = resolved;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return resolvedHeaders ?? headers;
|
|
464
|
+
}
|
|
465
|
+
//#endregion
|
|
466
|
+
export { resolveAnthropicThinkingEffort as _, describeToolResultMediaPlaceholder as a, usesClaudeStreamingRefusalContract as b, hasMediaPayload as c, ANTHROPIC_CLAUDE_CODE_VERSION as d, applyClaudeRequestContract as f, requiresClaudeAdaptiveThinking as g, prepareClaudeNoPrefillRequestContext as h, transformMessages as i, isImageWithMediaPayload as l, mapAnthropicStopReason as m, getAiTransportHost as n, extractToolResultBlockText as o, defaultsClaudeAdaptiveThinking as p, resolveAiTransportHeaderSentinels as r, extractToolResultText as s, configureAiTransportHost as t, ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK as u, resolveModelBoundThinkingReplayMode as v, usesClaudeFable5MessagesContract as y };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as ApiRegistry } from "./api-registry-
|
|
1
|
+
import { B as StreamFn, E as Model, n as Api, u as Context } from "./types-BHNrPS1l.mjs";
|
|
2
|
+
import { n as ApiRegistry } from "./api-registry-k3zTz0cV.mjs";
|
|
3
3
|
|
|
4
4
|
//#region packages/ai/src/host.d.ts
|
|
5
5
|
/** Provider capability facts needed by the package-owned transports. */
|
|
@@ -29,6 +29,8 @@ interface AiProviderStreamHookContext {
|
|
|
29
29
|
provider: string;
|
|
30
30
|
modelId: string;
|
|
31
31
|
model: Model;
|
|
32
|
+
/** Wire-format API before simple completion projects an internal transport alias. */
|
|
33
|
+
sourceApi?: Api;
|
|
32
34
|
}
|
|
33
35
|
/** Narrow plugin-runtime port used by package-owned transports. */
|
|
34
36
|
interface AiTransportPluginHost {
|
|
@@ -59,6 +61,10 @@ interface AiTransportPluginHost {
|
|
|
59
61
|
}): {
|
|
60
62
|
headers?: Record<string, string>;
|
|
61
63
|
metadata?: Record<string, string>;
|
|
64
|
+
websocket?: {
|
|
65
|
+
headers?: Record<string, string>;
|
|
66
|
+
degradeCooldownMs?: number;
|
|
67
|
+
};
|
|
62
68
|
} | undefined;
|
|
63
69
|
wrapSimpleCompletionStream(this: void, params: {
|
|
64
70
|
provider: string;
|
|
@@ -77,6 +83,7 @@ type AiTransformTransportMessages = (messages: Context["messages"], model: Model
|
|
|
77
83
|
}) => string, options?: {
|
|
78
84
|
normalizeSameModelToolCallIds?: boolean;
|
|
79
85
|
preserveCrossModelToolCallThoughtSignature?: boolean;
|
|
86
|
+
preserveUnframedToolResults?: boolean;
|
|
80
87
|
}) => Context["messages"];
|
|
81
88
|
/** Strict-tool policy inputs for OpenAI-compatible routes. */
|
|
82
89
|
interface OpenAIStrictToolSettingOptions {
|
|
@@ -145,8 +152,6 @@ interface AiTransportHost {
|
|
|
145
152
|
transformTransportMessages: AiTransformTransportMessages;
|
|
146
153
|
/** Registers a custom transport API with the host's stream error bridge. */
|
|
147
154
|
registerCustomApi(registry: ApiRegistry, api: Api, streamFn: StreamFn): boolean;
|
|
148
|
-
/** Prepares the provider-owned Google simple-completion alias when needed. */
|
|
149
|
-
prepareGoogleSimpleCompletionModel(registry: ApiRegistry, model: Model): Model;
|
|
150
155
|
/**
|
|
151
156
|
* Emits one transport diagnostic; build runs only when the host logs it and
|
|
152
157
|
* may return null to suppress the entry (e.g. de-duplication).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, f as supportsClaude1MContext, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, m as supportsClaudeFastMode, n as CLAUDE_OPUS_5_THINKING_PROFILE, o as resolveClaudeFable5ModelIdentity, p as supportsClaudeAdaptiveThinking, r as CLAUDE_SONNET_5_THINKING_PROFILE, s as resolveClaudeModelIdentity, t as CLAUDE_FABLE_5_THINKING_PROFILE, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-SrGtwsJu.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-
|
|
6
|
-
import { a as RegisteredApiProvider, i as ApiStreamSimpleFunction, n as ApiRegistry, o as createApiRegistry, r as ApiStreamFunction, t as ApiProvider } from "./api-registry-
|
|
7
|
-
import { a as AiProviderRequestPolicyInput, c as AiTransportHost, d as configureAiTransportHost, f as getAiTransportHost, i as AiProviderRequestCapabilities, l as AiTransportPluginHost, n as AiInlineImageBlock, o as AiProviderStreamHookContext, p as resolveAiTransportHeaderSentinels, r as AiInlineTextBlock, s as AiTransformTransportMessages, t as AiInlineContentBlock, u as OpenAIStrictToolSettingOptions } from "./host-
|
|
3
|
+
import { $ as Usage, A as OpenRouterRouting, B as StreamFn, C as KnownImagesProvider, D as ModelThinkingLevel, E as Model, F as ProviderReplayState, G as ThinkingBudgets, H as StreamOptions, I as ProviderResponse, J as ThinkingLevelMap, K as ThinkingContent, L as ProviderStreamOptions, M as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, N as Provider, O as OpenAICompletionsCompat, P as ProviderImagesOptions, Q as Transport, R as SimpleStreamOptions, S as KnownImagesApi, T as Message, U as TextContent, V as StreamFunction, W as TextSignatureV1, X as ToolCall, Y as Tool, Z as ToolResultMessage, _ as ImagesOptions, a as AssistantMessageEvent, b as ImagesStopReason, c as CacheRetention, d as ImageContent, et as UserMessage, f as ImagesApi, g as ImagesModel, h as ImagesInputContent, i as AssistantMessage, j as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, k as OpenAIResponsesCompat, l as CompleteSimpleFn, m as ImagesFunction, n as Api, nt as VercelGatewayRouting, o as AssistantMessageEventStreamContract, p as ImagesContext, q as ThinkingLevel, r as AssistantImages, s as AssistantMessageEventStreamLike, t as AnthropicMessagesCompat, tt as ValidateToolArgumentsFn, u as Context, v as ImagesOutputContent, w as MaybePromise, x as KnownApi, y as ImagesProvider, z as StopReason } from "./types-BHNrPS1l.mjs";
|
|
4
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-BP6AWT8j.mjs";
|
|
5
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-DT9SrFn3.mjs";
|
|
6
|
+
import { a as RegisteredApiProvider, i as ApiStreamSimpleFunction, n as ApiRegistry, o as createApiRegistry, r as ApiStreamFunction, t as ApiProvider } from "./api-registry-k3zTz0cV.mjs";
|
|
7
|
+
import { a as AiProviderRequestPolicyInput, c as AiTransportHost, d as configureAiTransportHost, f as getAiTransportHost, i as AiProviderRequestCapabilities, l as AiTransportPluginHost, n as AiInlineImageBlock, o as AiProviderStreamHookContext, p as resolveAiTransportHeaderSentinels, r as AiInlineTextBlock, s as AiTransformTransportMessages, t as AiInlineContentBlock, u as OpenAIStrictToolSettingOptions } from "./host-vWgMMhiJ.mjs";
|
|
8
8
|
|
|
9
9
|
//#region packages/ai/src/stream.d.ts
|
|
10
10
|
/** Creates an isolated LLM runtime backed by the supplied provider registry. */
|
|
@@ -23,4 +23,4 @@ declare function createLlmRuntime(registry?: ApiRegistry): {
|
|
|
23
23
|
};
|
|
24
24
|
type LlmRuntime = ReturnType<typeof createLlmRuntime>;
|
|
25
25
|
//#endregion
|
|
26
|
-
export { AiInlineContentBlock, AiInlineImageBlock, AiInlineTextBlock, AiProviderRequestCapabilities, AiProviderRequestPolicyInput, AiProviderStreamHookContext, AiTransformTransportMessages, AiTransportHost, AiTransportPluginHost, AnthropicMessagesCompat, Api, ApiProvider, ApiRegistry, ApiStreamFunction, ApiStreamSimpleFunction, AssistantImages, AssistantMessage, AssistantMessageDiagnostic, AssistantMessageEvent, AssistantMessageEventStream, AssistantMessageEventStreamContract, AssistantMessageEventStreamLike, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, CacheRetention, CompleteSimpleFn, Context, DiagnosticErrorInfo, EventStream, ImageContent, ImagesApi, ImagesContext, ImagesFunction, ImagesInputContent, ImagesModel, ImagesOptions, ImagesOutputContent, ImagesProvider, ImagesStopReason, KnownApi, KnownImagesApi, KnownImagesProvider, LlmRuntime, MaybePromise, Message, Model, ModelThinkingLevel, OpenAICompletionsCompat, OpenAIResponsesCompat, OpenAIStrictToolSettingOptions, OpenRouterRouting, Provider, ProviderImagesOptions, ProviderResponse, ProviderStreamOptions, RegisteredApiProvider, SimpleStreamOptions, StopReason, StreamFn, StreamFunction, StreamOptions, TextContent, TextSignatureV1, ThinkingBudgets, ThinkingContent, ThinkingLevel, ThinkingLevelMap, Tool, ToolCall, ToolResultMessage, Transport, Usage, UserMessage, ValidateToolArgumentsFn, VercelGatewayRouting, appendAssistantMessageDiagnostic, configureAiTransportHost, createApiRegistry, createAssistantMessageDiagnostic, createAssistantMessageEventStream, createLlmRuntime, extractDiagnosticError, formatThrownValue, getAiTransportHost, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAiTransportHeaderSentinels, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
26
|
+
export { AiInlineContentBlock, AiInlineImageBlock, AiInlineTextBlock, AiProviderRequestCapabilities, AiProviderRequestPolicyInput, AiProviderStreamHookContext, AiTransformTransportMessages, AiTransportHost, AiTransportPluginHost, AnthropicMessagesCompat, Api, ApiProvider, ApiRegistry, ApiStreamFunction, ApiStreamSimpleFunction, AssistantImages, AssistantMessage, AssistantMessageDiagnostic, AssistantMessageEvent, AssistantMessageEventStream, AssistantMessageEventStreamContract, AssistantMessageEventStreamLike, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, CacheRetention, CompleteSimpleFn, Context, DiagnosticErrorInfo, EventStream, ImageContent, ImagesApi, ImagesContext, ImagesFunction, ImagesInputContent, ImagesModel, ImagesOptions, ImagesOutputContent, ImagesProvider, ImagesStopReason, KnownApi, KnownImagesApi, KnownImagesProvider, LlmRuntime, MaybePromise, Message, Model, ModelThinkingLevel, OpenAICompletionsCompat, OpenAIResponsesCompat, OpenAIStrictToolSettingOptions, OpenRouterRouting, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, Provider, ProviderImagesOptions, ProviderReplayState, ProviderResponse, ProviderStreamOptions, RegisteredApiProvider, SimpleStreamOptions, StopReason, StreamFn, StreamFunction, StreamOptions, TextContent, TextSignatureV1, ThinkingBudgets, ThinkingContent, ThinkingLevel, ThinkingLevelMap, Tool, ToolCall, ToolResultMessage, Transport, Usage, UserMessage, ValidateToolArgumentsFn, VercelGatewayRouting, appendAssistantMessageDiagnostic, configureAiTransportHost, createApiRegistry, createAssistantMessageDiagnostic, createAssistantMessageEventStream, createLlmRuntime, extractDiagnosticError, formatThrownValue, getAiTransportHost, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAiTransportHeaderSentinels, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, f as supportsClaude1MContext, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, m as supportsClaudeFastMode, n as CLAUDE_OPUS_5_THINKING_PROFILE, o as resolveClaudeFable5ModelIdentity, p as supportsClaudeAdaptiveThinking, r as CLAUDE_SONNET_5_THINKING_PROFILE, s as resolveClaudeModelIdentity, t as CLAUDE_FABLE_5_THINKING_PROFILE, u as resolveClaudeOpus5ModelIdentity } from "./
|
|
1
|
+
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, f as supportsClaude1MContext, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, m as supportsClaudeFastMode, n as CLAUDE_OPUS_5_THINKING_PROFILE, o as resolveClaudeFable5ModelIdentity, p as supportsClaudeAdaptiveThinking, r as CLAUDE_SONNET_5_THINKING_PROFILE, s as resolveClaudeModelIdentity, t as CLAUDE_FABLE_5_THINKING_PROFILE, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-JsNA5KCu.mjs";
|
|
2
|
+
import { n as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, t as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE } from "./types-BDdaOVi2.mjs";
|
|
2
3
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-COpOtRwq.mjs";
|
|
3
|
-
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import { n as validateToolCall, t as validateToolArguments } from "./validation-
|
|
4
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
5
|
+
import { n as validateToolCall, t as validateToolArguments } from "./validation-B61OhAio.mjs";
|
|
6
|
+
import "./src-D2H6yKkH.mjs";
|
|
5
7
|
import { n as createApiRegistry, t as createLlmRuntime } from "./stream-CREqxHgU.mjs";
|
|
6
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels, t as configureAiTransportHost } from "./host-
|
|
7
|
-
export { AssistantMessageEventStream, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, EventStream, appendAssistantMessageDiagnostic, configureAiTransportHost, createApiRegistry, createAssistantMessageDiagnostic, createAssistantMessageEventStream, createLlmRuntime, extractDiagnosticError, formatThrownValue, getAiTransportHost, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAiTransportHeaderSentinels, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
8
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels, t as configureAiTransportHost } from "./host-DTqNc7ad.mjs";
|
|
9
|
+
export { AssistantMessageEventStream, CLAUDE_FABLE_5_THINKING_PROFILE, CLAUDE_OPUS_5_THINKING_PROFILE, CLAUDE_SONNET_5_THINKING_PROFILE, EventStream, PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, appendAssistantMessageDiagnostic, configureAiTransportHost, createApiRegistry, createAssistantMessageDiagnostic, createAssistantMessageEventStream, createLlmRuntime, extractDiagnosticError, formatThrownValue, getAiTransportHost, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAiTransportHeaderSentinels, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, supportsClaude1MContext, supportsClaudeAdaptiveThinking, supportsClaudeFastMode, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, validateToolArguments, validateToolCall };
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, o as resolveClaudeFable5ModelIdentity, p as supportsClaudeAdaptiveThinking, s as resolveClaudeModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "../anthropic-SrGtwsJu.mjs";
|
|
2
2
|
import { t as AssistantMessageDiagnostic } from "../diagnostics-BaTA9eVl.mjs";
|
|
3
|
-
import { E as Model,
|
|
4
|
-
import { n as AnthropicOptions, r as AnthropicThinkingDisplay, t as AnthropicEffort } from "../provider-options-
|
|
3
|
+
import { $ as Usage, E as Model, R as SimpleStreamOptions, V as StreamFunction, u as Context, z as StopReason } from "../types-BHNrPS1l.mjs";
|
|
4
|
+
import { n as AnthropicOptions, r as AnthropicThinkingDisplay, t as AnthropicEffort } from "../provider-options-B96RdNpH.mjs";
|
|
5
|
+
import { o as resolveAnthropicServerCompactionPlan } from "../anthropic-payload-policy-CiEuQS72.mjs";
|
|
6
|
+
|
|
5
7
|
//#region packages/ai/src/providers/anthropic.d.ts
|
|
6
|
-
|
|
8
|
+
type AnthropicCompactionOptions = AnthropicOptions & {
|
|
9
|
+
anthropicServerCompaction?: boolean;
|
|
10
|
+
authProfileId?: string;
|
|
11
|
+
};
|
|
12
|
+
declare const streamAnthropic: StreamFunction<"anthropic-messages", AnthropicCompactionOptions>;
|
|
7
13
|
type AnthropicSimpleStreamOptions = SimpleStreamOptions & {
|
|
8
|
-
|
|
14
|
+
anthropicServerCompaction?: boolean;
|
|
15
|
+
authProfileId?: string;
|
|
16
|
+
toolChoice?: AnthropicCompactionOptions["toolChoice"];
|
|
9
17
|
};
|
|
10
18
|
declare const streamSimpleAnthropic: StreamFunction<"anthropic-messages", AnthropicSimpleStreamOptions>;
|
|
11
19
|
//#endregion
|
|
@@ -19,6 +27,8 @@ declare function usesFoundryBearerAuth(model: AnthropicAuthModel): boolean;
|
|
|
19
27
|
declare function omitFoundryBearerCredentialHeaders(headers?: Record<string, string>): Record<string, string> | undefined;
|
|
20
28
|
//#endregion
|
|
21
29
|
//#region packages/ai/src/providers/anthropic-model-contract.d.ts
|
|
30
|
+
declare const ANTHROPIC_CLAUDE_CODE_VERSION = "2.1.75";
|
|
31
|
+
declare const ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK = "x-anthropic-billing-header: cc_version=2.1.75; cc_entrypoint=sdk-cli;";
|
|
22
32
|
type ReplayModelRef = {
|
|
23
33
|
provider?: string;
|
|
24
34
|
api?: string;
|
|
@@ -48,6 +58,10 @@ declare function defaultsClaudeAdaptiveThinking(model: {
|
|
|
48
58
|
params?: Record<string, unknown>;
|
|
49
59
|
api?: string;
|
|
50
60
|
}): boolean;
|
|
61
|
+
/** Resolve provider-native effort once for direct and managed Claude requests. */
|
|
62
|
+
declare function resolveAnthropicThinkingEffort(model: Model<"anthropic-messages">, level: SimpleStreamOptions["reasoning"]): AnthropicEffort;
|
|
63
|
+
/** Normalize Anthropic and Anthropic-compatible terminal reasons identically. */
|
|
64
|
+
declare function mapAnthropicStopReason(reason: string | undefined): StopReason;
|
|
51
65
|
/** Remove unsupported assistant prefills while preserving completed tool-use turns. */
|
|
52
66
|
declare function prepareClaudeNoPrefillRequestContext(model: Model, context: Context): Context;
|
|
53
67
|
declare function applyClaudeRequestContract(params: Record<string, unknown>, model: {
|
|
@@ -149,6 +163,12 @@ type AnthropicProjectedToolChoice = ({
|
|
|
149
163
|
readonly type: "tool";
|
|
150
164
|
readonly name: string;
|
|
151
165
|
} & AnthropicParallelToolChoice);
|
|
166
|
+
/** Preserve Claude Code's canonical tool casing for subscription OAuth requests. */
|
|
167
|
+
declare function toClaudeCodeToolName(name: string): string;
|
|
168
|
+
/** Anthropic rejects forced tools while extended thinking is enabled. */
|
|
169
|
+
declare function normalizeAnthropicToolChoice(thinkingEnabled: boolean, toolChoice: NonNullable<AnthropicOptions["toolChoice"]>): AnthropicProjectedToolChoice;
|
|
170
|
+
/** Anthropic tool identifiers accept only ASCII word characters and dashes. */
|
|
171
|
+
declare function normalizeAnthropicToolCallId(id: string): string;
|
|
152
172
|
/** Snapshots direct/custom tool descriptors before Anthropic payload construction. */
|
|
153
173
|
declare function projectAnthropicTools(tools: readonly AnthropicToolDescriptor[], toWireName: (name: string) => string): AnthropicToolProjection;
|
|
154
174
|
/** Keeps forced Anthropic tool choices aligned with the projected wire names. */
|
|
@@ -190,5 +210,9 @@ declare function readAnthropicUsageTokenCount(value: unknown): number | undefine
|
|
|
190
210
|
declare function readAnthropicCacheWriteUsage(usage: AnthropicUsagePayload): AnthropicCacheWriteUsage;
|
|
191
211
|
declare function readAnthropicPromptUsageSnapshot(usage: AnthropicUsagePayload): AnthropicPromptUsageSnapshot | undefined;
|
|
192
212
|
declare function readLastAnthropicIterationUsage(usage: AnthropicUsagePayload): AnthropicIterationUsageResult;
|
|
213
|
+
/** Record independent billing buckets without treating zero placeholders as context proof. */
|
|
214
|
+
declare function applyAnthropicMessageStartUsage(target: Usage, payload: AnthropicUsagePayload): AnthropicPromptUsageSnapshot | undefined;
|
|
215
|
+
/** Keep cumulative billing separate from the final server-side iteration context. */
|
|
216
|
+
declare function applyAnthropicMessageDeltaUsage(target: Usage, payload: AnthropicUsagePayload | undefined, messageStartPromptUsage: AnthropicPromptUsageSnapshot | undefined): void;
|
|
193
217
|
//#endregion
|
|
194
|
-
export { ANTHROPIC_OMITTED_REASONING_TEXT, ANTHROPIC_SERVER_SIDE_FALLBACKS, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, AnthropicCacheWriteUsage, type AnthropicEffort, AnthropicFallbackBoundary, AnthropicIterationUsageResult, AnthropicIterationUsageSnapshot, type AnthropicOptions, AnthropicProjectedToolChoice, AnthropicPromptUsageSnapshot, type AnthropicThinkingDisplay, AnthropicToolProjection, CLAUDE_OPUS_FALLBACK_MODEL_COST, applyAnthropicFallbackBoundary, applyAnthropicRefusal, applyClaudeRequestContract, defaultsClaudeAdaptiveThinking, findActiveAnthropicToolTurnAssistantIndex, omitFoundryBearerCredentialHeaders, prepareClaudeNoPrefillRequestContext, projectAnthropicTools, readAnthropicCacheWriteUsage, readAnthropicFallbackBoundary, readAnthropicPromptUsageSnapshot, readAnthropicUsageTokenCount, readLastAnthropicIterationUsage, reconcileAnthropicToolChoice, requiresClaudeAdaptiveThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAnthropicFallbackServingModelCost, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, resolveModelBoundThinkingReplayMode, resolveOriginalAnthropicToolName, streamAnthropic, streamSimpleAnthropic, supportsClaudeAdaptiveThinking, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, usesClaudeFable5MessagesContract, usesClaudeStreamingRefusalContract, usesFoundryBearerAuth };
|
|
218
|
+
export { ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, ANTHROPIC_CLAUDE_CODE_VERSION, ANTHROPIC_OMITTED_REASONING_TEXT, ANTHROPIC_SERVER_SIDE_FALLBACKS, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, AnthropicCacheWriteUsage, type AnthropicEffort, AnthropicFallbackBoundary, AnthropicIterationUsageResult, AnthropicIterationUsageSnapshot, type AnthropicOptions, AnthropicProjectedToolChoice, AnthropicPromptUsageSnapshot, type AnthropicThinkingDisplay, AnthropicToolProjection, CLAUDE_OPUS_FALLBACK_MODEL_COST, applyAnthropicFallbackBoundary, applyAnthropicMessageDeltaUsage, applyAnthropicMessageStartUsage, applyAnthropicRefusal, applyClaudeRequestContract, defaultsClaudeAdaptiveThinking, findActiveAnthropicToolTurnAssistantIndex, mapAnthropicStopReason, normalizeAnthropicToolCallId, normalizeAnthropicToolChoice, omitFoundryBearerCredentialHeaders, prepareClaudeNoPrefillRequestContext, projectAnthropicTools, readAnthropicCacheWriteUsage, readAnthropicFallbackBoundary, readAnthropicPromptUsageSnapshot, readAnthropicUsageTokenCount, readLastAnthropicIterationUsage, reconcileAnthropicToolChoice, requiresClaudeAdaptiveThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAnthropicFallbackServingModelCost, resolveAnthropicServerCompactionPlan, resolveAnthropicThinkingEffort, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, resolveModelBoundThinkingReplayMode, resolveOriginalAnthropicToolName, streamAnthropic, streamSimpleAnthropic, supportsClaudeAdaptiveThinking, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, toClaudeCodeToolName, usesClaudeFable5MessagesContract, usesClaudeStreamingRefusalContract, usesFoundryBearerAuth };
|