@namzu/openai 1.1.1 → 1.2.1
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 +75 -0
- package/README.md +253 -30
- package/dist/client.d.ts +8 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +23 -4
- package/dist/client.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +26 -3
- package/dist/strict-schema.d.ts +0 -2
- package/dist/strict-schema.d.ts.map +0 -1
- package/dist/strict-schema.js +0 -2
- package/dist/strict-schema.js.map +0 -1
- package/src/strict-schema.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4edf2c6: Stop shipping an empty module.
|
|
8
|
+
|
|
9
|
+
`src/strict-schema.ts` has been zero bytes since PR #64. Nothing imported it, it
|
|
10
|
+
exported nothing, and the compiler still emitted `dist/strict-schema.js`,
|
|
11
|
+
`.d.ts` and both maps for it — five files in the published tarball, holding
|
|
12
|
+
nothing, behind a filename that promises the constrained-decoding schema logic.
|
|
13
|
+
|
|
14
|
+
That logic exists and always did, in `@namzu/sdk`: `assertStrictSchema` refuses a
|
|
15
|
+
tool whose schema falls outside the strict subset rather than rewriting it. No
|
|
16
|
+
consumer-visible behaviour changes here; `@namzu/openai` exports only `.`, so
|
|
17
|
+
the file was never reachable as a subpath either.
|
|
18
|
+
|
|
19
|
+
`.github/scripts/check-publish-metadata.mjs` now fails on any packed source file
|
|
20
|
+
of zero bytes, so the next one is caught before the registry rather than after.
|
|
21
|
+
|
|
22
|
+
- 3331493: A message can carry a reference to an attachment instead of its bytes.
|
|
23
|
+
|
|
24
|
+
Every attachment was inline base64 on the message. That is fine for one screenshot and wrong for everything it implies: the bytes are copied into the run's durable transcript, into every checkpoint, into every compaction pass that walks the history, and — because a conversation resends its history — into every subsequent request. A 4 MB PDF attached once is 4 MB in the transcript and 4 MB on the wire per turn for the rest of the run.
|
|
25
|
+
|
|
26
|
+
New: `StoredAttachmentRef` as a third member of `MessageAttachment`, the `AttachmentStore` seam, and `attachmentStore` on `query`. The kernel treats `ref` as **opaque** — this seam says nothing about whether it is a hash, a path or a URL, because the store that minted it is the only thing that can answer. A content-addressed store gets deduplication for free; this interface neither requires nor prevents that.
|
|
27
|
+
|
|
28
|
+
Resolution happens once, where the run is seeded, before the messages reach the run record. Resolving at the provider boundary instead would put refs in the durable transcript, and a run resumed against a store that had since forgotten a ref would fail replaying its own history rather than at the moment somebody asked for the bytes.
|
|
29
|
+
|
|
30
|
+
**Every failure refuses**, and none of the three returns the message unchanged: no store, no such ref, and bytes whose media type is not what the message declared. A message that quietly lost its image is a model answering about a picture it never saw, confidently, with nothing in the transcript saying why. One unresolvable ref refuses the whole conversation rather than resolving what it can.
|
|
31
|
+
|
|
32
|
+
Both provider drivers refuse an unresolved stored attachment rather than sending `data: undefined`. The OpenAI driver reads the real SDK type and the compiler caught it; the Anthropic driver reads through a structural cast and did not, so the stored member is spelled out in its local type — that difference is written at the site.
|
|
33
|
+
|
|
34
|
+
## 1.2.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- d3bd080: A wrong API key is no longer reported as working
|
|
39
|
+
|
|
40
|
+
Typing a key into the picker ran a check that could not fail for two providers.
|
|
41
|
+
Measured against deliberately invalid keys, both said the key was good.
|
|
42
|
+
|
|
43
|
+
**With an OpenRouter key, any string at all passed.** A typo, the wrong
|
|
44
|
+
clipboard entry, a revoked key — all were accepted and reported as verified. The
|
|
45
|
+
check listed the model catalogue and treated a successful list as a passed
|
|
46
|
+
check, and OpenRouter's catalogue endpoint does not authenticate, so it answered
|
|
47
|
+
the same way whatever was sent. Nothing was wrong with that driver's listing; a
|
|
48
|
+
catalogue was simply never evidence about a key.
|
|
49
|
+
|
|
50
|
+
**With an Anthropic key, a real rejection was discarded.** The listing caught
|
|
51
|
+
the `401` and returned a hardcoded three-model list, which the check read as
|
|
52
|
+
success — so the truth existed, was thrown away, and was replaced by something
|
|
53
|
+
that looked like an answer.
|
|
54
|
+
|
|
55
|
+
A credential check is now a separate, declared capability. A driver that
|
|
56
|
+
declares no probe is reported as **not checked**, never as verified, so a driver
|
|
57
|
+
added in future cannot silently inherit a check it does not perform. Anthropic,
|
|
58
|
+
OpenRouter, OpenAI and Ollama declare one; OpenRouter's asks about the key
|
|
59
|
+
rather than the catalogue.
|
|
60
|
+
|
|
61
|
+
Refusal and doubt stay distinct. A `401` means the key is genuinely refused; a
|
|
62
|
+
timeout or a DNS failure means nothing was learned, and is reported that way —
|
|
63
|
+
telling someone on a broken connection to rotate a working key is a different
|
|
64
|
+
error, not a smaller one.
|
|
65
|
+
|
|
66
|
+
**Anthropic's model listing also never once ran.** The SDK method was pulled out
|
|
67
|
+
of its namespace and called bare, so it lost `this`, threw a `TypeError` on
|
|
68
|
+
every call, and was swallowed by the same catch — the hardcoded models were not
|
|
69
|
+
a fallback but the only answer the method could give. It now calls the live
|
|
70
|
+
endpoint, and falls back only when that genuinely fails.
|
|
71
|
+
|
|
72
|
+
The four driver packages are `minor` rather than `patch`: each gains a method
|
|
73
|
+
it did not have, and added functionality is a minor whatever the size of the
|
|
74
|
+
diff. Anthropic's earns it twice over, because its listing now returns the live
|
|
75
|
+
catalogue where it previously returned the same three hardcoded entries to every
|
|
76
|
+
caller - so the value every existing caller receives changes.
|
|
77
|
+
|
|
3
78
|
## 1.1.1
|
|
4
79
|
|
|
5
80
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- okf
|
|
2
|
+
type: Reference
|
|
3
|
+
title: "@namzu/openai"
|
|
4
|
+
description: >-
|
|
5
|
+
The OpenAI model driver for @namzu/sdk. Wraps the official openai client and
|
|
6
|
+
implements the LLMProvider contract over the Chat Completions API — one
|
|
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.
|
|
9
|
+
tags: [readme, package, provider, openai]
|
|
10
|
+
timestamp: 2026-08-17T00:00:00Z
|
|
11
|
+
status: active
|
|
12
|
+
diataxis: reference
|
|
13
|
+
-->
|
|
2
14
|
|
|
3
|
-
|
|
15
|
+
<div align="center">
|
|
16
|
+
|
|
17
|
+
<h1>@namzu/openai</h1>
|
|
18
|
+
|
|
19
|
+
**The OpenAI driver for [`@namzu/sdk`](https://www.npmjs.com/package/@namzu/sdk).**
|
|
20
|
+
|
|
21
|
+
[](https://github.com/cogitave/namzu/blob/main/LICENSE.md)
|
|
22
|
+
[](https://www.npmjs.com/package/@namzu/openai)
|
|
23
|
+
|
|
24
|
+
[Install](#install) · [Use it](#use-it) · [Configuration](#configuration) · [Capabilities](#capabilities) · [What it refuses](#what-it-refuses) · [Errors](#errors) · [Compatible endpoints](#openai-compatible-endpoints)
|
|
25
|
+
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## What this is
|
|
31
|
+
|
|
32
|
+
`@namzu/sdk` has no preferred model vendor. It defines the `LLMProvider`
|
|
33
|
+
contract and ships a scriptable mock; every real service is a separate driver
|
|
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.
|
|
4
46
|
|
|
5
47
|
## Install
|
|
6
48
|
|
|
@@ -8,58 +50,105 @@
|
|
|
8
50
|
pnpm add @namzu/sdk @namzu/openai
|
|
9
51
|
```
|
|
10
52
|
|
|
11
|
-
`@namzu/
|
|
53
|
+
`@namzu/sdk` is a **peer** dependency (`>=1.3.0`), so your lockfile owns the
|
|
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.
|
|
12
56
|
|
|
13
|
-
##
|
|
57
|
+
## Use it
|
|
14
58
|
|
|
15
59
|
```ts
|
|
16
60
|
import { ProviderRegistry } from '@namzu/sdk'
|
|
17
61
|
import { registerOpenAI } from '@namzu/openai'
|
|
18
62
|
|
|
19
|
-
//
|
|
63
|
+
// Once, at startup.
|
|
20
64
|
registerOpenAI()
|
|
21
65
|
|
|
22
|
-
|
|
23
|
-
const { provider, capabilities } = ProviderRegistry.create({
|
|
66
|
+
const { provider } = ProviderRegistry.create({
|
|
24
67
|
type: 'openai',
|
|
25
68
|
apiKey: process.env.OPENAI_API_KEY!,
|
|
26
|
-
model: 'gpt-4o-mini', //
|
|
69
|
+
model: 'gpt-4o-mini', // default; overridable per call
|
|
27
70
|
})
|
|
28
71
|
|
|
29
|
-
const
|
|
72
|
+
for await (const chunk of provider.chatStream({
|
|
30
73
|
model: 'gpt-4o-mini',
|
|
31
74
|
messages: [{ role: 'user', content: 'Hello' }],
|
|
32
|
-
})
|
|
75
|
+
})) {
|
|
76
|
+
if (chunk.delta.content) process.stdout.write(chunk.delta.content)
|
|
77
|
+
}
|
|
33
78
|
```
|
|
34
79
|
|
|
35
|
-
|
|
80
|
+
`registerOpenAI()` adds the `'openai'` type to the kernel's registry and
|
|
81
|
+
augments `ProviderConfigRegistry`, so a `create()` call carrying
|
|
82
|
+
`type: 'openai'` is fully type-narrowed to this driver's config. Registering a
|
|
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:
|
|
36
90
|
|
|
37
91
|
```ts
|
|
38
|
-
|
|
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,
|
|
39
111
|
model: 'gpt-4o-mini',
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
|
|
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! })
|
|
44
123
|
```
|
|
45
124
|
|
|
46
125
|
## Configuration
|
|
47
126
|
|
|
48
|
-
| Field
|
|
49
|
-
|
|
50
|
-
| `apiKey`
|
|
51
|
-
| `model`
|
|
52
|
-
| `baseURL`
|
|
53
|
-
| `organization`
|
|
54
|
-
| `project`
|
|
55
|
-
| `timeout`
|
|
56
|
-
| `defaultHeaders` |
|
|
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 |
|
|
57
136
|
|
|
58
|
-
|
|
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
|
+
```
|
|
59
142
|
|
|
60
|
-
|
|
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.
|
|
61
146
|
|
|
62
|
-
|
|
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.
|
|
63
152
|
|
|
64
153
|
## Capabilities
|
|
65
154
|
|
|
@@ -70,13 +159,147 @@ import { OPENAI_CAPABILITIES } from '@namzu/openai'
|
|
|
70
159
|
// supportsTools: true,
|
|
71
160
|
// supportsStreaming: true,
|
|
72
161
|
// supportsFunctionCalling: true,
|
|
162
|
+
// supportsVision: true,
|
|
163
|
+
// supportsDocuments: true,
|
|
73
164
|
// }
|
|
74
165
|
```
|
|
75
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.
|
|
292
|
+
|
|
76
293
|
## Observability
|
|
77
294
|
|
|
78
|
-
|
|
295
|
+
There is nothing to install or enable here. The kernel emits the GenAI
|
|
296
|
+
semantic-convention spans and metrics around the model call itself — request
|
|
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.
|
|
79
301
|
|
|
80
302
|
## License
|
|
81
303
|
|
|
82
|
-
FSL-1.1-MIT. Same as
|
|
304
|
+
FSL-1.1-MIT, converting to MIT two years after each release. Same as
|
|
305
|
+
`@namzu/sdk`.
|
package/dist/client.d.ts
CHANGED
|
@@ -44,6 +44,14 @@ export declare class OpenAIProvider implements LLMProvider {
|
|
|
44
44
|
constructor(config: OpenAIConfig);
|
|
45
45
|
private resolveModel;
|
|
46
46
|
chatStream(params: ChatCompletionParams): AsyncIterable<StreamChunk>;
|
|
47
|
+
/**
|
|
48
|
+
* Declared even though this driver's listing already fails correctly on a
|
|
49
|
+
* bad key. The check is a declared capability rather than something inferred
|
|
50
|
+
* from whether a menu happened to throw, so a driver that answers the
|
|
51
|
+
* question has to say so — otherwise it is reported unverifiable, which is
|
|
52
|
+
* the honest default and would be a regression here.
|
|
53
|
+
*/
|
|
54
|
+
probeCredential(): Promise<void>;
|
|
47
55
|
listModels(): Promise<ModelInfo[]>;
|
|
48
56
|
healthCheck(): Promise<boolean>;
|
|
49
57
|
}
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EAEpB,WAAW,EACX,SAAS,EACT,oBAAoB,EACpB,WAAW,EAGX,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EAEpB,WAAW,EACX,SAAS,EACT,oBAAoB,EACpB,WAAW,EAGX,MAAM,YAAY,CAAA;AAYnB,OAAO,KAAK,EAEX,0BAA0B,EAC1B,kBAAkB,EAElB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,oBAMjC,CAAA;AAyDD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAC/C,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,UAAU,CAAA;KAAE,CAAA;CACxD,GAAG,IAAI,CAOP;AAuBD,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,GACxC,0BAA0B,EAAE,CA8E9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,kBAAkB,EAAE,GAAG,SAAS,CAY5F;AAED,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,EAAE,YAAW;IACtB,QAAQ,CAAC,IAAI,YAAW;IACxB,QAAQ,CAAC,YAAY,uBAAsB;IAE3C,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAC,CAAQ;gBAEjB,MAAM,EAAE,YAAY;IAqBhC,OAAO,CAAC,YAAY;IAUb,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;IA6F3E;;;;;;OAMG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAYlC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAQrC"}
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertThinkingUnsupported } from '@namzu/sdk';
|
|
2
2
|
import { toolResultToText } from '@namzu/sdk';
|
|
3
3
|
import { ProviderRequestError, isCallerAbortError, isProviderRequestError, providerVendorError, } from '@namzu/sdk';
|
|
4
|
+
import { attributionHeaders } from '@namzu/sdk';
|
|
4
5
|
import OpenAI from 'openai';
|
|
5
6
|
/**
|
|
6
7
|
* Full capability set — this driver maps tools (`toOpenAITools`), streams
|
|
@@ -122,6 +123,14 @@ export function toOpenAIMessages(messages) {
|
|
|
122
123
|
});
|
|
123
124
|
continue;
|
|
124
125
|
}
|
|
126
|
+
if (att.type === 'stored') {
|
|
127
|
+
// Unreachable through `query`, which resolves stored
|
|
128
|
+
// attachments before a driver sees them. REFUSED rather
|
|
129
|
+
// than skipped because the alternative is a user message
|
|
130
|
+
// that silently lost its image: the model answers about a
|
|
131
|
+
// picture it never saw, confidently, and nothing says why.
|
|
132
|
+
throw new Error(`A stored attachment ("${att.ref}") reached the driver unresolved. Resolve it against the run's attachment store before sending.`);
|
|
133
|
+
}
|
|
125
134
|
parts.push({
|
|
126
135
|
type: 'image_url',
|
|
127
136
|
image_url: { url: `data:${att.mediaType};base64,${att.data}` },
|
|
@@ -207,8 +216,10 @@ export class OpenAIProvider {
|
|
|
207
216
|
clientOptions.project = config.project;
|
|
208
217
|
if (config.timeout !== undefined)
|
|
209
218
|
clientOptions.timeout = config.timeout;
|
|
210
|
-
|
|
211
|
-
|
|
219
|
+
// Merged rather than replaced. Assigning `config.defaultHeaders`
|
|
220
|
+
// straight over would drop attribution for exactly the hosts that
|
|
221
|
+
// customise their transport.
|
|
222
|
+
clientOptions.defaultHeaders = { ...attributionHeaders(), ...(config.defaultHeaders ?? {}) };
|
|
212
223
|
this.client = new OpenAI(clientOptions);
|
|
213
224
|
this.defaultModel = config.model;
|
|
214
225
|
}
|
|
@@ -311,13 +322,21 @@ export class OpenAIProvider {
|
|
|
311
322
|
throw providerVendorError({ providerId: 'openai', error: err });
|
|
312
323
|
}
|
|
313
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Declared even though this driver's listing already fails correctly on a
|
|
327
|
+
* bad key. The check is a declared capability rather than something inferred
|
|
328
|
+
* from whether a menu happened to throw, so a driver that answers the
|
|
329
|
+
* question has to say so — otherwise it is reported unverifiable, which is
|
|
330
|
+
* the honest default and would be a regression here.
|
|
331
|
+
*/
|
|
332
|
+
async probeCredential() {
|
|
333
|
+
await this.client.models.list();
|
|
334
|
+
}
|
|
314
335
|
async listModels() {
|
|
315
336
|
const page = await this.client.models.list();
|
|
316
337
|
return page.data.map((m) => ({
|
|
317
338
|
id: m.id,
|
|
318
339
|
name: m.id,
|
|
319
|
-
contextWindow: 0,
|
|
320
|
-
maxOutputTokens: 0,
|
|
321
340
|
inputPrice: 0,
|
|
322
341
|
outputPrice: 0,
|
|
323
342
|
supportsToolUse: true,
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACN,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,YAAY,CAAA;AACnB,OAAO,MAAM,MAAM,QAAQ,CAAA;AAS3B;;;;GAIG;AACH,MAAM,CAA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k via the official `openai` npm SDK. Chat Completions API with streaming + tool-use.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@types/node": "^22.19.17",
|
|
55
55
|
"typescript": "^5.5.0",
|
|
56
56
|
"vitest": "^3.2.6",
|
|
57
|
-
"@namzu/sdk": "^
|
|
57
|
+
"@namzu/sdk": "^28.0.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsc --build",
|
package/src/client.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
isProviderRequestError,
|
|
18
18
|
providerVendorError,
|
|
19
19
|
} from '@namzu/sdk'
|
|
20
|
+
import { attributionHeaders } from '@namzu/sdk'
|
|
20
21
|
import OpenAI from 'openai'
|
|
21
22
|
import type {
|
|
22
23
|
ChatCompletionContentPart,
|
|
@@ -169,6 +170,16 @@ export function toOpenAIMessages(
|
|
|
169
170
|
} as ChatCompletionContentPart)
|
|
170
171
|
continue
|
|
171
172
|
}
|
|
173
|
+
if (att.type === 'stored') {
|
|
174
|
+
// Unreachable through `query`, which resolves stored
|
|
175
|
+
// attachments before a driver sees them. REFUSED rather
|
|
176
|
+
// than skipped because the alternative is a user message
|
|
177
|
+
// that silently lost its image: the model answers about a
|
|
178
|
+
// picture it never saw, confidently, and nothing says why.
|
|
179
|
+
throw new Error(
|
|
180
|
+
`A stored attachment ("${att.ref}") reached the driver unresolved. Resolve it against the run's attachment store before sending.`,
|
|
181
|
+
)
|
|
182
|
+
}
|
|
172
183
|
parts.push({
|
|
173
184
|
type: 'image_url',
|
|
174
185
|
image_url: { url: `data:${att.mediaType};base64,${att.data}` },
|
|
@@ -253,7 +264,10 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
253
264
|
if (config.organization) clientOptions.organization = config.organization
|
|
254
265
|
if (config.project) clientOptions.project = config.project
|
|
255
266
|
if (config.timeout !== undefined) clientOptions.timeout = config.timeout
|
|
256
|
-
|
|
267
|
+
// Merged rather than replaced. Assigning `config.defaultHeaders`
|
|
268
|
+
// straight over would drop attribution for exactly the hosts that
|
|
269
|
+
// customise their transport.
|
|
270
|
+
clientOptions.defaultHeaders = { ...attributionHeaders(), ...(config.defaultHeaders ?? {}) }
|
|
257
271
|
|
|
258
272
|
this.client = new OpenAI(clientOptions)
|
|
259
273
|
this.defaultModel = config.model
|
|
@@ -362,13 +376,22 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
362
376
|
}
|
|
363
377
|
}
|
|
364
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Declared even though this driver's listing already fails correctly on a
|
|
381
|
+
* bad key. The check is a declared capability rather than something inferred
|
|
382
|
+
* from whether a menu happened to throw, so a driver that answers the
|
|
383
|
+
* question has to say so — otherwise it is reported unverifiable, which is
|
|
384
|
+
* the honest default and would be a regression here.
|
|
385
|
+
*/
|
|
386
|
+
async probeCredential(): Promise<void> {
|
|
387
|
+
await this.client.models.list()
|
|
388
|
+
}
|
|
389
|
+
|
|
365
390
|
async listModels(): Promise<ModelInfo[]> {
|
|
366
391
|
const page = await this.client.models.list()
|
|
367
392
|
return page.data.map((m) => ({
|
|
368
393
|
id: m.id,
|
|
369
394
|
name: m.id,
|
|
370
|
-
contextWindow: 0,
|
|
371
|
-
maxOutputTokens: 0,
|
|
372
395
|
inputPrice: 0,
|
|
373
396
|
outputPrice: 0,
|
|
374
397
|
supportsToolUse: true,
|
package/dist/strict-schema.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strict-schema.d.ts","sourceRoot":"","sources":["../src/strict-schema.ts"],"names":[],"mappings":""}
|
package/dist/strict-schema.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strict-schema.js","sourceRoot":"","sources":["../src/strict-schema.ts"],"names":[],"mappings":""}
|
package/src/strict-schema.ts
DELETED
|
File without changes
|