pendra 0.8.0 → 0.10.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.
package/README.md CHANGED
@@ -51,6 +51,35 @@ for await (const chunk of stream) {
51
51
  }
52
52
  ```
53
53
 
54
+ ## Reasoning models
55
+
56
+ A reasoning model's chain-of-thought comes back separately from its answer, on
57
+ `reasoning_content` (mirrored on `reasoning`, and streamed as
58
+ `delta.reasoning_content`). On a hybrid model you can skip the thinking
59
+ entirely and get straight to the answer:
60
+
61
+ ```typescript
62
+ const response = await client.chat.completions.create({
63
+ model: 'qwen3.6:27b',
64
+ messages: [{ role: 'user', content: "Classify: 'ship it'. positive or negative?" }],
65
+ max_tokens: 5,
66
+ enable_thinking: false, // or reasoning_effort: 'none'
67
+ });
68
+
69
+ console.log(response.choices[0].message.reasoning_content); // the working, when thinking is on
70
+ console.log(response.choices[0].message.content); // the answer
71
+ ```
72
+
73
+ ## Parameters
74
+
75
+ `chat.completions.create()` passes everything you give it to the API —
76
+ including fields these types don't declare yet, so a Chat Completions
77
+ parameter newer than your SDK version still reaches the model. TypeScript
78
+ rejects an undeclared key written straight into the call (that's what catches
79
+ typos), so pass a newer one through a variable or a cast when you mean it. The
80
+ only field that isn't sent as JSON is `worker_id`, which travels as the
81
+ `X-Pendra-Worker-Id` routing header.
82
+
54
83
  ## List Models
55
84
 
56
85
  ```typescript
package/dist/index.d.mts CHANGED
@@ -67,6 +67,41 @@ interface ChatCompletionMessage {
67
67
  role: string;
68
68
  content: string | null;
69
69
  tool_calls?: ChatCompletionMessageToolCall[];
70
+ /**
71
+ * A reasoning model's chain-of-thought, kept separate from the answer in
72
+ * `content`. The API sends it as `reasoning_content` and mirrors it on
73
+ * `reasoning` for wider client compatibility — both are populated here.
74
+ * Turn the thinking off with `enable_thinking: false`.
75
+ */
76
+ reasoning_content?: string | null;
77
+ /** Mirror of {@link ChatCompletionMessage.reasoning_content}. */
78
+ reasoning?: string | null;
79
+ }
80
+ /** One part of a multimodal message — text, or an image for a vision model. */
81
+ type ChatCompletionContentPart = {
82
+ type: "text";
83
+ text: string;
84
+ } | {
85
+ type: "image_url";
86
+ image_url: {
87
+ url: string;
88
+ detail?: "auto" | "low" | "high";
89
+ };
90
+ };
91
+ /**
92
+ * A message you send. `content` is a plain string for text, or an array of
93
+ * parts for a vision model. Tool results come back as
94
+ * `{ role: "tool", tool_call_id, content }`.
95
+ */
96
+ interface ChatCompletionMessageParam {
97
+ role: string;
98
+ content: string | ChatCompletionContentPart[] | null;
99
+ /** Names a participant, e.g. which function a tool/function message is from. */
100
+ name?: string;
101
+ /** On a `"tool"` message, the id of the call this is the result of. */
102
+ tool_call_id?: string;
103
+ /** On an assistant message you replay back, the calls it made. */
104
+ tool_calls?: ChatCompletionMessageToolCall[];
70
105
  }
71
106
  interface Choice {
72
107
  index: number;
@@ -85,6 +120,13 @@ interface ChoiceDelta {
85
120
  role?: string | null;
86
121
  content?: string | null;
87
122
  tool_calls?: ChatCompletionMessageToolCall[];
123
+ /**
124
+ * Streaming chain-of-thought, arriving in its own deltas before the content
125
+ * deltas start. Same both-spellings rule as {@link ChatCompletionMessage}.
126
+ */
127
+ reasoning_content?: string | null;
128
+ /** Mirror of {@link ChoiceDelta.reasoning_content}. */
129
+ reasoning?: string | null;
88
130
  }
89
131
  interface StreamChoice {
90
132
  index: number;
@@ -98,17 +140,41 @@ interface ChatCompletionChunk {
98
140
  model: string;
99
141
  choices: StreamChoice[];
100
142
  }
143
+ /**
144
+ * Parameters for `client.chat.completions.create()`.
145
+ *
146
+ * Every field except `worker_id` (which travels as a header) is sent to the
147
+ * API as you pass it — including keys this interface doesn't declare, so a
148
+ * Chat Completions field newer than your SDK version still reaches the model.
149
+ * TypeScript will reject an undeclared key written directly in the call, which
150
+ * is what catches typos; pass it through a variable or a cast when you mean it.
151
+ */
101
152
  interface ChatCompletionCreateParams {
102
153
  model: string;
103
- messages: Array<{
104
- role: string;
105
- content: string;
106
- }>;
154
+ messages: ChatCompletionMessageParam[];
107
155
  temperature?: number | null;
108
156
  max_tokens?: number | null;
109
157
  top_p?: number | null;
158
+ /** Keep only the `top_k` most likely tokens (0 = off). */
159
+ top_k?: number | null;
160
+ /** Drop tokens less likely than `min_p` × the top token's probability. */
161
+ min_p?: number | null;
162
+ /** Penalise tokens by how often they've appeared (-2 to 2; 0 = off). */
163
+ frequency_penalty?: number | null;
164
+ /** Penalise tokens that have appeared at all (-2 to 2; 0 = off). */
165
+ presence_penalty?: number | null;
166
+ /** Classic repetition penalty (1.0 = off; e.g. 1.1–1.3 discourages repeats). */
167
+ repeat_penalty?: number | null;
168
+ /** How many recent tokens `repeat_penalty` looks back over (default 64). */
169
+ repeat_last_n?: number | null;
170
+ /** Seed the sampler for reproducible output. */
171
+ seed?: number | null;
110
172
  stop?: string | string[] | null;
111
173
  stream?: boolean;
174
+ /** Ask for `usage` on the final streamed chunk. */
175
+ stream_options?: {
176
+ include_usage?: boolean;
177
+ } | null;
112
178
  /**
113
179
  * Functions the model may call, in the OpenAI tools format. When the model
114
180
  * calls one, the reply's `choices[0].message.tool_calls` is populated and
@@ -120,6 +186,37 @@ interface ChatCompletionCreateParams {
120
186
  tool_choice?: unknown;
121
187
  /** Allow the model to request several tool calls in one reply. */
122
188
  parallel_tool_calls?: boolean | null;
189
+ /**
190
+ * Constrain the reply's shape — `{ type: "json_object" }` for any JSON, or
191
+ * `{ type: "json_schema", json_schema: { ... } }` to pin it to a schema.
192
+ */
193
+ response_format?: {
194
+ type: "text" | "json_object" | "json_schema";
195
+ json_schema?: Record<string, unknown>;
196
+ } | null;
197
+ /**
198
+ * Set `false` to make a reasoning model answer directly, skipping its
199
+ * chain-of-thought. Defaults to `true`. Only "hybrid" models can toggle it.
200
+ */
201
+ enable_thinking?: boolean | null;
202
+ /**
203
+ * How hard a reasoning model should think — `"low"`, `"medium"`, `"high"`,
204
+ * or `"none"` (alias `"minimal"`) to turn thinking off, the same as
205
+ * `enable_thinking: false`.
206
+ */
207
+ reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | (string & {}) | null;
208
+ /** Bias specific tokens, keyed by token id (-100 to 100). */
209
+ logit_bias?: Record<string, number> | null;
210
+ /** Return log-probabilities for the chosen tokens (model permitting). */
211
+ logprobs?: boolean | null;
212
+ /** How many alternatives to report per position when `logprobs` is on. */
213
+ top_logprobs?: number | null;
214
+ /** OpenAI's newer spelling of `max_tokens`. */
215
+ max_completion_tokens?: number | null;
216
+ /** How many completions to generate. */
217
+ n?: number | null;
218
+ /** An opaque end-user id, passed through for your own attribution. */
219
+ user?: string | null;
123
220
  /**
124
221
  * Optionally pin the request to a specific worker that serves this model.
125
222
  * Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
@@ -128,10 +225,18 @@ interface ChatCompletionCreateParams {
128
225
  worker_id?: string | null;
129
226
  }
130
227
 
228
+ /**
229
+ * Async-iterable reader for a streaming chat completion.
230
+ *
231
+ * Framing is handled by {@link SseDecoder}, which assembles whole SSE frames
232
+ * rather than filtering lines — so a frame the server tags with a named
233
+ * `event:` is dropped in one piece instead of having its `data:` line mistaken
234
+ * for a chat chunk (issue #1398).
235
+ */
131
236
  declare class Stream implements AsyncIterable<ChatCompletionChunk> {
132
237
  private reader;
133
238
  private decoder;
134
- private buffer;
239
+ private sse;
135
240
  private done;
136
241
  private controller;
137
242
  constructor(response: Response, controller: AbortController);
@@ -459,4 +564,4 @@ declare class RateLimitError extends APIStatusError {
459
564
  constructor(message?: string);
460
565
  }
461
566
 
462
- export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageToolCall, type Choice, type ChoiceDelta, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, PrivateInferenceError, RateLimitError, type RerankCreateParams, type RerankResponse, type RerankResult, type RerankResultDocument, Stream, type StreamChoice, type TranscriptionCreateParams, type TranscriptionResponse, type TranscriptionSegment, type Usage, Pendra as default };
567
+ export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageParam, type ChatCompletionMessageToolCall, type Choice, type ChoiceDelta, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, PrivateInferenceError, RateLimitError, type RerankCreateParams, type RerankResponse, type RerankResult, type RerankResultDocument, Stream, type StreamChoice, type TranscriptionCreateParams, type TranscriptionResponse, type TranscriptionSegment, type Usage, Pendra as default };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,41 @@ interface ChatCompletionMessage {
67
67
  role: string;
68
68
  content: string | null;
69
69
  tool_calls?: ChatCompletionMessageToolCall[];
70
+ /**
71
+ * A reasoning model's chain-of-thought, kept separate from the answer in
72
+ * `content`. The API sends it as `reasoning_content` and mirrors it on
73
+ * `reasoning` for wider client compatibility — both are populated here.
74
+ * Turn the thinking off with `enable_thinking: false`.
75
+ */
76
+ reasoning_content?: string | null;
77
+ /** Mirror of {@link ChatCompletionMessage.reasoning_content}. */
78
+ reasoning?: string | null;
79
+ }
80
+ /** One part of a multimodal message — text, or an image for a vision model. */
81
+ type ChatCompletionContentPart = {
82
+ type: "text";
83
+ text: string;
84
+ } | {
85
+ type: "image_url";
86
+ image_url: {
87
+ url: string;
88
+ detail?: "auto" | "low" | "high";
89
+ };
90
+ };
91
+ /**
92
+ * A message you send. `content` is a plain string for text, or an array of
93
+ * parts for a vision model. Tool results come back as
94
+ * `{ role: "tool", tool_call_id, content }`.
95
+ */
96
+ interface ChatCompletionMessageParam {
97
+ role: string;
98
+ content: string | ChatCompletionContentPart[] | null;
99
+ /** Names a participant, e.g. which function a tool/function message is from. */
100
+ name?: string;
101
+ /** On a `"tool"` message, the id of the call this is the result of. */
102
+ tool_call_id?: string;
103
+ /** On an assistant message you replay back, the calls it made. */
104
+ tool_calls?: ChatCompletionMessageToolCall[];
70
105
  }
71
106
  interface Choice {
72
107
  index: number;
@@ -85,6 +120,13 @@ interface ChoiceDelta {
85
120
  role?: string | null;
86
121
  content?: string | null;
87
122
  tool_calls?: ChatCompletionMessageToolCall[];
123
+ /**
124
+ * Streaming chain-of-thought, arriving in its own deltas before the content
125
+ * deltas start. Same both-spellings rule as {@link ChatCompletionMessage}.
126
+ */
127
+ reasoning_content?: string | null;
128
+ /** Mirror of {@link ChoiceDelta.reasoning_content}. */
129
+ reasoning?: string | null;
88
130
  }
89
131
  interface StreamChoice {
90
132
  index: number;
@@ -98,17 +140,41 @@ interface ChatCompletionChunk {
98
140
  model: string;
99
141
  choices: StreamChoice[];
100
142
  }
143
+ /**
144
+ * Parameters for `client.chat.completions.create()`.
145
+ *
146
+ * Every field except `worker_id` (which travels as a header) is sent to the
147
+ * API as you pass it — including keys this interface doesn't declare, so a
148
+ * Chat Completions field newer than your SDK version still reaches the model.
149
+ * TypeScript will reject an undeclared key written directly in the call, which
150
+ * is what catches typos; pass it through a variable or a cast when you mean it.
151
+ */
101
152
  interface ChatCompletionCreateParams {
102
153
  model: string;
103
- messages: Array<{
104
- role: string;
105
- content: string;
106
- }>;
154
+ messages: ChatCompletionMessageParam[];
107
155
  temperature?: number | null;
108
156
  max_tokens?: number | null;
109
157
  top_p?: number | null;
158
+ /** Keep only the `top_k` most likely tokens (0 = off). */
159
+ top_k?: number | null;
160
+ /** Drop tokens less likely than `min_p` × the top token's probability. */
161
+ min_p?: number | null;
162
+ /** Penalise tokens by how often they've appeared (-2 to 2; 0 = off). */
163
+ frequency_penalty?: number | null;
164
+ /** Penalise tokens that have appeared at all (-2 to 2; 0 = off). */
165
+ presence_penalty?: number | null;
166
+ /** Classic repetition penalty (1.0 = off; e.g. 1.1–1.3 discourages repeats). */
167
+ repeat_penalty?: number | null;
168
+ /** How many recent tokens `repeat_penalty` looks back over (default 64). */
169
+ repeat_last_n?: number | null;
170
+ /** Seed the sampler for reproducible output. */
171
+ seed?: number | null;
110
172
  stop?: string | string[] | null;
111
173
  stream?: boolean;
174
+ /** Ask for `usage` on the final streamed chunk. */
175
+ stream_options?: {
176
+ include_usage?: boolean;
177
+ } | null;
112
178
  /**
113
179
  * Functions the model may call, in the OpenAI tools format. When the model
114
180
  * calls one, the reply's `choices[0].message.tool_calls` is populated and
@@ -120,6 +186,37 @@ interface ChatCompletionCreateParams {
120
186
  tool_choice?: unknown;
121
187
  /** Allow the model to request several tool calls in one reply. */
122
188
  parallel_tool_calls?: boolean | null;
189
+ /**
190
+ * Constrain the reply's shape — `{ type: "json_object" }` for any JSON, or
191
+ * `{ type: "json_schema", json_schema: { ... } }` to pin it to a schema.
192
+ */
193
+ response_format?: {
194
+ type: "text" | "json_object" | "json_schema";
195
+ json_schema?: Record<string, unknown>;
196
+ } | null;
197
+ /**
198
+ * Set `false` to make a reasoning model answer directly, skipping its
199
+ * chain-of-thought. Defaults to `true`. Only "hybrid" models can toggle it.
200
+ */
201
+ enable_thinking?: boolean | null;
202
+ /**
203
+ * How hard a reasoning model should think — `"low"`, `"medium"`, `"high"`,
204
+ * or `"none"` (alias `"minimal"`) to turn thinking off, the same as
205
+ * `enable_thinking: false`.
206
+ */
207
+ reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | (string & {}) | null;
208
+ /** Bias specific tokens, keyed by token id (-100 to 100). */
209
+ logit_bias?: Record<string, number> | null;
210
+ /** Return log-probabilities for the chosen tokens (model permitting). */
211
+ logprobs?: boolean | null;
212
+ /** How many alternatives to report per position when `logprobs` is on. */
213
+ top_logprobs?: number | null;
214
+ /** OpenAI's newer spelling of `max_tokens`. */
215
+ max_completion_tokens?: number | null;
216
+ /** How many completions to generate. */
217
+ n?: number | null;
218
+ /** An opaque end-user id, passed through for your own attribution. */
219
+ user?: string | null;
123
220
  /**
124
221
  * Optionally pin the request to a specific worker that serves this model.
125
222
  * Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
@@ -128,10 +225,18 @@ interface ChatCompletionCreateParams {
128
225
  worker_id?: string | null;
129
226
  }
130
227
 
228
+ /**
229
+ * Async-iterable reader for a streaming chat completion.
230
+ *
231
+ * Framing is handled by {@link SseDecoder}, which assembles whole SSE frames
232
+ * rather than filtering lines — so a frame the server tags with a named
233
+ * `event:` is dropped in one piece instead of having its `data:` line mistaken
234
+ * for a chat chunk (issue #1398).
235
+ */
131
236
  declare class Stream implements AsyncIterable<ChatCompletionChunk> {
132
237
  private reader;
133
238
  private decoder;
134
- private buffer;
239
+ private sse;
135
240
  private done;
136
241
  private controller;
137
242
  constructor(response: Response, controller: AbortController);
@@ -459,4 +564,4 @@ declare class RateLimitError extends APIStatusError {
459
564
  constructor(message?: string);
460
565
  }
461
566
 
462
- export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageToolCall, type Choice, type ChoiceDelta, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, PrivateInferenceError, RateLimitError, type RerankCreateParams, type RerankResponse, type RerankResult, type RerankResultDocument, Stream, type StreamChoice, type TranscriptionCreateParams, type TranscriptionResponse, type TranscriptionSegment, type Usage, Pendra as default };
567
+ export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageParam, type ChatCompletionMessageToolCall, type Choice, type ChoiceDelta, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, PrivateInferenceError, RateLimitError, type RerankCreateParams, type RerankResponse, type RerankResult, type RerankResultDocument, Stream, type StreamChoice, type TranscriptionCreateParams, type TranscriptionResponse, type TranscriptionSegment, type Usage, Pendra as default };
package/dist/index.js CHANGED
@@ -203,11 +203,78 @@ var Audio = class {
203
203
  }
204
204
  };
205
205
 
206
+ // src/_sse.ts
207
+ var DEFAULT_EVENT = "message";
208
+ function fieldValue(line, name) {
209
+ const value = line.slice(name.length + 1);
210
+ return value.startsWith(" ") ? value.slice(1) : value;
211
+ }
212
+ var SseDecoder = class {
213
+ constructor() {
214
+ this.buffer = "";
215
+ this.event = "";
216
+ this.data = [];
217
+ }
218
+ /** Feed a chunk of decoded text; returns the payloads it completed. */
219
+ push(text) {
220
+ this.buffer += text;
221
+ const lines = this.buffer.split("\n");
222
+ this.buffer = lines.pop() ?? "";
223
+ const out = [];
224
+ for (const line of lines) {
225
+ const payload = this.pushLine(line);
226
+ if (payload !== null) out.push(payload);
227
+ }
228
+ return out;
229
+ }
230
+ /**
231
+ * Release what the stream ended without terminating: the held-back partial
232
+ * line, plus any frame that never got its blank line.
233
+ *
234
+ * The spec discards an unterminated final block; we keep it, so a connection
235
+ * that drops after the last `data:` line but before its blank line still
236
+ * delivers that payload rather than silently losing it.
237
+ */
238
+ flush() {
239
+ const out = [];
240
+ if (this.buffer !== "") {
241
+ const payload = this.pushLine(this.buffer);
242
+ this.buffer = "";
243
+ if (payload !== null) out.push(payload);
244
+ }
245
+ const tail = this.endFrame();
246
+ if (tail !== null) out.push(tail);
247
+ return out;
248
+ }
249
+ pushLine(rawLine) {
250
+ const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
251
+ if (line === "") return this.endFrame();
252
+ if (line.startsWith(":")) return null;
253
+ if (line.startsWith("event:")) {
254
+ this.event = fieldValue(line, "event");
255
+ return null;
256
+ }
257
+ if (line.startsWith("data:")) {
258
+ this.data.push(fieldValue(line, "data"));
259
+ return null;
260
+ }
261
+ return null;
262
+ }
263
+ endFrame() {
264
+ const { data, event } = this;
265
+ this.data = [];
266
+ this.event = "";
267
+ if (data.length === 0) return null;
268
+ if (event !== "" && event !== DEFAULT_EVENT) return null;
269
+ return data.join("\n");
270
+ }
271
+ };
272
+
206
273
  // src/streaming.ts
207
274
  var Stream = class {
208
275
  constructor(response, controller) {
209
276
  this.decoder = new TextDecoder();
210
- this.buffer = "";
277
+ this.sse = new SseDecoder();
211
278
  this.done = false;
212
279
  if (!response.body) {
213
280
  throw new Error("Response body is null \u2014 streaming not supported");
@@ -219,18 +286,8 @@ var Stream = class {
219
286
  try {
220
287
  while (!this.done) {
221
288
  const { value, done: readerDone } = await this.reader.read();
222
- if (readerDone) {
223
- this.done = true;
224
- break;
225
- }
226
- this.buffer += this.decoder.decode(value, { stream: true });
227
- const lines = this.buffer.split("\n");
228
- this.buffer = lines.pop() ?? "";
229
- for (const line of lines) {
230
- const trimmed = line.trim();
231
- if (!trimmed || trimmed.startsWith(":")) continue;
232
- if (!trimmed.startsWith("data: ")) continue;
233
- const data = trimmed.slice(6);
289
+ const payloads = readerDone ? this.sse.flush() : this.sse.push(this.decoder.decode(value, { stream: true }));
290
+ for (const data of payloads) {
234
291
  if (data === "[DONE]") {
235
292
  this.done = true;
236
293
  return;
@@ -240,6 +297,10 @@ var Stream = class {
240
297
  } catch {
241
298
  }
242
299
  }
300
+ if (readerDone) {
301
+ this.done = true;
302
+ break;
303
+ }
243
304
  }
244
305
  } finally {
245
306
  this.reader.releaseLock();
@@ -255,7 +316,8 @@ var Stream = class {
255
316
  var DECODER = new TextDecoder();
256
317
  var EncryptedStream = class {
257
318
  constructor(response, controller, decryptor) {
258
- this.buffer = "";
319
+ this.decoder = new TextDecoder();
320
+ this.sse = new SseDecoder();
259
321
  this.done = false;
260
322
  if (!response.body) {
261
323
  throw new Error("Response body is null \u2014 streaming not supported");
@@ -268,18 +330,8 @@ var EncryptedStream = class {
268
330
  try {
269
331
  while (!this.done) {
270
332
  const { value, done: readerDone } = await this.reader.read();
271
- if (readerDone) {
272
- this.done = true;
273
- break;
274
- }
275
- this.buffer += DECODER.decode(value, { stream: true });
276
- const lines = this.buffer.split("\n");
277
- this.buffer = lines.pop() ?? "";
278
- for (const line of lines) {
279
- const trimmed = line.trim();
280
- if (!trimmed || trimmed.startsWith(":") || trimmed.startsWith("event:")) continue;
281
- if (!trimmed.startsWith("data:")) continue;
282
- const data = trimmed.slice("data:".length).trimStart();
333
+ const payloads = readerDone ? this.sse.flush() : this.sse.push(this.decoder.decode(value, { stream: true }));
334
+ for (const data of payloads) {
283
335
  if (data === "[DONE]") {
284
336
  this.done = true;
285
337
  return;
@@ -309,6 +361,10 @@ var EncryptedStream = class {
309
361
  } catch {
310
362
  }
311
363
  }
364
+ if (readerDone) {
365
+ this.done = true;
366
+ break;
367
+ }
312
368
  }
313
369
  } finally {
314
370
  this.reader.releaseLock();
@@ -328,19 +384,11 @@ var Completions = class {
328
384
  this.client = client;
329
385
  }
330
386
  async create(params) {
331
- const body = {
332
- model: params.model,
333
- messages: params.messages
334
- };
335
- if (params.stream != null) body.stream = params.stream;
336
- if (params.temperature != null) body.temperature = params.temperature;
337
- if (params.max_tokens != null) body.max_tokens = params.max_tokens;
338
- if (params.top_p != null) body.top_p = params.top_p;
339
- if (params.stop != null) body.stop = params.stop;
340
- if (params.tools != null) body.tools = params.tools;
341
- if (params.tool_choice != null) body.tool_choice = params.tool_choice;
342
- if (params.parallel_tool_calls != null)
343
- body.parallel_tool_calls = params.parallel_tool_calls;
387
+ const { worker_id: _workerId, ...rest } = params;
388
+ const body = {};
389
+ for (const [key, value] of Object.entries(rest)) {
390
+ if (value != null) body[key] = value;
391
+ }
344
392
  const headers = params.worker_id ? { "X-Pendra-Worker-Id": params.worker_id } : void 0;
345
393
  if (this.client.privateInferenceEnabled) {
346
394
  return this.createEncrypted(params, body, headers);