@namzu/anthropic 1.3.0 → 2.0.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 CHANGED
@@ -1,5 +1,175 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f25ebce: a model id's date suffix is no longer read as its minor version
8
+
9
+ Three copies of one regular expression matched Claude model ids — the capability
10
+ table plus two drivers — and all three had the same defect: the minor-version
11
+ group was `(\d+)`, which swallowed the 8-digit date suffix.
12
+
13
+ Measured against the shipped pattern:
14
+
15
+ ```
16
+ claude-sonnet-4-20250514 -> major=4 minor=20250514
17
+ claude-opus-4-1-20250805 -> major=4 minor=1
18
+ ```
19
+
20
+ So a dated id naming no minor version compared as enormously _newer_ than one
21
+ that does, and every capability gate keyed on `minor >= n` inverted for exactly
22
+ those ids. `claude-sonnet-4-20250514` was classified as a 4.7+ model: the driver
23
+ sent it `thinking: {type: 'adaptive'}`, silently discarding a caller's
24
+ `budgetTokens`, and cleared the 4.5 gate that enables strict tool inputs.
25
+
26
+ `parseClaudeModelVersion` and `claudeVersionAtLeast` are now exported from
27
+ `@namzu/sdk` and used by both drivers and the capability table. A real minor
28
+ version is one to three digits; a date is eight, and the group is bounded
29
+ accordingly. An id the parser does not recognise makes `claudeVersionAtLeast`
30
+ return `false` — a capability gate must not open for a name it does not
31
+ understand.
32
+
33
+ The comment above the old parser warned that "a second, subtly different model
34
+ matcher is how two capability decisions drift apart on the same model name."
35
+ There were three.
36
+
37
+ - f25ebce: an effort level a model does not have is no longer sent
38
+
39
+ `ThinkingCapability.effort` was a boolean — "does this model take an effort
40
+ hint?" — and that was never the question. The ceiling moved twice: `xhigh`
41
+ arrived with 4.7, and `max` does not exist below 4.6. The accepted levels are a
42
+ **set**, and a flag could not say that `xhigh` is rejected on a 4.6 or that
43
+ `max` is rejected on a 4.5.
44
+
45
+ While it was a flag, both of those went to the wire, and the vendor rejects an
46
+ unknown level rather than clamping it — so a caller who set `effort: 'xhigh'`
47
+ and pointed at a 4.6 got a failed request, not a slightly different answer.
48
+
49
+ The driver now checks the level against the model:
50
+
51
+ | model | accepted levels |
52
+ | ----------------------------------------- | ----------------------------------- |
53
+ | 4.7 and later, and the always-on families | `low` `medium` `high` `xhigh` `max` |
54
+ | 4.6 | `low` `medium` `high` `max` |
55
+ | Opus 4.5 | `low` `medium` `high` |
56
+ | everything else | none |
57
+
58
+ A level the model does not have is dropped rather than refused: `effort` shapes
59
+ an answer the model will still produce, so a request without it is the same
60
+ request at the model's own default — whereas refusing would fail a call that
61
+ has a correct answer. The existing rule about disabled thinking at `xhigh`/`max`
62
+ is unchanged.
63
+
64
+ `patch`, not `minor` or `major`: `ThinkingCapability` is internal to this
65
+ package. The entry point exports `registerAnthropic`, `AnthropicProvider`,
66
+ `ANTHROPIC_CAPABILITIES` and two config types, and the changed field is
67
+ reachable from none of them — so no consumer's code compiles differently. What
68
+ a consumer sees is only that a request that used to fail now succeeds.
69
+
70
+ The capability table's tests now cover every currently-served model with its
71
+ level set, plus the dated-id shape that previously parsed a release date as a
72
+ minor version.
73
+
74
+ - f25ebce: the edit tool's schema could not be sent under strict validation
75
+
76
+ Strict tool input is not "JSON Schema, enforced" — it is a **subset** of JSON
77
+ Schema, and a keyword outside that subset is not degraded. The vendor rejects
78
+ the whole request, so one unexpressible field in one tool takes every other
79
+ tool down with it and the turn dies before producing a token.
80
+
81
+ The `edit` tool declared its integer-or-`"end"` field with `oneOf`, which is
82
+ outside the subset while the equivalent `anyOf` is inside it. Measured against
83
+ the live API:
84
+
85
+ | body | result |
86
+ | ------------------------- | ------------------------------------------------ |
87
+ | `strict: true` + `oneOf` | **400** — `Schema type 'oneOf' is not supported` |
88
+ | `strict: false` + `oneOf` | accepted |
89
+ | `strict: true` + `anyOf` | accepted |
90
+
91
+ The middle row is why nothing caught it. Neither half is wrong on its own — the
92
+ schema is valid JSON Schema, and marking the tool strict is correct policy — so
93
+ no test of either one failed. Only the pairing did, and the pairing had no
94
+ owner. Every agent using the built-in `edit` tool on a model at or above the
95
+ strict gate lost its first tool-carrying turn to a 400.
96
+
97
+ `oneOf` is now `anyOf` (equivalent here — the branches are disjoint), and
98
+ `minimum` is gone from the model-facing schema for the same reason: numeric
99
+ bounds are outside the subset too. The bound is not lost, the execution schema
100
+ still enforces it.
101
+
102
+ **The general fix is the second half.** `assertStrictSchema` and
103
+ `findStrictSchemaViolations` are exported from `@namzu/sdk`, and the driver now
104
+ checks every schema it is about to mark strict — refusing with the exact path
105
+ and the remedy rather than letting the request go and getting back an error
106
+ that names the keyword but not where it lives:
107
+
108
+ ```
109
+ Tool "edit" is marked for strict input validation, but its model-facing schema
110
+ uses 1 construct(s) the strict subset does not accept…
111
+ edit.properties.insertLine.oneOf — use `anyOf` — for disjoint branches the two are equivalent
112
+ ```
113
+
114
+ A test sweeps every built-in tool that asks for strict validation, so the next
115
+ one is caught in the suite rather than in production.
116
+
117
+ ## 2.0.0
118
+
119
+ ### Major Changes
120
+
121
+ - 1cd1094: Thinking is now resolved per model, `effort` is sendable, and thinking tokens
122
+ are reported.
123
+
124
+ **Thinking on a current model was a failed request, not a degraded one.** The
125
+ driver mapped `type: 'enabled'` straight to the wire and everything else to
126
+ `disabled`. The vendor rejects a mismatched mode with a 400 rather than
127
+ falling back: `thinking.type.enabled` is refused from Claude 4.7 onward,
128
+ `adaptive` is refused on 4.5 and earlier, and the always-on models refuse
129
+ `disabled`. One body for every model does not compromise quality, it fails.
130
+
131
+ `ThinkingConfig.type` gains `'adaptive'`, and the Anthropic driver resolves the
132
+ declared intent against the model it is about to call — sending the mode that
133
+ model accepts, dropping a budget where budgets have no meaning, and omitting
134
+ the field entirely rather than asking an always-on model to stop thinking. An
135
+ unrecognised model is treated as manual-only, which is the previous behaviour
136
+ and keeps a gateway serving an older model working.
137
+
138
+ **`ThinkingConfig.display` is narrowed to `'summarized' | 'omitted'`**, and now
139
+ actually reaches the wire. It was `'full' | 'summarized'`: `'full'` is not a
140
+ value any vendor accepts — a declared option that could only ever have been
141
+ rejected — and `'omitted'` was missing. It also was not serialized at all,
142
+ which matters more than it sounds: `display` defaults to `'omitted'` on newer
143
+ models, so a caller wanting to show reasoning received thinking blocks with
144
+ empty text and nothing to explain why.
145
+
146
+ **`effort` is new on `ChatCompletionParams`** — `'low' | 'medium' | 'high' |
147
+ 'xhigh' | 'max'`. It goes out as `output_config.effort`, a _sibling_ of
148
+ `thinking` rather than a field inside it, because it shapes the whole response
149
+ and one manual-mode model accepts it alongside a token budget; nesting it would
150
+ have made that combination unsayable. It is dropped on models that do not
151
+ accept it, and refused in the one combination the vendor rejects — thinking
152
+ disabled at `xhigh`/`max`.
153
+
154
+ **`TokenUsage.reasoningTokens`** carries `output_tokens_details.thinking_tokens`
155
+ when the vendor reports it. It is a _subset_ of `completionTokens`, not an
156
+ addition — reasoning is billed as output, so summing it into a total would
157
+ double-count. Absent means not reported, never zero: coercing would claim every
158
+ turn on every silent driver did no thinking, and streamed events carry the
159
+ breakdown only on the final delta.
160
+
161
+ **Migration.** `display: 'full'` no longer compiles — use `'summarized'`, which
162
+ is what it meant. Code passing `thinking: { type: 'enabled', budgetTokens }`
163
+ keeps working and is now translated per model instead of rejected by newer
164
+ ones. `assertThinkingSupported` in `@namzu/openai` refuses `'adaptive'` as it
165
+ already refused `'enabled'`, since that driver implements neither.
166
+
167
+ Not changed: a report accompanying this work claimed `temperature`, `top_p` and
168
+ `top_k` are rejected on 5-series models and should be dropped by the driver.
169
+ The Messages reference, the extended-thinking page and the thinking
170
+ troubleshooting page document no such restriction, so nothing was implemented —
171
+ silently dropping sampling parameters that would have worked is its own defect.
172
+
3
173
  ## 1.3.0
4
174
 
5
175
  ### Minor Changes
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=thinking-capability.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-capability.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/thinking-capability.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,178 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { resolveEffort, resolveThinkingBody, resolveThinkingCapability, } from '../thinking-capability.js';
3
+ /**
4
+ * The driver mapped `enabled` straight through and everything else to
5
+ * `disabled`. On a current model that is not a degraded request, it is a
6
+ * failed one: `thinking.type.enabled` is rejected with a 400 from 4.7 onward,
7
+ * `adaptive` is rejected on 4.5 and earlier, and the always-on models reject
8
+ * `disabled`.
9
+ *
10
+ * The table below is transcribed from the vendor's per-model reference, one
11
+ * case per row, because that table IS the specification — a summary of it in
12
+ * prose would be the thing that drifts.
13
+ */
14
+ const ALL = ['low', 'medium', 'high', 'xhigh', 'max'];
15
+ /** 4.6 has `max` but not `xhigh` — `xhigh` arrived with 4.7. */
16
+ const NO_XHIGH = ['low', 'medium', 'high', 'max'];
17
+ /** 4.5 has neither. */
18
+ const BASE = ['low', 'medium', 'high'];
19
+ const NONE = [];
20
+ /**
21
+ * [model, adaptive, manual, canDisable, effort levels]
22
+ *
23
+ * Every currently-served model, plus the legacy ones a gateway may still be
24
+ * pointed at. `effort` is the accepted LEVELS, not a flag: the ceiling moved
25
+ * twice, so a boolean could not say that `xhigh` is rejected on 4.6 and `max`
26
+ * is rejected on 4.5 — which is exactly what it failed to say.
27
+ */
28
+ const TABLE = [
29
+ // Always-on families: thinking cannot be switched off at any version.
30
+ ['claude-fable-5', true, false, false, ALL],
31
+ ['claude-mythos-5', true, false, false, ALL],
32
+ ['claude-mythos-preview', true, true, false, ALL],
33
+ // 4.7 and later: adaptive only, and it can still be disabled.
34
+ ['claude-opus-5', true, false, true, ALL],
35
+ ['claude-sonnet-5', true, false, true, ALL],
36
+ ['claude-opus-4-8', true, false, true, ALL],
37
+ ['claude-opus-4-7', true, false, true, ALL],
38
+ // 4.6: both modes, manual deprecated but working — and no `xhigh`.
39
+ ['claude-opus-4-6', true, true, true, NO_XHIGH],
40
+ ['claude-sonnet-4-6', true, true, true, NO_XHIGH],
41
+ // 4.5 and earlier: manual only. Opus 4.5 is the one that takes effort,
42
+ // and only the first three levels.
43
+ ['claude-opus-4-5', false, true, true, BASE],
44
+ ['claude-haiku-4-5', false, true, true, NONE],
45
+ ['claude-sonnet-4-5', false, true, true, NONE],
46
+ ['claude-opus-4-1', false, true, true, NONE],
47
+ ];
48
+ describe('what each model accepts', () => {
49
+ for (const [model, adaptive, manual, canDisable, effort] of TABLE) {
50
+ it(`resolves ${model}`, () => {
51
+ expect(resolveThinkingCapability(model)).toEqual({ adaptive, manual, canDisable, effort });
52
+ });
53
+ }
54
+ it('tolerates a vendor prefix and a date suffix', () => {
55
+ expect(resolveThinkingCapability('anthropic/claude-sonnet-5')).toMatchObject({
56
+ adaptive: true,
57
+ manual: false,
58
+ });
59
+ expect(resolveThinkingCapability('claude-sonnet-4-5-20250929')).toMatchObject({
60
+ adaptive: false,
61
+ manual: true,
62
+ });
63
+ });
64
+ it('does not read a date suffix as the minor version', () => {
65
+ // The row this table did not have. Every dated id it listed carried a
66
+ // REAL minor (`4-5-20250929`), so the `<family>-<major>-<DATE>` shape —
67
+ // a dated id naming no minor — was never exercised, and the matcher
68
+ // parsed its date as minor 20250514. That compared as enormously newer
69
+ // than 4.1, so these two were classified adaptive-only and had their
70
+ // caller's thinking budget silently discarded.
71
+ for (const model of ['claude-sonnet-4-20250514', 'claude-opus-4-20250514']) {
72
+ expect(resolveThinkingCapability(model), model).toMatchObject({
73
+ adaptive: false,
74
+ manual: true,
75
+ });
76
+ }
77
+ });
78
+ it('treats an unrecognised model as manual-only', () => {
79
+ // The pre-existing behaviour, and the safe answer for a name this
80
+ // table has not seen: an older model behind a gateway keeps working,
81
+ // and a newer one fails with the vendor's own clear 400 rather than
82
+ // with a request this driver quietly rewrote.
83
+ expect(resolveThinkingCapability('some-gateway/mystery-model')).toEqual({
84
+ adaptive: false,
85
+ manual: true,
86
+ canDisable: true,
87
+ effort: [],
88
+ });
89
+ });
90
+ });
91
+ describe('turning an intent into a body this model accepts', () => {
92
+ const adaptiveOnly = resolveThinkingCapability('claude-sonnet-5');
93
+ const manualOnly = resolveThinkingCapability('claude-sonnet-4-5');
94
+ const alwaysOn = resolveThinkingCapability('claude-fable-5');
95
+ it('sends adaptive to an adaptive model', () => {
96
+ expect(resolveThinkingBody({ type: 'adaptive' }, adaptiveOnly)).toEqual({ type: 'adaptive' });
97
+ });
98
+ it('rewrites a manual intent to adaptive where manual is rejected', () => {
99
+ // The caller asked to think. This model's way of thinking is adaptive,
100
+ // and the budget has no meaning there, so it goes.
101
+ expect(resolveThinkingBody({ type: 'enabled', budgetTokens: 10_000 }, adaptiveOnly)).toEqual({
102
+ type: 'adaptive',
103
+ });
104
+ });
105
+ it('rewrites an adaptive intent to manual where adaptive is rejected', () => {
106
+ expect(resolveThinkingBody({ type: 'adaptive' }, manualOnly)).toEqual({ type: 'enabled' });
107
+ });
108
+ it('keeps the budget on a model that has budgets', () => {
109
+ expect(resolveThinkingBody({ type: 'enabled', budgetTokens: 10_000 }, manualOnly)).toEqual({
110
+ type: 'enabled',
111
+ budget_tokens: 10_000,
112
+ });
113
+ });
114
+ it('carries display through, which is the whole reason thinking text arrives', () => {
115
+ // It defaults to `omitted` on newer models, so a caller who wants to
116
+ // show reasoning and never serializes this gets empty blocks.
117
+ expect(resolveThinkingBody({ type: 'adaptive', display: 'summarized' }, adaptiveOnly)).toEqual({
118
+ type: 'adaptive',
119
+ display: 'summarized',
120
+ });
121
+ });
122
+ it('omits the field entirely when a model cannot be told to stop thinking', () => {
123
+ // Not an error: failing here teaches nothing the vendor 400 would not,
124
+ // and it breaks a caller whose config spans models. No field means the
125
+ // model's documented default, which is the closest honest reading.
126
+ expect(resolveThinkingBody({ type: 'disabled' }, alwaysOn)).toBeUndefined();
127
+ });
128
+ it('honours disable where it is accepted', () => {
129
+ expect(resolveThinkingBody({ type: 'disabled' }, adaptiveOnly)).toEqual({ type: 'disabled' });
130
+ });
131
+ it('sends nothing when the caller asked for nothing', () => {
132
+ expect(resolveThinkingBody(undefined, adaptiveOnly)).toBeUndefined();
133
+ });
134
+ });
135
+ describe('when effort rides along', () => {
136
+ const adaptiveOnly = resolveThinkingCapability('claude-sonnet-5');
137
+ const noEffort = resolveThinkingCapability('claude-sonnet-4-5');
138
+ it('passes effort to a model that takes it', () => {
139
+ expect(resolveEffort('high', { type: 'adaptive' }, adaptiveOnly)).toBe('high');
140
+ });
141
+ it('drops effort on a model that does not', () => {
142
+ expect(resolveEffort('high', { type: 'enabled' }, noEffort)).toBeUndefined();
143
+ });
144
+ it('keeps effort on the one manual model that accepts it', () => {
145
+ // Opus 4.5: effort shapes the answer, the budget sets thinking depth,
146
+ // and both are meant to be set. So effort is not adaptive-only and
147
+ // must not be gated on the mode.
148
+ const opus45 = resolveThinkingCapability('claude-opus-4-5');
149
+ expect(resolveEffort('high', { type: 'enabled', budget_tokens: 8000 }, opus45)).toBe('high');
150
+ });
151
+ it('refuses the combination the vendor rejects', () => {
152
+ // Thinking off at effort xhigh/max is a 400 on Opus 5 and later, and
153
+ // is incoherent anyway: do not think, and think as hard as possible.
154
+ expect(resolveEffort('xhigh', { type: 'disabled' }, adaptiveOnly)).toBeUndefined();
155
+ expect(resolveEffort('max', { type: 'disabled' }, adaptiveOnly)).toBeUndefined();
156
+ expect(resolveEffort('high', { type: 'disabled' }, adaptiveOnly)).toBe('high');
157
+ });
158
+ it('drops a level this model does not have', () => {
159
+ // The ceiling moved twice, so "does this model take effort?" was never
160
+ // a yes/no question. While it was modelled as one, `xhigh` on a 4.6 and
161
+ // `max` on a 4.5 went to the wire, and the vendor rejects an unknown
162
+ // level rather than clamping it.
163
+ const v46 = resolveThinkingCapability('claude-opus-4-6');
164
+ expect(resolveEffort('xhigh', { type: 'adaptive' }, v46)).toBeUndefined();
165
+ expect(resolveEffort('max', { type: 'adaptive' }, v46)).toBe('max');
166
+ const opus45 = resolveThinkingCapability('claude-opus-4-5');
167
+ expect(resolveEffort('max', { type: 'enabled' }, opus45)).toBeUndefined();
168
+ expect(resolveEffort('xhigh', { type: 'enabled' }, opus45)).toBeUndefined();
169
+ expect(resolveEffort('high', { type: 'enabled' }, opus45)).toBe('high');
170
+ });
171
+ it('takes every level on a current model', () => {
172
+ const opus5 = resolveThinkingCapability('claude-opus-5');
173
+ for (const level of ['low', 'medium', 'high', 'xhigh', 'max']) {
174
+ expect(resolveEffort(level, { type: 'adaptive' }, opus5), level).toBe(level);
175
+ }
176
+ });
177
+ });
178
+ //# sourceMappingURL=thinking-capability.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-capability.test.js","sourceRoot":"","sources":["../../src/__tests__/thinking-capability.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EACN,aAAa,EACb,mBAAmB,EACnB,yBAAyB,GACzB,MAAM,2BAA2B,CAAA;AAElC;;;;;;;;;;GAUG;AAEH,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;AACrD,gEAAgE;AAChE,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACjD,uBAAuB;AACvB,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;AACtC,MAAM,IAAI,GAAa,EAAE,CAAA;AAEzB;;;;;;;GAOG;AACH,MAAM,KAAK,GAA6D;IACvE,sEAAsE;IACtE,CAAC,gBAAgB,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC;IAC3C,CAAC,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC;IAC5C,CAAC,uBAAuB,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC;IACjD,8DAA8D;IAC9D,CAAC,eAAe,EAAE,IAAI,E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,CAAC,CAAA;QAC3D,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,aAAa,EAAE,CAAA;QACzE,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,aAAa,EAAE,CAAA;QAC3E,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC/C,MAAM,KAAK,GAAG,yBAAyB,CAAC,eAAe,CAAC,CAAA;QACxD,KAAK,MAAM,KAAK,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAU,EAAE,CAAC;YACxE,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC7E,CAAC;IACF,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=thinking-request-body.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-request-body.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/thinking-request-body.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,90 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { AnthropicProvider } from '../client.js';
3
+ /**
4
+ * The resolver's own tests pass whether or not the client calls it. These
5
+ * drive the real `chatStream` and read the body that would have gone on the
6
+ * wire, because "declared, typed, exported, and never sent" is precisely the
7
+ * defect being fixed here — `display` had been on `ThinkingConfig` all along
8
+ * and the request builder dropped it.
9
+ */
10
+ async function bodyFor(params) {
11
+ const seen = {};
12
+ const provider = new AnthropicProvider({ apiKey: 'test-key' });
13
+ provider.client = {
14
+ messages: {
15
+ create: vi.fn(async (body) => {
16
+ seen.body = body;
17
+ return (async function* () {
18
+ yield { type: 'message_start', message: { id: 'msg_1' } };
19
+ })();
20
+ }),
21
+ },
22
+ };
23
+ for await (const _chunk of provider.chatStream({
24
+ model: 'claude-sonnet-5',
25
+ messages: [{ role: 'user', content: 'hi' }],
26
+ ...params,
27
+ })) {
28
+ // drain
29
+ }
30
+ return seen.body ?? {};
31
+ }
32
+ describe('the thinking configuration that reaches the wire', () => {
33
+ it('sends adaptive to a model that only accepts adaptive', async () => {
34
+ const body = await bodyFor({ model: 'claude-sonnet-5', thinking: { type: 'adaptive' } });
35
+ expect(body.thinking).toEqual({ type: 'adaptive' });
36
+ });
37
+ it('does not send a manual budget to a model that rejects manual mode', async () => {
38
+ // This is the failure being fixed: the old builder passed `enabled`
39
+ // straight through, and the vendor answers that with a 400.
40
+ const body = await bodyFor({
41
+ model: 'claude-sonnet-5',
42
+ thinking: { type: 'enabled', budgetTokens: 10_000 },
43
+ });
44
+ expect(body.thinking).toEqual({ type: 'adaptive' });
45
+ expect(JSON.stringify(body)).not.toContain('budget_tokens');
46
+ });
47
+ it('still sends a manual budget to a manual model', async () => {
48
+ const body = await bodyFor({
49
+ model: 'claude-sonnet-4-5',
50
+ thinking: { type: 'enabled', budgetTokens: 10_000 },
51
+ });
52
+ expect(body.thinking).toEqual({ type: 'enabled', budget_tokens: 10_000 });
53
+ });
54
+ it('serializes display, without which the thinking text comes back empty', async () => {
55
+ const body = await bodyFor({
56
+ model: 'claude-sonnet-5',
57
+ thinking: { type: 'adaptive', display: 'summarized' },
58
+ });
59
+ expect(body.thinking).toEqual({ type: 'adaptive', display: 'summarized' });
60
+ });
61
+ it('sends effort beside thinking, not inside it', async () => {
62
+ const body = await bodyFor({
63
+ model: 'claude-sonnet-5',
64
+ thinking: { type: 'adaptive' },
65
+ effort: 'xhigh',
66
+ });
67
+ expect(body.output_config).toEqual({ effort: 'xhigh' });
68
+ expect(body.thinking).toEqual({ type: 'adaptive' });
69
+ });
70
+ it('sends effort even with no thinking configuration at all', async () => {
71
+ // Effort shapes the whole response, so it is not conditional on a
72
+ // thinking block being present.
73
+ const body = await bodyFor({ model: 'claude-sonnet-5', effort: 'low' });
74
+ expect(body.output_config).toEqual({ effort: 'low' });
75
+ });
76
+ it('drops effort on a model that does not accept it', async () => {
77
+ const body = await bodyFor({ model: 'claude-sonnet-4-5', effort: 'high' });
78
+ expect(body.output_config).toBeUndefined();
79
+ });
80
+ it('omits thinking entirely on a model that cannot be told to stop', async () => {
81
+ const body = await bodyFor({ model: 'claude-fable-5', thinking: { type: 'disabled' } });
82
+ expect(body.thinking).toBeUndefined();
83
+ });
84
+ it('sends no thinking field when the caller configured none', async () => {
85
+ const body = await bodyFor({ model: 'claude-sonnet-5' });
86
+ expect(body.thinking).toBeUndefined();
87
+ expect(body.output_config).toBeUndefined();
88
+ });
89
+ });
90
+ //# sourceMappingURL=thinking-request-body.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-request-body.test.js","sourceRoot":"","sources":["../../src/__tests__/thinking-request-body.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD;;;;;;GAMG;AAEH,KAAK,UAAU,OAAO,CAAC,MAAqC;IAC3D,MAAM,IAAI,GAAuC,EAAE,CAAA;IACnD,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAC7D;IAAC,QAAqE,CAAC,MAAM,GAAG;QAChF,QAAQ,EAAE;YACT,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,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CAAA;IAC3C,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,oBAAoB,EAGpB,WAAW,EACX,SAAS,EACT,oBAAoB,EAEpB,WAAW,EAIX,MAAM,YAAY,CAAA;AAQnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA+iBjD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,oBAMpC,CAAA;AAED,qBAAa,iBAAkB,YAAW,WAAW;IACpD,QAAQ,CAAC,EAAE,eAAc;IACzB,QAAQ,CAAC,IAAI,eAAc;IAC3B,QAAQ,CAAC,YAAY,uBAAyB;IAE9C,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,eAAe;IA8BnC,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,iBAAiB;IAoEzB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAcV,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;IAiPrE,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IA+BxC,OAAO,CAAC,WAAW;IAmCb,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAMrC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,oBAAoB,EAGpB,WAAW,EACX,SAAS,EACT,oBAAoB,EAEpB,WAAW,EAIX,MAAM,YAAY,CAAA;AAgBnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAikBjD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,oBAMpC,CAAA;AAED,qBAAa,iBAAkB,YAAW,WAAW;IACpD,QAAQ,CAAC,EAAE,eAAc;IACzB,QAAQ,CAAC,IAAI,eAAc;IAC3B,QAAQ,CAAC,YAAY,uBAAyB;IAE9C,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,eAAe;IA8BnC,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,iBAAiB;IAyEzB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAcV,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;IAiPrE,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IA+BxC,OAAO,CAAC,WAAW;IAmCb,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAMrC"}
package/dist/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { ProviderRequestError, isCallerAbortError, isProviderRequestError, providerVendorError, toolResultToText, } from '@namzu/sdk';
3
+ import { ProviderRequestError, assertStrictSchema, isCallerAbortError, isProviderRequestError, modelVersionAtLeast, providerVendorError, toolResultToText, } from '@namzu/sdk';
4
+ import { MODEL_ID_GRAMMAR, resolveEffort, resolveThinkingBody, resolveThinkingCapability, } from './thinking-capability.js';
4
5
  // Floor for `max_tokens` when neither the request nor the provider
5
6
  // config supplied one. Anthropic's API requires the field, so we cannot
6
7
  // truly omit it — but 4096 (the original SDK example default) is far
@@ -226,6 +227,13 @@ function toAnthropicTools(params, cachingEnabled, strictToolUseEnabled) {
226
227
  const enforcedNames = new Set(params.enforceToolInputSchema ?? []);
227
228
  const tools = params.tools.map((t) => {
228
229
  const strict = strictToolUseEnabled && enforcedNames.has(t.function.name);
230
+ // Checked exactly where the pairing is made, because this is the only
231
+ // place both facts are in hand: that this schema is going out, and that
232
+ // this driver is about to vouch for it. A schema outside the strict
233
+ // subset is not degraded by the vendor — the whole request is rejected,
234
+ // so one unexpressible field takes down every other tool with it.
235
+ if (strict)
236
+ assertStrictSchema(t.function.name, t.function.parameters);
229
237
  return {
230
238
  name: t.function.name,
231
239
  description: t.function.description ?? '',
@@ -251,12 +259,11 @@ function shouldUseStrictToolInputs(model, mode = 'auto') {
251
259
  const normalized = model.toLowerCase();
252
260
  if (/^(?:anthropic\/)?claude-mythos-preview$/.test(normalized))
253
261
  return true;
254
- const version = normalized.match(/^(?:anthropic\/)?claude-(?:haiku|sonnet|opus|fable|mythos)-(\d+)(?:[-_.](\d+))?(?:-\d{8})?$/);
255
- if (!version)
256
- return false;
257
- const major = Number(version[1]);
258
- const minor = Number(version[2] ?? 0);
259
- return major > 4 || (major === 4 && minor >= 5);
262
+ // Shared matcher. The copy that stood here read the 8-digit date suffix as
263
+ // the minor version, so `claude-sonnet-4-20250514` compared as 4.20250514
264
+ // and cleared this 4.5 gate — strict tool inputs were enabled for a model
265
+ // below the threshold.
266
+ return modelVersionAtLeast(normalized, MODEL_ID_GRAMMAR, 4, 5);
260
267
  }
261
268
  function toAnthropicToolChoice(tc, parallelToolCalls) {
262
269
  // Anthropic expresses "no parallel tool calls" as a field ON tool_choice,
@@ -325,12 +332,17 @@ function parseUsage(raw) {
325
332
  return emptyUsage();
326
333
  const input = raw.input_tokens ?? 0;
327
334
  const output = raw.output_tokens ?? 0;
335
+ const thinking = raw.output_tokens_details?.thinking_tokens;
328
336
  return {
329
337
  promptTokens: input,
330
338
  completionTokens: output,
331
339
  totalTokens: input + output,
332
340
  cachedTokens: raw.cache_read_input_tokens ?? 0,
333
341
  cacheWriteTokens: raw.cache_creation_input_tokens ?? 0,
342
+ // Only when reported. Defaulting to 0 would say "this turn did no
343
+ // thinking" about every turn on every driver that stays silent, and
344
+ // about every streamed event before the last one.
345
+ ...(thinking !== undefined ? { reasoningTokens: thinking } : {}),
334
346
  };
335
347
  }
336
348
  function mapStopReason(reason) {
@@ -477,20 +489,26 @@ export class AnthropicProvider {
477
489
  // tool-less requests.
478
490
  if (tools && toolChoice)
479
491
  body.tool_choice = toolChoice;
480
- if (params.thinking) {
481
- // Thinking could not be REQUESTED at all before this: on a model
482
- // where it is off by default the feature was unreachable, and on
483
- // one where it is on by default its budget could not be tuned.
484
- body.thinking =
485
- params.thinking.type === 'enabled'
486
- ? {
487
- type: 'enabled',
488
- ...(params.thinking.budgetTokens !== undefined
489
- ? { budget_tokens: params.thinking.budgetTokens }
490
- : {}),
491
- }
492
- : { type: 'disabled' };
493
- }
492
+ // Resolved against the model rather than sent verbatim. This used to
493
+ // map `enabled` straight through and everything else to `disabled`,
494
+ // which fails outright on current models: `thinking.type.enabled` is
495
+ // rejected with a 400 from 4.7 onward, `adaptive` is rejected on 4.5
496
+ // and earlier, and the always-on models reject `disabled`. One body
497
+ // for every model is not a compromise here, it is a failed request.
498
+ //
499
+ // `display` is carried through now too. It defaults to `omitted` on
500
+ // newer models, so a caller who wanted to show reasoning and never
501
+ // serialized the field received thinking blocks with empty text and
502
+ // nothing to explain why.
503
+ const capability = resolveThinkingCapability(params.model);
504
+ const thinkingBody = resolveThinkingBody(params.thinking, capability);
505
+ if (thinkingBody)
506
+ body.thinking = thinkingBody;
507
+ // A sibling of `thinking`, not a field inside it — and gated on the
508
+ // model, since only some accept it at all.
509
+ const effort = resolveEffort(params.effort, thinkingBody, capability);
510
+ if (effort)
511
+ body.output_config = { effort };
494
512
  if (params.temperature !== undefined)
495
513
  body.temperature = params.temperature;
496
514
  if (params.topP !== undefined)