@rulvar/anthropic 1.1.0 → 1.2.0
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/index.d.ts +11 -12
- package/dist/index.js +13 -14
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,13 +6,13 @@ interface AnthropicModelInfo {
|
|
|
6
6
|
/**
|
|
7
7
|
* Wire thinking form: current models accept only adaptive; the
|
|
8
8
|
* enabled/budget form remains functional only on Opus 4.6 and Sonnet
|
|
9
|
-
* 4.6
|
|
9
|
+
* 4.6.
|
|
10
10
|
*/
|
|
11
11
|
thinkingForm: "adaptive" | "enabled-budget";
|
|
12
|
-
/** Minimum cacheable prefix in tokens
|
|
12
|
+
/** Minimum cacheable prefix in tokens. */
|
|
13
13
|
cacheMinTokens: number;
|
|
14
14
|
}
|
|
15
|
-
/** Static seed table
|
|
15
|
+
/** Static seed table naming the current model set. */
|
|
16
16
|
declare const ANTHROPIC_MODELS: Record<string, AnthropicModelInfo>;
|
|
17
17
|
/**
|
|
18
18
|
* Unknown Anthropic models are assumed current-generation: adaptive
|
|
@@ -22,7 +22,7 @@ declare const ANTHROPIC_MODELS: Record<string, AnthropicModelInfo>;
|
|
|
22
22
|
declare function anthropicModelInfo(model: string): AnthropicModelInfo;
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/adapter.d.ts
|
|
25
|
-
/** pause_turn continuation cap
|
|
25
|
+
/** pause_turn continuation cap. */
|
|
26
26
|
declare const DEFAULT_PAUSE_TURN_MAX_CONTINUATIONS = 5;
|
|
27
27
|
/** The client sub-surface the adapter consumes; injectable for tests. */
|
|
28
28
|
interface AnthropicClientLike {
|
|
@@ -51,12 +51,12 @@ interface AnthropicAdapterOptions {
|
|
|
51
51
|
/**
|
|
52
52
|
* Creates the first-class Anthropic adapter (id 'anthropic'). SDK
|
|
53
53
|
* autoretries are disabled (max_retries 0): the core owns retries and
|
|
54
|
-
* wall-clock
|
|
54
|
+
* wall-clock.
|
|
55
55
|
*/
|
|
56
56
|
declare function anthropic(options?: AnthropicAdapterOptions): ProviderAdapter;
|
|
57
57
|
//#endregion
|
|
58
58
|
//#region src/wire.d.ts
|
|
59
|
-
/** Bijective canonical-to-wire tool-call id map
|
|
59
|
+
/** Bijective canonical-to-wire tool-call id map. */
|
|
60
60
|
declare class IdMap {
|
|
61
61
|
private readonly toWire;
|
|
62
62
|
private readonly toCanonical;
|
|
@@ -75,8 +75,7 @@ type Block = Record<string, unknown>;
|
|
|
75
75
|
/**
|
|
76
76
|
* Builds Messages API params from a ChatRequest. cacheHint compiles into
|
|
77
77
|
* cache_control breakpoints; beyond the provider cap of 4 the DEEPEST
|
|
78
|
-
* breakpoints are kept and the shallowest dropped, deterministically
|
|
79
|
-
* (docs/04, sections 1.7 and 4.4).
|
|
78
|
+
* breakpoints are kept and the shallowest dropped, deterministically.
|
|
80
79
|
*/
|
|
81
80
|
declare function buildAnthropicParams(req: ChatRequest, options: {
|
|
82
81
|
ids: IdMap;
|
|
@@ -92,14 +91,14 @@ interface MappedStop {
|
|
|
92
91
|
pauseTurn: boolean;
|
|
93
92
|
}
|
|
94
93
|
/**
|
|
95
|
-
* The
|
|
94
|
+
* The stop-reason table. pause_turn never surfaces as
|
|
96
95
|
* a canonical finish: the adapter continues internally.
|
|
97
96
|
*/
|
|
98
97
|
declare function mapStopReason(stopReason: string | null | undefined, stopDetails: Record<string, unknown> | null | undefined): MappedStop;
|
|
99
98
|
/**
|
|
100
99
|
* Normalizes Messages API usage under the Usage invariant: Anthropic
|
|
101
100
|
* reports input_tokens EXCLUDING cache reads and writes, so the canonical
|
|
102
|
-
* inputTokens is the sum of all three
|
|
101
|
+
* inputTokens is the sum of all three.
|
|
103
102
|
*/
|
|
104
103
|
declare function normalizeAnthropicUsage(raw: Record<string, unknown> | undefined): Usage;
|
|
105
104
|
interface TurnMapping {
|
|
@@ -115,7 +114,7 @@ interface TurnMapping {
|
|
|
115
114
|
* terminal finish unless the turn paused (pause_turn) or errored.
|
|
116
115
|
* `carryRetained` holds thinking blocks from earlier pause_turn
|
|
117
116
|
* continuations of the same turn so the terminal finish ships the whole
|
|
118
|
-
* turn's retention payload (
|
|
117
|
+
* turn's retention payload (M4-T02).
|
|
119
118
|
*/
|
|
120
119
|
declare function mapAnthropicStream(stream: AsyncIterable<AnthropicStreamEvent>, ids: IdMap, emit: (event: ChatEvent) => void, options?: {
|
|
121
120
|
carryRetained?: Block[];
|
|
@@ -124,7 +123,7 @@ declare function mapAnthropicStream(stream: AsyncIterable<AnthropicStreamEvent>,
|
|
|
124
123
|
* Projects an SDK/API error into the retryable WireError vocabulary:
|
|
125
124
|
* 429 rate limits surface retryAfterMs and the x-ratelimit-* buckets; 529
|
|
126
125
|
* overloaded and 5xx are retryable transport; everything else is terminal
|
|
127
|
-
* transport
|
|
126
|
+
* transport. Adapters never sleep internally.
|
|
128
127
|
*/
|
|
129
128
|
declare function anthropicErrorToWire(error: unknown): WireError;
|
|
130
129
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ function current(contextWindow, maxOutputTokens, pricing, cacheMinTokens) {
|
|
|
28
28
|
cacheMinTokens
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
/** Static seed table
|
|
31
|
+
/** Static seed table naming the current model set. */
|
|
32
32
|
const ANTHROPIC_MODELS = {
|
|
33
33
|
"claude-fable-5": current(1e6, 128e3, {
|
|
34
34
|
in: 20,
|
|
@@ -114,10 +114,10 @@ function anthropicModelInfo(model) {
|
|
|
114
114
|
* the SSE-to-ChatEvent stream mapper with pause_turn absorption, the full
|
|
115
115
|
* stop-reason table, and usage normalization under the Usage invariant.
|
|
116
116
|
*
|
|
117
|
-
*
|
|
117
|
+
* Adapter contract: https://docs.rulvar.com/guide/adapter-authors.
|
|
118
118
|
* Pure functions; the adapter glue in adapter.ts owns the SDK client.
|
|
119
119
|
*/
|
|
120
|
-
/** Bijective canonical-to-wire tool-call id map
|
|
120
|
+
/** Bijective canonical-to-wire tool-call id map. */
|
|
121
121
|
var IdMap = class {
|
|
122
122
|
toWire = /* @__PURE__ */ new Map();
|
|
123
123
|
toCanonical = /* @__PURE__ */ new Map();
|
|
@@ -149,8 +149,8 @@ var IdMap = class {
|
|
|
149
149
|
* (minItems, the string bounds, pattern, format, enum and const all
|
|
150
150
|
* pass). The validator guards exactly two wire positions: tools sent
|
|
151
151
|
* with strict: true and output_config.format json_schema; plain tools
|
|
152
|
-
* accept full JSON Schema. Probed live on claude-sonnet-5, 2026-07-11
|
|
153
|
-
*
|
|
152
|
+
* accept full JSON Schema. Probed live on claude-sonnet-5, 2026-07-11.
|
|
153
|
+
* The engine still validates tool args and
|
|
154
154
|
* structured output against the UNSCRUBBED schema, so the dropped
|
|
155
155
|
* keywords stay enforced; only the model-side hint is lost.
|
|
156
156
|
*/
|
|
@@ -220,8 +220,7 @@ function cacheControl(ttl) {
|
|
|
220
220
|
/**
|
|
221
221
|
* Builds Messages API params from a ChatRequest. cacheHint compiles into
|
|
222
222
|
* cache_control breakpoints; beyond the provider cap of 4 the DEEPEST
|
|
223
|
-
* breakpoints are kept and the shallowest dropped, deterministically
|
|
224
|
-
* (docs/04, sections 1.7 and 4.4).
|
|
223
|
+
* breakpoints are kept and the shallowest dropped, deterministically.
|
|
225
224
|
*/
|
|
226
225
|
function buildAnthropicParams(req, options) {
|
|
227
226
|
const systemBlocks = [];
|
|
@@ -352,7 +351,7 @@ function applyCacheHint(params, hint) {
|
|
|
352
351
|
}
|
|
353
352
|
}
|
|
354
353
|
/**
|
|
355
|
-
* The
|
|
354
|
+
* The stop-reason table. pause_turn never surfaces as
|
|
356
355
|
* a canonical finish: the adapter continues internally.
|
|
357
356
|
*/
|
|
358
357
|
function mapStopReason(stopReason, stopDetails) {
|
|
@@ -398,7 +397,7 @@ function mapStopReason(stopReason, stopDetails) {
|
|
|
398
397
|
/**
|
|
399
398
|
* Normalizes Messages API usage under the Usage invariant: Anthropic
|
|
400
399
|
* reports input_tokens EXCLUDING cache reads and writes, so the canonical
|
|
401
|
-
* inputTokens is the sum of all three
|
|
400
|
+
* inputTokens is the sum of all three.
|
|
402
401
|
*/
|
|
403
402
|
function normalizeAnthropicUsage(raw) {
|
|
404
403
|
const input = typeof raw?.input_tokens === "number" ? raw.input_tokens : 0;
|
|
@@ -418,7 +417,7 @@ function normalizeAnthropicUsage(raw) {
|
|
|
418
417
|
* terminal finish unless the turn paused (pause_turn) or errored.
|
|
419
418
|
* `carryRetained` holds thinking blocks from earlier pause_turn
|
|
420
419
|
* continuations of the same turn so the terminal finish ships the whole
|
|
421
|
-
* turn's retention payload (
|
|
420
|
+
* turn's retention payload (M4-T02).
|
|
422
421
|
*/
|
|
423
422
|
async function mapAnthropicStream(stream, ids, emit, options) {
|
|
424
423
|
const mapping = {
|
|
@@ -584,7 +583,7 @@ async function mapAnthropicStream(stream, ids, emit, options) {
|
|
|
584
583
|
* Projects an SDK/API error into the retryable WireError vocabulary:
|
|
585
584
|
* 429 rate limits surface retryAfterMs and the x-ratelimit-* buckets; 529
|
|
586
585
|
* overloaded and 5xx are retryable transport; everything else is terminal
|
|
587
|
-
* transport
|
|
586
|
+
* transport. Adapters never sleep internally.
|
|
588
587
|
*/
|
|
589
588
|
function anthropicErrorToWire(error) {
|
|
590
589
|
const record = error;
|
|
@@ -639,14 +638,14 @@ function anthropicErrorToWire(error) {
|
|
|
639
638
|
* wire mapping, with pause_turn absorption, SDK autoretries disabled, and
|
|
640
639
|
* refreshCaps from the capabilities-bearing model list.
|
|
641
640
|
*
|
|
642
|
-
*
|
|
641
|
+
* Full contract: https://docs.rulvar.com/guide/providers.
|
|
643
642
|
*/
|
|
644
|
-
/** pause_turn continuation cap
|
|
643
|
+
/** pause_turn continuation cap. */
|
|
645
644
|
const DEFAULT_PAUSE_TURN_MAX_CONTINUATIONS = 5;
|
|
646
645
|
/**
|
|
647
646
|
* Creates the first-class Anthropic adapter (id 'anthropic'). SDK
|
|
648
647
|
* autoretries are disabled (max_retries 0): the core owns retries and
|
|
649
|
-
* wall-clock
|
|
648
|
+
* wall-clock.
|
|
650
649
|
*/
|
|
651
650
|
function anthropic(options = {}) {
|
|
652
651
|
const client = options.client ?? new Anthropic({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulvar/anthropic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "rulvar first-class provider adapter over @anthropic-ai/sdk.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@anthropic-ai/sdk": "^0.110.0",
|
|
26
|
-
"@rulvar/core": "1.
|
|
26
|
+
"@rulvar/core": "1.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.20.0",
|