@jxburros/ai-nugget 0.4.1 → 0.6.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 +132 -385
- package/UPGRADING.md +158 -0
- package/dist/adapters/engines/anthropic.d.ts +7 -1
- package/dist/adapters/engines/anthropic.js +64 -37
- package/dist/adapters/engines/base.d.ts +29 -2
- package/dist/adapters/engines/base.js +52 -8
- package/dist/adapters/engines/google.d.ts +7 -1
- package/dist/adapters/engines/google.js +73 -29
- package/dist/adapters/engines/ollama.d.ts +2 -1
- package/dist/adapters/engines/ollama.js +51 -15
- package/dist/adapters/engines/openaiChat.d.ts +2 -1
- package/dist/adapters/engines/openaiChat.js +60 -30
- package/dist/adapters/profiles.d.ts +21 -1
- package/dist/adapters/profiles.js +12 -2
- package/dist/agent/loop.d.ts +43 -1
- package/dist/agent/loop.js +116 -12
- package/dist/cjs/adapters/engines/anthropic.js +308 -0
- package/dist/cjs/adapters/engines/base.js +147 -0
- package/dist/cjs/adapters/engines/google.js +284 -0
- package/dist/cjs/adapters/engines/ollama.js +199 -0
- package/dist/cjs/adapters/engines/openaiChat.js +261 -0
- package/dist/cjs/adapters/index.js +22 -0
- package/dist/cjs/adapters/profiles.js +125 -0
- package/dist/cjs/agent/index.js +18 -0
- package/dist/cjs/agent/loop.js +372 -0
- package/dist/cjs/agent/tools.js +51 -0
- package/dist/cjs/connect.js +27 -0
- package/dist/cjs/errors.js +110 -0
- package/dist/cjs/handler.js +561 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/json.js +121 -0
- package/dist/cjs/keys.js +81 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/policy.js +42 -0
- package/dist/cjs/redact.js +78 -0
- package/dist/cjs/tokens.js +22 -0
- package/dist/cjs/transport.js +172 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/util.js +112 -0
- package/dist/errors.js +25 -1
- package/dist/handler.d.ts +61 -1
- package/dist/handler.js +239 -59
- package/dist/redact.d.ts +18 -0
- package/dist/redact.js +29 -1
- package/dist/transport.d.ts +3 -1
- package/dist/transport.js +21 -1
- package/dist/types.d.ts +96 -2
- package/dist/util.d.ts +15 -0
- package/dist/util.js +46 -0
- package/nugget/VERSION.txt +2 -2
- package/nugget/dist/adapters/engines/anthropic.d.ts +14 -0
- package/nugget/dist/adapters/engines/anthropic.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/anthropic.js +305 -0
- package/nugget/dist/adapters/engines/anthropic.js.map +1 -0
- package/nugget/dist/adapters/engines/base.d.ts +50 -0
- package/nugget/dist/adapters/engines/base.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/base.js +137 -0
- package/nugget/dist/adapters/engines/base.js.map +1 -0
- package/nugget/dist/adapters/engines/google.d.ts +24 -0
- package/nugget/dist/adapters/engines/google.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/google.js +281 -0
- package/nugget/dist/adapters/engines/google.js.map +1 -0
- package/nugget/dist/adapters/engines/ollama.d.ts +11 -0
- package/nugget/dist/adapters/engines/ollama.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/ollama.js +196 -0
- package/nugget/dist/adapters/engines/ollama.js.map +1 -0
- package/nugget/dist/adapters/engines/openaiChat.d.ts +16 -0
- package/nugget/dist/adapters/engines/openaiChat.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/openaiChat.js +258 -0
- package/nugget/dist/adapters/engines/openaiChat.js.map +1 -0
- package/nugget/dist/adapters/index.d.ts +5 -0
- package/nugget/dist/adapters/index.d.ts.map +1 -0
- package/nugget/dist/adapters/index.js +17 -0
- package/nugget/dist/adapters/index.js.map +1 -0
- package/nugget/dist/adapters/profiles.d.ts +62 -0
- package/nugget/dist/adapters/profiles.d.ts.map +1 -0
- package/nugget/dist/adapters/profiles.js +121 -0
- package/nugget/dist/adapters/profiles.js.map +1 -0
- package/nugget/dist/agent/index.d.ts +3 -0
- package/nugget/dist/agent/index.d.ts.map +1 -0
- package/nugget/dist/agent/index.js +3 -0
- package/nugget/dist/agent/index.js.map +1 -0
- package/nugget/dist/agent/loop.d.ts +112 -0
- package/nugget/dist/agent/loop.d.ts.map +1 -0
- package/nugget/dist/agent/loop.js +370 -0
- package/nugget/dist/agent/loop.js.map +1 -0
- package/nugget/dist/agent/tools.d.ts +29 -0
- package/nugget/dist/agent/tools.d.ts.map +1 -0
- package/nugget/dist/agent/tools.js +48 -0
- package/nugget/dist/agent/tools.js.map +1 -0
- package/nugget/dist/cjs/adapters/engines/anthropic.js +308 -0
- package/nugget/dist/cjs/adapters/engines/base.js +147 -0
- package/nugget/dist/cjs/adapters/engines/google.js +284 -0
- package/nugget/dist/cjs/adapters/engines/ollama.js +199 -0
- package/nugget/dist/cjs/adapters/engines/openaiChat.js +261 -0
- package/nugget/dist/cjs/adapters/index.js +22 -0
- package/nugget/dist/cjs/adapters/profiles.js +125 -0
- package/nugget/dist/cjs/agent/index.js +18 -0
- package/nugget/dist/cjs/agent/loop.js +372 -0
- package/nugget/dist/cjs/agent/tools.js +51 -0
- package/nugget/dist/cjs/connect.js +27 -0
- package/nugget/dist/cjs/errors.js +110 -0
- package/nugget/dist/cjs/handler.js +561 -0
- package/nugget/dist/cjs/index.js +27 -0
- package/nugget/dist/cjs/json.js +121 -0
- package/nugget/dist/cjs/keys.js +81 -0
- package/nugget/dist/cjs/package.json +3 -0
- package/nugget/dist/cjs/policy.js +42 -0
- package/nugget/dist/cjs/redact.js +78 -0
- package/nugget/dist/cjs/tokens.js +22 -0
- package/nugget/dist/cjs/transport.js +172 -0
- package/nugget/dist/cjs/types.js +6 -0
- package/nugget/dist/cjs/util.js +112 -0
- package/nugget/dist/connect.d.ts +31 -0
- package/nugget/dist/connect.d.ts.map +1 -0
- package/nugget/dist/connect.js +25 -0
- package/nugget/dist/connect.js.map +1 -0
- package/nugget/dist/errors.d.ts +22 -0
- package/nugget/dist/errors.d.ts.map +1 -0
- package/nugget/dist/errors.js +104 -0
- package/nugget/dist/errors.js.map +1 -0
- package/nugget/dist/handler.d.ts +108 -0
- package/nugget/dist/handler.d.ts.map +1 -0
- package/nugget/dist/handler.js +557 -0
- package/nugget/dist/handler.js.map +1 -0
- package/nugget/dist/index.d.ts +12 -0
- package/nugget/dist/index.d.ts.map +1 -0
- package/nugget/dist/index.js +12 -0
- package/nugget/dist/index.js.map +1 -0
- package/nugget/dist/json.d.ts +7 -0
- package/nugget/dist/json.d.ts.map +1 -0
- package/nugget/dist/json.js +114 -0
- package/nugget/dist/json.js.map +1 -0
- package/nugget/dist/keys.d.ts +7 -0
- package/nugget/dist/keys.d.ts.map +1 -0
- package/nugget/dist/keys.js +75 -0
- package/nugget/dist/keys.js.map +1 -0
- package/nugget/dist/policy.d.ts +6 -0
- package/nugget/dist/policy.d.ts.map +1 -0
- package/nugget/dist/policy.js +37 -0
- package/nugget/dist/policy.js.map +1 -0
- package/nugget/dist/redact.d.ts +26 -0
- package/nugget/dist/redact.d.ts.map +1 -0
- package/nugget/dist/redact.js +74 -0
- package/nugget/dist/redact.js.map +1 -0
- package/nugget/dist/tokens.d.ts +5 -0
- package/nugget/dist/tokens.d.ts.map +1 -0
- package/nugget/dist/tokens.js +18 -0
- package/nugget/dist/tokens.js.map +1 -0
- package/nugget/dist/transport.d.ts +30 -0
- package/nugget/dist/transport.d.ts.map +1 -0
- package/nugget/dist/transport.js +165 -0
- package/nugget/dist/transport.js.map +1 -0
- package/nugget/dist/types.d.ts +285 -0
- package/nugget/dist/types.d.ts.map +1 -0
- package/nugget/dist/types.js +4 -0
- package/nugget/dist/types.js.map +1 -0
- package/nugget/dist/util.d.ts +24 -0
- package/nugget/dist/util.d.ts.map +1 -0
- package/nugget/dist/util.js +101 -0
- package/nugget/dist/util.js.map +1 -0
- package/nugget/src/adapters/engines/anthropic.ts +62 -37
- package/nugget/src/adapters/engines/base.ts +50 -7
- package/nugget/src/adapters/engines/google.ts +72 -29
- package/nugget/src/adapters/engines/ollama.ts +51 -17
- package/nugget/src/adapters/engines/openaiChat.ts +61 -32
- package/nugget/src/adapters/profiles.ts +53 -3
- package/nugget/src/agent/loop.ts +153 -13
- package/nugget/src/errors.ts +25 -1
- package/nugget/src/handler.ts +279 -57
- package/nugget/src/redact.ts +32 -1
- package/nugget/src/transport.ts +20 -1
- package/nugget/src/types.ts +96 -1
- package/nugget/src/util.ts +50 -0
- package/package.json +18 -5
package/README.md
CHANGED
|
@@ -1,432 +1,179 @@
|
|
|
1
1
|
# AI Nugget
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
**Version 0.6.0** · [What's changed since 0.5.0](#whats-changed-since-050) · [Changelog](./CHANGELOG.md) · [Upgrading](./UPGRADING.md)
|
|
4
|
+
|
|
5
|
+
A small, zero-dependency, isomorphic TypeScript nugget for talking to AI model
|
|
6
|
+
providers through one pipeline:
|
|
5
7
|
|
|
6
8
|
```
|
|
7
9
|
policy → key resolution → beforeCall hook → concurrency/retry → provider adapter → redacted telemetry
|
|
8
10
|
```
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
only `fetch`, `ReadableStream`,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
19 provider profiles over 4 protocol engines. Runs identically in Node, the
|
|
13
|
+
browser main thread, and Web Workers using only `fetch`, `ReadableStream`,
|
|
14
|
+
`AbortController`, and `TextDecoder`. MIT licensed.
|
|
15
|
+
|
|
16
|
+
It is intentionally **not** a router, prompt library, memory system, or secrets
|
|
17
|
+
vault: apps choose models, own prompts, store secrets, and decide policy.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
build/adoption plan, and dev handoff are archived under `docs/archive/`.
|
|
21
|
+
Requires Node `^20.19.0` or `>=22.12.0` ([why](./docs/distribution.md#requirements)).
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
```bash
|
|
24
|
+
npm install @jxburros/ai-nugget
|
|
25
|
+
```
|
|
20
26
|
|
|
21
27
|
```ts
|
|
22
28
|
import { AIHandler, envKeySource } from '@jxburros/ai-nugget';
|
|
23
29
|
|
|
24
30
|
const handler = new AIHandler({ keySource: envKeySource() });
|
|
25
31
|
|
|
32
|
+
const conn = { id: 'main', provider: 'openai', keyRef: { kind: 'env', name: 'OPENAI_API_KEY' } };
|
|
33
|
+
const req = { model: 'gpt-4o-mini', messages: [{ role: 'user', content: 'Hello!' }] };
|
|
34
|
+
|
|
26
35
|
// Non-streaming
|
|
27
|
-
const result = await handler.chat(
|
|
28
|
-
{ id: 'main', provider: 'openai', keyRef: { kind: 'env', name: 'OPENAI_API_KEY' } },
|
|
29
|
-
{ model: 'gpt-4o-mini', messages: [{ role: 'user', content: 'Hello!' }] },
|
|
30
|
-
);
|
|
36
|
+
const result = await handler.chat(conn, req);
|
|
31
37
|
console.log(result.text, result.usage, result.finishReason);
|
|
32
38
|
|
|
33
|
-
// Streaming (
|
|
39
|
+
// Streaming (Node route handlers, React, Web Workers — same code)
|
|
34
40
|
for await (const event of handler.stream(conn, req)) {
|
|
35
41
|
if (event.type === 'delta') process.stdout.write(event.text);
|
|
36
42
|
if (event.type === 'done') console.log('\n', event.result.usage);
|
|
43
|
+
if (event.type === 'error') console.error(event.error.kind, event.error.message);
|
|
37
44
|
}
|
|
38
45
|
```
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
folder (see below).
|
|
42
|
-
|
|
43
|
-
## Providers
|
|
44
|
-
|
|
45
|
-
Four **protocol engines** own the wire formats; a data-driven **profile table**
|
|
46
|
-
turns each named provider into defaults + quirks on top of an engine, so adding
|
|
47
|
-
an OpenAI-compatible provider is a table row, not another copy of the SSE loop.
|
|
48
|
-
|
|
49
|
-
| Engine | Providers | Streaming | Tools | JSON mode |
|
|
50
|
-
|---|---|---|---|---|
|
|
51
|
-
| `openaiChat` | `openai`, `azure-openai`, `openrouter`, `groq`, `deepseek`, `mistral`, `together`, `fireworks`, `lmstudio`, `llamacpp`, `vllm`, `openai-compat` | SSE + `stream_options.include_usage` | `tools`/`tool_calls` deltas | `response_format` (`json_schema` where supported, otherwise `json_object`) |
|
|
52
|
-
| `anthropic` | `anthropic` | SSE (`content_block_delta`) | `tool_use` blocks (streamed) | forced-tool JSON mode |
|
|
53
|
-
| `google` | `google` | SSE (`streamGenerateContent`) | `functionDeclarations` | `responseMimeType` |
|
|
54
|
-
| `ollama` | `ollama` | NDJSON | native `tools` | `format: json` |
|
|
55
|
-
|
|
56
|
-
`adapterFor(provider)` lives once, in `adapters/index.ts`. Unknown provider keys
|
|
57
|
-
with a `baseUrl` resolve to the `openai-compat` escape hatch. **Grok/xAI is not
|
|
58
|
-
blocked and is never officially integrated** — point `openai-compat` at any
|
|
59
|
-
endpoint if you must; that is your configuration, not a supported profile.
|
|
60
|
-
|
|
61
|
-
**Wire URL for `openai-compat` and the other local runtimes.** `openai-compat`,
|
|
62
|
-
`lmstudio`, `llamacpp`, and `vllm` have no `urlTemplate` in the profile table,
|
|
63
|
-
so the `openaiChat` engine falls back to `POST {baseUrl}/chat/completions`
|
|
64
|
-
(no `/v1` prefix — include it in `baseUrl` yourself if your server needs it,
|
|
65
|
-
e.g. `http://localhost:8080/v1`). This matters most when standing up a local
|
|
66
|
-
mock or test server: it has to listen on that exact path.
|
|
67
|
-
|
|
68
|
-
Model identity is always `(source, model)` — `modelRef(source, model)` gives the
|
|
69
|
-
canonical `provider/model` key so the same weights served by different hosts stay
|
|
70
|
-
distinct and comparable.
|
|
71
|
-
|
|
72
|
-
### Provider capabilities
|
|
73
|
-
|
|
74
|
-
Beyond wire-format `quirks` (auth, URL templates, whether a stream reports
|
|
75
|
-
usage), each profile also carries `capabilities` — the higher-level questions
|
|
76
|
-
apps need answered before they pick behavior:
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
interface ProviderCapabilities {
|
|
80
|
-
nativeTools: boolean; // reliable native tool/function-calling for this
|
|
81
|
-
// provider's protocol (not just model-dependent)
|
|
82
|
-
jsonMode: boolean; // a provider-enforced structured-output mode exists
|
|
83
|
-
local: boolean; // runs on localhost / user-controlled infra
|
|
84
|
-
embeddable: boolean; // meant to run as a local sidecar, not a hosted service
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Hosted cloud providers (`openai`, `azure-openai`, `openrouter`, `groq`,
|
|
89
|
-
`deepseek`, `mistral`, `together`, `fireworks`, `anthropic`, `google`) ship
|
|
90
|
-
`{ nativeTools: true, jsonMode: true, local: false, embeddable: false }`. Local
|
|
91
|
-
runtimes (`lmstudio`, `llamacpp`, `vllm`, and the `openai-compat` escape hatch)
|
|
92
|
-
ship the conservative `{ nativeTools: false, jsonMode: false, local: true,
|
|
93
|
-
embeddable: true }`, since native tool support there is model-dependent, not
|
|
94
|
-
protocol-guaranteed. `ollama` is the one exception with `jsonMode: true` —
|
|
95
|
-
its `format: 'json'` is engine-enforced regardless of which model is loaded.
|
|
96
|
-
These are per-provider defaults, not per-model guarantees: a caller that knows
|
|
97
|
-
its specific loaded model better should configure behavior explicitly (e.g.
|
|
98
|
-
`toolMode: 'native'`) rather than rely on the default.
|
|
99
|
-
|
|
100
|
-
Access via `profileFor(provider, baseUrl).capabilities`.
|
|
101
|
-
|
|
102
|
-
**These are provider-level defaults, not per-model guarantees.** A specific
|
|
103
|
-
model behind a "hosted" provider can still lack reliable native tool-calling
|
|
104
|
-
(and a specific local model behind a "local" provider can have it) — this
|
|
105
|
-
matters most for OpenRouter, Ollama, LM Studio, vLLM, and any
|
|
106
|
-
`openai-compat` endpoint, where the model actually loaded is opaque to the
|
|
107
|
-
profile table. A caller that knows its model better should pass an explicit
|
|
108
|
-
`toolMode` (agent layer) rather than rely on the capability default.
|
|
109
|
-
|
|
110
|
-
**`listModels()` is optional per adapter — two engines never return anything.**
|
|
111
|
-
`ProviderAdapter.listModels` is `?`-optional, and `AIHandler.listModels()`
|
|
112
|
-
falls back to `[]` when an adapter doesn't implement it. Concretely: the
|
|
113
|
-
`openaiChat` and `ollama` engines implement it (`GET /models` /
|
|
114
|
-
`GET /api/tags`); the `anthropic` and `google` engines currently don't, so
|
|
115
|
-
`handler.listModels()` for those providers always resolves to `[]`, not an
|
|
116
|
-
error. This is easy to miss because `capabilities` doesn't surface it — an
|
|
117
|
-
app building a model picker on top of `listModels()` should treat an empty
|
|
118
|
-
result as "this provider doesn't support discovery," not "this provider has
|
|
119
|
-
no models," and have a fallback (e.g. an app-configured default model per
|
|
120
|
-
connection) ready for `anthropic`/`google` rather than showing an empty list.
|
|
121
|
-
|
|
122
|
-
### Letting an app's users pick a model (best practice)
|
|
123
|
-
|
|
124
|
-
The nugget deliberately has no concept of "the app's currently selected
|
|
125
|
-
model" — that's app policy, same as governance (see Non-goals). The pattern
|
|
126
|
-
that has worked well for apps building a model-picker UI on top of the
|
|
127
|
-
AI Nugget handler:
|
|
128
|
-
|
|
129
|
-
1. **Keep `provider`/`baseUrl` on a server-side allowlist; never take them
|
|
130
|
-
from client input.** A `Connection`'s `provider`/`baseUrl` decide where
|
|
131
|
-
the server's resolved API key gets sent (via `KeySource` → `applyAuth`);
|
|
132
|
-
letting a client control either directly is effectively letting it
|
|
133
|
-
redirect a real credential to an arbitrary endpoint (SSRF plus key
|
|
134
|
-
exposure). Define your app's available connections server-side (e.g. a
|
|
135
|
-
small config list, each with its own `KeyRef`), and only let the client
|
|
136
|
-
choose a `connectionId` out of that list.
|
|
137
|
-
2. **`model` is fine as ordinary client input.** Unlike `provider`/`baseUrl`,
|
|
138
|
-
a bad or unexpected `model` string just comes back as a normal provider
|
|
139
|
-
error (unknown model) from `chat()`/`stream()` — there's no equivalent
|
|
140
|
-
security concern, so there's no need to allowlist it server-side beyond
|
|
141
|
-
what the provider itself enforces.
|
|
142
|
-
3. **Use `handler.listModels(connection)` to populate the picker live**, and
|
|
143
|
-
fall back to an app-configured default model for connections whose engine
|
|
144
|
-
doesn't implement discovery (see above).
|
|
145
|
-
|
|
146
|
-
See `examples/model-picker.mjs` for a minimal runnable reference implementing
|
|
147
|
-
this pattern.
|
|
148
|
-
|
|
149
|
-
## Recipes
|
|
150
|
-
|
|
151
|
-
Small server apps built directly on `AIHandler` (see
|
|
152
|
-
`examples/npm-mini-apps/`) tend to hit the same three points of friction:
|
|
153
|
-
resolving connection config, turning a JSON-mode reply into a validated app
|
|
154
|
-
object, and mapping a failure into an HTTP response. None of this is policy —
|
|
155
|
-
it's just the boilerplate every consumer re-derives — so here's the
|
|
156
|
-
canonical shape for each.
|
|
157
|
-
|
|
158
|
-
### Env-based connection setup
|
|
159
|
-
|
|
160
|
-
`envConnection()` resolves a `Connection` plus a default `model` from
|
|
161
|
-
app-owned env vars (`AI_PROVIDER`, `AI_MODEL`, `AI_KEY_ENV`, `AI_BASE_URL` by
|
|
162
|
-
default):
|
|
47
|
+
No key? Point at a local model instead — same code, no `keyRef`:
|
|
163
48
|
|
|
164
49
|
```ts
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const handler = new AIHandler({ keySource: envKeySource() });
|
|
168
|
-
const { connection, model } = envConnection({ id: 'my-app', defaultProvider: 'openai', defaultModel: 'gpt-4o-mini' });
|
|
169
|
-
|
|
170
|
-
const result = await handler.chat(connection, { model, messages: [{ role: 'user', content: 'Hello!' }] });
|
|
50
|
+
const conn = { id: 'local', provider: 'ollama', baseUrl: 'http://127.0.0.1:11434' };
|
|
171
51
|
```
|
|
172
52
|
|
|
173
|
-
|
|
174
|
-
from client input this way either, same as the manual pattern it replaces.
|
|
175
|
-
Pass `env`, `providerVar`/`modelVar`/`keyEnvVar`/`baseUrlVar`, or
|
|
176
|
-
`defaultProvider`/`defaultModel`/`defaultKeyEnv` to override the var names or
|
|
177
|
-
fallbacks an app already uses.
|
|
178
|
-
|
|
179
|
-
### JSON output + validation
|
|
180
|
-
|
|
181
|
-
Ask for JSON in the prompt (and set `responseFormat: { type: 'json' }` for
|
|
182
|
-
providers with `capabilities.jsonMode`), then run the raw text through
|
|
183
|
-
`extractJsonWithSchema` with a small parse function built from the
|
|
184
|
-
`require*` guards in `json.ts` — don't hand-roll a `/\{[\s\S]*\}/` regex plus
|
|
185
|
-
`JSON.parse`, which silently accepts the first brace-looking substring and
|
|
186
|
-
gives no useful error on a malformed or schema-incomplete reply:
|
|
53
|
+
CommonJS works too: `const { AIHandler } = require('@jxburros/ai-nugget')`.
|
|
187
54
|
|
|
188
|
-
|
|
189
|
-
|
|
55
|
+
For a running server, copy a starter from
|
|
56
|
+
[`examples/integrations/`](./examples/integrations/) — Express, Next.js,
|
|
57
|
+
Cloudflare Workers, or local Ollama.
|
|
190
58
|
|
|
191
|
-
|
|
192
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('Expected a JSON object');
|
|
193
|
-
const record = raw as Record<string, unknown>;
|
|
194
|
-
return { headline: requireString(record, 'headline'), minutes: requireNumber(record, 'minutes') };
|
|
195
|
-
}
|
|
59
|
+
## Two things to configure before production
|
|
196
60
|
|
|
197
|
-
|
|
198
|
-
```
|
|
61
|
+
Both are seams the library leaves open on purpose, and both are easy to miss:
|
|
199
62
|
|
|
200
|
-
`
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
validation doesn't need its own error path. `require*` covers scalars and
|
|
207
|
-
string arrays only — validate array length, numeric ranges, or nested shapes
|
|
208
|
-
yourself, same as `parseSprint` above; this is deliberately not a full
|
|
209
|
-
schema validator (see Non-goals).
|
|
210
|
-
|
|
211
|
-
### Error handling matrix
|
|
212
|
-
|
|
213
|
-
Every failure that reaches your `catch` around `handler.chat()`/`stream()` —
|
|
214
|
-
including a JSON-validation failure from `extractJsonWithSchema` — is (or is
|
|
215
|
-
normalized to) an `AIError` with a `kind`. Map `kind` to an HTTP status and a
|
|
216
|
-
user-facing message once, log the raw `error.message` server-side, and never
|
|
217
|
-
forward it to the client:
|
|
218
|
-
|
|
219
|
-
| `kind` | Suggested status | Example user-facing message |
|
|
220
|
-
|---|---|---|
|
|
221
|
-
| `invalid_request` | 400 | "That request was invalid." |
|
|
222
|
-
| `context_length` | 413 | "Your input is too long. Please shorten it and try again." |
|
|
223
|
-
| `auth` | 502 | "The AI service is not configured correctly." |
|
|
224
|
-
| `key_unavailable` | 500 | "The AI service is not configured correctly." |
|
|
225
|
-
| `policy_blocked` | 403 | "This request was blocked by policy." |
|
|
226
|
-
| `rate_limit` | 429 | "The AI service is busy. Please try again shortly." |
|
|
227
|
-
| `timeout` | 504 | "The request took too long. Please try again." |
|
|
228
|
-
| `canceled` | 499 | "The request was canceled." |
|
|
229
|
-
| `invalid_response` | 502 | "The AI response wasn't in the expected format. Please try again." |
|
|
230
|
-
| `network` / `server` | 502 | "The AI service is temporarily unavailable." |
|
|
231
|
-
| `tool_error` | 500 | "Something went wrong running a tool." |
|
|
232
|
-
| `budget_exceeded` | 429 | "This request used too many steps/tokens. Please try again." |
|
|
233
|
-
|
|
234
|
-
`auth` and `key_unavailable` map to 5xx, not 401/403, because it's the
|
|
235
|
-
*server's* credential that's wrong, not the caller's — the distinction
|
|
236
|
-
matters for who should act on the error. `examples/npm-mini-apps/*/ai-error-map.mjs`
|
|
237
|
-
is a copyable implementation of this table.
|
|
238
|
-
|
|
239
|
-
## What's implemented
|
|
240
|
-
|
|
241
|
-
- **Core:** message-based contracts (`types.ts`), typed `AIError` + `classify()`,
|
|
242
|
-
timeout/abort merging and SSE/NDJSON readers (`transport.ts`), defensive JSON
|
|
243
|
-
extraction with array support + schema guards (`json.ts`), token estimation with
|
|
244
|
-
an explicit `estimated` flag (`tokens.ts`).
|
|
245
|
-
- **Adapters:** all four engines with streaming, native tool-calling, JSON modes,
|
|
246
|
-
`finishReason` mapping, buffered-`stream:true` fallback, first-token latency,
|
|
247
|
-
and usage normalization; the full v1 provider profile table. The
|
|
248
|
-
OpenAI-compatible engine only sends `stream_options: { include_usage: true }`
|
|
249
|
-
when the profile's `supportsUsageInStream` quirk confirms the server expects
|
|
250
|
-
it — local servers (llama.cpp, LM Studio, vLLM) that don't have the quirk set
|
|
251
|
-
never receive the option. The OpenAI and Azure OpenAI profiles send
|
|
252
|
-
`max_completion_tokens` for `maxTokens`; local/OpenAI-compatible profiles keep
|
|
253
|
-
`max_tokens` for compatibility. Google receives `responseSchema` for JSON mode
|
|
254
|
-
only when native tools are absent, avoiding Gemini's JSON-with-tools rejection.
|
|
255
|
-
- **Pipeline (`AIHandler`):** policy → keys → `beforeCall` → concurrency/min-interval
|
|
256
|
-
→ jittered retry (honoring `Retry-After`) → redacted `CallRecord` telemetry →
|
|
257
|
-
`afterCall`, with `chat`, `stream`, `listModels`, `testConnection`. Every call —
|
|
258
|
-
success, failure, or consumer-abandoned stream — produces one redacted telemetry
|
|
259
|
-
record. Retries stop once user-visible output has been emitted, and telemetry
|
|
260
|
-
or `afterCall` failures never re-execute an already-successful provider call.
|
|
261
|
-
`listModels()` and `testConnection()` use explicit operation IDs
|
|
262
|
-
(`__listModels__`, `__testConnection__`) so policy and telemetry can see those
|
|
263
|
-
key-bearing probes too.
|
|
264
|
-
- **Seams:** `KeySource` (`env`/`literal`/`memory`/chain + ref parsing),
|
|
265
|
-
`Redactor` (default secret patterns + session-resolved key redaction),
|
|
266
|
-
neutral `GovernancePolicy` (`blocklistPolicy`/`allowlistPolicy`/`composePolicies`).
|
|
267
|
-
`allowlistPolicy` fails closed for providers omitted from the configured map;
|
|
268
|
-
use `'*'` in a provider's prefix list to allow non-chat operation IDs.
|
|
269
|
-
The default redactor covers common provider token formats and generic bearer
|
|
270
|
-
tokens, with session-resolved keys always added exactly. `envConnection()`
|
|
271
|
-
(`connect.ts`) resolves a `Connection` + default `model` from app-owned env
|
|
272
|
-
vars — config-resolution convenience only, not a new seam or a policy
|
|
273
|
-
default (see Recipes above).
|
|
274
|
-
- **Agent layer (`@jxburros/ai-nugget/agent`):** `defineTool` + light JSON-schema
|
|
275
|
-
arg validation (object-ness, `required`, top-level `properties[key].type` —
|
|
276
|
-
not full JSON Schema: no `enum`, nested schemas, `oneOf`, bounds, `pattern`,
|
|
277
|
-
array `items`, or `additionalProperties`; validate again inside
|
|
278
|
-
`tool.execute` if you need stricter guarantees), `runAgent()` model↔tool loop
|
|
279
|
-
over the full handler pipeline,
|
|
280
|
-
streamed `AgentEvent`s, budgets (`maxSteps`/`maxTokens`/`deadlineMs`) with honest
|
|
281
|
-
`stopReason`s, `ApprovalGate` for side-effecting tools (deny is fed back to the
|
|
282
|
-
model as data), and `native` / `promptJson` / `auto` tool modes. `auto` (the
|
|
283
|
-
default) resolves per call from the connection's provider capability profile
|
|
284
|
-
(`profileFor(provider).capabilities.nativeTools`) — hosted providers get
|
|
285
|
-
`native`, local runtimes and the `openai-compat` escape hatch get
|
|
286
|
-
`promptJson`, and an explicit `toolMode` always overrides the default.
|
|
287
|
-
`promptJson` mode accepts a single `{"tool","input"}` directive or a batched
|
|
288
|
-
`{"tools":[…]}` (a bare array works too), so the model can request several
|
|
289
|
-
tools in one turn just like native tool-calling. Prompt-JSON history is
|
|
290
|
-
serialized as plain text turns, not provider-native tool-call wire format.
|
|
63
|
+
1. **Never take `provider` or `baseUrl` from client input.** They decide where
|
|
64
|
+
your resolved API key gets sent. Keep connections on a server-side allowlist
|
|
65
|
+
and let clients pick an id. → [security.md](./docs/security.md#ssrf-caller-controlled-baseurl)
|
|
66
|
+
2. **Configure a `GovernancePolicy`.** With none, every provider and model is
|
|
67
|
+
allowed; the handler logs a startup notice so this is visible at runtime.
|
|
68
|
+
→ [security.md](./docs/security.md#governance-is-neutral-by-default)
|
|
291
69
|
|
|
292
70
|
```ts
|
|
293
|
-
|
|
71
|
+
new AIHandler({
|
|
72
|
+
keySource: envKeySource(),
|
|
73
|
+
policy: allowlistPolicy({ openai: ['gpt-4o', 'gpt-4o-mini'], ollama: ['*'] }),
|
|
74
|
+
});
|
|
294
75
|
```
|
|
295
76
|
|
|
296
|
-
##
|
|
77
|
+
## Documentation
|
|
78
|
+
|
|
79
|
+
| Doc | Covers |
|
|
80
|
+
|---|---|
|
|
81
|
+
| [providers.md](./docs/providers.md) | The 19 profiles, which are **live-verified vs mock-verified vs config-only**, capabilities, JSON-mode/tools limits, `openai-compat`, model discovery |
|
|
82
|
+
| [reliability.md](./docs/reliability.md) | `timeoutMs` vs `idleTimeoutMs`, why retries stop after output is emitted, double-billing and idempotency, why limits are per-instance |
|
|
83
|
+
| [security.md](./docs/security.md) | Key handling, redaction coverage, SSRF, opt-in injection defenses, the secure-tool recipe |
|
|
84
|
+
| [agent-loop.md](./docs/agent-loop.md) | `runAgent`, tool modes, budgets and what happens mid-step, the approval gate |
|
|
85
|
+
| [recipes.md](./docs/recipes.md) | Env-based connections, JSON output + validation, the error-handling matrix, telemetry |
|
|
86
|
+
| [integrations.md](./docs/integrations.md) | The host matrix CI runs (Node, Next.js, Workers, local runtime, packaging) |
|
|
87
|
+
| [distribution.md](./docs/distribution.md) | Commands, live smoke tests, CI workflows, npm/GitHub Packages/vendored `nugget/`, bundler notes |
|
|
88
|
+
| [design.md](./design.md) | The full contract |
|
|
89
|
+
| [state-of-the-nugget.md](./docs/state-of-the-nugget.md) | Current health snapshot: architecture, safety and reliability posture, coverage gaps, what's next |
|
|
90
|
+
| [UPGRADING.md](./UPGRADING.md) | Version-by-version changes |
|
|
91
|
+
|
|
92
|
+
## What's in the box
|
|
93
|
+
|
|
94
|
+
- **Core** — message-based contracts (`types.ts`), typed `AIError` + `classify()`
|
|
95
|
+
with wire-boundary redaction, timeout/idle-timeout/abort merging and SSE/NDJSON
|
|
96
|
+
readers (`transport.ts`), defensive JSON extraction with schema guards
|
|
97
|
+
(`json.ts`), token estimation with an explicit `estimated` flag.
|
|
98
|
+
- **Adapters** — four engines (`openaiChat`, `anthropic`, `google`, `ollama`)
|
|
99
|
+
with streaming, native tool-calling, JSON modes, `finishReason` mapping,
|
|
100
|
+
buffered-`stream:true` fallback, reasoning-token channel, first-token latency,
|
|
101
|
+
usage normalization, and truncation detection (`stream_anomaly`). Provider
|
|
102
|
+
differences live in a data-driven profile table, not in copies of the SSE loop.
|
|
103
|
+
- **Pipeline (`AIHandler`)** — `chat`, `stream`, `chatParsed`, `embed`,
|
|
104
|
+
`listModels`, `testConnection`, `prewarm`. Every call — success, failure, or
|
|
105
|
+
abandoned stream — produces exactly one redacted `CallRecord`. Retries are
|
|
106
|
+
jittered and honor `Retry-After`; telemetry or `afterCall` failures never
|
|
107
|
+
re-run a completed provider call.
|
|
108
|
+
- **Seams** — `KeySource` (env/literal/memory/chain + ref parsing), `Redactor`,
|
|
109
|
+
neutral `GovernancePolicy` (`blocklistPolicy`/`allowlistPolicy`/`composePolicies`),
|
|
110
|
+
`TelemetrySink`, and an optional `pricing` hook. `providerOptions` passes
|
|
111
|
+
provider-native fields through without waiting for a library release.
|
|
112
|
+
- **Agent layer** (`@jxburros/ai-nugget/agent`) — `defineTool`, `runAgent()`
|
|
113
|
+
model↔tool loop over the full pipeline, streamed `AgentEvent`s, budgets with
|
|
114
|
+
honest `stopReason`s, an `ApprovalGate` for side-effecting tools, and
|
|
115
|
+
`native`/`promptJson`/`auto` tool modes.
|
|
116
|
+
|
|
117
|
+
## What's changed since 0.5.0
|
|
118
|
+
|
|
119
|
+
**0.6.0 is backward-compatible** — every change below is additive. The one thing
|
|
120
|
+
to check is the new `not_found` error kind if you `switch` exhaustively over
|
|
121
|
+
`AIErrorKind`; see [UPGRADING.md](./UPGRADING.md#05x--060). Full detail lives in
|
|
122
|
+
the [changelog](./CHANGELOG.md).
|
|
123
|
+
|
|
124
|
+
- **Security & correctness** — `beforeCall` hooks now receive a scrubbed
|
|
125
|
+
connection (masked literal `keyRef` and auth headers, safe to log);
|
|
126
|
+
`classify()` redacts provider response excerpts at the wire boundary so an
|
|
127
|
+
`AIError` can never carry an unredacted secret; label-anchored redaction
|
|
128
|
+
covers unprefixed secrets (Azure `api-key`, AWS keys, `client_secret`, session
|
|
129
|
+
tokens); a new `not_found` error kind distinguishes 404/410 from a malformed
|
|
130
|
+
request; and Ollama tool-call arguments coerce through the shared parser so a
|
|
131
|
+
llama.cpp-style backend sending JSON-as-string no longer fails.
|
|
132
|
+
- **Observability** — `stream_anomaly` detection now fires on all four engines
|
|
133
|
+
(not just `openaiChat`); Google and Anthropic emit `json_mode_downgraded` when
|
|
134
|
+
a JSON mode is dropped for tools; `AIHandler` logs a startup notice when no
|
|
135
|
+
`GovernancePolicy` is configured; and OpenAI requests carry a stable
|
|
136
|
+
`Idempotency-Key` across retries to mitigate double-billing.
|
|
137
|
+
- **Providers & types** — `openai-compat` is now `keyOptional`, matching the
|
|
138
|
+
other local-runtime profiles, so keyless servers (including JX Runtime) work
|
|
139
|
+
without a `keyRef`; `Connection.provider` is typed `KnownProvider | (string &
|
|
140
|
+
{})` for autocomplete and typo-catching with the escape hatch still open.
|
|
141
|
+
- **Docs & examples** — `README.md` was trimmed to a front door with reference
|
|
142
|
+
material moved under [`docs/`](./docs/) (`providers`, `reliability`,
|
|
143
|
+
`security`, `agent-loop`, `recipes`, `integrations`, `distribution`), and
|
|
144
|
+
[`examples/integrations/`](./examples/integrations/) added five CI-verified
|
|
145
|
+
starters (Express, Next.js, Cloudflare Workers, local Ollama, ESM/CJS
|
|
146
|
+
packaging check).
|
|
147
|
+
|
|
148
|
+
## Contributing
|
|
149
|
+
|
|
150
|
+
`AGENTS.md` is the always-on baseline — invariants, required reading, and the
|
|
151
|
+
[admission test](./AGENTS.md#feature-admission-test) a new feature has to pass.
|
|
152
|
+
`.claude/skills/` holds task-specific guides (`use-ai-nugget`,
|
|
153
|
+
`build-agent-loop`, `add-provider`, `develop-nugget`) that Claude Code loads
|
|
154
|
+
automatically and any agent or human can read as plain Markdown.
|
|
297
155
|
|
|
298
156
|
```bash
|
|
299
|
-
npm
|
|
300
|
-
npm test
|
|
301
|
-
|
|
302
|
-
npm run test:browser # same suite in headless Chromium (proves isomorphism)
|
|
303
|
-
npm run build # tsc → dist/ (also the typecheck)
|
|
304
|
-
npm run build:nugget # writes a vendorable nugget/ stamped with version + content hash
|
|
157
|
+
npm test # Node contract suite
|
|
158
|
+
npm run test:browser # same suite in headless Chromium (isomorphism)
|
|
159
|
+
npm run build && npm run build:nugget
|
|
305
160
|
```
|
|
306
161
|
|
|
307
|
-
|
|
308
|
-
`.nvmrc`) — the toolchain's build step (`vitest` → `rolldown`) needs a native
|
|
309
|
-
binding unavailable on older Node 20 patch releases.
|
|
310
|
-
|
|
311
|
-
### Live smoke tests (optional, env-gated)
|
|
312
|
-
|
|
313
|
-
`tests/live-smoke.test.ts` exercises the real wire path against a live provider.
|
|
314
|
-
It is **skipped unless `AI_HANDLER_LIVE=1`**, so it never runs in the default
|
|
315
|
-
suite or in CI:
|
|
316
|
-
|
|
317
|
-
```bash
|
|
318
|
-
# Local Ollama (defaults: provider=ollama, model=llama3.2)
|
|
319
|
-
AI_HANDLER_LIVE=1 npm run test:live
|
|
320
|
-
|
|
321
|
-
# A cloud provider, with JSON-mode and agent tool-loop checks enabled
|
|
322
|
-
AI_HANDLER_LIVE=1 AI_HANDLER_LIVE_PROVIDER=openai AI_HANDLER_LIVE_MODEL=gpt-4o-mini \
|
|
323
|
-
AI_HANDLER_LIVE_KEY_ENV=OPENAI_API_KEY AI_HANDLER_LIVE_JSON=1 AI_HANDLER_LIVE_TOOLS=1 \
|
|
324
|
-
npm run test:live
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
Config env vars: `AI_HANDLER_LIVE_PROVIDER`, `AI_HANDLER_LIVE_MODEL`,
|
|
328
|
-
`AI_HANDLER_LIVE_BASE_URL`, `AI_HANDLER_LIVE_KEY` (literal) or
|
|
329
|
-
`AI_HANDLER_LIVE_KEY_ENV` (key from an env var), `AI_HANDLER_LIVE_JSON`,
|
|
330
|
-
`AI_HANDLER_LIVE_TOOLS`.
|
|
331
|
-
|
|
332
|
-
**Live provider matrix (`.github/workflows/live-matrix.yml`).** The default
|
|
333
|
-
CI workflow only exercises mocked fetch responses, so subtle live-wire
|
|
334
|
-
behavior differences (OpenAI, Anthropic, Google, OpenRouter, and local
|
|
335
|
-
runtimes each drift independently) can't surface there. `live-matrix.yml`
|
|
336
|
-
runs the same `tests/live-smoke.test.ts` suite against real endpoints —
|
|
337
|
-
manually (`workflow_dispatch`) or on a weekly schedule — never on push/PR, so
|
|
338
|
-
it can't block or flake a normal CI run. Each matrix entry reads its API key
|
|
339
|
-
from a same-named repository secret (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`,
|
|
340
|
-
`GOOGLE_API_KEY`, `OPENROUTER_API_KEY`) and skips itself with a notice if that
|
|
341
|
-
secret isn't configured, so you only need to add secrets for the providers
|
|
342
|
-
you actually use. Local runtimes (Ollama, llama.cpp, LM Studio, vLLM) aren't
|
|
343
|
-
in the matrix since they need a reachable server; smoke-test those manually
|
|
344
|
-
with the local `test:live` invocation above.
|
|
345
|
-
|
|
346
|
-
## Distribution
|
|
347
|
-
|
|
348
|
-
Three supported paths, in order of preference:
|
|
349
|
-
|
|
350
|
-
1. **npm registry (primary).** `@jxburros/ai-nugget` publishes to
|
|
351
|
-
[npmjs.org](https://www.npmjs.com/package/@jxburros/ai-nugget) on every
|
|
352
|
-
published GitHub release (`.github/workflows/publish.yml`). Consumers install
|
|
353
|
-
from the normal npm registry:
|
|
354
|
-
|
|
355
|
-
```bash
|
|
356
|
-
npm install @jxburros/ai-nugget@^0.3.1
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
This is the default dependency path for apps: fix once here, bump the
|
|
360
|
-
dependency in each app, and let npm resolve it normally.
|
|
361
|
-
2. **GitHub Packages (kept).** The same release workflow also publishes
|
|
362
|
-
`@jxburros/ai-nugget` to GitHub Packages for GitHub-native workflows and
|
|
363
|
-
existing portfolio consumers that already point at that registry. Those apps
|
|
364
|
-
add a project `.npmrc`:
|
|
365
|
-
|
|
366
|
-
```
|
|
367
|
-
@jxburros:registry=https://npm.pkg.github.com
|
|
368
|
-
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
(GitHub Packages requires an authenticated token even for public-repo
|
|
372
|
-
packages.) Then `npm install @jxburros/ai-nugget@^0.3.1`.
|
|
373
|
-
3. **Vendored `nugget/` (fallback).** `nugget/` is a generated single-folder
|
|
374
|
-
build (`src/` + `VERSION.txt` with a version + content-hash stamp) for repos
|
|
375
|
-
that cannot take a package dependency. Copy it in; `VERSION.txt` makes drift
|
|
376
|
-
from the source of truth detectable. (Bundlers that don't resolve
|
|
377
|
-
`.ts`+`.js`-suffixed imports the way `tsc` does — e.g. Turbopack — should
|
|
378
|
-
vendor `dist/` instead; see below.)
|
|
379
|
-
|
|
380
|
-
`dist/` (ESM + `.d.ts`) is the package's own build output. `dist/` and
|
|
381
|
-
`nugget/` are both committed and regenerated from `src/`; `prepublishOnly`
|
|
382
|
-
rebuilds both, and CI fails if either is stale.
|
|
383
|
-
|
|
384
|
-
**Bundler compatibility for the vendored `nugget/` path.** `nugget/src/*.ts`
|
|
385
|
-
uses NodeNext-style relative imports with explicit `.js` extensions (e.g.
|
|
386
|
-
`export * from './types.js'`), which `tsc` needs to resolve `.ts` files under
|
|
387
|
-
`moduleResolution: bundler`/`nodenext`. Not every bundler's runtime module
|
|
388
|
-
graph treats `.ts`/`.js` as interchangeable the way `tsc` does — confirmed
|
|
389
|
-
with Next.js 16's Turbopack: aliasing straight at `nugget/src/index.ts`
|
|
390
|
-
type-checks but fails to resolve at build/dev time (`Module not found: Can't
|
|
391
|
-
resolve './types.js'`), and aliasing at the compiled `dist/index.d.ts` builds
|
|
392
|
-
but silently resolves some named exports to `undefined` at runtime. If your
|
|
393
|
-
bundler hits this, vendor `dist/` (real `.js` + `.d.ts` pairs) instead of
|
|
394
|
-
`nugget/`, and point path aliases at its `.js` entry points (e.g.
|
|
395
|
-
`dist/index.js`, `dist/agent/index.js`) — TypeScript picks up the sibling
|
|
396
|
-
`.d.ts` automatically.
|
|
162
|
+
Full command list and CI layout: [distribution.md](./docs/distribution.md).
|
|
397
163
|
|
|
398
164
|
## Examples
|
|
399
165
|
|
|
400
|
-
`examples/` has runnable scripts
|
|
401
|
-
|
|
402
|
-
|
|
166
|
+
`examples/` has runnable scripts (local Ollama, llama.cpp, `promptJson` vs
|
|
167
|
+
native tools, approval gates, telemetry, a model picker), a small chat demo
|
|
168
|
+
(`npm run demo:steel-chat`), three mini-apps consuming the published package,
|
|
169
|
+
and the CI-verified [integration starters](./examples/integrations/). See
|
|
403
170
|
`examples/README.md`.
|
|
404
171
|
|
|
405
|
-
If you want a compact end-to-end app example instead of a single script, run:
|
|
406
|
-
|
|
407
|
-
```bash
|
|
408
|
-
npm run demo:steel-chat
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
That demo exposes a simple browser chat UI backed by `AIHandler`, discovers
|
|
412
|
-
allowed connections/models server-side, and displays the current package
|
|
413
|
-
version in the interface so the example stays aligned with the installed nugget.
|
|
414
|
-
|
|
415
|
-
## Agent skills
|
|
416
|
-
|
|
417
|
-
`.claude/skills/` contains Agent Skills — task-specific guides that Claude Code
|
|
418
|
-
picks up automatically and that any AI agent (or human) can read as plain
|
|
419
|
-
Markdown: `use-ai-nugget` (integrating the nugget into an app),
|
|
420
|
-
`build-agent-loop` (the agent/tool-calling layer), `add-provider` (extending
|
|
421
|
-
the provider profile table), and `develop-nugget` (invariants and validation
|
|
422
|
-
for changes to this repo). `AGENTS.md` remains the always-on baseline; the
|
|
423
|
-
skills carry the per-task detail.
|
|
424
|
-
|
|
425
172
|
## Non-goals
|
|
426
173
|
|
|
427
|
-
Not a full agent framework (no planning/memory/RAG/multi-agent
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
174
|
+
Not a full agent framework (no planning/memory/RAG/multi-agent), not a
|
|
175
|
+
router/recommender (apps choose models), not a secrets vault (`KeySource` is a
|
|
176
|
+
seam), and not a UI. The governance seam ships neutral: it is where an app *can*
|
|
177
|
+
enforce rules, not a place the library imposes its own.
|
|
178
|
+
|
|
179
|
+
<!-- GitHub Pages deployment is configured in .github/workflows/pages.yml. -->
|