@zenmux/rosetta-ai 1.0.25 → 1.0.26

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.
@@ -16,6 +16,8 @@ export declare class MessagesToResponsesConverter {
16
16
  private convertThinking;
17
17
  private statusToStopReason;
18
18
  private generateId;
19
+ private packReasoningSignature;
20
+ private unpackReasoningSignature;
19
21
  private createStreamState;
20
22
  }
21
23
  export {};
@@ -76,7 +76,7 @@ class MessagesToResponsesConverter {
76
76
  content.push({
77
77
  type: "thinking",
78
78
  thinking: summaryText,
79
- signature: ri.encrypted_content ?? "",
79
+ signature: this.packReasoningSignature(ri.id, ri.encrypted_content),
80
80
  });
81
81
  }
82
82
  else if (item.type === "web_search_call" &&
@@ -301,7 +301,7 @@ class MessagesToResponsesConverter {
301
301
  index: state.currentBlockIndex,
302
302
  delta: {
303
303
  type: "signature_delta",
304
- signature: ri.encrypted_content,
304
+ signature: this.packReasoningSignature(ri.id, ri.encrypted_content),
305
305
  },
306
306
  });
307
307
  }
@@ -434,14 +434,12 @@ class MessagesToResponsesConverter {
434
434
  else {
435
435
  for (const block of msg.content) {
436
436
  if (block.type === "thinking") {
437
- // ponytail: fresh reasoning id, not the backend's original. Fine for
438
- // stateless (store:false) encrypted reasoning; if a backend rejects
439
- // mismatched ids, the original id would need a carrier channel.
437
+ const { id, encryptedContent } = this.unpackReasoningSignature(block.signature);
440
438
  input.push({
441
439
  type: "reasoning",
442
- id: `rs_${this.generateId()}`,
440
+ id: id ?? `rs_${this.generateId()}`,
443
441
  summary: block.thinking ? [{ type: "summary_text", text: block.thinking }] : [],
444
- encrypted_content: block.signature || null,
442
+ encrypted_content: encryptedContent,
445
443
  });
446
444
  }
447
445
  else if (block.type === "text") {
@@ -533,6 +531,34 @@ class MessagesToResponsesConverter {
533
531
  generateId() {
534
532
  return Math.random().toString(36).substring(2, 15);
535
533
  }
534
+ // Pack the Responses reasoning id + encrypted_content into the opaque Anthropic
535
+ // `signature` (base64url JSON, no prefix) so the backend-bound id survives the
536
+ // round-trip. Returns "" when there is no encrypted_content to preserve.
537
+ packReasoningSignature(id, encryptedContent) {
538
+ if (!encryptedContent)
539
+ return "";
540
+ return Buffer.from(JSON.stringify({ id, encrypted_content: encryptedContent }), "utf8").toString("base64url");
541
+ }
542
+ // Recover { id, encrypted_content } from a packed signature. Signatures not
543
+ // produced by this converter (or otherwise undecodable) fall back to being
544
+ // treated as raw encrypted_content with no id.
545
+ unpackReasoningSignature(signature) {
546
+ if (!signature)
547
+ return { encryptedContent: null };
548
+ try {
549
+ const parsed = JSON.parse(Buffer.from(signature, "base64url").toString("utf8"));
550
+ if (parsed && typeof parsed.encrypted_content === "string") {
551
+ return {
552
+ id: typeof parsed.id === "string" ? parsed.id : undefined,
553
+ encryptedContent: parsed.encrypted_content,
554
+ };
555
+ }
556
+ }
557
+ catch {
558
+ // not a packed signature
559
+ }
560
+ return { encryptedContent: signature };
561
+ }
536
562
  createStreamState() {
537
563
  return {
538
564
  id: "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenmux/rosetta-ai",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "Universal translator between AI provider protocols",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",