@openclaw/ai 2026.11.5-beta.4 → 2026.11.10-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 +15 -3
- package/dist/{anthropic-c499kyoI.mjs → anthropic-CBz5v2U3.mjs} +16 -15
- package/dist/{anthropic-payload-policy-DVk38bnY.d.mts → anthropic-payload-policy-BTrHSS_v.d.mts} +4 -8
- package/dist/{anthropic-stream-lifecycle-KkyqdnjW.mjs → anthropic-stream-lifecycle-96vq-4V9.mjs} +154 -89
- package/dist/{anthropic-tool-projection-DcvsDiyX.mjs → anthropic-tool-projection-A9GceDnD.mjs} +4 -5
- package/dist/{anthropic-tool-projection-DKAlondV.d.mts → anthropic-tool-projection-DCOX8qai.d.mts} +1 -3
- package/dist/{api-registry-DY2MLUyg.d.mts → api-registry-DUEK-a3o.d.mts} +2 -4
- package/dist/{assistant-message-events-CHMJgbhs.mjs → assistant-message-events-DtSjIQmB.mjs} +1 -2
- package/dist/{assistant-output-C3czmoN4.mjs → assistant-output-kYOaiso5.mjs} +2 -3
- package/dist/{azure-openai-responses-client-compat-D0dvJMbZ.mjs → azure-deployment-map-hwDQc3uL.mjs} +2 -16
- package/dist/{azure-openai-responses-CyuUQ3JJ.mjs → azure-openai-responses-CZheDTt_.mjs} +12 -13
- package/dist/azure-openai-responses-client-compat-DLsS6V6z.mjs +13 -0
- package/dist/{base64-C8CdcsjU.mjs → base64-FdymvxN9.mjs} +1 -2
- package/dist/cloudflare-BCLfDuew.mjs +15 -0
- package/dist/{credential-redaction-DrgndwTJ.d.mts → credential-redaction-BNv5SWQz.d.mts} +0 -2
- package/dist/{deferred-event-buffer-tIGkTkTm.mjs → deferred-event-buffer-BgT1IIfq.mjs} +1 -2
- package/dist/{diagnostics-CloVGQiK.mjs → diagnostics-BNlb1zlT.mjs} +12 -19
- package/dist/{diagnostics-o1PrVNQb.mjs → diagnostics-DP1SXgAW.mjs} +1 -2
- package/dist/diagnostics.d.mts +6 -10
- package/dist/diagnostics.mjs +3 -3
- package/dist/{env-api-keys-BuHc86ya.mjs → env-api-keys-DlUbTgKq.mjs} +1 -2
- package/dist/{event-stream-BYmtRe8-.d.mts → event-stream-BJS9Q8G_.d.mts} +1 -3
- package/dist/{event-stream-X2gmsUWv.mjs → event-stream-Bf6cK7-d.mjs} +1 -2
- package/dist/event-stream-CPiqa8PI.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{expect-lbe3Hgrh.mjs → expect-DqyhV9d8.mjs} +1 -2
- package/dist/github-copilot-headers-CqLRrd-i.mjs +22 -0
- package/dist/{github-copilot-request-facts-BZ_EMo7X.mjs → github-copilot-request-facts-BxuLEdNF.mjs} +2 -3
- package/dist/{google-DqG05iBa.mjs → google-BUgkXPYL.mjs} +6 -7
- package/dist/{google-interactions-B_xZUObF.mjs → google-interactions-84f0xFly.mjs} +36 -25
- package/dist/{google-messages-p2iBzsAp.mjs → google-messages-Dip5zphv.mjs} +16 -20
- package/dist/{google-provider-stream-DZ6tqteU.mjs → google-provider-stream-COaKMdQv.mjs} +14 -15
- package/dist/{google-shared-BMYt1xSI.mjs → google-shared-Dooy5JJL.mjs} +11 -14
- package/dist/{google-vertex-CAq2q1Ln.mjs → google-vertex--S8AlXUD.mjs} +4 -5
- package/dist/{google-video-slots-Bxt-OXO8.mjs → google-video-slots-CzdrKzrO.mjs} +2 -3
- package/dist/{host-DqX-64Pb.mjs → host-Cf7zb-48.mjs} +73 -89
- package/dist/{host-ccbwPC3A.d.mts → host-Dgpzj407.d.mts} +3 -5
- package/dist/{host-policy-Bk85E9ue.mjs → host-policy-B1qzS7Xe.mjs} +2 -3
- package/dist/{index-Bczt0MnO.d.mts → index-BDF5kurq.d.mts} +10 -10
- package/dist/index.d.mts +8 -10
- package/dist/index.mjs +11 -11
- package/dist/internal/anthropic.d.mts +10 -21
- package/dist/internal/anthropic.mjs +6 -6
- package/dist/internal/google-model-family.d.mts +1 -3
- package/dist/internal/google-model-family.mjs +2 -3
- package/dist/internal/google.d.mts +3 -5
- package/dist/internal/google.mjs +1 -1
- package/dist/internal/model-request-body.d.mts +5 -5
- package/dist/internal/model-request-body.mjs +19 -6
- package/dist/internal/openai-completions-compat.d.mts +1 -3
- package/dist/internal/openai-completions-compat.mjs +2 -2
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -4
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +10 -32
- package/dist/internal/openai.mjs +12 -11
- package/dist/internal/reasoning-tag-text-partitioner.d.mts +0 -4
- package/dist/internal/reasoning-tag-text-partitioner.mjs +64 -125
- package/dist/internal/retry-after.d.mts +1 -1
- package/dist/internal/retry-after.mjs +1 -2
- package/dist/internal/runtime.d.mts +9 -43
- package/dist/internal/runtime.mjs +14 -15
- package/dist/internal/session-resources.d.mts +11 -0
- package/dist/{session-resources-vKvGIE3J.mjs → internal/session-resources.mjs} +2 -3
- package/dist/internal/shared.d.mts +17 -26
- package/dist/internal/shared.mjs +10 -10
- package/dist/internal/tool-schema.d.mts +2 -22
- package/dist/internal/tool-schema.mjs +3 -3
- package/dist/{llm-request-activity-DzaHoRAU.mjs → llm-request-activity-v1liRqNt.mjs} +1 -2
- package/dist/{mistral-DIGInqJI.mjs → mistral-BAps5cN2.mjs} +713 -299
- package/dist/{model-transport-url-BdksnBqu.d.mts → model-transport-url-Dad-sfx2.d.mts} +0 -4
- package/dist/{number-coercion-C7HsBgUL.mjs → number-coercion-BO6bhGm6.mjs} +2 -3
- package/dist/{observe-async-iterator-DgmegcZR.mjs → observe-async-iterator-DdOlbgrr.mjs} +1 -2
- package/dist/{observe-async-iterator-AlARO5wS.d.mts → observe-async-iterator-DeB_Vxes.d.mts} +14 -7
- package/dist/openai-BtJTmLWF.mjs +21460 -0
- package/dist/{openai-chatgpt-jwt-KWcgd0d_.mjs → openai-chatgpt-jwt-v5F5jJmX.mjs} +1 -2
- package/dist/{openai-chatgpt-responses-B-MopEDG.mjs → openai-chatgpt-responses-CYXMKG89.mjs} +55 -56
- package/dist/{openai-completions-B62Yg3hQ.mjs → openai-completions-Bi4Ghg3V.mjs} +6 -7
- package/dist/{openai-completions-compat-CJ-NsDzg.d.mts → openai-completions-compat-BJBQ682M.d.mts} +10 -5
- package/dist/{openai-completions-compat-CS3dlDBR.mjs → openai-completions-compat-DZLGotNt.mjs} +19 -16
- package/dist/{openai-completions-reasoning-replay-BwT1xwRI.mjs → openai-completions-reasoning-replay-DyH5XzNo.mjs} +1 -2
- package/dist/{openai-completions-transport-BQ8dr3FV.mjs → openai-completions-transport-otONaRhv.mjs} +161 -535
- package/dist/{openai-prompt-cache-BZGaIWYh.d.mts → openai-prompt-cache-C5rwtmA_.d.mts} +2 -4
- package/dist/{openai-prompt-cache-3H_Fz0ya.mjs → openai-prompt-cache-CJv1bvw0.mjs} +3 -5
- package/dist/openai-provider-client-apBsWo9b.mjs +51 -0
- package/dist/{openai-responses-VUkMi_Bc.mjs → openai-responses-CiIAm8fJ.mjs} +14 -15
- package/dist/{openai-responses-compaction-replay-DXF5BjD2.d.mts → openai-responses-compaction-replay-CUw4owu9.d.mts} +6 -7
- package/dist/{openai-responses-contracts-Cb1IIRRG.d.mts → openai-responses-contracts-bYtvXSvv.d.mts} +7 -12
- package/dist/{openai-responses-contracts-xU-n9AJJ.mjs → openai-responses-contracts-eppTI5DQ.mjs} +11 -18
- package/dist/{openai-responses-endpoint-CqO3ejTe.mjs → openai-responses-endpoint-AeVu3HmP.mjs} +80 -34
- package/dist/{openai-responses-payload-policy-BsQaD-gD.d.mts → openai-responses-payload-policy-Cihgy9fC.d.mts} +0 -2
- package/dist/{openai-responses-request-lifecycle-DNITxJPO.mjs → openai-responses-request-lifecycle-DfE4xNHj.mjs} +120 -20
- package/dist/{openai-responses-shared-WMDQDwC6.mjs → openai-responses-shared-BAJzOqwt.mjs} +1651 -322
- package/dist/{openai-responses-terminal-usage-D7IhRA6i.d.mts → openai-responses-terminal-usage-BYXQTt9u.d.mts} +2 -4
- package/dist/openai-responses-websocket-DywDiO81.mjs +8143 -0
- package/dist/{openai-stop-reason-8s70vDXj.mjs → openai-stop-reason-cA0GUHlU.mjs} +4 -3
- package/dist/{openai-tool-schema-CvxySRyf.mjs → openai-tool-schema-Ca74_fkR.mjs} +17 -26
- package/dist/openai.LICENSE +201 -0
- package/dist/{otel-B2u5HGvm.mjs → otel-C5Cn7IFQ.mjs} +8 -8
- package/dist/{overflow-CpApyjG2.mjs → overflow-CM0yZomw.mjs} +2 -3
- package/dist/{positive-integer-DiqE5vNi.mjs → positive-integer-AM4ltyhP.mjs} +2 -3
- package/dist/{prompt-cache-stability-w-ICeyOI.mjs → prompt-cache-stability-oTx0nIsh.mjs} +3 -4
- package/dist/{prompt-cache-stability-Cwcjv_fx.d.mts → prompt-cache-stability-xNfkD-3g.d.mts} +0 -2
- package/dist/{provider-error-DD-fo4Rz.mjs → provider-error-B7aKA_dg.mjs} +24 -23
- package/dist/{provider-error-CnaWYTRY.d.mts → provider-error-DZMru0Jv.d.mts} +0 -2
- package/dist/{provider-options-BQ2Msop2.d.mts → provider-options-CR_UfgUE.d.mts} +15 -11
- package/dist/{provider-replay-context-5gFUstgv.mjs → provider-replay-context-CHJQzB0n.mjs} +5 -7
- package/dist/{provider-transcript-transform-Hr1kCoMX.mjs → provider-transcript-transform-C-WfgiLJ.mjs} +2 -3
- package/dist/{provider-transport-turn-state-d1uIBP1i.mjs → provider-transport-turn-state-BdMA1v46.mjs} +4 -27
- package/dist/{provider-types-B1e98js5.d.mts → provider-types-CfiTmXyw.d.mts} +3 -5
- package/dist/provider-types.d.mts +7 -7
- package/dist/provider-types.mjs +1 -2
- package/dist/providers.d.mts +2 -4
- package/dist/providers.mjs +14 -15
- package/dist/{record-coerce-BQaoiN3r.mjs → record-coerce-BgUo6bj4.mjs} +1 -2
- package/dist/{request-headers-DO4Mqhw1.mjs → request-headers-DJ4QrMC_.mjs} +1 -2
- package/dist/{required-api-key-2zZTkmsi.mjs → required-api-key-BniLGxy4.mjs} +2 -3
- package/dist/{retry-after-DnHBlFS2.d.mts → retry-after-f3ZIm8TA.d.mts} +0 -2
- package/dist/rolldown-runtime-DYf_mQCB.mjs +34 -0
- package/dist/{sanitize-unicode-CRGuMONI.mjs → sanitize-unicode-B3kUqQ-q.mjs} +1 -2
- package/dist/{sanitize-unicode-BISmUlUv.d.mts → sanitize-unicode-DlVtgmsw.d.mts} +2 -6
- package/dist/{session-affinity-DA4WHv1h.mjs → session-affinity-Czm9tjAm.mjs} +1 -2
- package/dist/{simple-options-CQNPKCEb.mjs → simple-options-D8CTqHvk.mjs} +40 -16
- package/dist/src-CNWvILd1.mjs +2 -0
- package/dist/{src-CQ7nH2mL.mjs → src-CmBmaGOV.mjs} +87 -20
- package/dist/{stable-stringify-CchQEmeA.mjs → stable-stringify-CGB-o900.mjs} +10 -8
- package/dist/{stream-DM-q0y5H.mjs → stream-BEE5qy7Z.mjs} +5 -7
- package/dist/{stream-first-event-timeout-B7RcufAV.mjs → stream-first-event-timeout-CWiv_y--.mjs} +2 -3
- package/dist/{streaming-byte-guard-DBXr1XYn.mjs → streaming-byte-guard-gOcUrHJF.mjs} +1 -2
- package/dist/{string-coerce-BCuWMIrk.mjs → string-coerce-CpcyRbc6.mjs} +1 -2
- package/dist/{string-normalization-B8TDDBX_.mjs → string-normalization-CS77PHD3.mjs} +2 -3
- package/dist/{telemetry-DJibfNKZ.mjs → telemetry-Cd4i-clM.mjs} +6 -8
- package/dist/{tool-schema-json-projection-BSHb4gaJ.mjs → tool-schema-json-projection-C13fPskA.mjs} +11 -16
- package/dist/{transport-stream-shared-CBVh6QEc.mjs → transport-stream-shared-DEpLe9fG.mjs} +24 -30
- package/dist/{transport-stream-shared-D3IAU4jn.d.mts → transport-stream-shared-DW4DoJLv.d.mts} +7 -8
- package/dist/{transport-utils-rxOHnq9y.mjs → transport-utils-Cx9L80PZ.mjs} +6 -8
- package/dist/transports.d.mts +29 -83
- package/dist/transports.mjs +39 -38
- package/dist/{types-BVdTf0YV.d.mts → types-BNp71XKW.d.mts} +11 -6
- package/dist/types-CwcLeW-7.d.mts +1 -0
- package/dist/{types-OVEWUaDh.mjs → types-DIBUKaTM.mjs} +1 -2
- package/dist/types.d.mts +7 -7
- package/dist/types.mjs +9 -9
- package/dist/{usage-CJH5D6Ea.mjs → usage-B8ggJtuG.mjs} +1 -2
- package/dist/{validation-QmyD0E5A.d.mts → validation-BFNWNeUl.d.mts} +1 -3
- package/dist/{validation-DGXqfvkj.mjs → validation-BO7nCOKO.mjs} +5 -8
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/dist/ws.LICENSE +20 -0
- package/dist/x509-transport-state-D4gFbgWG.mjs +40 -0
- package/package.json +13 -7
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +0 -1
- package/dist/cloudflare-BJ2_Xabx.mjs +0 -39
- package/dist/event-stream-B4ZcSvsu.d.mts +0 -1
- package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
- package/dist/src-BUsVkrNt.mjs +0 -105
- package/dist/types-Cb3-5WM9.d.mts +0 -1
package/README.md
CHANGED
|
@@ -35,6 +35,13 @@ OpenAI HTTP adapters report rejected response status and headers through
|
|
|
35
35
|
invoke the callback before the first event. Retry and failover policy remains
|
|
36
36
|
with the application.
|
|
37
37
|
|
|
38
|
+
Anthropic Messages, OpenAI-compatible Chat Completions, Google, Mistral, and
|
|
39
|
+
OpenAI Responses calls stop waiting for payload and response hooks when the
|
|
40
|
+
request signal aborts. A hook can continue running after cancellation; embedding
|
|
41
|
+
hosts can retain that work through `observePendingProviderWork` until it
|
|
42
|
+
settles. Native provider transports get the same payload-hook behavior from
|
|
43
|
+
`applyProviderPayloadHook`.
|
|
44
|
+
|
|
38
45
|
Hosts that attach request state to async contexts should supply
|
|
39
46
|
`runInDetachedAsyncContext` from a context-free root initialized before requests
|
|
40
47
|
start. Retained HTTP continuation timers use it at creation so completed caller
|
|
@@ -49,9 +56,14 @@ producer reads the latest value, or none once the call has finished.
|
|
|
49
56
|
|
|
50
57
|
The Anthropic and Mistral adapters report unreadable tool descriptors as
|
|
51
58
|
a stream error before sending a model request rather than silently omitting them.
|
|
52
|
-
The pinned Mistral SDK
|
|
53
|
-
|
|
54
|
-
`dist/mistral.LICENSE`.
|
|
59
|
+
The pinned Mistral and OpenAI SDK clients are bundled into the adapters to avoid
|
|
60
|
+
loading their individual package modules on first use. Their Apache-2.0 licenses
|
|
61
|
+
ship as `dist/mistral.LICENSE` and `dist/openai.LICENSE`. TypeBox remains external
|
|
62
|
+
so host and plugin validation share its mutable format and settings registries.
|
|
63
|
+
OpenAI types resolve through the declared `openai` dependency, preserving its
|
|
64
|
+
namespace aliases without flattening them into the bundled declarations.
|
|
65
|
+
OpenAI's `ws` dependency is bundled alongside the client, with its MIT license
|
|
66
|
+
at `dist/ws.LICENSE`.
|
|
55
67
|
|
|
56
68
|
The explicit `@openclaw/ai/internal/anthropic`, `google`, `google-model-family`, `openai`,
|
|
57
69
|
`openai-completions-compat`, `openai-responses-payload-policy`, `retry-after`, `runtime`, `shared`, and
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import { _ as buildAnthropicClaudeCodeIdentity, a as resolveAiTransportHeaderSentinels,
|
|
5
|
-
import { a as streamFragmentError } from "./transport-utils-
|
|
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-
|
|
7
|
-
import {
|
|
8
|
-
import { n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-
|
|
9
|
-
import {
|
|
10
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
11
|
-
import { t as notifyLlmRequestActivity } from "./llm-request-activity-
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-DYf_mQCB.mjs";
|
|
2
|
+
import { D as supportsClaudeAdaptiveThinking } from "./src-CmBmaGOV.mjs";
|
|
3
|
+
import { t as AssistantMessageEventStream } from "./event-stream-Bf6cK7-d.mjs";
|
|
4
|
+
import { _ as buildAnthropicClaudeCodeIdentity, a as resolveAiTransportHeaderSentinels, r as getAiTransportHost, x as prepareClaudeNoPrefillRequestContext } from "./host-Cf7zb-48.mjs";
|
|
5
|
+
import { a as streamFragmentError } from "./transport-utils-Cx9L80PZ.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-96vq-4V9.mjs";
|
|
7
|
+
import { n as resolveCacheRetention, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-CqLRrd-i.mjs";
|
|
8
|
+
import { n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-D8CTqHvk.mjs";
|
|
9
|
+
import { A as parseJsonWithRepair } from "./transport-stream-shared-DEpLe9fG.mjs";
|
|
10
|
+
import { n as getEnvApiKey } from "./env-api-keys-DlUbTgKq.mjs";
|
|
11
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-v1liRqNt.mjs";
|
|
12
12
|
import { withModelRequestBodyBytes } from "./internal/model-request-body.mjs";
|
|
13
|
-
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-
|
|
14
|
-
import { t as requireApiKey } from "./required-api-key-
|
|
13
|
+
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-Czm9tjAm.mjs";
|
|
14
|
+
import { t as requireApiKey } from "./required-api-key-BniLGxy4.mjs";
|
|
15
|
+
import { n as resolveCloudflareBaseUrl } from "./cloudflare-BCLfDuew.mjs";
|
|
15
16
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
16
|
-
|
|
17
|
+
// packages/ai/src/providers/anthropic.ts
|
|
17
18
|
var anthropic_exports = /* @__PURE__ */ __exportAll({
|
|
18
19
|
streamAnthropic: () => streamAnthropic,
|
|
19
20
|
streamSimpleAnthropic: () => streamSimpleAnthropic
|
|
@@ -171,6 +172,7 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
171
172
|
cacheTtlPruning: options?.cacheTtlPruning,
|
|
172
173
|
onCompactionRejected: options?.onCompactionRejected,
|
|
173
174
|
onClaudeCodeVersionRequired: options?.onClaudeCodeVersionRequired,
|
|
175
|
+
onFastModeUnsupported: options?.onFastModeUnsupported,
|
|
174
176
|
authProfileId: options?.authProfileId,
|
|
175
177
|
maxTokens: clampMaxTokensToModel(model, options?.maxTokens ?? model.maxTokens),
|
|
176
178
|
toolChoice: options?.toolChoice,
|
|
@@ -179,5 +181,4 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
179
181
|
applyAnthropicThinkingOptions(model, base, options, "provider");
|
|
180
182
|
return streamAnthropic(model, context, base);
|
|
181
183
|
};
|
|
182
|
-
//#endregion
|
|
183
184
|
export { streamAnthropic as n, streamSimpleAnthropic as r, anthropic_exports as t };
|
package/dist/{anthropic-payload-policy-DVk38bnY.d.mts → anthropic-payload-policy-BTrHSS_v.d.mts}
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { k as Model, tt as SimpleStreamOptions } from "./types-
|
|
2
|
-
import "./index-
|
|
3
|
-
import { r as AnthropicOptions, t as AnthropicContextManagementOptions } from "./provider-options-
|
|
1
|
+
import { k as Model, tt as SimpleStreamOptions, z as PreparedSystemPrompt } from "./types-BNp71XKW.mjs";
|
|
2
|
+
import "./index-BDF5kurq.mjs";
|
|
3
|
+
import { r as AnthropicOptions, t as AnthropicContextManagementOptions } from "./provider-options-CR_UfgUE.mjs";
|
|
4
4
|
import { TextBlockParam } from "@anthropic-ai/sdk/resources/messages.js";
|
|
5
|
-
//#region packages/ai/src/transports/anthropic-transport-options.d.ts
|
|
6
5
|
/** Keep both entry points on one thinking mode while retaining their output-budget policies. */
|
|
7
6
|
declare function applyAnthropicThinkingOptions(model: Model<"anthropic-messages">, resolved: Pick<AnthropicOptions, "thinkingEnabled" | "thinkingBudgetTokens" | "effort"> & {
|
|
8
7
|
maxTokens: number;
|
|
@@ -18,8 +17,6 @@ declare function applyAnthropicThinkingOptions(model: Model<"anthropic-messages"
|
|
|
18
17
|
* shrinks the prompt; it never overflows the window.
|
|
19
18
|
*/
|
|
20
19
|
declare function resolveCompletionTokenReservation(model: Model, maxTokens: number, reasoning: SimpleStreamOptions["reasoning"]): number;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region packages/ai/src/transports/anthropic-payload-policy.d.ts
|
|
23
20
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
24
21
|
type AnthropicServiceTier = "auto" | "standard_only";
|
|
25
22
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
@@ -72,7 +69,7 @@ declare function resolveAnthropicCacheOptions(model: Model<"anthropic-messages">
|
|
|
72
69
|
cacheControl: AnthropicEphemeralCacheControl | undefined;
|
|
73
70
|
supportsCacheControlOnTools: boolean;
|
|
74
71
|
};
|
|
75
|
-
declare function buildAnthropicSystemBlocks(systemPrompt: string | undefined, isOAuthToken: boolean, cacheControl: AnthropicEphemeralCacheControl | undefined, claudeCodeVersion?: string): TextBlockParam[] | undefined;
|
|
72
|
+
declare function buildAnthropicSystemBlocks(systemPrompt: string | undefined, isOAuthToken: boolean, cacheControl: AnthropicEphemeralCacheControl | undefined, claudeCodeVersion?: string, preparedSystemPrompt?: PreparedSystemPrompt): TextBlockParam[] | undefined;
|
|
76
73
|
/** Allocate tool and history checkpoints around the prepared stable system blocks. */
|
|
77
74
|
declare function applyAnthropicRequestCacheControl(payload: {
|
|
78
75
|
system?: unknown;
|
|
@@ -109,5 +106,4 @@ declare function logAnthropicContextEdits(event: unknown): void;
|
|
|
109
106
|
declare function applyAnthropicPayloadPolicyToParams(payloadObj: Record<string, unknown>, policy: AnthropicPayloadPolicy, cacheBreakpointOptOutMessageIndexes: ReadonlySet<number>): void;
|
|
110
107
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
111
108
|
declare function applyAnthropicEphemeralCacheControlMarkers(payloadObj: Record<string, unknown>, cacheControl?: AnthropicEphemeralCacheControl | null): void;
|
|
112
|
-
//#endregion
|
|
113
109
|
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 };
|
package/dist/{anthropic-stream-lifecycle-KkyqdnjW.mjs → anthropic-stream-lifecycle-96vq-4V9.mjs}
RENAMED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { p as hasRuntimeContextMarker } from "./types-
|
|
3
|
-
import { r as
|
|
4
|
-
import {
|
|
5
|
-
import { a as normalizeOptionalLowercaseString, i as normalizeNullableString } from "./string-coerce-
|
|
6
|
-
import { n as asNonNegativeFiniteNumber } from "./number-coercion-
|
|
7
|
-
import { C as
|
|
8
|
-
import "./transport-utils-
|
|
9
|
-
import { n as estimateBase64DecodedBytes } from "./base64-
|
|
10
|
-
import { a as resolveProviderRequestCapabilities, i as resolveProviderEndpoint } from "./host-policy-
|
|
11
|
-
import {
|
|
12
|
-
import { t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
13
|
-
import { C as stripSystemPromptCacheBoundary, a as describeToolResultMediaPlaceholder, c as extractToolResultText, f as preparedRequestSuffix, s as extractToolResultBlockText, t as adjustMaxTokensForThinking, w as
|
|
14
|
-
import {
|
|
15
|
-
import { t as parsePositiveInteger } from "./positive-integer-
|
|
16
|
-
import { a as reconcileAnthropicToolChoice, i as projectAnthropicTools, n as normalizeAnthropicToolChoice, o as resolveOriginalAnthropicToolName, s as toClaudeCodeToolName, t as normalizeAnthropicToolCallId } from "./anthropic-tool-projection-
|
|
17
|
-
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-
|
|
18
|
-
import { t as notifyLlmRequestActivity } from "./llm-request-activity-
|
|
19
|
-
import { n as isProviderReplayContext, r as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-
|
|
20
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
1
|
+
import { C as resolveClaudeOpus5ModelIdentity, D as supportsClaudeAdaptiveThinking, M as supportsClaudeServerCompaction, N as usesClaude5RequestContract, S as resolveClaudeOpus55ModelIdentity, _ as resolveClaudeFable5ModelIdentity, d as bindsClaudeThinkingPrefix, j as supportsClaudeNativeXhighEffort, k as supportsClaudeInHistorySystemMessages, m as requiresClaudeBetweenToolsThinking, v as resolveClaudeHaiku55ModelIdentity, w as resolveClaudeSonnet55ModelIdentity, y as resolveClaudeModelIdentity } from "./src-CmBmaGOV.mjs";
|
|
2
|
+
import { p as hasRuntimeContextMarker } from "./types-DIBUKaTM.mjs";
|
|
3
|
+
import { a as asRecord, c as readStringField, o as isRecord, r as asOptionalObjectRecord } from "./record-coerce-BgUo6bj4.mjs";
|
|
4
|
+
import { r as appendAssistantThinking } from "./event-stream-Bf6cK7-d.mjs";
|
|
5
|
+
import { a as normalizeOptionalLowercaseString, i as normalizeNullableString } from "./string-coerce-CpcyRbc6.mjs";
|
|
6
|
+
import { n as asNonNegativeFiniteNumber } from "./number-coercion-BO6bhGm6.mjs";
|
|
7
|
+
import { C as raiseClaudeCodeVersionFloor, D as resolveAnthropicThinkingEffort, L as isImageWithMediaPayload, M as calculateCost, O as usesClaudeFable5MessagesContract, T as requiresClaudeAdaptiveThinking, b as mapAnthropicStopReason, g as applyClaudeRequestContract, h as ANTHROPIC_CLAUDE_CODE_VERSION, k as usesClaudeStreamingRefusalContract, r as getAiTransportHost, u as STREAM_ERROR_FALLBACK_TEXT, v as defaultsClaudeAdaptiveThinking, w as readRequiredClaudeCodeVersion, y as isUnsupportedClaudeFastModeError } from "./host-Cf7zb-48.mjs";
|
|
8
|
+
import "./transport-utils-Cx9L80PZ.mjs";
|
|
9
|
+
import { n as estimateBase64DecodedBytes } from "./base64-FdymvxN9.mjs";
|
|
10
|
+
import { a as resolveProviderRequestCapabilities, i as resolveProviderEndpoint } from "./host-policy-B1qzS7Xe.mjs";
|
|
11
|
+
import { n as resolveCacheRetention } from "./github-copilot-headers-CqLRrd-i.mjs";
|
|
12
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-B3kUqQ-q.mjs";
|
|
13
|
+
import { C as splitSystemPromptCacheBoundaryForWire, E as stripSystemPromptRelocatableBoundary, T as stripSystemPromptCacheBoundary, a as describeToolResultMediaPlaceholder, c as extractToolResultText, f as preparedRequestSuffix, g as SYSTEM_PROMPT_RELOCATABLE_BOUNDARY, m as uncachedSuffixMessage, s as extractToolResultBlockText, t as adjustMaxTokensForThinking, w as splitSystemPromptRelocatableBoundary } from "./simple-options-D8CTqHvk.mjs";
|
|
14
|
+
import { S as transportAbortError, T as parseJsonObjectPreservingUnsafeIntegers, a as copyProviderAcceptanceObserver, b as sanitizeTransportPayloadText, d as finalizeTransportStream, f as iterateModelStream, g as notifyProviderHttpResponse, i as coerceTransportToolCallArguments, j as parseStreamingJson, k as createToolArgumentPreviewSchedule, l as failTransportStream, r as awaitProviderLifecycleCallback, u as finalizeTerminalToolCallArguments } from "./transport-stream-shared-DEpLe9fG.mjs";
|
|
15
|
+
import { t as parsePositiveInteger } from "./positive-integer-AM4ltyhP.mjs";
|
|
16
|
+
import { a as reconcileAnthropicToolChoice, i as projectAnthropicTools, n as normalizeAnthropicToolChoice, o as resolveOriginalAnthropicToolName, s as toClaudeCodeToolName, t as normalizeAnthropicToolCallId } from "./anthropic-tool-projection-A9GceDnD.mjs";
|
|
17
|
+
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-BgT1IIfq.mjs";
|
|
18
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-v1liRqNt.mjs";
|
|
19
|
+
import { n as isProviderReplayContext, r as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-CHJQzB0n.mjs";
|
|
20
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-C-WfgiLJ.mjs";
|
|
21
21
|
import { markEncodedModelRequestBody } from "./internal/model-request-body.mjs";
|
|
22
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
22
|
+
import { t as createAssistantOutput } from "./assistant-output-kYOaiso5.mjs";
|
|
23
23
|
import { isProxy } from "node:util/types";
|
|
24
|
-
|
|
24
|
+
// packages/ai/src/providers/anthropic-auth-headers.ts
|
|
25
25
|
/** Inspect resolved credential shape for auth routing without exposing its value. */
|
|
26
26
|
function isAnthropicOAuthApiKey(apiKey) {
|
|
27
27
|
return typeof apiKey === "string" && getAiTransportHost().resolveSecretSentinel(apiKey).includes("sk-ant-oat");
|
|
@@ -39,8 +39,7 @@ function omitFoundryBearerCredentialHeaders(headers) {
|
|
|
39
39
|
}
|
|
40
40
|
return Object.keys(next).length > 0 ? next : void 0;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
//#region packages/ai/src/providers/anthropic-server-fallback.ts
|
|
42
|
+
// packages/ai/src/providers/anthropic-server-fallback.ts
|
|
44
43
|
/** Anthropic beta that re-serves safety refusals on an allowed fallback model. */
|
|
45
44
|
const ANTHROPIC_SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
46
45
|
/** Let Anthropic select the recommended model for each refusal category. */
|
|
@@ -122,8 +121,7 @@ function applyAnthropicFallbackBoundary(params) {
|
|
|
122
121
|
}
|
|
123
122
|
}];
|
|
124
123
|
}
|
|
125
|
-
|
|
126
|
-
//#region packages/ai/src/transports/anthropic-payload-policy.ts
|
|
124
|
+
// packages/ai/src/transports/anthropic-payload-policy.ts
|
|
127
125
|
const ANTHROPIC_CACHE_CONTROL_LIMIT = 4;
|
|
128
126
|
const ANTHROPIC_COMPACT_THRESHOLD_MIN = 5e4;
|
|
129
127
|
const ANTHROPIC_COMPACTION_INSTRUCTIONS = "Summarize the transcript inside <summary></summary> tags. Include the current state, decisions, and next steps needed to continue the task in the next context window. Do not call any tools while writing this summary; respond with text only.";
|
|
@@ -184,15 +182,36 @@ function resolveAnthropicCacheOptions(model, cacheRetention) {
|
|
|
184
182
|
supportsCacheControlOnTools: model.compat?.supportsCacheControlOnTools ?? model.provider !== "fireworks"
|
|
185
183
|
};
|
|
186
184
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
185
|
+
const normalizedSystemBlocks = /* @__PURE__ */ new WeakMap();
|
|
186
|
+
const sessionSharedSystemBlocks = /* @__PURE__ */ new WeakSet();
|
|
187
|
+
function buildAnthropicSystemBlocks(systemPrompt, isOAuthToken, cacheControl, claudeCodeVersion = ANTHROPIC_CLAUDE_CODE_VERSION, preparedSystemPrompt) {
|
|
188
|
+
const revision = preparedSystemPrompt?.text === systemPrompt ? preparedSystemPrompt : void 0;
|
|
189
|
+
const policy = cacheControl ? cacheControl.ttl ?? "default" : "none";
|
|
190
|
+
let variants = revision && normalizedSystemBlocks.get(revision);
|
|
191
|
+
let blocks = variants?.get(policy);
|
|
192
|
+
if (!blocks) {
|
|
193
|
+
blocks = systemPrompt ? [{
|
|
194
|
+
type: "text",
|
|
195
|
+
text: sanitizeSurrogates(systemPrompt)
|
|
196
|
+
}] : [];
|
|
197
|
+
normalizeAnthropicSystemBlocks(blocks, revision && cacheControl ? { ...cacheControl } : cacheControl);
|
|
198
|
+
if (systemPrompt && blocks.length === 0) blocks.push({
|
|
199
|
+
type: "text",
|
|
200
|
+
text: ""
|
|
201
|
+
});
|
|
202
|
+
if (revision) {
|
|
203
|
+
variants ??= /* @__PURE__ */ new Map();
|
|
204
|
+
variants.set(policy, blocks);
|
|
205
|
+
normalizedSystemBlocks.set(revision, variants);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (revision) blocks = blocks.map((block) => {
|
|
209
|
+
const editable = {
|
|
210
|
+
...block,
|
|
211
|
+
...block.cache_control ? { cache_control: { ...block.cache_control } } : {}
|
|
212
|
+
};
|
|
213
|
+
if (sessionSharedSystemBlocks.has(block)) sessionSharedSystemBlocks.add(editable);
|
|
214
|
+
return editable;
|
|
196
215
|
});
|
|
197
216
|
if (isOAuthToken) {
|
|
198
217
|
const identityCacheControl = blocks.some((block) => block.cache_control) ? void 0 : cacheControl;
|
|
@@ -214,8 +233,14 @@ function applyAnthropicRequestCacheControl(payload, cacheControl, supportsCacheC
|
|
|
214
233
|
const lastTool = payload.tools.at(-1);
|
|
215
234
|
if (isRecord(lastTool)) lastTool.cache_control = cacheControl;
|
|
216
235
|
}
|
|
217
|
-
const usedMarkers = countAnthropicCacheControlMarkers(payload.system) + countAnthropicCacheControlMarkers(payload.tools);
|
|
218
236
|
const messages = payload.messages;
|
|
237
|
+
let usedMarkers = countAnthropicCacheControlMarkers(payload.system) + countAnthropicCacheControlMarkers(payload.tools);
|
|
238
|
+
if (Array.isArray(messages) && !messages.some((message) => isRecord(message) && message.role === "assistant") && Array.isArray(payload.system)) {
|
|
239
|
+
for (const block of payload.system) if (usedMarkers < 3 && isRecord(block) && sessionSharedSystemBlocks.has(block) && block.cache_control === void 0) {
|
|
240
|
+
block.cache_control = cacheControl;
|
|
241
|
+
usedMarkers++;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
219
244
|
const markerLimit = ANTHROPIC_CACHE_CONTROL_LIMIT - usedMarkers;
|
|
220
245
|
if (!Array.isArray(messages) || messages.length === 0 || markerLimit <= 0) return;
|
|
221
246
|
let stableEnd = messages.length;
|
|
@@ -272,23 +297,37 @@ function normalizeAnthropicSystemBlocks(system, cacheControl) {
|
|
|
272
297
|
record.text = stripSystemPromptCacheBoundary(blockText);
|
|
273
298
|
continue;
|
|
274
299
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const split = splitSystemPromptCacheBoundary(text);
|
|
300
|
+
record.text = stripSystemPromptRelocatableBoundary(blockText);
|
|
301
|
+
const split = splitSystemPromptCacheBoundaryForWire(blockText);
|
|
278
302
|
if (!split) {
|
|
279
|
-
if (record.cache_control === void 0) record.cache_control = cacheControl;
|
|
303
|
+
if (record.cache_control === void 0 && !sessionSharedSystemBlocks.has(record)) record.cache_control = cacheControl;
|
|
280
304
|
normalizedBlocks.push(record);
|
|
281
305
|
continue;
|
|
282
306
|
}
|
|
283
307
|
const { cache_control: existingCacheControl, ...rest } = record;
|
|
284
|
-
|
|
308
|
+
const stablePrefix = stripSystemPromptRelocatableBoundary(split.stablePrefix);
|
|
309
|
+
if (stablePrefix) normalizedBlocks.push({
|
|
285
310
|
...rest,
|
|
286
|
-
text:
|
|
311
|
+
text: stablePrefix,
|
|
287
312
|
cache_control: existingCacheControl ?? cacheControl
|
|
288
313
|
});
|
|
289
|
-
|
|
314
|
+
const runtimeFactsStart = splitSystemPromptRelocatableBoundary(split.dynamicSuffix) ? split.dynamicSuffix.indexOf(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY) : -1;
|
|
315
|
+
const sessionShared = runtimeFactsStart > 0 ? split.dynamicSuffix.slice(0, runtimeFactsStart) : "";
|
|
316
|
+
const sessionOwned = stripSystemPromptRelocatableBoundary(sessionShared.trim() ? split.dynamicSuffix.slice(runtimeFactsStart) : split.dynamicSuffix);
|
|
317
|
+
const dynamicSuffix = stripSystemPromptRelocatableBoundary(split.dynamicSuffix);
|
|
318
|
+
if (sessionShared.trim() && sessionOwned) {
|
|
319
|
+
const sharedBlock = {
|
|
320
|
+
...rest,
|
|
321
|
+
text: sessionShared
|
|
322
|
+
};
|
|
323
|
+
sessionSharedSystemBlocks.add(sharedBlock);
|
|
324
|
+
normalizedBlocks.push(sharedBlock, {
|
|
325
|
+
...rest,
|
|
326
|
+
text: sessionOwned
|
|
327
|
+
});
|
|
328
|
+
} else if (dynamicSuffix) normalizedBlocks.push({
|
|
290
329
|
...rest,
|
|
291
|
-
text:
|
|
330
|
+
text: dynamicSuffix
|
|
292
331
|
});
|
|
293
332
|
}
|
|
294
333
|
if (cacheControl) system.splice(0, system.length, ...normalizedBlocks);
|
|
@@ -443,8 +482,7 @@ function applyAnthropicEphemeralCacheControlMarkers(payloadObj, cacheControl = {
|
|
|
443
482
|
}
|
|
444
483
|
}
|
|
445
484
|
}
|
|
446
|
-
|
|
447
|
-
//#region packages/ai/src/providers/anthropic-refusal.ts
|
|
485
|
+
// packages/ai/src/providers/anthropic-refusal.ts
|
|
448
486
|
function applyAnthropicRefusal(output, stopDetails, provider) {
|
|
449
487
|
const record = asOptionalObjectRecord(stopDetails);
|
|
450
488
|
const details = {
|
|
@@ -465,8 +503,7 @@ function applyAnthropicRefusal(output, stopDetails, provider) {
|
|
|
465
503
|
}
|
|
466
504
|
}];
|
|
467
505
|
}
|
|
468
|
-
|
|
469
|
-
//#region packages/ai/src/providers/anthropic-thinking-replay.ts
|
|
506
|
+
// packages/ai/src/providers/anthropic-thinking-replay.ts
|
|
470
507
|
const ANTHROPIC_OMITTED_REASONING_TEXT = "[assistant reasoning omitted]";
|
|
471
508
|
function applyAnthropicThinkingBindingControls(params, directApiKeyBetaHeader) {
|
|
472
509
|
if (directApiKeyBetaHeader === void 0 || !isRecord(params.thinking) || params.thinking.type !== "adaptive") return;
|
|
@@ -513,8 +550,7 @@ function findActiveAnthropicToolTurnAssistantIndex(messages) {
|
|
|
513
550
|
}
|
|
514
551
|
return [...toolResultIds].every((toolCallId) => toolCallIds.has(toolCallId)) ? index : -1;
|
|
515
552
|
}
|
|
516
|
-
|
|
517
|
-
//#region packages/ai/src/providers/anthropic-usage.ts
|
|
553
|
+
// packages/ai/src/providers/anthropic-usage.ts
|
|
518
554
|
const BILLED_USAGE_KEYS = [
|
|
519
555
|
"input",
|
|
520
556
|
"output",
|
|
@@ -648,8 +684,7 @@ function applyAnthropicMessageDeltaUsage(target, usage, messageStartPromptUsage)
|
|
|
648
684
|
};
|
|
649
685
|
} else target.contextUsage = { state: "unavailable" };
|
|
650
686
|
}
|
|
651
|
-
|
|
652
|
-
//#region packages/ai/src/transports/anthropic-compaction-replay.ts
|
|
687
|
+
// packages/ai/src/transports/anthropic-compaction-replay.ts
|
|
653
688
|
const ANTHROPIC_COMPACTION_REPLAY_TYPE = "anthropic-compaction";
|
|
654
689
|
const ANTHROPIC_COMPACTION_SUPPRESSION_TYPE = "anthropic-compaction-suppression";
|
|
655
690
|
const ANTHROPIC_COMPACTION_SUPPRESSION_DATA = "rejected";
|
|
@@ -772,8 +807,7 @@ function isAnthropicReplayRejection(error) {
|
|
|
772
807
|
].filter((value) => typeof value === "string").join(" ").toLowerCase();
|
|
773
808
|
return (record.status === 400 || record.errorCode === "400" || text.startsWith("http 400:")) && (text.includes("compaction") || text.includes("context_management"));
|
|
774
809
|
}
|
|
775
|
-
|
|
776
|
-
//#region packages/ai/src/internal/anthropic-inline-images.ts
|
|
810
|
+
// packages/ai/src/internal/anthropic-inline-images.ts
|
|
777
811
|
const ANTHROPIC_IMAGE_MEDIA_TYPE_SET = /* @__PURE__ */ new Set([
|
|
778
812
|
"image/jpeg",
|
|
779
813
|
"image/png",
|
|
@@ -808,9 +842,17 @@ async function normalizeAnthropicInlineContent(content, budget) {
|
|
|
808
842
|
}
|
|
809
843
|
return normalized;
|
|
810
844
|
}
|
|
811
|
-
|
|
812
|
-
//#region packages/ai/src/transports/anthropic-request-body.ts
|
|
845
|
+
// packages/ai/src/transports/anthropic-request-body.ts
|
|
813
846
|
const fragments = /* @__PURE__ */ new WeakMap();
|
|
847
|
+
const encoder = new TextEncoder();
|
|
848
|
+
function encodeMessageFragment(message, source) {
|
|
849
|
+
let fragment = source ? fragments.get(source) : void 0;
|
|
850
|
+
if (!fragment) {
|
|
851
|
+
fragment = encoder.encode("," + JSON.stringify(message));
|
|
852
|
+
if (source) fragments.set(source, fragment);
|
|
853
|
+
}
|
|
854
|
+
return fragment;
|
|
855
|
+
}
|
|
814
856
|
function copyPlainData(value, retainFrozen = false, copies = /* @__PURE__ */ new Map()) {
|
|
815
857
|
if (!value || typeof value !== "object") return value;
|
|
816
858
|
if (retainFrozen && getAiTransportHost().immutableData?.isDeeplyFrozenPlainData(value)) return value;
|
|
@@ -848,20 +890,29 @@ function samePlainData(left, right, seen = /* @__PURE__ */ new Map()) {
|
|
|
848
890
|
}
|
|
849
891
|
return true;
|
|
850
892
|
}
|
|
851
|
-
/** Hooks receive editable containers;
|
|
893
|
+
/** Hooks receive editable containers; envelope edits preserve unchanged history fragments. */
|
|
852
894
|
async function applyAnthropicPayloadHook(params, model, options) {
|
|
853
895
|
if (!options?.onPayload) return { params };
|
|
854
|
-
const
|
|
855
|
-
const
|
|
896
|
+
const immutable = getAiTransportHost().immutableData;
|
|
897
|
+
const plain = immutable?.isPlainData;
|
|
898
|
+
const snapshot = plain?.(params) ? copyPlainData(params.messages, true) : void 0;
|
|
856
899
|
const editable = snapshot ? copyPlainData(params) : {
|
|
857
900
|
...params,
|
|
858
901
|
messages: params.messages.map((message) => plain?.(message) ? copyPlainData(message) : message)
|
|
859
902
|
};
|
|
860
|
-
const replacement = await options.onPayload(editable, model);
|
|
861
|
-
|
|
903
|
+
const replacement = await awaitProviderLifecycleCallback(() => options.onPayload?.(editable, model), options.signal);
|
|
904
|
+
let unchanged = false;
|
|
905
|
+
if ((replacement === void 0 || replacement === editable) && snapshot !== void 0) {
|
|
906
|
+
const { messages, ...envelope } = Object.getOwnPropertyDescriptors(editable);
|
|
907
|
+
unchanged = messages !== void 0 && "value" in messages && samePlainData(snapshot, messages.value) && plain?.(Object.create(Object.getPrototypeOf(editable), envelope)) === true;
|
|
908
|
+
if (unchanged && !("toJSON" in Object.prototype) && !("toJSON" in Array.prototype)) for (let index = 0; index < snapshot.length; index++) {
|
|
909
|
+
const source = snapshot[index];
|
|
910
|
+
if (immutable?.isDeeplyFrozenPlainData(source)) encodeMessageFragment(editable.messages[index], source);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
862
913
|
return {
|
|
863
914
|
params: replacement === void 0 ? editable : replacement,
|
|
864
|
-
messageSources: unchanged ? snapshot
|
|
915
|
+
messageSources: unchanged ? snapshot : null
|
|
865
916
|
};
|
|
866
917
|
}
|
|
867
918
|
/** Assemble immutable history bytes while encoding the envelope and mutable tail each time. */
|
|
@@ -875,17 +926,12 @@ function serializeAnthropicRequestBody(payload, messageSources) {
|
|
|
875
926
|
for (const key of Object.keys(payload)) {
|
|
876
927
|
const value = Reflect.get(payload, key);
|
|
877
928
|
if (key === "messages") {
|
|
878
|
-
parts.push(`${envelope}${separator}"messages":[`);
|
|
929
|
+
parts.push(encoder.encode(`${envelope}${separator}"messages":[`));
|
|
879
930
|
envelope = "]";
|
|
880
931
|
for (let index = 0; index < messages.length; index++) {
|
|
881
932
|
const message = messages[index];
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
if (!fragment) {
|
|
885
|
-
fragment = new Blob(["," + JSON.stringify(message)]);
|
|
886
|
-
if (reusable) fragments.set(message, fragment);
|
|
887
|
-
}
|
|
888
|
-
parts.push(index === 0 ? fragment.slice(1) : fragment);
|
|
933
|
+
const fragment = encodeMessageFragment(message, message !== null && typeof message === "object" && immutable.isDeeplyFrozenPlainData(message) ? message : void 0);
|
|
934
|
+
parts.push(index === 0 ? fragment.subarray(1) : fragment);
|
|
889
935
|
}
|
|
890
936
|
} else {
|
|
891
937
|
const json = JSON.stringify(value);
|
|
@@ -894,13 +940,17 @@ function serializeAnthropicRequestBody(payload, messageSources) {
|
|
|
894
940
|
}
|
|
895
941
|
separator = ",";
|
|
896
942
|
}
|
|
897
|
-
parts.push(`${envelope}}`);
|
|
898
|
-
const body = new
|
|
943
|
+
parts.push(encoder.encode(`${envelope}}`));
|
|
944
|
+
const body = new Uint8Array(parts.reduce((size, part) => size + part.byteLength, 0));
|
|
945
|
+
let offset = 0;
|
|
946
|
+
for (const part of parts) {
|
|
947
|
+
body.set(part, offset);
|
|
948
|
+
offset += part.byteLength;
|
|
949
|
+
}
|
|
899
950
|
markEncodedModelRequestBody(body, payload.stream);
|
|
900
951
|
return body;
|
|
901
952
|
}
|
|
902
|
-
|
|
903
|
-
//#region packages/ai/src/transports/anthropic-transport-options.ts
|
|
953
|
+
// packages/ai/src/transports/anthropic-transport-options.ts
|
|
904
954
|
const ANTHROPIC_MESSAGES_DEFAULT_MAX_TOKENS = 4096;
|
|
905
955
|
const ANTHROPIC_MESSAGES_FALLBACK_CONTEXT_DIVISOR = 4;
|
|
906
956
|
function resolvePositiveAnthropicTokenLimit(value) {
|
|
@@ -922,7 +972,7 @@ function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
|
922
972
|
modelContextWindow: model.contextWindow,
|
|
923
973
|
modelMaxTokens: model.maxTokens,
|
|
924
974
|
requestedMaxTokens: options?.maxTokens,
|
|
925
|
-
useModelDefault:
|
|
975
|
+
useModelDefault: usesClaude5RequestContract(model)
|
|
926
976
|
});
|
|
927
977
|
if (baseMaxTokens === void 0) throw new Error(`Anthropic Messages transport requires a positive maxTokens value for ${model.provider}/${model.id}`);
|
|
928
978
|
const resolved = copyProviderAcceptanceObserver(options, {
|
|
@@ -946,6 +996,7 @@ function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
|
946
996
|
anthropicCompactThreshold: options?.anthropicCompactThreshold,
|
|
947
997
|
cacheTtlPruning: options?.cacheTtlPruning,
|
|
948
998
|
onClaudeCodeVersionRequired: options?.onClaudeCodeVersionRequired,
|
|
999
|
+
onFastModeUnsupported: options?.onFastModeUnsupported,
|
|
949
1000
|
...options?.authProfileId ? { authProfileId: options.authProfileId } : {}
|
|
950
1001
|
});
|
|
951
1002
|
resolved.reasoning = applyAnthropicThinkingOptions(model, resolved, options, "transport");
|
|
@@ -985,8 +1036,7 @@ function resolveCompletionTokenReservation(model, maxTokens, reasoning) {
|
|
|
985
1036
|
if (!reasoning || reasoning === "off" || model.api !== "anthropic-messages" && model.api !== "bedrock-converse-stream") return maxTokens;
|
|
986
1037
|
return adjustMaxTokensForThinking(maxTokens, resolvePositiveAnthropicTokenLimit(model.maxTokens) ?? Number.POSITIVE_INFINITY, reasoning).maxTokens;
|
|
987
1038
|
}
|
|
988
|
-
|
|
989
|
-
//#region packages/ai/src/transports/anthropic-messages.ts
|
|
1039
|
+
// packages/ai/src/transports/anthropic-messages.ts
|
|
990
1040
|
const anthropicMessageProjections = /* @__PURE__ */ new WeakMap();
|
|
991
1041
|
const NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
|
|
992
1042
|
async function convertContentBlocks(content, model, imageBudget, profile, isError) {
|
|
@@ -1034,7 +1084,7 @@ async function buildAnthropicRequest(model, context, options, profile, isOAuthTo
|
|
|
1034
1084
|
}) : options?.maxTokens ?? model.maxTokens;
|
|
1035
1085
|
if (managed && maxTokens === void 0) throw new Error(`Anthropic Messages transport requires a positive maxTokens value for ${model.provider}/${model.id}`);
|
|
1036
1086
|
const { cacheControl, supportsCacheControlOnTools } = resolveAnthropicCacheOptions(model, options?.cacheRetention);
|
|
1037
|
-
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthToken, cacheControl, claudeCodeVersion);
|
|
1087
|
+
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthToken, cacheControl, claudeCodeVersion, context.preparedSystemPrompt);
|
|
1038
1088
|
let toolProjection;
|
|
1039
1089
|
let eagerToolInputStreaming = false;
|
|
1040
1090
|
if (context.tools) {
|
|
@@ -1044,7 +1094,6 @@ async function buildAnthropicRequest(model, context, options, profile, isOAuthTo
|
|
|
1044
1094
|
}
|
|
1045
1095
|
const replayPlan = buildAnthropicReplayPlan(context.messages, model, {
|
|
1046
1096
|
enabled: !isOAuthToken && options?.anthropicServerCompaction === true,
|
|
1047
|
-
authProfileId: options?.authProfileId,
|
|
1048
1097
|
sessionId: options?.sessionId
|
|
1049
1098
|
});
|
|
1050
1099
|
const cacheBreakpointOptOutMessageIndexes = /* @__PURE__ */ new Set();
|
|
@@ -1245,6 +1294,7 @@ async function buildAnthropicRequest(model, context, options, profile, isOAuthTo
|
|
|
1245
1294
|
}
|
|
1246
1295
|
if (output) {
|
|
1247
1296
|
appendMessage(output);
|
|
1297
|
+
if (transformed.slice(i, end).some((source) => uncachedSuffixMessage.has(source))) cacheBreakpointOptOutMessageIndexes.add(messages.length - 1);
|
|
1248
1298
|
if (msg.role === "user") {
|
|
1249
1299
|
const runtimeContextRetained = msg.runtimeContext !== void 0 ? msg.runtimeContext.retained : msg.runtimeContextCarrierRetained;
|
|
1250
1300
|
if (hasRuntimeContextMarker(msg) && !(runtimeContextRetained ?? modelRetainsRuntimeContext)) cacheBreakpointOptOutMessageIndexes.add(messages.length - 1);
|
|
@@ -1323,8 +1373,12 @@ async function prepareAnthropicRequest(initialParams, model, options, directApiK
|
|
|
1323
1373
|
messageSources: hooked.messageSources
|
|
1324
1374
|
};
|
|
1325
1375
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1376
|
+
// packages/ai/src/transports/anthropic-stream-lifecycle.ts
|
|
1377
|
+
function notifyOwner(callback) {
|
|
1378
|
+
try {
|
|
1379
|
+
callback();
|
|
1380
|
+
} catch {}
|
|
1381
|
+
}
|
|
1328
1382
|
/** Entry points retain their SDK/fetch adapters; request and terminal ownership is shared. */
|
|
1329
1383
|
async function runAnthropicStreamLifecycle(params) {
|
|
1330
1384
|
const { model, stream, options, profile } = params;
|
|
@@ -1332,7 +1386,7 @@ async function runAnthropicStreamLifecycle(params) {
|
|
|
1332
1386
|
const refusalBuffer = usesClaudeStreamingRefusalContract(model) ? createDeferredEventBuffer(stream) : void 0;
|
|
1333
1387
|
let replayedCompaction;
|
|
1334
1388
|
try {
|
|
1335
|
-
const send = async (
|
|
1389
|
+
const send = async (retry) => {
|
|
1336
1390
|
const prepared = await params.prepare();
|
|
1337
1391
|
const built = await buildAnthropicRequest(model, prepared.context, prepared.options, profile, prepared.isOAuthToken, prepared.serverSideFallback, prepared.claudeCodeVersion);
|
|
1338
1392
|
replayedCompaction = built.replayedCompaction;
|
|
@@ -1341,6 +1395,7 @@ async function runAnthropicStreamLifecycle(params) {
|
|
|
1341
1395
|
...body,
|
|
1342
1396
|
stream: true
|
|
1343
1397
|
};
|
|
1398
|
+
if (!retry.speed) delete wireBody.speed;
|
|
1344
1399
|
try {
|
|
1345
1400
|
const { response, events } = await prepared.request(wireBody, headers, () => serializeAnthropicRequestBody(wireBody, messageSources));
|
|
1346
1401
|
await notifyProviderHttpResponse({
|
|
@@ -1356,16 +1411,27 @@ async function runAnthropicStreamLifecycle(params) {
|
|
|
1356
1411
|
};
|
|
1357
1412
|
} catch (error) {
|
|
1358
1413
|
const required = prepared.isOAuthToken ? readRequiredClaudeCodeVersion(error) : void 0;
|
|
1359
|
-
if (
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1414
|
+
if (retry.version && required && raiseClaudeCodeVersionFloor(required)) {
|
|
1415
|
+
notifyOwner(() => prepared.options?.onClaudeCodeVersionRequired?.(required));
|
|
1416
|
+
return send({
|
|
1417
|
+
...retry,
|
|
1418
|
+
version: false
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
if (retry.speed && wireBody.speed !== void 0 && isUnsupportedClaudeFastModeError(error)) {
|
|
1422
|
+
notifyOwner(() => prepared.options?.onFastModeUnsupported?.(model.id));
|
|
1423
|
+
return send({
|
|
1424
|
+
...retry,
|
|
1425
|
+
speed: false
|
|
1426
|
+
});
|
|
1364
1427
|
}
|
|
1365
1428
|
throw error;
|
|
1366
1429
|
}
|
|
1367
1430
|
};
|
|
1368
|
-
const { prepared, built, events } = await send(
|
|
1431
|
+
const { prepared, built, events } = await send({
|
|
1432
|
+
version: true,
|
|
1433
|
+
speed: true
|
|
1434
|
+
});
|
|
1369
1435
|
await (async () => {
|
|
1370
1436
|
const reducerOptions = prepared.options ?? {};
|
|
1371
1437
|
const isOAuthToken = prepared.isOAuthToken;
|
|
@@ -1719,5 +1785,4 @@ async function runAnthropicStreamLifecycle(params) {
|
|
|
1719
1785
|
});
|
|
1720
1786
|
}
|
|
1721
1787
|
}
|
|
1722
|
-
//#endregion
|
|
1723
1788
|
export { resolveAnthropicServerCompactionPlan as A, usesFoundryBearerAuth as B, isAnthropicServerToolClearingEnabled as C, resolveAnthropicEphemeralCacheControl as D, resolveAnthropicCacheOptions as E, applyAnthropicFallbackBoundary as F, readAnthropicFallbackBoundary as I, resolveAnthropicFallbackServingModelCost as L, ANTHROPIC_SERVER_SIDE_FALLBACKS as M, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as N, resolveAnthropicPayloadPolicy as O, CLAUDE_OPUS_FALLBACK_MODEL_COST as P, isAnthropicOAuthApiKey as R, buildAnthropicSystemBlocks as S, logAnthropicContextEdits as T, applyAnthropicRefusal as _, resolveNewestAnthropicCompaction as a, applyAnthropicPayloadPolicyToParams as b, readAnthropicCacheWriteUsage as c, readLastAnthropicIterationUsage as d, ANTHROPIC_OMITTED_REASONING_TEXT as f, readAnthropicInputTransformations as g, logAnthropicThinkingDrops as h, resolveCompletionTokenReservation as i, supportsAnthropicServerSideFallback as j, resolveAnthropicRequestBetaHeader as k, readAnthropicPromptUsageSnapshot as l, findActiveAnthropicToolTurnAssistantIndex as m, applyAnthropicThinkingOptions as n, applyAnthropicMessageDeltaUsage as o, applyAnthropicThinkingBindingControls as p, resolveAnthropicTransportOptions as r, applyAnthropicMessageStartUsage as s, runAnthropicStreamLifecycle as t, readAnthropicUsageTokenCount as u, applyAnthropicContextManagementToRequest as v, isDirectAnthropicModel as w, applyAnthropicRequestCacheControl as x, applyAnthropicEphemeralCacheControlMarkers as y, omitFoundryBearerCredentialHeaders as z };
|
package/dist/{anthropic-tool-projection-DcvsDiyX.mjs → anthropic-tool-projection-A9GceDnD.mjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { o as isRecord, s as isStringArray } from "./record-coerce-
|
|
2
|
-
import { r as sortPromptCacheToolsByName } from "./prompt-cache-stability-
|
|
3
|
-
import { _ as SCHEMA_ARRAY_KEYS, b as SCHEMA_OBJECT_KEYS, f as inheritToolSchemaTruncation, i as publishRuntimeToolInputSchema, r as projectRuntimeToolInputSchema, t as getPublishedRuntimeToolInputSchema, v as SCHEMA_MAP_KEYS } from "./tool-schema-json-projection-
|
|
4
|
-
|
|
1
|
+
import { o as isRecord, s as isStringArray } from "./record-coerce-BgUo6bj4.mjs";
|
|
2
|
+
import { r as sortPromptCacheToolsByName } from "./prompt-cache-stability-oTx0nIsh.mjs";
|
|
3
|
+
import { _ as SCHEMA_ARRAY_KEYS, b as SCHEMA_OBJECT_KEYS, f as inheritToolSchemaTruncation, i as publishRuntimeToolInputSchema, r as projectRuntimeToolInputSchema, t as getPublishedRuntimeToolInputSchema, v as SCHEMA_MAP_KEYS } from "./tool-schema-json-projection-C13fPskA.mjs";
|
|
4
|
+
// packages/ai/src/providers/anthropic-tool-projection.ts
|
|
5
5
|
const CLAUDE_CODE_TOOL_LOOKUP = new Map([
|
|
6
6
|
"Read",
|
|
7
7
|
"Write",
|
|
@@ -151,5 +151,4 @@ function reconcileAnthropicToolChoice(choice, projection) {
|
|
|
151
151
|
function resolveOriginalAnthropicToolName(name, projection) {
|
|
152
152
|
return projection?.tools.find((tool) => tool.wireName === name)?.originalName ?? name;
|
|
153
153
|
}
|
|
154
|
-
//#endregion
|
|
155
154
|
export { reconcileAnthropicToolChoice as a, projectAnthropicTools as i, normalizeAnthropicToolChoice as n, resolveOriginalAnthropicToolName as o, prepareAnthropicInputSchema as r, toClaudeCodeToolName as s, normalizeAnthropicToolCallId as t };
|
package/dist/{anthropic-tool-projection-DKAlondV.d.mts → anthropic-tool-projection-DCOX8qai.d.mts}
RENAMED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { r as AnthropicOptions } from "./provider-options-
|
|
1
|
+
import { r as AnthropicOptions } from "./provider-options-CR_UfgUE.mjs";
|
|
2
2
|
import { Tool } from "@anthropic-ai/sdk/resources/messages.js";
|
|
3
|
-
//#region packages/ai/src/providers/anthropic-tool-projection.d.ts
|
|
4
3
|
type AnthropicProjectedTool = {
|
|
5
4
|
readonly originalName: string;
|
|
6
5
|
readonly wireName: string;
|
|
@@ -46,5 +45,4 @@ declare function projectAnthropicTools(tools: readonly {
|
|
|
46
45
|
declare function reconcileAnthropicToolChoice(choice: AnthropicProjectedToolChoice, projection: AnthropicToolProjection): AnthropicProjectedToolChoice | undefined;
|
|
47
46
|
/** Maps Claude Code wire names without trusting every direct/custom descriptor. */
|
|
48
47
|
declare function resolveOriginalAnthropicToolName(name: string, projection: AnthropicToolProjection | undefined): string;
|
|
49
|
-
//#endregion
|
|
50
48
|
export { prepareAnthropicInputSchema as a, resolveOriginalAnthropicToolName as c, normalizeAnthropicToolChoice as i, toClaudeCodeToolName as l, AnthropicToolProjection as n, projectAnthropicTools as o, normalizeAnthropicToolCallId as r, reconcileAnthropicToolChoice as s, AnthropicProjectedToolChoice as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { at as StreamOptions, it as StreamFunction, n as Api, tt as SimpleStreamOptions } from "./types-
|
|
2
|
-
import "./index-
|
|
3
|
-
//#region packages/ai/src/api-registry.d.ts
|
|
1
|
+
import { at as StreamOptions, it as StreamFunction, n as Api, tt as SimpleStreamOptions } from "./types-BNp71XKW.mjs";
|
|
2
|
+
import "./index-BDF5kurq.mjs";
|
|
4
3
|
/** Runtime stream adapter signature stored in the API provider registry. */
|
|
5
4
|
type ApiStreamFunction = StreamFunction;
|
|
6
5
|
/** Runtime simple-stream adapter signature stored in the API provider registry. */
|
|
@@ -29,5 +28,4 @@ declare function createApiRegistry(): {
|
|
|
29
28
|
clearApiProviders: () => void;
|
|
30
29
|
};
|
|
31
30
|
type ApiRegistry = ReturnType<typeof createApiRegistry>;
|
|
32
|
-
//#endregion
|
|
33
31
|
export { RegisteredApiProvider as a, ApiStreamSimpleFunction as i, ApiRegistry as n, createApiRegistry as o, ApiStreamFunction as r, ApiProvider as t };
|