@zenmux/rosetta-ai 0.15.0 → 0.17.0

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.
@@ -9,6 +9,18 @@ export declare class MessagesToChatCompletionConverter {
9
9
  private buildUsage;
10
10
  private generateId;
11
11
  convertStream(stream: AsyncIterable<OpenAI.ChatCompletionChunk>): AsyncIterable<Anthropic.RawMessageStreamEvent>;
12
+ /**
13
+ * Emit the trailing terminal events (message_delta + message_stop) when the
14
+ * backend signalled a finish reason but never sent the trailing usage-only
15
+ * chunk that normally triggers them. Returns an empty array when the stream
16
+ * already terminated cleanly.
17
+ *
18
+ * Callers that drive the stream chunk-by-chunk via convertStreamChunk (instead
19
+ * of convertStream) must invoke this once the upstream stream is exhausted, or
20
+ * a backend that omits the usage chunk will leave the converted stream without
21
+ * a message_stop.
22
+ */
23
+ flushTerminalEvents(): Anthropic.RawMessageStreamEvent[];
12
24
  convertStreamChunk(chunk: OpenAI.ChatCompletionChunk): Anthropic.RawMessageStreamEvent[];
13
25
  private emitTerminalEvents;
14
26
  private createStreamState;
@@ -35,7 +35,9 @@ class MessagesToChatCompletionConverter {
35
35
  messages,
36
36
  };
37
37
  if (params.max_tokens !== undefined) {
38
- result.max_tokens = params.max_tokens;
38
+ // Use max_completion_tokens: max_tokens is deprecated and rejected by
39
+ // o-series / reasoning models.
40
+ result.max_completion_tokens = params.max_tokens;
39
41
  }
40
42
  if (params.temperature !== undefined) {
41
43
  result.temperature = params.temperature;
@@ -192,13 +194,27 @@ class MessagesToChatCompletionConverter {
192
194
  }
193
195
  // Safety flush: if the backend signalled finish but never sent the trailing
194
196
  // usage chunk, emit terminal events so the stream is well-formed.
197
+ for (const event of this.flushTerminalEvents()) {
198
+ yield event;
199
+ }
200
+ }
201
+ /**
202
+ * Emit the trailing terminal events (message_delta + message_stop) when the
203
+ * backend signalled a finish reason but never sent the trailing usage-only
204
+ * chunk that normally triggers them. Returns an empty array when the stream
205
+ * already terminated cleanly.
206
+ *
207
+ * Callers that drive the stream chunk-by-chunk via convertStreamChunk (instead
208
+ * of convertStream) must invoke this once the upstream stream is exhausted, or
209
+ * a backend that omits the usage chunk will leave the converted stream without
210
+ * a message_stop.
211
+ */
212
+ flushTerminalEvents() {
213
+ const events = [];
195
214
  if (this.streamState.stopReason !== null && !this.streamState.finished) {
196
- const events = [];
197
215
  this.emitTerminalEvents(this.streamState, events, undefined);
198
- for (const event of events) {
199
- yield event;
200
- }
201
216
  }
217
+ return events;
202
218
  }
203
219
  convertStreamChunk(chunk) {
204
220
  const state = this.streamState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenmux/rosetta-ai",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Universal translator between AI provider protocols",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",