@namzu/openai 1.2.1 → 1.3.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/CHANGELOG.md +26 -0
- package/README.md +20 -249
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 03e363c: Declare the Node floor these packages already had, and export a type `TelemetryConfig` already required.
|
|
8
|
+
|
|
9
|
+
**`engines.node: ">=20.0.0"`.** Only `@namzu/cli` declared one; the other fourteen published without any, so npm could not warn a consumer installing onto an unsupported runtime — they got a crash at some later import instead. The floor is not new: `@namzu/cli` has declared it since it shipped and `install.sh` has enforced it since it existed. This makes the other fourteen say the same thing.
|
|
10
|
+
|
|
11
|
+
If you install with `engine-strict=true` on Node 18, an install that previously emitted nothing will now fail. Upgrade to Node 20 or newer, which the code already assumed. Everyone else sees no change, or an `EBADENGINE` warning that replaces a later crash.
|
|
12
|
+
|
|
13
|
+
Worth stating plainly: CI verifies Node 22 and 24. The 20 floor is a declared minimum, not a tested one.
|
|
14
|
+
|
|
15
|
+
**`SpanProcessorLike` is now exported from `@namzu/telemetry`.** `TelemetryConfig.spanProcessors` takes `readonly SpanProcessorLike[]`, and the type had no export — a field on the public surface whose type was not on it, so a host supplying the value had to inline the shape or reach for `any`.
|
|
16
|
+
|
|
17
|
+
## 1.2.2
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 5394981: Make each driver's README an npm package page rather than its manual.
|
|
22
|
+
|
|
23
|
+
Every driver README carried its full reference — configuration tables, capability matrices, error surfaces — between 167 and 392 lines of it. That is a reasonable shape for a single-package repository, where the README _is_ the documentation, and the wrong one for a package in a monorepo that has a `docs/` tree: it duplicates what the docs say, and nothing checks that the two agree.
|
|
24
|
+
|
|
25
|
+
The README is now what a reader needs in the first minute — what the driver is, install, one working example, links. The reference moved to `docs/providers/<name>.md`, whole, and its code samples are now compiled against the built SDK by the doc-fence gate on every CI run. They never were before; several did not compile.
|
|
26
|
+
|
|
27
|
+
No API change.
|
|
28
|
+
|
|
3
29
|
## 1.2.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "@namzu/openai"
|
|
4
4
|
description: >-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
streaming entry point, tool use, images and documents. Separate from the
|
|
8
|
-
kernel so a consumer who never calls this vendor installs no vendor client.
|
|
5
|
+
Implements the kernel's `LLMProvider` interface over the official OpenAI
|
|
6
|
+
SDK, and over any endpoint that speaks the same wire format.
|
|
9
7
|
tags: [readme, package, provider, openai]
|
|
10
8
|
timestamp: 2026-08-17T00:00:00Z
|
|
11
9
|
status: active
|
|
@@ -16,33 +14,22 @@ diataxis: reference
|
|
|
16
14
|
|
|
17
15
|
<h1>@namzu/openai</h1>
|
|
18
16
|
|
|
19
|
-
**The OpenAI driver for [
|
|
17
|
+
**The OpenAI model driver for [Namzu](https://github.com/cogitave/namzu).**
|
|
20
18
|
|
|
21
|
-
[](https://www.npmjs.com/package/@namzu/openai)
|
|
20
|
+
[](https://github.com/cogitave/namzu/actions/workflows/ci.yml)
|
|
21
|
+
[](https://github.com/cogitave/namzu/blob/main/LICENSE.md)
|
|
23
22
|
|
|
24
|
-
[Install](#install) · [
|
|
23
|
+
[Install](#install) · [Usage](#usage) · [Documentation](#documentation)
|
|
25
24
|
|
|
26
25
|
</div>
|
|
27
26
|
|
|
28
27
|
---
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
package, installed only if you call that service.
|
|
35
|
-
|
|
36
|
-
This is the driver for OpenAI. It wraps the official
|
|
37
|
-
[`openai`](https://www.npmjs.com/package/openai) client and speaks the **Chat
|
|
38
|
-
Completions API**: one streaming entry point, tool use with optional
|
|
39
|
-
constrained generation, image and document attachments, and the kernel's error
|
|
40
|
-
taxonomy on every failure path.
|
|
41
|
-
|
|
42
|
-
Nothing here is a second way to talk to the model. The driver's job is to turn
|
|
43
|
-
the kernel's request into this vendor's request and its response back into
|
|
44
|
-
`StreamChunk`s — and to refuse, loudly, anything the kernel can ask for that
|
|
45
|
-
this wire cannot carry.
|
|
29
|
+
Implements the kernel's `LLMProvider` interface over the official OpenAI
|
|
30
|
+
SDK, and over any endpoint that speaks the same wire format. Installed only
|
|
31
|
+
if you use it — the kernel has no preferred vendor and no driver is a
|
|
32
|
+
dependency of it.
|
|
46
33
|
|
|
47
34
|
## Install
|
|
48
35
|
|
|
@@ -50,11 +37,9 @@ this wire cannot carry.
|
|
|
50
37
|
pnpm add @namzu/sdk @namzu/openai
|
|
51
38
|
```
|
|
52
39
|
|
|
53
|
-
`@namzu/sdk` is a
|
|
54
|
-
kernel version and one copy is shared with every other driver. The `openai`
|
|
55
|
-
client (`^6.0.0`) is an ordinary dependency and arrives with this package.
|
|
40
|
+
`@namzu/sdk` is a peer dependency. Install both.
|
|
56
41
|
|
|
57
|
-
##
|
|
42
|
+
## Usage
|
|
58
43
|
|
|
59
44
|
```ts
|
|
60
45
|
import { ProviderRegistry } from '@namzu/sdk'
|
|
@@ -77,229 +62,15 @@ for await (const chunk of provider.chatStream({
|
|
|
77
62
|
}
|
|
78
63
|
```
|
|
79
64
|
|
|
80
|
-
`
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
second time throws `DuplicateProviderError`; pass `{ replace: true }` if that
|
|
84
|
-
is what you meant.
|
|
85
|
-
|
|
86
|
-
**There is one model entry point and it streams.** `LLMProvider` declares
|
|
87
|
-
`chatStream(params)` and nothing else — there is no `chat()` method on this or
|
|
88
|
-
any other driver. When you want the aggregated, non-streaming shape, drain the
|
|
89
|
-
stream through the kernel's helper:
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
import { collectChatCompletion } from '@namzu/sdk'
|
|
93
|
-
|
|
94
|
-
const response = await collectChatCompletion(
|
|
95
|
-
provider.chatStream({
|
|
96
|
-
model: 'gpt-4o-mini',
|
|
97
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
98
|
-
}),
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
console.log(response.message.content)
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Most callers never do either, because the run loop consumes the stream itself:
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
import { runAgent } from '@namzu/sdk'
|
|
108
|
-
|
|
109
|
-
const { output, run } = await runAgent({
|
|
110
|
-
provider,
|
|
111
|
-
model: 'gpt-4o-mini',
|
|
112
|
-
prompt: 'What is the capital of France?',
|
|
113
|
-
})
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
You can also construct the driver directly and skip the registry — useful when
|
|
117
|
-
a host holds one provider per tenant rather than one per process:
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
import { OpenAIProvider } from '@namzu/openai'
|
|
121
|
-
|
|
122
|
-
const provider = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY! })
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## Configuration
|
|
126
|
-
|
|
127
|
-
| Field | Default | Notes |
|
|
128
|
-
|---|---|---|
|
|
129
|
-
| `apiKey` | — | required; the constructor throws on an empty value |
|
|
130
|
-
| `model` | — | default model, overridden by `params.model` on a call |
|
|
131
|
-
| `baseURL` | `OPENAI_BASE_URL`, else `https://api.openai.com/v1` | any OpenAI-shaped endpoint |
|
|
132
|
-
| `organization` | — | organization id |
|
|
133
|
-
| `project` | — | project id |
|
|
134
|
-
| `timeout` | the `openai` client's default (10 minutes) | per-request, in milliseconds |
|
|
135
|
-
| `defaultHeaders` | — | merged **over** the attribution header on every request |
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
import type { OpenAIConfig, OpenAIProviderConfig } from '@namzu/openai'
|
|
139
|
-
// OpenAIProviderConfig is OpenAIConfig plus the `type: 'openai'` discriminator
|
|
140
|
-
// the registry narrows on. The class takes the former; `create()` takes the latter.
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
That table is the whole surface. A field the vendor client accepts and this
|
|
144
|
-
config does not name — `maxRetries`, for one — is not forwarded, and the
|
|
145
|
-
client's own default stands.
|
|
146
|
-
|
|
147
|
-
`apiKey` is checked here rather than left to the vendor client, so setting
|
|
148
|
-
`OPENAI_API_KEY` in the environment is not by itself enough: read it and pass
|
|
149
|
-
it. The driver sends one `User-Agent` header identifying the kernel and its
|
|
150
|
-
version, merged so that anything you put in `defaultHeaders` wins — including
|
|
151
|
-
that header, if you would rather send your own.
|
|
152
|
-
|
|
153
|
-
## Capabilities
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
import { OPENAI_CAPABILITIES } from '@namzu/openai'
|
|
157
|
-
|
|
158
|
-
// {
|
|
159
|
-
// supportsTools: true,
|
|
160
|
-
// supportsStreaming: true,
|
|
161
|
-
// supportsFunctionCalling: true,
|
|
162
|
-
// supportsVision: true,
|
|
163
|
-
// supportsDocuments: true,
|
|
164
|
-
// }
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
A capability declaration here is about **this driver**, not about the vendor
|
|
168
|
-
API: it answers "does the code map this?" rather than "could it?". The runtime
|
|
169
|
-
negotiates against the constructed instance, and an absent flag is read as
|
|
170
|
-
permissive — so a missing flag is a claim, not an omission, which is why all
|
|
171
|
-
five are stated.
|
|
172
|
-
|
|
173
|
-
What each one is claiming:
|
|
174
|
-
|
|
175
|
-
- **Tools.** `params.tools` become function tools. `params.toolChoice` maps to
|
|
176
|
-
`auto` / `none` / `required` or a named function, and `parallelToolCalls` is
|
|
177
|
-
passed through.
|
|
178
|
-
- **Constrained tool input.** Every tool named in `enforceToolInputSchema` is
|
|
179
|
-
sent with `strict: true` on the function, so its schema is enforced rather
|
|
180
|
-
than suggested. Tools not named are unaffected.
|
|
181
|
-
- **Vision.** An image attachment on a user message becomes an `image_url`
|
|
182
|
-
content part carrying a base64 data URI, with the message text first.
|
|
183
|
-
- **Documents.** A document attachment becomes a `file` part — not an image
|
|
184
|
-
part with a different media type, which is what it used to be.
|
|
185
|
-
|
|
186
|
-
Two more shapes are worth knowing because they are not flags. Tool result
|
|
187
|
-
messages are text-only on this wire, so a structured result degrades through
|
|
188
|
-
the kernel's `toolResultToText` to an honest placeholder rather than having a
|
|
189
|
-
base64 payload dumped into the transcript. And the stream is requested with
|
|
190
|
-
usage included, so `chunk.usage` carries real token counts — `cachedTokens`
|
|
191
|
-
comes from the vendor's prompt-token detail, and `cacheWriteTokens` is always
|
|
192
|
-
`0` because this API does not report cache writes.
|
|
193
|
-
|
|
194
|
-
This driver emits no per-tool `toolCallEnd` boundary; the orchestrator infers
|
|
195
|
-
tool completion from the end of the stream. It emits no reasoning deltas and no
|
|
196
|
-
citation deltas either — which is not a gap to work around but the reason two
|
|
197
|
-
requests are refused outright, below.
|
|
198
|
-
|
|
199
|
-
## What it refuses
|
|
200
|
-
|
|
201
|
-
The kernel's rule is that a capability accepted and then quietly not applied is
|
|
202
|
-
worse than one that errors, because the caller stops looking. Four requests
|
|
203
|
-
throw here instead of being dropped:
|
|
204
|
-
|
|
205
|
-
- **`thinking: { type: 'enabled' | 'adaptive' }`** — this driver does not
|
|
206
|
-
implement extended thinking. Dropping the field would return an ordinary
|
|
207
|
-
completion with an empty reasoning list, which reads as "the model did not
|
|
208
|
-
reason" rather than "nobody asked it to". `{ type: 'disabled' }` and an
|
|
209
|
-
absent field are accepted, because off is the state the driver is already in.
|
|
210
|
-
- **`effort`** — refused on the same reasoning, and it is the quieter failure
|
|
211
|
-
of the two: a run someone believes they paid for at `max` would be
|
|
212
|
-
indistinguishable from one at the model's default, including on the bill.
|
|
213
|
-
- **A document attachment with `citations: true`** — this request format has no
|
|
214
|
-
way to carry citations back, and answering without them removes exactly the
|
|
215
|
-
checkability that was asked for.
|
|
216
|
-
- **A `stored` attachment that reaches the driver unresolved** — resolve it
|
|
217
|
-
against the run's attachment store first. Skipping it would send a user
|
|
218
|
-
message that silently lost its image.
|
|
219
|
-
|
|
220
|
-
The error names the driver and says what to do instead, which is what turns a
|
|
221
|
-
bug report about the model into a one-line configuration change in a
|
|
222
|
-
multi-provider setup.
|
|
223
|
-
|
|
224
|
-
## Errors
|
|
225
|
-
|
|
226
|
-
Every failure leaves this driver as the kernel's `ProviderRequestError`,
|
|
227
|
-
classified into the shared taxonomy — `auth`, `throttle`, `bad_request`,
|
|
228
|
-
`context_overflow`, `server`, `network` — with the status, a `Retry-After`
|
|
229
|
-
translated to milliseconds where the vendor sent one, and a scrubbed `detail`.
|
|
230
|
-
|
|
231
|
-
```ts
|
|
232
|
-
import { isProviderRequestError } from '@namzu/sdk'
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
for await (const chunk of provider.chatStream({
|
|
236
|
-
model: 'gpt-4o-mini',
|
|
237
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
238
|
-
})) {
|
|
239
|
-
if (chunk.delta.content) process.stdout.write(chunk.delta.content)
|
|
240
|
-
}
|
|
241
|
-
} catch (err) {
|
|
242
|
-
if (isProviderRequestError(err) && err.kind === 'throttle') {
|
|
243
|
-
// err.retryAfterMs, err.status, err.detail
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
The vendor error is **dropped**, not re-thrown and not attached as `cause`. The
|
|
249
|
-
`openai` client builds its message from the response body, so a credential the
|
|
250
|
-
upstream echoed back is already inside that message before this code runs — and
|
|
251
|
-
a `cause` is precisely what a structured logger walks. Classification is taken
|
|
252
|
-
from the status instead.
|
|
253
|
-
|
|
254
|
-
`params.signal` is honoured end to end: it is handed to the vendor request so
|
|
255
|
-
an abort tears down the in-flight SSE connection, and it is re-checked between
|
|
256
|
-
chunks so a stop lands mid-turn rather than at the next turn boundary. On abort
|
|
257
|
-
the signal's own `reason` is what you catch.
|
|
258
|
-
|
|
259
|
-
The driver declares no retry defaults, so the kernel's generic retry policy
|
|
260
|
-
applies, and the vendor client's internal retry behaviour is left exactly as it
|
|
261
|
-
ships.
|
|
262
|
-
|
|
263
|
-
## Health and model listing
|
|
264
|
-
|
|
265
|
-
- `probeCredential()` makes an authenticated call and rejects if the key is
|
|
266
|
-
refused. It is declared rather than inferred: a driver that does not
|
|
267
|
-
implement one is reported as *not checked*, never as verified.
|
|
268
|
-
- `listModels()` returns the live catalogue as `ModelInfo[]`. Treat it as a
|
|
269
|
-
menu, not a rate card — `inputPrice` and `outputPrice` come back `0` because
|
|
270
|
-
the listing endpoint does not carry prices.
|
|
271
|
-
- `healthCheck()` is the same probe reduced to a boolean.
|
|
272
|
-
|
|
273
|
-
All three are optional members of `LLMProvider`, so call them through the
|
|
274
|
-
optional chain (`await provider.probeCredential?.()`) unless you are holding
|
|
275
|
-
the concrete class. `doctorCheck`, `effortLevelsFor` and `resolveContextWindow` are
|
|
276
|
-
not implemented here, and are absent rather than stubbed — the runtime tells
|
|
277
|
-
"this driver cannot answer" from "it answered nothing", and a stub would
|
|
278
|
-
destroy that distinction.
|
|
279
|
-
|
|
280
|
-
## OpenAI-compatible endpoints
|
|
281
|
-
|
|
282
|
-
Setting `baseURL` points this driver at anything speaking the same shape:
|
|
283
|
-
Azure OpenAI with a deployment URL, an enterprise endpoint, a self-hosted
|
|
284
|
-
gateway, or a local server. The package constructs the base `OpenAI` client
|
|
285
|
-
only — it does not expose the vendor's Azure-specific constructor, so an Azure
|
|
286
|
-
deployment that needs that client's URL and api-version handling is better
|
|
287
|
-
built with the vendor SDK directly.
|
|
288
|
-
|
|
289
|
-
For a generic compatible backend where you would rather not carry the vendor
|
|
290
|
-
client at all, [`@namzu/http`](https://www.npmjs.com/package/@namzu/http) with
|
|
291
|
-
`dialect: 'openai'` is the zero-dependency alternative.
|
|
65
|
+
`chatStream` is the only model entry point; a non-streaming call is that
|
|
66
|
+
stream collected. In practice the kernel's run loop calls it and hands you
|
|
67
|
+
events.
|
|
292
68
|
|
|
293
|
-
##
|
|
69
|
+
## Documentation
|
|
294
70
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
model, token usage, finish reason — so they are the same whichever driver is
|
|
298
|
-
underneath. Add [`@namzu/telemetry`](https://www.npmjs.com/package/@namzu/telemetry)
|
|
299
|
-
to export them; without an exporter installed, the OTel API's no-op defaults
|
|
300
|
-
discard them.
|
|
71
|
+
- [The OpenAI driver — configuration, refusals and compatible endpoints](https://github.com/cogitave/namzu/blob/main/docs/providers/openai.md)
|
|
72
|
+
- [Namzu docs](https://github.com/cogitave/namzu/tree/main/docs)
|
|
301
73
|
|
|
302
74
|
## License
|
|
303
75
|
|
|
304
|
-
FSL-1.1-MIT, converting to MIT two years after each release.
|
|
305
|
-
`@namzu/sdk`.
|
|
76
|
+
FSL-1.1-MIT, converting to MIT two years after each release.
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/openai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "OpenAI LLM provider for @namzu/sdk via the official `openai` npm SDK. Chat Completions API with streaming + tool-use.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20.0.0"
|
|
8
|
+
},
|
|
6
9
|
"type": "module",
|
|
7
10
|
"homepage": "https://github.com/cogitave/namzu#readme",
|
|
8
11
|
"repository": {
|
|
@@ -54,7 +57,7 @@
|
|
|
54
57
|
"@types/node": "^22.19.17",
|
|
55
58
|
"typescript": "^5.5.0",
|
|
56
59
|
"vitest": "^3.2.6",
|
|
57
|
-
"@namzu/sdk": "^
|
|
60
|
+
"@namzu/sdk": "^30.1.0"
|
|
58
61
|
},
|
|
59
62
|
"scripts": {
|
|
60
63
|
"build": "tsc --build",
|