@rulvar/anthropic 1.126.0 → 1.128.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 +19 -1
- package/dist/index.js +14 -3
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,9 @@ interface AnthropicClientLike {
|
|
|
48
48
|
create(params: Record<string, unknown>, opts?: {
|
|
49
49
|
signal?: AbortSignal;
|
|
50
50
|
}): Promise<unknown>;
|
|
51
|
-
countTokens(params: Record<string, unknown
|
|
51
|
+
countTokens(params: Record<string, unknown>, opts?: {
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}): Promise<{
|
|
52
54
|
input_tokens: number;
|
|
53
55
|
}>;
|
|
54
56
|
};
|
|
@@ -164,6 +166,12 @@ interface TurnMapping {
|
|
|
164
166
|
assistantContent: Block[];
|
|
165
167
|
pauseTurn: boolean;
|
|
166
168
|
finished: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* The segment's provider message id, captured for paused and
|
|
171
|
+
* finished segments alike so the adapter can account every wire
|
|
172
|
+
* request of a pause_turn absorption (RV905).
|
|
173
|
+
*/
|
|
174
|
+
responseId?: string;
|
|
167
175
|
}
|
|
168
176
|
/**
|
|
169
177
|
* Maps one Messages API stream into ChatEvents, yielding each canonical
|
|
@@ -185,6 +193,16 @@ interface TurnMapping {
|
|
|
185
193
|
*/
|
|
186
194
|
declare function mapAnthropicStream(stream: AsyncIterable<AnthropicStreamEvent>, ids: IdMap, options?: {
|
|
187
195
|
carryRetained?: Block[];
|
|
196
|
+
/**
|
|
197
|
+
* Response ids of the PRIOR pause_turn segments of this turn
|
|
198
|
+
* (RV905): when present, the finish metadata names the whole wire
|
|
199
|
+
* request set (`wireRequests: { count, responseIds }`) so the core
|
|
200
|
+
* can account the dispatch at its true wire count. Absent on the
|
|
201
|
+
* first segment, so an unsegmented finish stays byte-identical.
|
|
202
|
+
*/
|
|
203
|
+
wirePrior?: {
|
|
204
|
+
responseIds: Array<string | undefined>;
|
|
205
|
+
};
|
|
188
206
|
}): AsyncGenerator<ChatEvent, TurnMapping>;
|
|
189
207
|
/**
|
|
190
208
|
* Projects an SDK/API error into the retryable WireError vocabulary:
|
package/dist/index.js
CHANGED
|
@@ -620,11 +620,16 @@ async function* mapAnthropicStream(stream, ids, options) {
|
|
|
620
620
|
const mapped = mapStopReason(stopReason, stopDetails);
|
|
621
621
|
if (mapped.pauseTurn) {
|
|
622
622
|
mapping.pauseTurn = true;
|
|
623
|
+
if (responseId !== void 0) mapping.responseId = responseId;
|
|
623
624
|
return mapping;
|
|
624
625
|
}
|
|
625
626
|
const providerMetadata = { anthropic: {} };
|
|
626
627
|
const meta = providerMetadata.anthropic;
|
|
627
628
|
if (responseId !== void 0) meta.responseId = responseId;
|
|
629
|
+
if (options?.wirePrior !== void 0) meta.wireRequests = {
|
|
630
|
+
count: options.wirePrior.responseIds.length + 1,
|
|
631
|
+
responseIds: [...options.wirePrior.responseIds, responseId].filter((id) => typeof id === "string")
|
|
632
|
+
};
|
|
628
633
|
if (stopSequence !== void 0) meta.stopSequence = stopSequence;
|
|
629
634
|
const retained = [...options?.carryRetained ?? [], ...mapping.assistantContent.filter((block) => block.type === "thinking" || block.type === "redacted_thinking")];
|
|
630
635
|
if (retained.length > 0) meta.retainedParts = retained;
|
|
@@ -635,6 +640,7 @@ async function* mapAnthropicStream(stream, ids, options) {
|
|
|
635
640
|
providerMetadata
|
|
636
641
|
};
|
|
637
642
|
mapping.finished = true;
|
|
643
|
+
if (responseId !== void 0) mapping.responseId = responseId;
|
|
638
644
|
return mapping;
|
|
639
645
|
}
|
|
640
646
|
default: break;
|
|
@@ -837,6 +843,7 @@ function anthropic(options = {}) {
|
|
|
837
843
|
});
|
|
838
844
|
let continuations = 0;
|
|
839
845
|
const carryRetained = [];
|
|
846
|
+
const priorSegmentIds = [];
|
|
840
847
|
while (true) {
|
|
841
848
|
let stream;
|
|
842
849
|
try {
|
|
@@ -852,7 +859,10 @@ function anthropic(options = {}) {
|
|
|
852
859
|
};
|
|
853
860
|
return;
|
|
854
861
|
}
|
|
855
|
-
const mapper = mapAnthropicStream(stream, ids, {
|
|
862
|
+
const mapper = mapAnthropicStream(stream, ids, {
|
|
863
|
+
carryRetained,
|
|
864
|
+
...priorSegmentIds.length === 0 ? {} : { wirePrior: { responseIds: priorSegmentIds } }
|
|
865
|
+
});
|
|
856
866
|
let mapping;
|
|
857
867
|
try {
|
|
858
868
|
while (true) {
|
|
@@ -886,6 +896,7 @@ function anthropic(options = {}) {
|
|
|
886
896
|
return;
|
|
887
897
|
}
|
|
888
898
|
carryRetained.push(...mapping.assistantContent.filter((block) => block.type === "thinking" || block.type === "redacted_thinking"));
|
|
899
|
+
priorSegmentIds.push(mapping.responseId);
|
|
889
900
|
continuations += 1;
|
|
890
901
|
if (continuations > pauseCap) {
|
|
891
902
|
yield {
|
|
@@ -909,7 +920,7 @@ function anthropic(options = {}) {
|
|
|
909
920
|
};
|
|
910
921
|
}
|
|
911
922
|
},
|
|
912
|
-
async countTokens(req) {
|
|
923
|
+
async countTokens(req, opts) {
|
|
913
924
|
const info = infoFor(req.model);
|
|
914
925
|
const params = buildAnthropicParams(req, {
|
|
915
926
|
ids,
|
|
@@ -922,7 +933,7 @@ function anthropic(options = {}) {
|
|
|
922
933
|
};
|
|
923
934
|
if (params.system !== void 0) body.system = params.system;
|
|
924
935
|
if (params.tools !== void 0) body.tools = params.tools;
|
|
925
|
-
return (await client.messages.countTokens(body)).input_tokens;
|
|
936
|
+
return (await client.messages.countTokens(body, opts?.signal === void 0 ? void 0 : { signal: opts.signal })).input_tokens;
|
|
926
937
|
}
|
|
927
938
|
};
|
|
928
939
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulvar/anthropic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.128.0",
|
|
4
4
|
"description": "Rulvar first-class provider adapter over @anthropic-ai/sdk.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@anthropic-ai/sdk": "^0.115.0",
|
|
26
|
-
"@rulvar/core": "1.
|
|
26
|
+
"@rulvar/core": "1.128.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.20.1",
|
|
30
30
|
"tsdown": "^0.22.14",
|
|
31
31
|
"typescript": "~6.0.3",
|
|
32
|
-
"@rulvar/testing": "1.
|
|
32
|
+
"@rulvar/testing": "1.128.0"
|
|
33
33
|
},
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|