@zenmux/rosetta-ai 1.0.24 → 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.
- package/dist/messages/responses.js +9 -18
- package/package.json +1 -1
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessagesToResponsesConverter = void 0;
|
|
4
|
-
// The Responses backend binds a reasoning item's encrypted_content to its id, so
|
|
5
|
-
// the id must survive the round-trip. Anthropic thinking blocks carry no id, so
|
|
6
|
-
// we pack {id, encrypted_content} into the opaque `signature` string and unpack
|
|
7
|
-
// it when converting the follow-up request back to Responses input.
|
|
8
|
-
const REASONING_SIG_PREFIX = "rosetta-ai/responses-reasoning:v1:";
|
|
9
4
|
class MessagesToResponsesConverter {
|
|
10
5
|
streamState;
|
|
11
6
|
constructor() {
|
|
@@ -536,26 +531,22 @@ class MessagesToResponsesConverter {
|
|
|
536
531
|
generateId() {
|
|
537
532
|
return Math.random().toString(36).substring(2, 15);
|
|
538
533
|
}
|
|
539
|
-
//
|
|
540
|
-
//
|
|
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.
|
|
541
537
|
packReasoningSignature(id, encryptedContent) {
|
|
542
538
|
if (!encryptedContent)
|
|
543
539
|
return "";
|
|
544
|
-
|
|
545
|
-
return `${REASONING_SIG_PREFIX}${data}`;
|
|
540
|
+
return Buffer.from(JSON.stringify({ id, encrypted_content: encryptedContent }), "utf8").toString("base64url");
|
|
546
541
|
}
|
|
547
|
-
// Recover { id, encrypted_content } from a packed signature.
|
|
548
|
-
//
|
|
549
|
-
//
|
|
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.
|
|
550
545
|
unpackReasoningSignature(signature) {
|
|
551
546
|
if (!signature)
|
|
552
547
|
return { encryptedContent: null };
|
|
553
|
-
if (!signature.startsWith(REASONING_SIG_PREFIX)) {
|
|
554
|
-
return { encryptedContent: signature };
|
|
555
|
-
}
|
|
556
548
|
try {
|
|
557
|
-
const
|
|
558
|
-
const parsed = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
|
|
549
|
+
const parsed = JSON.parse(Buffer.from(signature, "base64url").toString("utf8"));
|
|
559
550
|
if (parsed && typeof parsed.encrypted_content === "string") {
|
|
560
551
|
return {
|
|
561
552
|
id: typeof parsed.id === "string" ? parsed.id : undefined,
|
|
@@ -564,7 +555,7 @@ class MessagesToResponsesConverter {
|
|
|
564
555
|
}
|
|
565
556
|
}
|
|
566
557
|
catch {
|
|
567
|
-
//
|
|
558
|
+
// not a packed signature
|
|
568
559
|
}
|
|
569
560
|
return { encryptedContent: signature };
|
|
570
561
|
}
|