@openclaw/ai 2026.10.10 → 2026.11.5-beta.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/README.md +11 -1
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-CTND83W3.mjs +182 -0
- package/dist/{anthropic-payload-policy-rqCq9sT_.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-C__ByTq1.mjs → anthropic-stream-lifecycle-rJe4OH5H.mjs} +845 -649
- package/dist/{anthropic-tool-projection-JTvMo4KG.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DA_KeluM.mjs → anthropic-tool-projection-dGRfr4iT.mjs} +22 -32
- package/dist/{api-registry-gDt0faai.d.mts → api-registry-DY2MLUyg.d.mts} +2 -2
- package/dist/assistant-output-CD4kY9gu.mjs +16 -0
- package/dist/{azure-openai-responses-DHzTwi-y.mjs → azure-openai-responses-BhoLtP4Z.mjs} +46 -52
- package/dist/{cloudflare-Dttf8jKq.mjs → cloudflare-BJ2_Xabx.mjs} +1 -1
- package/dist/{credential-redaction-XvsPf7Yi.d.mts → credential-redaction-DrgndwTJ.d.mts} +5 -3
- package/dist/{deferred-event-buffer-DAvyP7qA.mjs → deferred-event-buffer-tIGkTkTm.mjs} +1 -2
- package/dist/{diagnostics-Cv7cW3pS.mjs → diagnostics-CloVGQiK.mjs} +42 -19
- package/dist/{diagnostics-DzrF1h4J.mjs → diagnostics-o1PrVNQb.mjs} +11 -4
- package/dist/diagnostics.d.mts +6 -7
- package/dist/diagnostics.mjs +4 -4
- package/dist/{env-api-keys-Xd8dm_aV.mjs → env-api-keys-BuHc86ya.mjs} +1 -26
- package/dist/event-stream-B4ZcSvsu.d.mts +1 -0
- package/dist/{event-stream-CzpE1g_o.d.mts → event-stream-BYmtRe8-.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{github-copilot-request-facts-F-EmvkpW.mjs → github-copilot-request-facts-BZ_EMo7X.mjs} +1 -1
- package/dist/{google-CZ6uGVkV.mjs → google-1uObh-eI.mjs} +7 -8
- package/dist/{google-interactions-qd4flmND.mjs → google-interactions-CY8Xb87S.mjs} +208 -233
- package/dist/{google-messages-B-svbJuN.mjs → google-messages-CwBqSoa4.mjs} +16 -13
- package/dist/{google-provider-stream-DlhaCvCf.mjs → google-provider-stream-D30s9EZp.mjs} +17 -10
- package/dist/{google-shared-Cif7nve-.mjs → google-shared-li0lmEZK.mjs} +70 -42
- package/dist/{google-vertex-BZTcYnWU.mjs → google-vertex-B5CHglca.mjs} +3 -3
- package/dist/{host-rCxf5Tjd.mjs → host-DX7ORpeH.mjs} +57 -46
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Ci1cKluf.mjs → host-policy-jCZebuXx.mjs} +2 -2
- package/dist/index-Bczt0MnO.d.mts +17 -0
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +9 -7
- package/dist/internal/anthropic.d.mts +21 -26
- package/dist/internal/anthropic.mjs +6 -6
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/google.d.mts +15 -0
- package/dist/internal/google.mjs +1 -0
- package/dist/internal/model-request-body.d.mts +37 -0
- package/dist/internal/model-request-body.mjs +106 -0
- package/dist/internal/openai-completions-compat.d.mts +5 -1
- package/dist/internal/openai-completions-compat.mjs +3 -2
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -12
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
- package/dist/{reasoning-tag-text-partitioner-DzlRubwU.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -122
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +165 -27
- package/dist/internal/runtime.d.mts +15 -41
- package/dist/internal/runtime.mjs +9 -10
- package/dist/internal/shared.d.mts +21 -25
- package/dist/internal/shared.mjs +9 -98
- package/dist/internal/tool-schema.d.mts +10 -10
- package/dist/internal/tool-schema.mjs +4 -4
- package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
- package/dist/mistral-F5_asrmU.mjs +3741 -0
- package/dist/mistral.LICENSE +201 -0
- package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
- package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
- package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
- package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
- package/dist/{openai-chatgpt-responses-iGYDPbmc.mjs → openai-chatgpt-responses-BIK7HROH.mjs} +61 -80
- package/dist/{openai-completions-CDy5u1mv.mjs → openai-completions-ClJ7QHEB.mjs} +5 -5
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-CJ0OXZgi.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/openai-completions-reasoning-replay-BwT1xwRI.mjs +45 -0
- package/dist/{openai-completions-transport-DLrm5EWi.mjs → openai-completions-transport-C6J4_oGf.mjs} +501 -563
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-h8vXRiaH.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/openai-responses-Beifmf1s.mjs +89 -0
- package/dist/{openai-responses-compaction-replay-DUBbsfku.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-gnl6ZRs1.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-DCG51Us0.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-JbBT8IDv.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-DuMpdA6y.mjs → openai-responses-request-lifecycle-o-ODC_rF.mjs} +12 -26
- package/dist/{openai-responses-shared-CNfHudFg.mjs → openai-responses-shared-CrFDkZ0N.mjs} +637 -389
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-CGhEl7ao.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-D-BkX8bB.mjs +766 -0
- package/dist/{overflow-OF3PgPbw.mjs → overflow-CpApyjG2.mjs} +1 -1
- package/dist/{positive-integer-Bb4Evc7L.mjs → positive-integer-DiqE5vNi.mjs} +2 -3
- package/dist/{prompt-cache-stability-D_MeCQFI.mjs → prompt-cache-stability-w-ICeyOI.mjs} +1 -1
- package/dist/{provider-error-qtZD2inE.mjs → provider-error-DD-fo4Rz.mjs} +71 -234
- package/dist/{provider-options-Bo8GzTGX.d.mts → provider-options-Mo8NM5d1.d.mts} +15 -4
- package/dist/{provider-replay-context-BC23HyZo.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-BHq3Q4nc.mjs +32 -0
- package/dist/{provider-transport-turn-state-B11rmZpv.mjs → provider-transport-turn-state-DQd9K4Pd.mjs} +3 -3
- package/dist/{provider-types-ODq57rG_.d.mts → provider-types-B1e98js5.d.mts} +6 -4
- package/dist/provider-types.d.mts +7 -6
- package/dist/provider-types.mjs +2 -1
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +26 -29
- package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
- package/dist/request-headers-DO4Mqhw1.mjs +10 -0
- package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
- package/dist/retry-after-DnHBlFS2.d.mts +45 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
- package/dist/{simple-options-BdJJbzZk.mjs → simple-options-tLSeECry.mjs} +108 -82
- package/dist/src-BUsVkrNt.mjs +105 -0
- package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
- package/dist/stable-stringify-CchQEmeA.mjs +84 -0
- package/dist/{stream-DQqGjhbq.mjs → stream-DrtAWu7c.mjs} +2 -6
- package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
- package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
- package/dist/string-normalization-B8TDDBX_.mjs +32 -0
- package/dist/telemetry-B9f7K_Xe.mjs +582 -0
- package/dist/{tool-schema-json-projection-Cvq69Ajp.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-DdnJGEj0.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
- package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
- package/dist/{transport-utils-CcCAuFVS.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +39 -38
- package/dist/transports.mjs +214 -295
- package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
- package/dist/types-Cb3-5WM9.d.mts +1 -0
- package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
- package/dist/types.d.mts +7 -6
- package/dist/types.mjs +7 -5
- package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
- package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -2
- package/package.json +40 -6
- package/dist/anthropic-B54Ts1tV.mjs +0 -221
- package/dist/assistant-output-DbgdWAhJ.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-C_ImzxlK.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-responses-Cp2QPq7K.mjs +0 -87
- package/dist/retry-after-sw-XX8aC.d.mts +0 -15
- package/dist/types-CBJthzJX.d.mts +0 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { w as supportsClaudeAdaptiveThinking } from "./src-CQ7nH2mL.mjs";
|
|
3
|
+
import { t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
4
|
+
import { _ as buildAnthropicClaudeCodeIdentity, a as resolveAiTransportHeaderSentinels, b as prepareClaudeNoPrefillRequestContext, r as getAiTransportHost } from "./host-DX7ORpeH.mjs";
|
|
5
|
+
import { a as streamFragmentError } from "./transport-utils-Da_39MYi.mjs";
|
|
6
|
+
import { B as usesFoundryBearerAuth, R as isAnthropicOAuthApiKey, j as supportsAnthropicServerSideFallback, n as applyAnthropicThinkingOptions, t as runAnthropicStreamLifecycle, w as isDirectAnthropicModel, z as omitFoundryBearerCredentialHeaders } from "./anthropic-stream-lifecycle-rJe4OH5H.mjs";
|
|
7
|
+
import { i as resolveCacheRetention, n as resolveCloudflareBaseUrl, r as buildCopilotDynamicHeaders } from "./cloudflare-BJ2_Xabx.mjs";
|
|
8
|
+
import { n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-tLSeECry.mjs";
|
|
9
|
+
import { k as parseJsonWithRepair } from "./transport-stream-shared-D2uFMhMc.mjs";
|
|
10
|
+
import { n as getEnvApiKey } from "./env-api-keys-BuHc86ya.mjs";
|
|
11
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-DzaHoRAU.mjs";
|
|
12
|
+
import { withModelRequestBodyBytes } from "./internal/model-request-body.mjs";
|
|
13
|
+
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-DA4WHv1h.mjs";
|
|
14
|
+
import { t as requireApiKey } from "./required-api-key-2zZTkmsi.mjs";
|
|
15
|
+
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
16
|
+
//#region packages/ai/src/providers/anthropic.ts
|
|
17
|
+
var anthropic_exports = /* @__PURE__ */ __exportAll({
|
|
18
|
+
streamAnthropic: () => streamAnthropic,
|
|
19
|
+
streamSimpleAnthropic: () => streamSimpleAnthropic
|
|
20
|
+
});
|
|
21
|
+
const FINE_GRAINED_TOOL_STREAMING_BETA = "fine-grained-tool-streaming-2025-05-14";
|
|
22
|
+
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
23
|
+
const ANTHROPIC_MIN_THINKING_BUDGET_TOKENS = 1024;
|
|
24
|
+
let anthropicSdkModule;
|
|
25
|
+
function getAnthropicCompat(model) {
|
|
26
|
+
const isFireworks = model.provider === "fireworks";
|
|
27
|
+
const isCloudflareAiGatewayAnthropic = model.provider === "cloudflare-ai-gateway" && model.baseUrl.includes("anthropic");
|
|
28
|
+
return {
|
|
29
|
+
supportsEagerToolInputStreaming: model.compat?.supportsEagerToolInputStreaming ?? !isFireworks,
|
|
30
|
+
sendSessionAffinityHeaders: model.compat?.sendSessionAffinityHeaders ?? (isFireworks || isCloudflareAiGatewayAnthropic)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const ANTHROPIC_MESSAGE_EVENTS = /* @__PURE__ */ new Set([
|
|
34
|
+
"message_start",
|
|
35
|
+
"message_delta",
|
|
36
|
+
"message_stop",
|
|
37
|
+
"content_block_start",
|
|
38
|
+
"content_block_delta",
|
|
39
|
+
"content_block_stop"
|
|
40
|
+
]);
|
|
41
|
+
async function* iterateAnthropicEvents(response, signal) {
|
|
42
|
+
if (!response.body) throw new Error("Attempted to iterate over an Anthropic response with no body");
|
|
43
|
+
for await (const sse of Stream.rawEvents(response)) {
|
|
44
|
+
if (sse.event === "error") throw new Error(sse.data);
|
|
45
|
+
notifyLlmRequestActivity(signal);
|
|
46
|
+
if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) continue;
|
|
47
|
+
try {
|
|
48
|
+
yield parseJsonWithRepair(sse.data);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw streamFragmentError(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const streamAnthropic = (model, context, options) => {
|
|
55
|
+
const stream = new AssistantMessageEventStream();
|
|
56
|
+
const requestContext = prepareClaudeNoPrefillRequestContext(model, context);
|
|
57
|
+
let requestOptions = options;
|
|
58
|
+
if (options?.thinkingEnabled === true && !supportsClaudeAdaptiveThinking(model)) {
|
|
59
|
+
const budgetTokens = options.thinkingBudgetTokens ?? ANTHROPIC_MIN_THINKING_BUDGET_TOKENS;
|
|
60
|
+
const maxTokens = options.maxTokens ?? model.maxTokens;
|
|
61
|
+
if (!(budgetTokens >= ANTHROPIC_MIN_THINKING_BUDGET_TOKENS && budgetTokens < maxTokens)) requestOptions = {
|
|
62
|
+
...options,
|
|
63
|
+
thinkingEnabled: false,
|
|
64
|
+
thinkingBudgetTokens: void 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
runAnthropicStreamLifecycle({
|
|
68
|
+
model,
|
|
69
|
+
stream,
|
|
70
|
+
options: requestOptions,
|
|
71
|
+
profile: "provider",
|
|
72
|
+
prepare: async () => {
|
|
73
|
+
let client = requestOptions?.client;
|
|
74
|
+
let isOAuthToken = false;
|
|
75
|
+
let serverSideFallback = false;
|
|
76
|
+
let directApiKeyBetaHeader;
|
|
77
|
+
let claudeCodeVersion;
|
|
78
|
+
if (!client) {
|
|
79
|
+
const apiKey = requestOptions?.apiKey ?? getEnvApiKey(model.provider) ?? "";
|
|
80
|
+
const dynamicHeaders = model.provider === "github-copilot" ? buildCopilotDynamicHeaders(requestContext.messages) : void 0;
|
|
81
|
+
const sessionId = (requestOptions?.cacheRetention ?? resolveCacheRetention()) === "none" ? void 0 : requestOptions?.sessionId;
|
|
82
|
+
const thinkingEnabled = requestOptions?.thinkingEnabled === true;
|
|
83
|
+
const interleavedThinking = requestOptions?.interleavedThinking ?? true;
|
|
84
|
+
const useFineGrainedToolStreamingBeta = Boolean(requestContext.tools?.length) && !getAnthropicCompat(model).supportsEagerToolInputStreaming;
|
|
85
|
+
const optionsHeaders = resolveOpencodeSessionHeaders(model, requestOptions);
|
|
86
|
+
const needsInterleavedBeta = interleavedThinking && !supportsClaudeAdaptiveThinking(model);
|
|
87
|
+
const betaFeatures = [];
|
|
88
|
+
if (useFineGrainedToolStreamingBeta) betaFeatures.push(FINE_GRAINED_TOOL_STREAMING_BETA);
|
|
89
|
+
if (needsInterleavedBeta) betaFeatures.push(INTERLEAVED_THINKING_BETA);
|
|
90
|
+
const fetchOptions = /^kimi(?:-|$)/.test(model.provider) && thinkingEnabled ? { sanitizeSse: false } : void 0;
|
|
91
|
+
const modelFetch = getAiTransportHost().buildModelFetch(model, void 0, fetchOptions);
|
|
92
|
+
const clientOptions = {
|
|
93
|
+
baseURL: model.baseUrl,
|
|
94
|
+
dangerouslyAllowBrowser: true,
|
|
95
|
+
fetch: modelFetch ? withModelRequestBodyBytes(requestOptions, modelFetch) : void 0,
|
|
96
|
+
maxRetries: 0
|
|
97
|
+
};
|
|
98
|
+
const baseHeaders = {
|
|
99
|
+
accept: "application/json",
|
|
100
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
101
|
+
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
102
|
+
};
|
|
103
|
+
let configuredApiKey = apiKey;
|
|
104
|
+
let authToken = null;
|
|
105
|
+
let defaultHeaders;
|
|
106
|
+
const isCopilot = model.provider === "github-copilot";
|
|
107
|
+
if (model.provider === "cloudflare-ai-gateway") {
|
|
108
|
+
clientOptions.baseURL = resolveCloudflareBaseUrl(model);
|
|
109
|
+
defaultHeaders = Object.assign({}, baseHeaders, { Authorization: null }, model.headers, optionsHeaders);
|
|
110
|
+
} else if (isCopilot || usesFoundryBearerAuth({
|
|
111
|
+
...model,
|
|
112
|
+
headers: resolveAiTransportHeaderSentinels(model.headers)
|
|
113
|
+
})) {
|
|
114
|
+
configuredApiKey = null;
|
|
115
|
+
authToken = apiKey;
|
|
116
|
+
defaultHeaders = Object.assign({}, baseHeaders, isCopilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), dynamicHeaders, optionsHeaders);
|
|
117
|
+
} else if (isAnthropicOAuthApiKey(apiKey)) {
|
|
118
|
+
const identity = buildAnthropicClaudeCodeIdentity([
|
|
119
|
+
"claude-code-20250219",
|
|
120
|
+
"oauth-2025-04-20",
|
|
121
|
+
...betaFeatures
|
|
122
|
+
].join(","), model.headers, optionsHeaders);
|
|
123
|
+
configuredApiKey = null;
|
|
124
|
+
authToken = apiKey;
|
|
125
|
+
defaultHeaders = identity.headers;
|
|
126
|
+
isOAuthToken = true;
|
|
127
|
+
claudeCodeVersion = identity.version;
|
|
128
|
+
} else {
|
|
129
|
+
serverSideFallback = model.provider === "anthropic" && supportsAnthropicServerSideFallback(model);
|
|
130
|
+
defaultHeaders = Object.assign({}, baseHeaders, sessionId && getAnthropicCompat(model).sendSessionAffinityHeaders ? { "x-session-affinity": sessionId } : {}, model.headers, optionsHeaders);
|
|
131
|
+
if (isDirectAnthropicModel(model)) directApiKeyBetaHeader = Object.entries(defaultHeaders).findLast(([name]) => name.toLowerCase() === "anthropic-beta")?.[1] ?? "";
|
|
132
|
+
}
|
|
133
|
+
const { default: Anthropic } = await (anthropicSdkModule ??= import("@anthropic-ai/sdk"));
|
|
134
|
+
client = new Anthropic({
|
|
135
|
+
...clientOptions,
|
|
136
|
+
apiKey: configuredApiKey,
|
|
137
|
+
authToken,
|
|
138
|
+
defaultHeaders
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
isOAuthToken,
|
|
143
|
+
serverSideFallback,
|
|
144
|
+
directApiKeyBetaHeader,
|
|
145
|
+
claudeCodeVersion,
|
|
146
|
+
context: requestContext,
|
|
147
|
+
options: requestOptions,
|
|
148
|
+
request: async (body, headers) => {
|
|
149
|
+
const response = await client.messages.create(body, {
|
|
150
|
+
...requestOptions?.signal ? { signal: requestOptions.signal } : {},
|
|
151
|
+
...requestOptions?.timeoutMs !== void 0 ? { timeout: requestOptions.timeoutMs } : {},
|
|
152
|
+
maxRetries: 0,
|
|
153
|
+
headers
|
|
154
|
+
}).asResponse();
|
|
155
|
+
return {
|
|
156
|
+
response,
|
|
157
|
+
events: iterateAnthropicEvents(response, requestOptions?.signal)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return stream;
|
|
164
|
+
};
|
|
165
|
+
const streamSimpleAnthropic = (model, context, options) => {
|
|
166
|
+
const apiKey = requireApiKey(model.provider, options?.apiKey);
|
|
167
|
+
const base = {
|
|
168
|
+
...buildBaseOptions(model, options, apiKey),
|
|
169
|
+
anthropicServerCompaction: options?.anthropicServerCompaction,
|
|
170
|
+
anthropicCompactThreshold: options?.anthropicCompactThreshold,
|
|
171
|
+
cacheTtlPruning: options?.cacheTtlPruning,
|
|
172
|
+
onCompactionRejected: options?.onCompactionRejected,
|
|
173
|
+
authProfileId: options?.authProfileId,
|
|
174
|
+
maxTokens: clampMaxTokensToModel(model, options?.maxTokens ?? model.maxTokens),
|
|
175
|
+
toolChoice: options?.toolChoice,
|
|
176
|
+
thinkingDisplay: options?.thinkingDisplay
|
|
177
|
+
};
|
|
178
|
+
applyAnthropicThinkingOptions(model, base, options, "provider");
|
|
179
|
+
return streamAnthropic(model, context, base);
|
|
180
|
+
};
|
|
181
|
+
//#endregion
|
|
182
|
+
export { streamAnthropic as n, streamSimpleAnthropic as r, anthropic_exports as t };
|
package/dist/{anthropic-payload-policy-rqCq9sT_.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts}
RENAMED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
3
|
-
import { t as AnthropicContextManagementOptions } from "./provider-options-
|
|
1
|
+
import { k as Model, tt as SimpleStreamOptions } from "./types-BVdTf0YV.mjs";
|
|
2
|
+
import "./index-Bczt0MnO.mjs";
|
|
3
|
+
import { r as AnthropicOptions, t as AnthropicContextManagementOptions } from "./provider-options-Mo8NM5d1.mjs";
|
|
4
4
|
import { TextBlockParam } from "@anthropic-ai/sdk/resources/messages.js";
|
|
5
|
+
//#region packages/ai/src/transports/anthropic-transport-options.d.ts
|
|
6
|
+
/** Keep both entry points on one thinking mode while retaining their output-budget policies. */
|
|
7
|
+
declare function applyAnthropicThinkingOptions(model: Model<"anthropic-messages">, resolved: Pick<AnthropicOptions, "thinkingEnabled" | "thinkingBudgetTokens" | "effort"> & {
|
|
8
|
+
maxTokens: number;
|
|
9
|
+
}, options: Pick<SimpleStreamOptions, "reasoning" | "thinkingBudgets"> | undefined, profile: "provider" | "transport"): SimpleStreamOptions["reasoning"];
|
|
10
|
+
/**
|
|
11
|
+
* Largest completion a request may ask for once transport thinking options
|
|
12
|
+
* apply, for callers that size the prompt before dispatch. Claude transports
|
|
13
|
+
* (Anthropic Messages, Vertex, Bedrock, Bedrock Mantle) may add a thinking
|
|
14
|
+
* budget to `maxTokens`, capped at the model's output limit; some add it even
|
|
15
|
+
* for adaptive models, and their Claude detection is plugin-owned, so every
|
|
16
|
+
* request on these APIs reserves the default budget for its level. Other
|
|
17
|
+
* transports keep `maxTokens` as the total output limit. Over-reserving only
|
|
18
|
+
* shrinks the prompt; it never overflows the window.
|
|
19
|
+
*/
|
|
20
|
+
declare function resolveCompletionTokenReservation(model: Model, maxTokens: number, reasoning: SimpleStreamOptions["reasoning"]): number;
|
|
21
|
+
//#endregion
|
|
5
22
|
//#region packages/ai/src/transports/anthropic-payload-policy.d.ts
|
|
6
23
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
7
24
|
type AnthropicServiceTier = "auto" | "standard_only";
|
|
@@ -93,4 +110,4 @@ declare function applyAnthropicPayloadPolicyToParams(payloadObj: Record<string,
|
|
|
93
110
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
94
111
|
declare function applyAnthropicEphemeralCacheControlMarkers(payloadObj: Record<string, unknown>, cacheControl?: AnthropicEphemeralCacheControl | null): void;
|
|
95
112
|
//#endregion
|
|
96
|
-
export { buildAnthropicSystemBlocks as a, logAnthropicContextEdits as c, resolveAnthropicPayloadPolicy as d, resolveAnthropicRequestBetaHeader as f, applyAnthropicRequestCacheControl as i, resolveAnthropicCacheOptions as l, supportsAnthropicServerSideFallback as m, applyAnthropicEphemeralCacheControlMarkers as n, isAnthropicServerToolClearingEnabled as o, resolveAnthropicServerCompactionPlan as p, applyAnthropicPayloadPolicyToParams as r, isDirectAnthropicModel as s, applyAnthropicContextManagementToRequest as t, resolveAnthropicEphemeralCacheControl as u };
|
|
113
|
+
export { buildAnthropicSystemBlocks as a, logAnthropicContextEdits as c, resolveAnthropicPayloadPolicy as d, resolveAnthropicRequestBetaHeader as f, resolveCompletionTokenReservation as g, applyAnthropicThinkingOptions as h, applyAnthropicRequestCacheControl as i, resolveAnthropicCacheOptions as l, supportsAnthropicServerSideFallback as m, applyAnthropicEphemeralCacheControlMarkers as n, isAnthropicServerToolClearingEnabled as o, resolveAnthropicServerCompactionPlan as p, applyAnthropicPayloadPolicyToParams as r, isDirectAnthropicModel as s, applyAnthropicContextManagementToRequest as t, resolveAnthropicEphemeralCacheControl as u };
|