@openclaw/ai 2026.9.1-beta.1 → 2026.9.1
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-compaction-replay-nhKaCXu6.mjs → anthropic-compaction-replay-OMJZ0uyo.mjs} +37 -34
- package/dist/{anthropic-DI4PZKKB.mjs → anthropic-hk7F7ptG.mjs} +28 -25
- package/dist/{anthropic-payload-policy-B_0n0enE.d.mts → anthropic-payload-policy-DBT1itQ-.d.mts} +3 -3
- package/dist/{api-registry-CTd8NzcD.d.mts → api-registry-Cs6HGNqY.d.mts} +2 -2
- package/dist/{azure-openai-responses-D8dI0ekg.mjs → azure-openai-responses-CN4Fy5zV.mjs} +10 -7
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/{diagnostics-COpOtRwq.mjs → diagnostics-CPeq9F7y.mjs} +5 -1
- package/dist/{diagnostics-BaTA9eVl.d.mts → diagnostics-DnPnOui6.d.mts} +5 -1
- package/dist/diagnostics-KhXK-QJI.mjs +136 -0
- package/dist/diagnostics.d.mts +8 -3
- package/dist/diagnostics.mjs +4 -3
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/event-stream-DeDhbCc5.d.mts +1 -0
- package/dist/{event-stream-LiXePESD.d.mts → event-stream-vK_7r3bj.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/{google-Od-LLdVK.mjs → google-CC-nrwXg.mjs} +8 -6
- package/dist/{google-shared-Bgr9lFPw.mjs → google-shared-CjPY0hZM.mjs} +25 -23
- package/dist/{google-vertex-aerRSXc4.mjs → google-vertex-DCr0pyzQ.mjs} +7 -5
- package/dist/{host-D51fmkH6.mjs → host-BIaiBURL.mjs} +2 -2
- package/dist/{host-DsbPMFU6.d.mts → host-BztR4tQj.d.mts} +3 -3
- package/dist/index-AfaxKT8w.d.mts +111 -0
- package/dist/index.d.mts +10 -11
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +53 -52
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +2 -3
- package/dist/internal/openai.d.mts +65 -63
- package/dist/internal/openai.mjs +9 -9
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +43 -43
- package/dist/internal/runtime.mjs +10 -8
- package/dist/internal/shared.d.mts +25 -25
- package/dist/internal/shared.mjs +95 -4
- package/dist/{mistral-EiHdymeb.mjs → mistral-B7etBd_H.mjs} +25 -20
- package/dist/{openai-chatgpt-responses-DHpF9o1e.mjs → openai-chatgpt-responses-BAJ4gq3i.mjs} +63 -122
- package/dist/{openai-completions-EFPiUGfS.mjs → openai-completions-D0QZ0AyB.mjs} +24 -20
- package/dist/{openai-completions-compat-BefmHT26.d.mts → openai-completions-compat-4IjSBpr6.d.mts} +5 -5
- package/dist/{openai-completions-stream-DUlGwRMz.mjs → openai-completions-stream-DZjwK8vp.mjs} +97 -90
- package/dist/{openai-responses-BogP8OjX.mjs → openai-responses-BEUlxfDu.mjs} +12 -8
- package/dist/openai-responses-compaction-window-DO7yV7az.mjs +686 -0
- package/dist/{openai-responses-contracts-Dvj_UtPy.d.mts → openai-responses-contracts-bPzSN_Ba.d.mts} +14 -5
- package/dist/{openai-responses-payload-policy-CNGFT9zr.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +1 -0
- package/dist/{openai-responses-prompt-observer-internal-Cd4hJG-S.mjs → openai-responses-prompt-observer-internal-C7x4IK7r.mjs} +4 -18
- package/dist/{openai-responses-shared-DJThc6jW.mjs → openai-responses-shared-DiAdpNAM.mjs} +274 -221
- package/dist/{openai-tool-schema-ho-hIkQf.mjs → openai-tool-schema-BMiHFH36.mjs} +14 -12
- package/dist/{provider-error-DDOs_Bz0.mjs → provider-error-B6EGq6gg.mjs} +14 -85
- package/dist/{provider-options-MdMBLzlU.d.mts → provider-options-CxFPtvh7.d.mts} +11 -3
- package/dist/{provider-transcript-transform-C01bQ5a3.mjs → provider-transcript-transform-WvJmFUAf.mjs} +1 -1
- package/dist/provider-types.d.mts +19 -20
- package/dist/providers.d.mts +5 -5
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-C-4uedDb.mjs} +93 -77
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-DCkltN94.mjs → sanitize-unicode-S6binQG-.mjs} +2 -8
- package/dist/{simple-options-CFj7x3J4.mjs → simple-options-0PLDyJ-d.mjs} +42 -6
- package/dist/{src-Bu3FiFAG.mjs → src-C8U7lkoa.mjs} +75 -2
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{tool-schema-json-projection-qvTEs5Am.mjs → tool-schema-json-projection-BtZiml7r.mjs} +21 -31
- package/dist/{transport-stream-shared-rvaCyFYt.d.mts → transport-stream-shared-BrvFTkoO.d.mts} +5 -5
- package/dist/{transport-stream-shared-ljShVIZB.mjs → transport-stream-shared-CytPVLIg.mjs} +18 -5
- package/dist/{transport-utils-LJ1_rbi-.mjs → transport-utils-CtuS1Upe.mjs} +5 -8
- package/dist/transports.d.mts +120 -85
- package/dist/transports.mjs +218 -249
- package/dist/types-B5EFUmXs.d.mts +1 -0
- package/dist/{types-DhLoJbFm.d.mts → types-DbrhszyQ.d.mts} +27 -13
- package/dist/types.d.mts +7 -7
- package/dist/types.mjs +4 -4
- package/dist/{validation-Dk7q7NMN.d.mts → validation-BOwtcl9X.d.mts} +1 -1
- package/dist/{validation-B61OhAio.mjs → validation-CJZtym2g.mjs} +7 -5
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +5 -5
- package/dist/anthropic-BECQCNdF.d.mts +0 -98
- package/dist/event-stream-BKp4fOt_.d.mts +0 -1
- package/dist/index-Qbej8io0.d.mts +0 -3
- package/dist/openai-responses-contracts-QUY12X0B.mjs +0 -233
- package/dist/openai-responses-payload-policy-D8EdimYe.mjs +0 -204
- package/dist/provider-options-AvldWZt8.mjs +0 -21
- package/dist/tls-certificate-errors-DXSpluKI.mjs +0 -93
- package/dist/types-GiAjXatj.d.mts +0 -1
package/dist/{anthropic-compaction-replay-nhKaCXu6.mjs → anthropic-compaction-replay-OMJZ0uyo.mjs}
RENAMED
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as resolveClaudeFable5ModelIdentity, p as resolveClaudeOpus5ModelIdentity, u as resolveClaudeModelIdentity } from "./src-C8U7lkoa.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-
|
|
4
|
-
import { a as estimateBase64DecodedBytes } from "./
|
|
5
|
-
import { r as asNonNegativeFiniteNumber } from "./number-coercion-H9qHik3g.mjs";
|
|
3
|
+
import { n as getAiTransportHost } from "./host-BIaiBURL.mjs";
|
|
4
|
+
import { a as asNonNegativeFiniteNumber, n as estimateBase64DecodedBytes } from "./base64-CEFBpSkN.mjs";
|
|
6
5
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { a as resolveProviderEndpoint, o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-
|
|
9
|
-
import { s as parsePositiveInteger } from "./transport-utils-
|
|
6
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, u as splitSystemPromptCacheBoundary } from "./simple-options-0PLDyJ-d.mjs";
|
|
7
|
+
import { a as resolveProviderEndpoint, o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-BtZiml7r.mjs";
|
|
8
|
+
import { s as parsePositiveInteger } from "./transport-utils-CtuS1Upe.mjs";
|
|
10
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
+
//#region packages/ai/src/providers/anthropic-auth-headers.ts
|
|
11
|
+
/** Inspect resolved credential shape for auth routing without exposing its value. */
|
|
12
|
+
function isAnthropicOAuthApiKey(apiKey) {
|
|
13
|
+
return typeof apiKey === "string" && getAiTransportHost().resolveSecretSentinel(apiKey).includes("sk-ant-oat");
|
|
14
|
+
}
|
|
15
|
+
function usesFoundryBearerAuth(model) {
|
|
16
|
+
return model.provider === "microsoft-foundry" && (model.authHeader === true || hasBearerAuthorizationHeader(model.headers));
|
|
17
|
+
}
|
|
18
|
+
function hasBearerAuthorizationHeader(headers) {
|
|
19
|
+
if (!headers) return false;
|
|
20
|
+
return Object.entries(headers).some(([key, value]) => key.toLowerCase() === "authorization" && /^bearer\s+\S+/i.test(value.trim()));
|
|
21
|
+
}
|
|
22
|
+
function omitFoundryBearerCredentialHeaders(headers) {
|
|
23
|
+
if (!headers) return;
|
|
24
|
+
const next = {};
|
|
25
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
26
|
+
const lower = key.toLowerCase();
|
|
27
|
+
if (lower === "authorization" || lower === "x-api-key" || lower === "api-key") continue;
|
|
28
|
+
next[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return Object.keys(next).length > 0 ? next : void 0;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
11
33
|
//#region packages/ai/src/transports/anthropic-payload-policy.ts
|
|
12
34
|
/**
|
|
13
35
|
* Anthropic-family request payload policy helpers.
|
|
@@ -24,11 +46,11 @@ function resolveAnthropicCompactThreshold(contextWindow, configured) {
|
|
|
24
46
|
return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, resolvedContextWindow === void 0 ? ANTHROPIC_COMPACT_THRESHOLD_MIN : Math.floor(resolvedContextWindow * .7));
|
|
25
47
|
}
|
|
26
48
|
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
27
|
-
function resolveAnthropicServerCompactionPlan(model, extraParams) {
|
|
49
|
+
function resolveAnthropicServerCompactionPlan(model, extraParams, apiKey) {
|
|
28
50
|
const provider = normalizeOptionalLowercaseString(model.provider);
|
|
29
51
|
const api = normalizeOptionalLowercaseString(model.api);
|
|
30
52
|
const endpointClass = resolveProviderEndpoint(model).endpointClass;
|
|
31
|
-
const enabled = extraParams?.anthropicServerCompaction === true && provider === "anthropic" && api === "anthropic-messages" && (endpointClass === "default" || endpointClass === "anthropic-public");
|
|
53
|
+
const enabled = extraParams?.anthropicServerCompaction === true && !isAnthropicOAuthApiKey(apiKey) && provider === "anthropic" && api === "anthropic-messages" && (endpointClass === "default" || endpointClass === "anthropic-public");
|
|
32
54
|
return {
|
|
33
55
|
enabled,
|
|
34
56
|
...enabled ? { threshold: resolveAnthropicCompactThreshold(model.contextWindow, extraParams?.anthropicCompactThreshold) } : {}
|
|
@@ -218,7 +240,7 @@ const ANTHROPIC_IMAGE_MEDIA_TYPE_SET = /* @__PURE__ */ new Set([
|
|
|
218
240
|
"image/gif",
|
|
219
241
|
"image/webp"
|
|
220
242
|
]);
|
|
221
|
-
const ANTHROPIC_INLINE_IMAGES_DECODE_SAFETY_BYTES =
|
|
243
|
+
const ANTHROPIC_INLINE_IMAGES_DECODE_SAFETY_BYTES = 67108864;
|
|
222
244
|
function createAnthropicInlineImageBudget() {
|
|
223
245
|
return { totalBytes: 0 };
|
|
224
246
|
}
|
|
@@ -245,25 +267,6 @@ async function normalizeAnthropicInlineContent(content, budget) {
|
|
|
245
267
|
return normalized;
|
|
246
268
|
}
|
|
247
269
|
//#endregion
|
|
248
|
-
//#region packages/ai/src/providers/anthropic-auth-headers.ts
|
|
249
|
-
function usesFoundryBearerAuth(model) {
|
|
250
|
-
return model.provider === "microsoft-foundry" && (model.authHeader === true || hasBearerAuthorizationHeader(model.headers));
|
|
251
|
-
}
|
|
252
|
-
function hasBearerAuthorizationHeader(headers) {
|
|
253
|
-
if (!headers) return false;
|
|
254
|
-
return Object.entries(headers).some(([key, value]) => key.toLowerCase() === "authorization" && /^bearer\s+\S+/i.test(value.trim()));
|
|
255
|
-
}
|
|
256
|
-
function omitFoundryBearerCredentialHeaders(headers) {
|
|
257
|
-
if (!headers) return;
|
|
258
|
-
const next = {};
|
|
259
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
260
|
-
const lower = key.toLowerCase();
|
|
261
|
-
if (lower === "authorization" || lower === "x-api-key" || lower === "api-key") continue;
|
|
262
|
-
next[key] = value;
|
|
263
|
-
}
|
|
264
|
-
return Object.keys(next).length > 0 ? next : void 0;
|
|
265
|
-
}
|
|
266
|
-
//#endregion
|
|
267
270
|
//#region packages/ai/src/providers/anthropic-refusal.ts
|
|
268
271
|
function readAnthropicRefusalDetails(value) {
|
|
269
272
|
if (!value || typeof value !== "object") return {
|
|
@@ -665,9 +668,9 @@ function applyAnthropicMessageStartUsage(target, payload) {
|
|
|
665
668
|
};
|
|
666
669
|
return promptTokens > 0 ? promptUsage : void 0;
|
|
667
670
|
}
|
|
668
|
-
/** Keep
|
|
669
|
-
function applyAnthropicMessageDeltaUsage(target,
|
|
670
|
-
|
|
671
|
+
/** Keep billing and context distinct; omitted usage preserves the last snapshot. */
|
|
672
|
+
function applyAnthropicMessageDeltaUsage(target, usage, messageStartPromptUsage) {
|
|
673
|
+
if (!usage) return;
|
|
671
674
|
const billedIterations = readAnthropicCompactionBilledUsage(usage.iterations);
|
|
672
675
|
const inputTokens = readAnthropicUsageTokenCount(usage.input_tokens);
|
|
673
676
|
const outputTokens = readAnthropicUsageTokenCount(usage.output_tokens);
|
|
@@ -693,7 +696,7 @@ function applyAnthropicMessageDeltaUsage(target, payload, messageStartPromptUsag
|
|
|
693
696
|
totalTokens: iterationUsage.usage.totalTokens
|
|
694
697
|
};
|
|
695
698
|
else if (iterationUsage.state === "invalid") target.contextUsage = { state: "unavailable" };
|
|
696
|
-
else if (outputTokens !== void 0 && (messageStartPromptUsage !== void 0 ||
|
|
699
|
+
else if (outputTokens !== void 0 && (messageStartPromptUsage !== void 0 || (cacheReadTokens !== void 0 || cacheWriteTokens !== void 0) && readAnthropicPromptUsageSnapshot(usage) !== void 0)) {
|
|
697
700
|
const promptTokens = target.input + target.cacheRead + target.cacheWrite;
|
|
698
701
|
target.contextUsage = {
|
|
699
702
|
state: "available",
|
|
@@ -832,4 +835,4 @@ function isAnthropicReplayRejection(error) {
|
|
|
832
835
|
return (record.status === 400 || text.startsWith("http 400:")) && (text.includes("compaction") || text.includes("context_management"));
|
|
833
836
|
}
|
|
834
837
|
//#endregion
|
|
835
|
-
export {
|
|
838
|
+
export { applyAnthropicCacheControlToMessages as A, applyAnthropicFallbackBoundary as C, createAnthropicInlineImageBudget as D, applyAnthropicRefusal as E, resolveAnthropicServerCompactionPlan as F, isAnthropicOAuthApiKey as I, omitFoundryBearerCredentialHeaders as L, applyAnthropicPayloadPolicyToParams as M, resolveAnthropicEphemeralCacheControl as N, normalizeAnthropicInlineContent as O, resolveAnthropicPayloadPolicy as P, usesFoundryBearerAuth as R, CLAUDE_OPUS_FALLBACK_MODEL_COST as S, resolveAnthropicFallbackServingModelCost as T, toClaudeCodeToolName as _, suppressAnthropicCompaction as a, ANTHROPIC_SERVER_SIDE_FALLBACKS as b, readAnthropicCacheWriteUsage as c, readLastAnthropicIterationUsage as d, normalizeAnthropicToolCallId as f, resolveOriginalAnthropicToolName as g, reconcileAnthropicToolChoice as h, resolveNewestAnthropicCompaction as i, applyAnthropicEphemeralCacheControlMarkers as j, resolveAnthropicImageMediaType 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, readAnthropicFallbackBoundary as w, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as x, findActiveAnthropicToolTurnAssistantIndex as y };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { g as supportsClaudeAdaptiveThinking, m as resolveClaudeSonnet5ModelIdentity, p as resolveClaudeOpus5ModelIdentity, y as supportsClaudeNativeXhighEffort } from "./src-C8U7lkoa.mjs";
|
|
3
3
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
4
4
|
import { o as isRecord } from "./utf16-slice-qz3nsy87.mjs";
|
|
5
|
-
import { r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
6
|
-
import { S as usesClaudeStreamingRefusalContract, _ as prepareClaudeNoPrefillRequestContext, a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, f as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, g as mapAnthropicStopReason, m as applyClaudeRequestContract, n as getAiTransportHost, p as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as extractToolResultBlockText, v as requiresClaudeAdaptiveThinking, x as usesClaudeFable5MessagesContract, y as resolveAnthropicThinkingEffort } from "./host-
|
|
7
|
-
import { n as
|
|
5
|
+
import { r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-S6binQG-.mjs";
|
|
6
|
+
import { S as usesClaudeStreamingRefusalContract, _ as prepareClaudeNoPrefillRequestContext, a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, f as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, g as mapAnthropicStopReason, m as applyClaudeRequestContract, n as getAiTransportHost, p as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as extractToolResultBlockText, v as requiresClaudeAdaptiveThinking, x as usesClaudeFable5MessagesContract, y as resolveAnthropicThinkingEffort } from "./host-BIaiBURL.mjs";
|
|
7
|
+
import { A as applyAnthropicCacheControlToMessages, C as applyAnthropicFallbackBoundary, D as createAnthropicInlineImageBudget, E as applyAnthropicRefusal, I as isAnthropicOAuthApiKey, L as omitFoundryBearerCredentialHeaders, O as normalizeAnthropicInlineContent, R as usesFoundryBearerAuth, T as resolveAnthropicFallbackServingModelCost, _ as toClaudeCodeToolName, a as suppressAnthropicCompaction, b as ANTHROPIC_SERVER_SIDE_FALLBACKS, f as normalizeAnthropicToolCallId, g as resolveOriginalAnthropicToolName, h as reconcileAnthropicToolChoice, k as resolveAnthropicImageMediaType, m as projectAnthropicTools, n as createCompactionCapture, o as applyAnthropicMessageDeltaUsage, p as normalizeAnthropicToolChoice, r as isAnthropicReplayRejection, s as applyAnthropicMessageStartUsage, t as buildAnthropicReplayPlan, v as ANTHROPIC_OMITTED_REASONING_TEXT, w as readAnthropicFallbackBoundary, x as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, y as findActiveAnthropicToolTurnAssistantIndex } from "./anthropic-compaction-replay-OMJZ0uyo.mjs";
|
|
8
8
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-
|
|
11
|
-
import {
|
|
12
|
-
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-
|
|
9
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking, u as splitSystemPromptCacheBoundary } from "./simple-options-0PLDyJ-d.mjs";
|
|
10
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-CtuS1Upe.mjs";
|
|
11
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
12
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments, t as assignTransportErrorDetails } from "./transport-stream-shared-CytPVLIg.mjs";
|
|
13
13
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
14
14
|
import { n as parseJsonWithRepair, r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
15
15
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
16
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
16
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-WvJmFUAf.mjs";
|
|
17
17
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
18
18
|
import Anthropic from "@anthropic-ai/sdk";
|
|
19
19
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
@@ -191,7 +191,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
191
191
|
const sdkRequestOptions = {
|
|
192
192
|
...requestOptions?.signal ? { signal: requestOptions.signal } : {},
|
|
193
193
|
...requestOptions?.timeoutMs !== void 0 ? { timeout: requestOptions.timeoutMs } : {},
|
|
194
|
-
maxRetries:
|
|
194
|
+
maxRetries: 0
|
|
195
195
|
};
|
|
196
196
|
const response = await client.messages.create({
|
|
197
197
|
...params,
|
|
@@ -397,9 +397,11 @@ const streamAnthropic = (model, context, options) => {
|
|
|
397
397
|
});
|
|
398
398
|
}
|
|
399
399
|
} else if (event.type === "message_delta") {
|
|
400
|
-
if (event.delta.stop_reason)
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
if (event.delta.stop_reason) {
|
|
401
|
+
if (event.delta.stop_reason === "refusal") applyAnthropicRefusal(output, event.delta.stop_details, model.provider);
|
|
402
|
+
else output.stopReason = mapAnthropicStopReason(event.delta.stop_reason);
|
|
403
|
+
}
|
|
404
|
+
applyAnthropicMessageDeltaUsage(output.usage, event.usage, messageStartPromptUsage);
|
|
403
405
|
calculateCost(costModel, output.usage);
|
|
404
406
|
}
|
|
405
407
|
if (requestOptions?.signal?.aborted) throw transportAbortError(requestOptions.signal);
|
|
@@ -423,6 +425,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
423
425
|
});
|
|
424
426
|
stream.end();
|
|
425
427
|
} catch (error) {
|
|
428
|
+
const terminal = assignTransportErrorDetails(output, error, requestOptions?.signal);
|
|
426
429
|
output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
427
430
|
for (const block of output.content) {
|
|
428
431
|
delete block.index;
|
|
@@ -433,8 +436,6 @@ const streamAnthropic = (model, context, options) => {
|
|
|
433
436
|
output.content = [];
|
|
434
437
|
}
|
|
435
438
|
if (usedCompactionReplay && isAnthropicReplayRejection(error)) suppressAnthropicCompaction(output, model, requestOptions);
|
|
436
|
-
const terminal = projectProviderError(error, requestOptions?.signal);
|
|
437
|
-
Object.assign(output, terminal);
|
|
438
439
|
stream.push({
|
|
439
440
|
type: "error",
|
|
440
441
|
reason: terminal.stopReason,
|
|
@@ -500,9 +501,6 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
500
501
|
thinkingBudgetTokens: thinkingEnabled ? adjusted.thinkingBudget : void 0
|
|
501
502
|
});
|
|
502
503
|
};
|
|
503
|
-
function isOAuthToken(apiKey) {
|
|
504
|
-
return getAiTransportHost().resolveSecretSentinel(apiKey).includes("sk-ant-oat");
|
|
505
|
-
}
|
|
506
504
|
function isAnthropicPublicEndpoint(baseUrl) {
|
|
507
505
|
if (!baseUrl) return true;
|
|
508
506
|
try {
|
|
@@ -539,7 +537,8 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
539
537
|
Authorization: null,
|
|
540
538
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
541
539
|
}, model.headers, optionsHeaders),
|
|
542
|
-
fetch
|
|
540
|
+
fetch,
|
|
541
|
+
maxRetries: 0
|
|
543
542
|
}),
|
|
544
543
|
isOAuthToken: false,
|
|
545
544
|
serverSideFallback: false
|
|
@@ -555,7 +554,8 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
555
554
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
556
555
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
557
556
|
}, model.headers, dynamicHeaders, optionsHeaders),
|
|
558
|
-
fetch
|
|
557
|
+
fetch,
|
|
558
|
+
maxRetries: 0
|
|
559
559
|
}),
|
|
560
560
|
isOAuthToken: false,
|
|
561
561
|
serverSideFallback: false
|
|
@@ -574,12 +574,13 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
574
574
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
575
575
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
576
576
|
}, omitFoundryBearerCredentialHeaders(model.headers), dynamicHeaders, optionsHeaders),
|
|
577
|
-
fetch
|
|
577
|
+
fetch,
|
|
578
|
+
maxRetries: 0
|
|
578
579
|
}),
|
|
579
580
|
isOAuthToken: false,
|
|
580
581
|
serverSideFallback: false
|
|
581
582
|
};
|
|
582
|
-
if (
|
|
583
|
+
if (isAnthropicOAuthApiKey(apiKey)) return {
|
|
583
584
|
client: new Anthropic({
|
|
584
585
|
apiKey: null,
|
|
585
586
|
authToken: apiKey,
|
|
@@ -596,7 +597,8 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
596
597
|
"user-agent": `claude-cli/${ANTHROPIC_CLAUDE_CODE_VERSION}`,
|
|
597
598
|
"x-app": "cli"
|
|
598
599
|
}, model.headers, optionsHeaders),
|
|
599
|
-
fetch
|
|
600
|
+
fetch,
|
|
601
|
+
maxRetries: 0
|
|
600
602
|
}),
|
|
601
603
|
isOAuthToken: true,
|
|
602
604
|
serverSideFallback: false
|
|
@@ -615,7 +617,8 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
615
617
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
616
618
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
617
619
|
}, sessionAffinityHeaders, model.headers, optionsHeaders),
|
|
618
|
-
fetch
|
|
620
|
+
fetch,
|
|
621
|
+
maxRetries: 0
|
|
619
622
|
}),
|
|
620
623
|
isOAuthToken: false,
|
|
621
624
|
serverSideFallback
|
package/dist/{anthropic-payload-policy-B_0n0enE.d.mts → anthropic-payload-policy-DBT1itQ-.d.mts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
1
|
+
import "./index-AfaxKT8w.mjs";
|
|
2
|
+
import { D as Model } from "./types-DbrhszyQ.mjs";
|
|
3
3
|
//#region packages/ai/src/transports/anthropic-payload-policy.d.ts
|
|
4
4
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
5
5
|
type AnthropicServiceTier = "auto" | "standard_only";
|
|
@@ -33,7 +33,7 @@ declare function resolveAnthropicServerCompactionPlan(model: {
|
|
|
33
33
|
api?: unknown;
|
|
34
34
|
baseUrl?: string;
|
|
35
35
|
contextWindow?: unknown;
|
|
36
|
-
}, extraParams?: Record<string, unknown
|
|
36
|
+
}, extraParams?: Record<string, unknown>, apiKey?: string): {
|
|
37
37
|
enabled: boolean;
|
|
38
38
|
threshold?: number;
|
|
39
39
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
1
|
+
import "./index-AfaxKT8w.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-DbrhszyQ.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 { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
1
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
2
|
+
import { n as getAiTransportHost } from "./host-BIaiBURL.mjs";
|
|
4
3
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
5
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
6
|
-
import {
|
|
4
|
+
import { n as buildBaseOptions } from "./simple-options-0PLDyJ-d.mjs";
|
|
5
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
6
|
+
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-DiAdpNAM.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
|
|
@@ -25,10 +25,11 @@ function resolveDeploymentName(model, options) {
|
|
|
25
25
|
*/
|
|
26
26
|
const streamAzureOpenAIResponses = (model, context, options) => {
|
|
27
27
|
const stream = new AssistantMessageEventStream();
|
|
28
|
+
const output = createResponsesAssistantOutput(model, "azure-openai-responses");
|
|
28
29
|
runResponsesStreamLifecycle({
|
|
29
30
|
stream,
|
|
30
31
|
model,
|
|
31
|
-
output
|
|
32
|
+
output,
|
|
32
33
|
options,
|
|
33
34
|
resolveRequestModel: (requestModel) => {
|
|
34
35
|
const { baseUrl } = resolveAzureConfig(requestModel, options);
|
|
@@ -103,7 +104,8 @@ function createClient(model, apiKeyInput, options) {
|
|
|
103
104
|
dangerouslyAllowBrowser: true,
|
|
104
105
|
defaultHeaders: headers,
|
|
105
106
|
baseURL: baseUrl,
|
|
106
|
-
fetch: guardedFetch
|
|
107
|
+
fetch: guardedFetch,
|
|
108
|
+
maxRetries: 0
|
|
107
109
|
});
|
|
108
110
|
return new AzureOpenAI({
|
|
109
111
|
apiKey,
|
|
@@ -111,7 +113,8 @@ function createClient(model, apiKeyInput, options) {
|
|
|
111
113
|
dangerouslyAllowBrowser: true,
|
|
112
114
|
defaultHeaders: headers,
|
|
113
115
|
baseURL: baseUrl,
|
|
114
|
-
fetch: guardedFetch
|
|
116
|
+
fetch: guardedFetch,
|
|
117
|
+
maxRetries: 0
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
120
|
function buildParams(model, context, options, deploymentName, replayMode = "checkpoint") {
|
|
@@ -68,4 +68,76 @@ function parseStrictNonNegativeInteger(value) {
|
|
|
68
68
|
return parsed !== void 0 && parsed >= 0 ? parsed : void 0;
|
|
69
69
|
}
|
|
70
70
|
//#endregion
|
|
71
|
-
|
|
71
|
+
//#region packages/media-core/src/base64.ts
|
|
72
|
+
/** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
|
|
73
|
+
function estimateBase64DecodedBytes(base64) {
|
|
74
|
+
let effectiveLen = 0;
|
|
75
|
+
for (let i = 0; i < base64.length; i += 1) {
|
|
76
|
+
if (base64.charCodeAt(i) <= 32) continue;
|
|
77
|
+
effectiveLen += 1;
|
|
78
|
+
}
|
|
79
|
+
if (effectiveLen === 0) return 0;
|
|
80
|
+
let padding = 0;
|
|
81
|
+
let end = base64.length - 1;
|
|
82
|
+
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
83
|
+
if (end >= 0 && base64[end] === "=") {
|
|
84
|
+
padding = 1;
|
|
85
|
+
end -= 1;
|
|
86
|
+
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
87
|
+
if (end >= 0 && base64[end] === "=") padding = 2;
|
|
88
|
+
}
|
|
89
|
+
const estimated = Math.floor(effectiveLen * 3 / 4) - padding;
|
|
90
|
+
return Math.max(0, estimated);
|
|
91
|
+
}
|
|
92
|
+
function isBase64DataChar(code) {
|
|
93
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47;
|
|
94
|
+
}
|
|
95
|
+
function base64DataValue(code) {
|
|
96
|
+
if (code >= 65 && code <= 90) return code - 65;
|
|
97
|
+
if (code >= 97 && code <= 122) return code - 97 + 26;
|
|
98
|
+
if (code >= 48 && code <= 57) return code - 48 + 52;
|
|
99
|
+
return code === 43 ? 62 : 63;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Normalizes and validates a base64 string, returning canonical no-whitespace
|
|
103
|
+
* base64 only when the input has valid alphabet, padding, and length.
|
|
104
|
+
*/
|
|
105
|
+
function canonicalizeBase64(base64) {
|
|
106
|
+
let out;
|
|
107
|
+
let outLen = 0;
|
|
108
|
+
let padding = 0;
|
|
109
|
+
let sawPadding = false;
|
|
110
|
+
let lastDataCode = 0;
|
|
111
|
+
for (let i = 0; i < base64.length; i += 1) {
|
|
112
|
+
const code = base64.charCodeAt(i);
|
|
113
|
+
if (code <= 32) {
|
|
114
|
+
if (out === void 0) {
|
|
115
|
+
out = Buffer.allocUnsafe(base64.length - 1);
|
|
116
|
+
for (let j = 0; j < i; j += 1) out[j] = base64.charCodeAt(j);
|
|
117
|
+
outLen = i;
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (code === 61) {
|
|
122
|
+
padding += 1;
|
|
123
|
+
if (padding > 2) return;
|
|
124
|
+
sawPadding = true;
|
|
125
|
+
} else if (sawPadding || !isBase64DataChar(code)) return;
|
|
126
|
+
else lastDataCode = code;
|
|
127
|
+
if (out !== void 0) {
|
|
128
|
+
out[outLen] = code;
|
|
129
|
+
outLen += 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const cleanedLength = out === void 0 ? base64.length : outLen;
|
|
133
|
+
if (cleanedLength === 0) return;
|
|
134
|
+
const remainder = cleanedLength % 4;
|
|
135
|
+
if (remainder !== 0 && (sawPadding || remainder === 1)) return;
|
|
136
|
+
const effectivePadding = remainder === 0 ? padding : 4 - remainder;
|
|
137
|
+
const padBitMask = effectivePadding === 2 ? 15 : effectivePadding === 1 ? 3 : 0;
|
|
138
|
+
if (padBitMask !== 0 && (base64DataValue(lastDataCode) & padBitMask) !== 0) return;
|
|
139
|
+
const cleaned = out === void 0 ? base64 : out.subarray(0, outLen).toString("latin1");
|
|
140
|
+
return remainder === 0 ? cleaned : cleaned + "=".repeat(4 - remainder);
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { asNonNegativeFiniteNumber as a, parseStrictNonNegativeInteger as c, asFiniteNumberInRange as i, parseStrictPositiveInteger as l, estimateBase64DecodedBytes as n, clampTimerTimeoutMs as o, asFiniteNumber as r, parseStrictFiniteNumber as s, canonicalizeBase64 as t, resolveTimerTimeoutMs as u };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
//#region packages/llm-core/src/utils/diagnostics.ts
|
|
2
|
+
/** True when the provider explicitly refused the request payload. */
|
|
3
|
+
function isProviderRefusalAssistantError(message) {
|
|
4
|
+
return Boolean(message?.diagnostics?.some((diagnostic) => diagnostic.type === "provider_refusal"));
|
|
5
|
+
}
|
|
2
6
|
/** Formats arbitrary thrown values into diagnostic-safe text. */
|
|
3
7
|
function formatThrownValue(value) {
|
|
4
8
|
if (value instanceof Error) return value.message || value.name;
|
|
@@ -33,4 +37,4 @@ function appendAssistantMessageDiagnostic(message, diagnostic) {
|
|
|
33
37
|
message.diagnostics = [...message.diagnostics ?? [], diagnostic];
|
|
34
38
|
}
|
|
35
39
|
//#endregion
|
|
36
|
-
export { formatThrownValue as i, createAssistantMessageDiagnostic as n, extractDiagnosticError as r, appendAssistantMessageDiagnostic as t };
|
|
40
|
+
export { isProviderRefusalAssistantError as a, formatThrownValue as i, createAssistantMessageDiagnostic as n, extractDiagnosticError as r, appendAssistantMessageDiagnostic as t };
|
|
@@ -11,6 +11,10 @@ interface AssistantMessageDiagnostic {
|
|
|
11
11
|
error?: DiagnosticErrorInfo;
|
|
12
12
|
details?: Record<string, unknown>;
|
|
13
13
|
}
|
|
14
|
+
/** True when the provider explicitly refused the request payload. */
|
|
15
|
+
declare function isProviderRefusalAssistantError(message: {
|
|
16
|
+
diagnostics?: AssistantMessageDiagnostic[];
|
|
17
|
+
} | null | undefined): boolean;
|
|
14
18
|
/** Formats arbitrary thrown values into diagnostic-safe text. */
|
|
15
19
|
declare function formatThrownValue(value: unknown): string;
|
|
16
20
|
/** Extracts serializable diagnostic error fields from Error and non-Error throws. */
|
|
@@ -22,4 +26,4 @@ declare function appendAssistantMessageDiagnostic(message: {
|
|
|
22
26
|
diagnostics?: AssistantMessageDiagnostic[];
|
|
23
27
|
}, diagnostic: AssistantMessageDiagnostic): void;
|
|
24
28
|
//#endregion
|
|
25
|
-
export { extractDiagnosticError as a, createAssistantMessageDiagnostic as i, DiagnosticErrorInfo as n, formatThrownValue as o, appendAssistantMessageDiagnostic as r, AssistantMessageDiagnostic as t };
|
|
29
|
+
export { extractDiagnosticError as a, createAssistantMessageDiagnostic as i, DiagnosticErrorInfo as n, formatThrownValue as o, appendAssistantMessageDiagnostic as r, isProviderRefusalAssistantError as s, AssistantMessageDiagnostic as t };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { c as normalizeLowercaseStringOrEmpty } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
+
import "./provider-error-B6EGq6gg.mjs";
|
|
3
|
+
//#region packages/normalization-core/src/error-coercion.ts
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes an unknown thrown value into an Error. Non-Error objects become
|
|
6
|
+
* the `cause` and have their enumerable fields copied so structured details
|
|
7
|
+
* (codes, statuses) survive the coercion.
|
|
8
|
+
*/
|
|
9
|
+
function toErrorObject(value, fallbackMessage) {
|
|
10
|
+
if (value instanceof Error) return value;
|
|
11
|
+
if (typeof value === "string") return new Error(value);
|
|
12
|
+
const error = new Error(fallbackMessage, { cause: value });
|
|
13
|
+
if (typeof value === "object" && value !== null || typeof value === "function") Object.assign(error, value);
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
16
|
+
function extractErrorCode(err) {
|
|
17
|
+
if (!err || typeof err !== "object") return;
|
|
18
|
+
const code = err.code;
|
|
19
|
+
if (typeof code === "string") return code;
|
|
20
|
+
if (typeof code === "number") return String(code);
|
|
21
|
+
}
|
|
22
|
+
function readErrorName(err) {
|
|
23
|
+
if (!err || typeof err !== "object") return "";
|
|
24
|
+
const name = err.name;
|
|
25
|
+
return typeof name === "string" ? name : "";
|
|
26
|
+
}
|
|
27
|
+
function collectErrorGraphCandidates(err, resolveNested) {
|
|
28
|
+
const queue = [err];
|
|
29
|
+
const seen = /* @__PURE__ */ new Set();
|
|
30
|
+
const candidates = [];
|
|
31
|
+
while (queue.length > 0) {
|
|
32
|
+
const current = queue.shift();
|
|
33
|
+
if (current == null || seen.has(current)) continue;
|
|
34
|
+
seen.add(current);
|
|
35
|
+
candidates.push(current);
|
|
36
|
+
if (!current || typeof current !== "object" || !resolveNested) continue;
|
|
37
|
+
for (const nested of resolveNested(current)) if (nested != null && !seen.has(nested)) queue.push(nested);
|
|
38
|
+
}
|
|
39
|
+
return candidates;
|
|
40
|
+
}
|
|
41
|
+
function extractErrorCodeOrErrno(err) {
|
|
42
|
+
const code = extractErrorCode(err);
|
|
43
|
+
if (code) return code.trim().toUpperCase();
|
|
44
|
+
if (!err || typeof err !== "object") return;
|
|
45
|
+
const errno = err.errno;
|
|
46
|
+
if (typeof errno === "string" && errno.trim()) return errno.trim().toUpperCase();
|
|
47
|
+
if (typeof errno === "number" && Number.isFinite(errno)) return String(errno);
|
|
48
|
+
}
|
|
49
|
+
function collectNestedErrorCandidates(err) {
|
|
50
|
+
return collectErrorGraphCandidates(err, (current) => {
|
|
51
|
+
const nested = [
|
|
52
|
+
current.cause,
|
|
53
|
+
current.reason,
|
|
54
|
+
current.original,
|
|
55
|
+
current.error,
|
|
56
|
+
current.data
|
|
57
|
+
];
|
|
58
|
+
if (Array.isArray(current.errors)) nested.push(...current.errors);
|
|
59
|
+
return nested;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region packages/ai/src/utils/retryable-network-errors.ts
|
|
64
|
+
const TRANSIENT_NETWORK_CODES = /* @__PURE__ */ new Set([
|
|
65
|
+
"ECONNRESET",
|
|
66
|
+
"ECONNREFUSED",
|
|
67
|
+
"ENOTFOUND",
|
|
68
|
+
"ETIMEDOUT",
|
|
69
|
+
"ESOCKETTIMEDOUT",
|
|
70
|
+
"ECONNABORTED",
|
|
71
|
+
"EPIPE",
|
|
72
|
+
"ENETDOWN",
|
|
73
|
+
"EHOSTUNREACH",
|
|
74
|
+
"ENETUNREACH",
|
|
75
|
+
"EADDRNOTAVAIL",
|
|
76
|
+
"EAI_AGAIN",
|
|
77
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
78
|
+
"UND_ERR_DNS_RESOLVE_FAILED",
|
|
79
|
+
"UND_ERR_CONNECT",
|
|
80
|
+
"UND_ERR_SOCKET",
|
|
81
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
82
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
83
|
+
"ERR_HTTP2_INVALID_SESSION",
|
|
84
|
+
"EPROTO",
|
|
85
|
+
"ERR_SSL_WRONG_VERSION_NUMBER",
|
|
86
|
+
"ERR_SSL_PROTOCOL_RETURNED_AN_ERROR"
|
|
87
|
+
]);
|
|
88
|
+
const TRANSIENT_NETWORK_ERROR_NAMES = /* @__PURE__ */ new Set([
|
|
89
|
+
"AbortError",
|
|
90
|
+
"ConnectTimeoutError",
|
|
91
|
+
"HeadersTimeoutError",
|
|
92
|
+
"BodyTimeoutError",
|
|
93
|
+
"TimeoutError"
|
|
94
|
+
]);
|
|
95
|
+
const TRANSIENT_NETWORK_MESSAGE_CODE_RE = /\b(ECONNRESET|ECONNREFUSED|ENOTFOUND|ETIMEDOUT|ESOCKETTIMEDOUT|ECONNABORTED|EPIPE|ENETDOWN|EHOSTUNREACH|ENETUNREACH|EADDRNOTAVAIL|EAI_AGAIN|EPROTO|UND_ERR_CONNECT_TIMEOUT|UND_ERR_DNS_RESOLVE_FAILED|UND_ERR_CONNECT|UND_ERR_SOCKET|UND_ERR_HEADERS_TIMEOUT|UND_ERR_BODY_TIMEOUT|ERR_HTTP2_INVALID_SESSION)\b/i;
|
|
96
|
+
const TRANSIENT_NETWORK_MESSAGE_SNIPPETS = [
|
|
97
|
+
"getaddrinfo",
|
|
98
|
+
"socket hang up",
|
|
99
|
+
"client network socket disconnected before secure tls connection was established",
|
|
100
|
+
"network error",
|
|
101
|
+
"network is unreachable",
|
|
102
|
+
"temporary failure in name resolution",
|
|
103
|
+
"upstream connect error",
|
|
104
|
+
"disconnect/reset before headers",
|
|
105
|
+
"tlsv1 alert",
|
|
106
|
+
"ssl routines",
|
|
107
|
+
"packet length too long",
|
|
108
|
+
"write eproto"
|
|
109
|
+
];
|
|
110
|
+
const RETRYABLE_CONNECTION_ERROR_CODE_RE = /\b(?:ECONNRESET|ECONNREFUSED|ETIMEDOUT|EPIPE|EHOSTUNREACH|ENETUNREACH|EAI_AGAIN|UND_ERR_SOCKET)\b/i;
|
|
111
|
+
function isWrappedFetchFailedMessage(message) {
|
|
112
|
+
if (message === "fetch failed") return true;
|
|
113
|
+
return /:\s*fetch failed$/.test(message);
|
|
114
|
+
}
|
|
115
|
+
function hasRetryableConnectionErrorCode(message) {
|
|
116
|
+
return RETRYABLE_CONNECTION_ERROR_CODE_RE.test(message);
|
|
117
|
+
}
|
|
118
|
+
/** Returns true when any nested error proves a transient network failure. */
|
|
119
|
+
function isTransientNetworkError(err) {
|
|
120
|
+
if (!err) return false;
|
|
121
|
+
for (const candidate of collectNestedErrorCandidates(err)) {
|
|
122
|
+
const code = extractErrorCodeOrErrno(candidate);
|
|
123
|
+
if (code && TRANSIENT_NETWORK_CODES.has(code)) return true;
|
|
124
|
+
const name = readErrorName(candidate);
|
|
125
|
+
if (name && TRANSIENT_NETWORK_ERROR_NAMES.has(name)) return true;
|
|
126
|
+
if (!candidate || typeof candidate !== "object") continue;
|
|
127
|
+
const message = normalizeLowercaseStringOrEmpty(candidate.message);
|
|
128
|
+
if (!message) continue;
|
|
129
|
+
if (TRANSIENT_NETWORK_MESSAGE_CODE_RE.test(message)) return true;
|
|
130
|
+
if (isWrappedFetchFailedMessage(message)) return true;
|
|
131
|
+
if (TRANSIENT_NETWORK_MESSAGE_SNIPPETS.some((snippet) => message.includes(snippet))) return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { isTransientNetworkError as n, toErrorObject as r, hasRetryableConnectionErrorCode as t };
|
package/dist/diagnostics.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as extractDiagnosticError, i as createAssistantMessageDiagnostic, n as DiagnosticErrorInfo, o as formatThrownValue, r as appendAssistantMessageDiagnostic, t as AssistantMessageDiagnostic } from "./diagnostics-
|
|
1
|
+
import { a as extractDiagnosticError, i as createAssistantMessageDiagnostic, n as DiagnosticErrorInfo, o as formatThrownValue, r as appendAssistantMessageDiagnostic, s as isProviderRefusalAssistantError, t as AssistantMessageDiagnostic } from "./diagnostics-DnPnOui6.mjs";
|
|
2
2
|
import { n as ProviderErrorRedactor, r as configureProviderErrorRedactor } from "./provider-error-CzNw4BWX.mjs";
|
|
3
3
|
//#region packages/ai/src/utils/credential-redaction.d.ts
|
|
4
4
|
type DiagnosticMediaField = {
|
|
@@ -16,9 +16,14 @@ type DiagnosticProjectionPolicy = {
|
|
|
16
16
|
kind: "redacted";
|
|
17
17
|
}>) => Record<string, unknown>;
|
|
18
18
|
};
|
|
19
|
-
declare function projectDiagnosticValue(value: unknown, policy?: DiagnosticProjectionPolicy, seen?: WeakSet<object>, mediaPayload?: boolean, state?: {
|
|
19
|
+
export declare function projectDiagnosticValue(value: unknown, policy?: DiagnosticProjectionPolicy, seen?: WeakSet<object>, mediaPayload?: boolean, state?: {
|
|
20
20
|
changed: boolean;
|
|
21
21
|
nodesRemaining: number;
|
|
22
22
|
}): unknown;
|
|
23
23
|
//#endregion
|
|
24
|
-
|
|
24
|
+
//#region packages/ai/src/utils/retryable-network-errors.d.ts
|
|
25
|
+
export declare function hasRetryableConnectionErrorCode(message: string): boolean;
|
|
26
|
+
/** Returns true when any nested error proves a transient network failure. */
|
|
27
|
+
export declare function isTransientNetworkError(err: unknown): boolean;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { AssistantMessageDiagnostic, DiagnosticErrorInfo, type DiagnosticProjectionPolicy, type ProviderErrorRedactor, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue, isProviderRefusalAssistantError };
|
package/dist/diagnostics.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-
|
|
2
|
-
import { r as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-
|
|
3
|
-
|
|
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-B6EGq6gg.mjs";
|
|
3
|
+
import { n as isTransientNetworkError, t as hasRetryableConnectionErrorCode } from "./diagnostics-KhXK-QJI.mjs";
|
|
4
|
+
export { appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue, hasRetryableConnectionErrorCode, isProviderRefusalAssistantError, isTransientNetworkError, projectDiagnosticValue };
|