@zenmux/rosetta-ai 1.0.26 → 1.0.28
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.
|
@@ -17,10 +17,13 @@ class ChatCompletionToGeminiConverter {
|
|
|
17
17
|
systemParts.push({ text });
|
|
18
18
|
}
|
|
19
19
|
else if (msg.role === "user") {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const parts = this.convertUserParts(msg.content);
|
|
21
|
+
if (parts.length > 0) {
|
|
22
|
+
contents.push({
|
|
23
|
+
role: "user",
|
|
24
|
+
parts,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
else if (msg.role === "assistant") {
|
|
26
29
|
for (const toolCall of msg.tool_calls ?? []) {
|
|
@@ -28,10 +31,13 @@ class ChatCompletionToGeminiConverter {
|
|
|
28
31
|
toolCallNames.set(toolCall.id, toolCall.function.name);
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const parts = this.convertAssistantParts(msg);
|
|
35
|
+
if (parts.length > 0) {
|
|
36
|
+
contents.push({
|
|
37
|
+
role: "model",
|
|
38
|
+
parts,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
else if (msg.role === "tool") {
|
|
37
43
|
this.appendToolResponse(contents, msg, toolCallNames.get(msg.tool_call_id));
|
|
@@ -323,6 +329,15 @@ class ChatCompletionToGeminiConverter {
|
|
|
323
329
|
}
|
|
324
330
|
}
|
|
325
331
|
}
|
|
332
|
+
// Responses reasoning history is represented as the non-standard
|
|
333
|
+
// reasoning_content field in Chat Completions. The legacy conversion sent
|
|
334
|
+
// standalone reasoning summaries to Gemini as ordinary model text.
|
|
335
|
+
if (parts.length === 0) {
|
|
336
|
+
const reasoningContent = msg.reasoning_content;
|
|
337
|
+
if (typeof reasoningContent === "string" && reasoningContent.length > 0) {
|
|
338
|
+
parts.push({ text: reasoningContent });
|
|
339
|
+
}
|
|
340
|
+
}
|
|
326
341
|
return parts;
|
|
327
342
|
}
|
|
328
343
|
appendToolResponse(contents, msg, functionName) {
|
|
@@ -412,38 +412,26 @@ class ChatCompletionToResponsesConverter {
|
|
|
412
412
|
convertReasoningInput(message) {
|
|
413
413
|
const items = [];
|
|
414
414
|
const details = message.reasoning_details;
|
|
415
|
-
if (Array.isArray(details)
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
415
|
+
if (!Array.isArray(details) || details.length === 0)
|
|
416
|
+
return items;
|
|
417
|
+
// Only reasoning that carries encrypted_content can be sent back: the
|
|
418
|
+
// Responses backend either matches a real stored id or reconstructs from
|
|
419
|
+
// encrypted_content. A summary-only item with a fabricated id is rejected
|
|
420
|
+
// ("item with id rs_... not found"), so drop those groups.
|
|
421
|
+
let summary = [];
|
|
422
|
+
for (const d of details) {
|
|
423
|
+
if (d?.type === "reasoning.summary" && typeof d.summary === "string") {
|
|
424
|
+
summary.push({ type: "summary_text", text: d.summary });
|
|
425
|
+
}
|
|
426
|
+
else if (d?.type === "reasoning.encrypted" && typeof d.data === "string") {
|
|
420
427
|
items.push({
|
|
421
428
|
type: "reasoning",
|
|
422
|
-
id: id
|
|
429
|
+
id: typeof d.id === "string" ? d.id : `rs_${this.generateId()}`,
|
|
423
430
|
summary,
|
|
424
|
-
|
|
431
|
+
encrypted_content: d.data,
|
|
425
432
|
});
|
|
426
433
|
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
434
|
}
|
|
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
435
|
}
|
|
448
436
|
return items;
|
|
449
437
|
}
|
|
@@ -842,18 +842,22 @@ class ResponsesToChatCompletionConverter {
|
|
|
842
842
|
}
|
|
843
843
|
else if (typed.role === "assistant") {
|
|
844
844
|
const textParts = [];
|
|
845
|
-
if (
|
|
845
|
+
if (typeof typed.content === "string") {
|
|
846
|
+
textParts.push(typed.content);
|
|
847
|
+
}
|
|
848
|
+
else if (Array.isArray(typed.content)) {
|
|
846
849
|
for (const part of typed.content) {
|
|
847
|
-
if (part.type === "output_text")
|
|
850
|
+
if (part.type === "output_text" || part.type === "input_text") {
|
|
848
851
|
textParts.push(part.text);
|
|
852
|
+
}
|
|
849
853
|
}
|
|
850
854
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
855
|
+
if (textParts.length > 0) {
|
|
856
|
+
messages.push({
|
|
857
|
+
role: "assistant",
|
|
858
|
+
content: textParts.join(""),
|
|
859
|
+
});
|
|
860
|
+
}
|
|
857
861
|
}
|
|
858
862
|
}
|
|
859
863
|
else if (typed.type === "reasoning") {
|