pendra 0.9.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,12 +140,18 @@ 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;
@@ -117,10 +165,16 @@ interface ChatCompletionCreateParams {
117
165
  presence_penalty?: number | null;
118
166
  /** Classic repetition penalty (1.0 = off; e.g. 1.1–1.3 discourages repeats). */
119
167
  repeat_penalty?: number | null;
168
+ /** How many recent tokens `repeat_penalty` looks back over (default 64). */
169
+ repeat_last_n?: number | null;
120
170
  /** Seed the sampler for reproducible output. */
121
171
  seed?: number | null;
122
172
  stop?: string | string[] | null;
123
173
  stream?: boolean;
174
+ /** Ask for `usage` on the final streamed chunk. */
175
+ stream_options?: {
176
+ include_usage?: boolean;
177
+ } | null;
124
178
  /**
125
179
  * Functions the model may call, in the OpenAI tools format. When the model
126
180
  * calls one, the reply's `choices[0].message.tool_calls` is populated and
@@ -132,6 +186,37 @@ interface ChatCompletionCreateParams {
132
186
  tool_choice?: unknown;
133
187
  /** Allow the model to request several tool calls in one reply. */
134
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;
135
220
  /**
136
221
  * Optionally pin the request to a specific worker that serves this model.
137
222
  * Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
@@ -479,4 +564,4 @@ declare class RateLimitError extends APIStatusError {
479
564
  constructor(message?: string);
480
565
  }
481
566
 
482
- 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,12 +140,18 @@ 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;
@@ -117,10 +165,16 @@ interface ChatCompletionCreateParams {
117
165
  presence_penalty?: number | null;
118
166
  /** Classic repetition penalty (1.0 = off; e.g. 1.1–1.3 discourages repeats). */
119
167
  repeat_penalty?: number | null;
168
+ /** How many recent tokens `repeat_penalty` looks back over (default 64). */
169
+ repeat_last_n?: number | null;
120
170
  /** Seed the sampler for reproducible output. */
121
171
  seed?: number | null;
122
172
  stop?: string | string[] | null;
123
173
  stream?: boolean;
174
+ /** Ask for `usage` on the final streamed chunk. */
175
+ stream_options?: {
176
+ include_usage?: boolean;
177
+ } | null;
124
178
  /**
125
179
  * Functions the model may call, in the OpenAI tools format. When the model
126
180
  * calls one, the reply's `choices[0].message.tool_calls` is populated and
@@ -132,6 +186,37 @@ interface ChatCompletionCreateParams {
132
186
  tool_choice?: unknown;
133
187
  /** Allow the model to request several tool calls in one reply. */
134
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;
135
220
  /**
136
221
  * Optionally pin the request to a specific worker that serves this model.
137
222
  * Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
@@ -479,4 +564,4 @@ declare class RateLimitError extends APIStatusError {
479
564
  constructor(message?: string);
480
565
  }
481
566
 
482
- 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
@@ -384,27 +384,11 @@ var Completions = class {
384
384
  this.client = client;
385
385
  }
386
386
  async create(params) {
387
- const body = {
388
- model: params.model,
389
- messages: params.messages
390
- };
391
- if (params.stream != null) body.stream = params.stream;
392
- if (params.temperature != null) body.temperature = params.temperature;
393
- if (params.max_tokens != null) body.max_tokens = params.max_tokens;
394
- if (params.top_p != null) body.top_p = params.top_p;
395
- if (params.top_k != null) body.top_k = params.top_k;
396
- if (params.min_p != null) body.min_p = params.min_p;
397
- if (params.frequency_penalty != null)
398
- body.frequency_penalty = params.frequency_penalty;
399
- if (params.presence_penalty != null)
400
- body.presence_penalty = params.presence_penalty;
401
- if (params.repeat_penalty != null) body.repeat_penalty = params.repeat_penalty;
402
- if (params.seed != null) body.seed = params.seed;
403
- if (params.stop != null) body.stop = params.stop;
404
- if (params.tools != null) body.tools = params.tools;
405
- if (params.tool_choice != null) body.tool_choice = params.tool_choice;
406
- if (params.parallel_tool_calls != null)
407
- 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
+ }
408
392
  const headers = params.worker_id ? { "X-Pendra-Worker-Id": params.worker_id } : void 0;
409
393
  if (this.client.privateInferenceEnabled) {
410
394
  return this.createEncrypted(params, body, headers);