@rulvar/anthropic 1.127.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 CHANGED
@@ -166,6 +166,12 @@ interface TurnMapping {
166
166
  assistantContent: Block[];
167
167
  pauseTurn: boolean;
168
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;
169
175
  }
170
176
  /**
171
177
  * Maps one Messages API stream into ChatEvents, yielding each canonical
@@ -187,6 +193,16 @@ interface TurnMapping {
187
193
  */
188
194
  declare function mapAnthropicStream(stream: AsyncIterable<AnthropicStreamEvent>, ids: IdMap, options?: {
189
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
+ };
190
206
  }): AsyncGenerator<ChatEvent, TurnMapping>;
191
207
  /**
192
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, { carryRetained });
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/anthropic",
3
- "version": "1.127.0",
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.127.0"
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.127.0"
32
+ "@rulvar/testing": "1.128.0"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",