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