@zenmux/rosetta-ai 1.0.23 → 1.0.24
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.
|
@@ -13,6 +13,8 @@ export declare class ChatCompletionToResponsesConverter {
|
|
|
13
13
|
convertStream(stream: AsyncIterable<RespStreamEvent>): AsyncIterable<OpenAI.ChatCompletionChunk>;
|
|
14
14
|
convertStreamEvent(event: RespStreamEvent): OpenAI.ChatCompletionChunk | OpenAI.ChatCompletionChunk[] | null;
|
|
15
15
|
private convertMessages;
|
|
16
|
+
private convertReasoningInput;
|
|
17
|
+
private generateId;
|
|
16
18
|
private convertAssistantMessage;
|
|
17
19
|
private convertUserContent;
|
|
18
20
|
private convertTools;
|
|
@@ -295,8 +295,7 @@ class ChatCompletionToResponsesConverter {
|
|
|
295
295
|
case "response.web_search_call.completed":
|
|
296
296
|
return null;
|
|
297
297
|
case "response.output_item.done":
|
|
298
|
-
this.handleOutputItemDone(event);
|
|
299
|
-
return null;
|
|
298
|
+
return this.handleOutputItemDone(event);
|
|
300
299
|
case "response.output_text.annotation.added":
|
|
301
300
|
this.recordStreamAnnotation(event.annotation);
|
|
302
301
|
return null;
|
|
@@ -335,6 +334,11 @@ class ChatCompletionToResponsesConverter {
|
|
|
335
334
|
}
|
|
336
335
|
}
|
|
337
336
|
else if (msg.role === "assistant") {
|
|
337
|
+
// Reconstruct reasoning items (with encrypted_content + id) so the backend
|
|
338
|
+
// sees the same reasoning it produced. Reasoning precedes the message.
|
|
339
|
+
for (const reasoningItem of this.convertReasoningInput(msg)) {
|
|
340
|
+
input.push(reasoningItem);
|
|
341
|
+
}
|
|
338
342
|
const toolCalls = msg.tool_calls ?? [];
|
|
339
343
|
const hasToolCalls = toolCalls.length > 0;
|
|
340
344
|
const hasLegacyFunctionCall = msg.function_call != null;
|
|
@@ -402,6 +406,50 @@ class ChatCompletionToResponsesConverter {
|
|
|
402
406
|
}
|
|
403
407
|
return input;
|
|
404
408
|
}
|
|
409
|
+
// Rebuild Responses reasoning input items from a CC assistant message's
|
|
410
|
+
// `reasoning_details` (produced by convertReasoning), preserving the original
|
|
411
|
+
// reasoning id + encrypted_content that the Responses backend binds together.
|
|
412
|
+
convertReasoningInput(message) {
|
|
413
|
+
const items = [];
|
|
414
|
+
const details = message.reasoning_details;
|
|
415
|
+
if (Array.isArray(details) && details.length > 0) {
|
|
416
|
+
let summary = [];
|
|
417
|
+
const flush = (id, encrypted) => {
|
|
418
|
+
if (summary.length === 0 && !encrypted)
|
|
419
|
+
return;
|
|
420
|
+
items.push({
|
|
421
|
+
type: "reasoning",
|
|
422
|
+
id: id ?? `rs_${this.generateId()}`,
|
|
423
|
+
summary,
|
|
424
|
+
...(encrypted ? { encrypted_content: encrypted } : {}),
|
|
425
|
+
});
|
|
426
|
+
summary = [];
|
|
427
|
+
};
|
|
428
|
+
for (const d of details) {
|
|
429
|
+
if (d?.type === "reasoning.summary" && typeof d.summary === "string") {
|
|
430
|
+
summary.push({ type: "summary_text", text: d.summary });
|
|
431
|
+
}
|
|
432
|
+
else if (d?.type === "reasoning.encrypted" && typeof d.data === "string") {
|
|
433
|
+
flush(typeof d.id === "string" ? d.id : undefined, d.data);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
flush();
|
|
437
|
+
return items;
|
|
438
|
+
}
|
|
439
|
+
// Fallback: only a plain `reasoning` string, no structured details.
|
|
440
|
+
const reasoning = message.reasoning;
|
|
441
|
+
if (typeof reasoning === "string" && reasoning.length > 0) {
|
|
442
|
+
items.push({
|
|
443
|
+
type: "reasoning",
|
|
444
|
+
id: `rs_${this.generateId()}`,
|
|
445
|
+
summary: [{ type: "summary_text", text: reasoning }],
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
return items;
|
|
449
|
+
}
|
|
450
|
+
generateId() {
|
|
451
|
+
return Math.random().toString(36).substring(2, 15);
|
|
452
|
+
}
|
|
405
453
|
convertAssistantMessage(message) {
|
|
406
454
|
const content = message.content;
|
|
407
455
|
if (typeof content === "string") {
|
|
@@ -756,7 +804,31 @@ class ChatCompletionToResponsesConverter {
|
|
|
756
804
|
if (item.status === "completed" && item.action.type === "search") {
|
|
757
805
|
this.streamState.webSearchCount++;
|
|
758
806
|
}
|
|
807
|
+
return null;
|
|
759
808
|
}
|
|
809
|
+
// Emit the encrypted reasoning (the Responses "signature") once the reasoning
|
|
810
|
+
// item is complete, mirroring the non-streaming convertReasoning output.
|
|
811
|
+
if (item?.type === "reasoning") {
|
|
812
|
+
const ri = item;
|
|
813
|
+
if (ri.encrypted_content) {
|
|
814
|
+
return this.makeChunk({
|
|
815
|
+
role: "assistant",
|
|
816
|
+
content: "",
|
|
817
|
+
...{
|
|
818
|
+
reasoning_details: [
|
|
819
|
+
{
|
|
820
|
+
id: ri.id,
|
|
821
|
+
index: "0",
|
|
822
|
+
type: "reasoning.encrypted",
|
|
823
|
+
format: "openai-responses-v1",
|
|
824
|
+
data: ri.encrypted_content,
|
|
825
|
+
},
|
|
826
|
+
],
|
|
827
|
+
},
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return null;
|
|
760
832
|
}
|
|
761
833
|
handleTextDelta(event) {
|
|
762
834
|
const logprobs = this.streamState.includeLogprobs
|