@combycode/llm-sdk 3.2.1 → 3.3.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +216 -0
  2. package/dist/catalog/catalog.d.ts +14 -1
  3. package/dist/index.browser.js +5428 -1665
  4. package/dist/index.js +5428 -1665
  5. package/dist/llm/client-internal.d.ts +3 -1
  6. package/dist/llm/client.d.ts +10 -0
  7. package/dist/llm/providers/anthropic/messages.d.ts +32 -7
  8. package/dist/llm/providers/anthropic/response-registry.d.ts +2 -0
  9. package/dist/llm/providers/anthropic/stream-registry.d.ts +2 -0
  10. package/dist/llm/providers/google/generate.d.ts +7 -8
  11. package/dist/llm/providers/google/interactions-registry.d.ts +2 -0
  12. package/dist/llm/providers/google/interactions-stream-registry.d.ts +2 -0
  13. package/dist/llm/providers/google/interactions.d.ts +7 -5
  14. package/dist/llm/providers/google/response-registry.d.ts +2 -0
  15. package/dist/llm/providers/google/stream-registry.d.ts +2 -0
  16. package/dist/llm/providers/openai/completions.d.ts +21 -3
  17. package/dist/llm/providers/openai/response-registry.d.ts +2 -0
  18. package/dist/llm/providers/openai/responses-registry.d.ts +2 -0
  19. package/dist/llm/providers/openai/responses-stream-registry.d.ts +2 -0
  20. package/dist/llm/providers/openai/responses.d.ts +31 -3
  21. package/dist/llm/providers/openai/stream-registry.d.ts +2 -0
  22. package/dist/llm/providers/openrouter/completions.d.ts +11 -7
  23. package/dist/llm/providers/openrouter/response-registry.d.ts +2 -0
  24. package/dist/llm/providers/openrouter/stream-registry.d.ts +2 -0
  25. package/dist/llm/providers/response-registries.d.ts +5 -0
  26. package/dist/llm/providers/xai/completions.d.ts +1 -4
  27. package/dist/llm/providers/xai/responses-registry.d.ts +2 -0
  28. package/dist/llm/providers/xai/responses.d.ts +12 -0
  29. package/dist/llm/providers/xai/stream-registry.d.ts +2 -0
  30. package/dist/plugins/context-guard/facts.d.ts +9 -0
  31. package/dist/plugins/context-guard/tools.d.ts +3 -0
  32. package/dist/plugins/context-guard/types.d.ts +5 -0
  33. package/dist/util/audio-mime.d.ts +16 -0
  34. package/dist/util/compare.d.ts +13 -0
  35. package/dist/wire/interpreter.d.ts +2 -0
  36. package/dist/wire/response-interpreter.d.ts +156 -0
  37. package/dist/wire/response-specs.d.ts +7 -0
  38. package/dist/wire/stream-interpreter.d.ts +94 -0
  39. package/dist/wire/stream-specs.d.ts +8 -0
  40. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -4,6 +4,222 @@ All notable changes to `@combycode/llm-sdk` are documented here. The format foll
4
4
  [Keep a Changelog](https://keepachangelog.com/) and the project adheres to
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ## [3.3.1] - 2026-09-08
10
+
11
+ ### Fixed
12
+
13
+ - **xAI Imagine video renders were billed at up to a twenty-fifth of their real price.** The
14
+ pricing page's first price column is `Media Input`, and the extraction read it as the first
15
+ resolution's rate -- shifting every per-resolution price one slot along and dropping the last.
16
+ `grok-imagine-video` charged $0.002/sec for 480p where the page says $0.05, so an 8-second
17
+ render estimated at $0.016 instead of $0.40; its flat `perSecond` fallback held $0.01, the rate
18
+ for a second of *input* video, a 5x under-bill on any request that named no resolution.
19
+ `grok-imagine-video-1.5` and `grok-imagine-image-2.0` were shifted the same way. Corrected from
20
+ the page's own table markup, cross-checked against LiteLLM where it carries the model.
21
+ `perUnit`/`perImage`/`perSecond` are what a model EMITS -- the doc comment now says so, having
22
+ previously used the misread pair as its example.
23
+
24
+ ### Changed
25
+
26
+ - Model catalog refreshed: 475 models, 20 added (`claude-fable-5.1`, `gpt-6-astra`,
27
+ `gemini-3.8-flash`, `gemini-3.5-transcribe`, `gemini-omni-1.1-flash`, `lyria-3.5` and 13 on
28
+ OpenRouter), 12 delisted and kept with `active: false`, none dropped. Prices, context windows
29
+ and deprecation dates updated across all five providers; every new chat model carries its
30
+ `wireSpec` pin and a frozen entry in the wire corpus.
31
+ - `outputModalities` now comes from what a source publishes rather than being inferred from the
32
+ model's `type`, which could not tell a model that emits audio from one that only accepts it.
33
+ 23 models gained a second modality: Gemini image models emit text alongside the image, Lyria
34
+ emits audio, `openrouter/auto` can route to an image model. Descriptive metadata -- no request
35
+ is built differently.
36
+
37
+ ## [3.3.0] - 2026-09-06
38
+
39
+ ### Fixed
40
+
41
+ - **xAI's batch API had never worked, and could not say so.** Three readings were wrong. The
42
+ status counts live under `state`, not at the top level, so `total` was always 0, the job never
43
+ reached a terminal state, and a polling caller waited on a batch that had completed in seconds --
44
+ no error, no output, just a wait. The results are nested and TAGGED,
45
+ `batch_result.response.<variant>`, so reading `row.response` found nothing and every answer came
46
+ back a failure with no error to explain it. And the cancel route is `<id>:cancel`; the slash form
47
+ answers 404 (`DELETE` and `PATCH` on the bare batch answer 405). All three measured live against
48
+ `api.x.ai` on 2026-09-04, which is also when the corpus cell for xAI batch went from unsupported
49
+ to green in 17 seconds -- the fastest of the four providers.
50
+
51
+ - **A hosted tool the provider cannot run was dropped without a word.** Asking OpenRouter for
52
+ `code_interpreter` put `tools: []` on the wire and said nothing: the catalog is right (OpenRouter
53
+ routes function tools and its own plugins, not hosted code execution), so omitting it is correct,
54
+ but the silent loss of a capability the caller asked for is the exact thing this library's
55
+ tool-constraint mechanic exists to prevent. An unsupported builtin now produces a
56
+ `request_adjusted` warning naming the tool and what the provider does run, and an empty `tools`
57
+ array no longer reaches any provider -- it used to be dropped only on the `web_search` path.
58
+
59
+ - **The local chunker silently dropped space-free text: CJK prose, minified JSON, base64 blobs,
60
+ long URLs.** `snapStep` moved the cursor to the next ASCII space no matter how far away it was,
61
+ and to the END of the document when there was none -- in both cases without emitting a chunk for
62
+ the span it stepped over. So a document with a base64 image in the middle lost the image and
63
+ everything the walk skipped with it (measured: 17983 of 26991 characters), and one that turns
64
+ space-free and stays that way was indexed as its first window alone. The text was never embedded
65
+ and no query could retrieve it. A space is now a boundary only while the next window would still
66
+ start inside the chunk just emitted; past that the walk advances by the step. Verified live
67
+ against real OpenAI embeddings, with the answer inside a minified payload: no hit before, the
68
+ right hit after, for the payload at the end of the document and in the middle of it.
69
+
70
+ - **A document that mixed prose with a space-free run was chunked into dozens of runts.** The
71
+ step is derived from the SNAPPED window length, so a window trimmed back hard -- its only space
72
+ near its start, which is exactly what the last window before a base64 blob or a minified payload
73
+ looks like -- left a step below the overlap, and the `max(step, 1)` floor became the actual step.
74
+ The walk then crawled one word at a time across the whole approach to the blob: on a README with
75
+ one embedded image, 42 of 58 chunks came out under half the budget and the smallest was 8
76
+ characters. Every one was embedded at the caller's expense, and because they are the same
77
+ sentence shifted by a word they crowded each other out of the results. A boundary is now taken
78
+ only when it leaves at least half the window; below that the window is used whole. The cut that
79
+ buys can only ever land inside a run with no space in it for 1024 characters, where there is no
80
+ word to split. Same README: 16 chunks, no runts. Prose is byte-for-byte unaffected.
81
+
82
+ - **The tail of every locally-indexed document was embedded several times over.** Once a window
83
+ reached the end of the text the walk kept going, re-emitting the same tail as a run of
84
+ ever-shorter chunks that all ended in the same place. Not lost text -- duplicate index entries,
85
+ each one paid for at the embedding endpoint and each one competing with the others for a result
86
+ slot. The walk now stops on the window that reaches the end.
87
+
88
+ - **Every OpenAI model was routed to the Responses API, whatever the model.** `resolveApi` chose by
89
+ PROVIDER alone, while the catalog had carried `preferredApi` per model from the start and nothing
90
+ read it. Six catalogued models cannot be called on Responses at all: `gpt-audio`, `gpt-audio-1.5`,
91
+ `gpt-audio-mini` and the three `*-search` models, which are Chat Completions-only. Asking for any
92
+ of them failed with *"The requested model 'gpt-audio' is not supported with the Responses API"*.
93
+ Routing now consults the model's own preference and falls back to the provider default. Verified
94
+ live: `gpt-audio` returns audio and `gpt-5-search` answers, both of which previously could not run.
95
+
96
+ - **`gpt-audio*` was described wrongly by the catalog.** `preferredApi: 'responses'` (see above),
97
+ `outputModalities: ['text']` for a model that returns audio bytes AND a transcript, and
98
+ `capabilities.audioGeneration: false` for the audio-generation model. OpenAI's guide is explicit:
99
+ *"For this audio-chat pattern, use Chat Completions with an audio-capable model."*
100
+
101
+ - **Streamed audio produced nothing at all.** `delta.audio` was ignored by the Chat Completions
102
+ stream parser, so a `gpt-audio` turn streamed 68 SSE events and yielded exactly ONE unified event:
103
+ `usage`. No text (the words are in `audio.transcript`, not `delta.content`), no media, and —
104
+ because these chunks never carry a `finish_reason` — no terminal event either, so a caller
105
+ awaiting `done` waited forever. Now the transcript surfaces as `text`, the fragments as
106
+ `media_start` / `media_chunk` / `media_end`, and the final `expires_at`-only delta closes the
107
+ stream. Streamed audio is always `pcm16` (the API refuses any other format when `stream=true`) and
108
+ raw PCM has no magic bytes, so the mime is stated rather than sniffed.
109
+
110
+ - **Audio output was silently dropped on the OpenAI chat path.** `openai-completions` gated its
111
+ `modalities` block on `hasAudioInput`, so `outputModalities: ['text', 'audio']` travelled from
112
+ `ExecuteOptions` all the way to the wire builder and died there. `gpt-audio` then refused the call
113
+ outright — *"this model requires that either input content or output modality contain audio"*.
114
+ The parser had always known how to build an `audio_output` part from `message.audio`, so both ends
115
+ of the feature existed and only this guard kept them apart. The guard now fires on audio in OR
116
+ audio out. OpenRouter inherits the same spec, so models routed through it now forward the audio
117
+ request the caller actually made.
118
+
119
+ - **Every audio clip was labelled `audio/wav`, whatever it was.** OpenAI returns `message.audio` as
120
+ `{ id, data, expires_at, transcript }` — there is no `format` key — so the adapter's
121
+ `audio/${format ?? 'wav'}` fell through to the default on every response. Request mp3, receive
122
+ `ID3`-prefixed mp3 bytes, be told it is wav. A new `sniffAudioMime` reads the container from the
123
+ magic bytes (mp3/wav/ogg/flac/aac), mirroring the existing `sniffImageMime`; the old template
124
+ remains as the last resort.
125
+
126
+ ### Changed
127
+
128
+ - **Stream parsing is spec-driven too.** The other half of the same migration: all seven
129
+ `createStreamParser` implementations now run one driver over a declarative spec, and **682 more
130
+ lines of hand-written parsing are gone**. The driver is the buffered interpreter with two
131
+ differences — state is created once per STREAM rather than per call, and one reserved
132
+ accumulator is drained and returned after each SSE event.
133
+
134
+ Measured before starting: of 518 lines across the five parsers, 38 touched state. The rest was
135
+ dispatch, which is what a spec expresses. Behaviour is unchanged and checked the same way, against
136
+ 29 recorded streams whose event sequences are frozen in the corpus, plus one live streaming call
137
+ per provider after the switch.
138
+
139
+ `parseStreamEvent` stays on the adapter interface as a stateless one-shot; `createStreamParser` is
140
+ the stateful one callers should use.
141
+
142
+ - **Response parsing is spec-driven.** Requests have been built from specs since 3.0.0; the parse
143
+ side was seven hand-written `parseResponse` implementations doing the same four things in four
144
+ spellings. All seven now run one interpreter over a declarative spec, and **599 lines of
145
+ hand-written parsing are gone**.
146
+
147
+ The evaluator is the request one, unchanged: `$`, `$map`, `$call`, `$table`, `$join`, `$when` and
148
+ `$default` never cared what the root object was. Only classification is new — `collect` walks a
149
+ discriminated array and emits into named accumulators, and naming several places ONE object in
150
+ each rather than copies, which is what the adapters did and what consumers depend on.
151
+
152
+ Behaviour is unchanged, and that is checked rather than asserted: the differential replays every
153
+ recorded provider body through the adapters and compares against `parsed` values frozen in the
154
+ corpus — data neither path recomputes, so it still means something now the code that produced
155
+ it is deleted. 46 of 46 buffered cells match, and one live call per provider was made against the
156
+ real API after the switch.
157
+
158
+ `OpenRouterAdapter.parseResponse` is gone entirely: its `:online` web-search rule is a delta of
159
+ the shared spec, so naming the spec is the override now, exactly as `wireFlavor` already was for
160
+ requests.
161
+
162
+ ### Internal
163
+
164
+ - **The response corpus covers the parse paths it never reached.** Measured against the fixtures,
165
+ `citations`, `files`, `builtinToolCalls`, `media` and `moderation` appeared in **zero** buffered
166
+ cells, and `thinking` in one target — so a parser that stopped producing any of them kept the
167
+ differential green. Five scenarios were added (`builtin.search`, `builtin.codeexec`, `media.audio`,
168
+ `thinking`, `moderation`), taking the corpus from 42 to 57 recorded cells. Both bugs above were
169
+ found by recording them.
170
+
171
+ Scenarios now declare which targets they apply to, because the matrix is no longer a full cross
172
+ product: Chat Completions has no hosted web search, and only `gpt-audio` returns audio. The
173
+ recorder and the differential read the same `expectedCells()`, so they cannot disagree about what
174
+ is missing.
175
+
176
+ - **The streaming corpus covers the branches that carry state.** Measured before this change, the
177
+ 14 streaming cells produced only `usage`, `done`, `text`, `tool_call_*` and `thinking`: NINE of the
178
+ sixteen `StreamEvent` types had no coverage, and they were exactly the stateful ones — the
179
+ accumulate-JSON-then-pair-with-its-result machine, the emit-once-per-stream flags, the three-event
180
+ media reassembly. Five streaming scenarios were added (search, code execution, audio, thinking,
181
+ moderation), taking the corpus from 60 to 75 cells and streaming coverage from 7/16 to **15/16**.
182
+ The sixteenth, `error`, is emitted only by the Realtime adapter, which this corpus does not cover.
183
+
184
+ The audio bug above was found by the first run of the new cell: it tripped the existing invariant
185
+ that every streaming cell must produce a terminal event.
186
+
187
+ - **`XAIAdapter` emitted every reasoning delta TWICE.** Its `parseStreamEvent` override prepended a
188
+ `thinking` event for `reasoning_content` while `OpenAIAdapter`, its parent, already appended one
189
+ for the same field. `xai/completions` is not a corpus target — xAI defaults to the Responses
190
+ API — so nothing was watching. The override was both redundant and duplicating; it is gone, and
191
+ a regression test pins the count at one.
192
+
193
+ - **A test that failed on timing alone.** `tiktoken-optional` builds a counter per case, and the
194
+ encoder is a ~5.6 MB WASM module loaded lazily per instance, landing either side of bun's 5s
195
+ default under load. It failed twice in one session, on a different case each time, with no
196
+ assertion involved. The limit is raised rather than the load hidden: the work is slow, not wrong.
197
+ (A first attempt to warm the encoder in `beforeAll` made it fail 3/3 instead of intermittently,
198
+ because the cache is per-instance and the warm-up only added a third load.)
199
+
200
+ - **The corpus did not catch everything, and that is worth recording.** Switching the adapters
201
+ dropped xAI's inline code-execution file extraction: `XAIResponsesAdapter` overrides
202
+ `filesFromOutputItem`, the shared spec transform called the OpenAI module function directly, and
203
+ the override was simply never consulted. No recorded xAI cell runs code execution, so the response
204
+ differential stayed green — an existing unit test failed instead. xAI now has its own response
205
+ registry, the parse-side twin of that adapter override.
206
+
207
+ - **The three parse branches for a failure reported inside a 200 are covered.** A provider cannot be
208
+ asked to fail on demand, so those cells are CONSTRUCTED — marked `synthetic: true`, built from the
209
+ target's own recorded envelope with only the failure fields changed, each traceable to the official
210
+ SDK type cited in the cell's `provenance`. They cover OpenAI Responses `status:'failed'` with
211
+ `response.error`, its `incomplete_details.reason: 'content_filter'` (which must not be reported as a
212
+ length truncation), and Google Interactions `status:'failed'`.
213
+
214
+ A synthetic body widens the derived shape book's `known` and `values` but is excluded from
215
+ `expected`: a failed response carries no `output`, and letting it into that intersection would
216
+ weaken the check on every genuine recording.
217
+
218
+ - **The frozen request corpus grew a waiver list.** A deliberate wire change previously had no way to
219
+ be recorded except re-freezing, which would absorb every *un*noticed change in the same pass. Each
220
+ waiver is checked in both directions: one whose cells no longer differ fails the suite, so it
221
+ cannot outlive the change it describes.
222
+
7
223
  ## [3.2.1] — 2026-08-31
8
224
 
9
225
  ### Fixed
@@ -16,7 +16,8 @@ export interface ModelPricing {
16
16
  perMinute?: number;
17
17
  perMChars?: number;
18
18
  /** Per-unit rates keyed by a quality/resolution tier (e.g. video
19
- * `{"720p":0.1,"1080p":0.12}`, image `{"1k":0.002,"2k":0.02}`). When the
19
+ * `{"720p":0.1,"1080p":0.12}`, image `{"1k":0.02,"2k":0.02}`). Rates are what the model
20
+ * EMITS: an input-media price does not belong here. When the
20
21
  * selected resolution matches a key, it overrides the flat perImage/perSecond. */
21
22
  perUnit?: Record<string, number>;
22
23
  /** Per-service-tier rate overrides, keyed by the provider's OWN billed tier
@@ -66,6 +67,18 @@ export interface ModelReasoning {
66
67
  effortValues?: string[];
67
68
  encryptedContent: boolean;
68
69
  summaryAvailable: boolean;
70
+ /** Whether `thinking: { mode: 'off' }` can actually be honoured.
71
+ *
72
+ * Deliberately optional, and deliberately not defaulted. Absent means NOBODY
73
+ * HAS ESTABLISHED IT for this model, which is not the same as `true`: only an
74
+ * explicit `false` makes the client drop the request and warn, so a provider
75
+ * nobody has measured keeps behaving exactly as it did.
76
+ *
77
+ * It exists because some models refuse: Gemini 2.5 Pro answers `Budget 0 is
78
+ * invalid. This model only works in thinking mode.`, and 3.7 Flash accepts a
79
+ * zero budget and reasons anyway. Sending the disable field to those buys a
80
+ * 400 or a silent lie; saying so up front costs a warning. */
81
+ canDisable?: boolean;
69
82
  }
70
83
  export interface TokenizerInfo {
71
84
  strategy: 'heuristic' | 'tiktoken' | 'count_api';