@openclaw/ai 2026.7.2-beta.3 → 2026.7.2-beta.4
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/README.md +6 -5
- package/dist/{anthropic-D7SyZQ5v.mjs → anthropic-CrUDIBpM.mjs} +123 -16
- package/dist/{api-registry-DXBIXISf.d.mts → api-registry-BMphkFf1.d.mts} +1 -2
- package/dist/{azure-openai-responses-BkZgyZ3I.mjs → azure-openai-responses-CbrpVeEv.mjs} +7 -10
- package/dist/{env-api-keys-DnhYpc27.mjs → env-api-keys-DrgeBuva.mjs} +1 -1
- package/dist/{event-stream-BPemFrFW.d.mts → event-stream-Douf9dob.d.mts} +1 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/{google-C_biGbV7.mjs → google-Cs62KA7t.mjs} +4 -4
- package/dist/{google-shared-BK-NoHl8.mjs → google-shared-CMLI-tCZ.mjs} +3 -3
- package/dist/{google-vertex-CvdzF1U7.mjs → google-vertex-B4SD3U0f.mjs} +3 -3
- package/dist/host-WvWBo4h8.d.mts +173 -0
- package/dist/host-XYGZcgO8.mjs +98 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.d.mts +7 -50
- package/dist/index.mjs +1 -1
- package/dist/internal/anthropic.d.mts +2 -2
- package/dist/internal/anthropic.mjs +2 -2
- package/dist/internal/openai.d.mts +2 -280
- package/dist/internal/openai.mjs +5 -5
- package/dist/internal/runtime.d.mts +8 -5
- package/dist/internal/runtime.mjs +19 -10
- package/dist/internal/shared.d.mts +1 -1
- package/dist/internal/shared.mjs +1 -1
- package/dist/{mistral-BdrQmDWp.mjs → mistral-D5Ps7Led.mjs} +4 -4
- package/dist/openai-CoGicoDt.d.mts +332 -0
- package/dist/{openai-chatgpt-responses-DP63Qt01.mjs → openai-chatgpt-responses-h0o5yV8Y.mjs} +40 -43
- package/dist/{openai-completions-zLDfebnN.mjs → openai-completions-exO8NFQf.mjs} +316 -100
- package/dist/{openai-responses-ClspWt4I.mjs → openai-responses-BHpmtUKo.mjs} +5 -5
- package/dist/{openai-responses-shared-CwnGU0KW.mjs → openai-responses-shared-CzCurmY1.mjs} +230 -71
- package/dist/{openai-tool-projection-WHf2nuOI.mjs → openai-tool-projection-ITOU9bG1.mjs} +1 -1
- package/dist/{provider-error-LMfTEkfO.mjs → provider-error-C4VvV_3t.mjs} +2 -1
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +8 -8
- package/dist/{stream-first-event-timeout-RjWszj8c.mjs → stream-first-event-timeout-DP4xEyBY.mjs} +45 -1
- package/dist/{transform-messages-eb6lxDLB.mjs → system-prompt-cache-boundary-CbHeV4_l.mjs} +164 -160
- package/dist/transports.d.mts +590 -0
- package/dist/transports.mjs +5701 -0
- package/dist/{types-CYORveZ7.d.mts → types-AFwwWium.d.mts} +1 -0
- package/dist/types.d.mts +4 -4
- package/dist/{validation-BX8euiDv.d.mts → validation-sxvxC8J-.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/npm-shrinkwrap.json +43 -50
- package/package.json +36 -10
- package/dist/host-4t713IeR.mjs +0 -37
- /package/dist/{index-BoTnz8cv.d.mts → anthropic-BoTnz8cv.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -14,15 +14,16 @@ registerBuiltInApiProviders(runtime.registry);
|
|
|
14
14
|
|
|
15
15
|
Provider-neutral contracts, validation, diagnostics, and event streams are
|
|
16
16
|
available from the package root and focused subpaths such as
|
|
17
|
-
`@openclaw/ai/event-stream
|
|
18
|
-
runtime package is required.
|
|
17
|
+
`@openclaw/ai/event-stream`, `@openclaw/ai/transports`, and
|
|
18
|
+
`@openclaw/ai/validation`. No second OpenClaw runtime package is required.
|
|
19
19
|
|
|
20
20
|
Provider ids, credentials, model catalogs, retries, and failover remain
|
|
21
21
|
application concerns. OpenClaw supplies those policies around this package.
|
|
22
22
|
Host policy (request fetch guarding, secret redaction, strict-tool defaults,
|
|
23
|
-
diagnostics logging) can be injected with
|
|
24
|
-
defaults are inert.
|
|
23
|
+
provider plugin hooks, and diagnostics logging) can be injected with
|
|
24
|
+
`configureAiTransportHost`; the defaults are inert.
|
|
25
25
|
|
|
26
|
-
`@openclaw/ai/internal
|
|
26
|
+
The explicit `@openclaw/ai/internal/anthropic`, `openai`, `retry-after`,
|
|
27
|
+
`runtime`, and `shared` subpaths exist for the OpenClaw application itself.
|
|
27
28
|
They carry no semver guarantee and can change or disappear in any release; do
|
|
28
29
|
not depend on them outside OpenClaw.
|
|
@@ -1,17 +1,117 @@
|
|
|
1
|
-
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-
|
|
1
|
+
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { c as resolveClaudeNativeThinkingLevelMap, d as supportsClaudeNativeMaxEffort, f as supportsClaudeNativeXhighEffort, l as resolveClaudeSonnet5ModelIdentity, u as supportsClaudeAdaptiveThinking } from "./src-CXno1H5g.mjs";
|
|
3
3
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
4
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-XYGZcgO8.mjs";
|
|
5
|
+
import { C as isImageWithMediaPayload, D as buildBaseOptions, E as adjustMaxTokensForThinking, O as clampMaxTokensToModel, T as isRecord, a as stripSystemPromptCacheBoundary, b as extractToolResultBlockText, c as transformMessages, d as prepareClaudeSonnet5RequestContext, f as requiresClaudeAdaptiveThinking, h as usesClaudeStreamingRefusalContract, i as splitSystemPromptCacheBoundary, l as applyClaudeRequestContract, m as usesClaudeFable5MessagesContract, x as extractToolResultText, y as describeToolResultMediaPlaceholder } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
6
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
5
7
|
import { n as calculateCost, r as clampThinkingLevel } from "./model-utils-1GiZ2_rr.mjs";
|
|
6
8
|
import { r as createDeferredEventBuffer, t as notifyLlmRequestActivity } from "./llm-request-activity-CehVkZP-.mjs";
|
|
7
9
|
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
8
10
|
import { n as parseStreamingJson, t as parseJsonWithRepair } from "./json-parse-BvXNt1-7.mjs";
|
|
9
|
-
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
10
|
-
import { C as splitSystemPromptCacheBoundary, c as adjustMaxTokensForThinking, f as isRecord, g as requiresClaudeAdaptiveThinking, h as prepareClaudeSonnet5RequestContext, i as extractToolResultText, l as buildBaseOptions, n as describeToolResultMediaPlaceholder, o as isImageWithMediaPayload, p as applyClaudeRequestContract, r as extractToolResultBlockText, t as transformMessages, u as clampMaxTokensToModel, v as usesClaudeFable5MessagesContract, w as stripSystemPromptCacheBoundary, y as usesClaudeStreamingRefusalContract } from "./transform-messages-eb6lxDLB.mjs";
|
|
11
11
|
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-BwNu3nDi.mjs";
|
|
12
12
|
import { a as resolveCacheRetention, i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-BsH5cqGj.mjs";
|
|
13
13
|
import Anthropic from "@anthropic-ai/sdk";
|
|
14
14
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
15
|
+
//#region packages/media-core/src/base64.ts
|
|
16
|
+
/** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
|
|
17
|
+
function estimateBase64DecodedBytes(base64) {
|
|
18
|
+
let effectiveLen = 0;
|
|
19
|
+
for (let i = 0; i < base64.length; i += 1) {
|
|
20
|
+
if (base64.charCodeAt(i) <= 32) continue;
|
|
21
|
+
effectiveLen += 1;
|
|
22
|
+
}
|
|
23
|
+
if (effectiveLen === 0) return 0;
|
|
24
|
+
let padding = 0;
|
|
25
|
+
let end = base64.length - 1;
|
|
26
|
+
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
27
|
+
if (end >= 0 && base64[end] === "=") {
|
|
28
|
+
padding = 1;
|
|
29
|
+
end -= 1;
|
|
30
|
+
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
31
|
+
if (end >= 0 && base64[end] === "=") padding = 2;
|
|
32
|
+
}
|
|
33
|
+
const estimated = Math.floor(effectiveLen * 3 / 4) - padding;
|
|
34
|
+
return Math.max(0, estimated);
|
|
35
|
+
}
|
|
36
|
+
const CANONICALIZE_BASE64_CHUNK_SIZE = 8192;
|
|
37
|
+
function isBase64DataChar(code) {
|
|
38
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Normalizes and validates a base64 string, returning canonical no-whitespace
|
|
42
|
+
* base64 only when the input has valid alphabet, padding, and length.
|
|
43
|
+
*/
|
|
44
|
+
function canonicalizeBase64(base64) {
|
|
45
|
+
const chunks = [];
|
|
46
|
+
let current = "";
|
|
47
|
+
let cleanedLength = 0;
|
|
48
|
+
let padding = 0;
|
|
49
|
+
let sawPadding = false;
|
|
50
|
+
const append = (char) => {
|
|
51
|
+
current += char;
|
|
52
|
+
cleanedLength += 1;
|
|
53
|
+
if (current.length >= CANONICALIZE_BASE64_CHUNK_SIZE) {
|
|
54
|
+
chunks.push(current);
|
|
55
|
+
current = "";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
for (let i = 0; i < base64.length; i += 1) {
|
|
59
|
+
const code = base64.charCodeAt(i);
|
|
60
|
+
if (code <= 32) continue;
|
|
61
|
+
if (code === 61) {
|
|
62
|
+
padding += 1;
|
|
63
|
+
if (padding > 2) return;
|
|
64
|
+
sawPadding = true;
|
|
65
|
+
append("=");
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (sawPadding || !isBase64DataChar(code)) return;
|
|
69
|
+
append(base64[i] ?? "");
|
|
70
|
+
}
|
|
71
|
+
if (cleanedLength === 0) return;
|
|
72
|
+
const remainder = cleanedLength % 4;
|
|
73
|
+
if (remainder !== 0) {
|
|
74
|
+
if (sawPadding || remainder === 1) return;
|
|
75
|
+
current += "=".repeat(4 - remainder);
|
|
76
|
+
}
|
|
77
|
+
if (current) chunks.push(current);
|
|
78
|
+
return chunks.join("");
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region packages/ai/src/internal/anthropic-inline-images.ts
|
|
82
|
+
const ANTHROPIC_IMAGE_MEDIA_TYPE_SET = /* @__PURE__ */ new Set([
|
|
83
|
+
"image/jpeg",
|
|
84
|
+
"image/png",
|
|
85
|
+
"image/gif",
|
|
86
|
+
"image/webp"
|
|
87
|
+
]);
|
|
88
|
+
const ANTHROPIC_INLINE_IMAGES_DECODE_SAFETY_BYTES = 64 * 1024 * 1024;
|
|
89
|
+
function createAnthropicInlineImageBudget() {
|
|
90
|
+
return { totalBytes: 0 };
|
|
91
|
+
}
|
|
92
|
+
function resolveAnthropicImageMediaType(value) {
|
|
93
|
+
if (ANTHROPIC_IMAGE_MEDIA_TYPE_SET.has(value)) return value;
|
|
94
|
+
throw new Error(`Unsupported Anthropic image media type after normalization: ${value}`);
|
|
95
|
+
}
|
|
96
|
+
async function normalizeAnthropicInlineContent(content, budget) {
|
|
97
|
+
if (!content.some((block) => block.type === "image")) return content.filter((block) => block.type === "text");
|
|
98
|
+
const inputBytes = content.reduce((total, block) => block.type === "image" ? total + estimateBase64DecodedBytes(block.data) : total, 0);
|
|
99
|
+
if (budget.totalBytes + inputBytes > ANTHROPIC_INLINE_IMAGES_DECODE_SAFETY_BYTES) throw new Error("Anthropic inline images exceed the 64 MB aggregate decoded safety limit.");
|
|
100
|
+
const normalized = [];
|
|
101
|
+
for (const block of content) {
|
|
102
|
+
if (block.type !== "image") {
|
|
103
|
+
normalized.push(block);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const normalizedBlocks = await getAiTransportHost().normalizeAnthropicInlineContentBlocks([block]);
|
|
107
|
+
const outputBytes = normalizedBlocks.reduce((total, normalizedBlock) => normalizedBlock.type === "image" ? total + estimateBase64DecodedBytes(normalizedBlock.data) : total, 0);
|
|
108
|
+
if (budget.totalBytes + outputBytes > ANTHROPIC_INLINE_IMAGES_DECODE_SAFETY_BYTES) throw new Error("Anthropic inline images exceed the 64 MB aggregate decoded safety limit.");
|
|
109
|
+
budget.totalBytes += outputBytes;
|
|
110
|
+
normalized.push(...normalizedBlocks);
|
|
111
|
+
}
|
|
112
|
+
return normalized;
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
15
115
|
//#region packages/ai/src/providers/anthropic-auth-headers.ts
|
|
16
116
|
function usesFoundryBearerAuth(model) {
|
|
17
117
|
return model.provider === "microsoft-foundry" && (model.authHeader === true || hasBearerAuthorizationHeader(model.headers));
|
|
@@ -381,7 +481,7 @@ const toClaudeCodeName = (name) => ccToolLookup.get(name.toLowerCase()) ?? name;
|
|
|
381
481
|
/**
|
|
382
482
|
* Convert content blocks to Anthropic API format
|
|
383
483
|
*/
|
|
384
|
-
function convertContentBlocks(content, isError) {
|
|
484
|
+
async function convertContentBlocks(content, isError, imageBudget) {
|
|
385
485
|
const text = extractToolResultText(content);
|
|
386
486
|
const mediaPlaceholder = describeToolResultMediaPlaceholder(content);
|
|
387
487
|
if (!content.some(isImageWithMediaPayload)) {
|
|
@@ -402,12 +502,18 @@ function convertContentBlocks(content, isError) {
|
|
|
402
502
|
hasTextBlock = true;
|
|
403
503
|
}
|
|
404
504
|
if (!isImageWithMediaPayload(record)) continue;
|
|
505
|
+
const [normalizedImage] = await normalizeAnthropicInlineContent([{
|
|
506
|
+
type: "image",
|
|
507
|
+
data: typeof record.data === "string" ? record.data : "",
|
|
508
|
+
mimeType: typeof record.mimeType === "string" ? record.mimeType : "image/jpeg"
|
|
509
|
+
}], imageBudget);
|
|
510
|
+
if (normalizedImage?.type !== "image") continue;
|
|
405
511
|
blocks.push({
|
|
406
512
|
type: "image",
|
|
407
513
|
source: {
|
|
408
514
|
type: "base64",
|
|
409
|
-
media_type:
|
|
410
|
-
data:
|
|
515
|
+
media_type: resolveAnthropicImageMediaType(normalizedImage.mimeType),
|
|
516
|
+
data: normalizedImage.data
|
|
411
517
|
}
|
|
412
518
|
});
|
|
413
519
|
}
|
|
@@ -518,7 +624,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
518
624
|
isOAuth = created.isOAuthToken;
|
|
519
625
|
serverSideFallback = created.serverSideFallback;
|
|
520
626
|
}
|
|
521
|
-
const builtParams = buildParams(model, requestContext, isOAuth, requestOptions, serverSideFallback);
|
|
627
|
+
const builtParams = await buildParams(model, requestContext, isOAuth, requestOptions, serverSideFallback);
|
|
522
628
|
let params = builtParams.params;
|
|
523
629
|
const toolProjection = builtParams.toolProjection;
|
|
524
630
|
const nextParams = await requestOptions?.onPayload?.(params, model);
|
|
@@ -1017,7 +1123,7 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
1017
1123
|
serverSideFallback
|
|
1018
1124
|
};
|
|
1019
1125
|
}
|
|
1020
|
-
function buildParams(model, context, isOAuthTokenResult, options, serverSideFallback = false) {
|
|
1126
|
+
async function buildParams(model, context, isOAuthTokenResult, options, serverSideFallback = false) {
|
|
1021
1127
|
const mandatoryAdaptiveThinking = requiresClaudeAdaptiveThinking(model);
|
|
1022
1128
|
const replayThinkingEnabled = mandatoryAdaptiveThinking || options?.thinkingEnabled === true;
|
|
1023
1129
|
const { cacheControl } = getCacheControl(model, options?.cacheRetention);
|
|
@@ -1031,7 +1137,7 @@ function buildParams(model, context, isOAuthTokenResult, options, serverSideFall
|
|
|
1031
1137
|
const messageCacheControlLimit = Math.max(0, ANTHROPIC_CACHE_CONTROL_LIMIT - systemCacheControlCount - toolCacheControlCount);
|
|
1032
1138
|
const params = {
|
|
1033
1139
|
model: model.id,
|
|
1034
|
-
messages: convertMessages(context.messages, model, isOAuthTokenResult, cacheControl, messageCacheControlLimit, replayThinkingEnabled, compat.allowEmptySignature),
|
|
1140
|
+
messages: await convertMessages(context.messages, model, isOAuthTokenResult, cacheControl, messageCacheControlLimit, replayThinkingEnabled, compat.allowEmptySignature),
|
|
1035
1141
|
max_tokens: options?.maxTokens ?? model.maxTokens,
|
|
1036
1142
|
stream: true
|
|
1037
1143
|
};
|
|
@@ -1074,8 +1180,9 @@ function buildParams(model, context, isOAuthTokenResult, options, serverSideFall
|
|
|
1074
1180
|
function normalizeToolCallId(id) {
|
|
1075
1181
|
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
1076
1182
|
}
|
|
1077
|
-
function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messageCacheControlLimit = 4, replayThinkingEnabled = true, allowEmptySignature = false) {
|
|
1183
|
+
async function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messageCacheControlLimit = 4, replayThinkingEnabled = true, allowEmptySignature = false) {
|
|
1078
1184
|
const params = [];
|
|
1185
|
+
const imageBudget = createAnthropicInlineImageBudget();
|
|
1079
1186
|
const cacheBreakpointOptOutParamIndexes = /* @__PURE__ */ new Set();
|
|
1080
1187
|
const transformedMessages = transformMessages(messages, model, normalizeToolCallId);
|
|
1081
1188
|
const activeToolTurnAssistantIndex = replayThinkingEnabled ? -1 : findActiveAnthropicToolTurnAssistantIndex(transformedMessages);
|
|
@@ -1093,7 +1200,7 @@ function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messa
|
|
|
1093
1200
|
});
|
|
1094
1201
|
}
|
|
1095
1202
|
} else {
|
|
1096
|
-
const filteredBlocks = msg.content.map((item) => {
|
|
1203
|
+
const filteredBlocks = (await normalizeAnthropicInlineContent(msg.content, imageBudget)).map((item) => {
|
|
1097
1204
|
if (item.type === "text") return {
|
|
1098
1205
|
type: "text",
|
|
1099
1206
|
text: sanitizeSurrogates(item.text)
|
|
@@ -1102,7 +1209,7 @@ function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messa
|
|
|
1102
1209
|
type: "image",
|
|
1103
1210
|
source: {
|
|
1104
1211
|
type: "base64",
|
|
1105
|
-
media_type: item.mimeType,
|
|
1212
|
+
media_type: resolveAnthropicImageMediaType(item.mimeType),
|
|
1106
1213
|
data: item.data
|
|
1107
1214
|
}
|
|
1108
1215
|
};
|
|
@@ -1174,7 +1281,7 @@ function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messa
|
|
|
1174
1281
|
toolResults.push({
|
|
1175
1282
|
type: "tool_result",
|
|
1176
1283
|
tool_use_id: msg.toolCallId,
|
|
1177
|
-
content: convertContentBlocks(msg.content, msg.isError),
|
|
1284
|
+
content: await convertContentBlocks(msg.content, msg.isError, imageBudget),
|
|
1178
1285
|
is_error: msg.isError
|
|
1179
1286
|
});
|
|
1180
1287
|
let j = i + 1;
|
|
@@ -1184,7 +1291,7 @@ function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messa
|
|
|
1184
1291
|
toolResults.push({
|
|
1185
1292
|
type: "tool_result",
|
|
1186
1293
|
tool_use_id: nextMsg.toolCallId,
|
|
1187
|
-
content: convertContentBlocks(nextMsg.content, nextMsg.isError),
|
|
1294
|
+
content: await convertContentBlocks(nextMsg.content, nextMsg.isError, imageBudget),
|
|
1188
1295
|
is_error: nextMsg.isError
|
|
1189
1296
|
});
|
|
1190
1297
|
j++;
|
|
@@ -1321,4 +1428,4 @@ function mapStopReason(reason) {
|
|
|
1321
1428
|
}
|
|
1322
1429
|
}
|
|
1323
1430
|
//#endregion
|
|
1324
|
-
export { buildAnthropicServerSideFallbacks as _, readAnthropicPromptUsageSnapshot as a, omitFoundryBearerCredentialHeaders as b, projectAnthropicTools as c, ANTHROPIC_OMITTED_REASONING_TEXT as d, findActiveAnthropicToolTurnAssistantIndex as f, applyAnthropicFallbackBoundary as g, CLAUDE_FABLE_5_FALLBACK_MODEL_COST as h, readAnthropicCacheWriteUsage as i, reconcileAnthropicToolChoice as l, CLAUDE_FABLE_5_FALLBACK_MODEL as m, streamAnthropic as n, readAnthropicUsageTokenCount as o, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as p, streamSimpleAnthropic as r, readLastAnthropicIterationUsage as s, anthropic_exports as t, resolveOriginalAnthropicToolName as u, readAnthropicFallbackBoundary as v, usesFoundryBearerAuth as x, applyAnthropicRefusal as y };
|
|
1431
|
+
export { normalizeAnthropicInlineContent as C, createAnthropicInlineImageBudget as S, canonicalizeBase64 as T, buildAnthropicServerSideFallbacks as _, readAnthropicPromptUsageSnapshot as a, omitFoundryBearerCredentialHeaders as b, projectAnthropicTools as c, ANTHROPIC_OMITTED_REASONING_TEXT as d, findActiveAnthropicToolTurnAssistantIndex as f, applyAnthropicFallbackBoundary as g, CLAUDE_FABLE_5_FALLBACK_MODEL_COST as h, readAnthropicCacheWriteUsage as i, reconcileAnthropicToolChoice as l, CLAUDE_FABLE_5_FALLBACK_MODEL as m, streamAnthropic as n, readAnthropicUsageTokenCount as o, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as p, streamSimpleAnthropic as r, readLastAnthropicIterationUsage as s, anthropic_exports as t, resolveOriginalAnthropicToolName as u, readAnthropicFallbackBoundary as v, resolveAnthropicImageMediaType as w, usesFoundryBearerAuth as x, applyAnthropicRefusal as y };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { E as Model, F as SimpleStreamOptions, R as StreamFunction, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "./types-
|
|
2
|
-
|
|
1
|
+
import { E as Model, F as SimpleStreamOptions, R as StreamFunction, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "./types-AFwwWium.mjs";
|
|
3
2
|
//#region packages/ai/src/api-registry.d.ts
|
|
4
3
|
/** Runtime stream adapter signature stored in the API provider registry. */
|
|
5
4
|
type ApiStreamFunction = (model: Model, context: Context, options?: StreamOptions) => AssistantMessageEventStreamContract;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
1
|
+
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
4
|
-
import {
|
|
5
|
-
import { a as resolveResponsesReasoningEffort, n as convertResponsesMessages, o as runResponsesStreamLifecycle, r as createResponsesAssistantOutput, t as applyCommonResponsesParams } from "./openai-responses-shared-
|
|
3
|
+
import { n as getAiTransportHost } from "./host-XYGZcgO8.mjs";
|
|
4
|
+
import { D as buildBaseOptions } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
5
|
+
import { a as resolveResponsesReasoningEffort, n as convertResponsesMessages, o as runResponsesStreamLifecycle, r as createResponsesAssistantOutput, t as applyCommonResponsesParams } from "./openai-responses-shared-CzCurmY1.mjs";
|
|
6
6
|
import { i as resolveAzureDeploymentNameFromMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "./azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
7
|
-
import { a as clampOpenAIPromptCacheKey } from "./openai-tool-projection-
|
|
7
|
+
import { a as clampOpenAIPromptCacheKey } from "./openai-tool-projection-ITOU9bG1.mjs";
|
|
8
8
|
import OpenAI, { AzureOpenAI } from "openai";
|
|
9
9
|
//#region packages/ai/src/providers/azure-openai-responses.ts
|
|
10
10
|
const DEFAULT_AZURE_API_VERSION = "v1";
|
|
@@ -94,11 +94,8 @@ function resolveAzureConfig(model, options) {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
function createClient(model, apiKeyInput, options) {
|
|
97
|
-
|
|
98
|
-
if (!apiKey)
|
|
99
|
-
if (!process.env.AZURE_OPENAI_API_KEY) throw new Error("Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
100
|
-
apiKey = process.env.AZURE_OPENAI_API_KEY;
|
|
101
|
-
}
|
|
97
|
+
const apiKey = apiKeyInput.trim();
|
|
98
|
+
if (!apiKey) throw new Error("Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
102
99
|
const headers = { ...model.headers };
|
|
103
100
|
if (options?.headers) Object.assign(headers, options.headers);
|
|
104
101
|
const { baseUrl, apiVersion } = resolveAzureConfig(model, options);
|
|
@@ -82,7 +82,7 @@ function getProcEnv(key) {
|
|
|
82
82
|
return procEnvCache.get(key);
|
|
83
83
|
}
|
|
84
84
|
function getEnvValue(key) {
|
|
85
|
-
return getProcessEnv()?.[key] || getProcEnv(key);
|
|
85
|
+
return (getProcessEnv()?.[key] || getProcEnv(key))?.trim() || void 0;
|
|
86
86
|
}
|
|
87
87
|
let cachedVertexAdcCredentialsExists = null;
|
|
88
88
|
function hasVertexAdcCredentials() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as AssistantMessageEvent, i as AssistantMessage, o as AssistantMessageEventStreamContract } from "./types-
|
|
1
|
+
import { a as AssistantMessageEvent, i as AssistantMessage, o as AssistantMessageEventStreamContract } from "./types-AFwwWium.mjs";
|
|
2
2
|
|
|
3
3
|
//#region packages/llm-core/src/utils/event-stream.d.ts
|
|
4
4
|
/** Generic async-iterable event stream with a separately awaited final result. */
|
package/dist/event-stream.d.mts
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-Douf9dob.mjs";
|
|
2
2
|
export { AssistantMessageEventStream, EventStream, createAssistantMessageEventStream };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
1
|
+
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
3
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
-
import {
|
|
5
|
-
import { a as runGoogleGenerateContentLifecycle, i as getDisabledGoogleThinkingConfig, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-XYGZcgO8.mjs";
|
|
4
|
+
import { D as buildBaseOptions } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
5
|
+
import { a as runGoogleGenerateContentLifecycle, i as getDisabledGoogleThinkingConfig, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-CMLI-tCZ.mjs";
|
|
6
6
|
import { GoogleGenAI } from "@google/genai";
|
|
7
7
|
//#region packages/ai/src/providers/google.ts
|
|
8
8
|
let toolCallCounter = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as isImageWithMediaPayload, a as stripSystemPromptCacheBoundary, c as transformMessages, x as extractToolResultText, y as describeToolResultMediaPlaceholder } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
2
2
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { t as formatProviderError } from "./provider-error-
|
|
3
|
+
import { n as calculateCost, r as clampThinkingLevel } from "./model-utils-1GiZ2_rr.mjs";
|
|
4
|
+
import { t as formatProviderError } from "./provider-error-C4VvV_3t.mjs";
|
|
5
5
|
import { FinishReason, FunctionCallingConfigMode, ThinkingLevel } from "@google/genai";
|
|
6
6
|
//#region packages/ai/src/providers/google-shared.ts
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
2
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
3
|
-
import {
|
|
4
|
-
import { a as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-
|
|
2
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-XYGZcgO8.mjs";
|
|
3
|
+
import { D as buildBaseOptions } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
4
|
+
import { a as runGoogleGenerateContentLifecycle, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-CMLI-tCZ.mjs";
|
|
5
5
|
import { GoogleGenAI, ResourceScope } from "@google/genai";
|
|
6
6
|
//#region packages/ai/src/providers/google-vertex.ts
|
|
7
7
|
const API_VERSION = "v1";
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { E as Model, L as StreamFn, n as Api, u as Context } from "./types-AFwwWium.mjs";
|
|
2
|
+
import { n as ApiRegistry } from "./api-registry-BMphkFf1.mjs";
|
|
3
|
+
|
|
4
|
+
//#region packages/ai/src/host.d.ts
|
|
5
|
+
/** Provider capability facts needed by the package-owned transports. */
|
|
6
|
+
interface AiProviderRequestCapabilities {
|
|
7
|
+
endpointClass: string;
|
|
8
|
+
knownProviderFamily: string;
|
|
9
|
+
supportsNativeStreamingUsageCompat: boolean;
|
|
10
|
+
supportsOpenAICompletionsStreamingUsageCompat: boolean;
|
|
11
|
+
usesExplicitProxyLikeEndpoint: boolean;
|
|
12
|
+
allowsAnthropicServiceTier: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Transport-safe provider policy input kept independent of OpenClaw config types. */
|
|
15
|
+
interface AiProviderRequestPolicyInput {
|
|
16
|
+
provider?: string;
|
|
17
|
+
api?: string;
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
capability?: "llm" | "audio" | "image" | "video" | "other";
|
|
20
|
+
transport?: "stream" | "websocket" | "http" | "media-understanding";
|
|
21
|
+
modelId?: string | null;
|
|
22
|
+
compat?: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** Context shared by plugin-owned provider stream hooks. */
|
|
25
|
+
interface AiProviderStreamHookContext {
|
|
26
|
+
config?: unknown;
|
|
27
|
+
agentDir?: string;
|
|
28
|
+
workspaceDir?: string;
|
|
29
|
+
provider: string;
|
|
30
|
+
modelId: string;
|
|
31
|
+
model: Model;
|
|
32
|
+
}
|
|
33
|
+
/** Narrow plugin-runtime port used by package-owned transports. */
|
|
34
|
+
interface AiTransportPluginHost {
|
|
35
|
+
resolveProviderStream(this: void, params: {
|
|
36
|
+
provider: string;
|
|
37
|
+
config?: unknown;
|
|
38
|
+
workspaceDir?: string;
|
|
39
|
+
env?: NodeJS.ProcessEnv;
|
|
40
|
+
allowRuntimePluginLoad?: boolean;
|
|
41
|
+
context: AiProviderStreamHookContext;
|
|
42
|
+
}): StreamFn | undefined;
|
|
43
|
+
resolveTransportTurnState(this: void, params: {
|
|
44
|
+
provider: string;
|
|
45
|
+
modelId?: string | null;
|
|
46
|
+
config?: unknown;
|
|
47
|
+
workspaceDir?: string;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
allowRuntimePluginLoad?: boolean;
|
|
50
|
+
context: {
|
|
51
|
+
provider: string;
|
|
52
|
+
modelId: string;
|
|
53
|
+
model?: Model;
|
|
54
|
+
sessionId?: string;
|
|
55
|
+
turnId: string;
|
|
56
|
+
attempt: number;
|
|
57
|
+
transport: "stream" | "websocket";
|
|
58
|
+
};
|
|
59
|
+
}): {
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
metadata?: Record<string, string>;
|
|
62
|
+
} | undefined;
|
|
63
|
+
wrapSimpleCompletionStream(this: void, params: {
|
|
64
|
+
provider: string;
|
|
65
|
+
config?: unknown;
|
|
66
|
+
context: AiProviderStreamHookContext & {
|
|
67
|
+
streamFn: StreamFn;
|
|
68
|
+
};
|
|
69
|
+
}): StreamFn | undefined;
|
|
70
|
+
createAnthropicVertexStream(this: void, model: Pick<Model, "baseUrl">, env?: NodeJS.ProcessEnv): StreamFn;
|
|
71
|
+
}
|
|
72
|
+
/** Host-owned transcript normalization contract used immediately before provider projection. */
|
|
73
|
+
type AiTransformTransportMessages = (messages: Context["messages"], model: Model, normalizeToolCallId?: (id: string, targetModel: Model, source: {
|
|
74
|
+
provider: string;
|
|
75
|
+
api: Api;
|
|
76
|
+
model: string;
|
|
77
|
+
}) => string, options?: {
|
|
78
|
+
normalizeSameModelToolCallIds?: boolean;
|
|
79
|
+
preserveCrossModelToolCallThoughtSignature?: boolean;
|
|
80
|
+
}) => Context["messages"];
|
|
81
|
+
/** Strict-tool policy inputs for OpenAI-compatible routes. */
|
|
82
|
+
interface OpenAIStrictToolSettingOptions {
|
|
83
|
+
transport?: "stream" | "websocket";
|
|
84
|
+
supportsStrictMode?: boolean;
|
|
85
|
+
}
|
|
86
|
+
type AiInlineTextBlock = {
|
|
87
|
+
type: "text";
|
|
88
|
+
text: string;
|
|
89
|
+
};
|
|
90
|
+
type AiInlineImageBlock = {
|
|
91
|
+
type: "image";
|
|
92
|
+
data: string;
|
|
93
|
+
mimeType: string;
|
|
94
|
+
};
|
|
95
|
+
type AiInlineContentBlock = AiInlineTextBlock | AiInlineImageBlock;
|
|
96
|
+
type AnthropicInlineContentNormalizer = (content: readonly AiInlineContentBlock[]) => Promise<AiInlineContentBlock[]>;
|
|
97
|
+
/** Narrow host ports consumed by the built-in provider adapters. */
|
|
98
|
+
interface AiTransportHost {
|
|
99
|
+
/**
|
|
100
|
+
* Builds a policy-guarded fetch for one model request.
|
|
101
|
+
* Returning undefined keeps the provider SDK's default fetch.
|
|
102
|
+
*/
|
|
103
|
+
buildModelFetch(model: Model, timeoutMs?: number, options?: {
|
|
104
|
+
sanitizeSse?: boolean;
|
|
105
|
+
}): typeof fetch | undefined;
|
|
106
|
+
/** Resolves host-owned process-local secret sentinel substrings immediately before egress. */
|
|
107
|
+
resolveSecretSentinel(value: string): string;
|
|
108
|
+
/** Redacts secrets inside structured tool-result payloads. */
|
|
109
|
+
redactSecrets<T>(value: T): T;
|
|
110
|
+
/** Redacts secret-bearing text in tool payload strings. */
|
|
111
|
+
redactToolPayloadText(text: string): string;
|
|
112
|
+
/** Normalizes Anthropic inline image blocks before provider payload construction. */
|
|
113
|
+
normalizeAnthropicInlineContentBlocks?: AnthropicInlineContentNormalizer;
|
|
114
|
+
/**
|
|
115
|
+
* Resolves the host strict-tool default for OpenAI-compatible routes.
|
|
116
|
+
* undefined lets the request omit the strict flag entirely.
|
|
117
|
+
*/
|
|
118
|
+
resolveOpenAIStrictToolSetting(model: Pick<Model, "provider" | "api" | "baseUrl" | "id"> & {
|
|
119
|
+
compat?: unknown;
|
|
120
|
+
}, options?: OpenAIStrictToolSettingOptions): boolean | undefined;
|
|
121
|
+
/** Provider-plugin operations required by the generic package transports. */
|
|
122
|
+
plugin: AiTransportPluginHost;
|
|
123
|
+
/** Builds provider-owned Copilot compatibility headers for one message turn. */
|
|
124
|
+
buildCopilotDynamicHeaders(messages: Context["messages"]): Record<string, string>;
|
|
125
|
+
/** Resolves endpoint classification without importing core provider registries. */
|
|
126
|
+
resolveProviderEndpointClass(baseUrl?: string): string;
|
|
127
|
+
/** Resolves provider capability flags used by payload compatibility policy. */
|
|
128
|
+
resolveProviderRequestCapabilities(input: AiProviderRequestPolicyInput): AiProviderRequestCapabilities;
|
|
129
|
+
/** Merges host-owned provider request headers and attribution policy. */
|
|
130
|
+
resolveProviderRequestHeaders(input: {
|
|
131
|
+
provider?: string;
|
|
132
|
+
api?: string;
|
|
133
|
+
baseUrl?: string;
|
|
134
|
+
providerHeaders?: Record<string, string>;
|
|
135
|
+
callerHeaders?: Record<string, string>;
|
|
136
|
+
precedence?: "caller-wins" | "defaults-win";
|
|
137
|
+
}): Record<string, string> | undefined;
|
|
138
|
+
/** Returns the host-configured request timeout attached to a model. */
|
|
139
|
+
resolveModelRequestTimeoutMs(model: Model): number | undefined;
|
|
140
|
+
/** Reports whether the model carries host-managed proxy, TLS, or local-service state. */
|
|
141
|
+
requiresManagedTransport(model: Model): boolean;
|
|
142
|
+
/** Copies host-owned managed-transport state onto a projected model. */
|
|
143
|
+
inheritManagedTransport(source: Model, target: Model): Model;
|
|
144
|
+
/** Applies host-owned transcript replay and pairing rules. */
|
|
145
|
+
transformTransportMessages: AiTransformTransportMessages;
|
|
146
|
+
/** Registers a custom transport API with the host's stream error bridge. */
|
|
147
|
+
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
|
+
/**
|
|
151
|
+
* Emits one transport diagnostic; build runs only when the host logs it and
|
|
152
|
+
* may return null to suppress the entry (e.g. de-duplication).
|
|
153
|
+
*/
|
|
154
|
+
logDebug(subsystem: string, build: () => {
|
|
155
|
+
message: string;
|
|
156
|
+
data?: Record<string, unknown>;
|
|
157
|
+
} | null): void;
|
|
158
|
+
/** Emits an informational transport diagnostic through the host logger. */
|
|
159
|
+
logInfo(subsystem: string, message: string, data?: Record<string, unknown>): void;
|
|
160
|
+
/** Emits a warning through the host logger. */
|
|
161
|
+
logWarn(subsystem: string, message: string, data?: Record<string, unknown>): void;
|
|
162
|
+
}
|
|
163
|
+
type ActiveAiTransportHost = Omit<AiTransportHost, "normalizeAnthropicInlineContentBlocks"> & {
|
|
164
|
+
normalizeAnthropicInlineContentBlocks: AnthropicInlineContentNormalizer;
|
|
165
|
+
};
|
|
166
|
+
/** Installs host implementations for the transport policy ports. */
|
|
167
|
+
declare function configureAiTransportHost(host: Partial<AiTransportHost>): void;
|
|
168
|
+
/** Returns the active transport host (inert defaults unless configured). */
|
|
169
|
+
declare function getAiTransportHost(): ActiveAiTransportHost;
|
|
170
|
+
/** Resolves sentinel substrings in custom headers at a no-fetch adapter boundary. */
|
|
171
|
+
declare function resolveAiTransportHeaderSentinels(headers: Record<string, string> | undefined): Record<string, string> | undefined;
|
|
172
|
+
//#endregion
|
|
173
|
+
export { AiProviderRequestPolicyInput as a, AiTransportHost as c, configureAiTransportHost as d, getAiTransportHost as f, AiProviderRequestCapabilities as i, AiTransportPluginHost as l, AiInlineImageBlock as n, AiProviderStreamHookContext as o, resolveAiTransportHeaderSentinels as p, AiInlineTextBlock as r, AiTransformTransportMessages as s, AiInlineContentBlock as t, OpenAIStrictToolSettingOptions as u };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//#region packages/ai/src/host.ts
|
|
2
|
+
const MAX_PENDING_CUSTOM_API_REGISTRATIONS = 32;
|
|
3
|
+
const pendingCustomApiRegistrations = [];
|
|
4
|
+
function queueCustomApiRegistration(registry, api, streamFn) {
|
|
5
|
+
const existing = pendingCustomApiRegistrations.find((registration) => registration.registry === registry && registration.api === api);
|
|
6
|
+
if (existing) {
|
|
7
|
+
existing.streamFn = streamFn;
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (pendingCustomApiRegistrations.length >= MAX_PENDING_CUSTOM_API_REGISTRATIONS) throw new Error("Too many custom transport APIs were registered before host configuration");
|
|
11
|
+
pendingCustomApiRegistrations.push({
|
|
12
|
+
registry,
|
|
13
|
+
api,
|
|
14
|
+
streamFn
|
|
15
|
+
});
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const inertAiTransportHost = {
|
|
19
|
+
buildModelFetch: () => void 0,
|
|
20
|
+
resolveSecretSentinel: (value) => value,
|
|
21
|
+
redactSecrets: (value) => value,
|
|
22
|
+
redactToolPayloadText: (text) => text,
|
|
23
|
+
normalizeAnthropicInlineContentBlocks: async (content) => [...content],
|
|
24
|
+
resolveOpenAIStrictToolSetting: (_model, options) => options?.supportsStrictMode ? false : void 0,
|
|
25
|
+
plugin: {
|
|
26
|
+
resolveProviderStream: () => void 0,
|
|
27
|
+
resolveTransportTurnState: () => void 0,
|
|
28
|
+
wrapSimpleCompletionStream: () => void 0,
|
|
29
|
+
createAnthropicVertexStream: () => {
|
|
30
|
+
throw new Error("Anthropic Vertex transport is not configured by the embedding host");
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
buildCopilotDynamicHeaders: () => ({}),
|
|
34
|
+
resolveProviderEndpointClass: () => "default",
|
|
35
|
+
resolveProviderRequestCapabilities: () => ({
|
|
36
|
+
endpointClass: "default",
|
|
37
|
+
knownProviderFamily: "",
|
|
38
|
+
supportsNativeStreamingUsageCompat: false,
|
|
39
|
+
supportsOpenAICompletionsStreamingUsageCompat: false,
|
|
40
|
+
usesExplicitProxyLikeEndpoint: false,
|
|
41
|
+
allowsAnthropicServiceTier: false
|
|
42
|
+
}),
|
|
43
|
+
resolveProviderRequestHeaders: ({ providerHeaders, callerHeaders, precedence }) => ({
|
|
44
|
+
...precedence === "caller-wins" ? providerHeaders : callerHeaders,
|
|
45
|
+
...precedence === "caller-wins" ? callerHeaders : providerHeaders
|
|
46
|
+
}),
|
|
47
|
+
resolveModelRequestTimeoutMs: () => void 0,
|
|
48
|
+
requiresManagedTransport: () => false,
|
|
49
|
+
inheritManagedTransport: (_source, target) => target,
|
|
50
|
+
transformTransportMessages: (messages) => messages,
|
|
51
|
+
registerCustomApi: queueCustomApiRegistration,
|
|
52
|
+
prepareGoogleSimpleCompletionModel: (_registry, model) => model,
|
|
53
|
+
logDebug: () => {},
|
|
54
|
+
logInfo: () => {},
|
|
55
|
+
logWarn: () => {}
|
|
56
|
+
};
|
|
57
|
+
let activeAiTransportHost = inertAiTransportHost;
|
|
58
|
+
/** Installs host implementations for the transport policy ports. */
|
|
59
|
+
function configureAiTransportHost(host) {
|
|
60
|
+
activeAiTransportHost = {
|
|
61
|
+
...inertAiTransportHost,
|
|
62
|
+
...host,
|
|
63
|
+
normalizeAnthropicInlineContentBlocks: host.normalizeAnthropicInlineContentBlocks ?? inertAiTransportHost.normalizeAnthropicInlineContentBlocks,
|
|
64
|
+
plugin: {
|
|
65
|
+
...inertAiTransportHost.plugin,
|
|
66
|
+
...host.plugin
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const transportHost = activeAiTransportHost;
|
|
70
|
+
if (transportHost.registerCustomApi === inertAiTransportHost.registerCustomApi || pendingCustomApiRegistrations.length === 0) return;
|
|
71
|
+
const pending = pendingCustomApiRegistrations.splice(0);
|
|
72
|
+
for (const [index, registration] of pending.entries()) try {
|
|
73
|
+
transportHost.registerCustomApi(registration.registry, registration.api, registration.streamFn);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
pendingCustomApiRegistrations.unshift(...pending.slice(index));
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Returns the active transport host (inert defaults unless configured). */
|
|
80
|
+
function getAiTransportHost() {
|
|
81
|
+
return activeAiTransportHost;
|
|
82
|
+
}
|
|
83
|
+
/** Resolves sentinel substrings in custom headers at a no-fetch adapter boundary. */
|
|
84
|
+
function resolveAiTransportHeaderSentinels(headers) {
|
|
85
|
+
if (!headers) return;
|
|
86
|
+
const host = getAiTransportHost();
|
|
87
|
+
let resolvedHeaders;
|
|
88
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
89
|
+
const resolved = host.resolveSecretSentinel(value);
|
|
90
|
+
if (resolved !== value) {
|
|
91
|
+
resolvedHeaders ??= { ...headers };
|
|
92
|
+
resolvedHeaders[name] = resolved;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return resolvedHeaders ?? headers;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { getAiTransportHost as n, resolveAiTransportHeaderSentinels as r, configureAiTransportHost as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|