@zenmux/rosetta-ai 1.0.6 → 1.0.7
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.
|
@@ -35,6 +35,14 @@ export declare class ResponsesToChatCompletionConverter {
|
|
|
35
35
|
* function / web_search / custom tools. Mirrors the legacy `toRespTool`.
|
|
36
36
|
*/
|
|
37
37
|
private toRespTool;
|
|
38
|
+
/**
|
|
39
|
+
* Compute `output_text` — the concatenation of all `output_text` content
|
|
40
|
+
* parts across the response's message output items, matching the Responses
|
|
41
|
+
* API convention. Returns "" when there are no text parts (e.g. tool-only
|
|
42
|
+
* or refusal-only responses), matching the legacy `toOpenAIRespResponse`
|
|
43
|
+
* default of `output_text: ""`.
|
|
44
|
+
*/
|
|
45
|
+
private collectOutputText;
|
|
38
46
|
convertStream(stream: AsyncIterable<OpenAI.ChatCompletionChunk>): AsyncIterable<RespStreamEvent>;
|
|
39
47
|
convertStreamChunk(chunk: OpenAI.ChatCompletionChunk): RespStreamEvent[];
|
|
40
48
|
/** Open a message output item and its first content part. */
|
|
@@ -177,6 +177,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
177
177
|
created_at: response.created,
|
|
178
178
|
model: response.model,
|
|
179
179
|
output,
|
|
180
|
+
output_text: this.collectOutputText(output),
|
|
180
181
|
status,
|
|
181
182
|
error: null,
|
|
182
183
|
incomplete_details: status === "incomplete" ? { reason: "max_output_tokens" } : null,
|
|
@@ -298,6 +299,29 @@ class ResponsesToChatCompletionConverter {
|
|
|
298
299
|
}
|
|
299
300
|
return undefined;
|
|
300
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Compute `output_text` — the concatenation of all `output_text` content
|
|
304
|
+
* parts across the response's message output items, matching the Responses
|
|
305
|
+
* API convention. Returns "" when there are no text parts (e.g. tool-only
|
|
306
|
+
* or refusal-only responses), matching the legacy `toOpenAIRespResponse`
|
|
307
|
+
* default of `output_text: ""`.
|
|
308
|
+
*/
|
|
309
|
+
collectOutputText(output) {
|
|
310
|
+
let text = "";
|
|
311
|
+
for (const item of output ?? []) {
|
|
312
|
+
if (item.type !== "message")
|
|
313
|
+
continue;
|
|
314
|
+
const content = item.content;
|
|
315
|
+
if (!Array.isArray(content))
|
|
316
|
+
continue;
|
|
317
|
+
for (const part of content) {
|
|
318
|
+
if (part?.type === "output_text" && typeof part.text === "string") {
|
|
319
|
+
text += part.text;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return text;
|
|
324
|
+
}
|
|
301
325
|
// --- Stream conversion (CC → Responses, backward) ---
|
|
302
326
|
async *convertStream(stream) {
|
|
303
327
|
for await (const chunk of stream) {
|
|
@@ -1079,6 +1103,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
1079
1103
|
resp.status = finalStatus;
|
|
1080
1104
|
// Carry the output items accumulated during the stream.
|
|
1081
1105
|
resp.output = [...state.output];
|
|
1106
|
+
resp.output_text = this.collectOutputText(resp.output);
|
|
1082
1107
|
// Echo request-scoped fields onto the terminal response when available.
|
|
1083
1108
|
const echoed = this.echoRequestFields(this.requestParams);
|
|
1084
1109
|
resp.instructions = echoed.instructions;
|