@zenmux/rosetta-ai 1.0.7 → 1.0.10
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.
|
@@ -67,7 +67,6 @@ export declare class ResponsesToChatCompletionConverter {
|
|
|
67
67
|
private convertToolChoice;
|
|
68
68
|
private convertTextFormat;
|
|
69
69
|
private finishReasonToStatus;
|
|
70
|
-
private generateId;
|
|
71
70
|
private createStreamState;
|
|
72
71
|
private makeSkeletonResponse;
|
|
73
72
|
private emitCompleted;
|
|
@@ -116,7 +116,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
116
116
|
if (reasoning) {
|
|
117
117
|
output.push({
|
|
118
118
|
type: "reasoning",
|
|
119
|
-
id: `rs_${
|
|
119
|
+
id: `rs_${choice?.index ?? 0}_${response.id}`,
|
|
120
120
|
summary: [{ type: "summary_text", text: reasoning }],
|
|
121
121
|
});
|
|
122
122
|
}
|
|
@@ -126,7 +126,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
126
126
|
if (tc.type === "function") {
|
|
127
127
|
output.push({
|
|
128
128
|
type: "function_call",
|
|
129
|
-
id: `fc_${
|
|
129
|
+
id: `fc_${choice?.index ?? 0}_${response.id}`,
|
|
130
130
|
call_id: tc.id,
|
|
131
131
|
name: tc.function.name,
|
|
132
132
|
arguments: tc.function.arguments,
|
|
@@ -160,7 +160,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
160
160
|
}
|
|
161
161
|
output.push({
|
|
162
162
|
type: "message",
|
|
163
|
-
id: `msg_${
|
|
163
|
+
id: `msg_${choice?.index ?? 0}_${response.id}`,
|
|
164
164
|
role: "assistant",
|
|
165
165
|
status: "completed",
|
|
166
166
|
content,
|
|
@@ -193,23 +193,28 @@ class ResponsesToChatCompletionConverter {
|
|
|
193
193
|
text: echoed.text,
|
|
194
194
|
reasoning: echoed.reasoning,
|
|
195
195
|
truncation: echoed.truncation,
|
|
196
|
-
user:
|
|
196
|
+
user: null,
|
|
197
|
+
// Fields the legacy converter always emitted; keep them for parity.
|
|
198
|
+
conversation: null,
|
|
199
|
+
prompt: null,
|
|
200
|
+
background: params?.background ?? false,
|
|
197
201
|
// Non-standard echoes (top_logprobs / safety_identifier / service_tier)
|
|
198
202
|
// are attached via cast; the Responses Response type does not declare them.
|
|
199
203
|
...(echoed.top_logprobs !== undefined
|
|
200
204
|
? { top_logprobs: echoed.top_logprobs }
|
|
201
205
|
: {}),
|
|
202
|
-
...(echoed.safety_identifier
|
|
206
|
+
...(echoed.safety_identifier != null
|
|
203
207
|
? { safety_identifier: echoed.safety_identifier }
|
|
204
|
-
: {}),
|
|
205
|
-
...(echoed.service_tier
|
|
206
|
-
|
|
208
|
+
: { safety_identifier: null }),
|
|
209
|
+
...(echoed.service_tier != null
|
|
210
|
+
? { service_tier: echoed.service_tier }
|
|
211
|
+
: { service_tier: response.service_tier ?? "default" }),
|
|
207
212
|
...(params?.prompt_cache_key !== undefined
|
|
208
213
|
? { prompt_cache_key: params.prompt_cache_key }
|
|
209
214
|
: {}),
|
|
210
215
|
...(params?.prompt_cache_retention !== undefined
|
|
211
216
|
? { prompt_cache_retention: params.prompt_cache_retention }
|
|
212
|
-
: {}),
|
|
217
|
+
: { prompt_cache_retention: null }),
|
|
213
218
|
usage: response.usage
|
|
214
219
|
? {
|
|
215
220
|
input_tokens: response.usage.prompt_tokens,
|
|
@@ -234,16 +239,16 @@ class ResponsesToChatCompletionConverter {
|
|
|
234
239
|
if (!params) {
|
|
235
240
|
return {
|
|
236
241
|
instructions: null,
|
|
237
|
-
temperature:
|
|
238
|
-
top_p:
|
|
242
|
+
temperature: 1,
|
|
243
|
+
top_p: 1,
|
|
239
244
|
max_output_tokens: null,
|
|
240
245
|
previous_response_id: null,
|
|
241
246
|
parallel_tool_calls: true,
|
|
242
247
|
tool_choice: "auto",
|
|
243
248
|
tools: [],
|
|
244
|
-
text: { format: { type: "text" } },
|
|
249
|
+
text: { format: { type: "text" }, verbosity: "medium" },
|
|
245
250
|
reasoning: null,
|
|
246
|
-
truncation:
|
|
251
|
+
truncation: "disabled",
|
|
247
252
|
};
|
|
248
253
|
}
|
|
249
254
|
const tools = (params.tools ?? [])
|
|
@@ -251,20 +256,18 @@ class ResponsesToChatCompletionConverter {
|
|
|
251
256
|
.filter(Boolean);
|
|
252
257
|
return {
|
|
253
258
|
instructions: params.instructions ?? null,
|
|
254
|
-
temperature: params.temperature ??
|
|
255
|
-
top_p: params.top_p ??
|
|
259
|
+
temperature: params.temperature ?? 1,
|
|
260
|
+
top_p: params.top_p ?? 1,
|
|
256
261
|
max_output_tokens: params.max_output_tokens ?? null,
|
|
257
262
|
previous_response_id: params.previous_response_id ?? null,
|
|
258
263
|
parallel_tool_calls: params.parallel_tool_calls ?? true,
|
|
259
264
|
tool_choice: params.tool_choice ?? "auto",
|
|
260
265
|
tools,
|
|
261
|
-
text: params.text ?? { format: { type: "text" } },
|
|
266
|
+
text: params.text ?? { format: { type: "text" }, verbosity: "medium" },
|
|
262
267
|
reasoning: params.reasoning ?? null,
|
|
263
|
-
truncation: params.truncation ??
|
|
268
|
+
truncation: params.truncation ?? "disabled",
|
|
264
269
|
top_logprobs: params.top_logprobs,
|
|
265
|
-
safety_identifier: params.safety_identifier,
|
|
266
|
-
// service_tier is normally returned by the upstream model; echo the
|
|
267
|
-
// request's value as a fallback (the legacy converter did the same).
|
|
270
|
+
safety_identifier: params.safety_identifier ?? null,
|
|
268
271
|
service_tier: params.service_tier,
|
|
269
272
|
};
|
|
270
273
|
}
|
|
@@ -366,7 +369,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
366
369
|
if (!state.current || state.current.type !== "reasoning") {
|
|
367
370
|
// Close any other open item before starting reasoning.
|
|
368
371
|
events.push(...this.closeCurrent());
|
|
369
|
-
const itemId = `rs_${
|
|
372
|
+
const itemId = `rs_${state.id}`;
|
|
370
373
|
state.current = {
|
|
371
374
|
type: "reasoning",
|
|
372
375
|
itemId,
|
|
@@ -430,7 +433,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
430
433
|
// matching the legacy converter's output_index math.
|
|
431
434
|
const outputIndex = state.outputIndex + state.toolCallCount - 1;
|
|
432
435
|
if (isCustom) {
|
|
433
|
-
const itemId = `ct_${
|
|
436
|
+
const itemId = `ct_${state.id}`;
|
|
434
437
|
state.current = {
|
|
435
438
|
type: "custom_tool_call",
|
|
436
439
|
itemId,
|
|
@@ -454,7 +457,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
454
457
|
});
|
|
455
458
|
}
|
|
456
459
|
else {
|
|
457
|
-
const itemId = `fc_${
|
|
460
|
+
const itemId = `fc_${state.id}`;
|
|
458
461
|
state.current = {
|
|
459
462
|
type: "function_call",
|
|
460
463
|
itemId,
|
|
@@ -583,7 +586,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
583
586
|
/** Open a message output item and its first content part. */
|
|
584
587
|
openMessage(state, kind, events) {
|
|
585
588
|
state.messageStarted = true;
|
|
586
|
-
const itemId = `msg_${
|
|
589
|
+
const itemId = `msg_${state.id}`;
|
|
587
590
|
const msgOutputIndex = state.outputIndex + state.toolCallCount;
|
|
588
591
|
state.current = {
|
|
589
592
|
type: "message",
|
|
@@ -1052,9 +1055,6 @@ class ResponsesToChatCompletionConverter {
|
|
|
1052
1055
|
return "completed";
|
|
1053
1056
|
}
|
|
1054
1057
|
}
|
|
1055
|
-
generateId() {
|
|
1056
|
-
return Math.random().toString(36).substring(2, 15);
|
|
1057
|
-
}
|
|
1058
1058
|
// --- Private: stream helpers ---
|
|
1059
1059
|
createStreamState() {
|
|
1060
1060
|
return {
|
|
@@ -1117,18 +1117,23 @@ class ResponsesToChatCompletionConverter {
|
|
|
1117
1117
|
resp.text = echoed.text;
|
|
1118
1118
|
resp.reasoning = echoed.reasoning;
|
|
1119
1119
|
resp.truncation = echoed.truncation;
|
|
1120
|
+
resp.user = null;
|
|
1121
|
+
resp.conversation = null;
|
|
1122
|
+
resp.prompt = null;
|
|
1123
|
+
resp.background = this.requestParams?.background ?? false;
|
|
1120
1124
|
if (echoed.top_logprobs !== undefined)
|
|
1121
1125
|
resp.top_logprobs = echoed.top_logprobs;
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1126
|
+
resp.safety_identifier =
|
|
1127
|
+
echoed.safety_identifier != null ? echoed.safety_identifier : null;
|
|
1128
|
+
resp.service_tier = echoed.service_tier != null ? echoed.service_tier : "default";
|
|
1129
|
+
resp.prompt_cache_key =
|
|
1130
|
+
this.requestParams?.prompt_cache_key !== undefined
|
|
1131
|
+
? this.requestParams.prompt_cache_key
|
|
1132
|
+
: null;
|
|
1133
|
+
resp.prompt_cache_retention =
|
|
1134
|
+
this.requestParams?.prompt_cache_retention !== undefined
|
|
1135
|
+
? this.requestParams.prompt_cache_retention
|
|
1136
|
+
: null;
|
|
1132
1137
|
if (finalStatus === "incomplete") {
|
|
1133
1138
|
resp.incomplete_details = { reason: "max_output_tokens" };
|
|
1134
1139
|
}
|