@zenmux/rosetta-ai 0.0.2 → 0.0.4

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.
@@ -209,16 +209,12 @@ class ChatCompletionToGeminiConverter {
209
209
  }
210
210
  for (const part of parts) {
211
211
  if (part.thought && part.text) {
212
- const newThought = part.text.slice(state.prevThought.length);
213
- if (newThought) {
214
- state.prevThought = part.text;
215
- events.push(this.makeChunk({
216
- content: "",
217
- ...{
218
- reasoning: newThought,
219
- },
220
- }));
221
- }
212
+ events.push(this.makeChunk({
213
+ content: "",
214
+ ...{
215
+ reasoning: part.text,
216
+ },
217
+ }));
222
218
  }
223
219
  else if (part.functionCall) {
224
220
  const fc = part.functionCall;
@@ -241,12 +237,8 @@ class ChatCompletionToGeminiConverter {
241
237
  }));
242
238
  }
243
239
  }
244
- else if (part.text != null) {
245
- const newText = part.text.slice(state.prevText.length);
246
- if (newText) {
247
- state.prevText = part.text;
248
- events.push(this.makeChunk({ content: newText }));
249
- }
240
+ else if (part.text != null && part.text !== "") {
241
+ events.push(this.makeChunk({ content: part.text }));
250
242
  }
251
243
  }
252
244
  const annotations = [];
@@ -198,23 +198,19 @@ class MessagesToGeminiConverter {
198
198
  }
199
199
  for (const part of parts) {
200
200
  if (part.thought && part.text) {
201
- const newThought = part.text.slice(state.prevThought.length);
202
- if (newThought) {
203
- if (state.currentBlockType !== "thinking") {
204
- this.transitionBlock(state, events, "thinking");
205
- events.push({
206
- type: "content_block_start",
207
- index: state.currentBlockIndex,
208
- content_block: { type: "thinking", thinking: "", signature: "" },
209
- });
210
- }
211
- state.prevThought = part.text;
201
+ if (state.currentBlockType !== "thinking") {
202
+ this.transitionBlock(state, events, "thinking");
212
203
  events.push({
213
- type: "content_block_delta",
204
+ type: "content_block_start",
214
205
  index: state.currentBlockIndex,
215
- delta: { type: "thinking_delta", thinking: newThought },
206
+ content_block: { type: "thinking", thinking: "", signature: "" },
216
207
  });
217
208
  }
209
+ events.push({
210
+ type: "content_block_delta",
211
+ index: state.currentBlockIndex,
212
+ delta: { type: "thinking_delta", thinking: part.text },
213
+ });
218
214
  }
219
215
  else if (part.functionCall) {
220
216
  const fc = part.functionCall;
@@ -244,24 +240,20 @@ class MessagesToGeminiConverter {
244
240
  }
245
241
  }
246
242
  }
247
- else if (part.text != null) {
248
- const newText = part.text.slice(state.prevText.length);
249
- if (newText) {
250
- if (state.currentBlockType !== "text") {
251
- this.transitionBlock(state, events, "text");
252
- events.push({
253
- type: "content_block_start",
254
- index: state.currentBlockIndex,
255
- content_block: { type: "text", text: "", citations: null },
256
- });
257
- }
258
- state.prevText = part.text;
243
+ else if (part.text != null && part.text !== "") {
244
+ if (state.currentBlockType !== "text") {
245
+ this.transitionBlock(state, events, "text");
259
246
  events.push({
260
- type: "content_block_delta",
247
+ type: "content_block_start",
261
248
  index: state.currentBlockIndex,
262
- delta: { type: "text_delta", text: newText },
249
+ content_block: { type: "text", text: "", citations: null },
263
250
  });
264
251
  }
252
+ events.push({
253
+ type: "content_block_delta",
254
+ index: state.currentBlockIndex,
255
+ delta: { type: "text_delta", text: part.text },
256
+ });
265
257
  }
266
258
  }
267
259
  const groundingAnnotations = this.extractGroundingAnnotations(candidate);
@@ -202,39 +202,35 @@ class ResponsesToGeminiConverter {
202
202
  }
203
203
  for (const part of parts) {
204
204
  if (part.thought && part.text) {
205
- const newThought = part.text.slice(state.prevThought.length);
206
- if (newThought) {
207
- if (!state.reasoningStarted) {
208
- state.reasoningStarted = true;
209
- events.push({
210
- type: "response.output_item.added",
211
- item: {
212
- type: "reasoning",
213
- id: `rs_${this.generateId()}`,
214
- summary: [],
215
- },
216
- output_index: state.outputIndex,
217
- sequence_number: state.seq++,
218
- });
219
- events.push({
220
- type: "response.reasoning_summary_part.added",
221
- item_id: `rs_${this.generateId()}`,
222
- output_index: state.outputIndex,
223
- summary_index: 0,
224
- part: { type: "summary_text", text: "" },
225
- sequence_number: state.seq++,
226
- });
227
- }
228
- state.prevThought = part.text;
205
+ if (!state.reasoningStarted) {
206
+ state.reasoningStarted = true;
229
207
  events.push({
230
- type: "response.reasoning_summary_text.delta",
208
+ type: "response.output_item.added",
209
+ item: {
210
+ type: "reasoning",
211
+ id: `rs_${this.generateId()}`,
212
+ summary: [],
213
+ },
214
+ output_index: state.outputIndex,
215
+ sequence_number: state.seq++,
216
+ });
217
+ events.push({
218
+ type: "response.reasoning_summary_part.added",
231
219
  item_id: `rs_${this.generateId()}`,
232
220
  output_index: state.outputIndex,
233
221
  summary_index: 0,
234
- delta: newThought,
222
+ part: { type: "summary_text", text: "" },
235
223
  sequence_number: state.seq++,
236
224
  });
237
225
  }
226
+ events.push({
227
+ type: "response.reasoning_summary_text.delta",
228
+ item_id: `rs_${this.generateId()}`,
229
+ output_index: state.outputIndex,
230
+ summary_index: 0,
231
+ delta: part.text,
232
+ sequence_number: state.seq++,
233
+ });
238
234
  }
239
235
  else if (part.functionCall) {
240
236
  const fc = part.functionCall;
@@ -271,43 +267,39 @@ class ResponsesToGeminiConverter {
271
267
  }
272
268
  }
273
269
  }
274
- else if (part.text != null) {
275
- const newText = part.text.slice(state.prevText.length);
276
- if (newText) {
277
- if (!state.textMessageStarted) {
278
- state.textMessageStarted = true;
279
- const msgOutputIndex = state.outputIndex + (state.reasoningStarted ? 1 : 0) + state.toolCallCount;
280
- events.push({
281
- type: "response.output_item.added",
282
- item: {
283
- type: "message",
284
- id: `msg_${this.generateId()}`,
285
- role: "assistant",
286
- status: "in_progress",
287
- content: [],
288
- },
289
- output_index: msgOutputIndex,
290
- sequence_number: state.seq++,
291
- });
292
- events.push({
293
- type: "response.content_part.added",
294
- item_id: `msg_${this.generateId()}`,
295
- output_index: msgOutputIndex,
296
- content_index: 0,
297
- part: { type: "output_text", text: "", annotations: [] },
298
- sequence_number: state.seq++,
299
- });
300
- }
301
- state.prevText = part.text;
270
+ else if (part.text != null && part.text !== "") {
271
+ if (!state.textMessageStarted) {
272
+ state.textMessageStarted = true;
273
+ const msgOutputIndex = state.outputIndex + (state.reasoningStarted ? 1 : 0) + state.toolCallCount;
302
274
  events.push({
303
- type: "response.output_text.delta",
275
+ type: "response.output_item.added",
276
+ item: {
277
+ type: "message",
278
+ id: `msg_${this.generateId()}`,
279
+ role: "assistant",
280
+ status: "in_progress",
281
+ content: [],
282
+ },
283
+ output_index: msgOutputIndex,
284
+ sequence_number: state.seq++,
285
+ });
286
+ events.push({
287
+ type: "response.content_part.added",
304
288
  item_id: `msg_${this.generateId()}`,
305
- output_index: state.outputIndex + (state.reasoningStarted ? 1 : 0) + state.toolCallCount,
289
+ output_index: msgOutputIndex,
306
290
  content_index: 0,
307
- delta: newText,
291
+ part: { type: "output_text", text: "", annotations: [] },
308
292
  sequence_number: state.seq++,
309
293
  });
310
294
  }
295
+ events.push({
296
+ type: "response.output_text.delta",
297
+ item_id: `msg_${this.generateId()}`,
298
+ output_index: state.outputIndex + (state.reasoningStarted ? 1 : 0) + state.toolCallCount,
299
+ content_index: 0,
300
+ delta: part.text,
301
+ sequence_number: state.seq++,
302
+ });
311
303
  }
312
304
  }
313
305
  if (candidate?.finishReason) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenmux/rosetta-ai",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Universal translator between AI provider protocols",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "dist"
15
15
  ],
16
16
  "engines": {
17
- "node": ">=22"
17
+ "node": ">=20"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "tsc",