@openclaw/ai 2026.9.1 → 2026.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-hk7F7ptG.mjs → anthropic-BDdqdVLK.mjs} +208 -205
- package/dist/{anthropic-compaction-replay-OMJZ0uyo.mjs → anthropic-compaction-replay-DB2FGLQc.mjs} +130 -41
- package/dist/{anthropic-payload-policy-DBT1itQ-.d.mts → anthropic-payload-policy-d46X2pR0.d.mts} +27 -3
- package/dist/{api-registry-Cs6HGNqY.d.mts → api-registry-DWtPjzyn.d.mts} +2 -2
- package/dist/{azure-openai-responses-CN4Fy5zV.mjs → azure-openai-responses-C5bZRfAP.mjs} +5 -5
- package/dist/{diagnostics-KhXK-QJI.mjs → diagnostics-DfFyKeX_.mjs} +1 -1
- package/dist/diagnostics.mjs +2 -2
- package/dist/{event-stream-uSMZJ3FA.mjs → event-stream-BgDvQeum.mjs} +3 -9
- package/dist/{event-stream-vK_7r3bj.d.mts → event-stream-BhT5T1Ay.d.mts} +1 -1
- package/dist/event-stream-zctLx0yr.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CC-nrwXg.mjs → google-4qeuE8iX.mjs} +4 -4
- package/dist/{google-shared-CjPY0hZM.mjs → google-shared-CWeG8RIl.mjs} +7 -5
- package/dist/{google-vertex-DCr0pyzQ.mjs → google-vertex-O9BcnB6X.mjs} +4 -4
- package/dist/{host-BIaiBURL.mjs → host-CEvLw30U.mjs} +54 -9
- package/dist/{host-BztR4tQj.d.mts → host-DjzGmdZ2.d.mts} +3 -3
- package/dist/{index-AfaxKT8w.d.mts → index-FnHM2FcI.d.mts} +11 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +4 -4
- package/dist/internal/anthropic.d.mts +12 -9
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +1 -1
- package/dist/internal/openai.d.mts +7 -7
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/runtime.d.mts +5 -5
- package/dist/internal/runtime.mjs +3 -3
- package/dist/internal/shared.d.mts +2 -2
- package/dist/internal/shared.mjs +3 -3
- package/dist/{mistral-B7etBd_H.mjs → mistral-Tb6oalqH.mjs} +10 -8
- package/dist/{openai-chatgpt-responses-BAJ4gq3i.mjs → openai-chatgpt-responses-yUXjPNfu.mjs} +26 -28
- package/dist/{openai-completions-D0QZ0AyB.mjs → openai-completions-BIUV3RDT.mjs} +8 -8
- package/dist/{openai-completions-compat-4IjSBpr6.d.mts → openai-completions-compat-CpjYUArk.d.mts} +3 -3
- package/dist/{openai-completions-stream-DZjwK8vp.mjs → openai-completions-stream-BsrBe3Gg.mjs} +16 -16
- package/dist/openai-prompt-cache-CGnVB74a.mjs +21 -0
- package/dist/openai-prompt-cache-CNoIfHYC.d.mts +16 -0
- package/dist/{openai-responses-BEUlxfDu.mjs → openai-responses-CCL41ALM.mjs} +8 -11
- package/dist/{openai-responses-compaction-window-DO7yV7az.mjs → openai-responses-compaction-window-BMVHFOtq.mjs} +18 -7
- package/dist/{openai-responses-contracts-bPzSN_Ba.d.mts → openai-responses-contracts-rF5DDRNS.d.mts} +12 -4
- package/dist/{openai-responses-prompt-observer-internal-C7x4IK7r.mjs → openai-responses-prompt-observer-internal-D0bhBfgL.mjs} +3 -3
- package/dist/{openai-responses-shared-DiAdpNAM.mjs → openai-responses-shared-Bmma_3Qc.mjs} +185 -109
- package/dist/{openai-tool-schema-BMiHFH36.mjs → openai-tool-schema-_pTAJqKF.mjs} +20 -32
- package/dist/{provider-error-B6EGq6gg.mjs → provider-error-9TraxGvt.mjs} +6 -7
- package/dist/{provider-options-CxFPtvh7.d.mts → provider-options-Bcc_p-TU.d.mts} +18 -6
- package/dist/provider-replay-context-BuSUaAk5.mjs +21 -0
- package/dist/{provider-transcript-transform-WvJmFUAf.mjs → provider-transcript-transform-BaMbI1hr.mjs} +1 -1
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-C-4uedDb.mjs → reasoning-tag-text-partitioner-DLCNXki6.mjs} +72 -24
- package/dist/{sanitize-unicode-S6binQG-.mjs → sanitize-unicode-D6xUvZaS.mjs} +1 -1
- package/dist/{simple-options-0PLDyJ-d.mjs → simple-options-BjHCCh4v.mjs} +2 -2
- package/dist/{src-C8U7lkoa.mjs → src-2qBGKg8O.mjs} +9 -1
- package/dist/{tool-schema-json-projection-BtZiml7r.mjs → tool-schema-json-projection-mJhXDcyz.mjs} +1 -1
- package/dist/{transport-stream-shared-CytPVLIg.mjs → transport-stream-shared-CZqMhfIw.mjs} +4 -4
- package/dist/{transport-stream-shared-BrvFTkoO.d.mts → transport-stream-shared-xnaqxmbP.d.mts} +4 -4
- package/dist/{transport-utils-CtuS1Upe.mjs → transport-utils-7il795_9.mjs} +1 -1
- package/dist/transports.d.mts +11 -10
- package/dist/transports.mjs +567 -253
- package/dist/types-3Lnm-QSJ.d.mts +1 -0
- package/dist/{types-DbrhszyQ.d.mts → types-CJ1-Ht7A.d.mts} +29 -7
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +3 -3
- package/dist/{validation-BOwtcl9X.d.mts → validation-AKZBDGQd.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +2 -2
- package/dist/event-stream-DeDhbCc5.d.mts +0 -1
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/types-B5EFUmXs.d.mts +0 -1
package/dist/{anthropic-compaction-replay-OMJZ0uyo.mjs → anthropic-compaction-replay-DB2FGLQc.mjs}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as resolveClaudeModelIdentity, m as resolveClaudeOpus5ModelIdentity, u as resolveClaudeFable5ModelIdentity } from "./src-2qBGKg8O.mjs";
|
|
2
2
|
import { l as normalizeNullableString, o as isRecord, u as normalizeOptionalLowercaseString } from "./utf16-slice-qz3nsy87.mjs";
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
3
|
+
import { n as getAiTransportHost } from "./host-CEvLw30U.mjs";
|
|
4
4
|
import { a as asNonNegativeFiniteNumber, n as estimateBase64DecodedBytes } from "./base64-CEFBpSkN.mjs";
|
|
5
5
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
|
-
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, u as splitSystemPromptCacheBoundary } from "./simple-options-
|
|
7
|
-
import { a as resolveProviderEndpoint, o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-
|
|
8
|
-
import { s as parsePositiveInteger } from "./transport-utils-
|
|
9
|
-
import { t as
|
|
6
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, u as splitSystemPromptCacheBoundary } from "./simple-options-BjHCCh4v.mjs";
|
|
7
|
+
import { a as resolveProviderEndpoint, o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-mJhXDcyz.mjs";
|
|
8
|
+
import { s as parsePositiveInteger } from "./transport-utils-7il795_9.mjs";
|
|
9
|
+
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-BuSUaAk5.mjs";
|
|
10
10
|
//#region packages/ai/src/providers/anthropic-auth-headers.ts
|
|
11
11
|
/** Inspect resolved credential shape for auth routing without exposing its value. */
|
|
12
12
|
function isAnthropicOAuthApiKey(apiKey) {
|
|
@@ -47,15 +47,25 @@ function resolveAnthropicCompactThreshold(contextWindow, configured) {
|
|
|
47
47
|
}
|
|
48
48
|
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
49
49
|
function resolveAnthropicServerCompactionPlan(model, extraParams, apiKey) {
|
|
50
|
-
const
|
|
51
|
-
const api = normalizeOptionalLowercaseString(model.api);
|
|
52
|
-
const endpointClass = resolveProviderEndpoint(model).endpointClass;
|
|
53
|
-
const enabled = extraParams?.anthropicServerCompaction === true && !isAnthropicOAuthApiKey(apiKey) && provider === "anthropic" && api === "anthropic-messages" && (endpointClass === "default" || endpointClass === "anthropic-public");
|
|
50
|
+
const enabled = extraParams?.anthropicServerCompaction === true && !isAnthropicOAuthApiKey(apiKey) && normalizeOptionalLowercaseString(model.api) === "anthropic-messages" && isDirectAnthropicModel(model);
|
|
54
51
|
return {
|
|
55
52
|
enabled,
|
|
56
53
|
...enabled ? { threshold: resolveAnthropicCompactThreshold(model.contextWindow, extraParams?.anthropicCompactThreshold) } : {}
|
|
57
54
|
};
|
|
58
55
|
}
|
|
56
|
+
function isDirectAnthropicModel(model) {
|
|
57
|
+
const baseUrl = model.baseUrl?.trim() || process.env.ANTHROPIC_BASE_URL?.trim();
|
|
58
|
+
const endpointModel = baseUrl === model.baseUrl ? model : {
|
|
59
|
+
...model,
|
|
60
|
+
baseUrl
|
|
61
|
+
};
|
|
62
|
+
const endpointClass = resolveProviderEndpoint(endpointModel).endpointClass;
|
|
63
|
+
return normalizeOptionalLowercaseString(model.provider) === "anthropic" && (endpointClass === "anthropic-public" || endpointClass === "default" && (!baseUrl || resolveBaseUrlHostname(baseUrl) === "api.anthropic.com"));
|
|
64
|
+
}
|
|
65
|
+
function isAnthropicServerToolClearingEnabled(model, apiKey) {
|
|
66
|
+
const resolvedApiKey = apiKey && getAiTransportHost().resolveSecretSentinel(apiKey);
|
|
67
|
+
return Boolean(resolvedApiKey?.trim()) && !isAnthropicOAuthApiKey(resolvedApiKey) && normalizeOptionalLowercaseString(model.api) === "anthropic-messages" && isDirectAnthropicModel(model);
|
|
68
|
+
}
|
|
59
69
|
function resolveBaseUrlHostname(baseUrl) {
|
|
60
70
|
try {
|
|
61
71
|
return new URL(baseUrl).hostname;
|
|
@@ -182,21 +192,100 @@ function resolveAnthropicPayloadPolicy(input, model) {
|
|
|
182
192
|
cacheControl: input.enableCacheControl === true ? resolveAnthropicEphemeralCacheControl(input.baseUrl, input.cacheRetention) : void 0,
|
|
183
193
|
compactThreshold: serverCompactionPlan.threshold ?? resolveAnthropicCompactThreshold(input.contextWindow, input.extraParams?.anthropicCompactThreshold),
|
|
184
194
|
serviceTier: input.serviceTier,
|
|
185
|
-
useServerCompaction: input.enableServerCompaction === true && serverCompactionPlan.enabled
|
|
195
|
+
useServerCompaction: input.enableServerCompaction === true && serverCompactionPlan.enabled,
|
|
196
|
+
...input.cacheTtlPruning && normalizeOptionalLowercaseString(input.api) === "anthropic-messages" && isDirectAnthropicModel(input) ? { toolClearing: {
|
|
197
|
+
trigger: Math.max(5e4, Math.floor((parsePositiveInteger(input.contextWindow) ?? 0) * .3)),
|
|
198
|
+
clearAtLeast: Math.max(12500, Math.floor((parsePositiveInteger(input.contextWindow) ?? 0) * .05)),
|
|
199
|
+
tools: input.cacheTtlPruning.tools
|
|
200
|
+
} } : {}
|
|
186
201
|
};
|
|
187
202
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
203
|
+
function resolveToolClearingExclusions(payload, filter) {
|
|
204
|
+
const compile = (patterns) => (patterns ?? []).map((pattern) => pattern.trim().toLowerCase()).filter(Boolean).map((pattern) => new RegExp(`^${pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replaceAll("\\*", ".*")}$`));
|
|
205
|
+
const allow = compile(filter?.allow);
|
|
206
|
+
const deny = compile(filter?.deny);
|
|
207
|
+
if (allow.length === 0 && deny.length === 0) return [];
|
|
208
|
+
const excluded = new Set(filter?.deny?.map((name) => name.trim()).filter((name) => name && !name.includes("*")));
|
|
209
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
210
|
+
for (const tool of Array.isArray(payload.tools) ? payload.tools : []) if (isRecord(tool) && typeof tool.name === "string") candidates.add(tool.name);
|
|
211
|
+
for (const message of Array.isArray(payload.messages) ? payload.messages : []) {
|
|
212
|
+
if (!isRecord(message) || !Array.isArray(message.content)) continue;
|
|
213
|
+
for (const block of message.content) if (isRecord(block) && block.type === "tool_use" && typeof block.name === "string") candidates.add(block.name);
|
|
214
|
+
}
|
|
215
|
+
for (const toolName of candidates) {
|
|
216
|
+
const name = toolName.trim().toLowerCase();
|
|
217
|
+
if (deny.some((pattern) => pattern.test(name)) || allow.length > 0 && !allow.some((pattern) => pattern.test(name))) excluded.add(toolName);
|
|
218
|
+
}
|
|
219
|
+
return [...excluded].toSorted();
|
|
220
|
+
}
|
|
221
|
+
function applyAnthropicContextManagementEdits(payload, policy) {
|
|
222
|
+
if (payload.context_management !== void 0) return;
|
|
223
|
+
const edits = [];
|
|
224
|
+
if (policy.toolClearing) edits.push({
|
|
225
|
+
type: "clear_tool_uses_20250919",
|
|
226
|
+
trigger: {
|
|
227
|
+
type: "input_tokens",
|
|
228
|
+
value: policy.toolClearing.trigger
|
|
229
|
+
},
|
|
230
|
+
keep: {
|
|
231
|
+
type: "tool_uses",
|
|
232
|
+
value: 3
|
|
233
|
+
},
|
|
234
|
+
clear_at_least: {
|
|
235
|
+
type: "input_tokens",
|
|
236
|
+
value: policy.toolClearing.clearAtLeast
|
|
237
|
+
},
|
|
238
|
+
exclude_tools: resolveToolClearingExclusions(payload, policy.toolClearing.tools),
|
|
239
|
+
clear_tool_inputs: false
|
|
240
|
+
});
|
|
241
|
+
if (policy.useServerCompaction) edits.push({
|
|
194
242
|
type: "compact_20260112",
|
|
195
243
|
trigger: {
|
|
196
244
|
type: "input_tokens",
|
|
197
245
|
value: policy.compactThreshold
|
|
198
246
|
}
|
|
199
|
-
}
|
|
247
|
+
});
|
|
248
|
+
if (edits.length > 0) payload.context_management = { edits };
|
|
249
|
+
}
|
|
250
|
+
function applyAnthropicContextManagementToRequest(payload, model, options, directApiKeyBetaHeader) {
|
|
251
|
+
if (directApiKeyBetaHeader === void 0 || !options?.cacheTtlPruning && !options?.anthropicServerCompaction) return;
|
|
252
|
+
applyAnthropicContextManagementEdits(payload, resolveAnthropicPayloadPolicy({
|
|
253
|
+
...model,
|
|
254
|
+
api: "anthropic-messages",
|
|
255
|
+
enableServerCompaction: true,
|
|
256
|
+
extraParams: { ...options },
|
|
257
|
+
cacheTtlPruning: options?.cacheTtlPruning
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
function resolveAnthropicContextManagementBetaHeader(payload, directApiKeyBetaHeader) {
|
|
261
|
+
if (directApiKeyBetaHeader === void 0 || !isRecord(payload.context_management)) return directApiKeyBetaHeader;
|
|
262
|
+
const edits = payload.context_management.edits;
|
|
263
|
+
const betas = new Set(directApiKeyBetaHeader.split(",").map((beta) => beta.trim()).filter(Boolean));
|
|
264
|
+
for (const edit of Array.isArray(edits) ? edits : []) {
|
|
265
|
+
if (!isRecord(edit)) continue;
|
|
266
|
+
if (edit.type === "clear_tool_uses_20250919") betas.add("context-management-2025-06-27");
|
|
267
|
+
else if (edit.type === "compact_20260112") betas.add("compact-2026-01-12");
|
|
268
|
+
}
|
|
269
|
+
return [...betas].join(",");
|
|
270
|
+
}
|
|
271
|
+
function logAnthropicContextEdits(event) {
|
|
272
|
+
if (!isRecord(event) || !isRecord(event.context_management)) return;
|
|
273
|
+
const edits = event.context_management.applied_edits;
|
|
274
|
+
let clearedTools = 0;
|
|
275
|
+
let clearedTokens = 0;
|
|
276
|
+
for (const edit of Array.isArray(edits) ? edits : []) {
|
|
277
|
+
if (!isRecord(edit) || edit.type !== "clear_tool_uses_20250919" || typeof edit.cleared_tool_uses !== "number" || !Number.isSafeInteger(edit.cleared_tool_uses) || edit.cleared_tool_uses < 0 || typeof edit.cleared_input_tokens !== "number" || !Number.isSafeInteger(edit.cleared_input_tokens) || edit.cleared_input_tokens < 0) continue;
|
|
278
|
+
clearedTools = Math.min(Number.MAX_SAFE_INTEGER, clearedTools + edit.cleared_tool_uses);
|
|
279
|
+
clearedTokens = Math.min(Number.MAX_SAFE_INTEGER, clearedTokens + edit.cleared_input_tokens);
|
|
280
|
+
}
|
|
281
|
+
if (clearedTools > 0 || clearedTokens > 0) getAiTransportHost().logInfo("anthropic", `server-side context edit: cleared ${clearedTools} tool results (${clearedTokens} input tokens)`);
|
|
282
|
+
}
|
|
283
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
284
|
+
function applyAnthropicPayloadPolicyToParams(payloadObj, policy, cacheBreakpointOptOutMessageIndexes) {
|
|
285
|
+
if (policy.allowsServiceTier && policy.serviceTier !== void 0 && payloadObj.service_tier === void 0) payloadObj.service_tier = policy.serviceTier;
|
|
286
|
+
if (policy.cacheControl) applyAnthropicCacheControlToSystem(payloadObj.system, policy.cacheControl);
|
|
287
|
+
else stripAnthropicSystemPromptBoundary(payloadObj.system);
|
|
288
|
+
applyAnthropicContextManagementEdits(payloadObj, policy);
|
|
200
289
|
if (!policy.cacheControl) return;
|
|
201
290
|
const usedMarkers = countAnthropicCacheControlMarkers(payloadObj.system) + countAnthropicCacheControlMarkers(payloadObj.tools);
|
|
202
291
|
applyAnthropicCacheControlToMessages(payloadObj.messages, policy.cacheControl, ANTHROPIC_CACHE_CONTROL_LIMIT - usedMarkers, cacheBreakpointOptOutMessageIndexes);
|
|
@@ -366,6 +455,23 @@ function applyAnthropicFallbackBoundary(params) {
|
|
|
366
455
|
//#endregion
|
|
367
456
|
//#region packages/ai/src/providers/anthropic-thinking-replay.ts
|
|
368
457
|
const ANTHROPIC_OMITTED_REASONING_TEXT = "[assistant reasoning omitted]";
|
|
458
|
+
function applyAnthropicThinkingBindingControls(params, directApiKeyBetaHeader) {
|
|
459
|
+
if (directApiKeyBetaHeader === void 0 || !isRecord(params.thinking) || params.thinking.type !== "adaptive") return;
|
|
460
|
+
params.thinking.block_binding = { prefix_mismatch_behavior: "drop_block" };
|
|
461
|
+
const betas = directApiKeyBetaHeader.split(",").map((beta) => beta.trim()).filter(Boolean);
|
|
462
|
+
return { "anthropic-beta": [.../* @__PURE__ */ new Set([...betas, "thinking-binding-controls-2026-08-01"])].join(",") };
|
|
463
|
+
}
|
|
464
|
+
function readAnthropicInputTransformations(event) {
|
|
465
|
+
if (!isRecord(event) || event.type !== "message_start" && event.type !== "message_delta") return;
|
|
466
|
+
const transformations = (isRecord(event.message) ? event.message : void 0)?.input_transformations ?? event.input_transformations;
|
|
467
|
+
return Array.isArray(transformations) ? transformations : void 0;
|
|
468
|
+
}
|
|
469
|
+
function logAnthropicThinkingDrops(transformations) {
|
|
470
|
+
const drops = transformations?.filter((entry) => isRecord(entry) && entry.type === "thinking_dropped" && typeof entry.reason === "string" && /^(?:prefix|model|organization|end_user)_binding_mismatch$/.test(entry.reason) && typeof entry.path === "string" && /^messages\.\d{1,10}\.content\.\d{1,10}$/.test(entry.path));
|
|
471
|
+
if (!drops?.length) return;
|
|
472
|
+
const paths = drops.slice(0, 5).map(({ reason, path }) => `${reason} at ${path}`);
|
|
473
|
+
getAiTransportHost().logWarn("anthropic", `replayed thinking dropped: ${drops.length} block(s) (${paths.join(", ")}${drops.length > 5 ? ", …" : ""})`);
|
|
474
|
+
}
|
|
369
475
|
function asReplayMessage(value) {
|
|
370
476
|
return value && typeof value === "object" ? value : void 0;
|
|
371
477
|
}
|
|
@@ -737,20 +843,6 @@ function createCompactionCapture(output, model, options) {
|
|
|
737
843
|
}
|
|
738
844
|
};
|
|
739
845
|
}
|
|
740
|
-
function hashReplayValue(value) {
|
|
741
|
-
const normalized = value?.trim();
|
|
742
|
-
return normalized ? shortHash(normalized) : void 0;
|
|
743
|
-
}
|
|
744
|
-
function buildAnthropicReplayContext(model, options) {
|
|
745
|
-
return {
|
|
746
|
-
provider: model.provider,
|
|
747
|
-
api: model.api,
|
|
748
|
-
model: model.id,
|
|
749
|
-
baseUrlHash: hashReplayValue(model.baseUrl),
|
|
750
|
-
sessionHash: hashReplayValue(options?.sessionId),
|
|
751
|
-
authProfileHash: hashReplayValue(options?.authProfileId)
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
846
|
function isAnthropicCompactionState(state) {
|
|
755
847
|
if (state.v !== 1 || typeof state.data !== "string" || typeof state.provider !== "string" || typeof state.api !== "string" || typeof state.model !== "string" || typeof state.baseUrlHash !== "string" || state.sessionHash !== void 0 && typeof state.sessionHash !== "string" || state.authProfileHash !== void 0 && typeof state.authProfileHash !== "string") return false;
|
|
756
848
|
if (state.type === ANTHROPIC_COMPACTION_SUPPRESSION_TYPE) return state.data === ANTHROPIC_COMPACTION_SUPPRESSION_DATA;
|
|
@@ -759,11 +851,8 @@ function isAnthropicCompactionState(state) {
|
|
|
759
851
|
function readAnthropicCompactionState(value) {
|
|
760
852
|
return isRecord(value) && isAnthropicCompactionState(value) ? value : void 0;
|
|
761
853
|
}
|
|
762
|
-
function replayContextMatches(state, context) {
|
|
763
|
-
return state.provider === context.provider && state.api === context.api && state.model === context.model && state.baseUrlHash === context.baseUrlHash && state.sessionHash === context.sessionHash && state.authProfileHash === context.authProfileHash;
|
|
764
|
-
}
|
|
765
854
|
function captureAnthropicCompaction(output, summary, replayIndex, model, options) {
|
|
766
|
-
const context =
|
|
855
|
+
const context = buildProviderReplayContext(model, options);
|
|
767
856
|
if (!summary || !context.baseUrlHash || !Number.isSafeInteger(replayIndex) || replayIndex < 0) return;
|
|
768
857
|
output.providerReplay = {
|
|
769
858
|
v: 1,
|
|
@@ -775,7 +864,7 @@ function captureAnthropicCompaction(output, summary, replayIndex, model, options
|
|
|
775
864
|
};
|
|
776
865
|
}
|
|
777
866
|
function suppressAnthropicCompaction(output, model, options) {
|
|
778
|
-
const context =
|
|
867
|
+
const context = buildProviderReplayContext(model, options);
|
|
779
868
|
if (!context.baseUrlHash) return;
|
|
780
869
|
output.providerReplay = {
|
|
781
870
|
v: 1,
|
|
@@ -786,18 +875,18 @@ function suppressAnthropicCompaction(output, model, options) {
|
|
|
786
875
|
};
|
|
787
876
|
}
|
|
788
877
|
function resolveNewestAnthropicCompaction(messages, model, options) {
|
|
789
|
-
const context =
|
|
878
|
+
const context = buildProviderReplayContext(model, options);
|
|
790
879
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
791
880
|
const message = messages[index];
|
|
792
881
|
if (message?.role !== "assistant") continue;
|
|
793
882
|
const replayState = readAnthropicCompactionState(message.providerReplay);
|
|
794
883
|
if (replayState?.type === ANTHROPIC_COMPACTION_SUPPRESSION_TYPE) {
|
|
795
|
-
if (
|
|
884
|
+
if (providerReplayContextMatches(replayState, context)) return;
|
|
796
885
|
continue;
|
|
797
886
|
}
|
|
798
887
|
if (message.providerReplay?.type !== ANTHROPIC_COMPACTION_REPLAY_TYPE) continue;
|
|
799
888
|
if (!replayState) return;
|
|
800
|
-
if (!
|
|
889
|
+
if (!providerReplayContextMatches(replayState, context)) return;
|
|
801
890
|
return {
|
|
802
891
|
owner: message,
|
|
803
892
|
replayIndex: replayState.replayIndex ?? 0,
|
|
@@ -835,4 +924,4 @@ function isAnthropicReplayRejection(error) {
|
|
|
835
924
|
return (record.status === 400 || text.startsWith("http 400:")) && (text.includes("compaction") || text.includes("context_management"));
|
|
836
925
|
}
|
|
837
926
|
//#endregion
|
|
838
|
-
export {
|
|
927
|
+
export { createAnthropicInlineImageBudget as A, resolveAnthropicContextManagementBetaHeader as B, ANTHROPIC_SERVER_SIDE_FALLBACKS as C, readAnthropicFallbackBoundary as D, applyAnthropicFallbackBoundary as E, applyAnthropicEphemeralCacheControlMarkers as F, omitFoundryBearerCredentialHeaders as G, resolveAnthropicPayloadPolicy as H, applyAnthropicPayloadPolicyToParams as I, usesFoundryBearerAuth as K, isAnthropicServerToolClearingEnabled as L, resolveAnthropicImageMediaType as M, applyAnthropicCacheControlToMessages as N, resolveAnthropicFallbackServingModelCost as O, applyAnthropicContextManagementToRequest as P, isDirectAnthropicModel as R, readAnthropicInputTransformations as S, CLAUDE_OPUS_FALLBACK_MODEL_COST as T, resolveAnthropicServerCompactionPlan as U, resolveAnthropicEphemeralCacheControl as V, isAnthropicOAuthApiKey as W, toClaudeCodeToolName as _, suppressAnthropicCompaction as a, findActiveAnthropicToolTurnAssistantIndex as b, readAnthropicCacheWriteUsage as c, readLastAnthropicIterationUsage as d, normalizeAnthropicToolCallId as f, resolveOriginalAnthropicToolName as g, reconcileAnthropicToolChoice as h, resolveNewestAnthropicCompaction as i, normalizeAnthropicInlineContent as j, applyAnthropicRefusal as k, readAnthropicPromptUsageSnapshot as l, projectAnthropicTools as m, createCompactionCapture as n, applyAnthropicMessageDeltaUsage as o, normalizeAnthropicToolChoice as p, isAnthropicReplayRejection as r, applyAnthropicMessageStartUsage as s, buildAnthropicReplayPlan as t, readAnthropicUsageTokenCount as u, ANTHROPIC_OMITTED_REASONING_TEXT as v, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as w, logAnthropicThinkingDrops as x, applyAnthropicThinkingBindingControls as y, logAnthropicContextEdits as z };
|
package/dist/{anthropic-payload-policy-DBT1itQ-.d.mts → anthropic-payload-policy-d46X2pR0.d.mts}
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model } from "./types-
|
|
1
|
+
import "./index-FnHM2FcI.mjs";
|
|
2
|
+
import { D as Model } from "./types-CJ1-Ht7A.mjs";
|
|
3
|
+
import { t as AnthropicContextManagementOptions } from "./provider-options-Bcc_p-TU.mjs";
|
|
3
4
|
//#region packages/ai/src/transports/anthropic-payload-policy.d.ts
|
|
4
5
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
5
6
|
type AnthropicServiceTier = "auto" | "standard_only";
|
|
@@ -12,6 +13,7 @@ type AnthropicPayloadPolicyInput = {
|
|
|
12
13
|
api?: string;
|
|
13
14
|
baseUrl?: string;
|
|
14
15
|
cacheRetention?: "short" | "long" | "none";
|
|
16
|
+
cacheTtlPruning?: AnthropicContextManagementOptions["cacheTtlPruning"];
|
|
15
17
|
contextWindow?: unknown;
|
|
16
18
|
enableCacheControl?: boolean;
|
|
17
19
|
enableServerCompaction?: boolean;
|
|
@@ -26,6 +28,11 @@ type AnthropicPayloadPolicy = {
|
|
|
26
28
|
compactThreshold: number;
|
|
27
29
|
serviceTier: AnthropicServiceTier | undefined;
|
|
28
30
|
useServerCompaction: boolean;
|
|
31
|
+
toolClearing?: {
|
|
32
|
+
trigger: number;
|
|
33
|
+
clearAtLeast: number;
|
|
34
|
+
tools: NonNullable<AnthropicContextManagementOptions["cacheTtlPruning"]>["tools"];
|
|
35
|
+
};
|
|
29
36
|
};
|
|
30
37
|
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
31
38
|
declare function resolveAnthropicServerCompactionPlan(model: {
|
|
@@ -37,15 +44,32 @@ declare function resolveAnthropicServerCompactionPlan(model: {
|
|
|
37
44
|
enabled: boolean;
|
|
38
45
|
threshold?: number;
|
|
39
46
|
};
|
|
47
|
+
declare function isDirectAnthropicModel(model: {
|
|
48
|
+
provider?: unknown;
|
|
49
|
+
baseUrl?: string;
|
|
50
|
+
}): boolean;
|
|
51
|
+
declare function isAnthropicServerToolClearingEnabled(model: {
|
|
52
|
+
provider?: unknown;
|
|
53
|
+
api?: unknown;
|
|
54
|
+
baseUrl?: string;
|
|
55
|
+
}, apiKey?: string): boolean;
|
|
40
56
|
/** Resolve Anthropic cache-control marker retention for a request endpoint. */
|
|
41
57
|
declare function resolveAnthropicEphemeralCacheControl(baseUrl: string | undefined, cacheRetention: AnthropicPayloadPolicyInput["cacheRetention"]): AnthropicEphemeralCacheControl | undefined;
|
|
42
58
|
/** Apply one shared deepest-stable-message cache breakpoint policy. */
|
|
43
59
|
declare function applyAnthropicCacheControlToMessages(messages: unknown, cacheControl: AnthropicEphemeralCacheControl, markerLimit: number, cacheBreakpointOptOutMessageIndexes: ReadonlySet<number>): void;
|
|
44
60
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
45
61
|
declare function resolveAnthropicPayloadPolicy(input: AnthropicPayloadPolicyInput, model?: Model): AnthropicPayloadPolicy;
|
|
62
|
+
type AnthropicContextManagementPayload = {
|
|
63
|
+
context_management?: unknown;
|
|
64
|
+
tools?: unknown;
|
|
65
|
+
messages?: unknown;
|
|
66
|
+
};
|
|
67
|
+
declare function applyAnthropicContextManagementToRequest(payload: AnthropicContextManagementPayload, model: Model, options: AnthropicContextManagementOptions | undefined, directApiKeyBetaHeader: string | undefined): void;
|
|
68
|
+
declare function resolveAnthropicContextManagementBetaHeader(payload: AnthropicContextManagementPayload, directApiKeyBetaHeader: string | undefined): string | undefined;
|
|
69
|
+
declare function logAnthropicContextEdits(event: unknown): void;
|
|
46
70
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
47
71
|
declare function applyAnthropicPayloadPolicyToParams(payloadObj: Record<string, unknown>, policy: AnthropicPayloadPolicy, cacheBreakpointOptOutMessageIndexes: ReadonlySet<number>): void;
|
|
48
72
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
49
73
|
declare function applyAnthropicEphemeralCacheControlMarkers(payloadObj: Record<string, unknown>, cacheControl?: AnthropicEphemeralCacheControl | null): void;
|
|
50
74
|
//#endregion
|
|
51
|
-
export {
|
|
75
|
+
export { isAnthropicServerToolClearingEnabled as a, resolveAnthropicContextManagementBetaHeader as c, resolveAnthropicServerCompactionPlan as d, applyAnthropicPayloadPolicyToParams as i, resolveAnthropicEphemeralCacheControl as l, applyAnthropicContextManagementToRequest as n, isDirectAnthropicModel as o, applyAnthropicEphemeralCacheControlMarkers as r, logAnthropicContextEdits as s, applyAnthropicCacheControlToMessages as t, resolveAnthropicPayloadPolicy as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model, J as StreamOptions, W as SimpleStreamOptions, d as Context, n as Api, q as StreamFunction, s as AssistantMessageEventStreamContract } from "./types-
|
|
1
|
+
import "./index-FnHM2FcI.mjs";
|
|
2
|
+
import { D as Model, J as StreamOptions, W as SimpleStreamOptions, d as Context, n as Api, q as StreamFunction, s as AssistantMessageEventStreamContract } from "./types-CJ1-Ht7A.mjs";
|
|
3
3
|
//#region packages/ai/src/api-registry.d.ts
|
|
4
4
|
/** Runtime stream adapter signature stored in the API provider registry. */
|
|
5
5
|
type ApiStreamFunction = (model: Model, context: Context, options?: StreamOptions) => AssistantMessageEventStreamContract;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import { n as getAiTransportHost } from "./host-
|
|
3
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
4
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
2
|
+
import { n as getAiTransportHost } from "./host-CEvLw30U.mjs";
|
|
3
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
4
|
+
import { n as buildBaseOptions } from "./simple-options-BjHCCh4v.mjs";
|
|
5
5
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
6
|
-
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput,
|
|
6
|
+
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, r as convertResponsesMessages, s as runResponsesStreamLifecycle, t as applyCommonResponsesParams } from "./openai-responses-shared-Bmma_3Qc.mjs";
|
|
7
7
|
import { i as resolveAzureDeploymentNameFromMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "./azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
8
8
|
import OpenAI, { AzureOpenAI } from "openai";
|
|
9
9
|
//#region packages/ai/src/providers/azure-openai-responses.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as normalizeLowercaseStringOrEmpty } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
-
import "./provider-error-
|
|
2
|
+
import "./provider-error-9TraxGvt.mjs";
|
|
3
3
|
//#region packages/normalization-core/src/error-coercion.ts
|
|
4
4
|
/**
|
|
5
5
|
* Normalizes an unknown thrown value into an Error. Non-Error objects become
|
package/dist/diagnostics.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { a as isProviderRefusalAssistantError, i as formatThrownValue, n as createAssistantMessageDiagnostic, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
|
-
import { r as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-
|
|
3
|
-
import { n as isTransientNetworkError, t as hasRetryableConnectionErrorCode } from "./diagnostics-
|
|
2
|
+
import { r as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-9TraxGvt.mjs";
|
|
3
|
+
import { n as isTransientNetworkError, t as hasRetryableConnectionErrorCode } from "./diagnostics-DfFyKeX_.mjs";
|
|
4
4
|
export { appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue, hasRetryableConnectionErrorCode, isProviderRefusalAssistantError, isTransientNetworkError, projectDiagnosticValue };
|
|
@@ -9,17 +9,10 @@ var EventStream = class {
|
|
|
9
9
|
this.resultSettled = false;
|
|
10
10
|
this.isComplete = isComplete;
|
|
11
11
|
this.extractResult = extractResult;
|
|
12
|
-
const resolvers = [];
|
|
13
|
-
const rejecters = [];
|
|
14
12
|
this.finalResultPromise = new Promise((resolve, reject) => {
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
this.resolveFinalResult = resolve;
|
|
14
|
+
this.rejectFinalResult = reject;
|
|
17
15
|
});
|
|
18
|
-
const resolveFinalResult = resolvers.at(0);
|
|
19
|
-
const rejectFinalResult = rejecters.at(0);
|
|
20
|
-
if (!resolveFinalResult || !rejectFinalResult) throw new Error("event stream result promise did not initialize its resolver");
|
|
21
|
-
this.resolveFinalResult = resolveFinalResult;
|
|
22
|
-
this.rejectFinalResult = rejectFinalResult;
|
|
23
16
|
}
|
|
24
17
|
push(event) {
|
|
25
18
|
if (this.done) return;
|
|
@@ -57,6 +50,7 @@ var EventStream = class {
|
|
|
57
50
|
async *[Symbol.asyncIterator]() {
|
|
58
51
|
while (true) if (this.queueHead < this.queue.length) {
|
|
59
52
|
const event = this.queue[this.queueHead];
|
|
53
|
+
this.queue[this.queueHead] = void 0;
|
|
60
54
|
this.queueHead += 1;
|
|
61
55
|
if (this.queueHead >= 1024 && this.queueHead * 2 >= this.queue.length) {
|
|
62
56
|
this.queue = this.queue.slice(this.queueHead);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-
|
|
1
|
+
import { a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-CJ1-Ht7A.mjs";
|
|
2
2
|
//#region packages/llm-core/src/utils/event-stream.d.ts
|
|
3
3
|
/** Generic async-iterable event stream with a separately awaited final result. */
|
|
4
4
|
declare class EventStream<T, R = T> implements AsyncIterable<T> {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./event-stream-BhT5T1Ay.mjs";
|
package/dist/event-stream.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import "./event-stream-
|
|
1
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-BhT5T1Ay.mjs";
|
|
2
|
+
import "./event-stream-zctLx0yr.mjs";
|
|
3
3
|
export { AssistantMessageEventStream, EventStream, createAssistantMessageEventStream };
|
package/dist/event-stream.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
1
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
2
2
|
export { AssistantMessageEventStream, EventStream, createAssistantMessageEventStream };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
3
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
2
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-CEvLw30U.mjs";
|
|
3
|
+
import { n as buildBaseOptions } from "./simple-options-BjHCCh4v.mjs";
|
|
4
4
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
5
|
-
import { i as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-
|
|
5
|
+
import { i as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-CWeG8RIl.mjs";
|
|
6
6
|
import { GoogleGenAI } from "@google/genai";
|
|
7
7
|
//#region packages/ai/src/providers/google.ts
|
|
8
8
|
let toolCallCounter = 0;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
2
|
-
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload } from "./host-
|
|
3
|
-
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName } from "./simple-options-
|
|
4
|
-
import { _ as transportAbortError, n as coerceTransportToolCallArguments, p as notifyProviderStreamOpened, t as assignTransportErrorDetails } from "./transport-stream-shared-
|
|
1
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-D6xUvZaS.mjs";
|
|
2
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload } from "./host-CEvLw30U.mjs";
|
|
3
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName } from "./simple-options-BjHCCh4v.mjs";
|
|
4
|
+
import { _ as transportAbortError, n as coerceTransportToolCallArguments, p as notifyProviderStreamOpened, t as assignTransportErrorDetails } from "./transport-stream-shared-CZqMhfIw.mjs";
|
|
5
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
5
6
|
import { t as googleFlashSupportsMinimalThinking } from "./google-thinking-level-C-V3tecN.mjs";
|
|
6
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
7
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BaMbI1hr.mjs";
|
|
7
8
|
import { FinishReason, FunctionCallingConfigMode, ThinkingLevel } from "@google/genai";
|
|
8
9
|
//#region packages/ai/src/providers/google-shared.ts
|
|
9
10
|
/**
|
|
@@ -459,6 +460,7 @@ async function consumeGoogleGenerateContentStream(params) {
|
|
|
459
460
|
currentBlock = null;
|
|
460
461
|
};
|
|
461
462
|
for await (const chunk of params.chunks) {
|
|
463
|
+
notifyLlmRequestActivity(params.signal);
|
|
462
464
|
params.output.responseId ||= chunk.responseId;
|
|
463
465
|
const responseModel = chunk.modelVersion?.trim();
|
|
464
466
|
if (responseModel && params.model.id.replace(GOOGLE_MODEL_RESOURCE_PREFIX, "") !== responseModel.replace(GOOGLE_MODEL_RESOURCE_PREFIX, "")) params.output.responseModel ||= responseModel;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
2
2
|
import { d as normalizeOptionalString } from "./utf16-slice-qz3nsy87.mjs";
|
|
3
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
5
|
-
import { i as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-CEvLw30U.mjs";
|
|
4
|
+
import { n as buildBaseOptions } from "./simple-options-BjHCCh4v.mjs";
|
|
5
|
+
import { i as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-CWeG8RIl.mjs";
|
|
6
6
|
import { GoogleGenAI, ResourceScope } from "@google/genai";
|
|
7
7
|
//#region packages/ai/src/providers/google-vertex.ts
|
|
8
8
|
const API_VERSION = "v1";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as supportsClaudeNativeXhighEffort, c as requiresClaudeDefaultSampling, f as resolveClaudeMythos5ModelIdentity, h as resolveClaudeSonnet5ModelIdentity, l as requiresClaudeMandatoryAdaptiveThinking, m as resolveClaudeOpus5ModelIdentity, p as resolveClaudeNativeThinkingLevelMap, u as resolveClaudeFable5ModelIdentity, y as supportsClaudeNativeMaxEffort } from "./src-2qBGKg8O.mjs";
|
|
2
2
|
import { c as normalizeLowercaseStringOrEmpty, o as isRecord, t as truncateUtf16Safe } from "./utf16-slice-qz3nsy87.mjs";
|
|
3
|
-
import { i as clampThinkingLevel, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
3
|
+
import { i as clampThinkingLevel, t as sanitizeSurrogates } from "./sanitize-unicode-D6xUvZaS.mjs";
|
|
4
4
|
//#region packages/ai/src/providers/anthropic-model-contract.ts
|
|
5
5
|
const ANTHROPIC_CLAUDE_CODE_VERSION = "2.1.75";
|
|
6
6
|
const ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK = `x-anthropic-billing-header: cc_version=${ANTHROPIC_CLAUDE_CODE_VERSION}; cc_entrypoint=sdk-cli;`;
|
|
@@ -107,6 +107,20 @@ function resolveReplayModelBoundIdentity(ref) {
|
|
|
107
107
|
const sonnetIdentity = resolveClaudeSonnet5ModelIdentity(modelRef);
|
|
108
108
|
return sonnetIdentity ? `sonnet:${sonnetIdentity}` : void 0;
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Fable 5.1 reads thinking from every earlier Claude generation (verified live:
|
|
112
|
+
* Opus 5, Sonnet 5, Opus 4.8 replay with no drops), while the API silently
|
|
113
|
+
* drops anything it cannot read. Moving onto it therefore keeps prior reasoning;
|
|
114
|
+
* every other cross-identity move, including unregistered Mythos targets, is
|
|
115
|
+
* still dropped here until its replay contract is proven separately.
|
|
116
|
+
*/
|
|
117
|
+
function readsPriorClaudeThinking(targetIdentity) {
|
|
118
|
+
return targetIdentity !== void 0 && /^fable:claude-fable-5-1(?=$|[^a-z0-9])/.test(targetIdentity);
|
|
119
|
+
}
|
|
120
|
+
function isClaudeReplaySource(ref) {
|
|
121
|
+
const modelId = hasConcreteResponseModel(ref) ? ref.responseModelId : ref.modelId;
|
|
122
|
+
return /(?:^|[-/])claude-/.test(normalizeModelId(modelId));
|
|
123
|
+
}
|
|
110
124
|
function resolveModelBoundThinkingReplayMode(params) {
|
|
111
125
|
const sourceApi = normalizeApi(params.source.api);
|
|
112
126
|
const targetApi = normalizeApi(params.target.api);
|
|
@@ -114,6 +128,7 @@ function resolveModelBoundThinkingReplayMode(params) {
|
|
|
114
128
|
const targetIdentity = resolveReplayModelBoundIdentity(params.target);
|
|
115
129
|
const sameRoute = normalizeLowercaseStringOrEmpty(params.source.provider) === normalizeLowercaseStringOrEmpty(params.target.provider) && sourceApi === targetApi && normalizeModelId(params.source.modelId) === normalizeModelId(params.target.modelId);
|
|
116
130
|
if (!sourceIdentity && !targetIdentity) return "default";
|
|
131
|
+
if (sourceApi === targetApi && readsPriorClaudeThinking(targetIdentity) && isClaudeReplaySource(params.source)) return "preserve";
|
|
117
132
|
if (!sourceIdentity && !hasConcreteResponseModel(params.source) && targetIdentity && sameRoute) return "preserve";
|
|
118
133
|
return sourceApi === targetApi && sourceIdentity === targetIdentity ? "preserve" : "drop";
|
|
119
134
|
}
|
|
@@ -240,9 +255,9 @@ function extractToolResultText(blocks, options) {
|
|
|
240
255
|
}
|
|
241
256
|
if (explicitTexts.length > 0) {
|
|
242
257
|
const text = (options?.includeStructured ? [...explicitTexts, ...structuredTexts] : explicitTexts).join("\n");
|
|
243
|
-
return
|
|
258
|
+
return options?.includeStructured ? truncateProviderToolText(text) : text;
|
|
244
259
|
}
|
|
245
|
-
return
|
|
260
|
+
return truncateProviderToolText(structuredTexts.join("\n"));
|
|
246
261
|
}
|
|
247
262
|
/** Describe media that cannot be represented on the target provider wire. */
|
|
248
263
|
function describeUnsupportedToolResultMedia(blocks, support) {
|
|
@@ -322,7 +337,7 @@ function transformAssistant(message, model, toolCallIdMap, normalizeToolCallId)
|
|
|
322
337
|
type: "text",
|
|
323
338
|
text: block.text
|
|
324
339
|
};
|
|
325
|
-
const { thoughtSignature: _, ...unsigned } = block;
|
|
340
|
+
const { thoughtSignature: _, async: _async, ...unsigned } = block;
|
|
326
341
|
const trimmedId = block.id.trim();
|
|
327
342
|
if (sameModel) return trimmedId === block.id ? block : Object.assign({}, block, { id: trimmedId });
|
|
328
343
|
const id = normalizeToolCallId?.(trimmedId, model, message) ?? trimmedId;
|
|
@@ -336,7 +351,26 @@ function transformAssistant(message, model, toolCallIdMap, normalizeToolCallId)
|
|
|
336
351
|
}
|
|
337
352
|
function transformMessages(messages, model, normalizeToolCallId) {
|
|
338
353
|
const toolCallIdMap = /* @__PURE__ */ new Map();
|
|
339
|
-
const
|
|
354
|
+
const asyncOwners = /* @__PURE__ */ new Map();
|
|
355
|
+
const relocated = /* @__PURE__ */ new Map();
|
|
356
|
+
const movedResults = /* @__PURE__ */ new Set();
|
|
357
|
+
for (const message of messages) if (message.role === "assistant") {
|
|
358
|
+
const sameModel = message.provider === model.provider && message.api === model.api && message.model === model.id;
|
|
359
|
+
for (const block of message.content ?? []) if (block.type === "toolCall") {
|
|
360
|
+
if (block.async && !sameModel) asyncOwners.set(block.id, message);
|
|
361
|
+
else asyncOwners.delete(block.id);
|
|
362
|
+
}
|
|
363
|
+
} else if (message.role === "toolResult") {
|
|
364
|
+
const owner = asyncOwners.get(message.toolCallId);
|
|
365
|
+
if (owner) {
|
|
366
|
+
const results = relocated.get(owner) ?? [];
|
|
367
|
+
results.push(message);
|
|
368
|
+
relocated.set(owner, results);
|
|
369
|
+
movedResults.add(message);
|
|
370
|
+
asyncOwners.delete(message.toolCallId);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const transformed = downgradeUnsupportedImages((movedResults.size > 0 ? messages.flatMap((message) => movedResults.has(message) ? [] : [message, ...message.role === "assistant" ? relocated.get(message) ?? [] : []]) : messages).map((message) => message.content == null ? Object.assign({}, message, { content: [] }) : message), model).map((message) => {
|
|
340
374
|
if (message.role === "assistant") return transformAssistant(message, model, toolCallIdMap, normalizeToolCallId);
|
|
341
375
|
if (message.role !== "toolResult") return message;
|
|
342
376
|
const trimmedId = message.toolCallId.trim();
|
|
@@ -344,6 +378,7 @@ function transformMessages(messages, model, normalizeToolCallId) {
|
|
|
344
378
|
return toolCallId === message.toolCallId ? message : Object.assign({}, message, { toolCallId });
|
|
345
379
|
});
|
|
346
380
|
const result = [];
|
|
381
|
+
const pendingAsyncCalls = /* @__PURE__ */ new Map();
|
|
347
382
|
let pendingToolCalls = [];
|
|
348
383
|
let existingToolResultIds = /* @__PURE__ */ new Set();
|
|
349
384
|
const flushToolCalls = () => {
|
|
@@ -365,11 +400,21 @@ function transformMessages(messages, model, normalizeToolCallId) {
|
|
|
365
400
|
if (message.role === "assistant") {
|
|
366
401
|
flushToolCalls();
|
|
367
402
|
if (message.stopReason === "error" || message.stopReason === "aborted") continue;
|
|
368
|
-
pendingToolCalls = message.content.filter((block) =>
|
|
369
|
-
|
|
370
|
-
|
|
403
|
+
pendingToolCalls = message.content.filter((block) => {
|
|
404
|
+
if (block.type !== "toolCall") return false;
|
|
405
|
+
if (block.async) {
|
|
406
|
+
pendingAsyncCalls.set(block.id, block);
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
return true;
|
|
410
|
+
});
|
|
411
|
+
} else if (message.role === "toolResult") {
|
|
412
|
+
existingToolResultIds.add(message.toolCallId);
|
|
413
|
+
pendingAsyncCalls.delete(message.toolCallId);
|
|
414
|
+
} else flushToolCalls();
|
|
371
415
|
result.push(message);
|
|
372
416
|
}
|
|
417
|
+
pendingToolCalls.push(...pendingAsyncCalls.values());
|
|
373
418
|
flushToolCalls();
|
|
374
419
|
return result;
|
|
375
420
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model, K as StreamFn, d as Context, n as Api } from "./types-
|
|
3
|
-
import { n as ApiRegistry } from "./api-registry-
|
|
1
|
+
import "./index-FnHM2FcI.mjs";
|
|
2
|
+
import { D as Model, K as StreamFn, d as Context, n as Api } from "./types-CJ1-Ht7A.mjs";
|
|
3
|
+
import { n as ApiRegistry } from "./api-registry-DWtPjzyn.mjs";
|
|
4
4
|
//#region packages/ai/src/host.d.ts
|
|
5
5
|
/** Provider capability facts needed by the package-owned transports. */
|
|
6
6
|
interface AiProviderRequestCapabilities {
|