@namzu/anthropic 2.0.0 → 3.0.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.
@@ -1,56 +1,97 @@
1
+ import { parseVersionedModelId } from '@namzu/sdk';
2
+ const NO_EFFORT = [];
3
+ /** Everything from 4.7 onward, plus the always-on families. */
4
+ const FULL_EFFORT = ['low', 'medium', 'high', 'xhigh', 'max'];
5
+ /** 4.6: `max` exists, `xhigh` does not — it arrived with 4.7. */
6
+ const EFFORT_WITHOUT_XHIGH = ['low', 'medium', 'high', 'max'];
7
+ /** 4.5: neither `xhigh` nor `max`. */
8
+ const EFFORT_BASE = ['low', 'medium', 'high'];
1
9
  const MANUAL_ONLY = {
2
10
  adaptive: false,
3
11
  manual: true,
4
12
  canDisable: true,
5
- effort: false,
13
+ effort: NO_EFFORT,
14
+ effortWhenDisabled: NO_EFFORT,
6
15
  };
7
16
  /**
8
- * Parse `claude-<family>-<major>[.<minor>]`, tolerating a vendor prefix and a
9
- * date suffix.
17
+ * The vocabulary this driver's ids are spelled in.
10
18
  *
11
- * Deliberately the same shape the driver's `shouldUseStrictToolInputs` already
12
- * parses. A second, subtly different model matcher in the same file is how two
13
- * capability decisions drift apart on the same model name.
19
+ * The matcher itself is `parseVersionedModelId` in the kernel; only these
20
+ * words are local, because only this package knows them. The comment that
21
+ * stood here warned that "a second, subtly different model matcher in the same
22
+ * file is how two capability decisions drift apart on the same model name" —
23
+ * and there were three copies of it, this file and two drivers, all with the
24
+ * same defect: the minor group was `\d+`, so it swallowed the 8-digit date
25
+ * suffix and a dated id naming no minor parsed as minor 20250514. The warning
26
+ * was right, and the answer to it was not another careful copy.
14
27
  */
15
- function parseModel(model) {
16
- const normalized = model.toLowerCase();
17
- const match = normalized.match(/^(?:anthropic\/)?claude-(haiku|sonnet|opus|fable|mythos)-(\d+)(?:[-_.](\d+))?(?:-\d{8})?$/);
18
- if (!match)
19
- return undefined;
20
- return {
21
- family: match[1],
22
- major: Number(match[2]),
23
- minor: Number(match[3] ?? 0),
24
- };
25
- }
28
+ export const MODEL_ID_GRAMMAR = {
29
+ product: 'claude',
30
+ families: ['haiku', 'sonnet', 'opus', 'fable', 'mythos'],
31
+ routingPrefix: 'anthropic/',
32
+ };
26
33
  export function resolveThinkingCapability(model) {
27
34
  const normalized = model.toLowerCase();
28
35
  // Named rather than versioned: the preview carries no version number the
29
36
  // parser can compare, and it is the one model supporting both modes while
30
37
  // refusing to be switched off.
31
38
  if (/^(?:anthropic\/)?claude-mythos-preview$/.test(normalized)) {
32
- return { adaptive: true, manual: true, canDisable: false, effort: true };
39
+ return {
40
+ adaptive: true,
41
+ manual: true,
42
+ canDisable: false,
43
+ effort: FULL_EFFORT,
44
+ effortWhenDisabled: FULL_EFFORT,
45
+ };
33
46
  }
34
- const parsed = parseModel(model);
47
+ const parsed = parseVersionedModelId(model, MODEL_ID_GRAMMAR);
35
48
  if (!parsed)
36
49
  return MANUAL_ONLY;
37
50
  const { family, major, minor } = parsed;
38
51
  // Always-on families: thinking cannot be disabled at any version.
39
52
  if (family === 'fable' || family === 'mythos') {
40
- return { adaptive: true, manual: false, canDisable: false, effort: true };
53
+ return {
54
+ adaptive: true,
55
+ manual: false,
56
+ canDisable: false,
57
+ effort: FULL_EFFORT,
58
+ effortWhenDisabled: FULL_EFFORT,
59
+ };
41
60
  }
42
61
  // 4.7 and later dropped manual mode outright.
43
62
  if (major > 4 || (major === 4 && minor >= 7)) {
44
- return { adaptive: true, manual: false, canDisable: true, effort: true };
63
+ // The Opus 5 family alone caps effort while thinking is off. Measured,
64
+ // not inferred: `claude-opus-5` refuses `disabled` + `xhigh`/`max` and
65
+ // accepts `disabled` + `high`, while `claude-sonnet-5` and
66
+ // `claude-opus-4-8` accept `disabled` + `max`. A version comparison of
67
+ // "5 and later" would have caught Sonnet 5 too and dropped an effort
68
+ // that wire honours.
69
+ const opus5Plus = family === 'opus' && major >= 5;
70
+ return {
71
+ adaptive: true,
72
+ manual: false,
73
+ canDisable: true,
74
+ effort: FULL_EFFORT,
75
+ effortWhenDisabled: opus5Plus ? EFFORT_BASE : FULL_EFFORT,
76
+ };
45
77
  }
46
78
  // 4.6 accepts both; manual is deprecated there but still functional.
47
79
  if (major === 4 && minor === 6) {
48
- return { adaptive: true, manual: true, canDisable: true, effort: true };
80
+ return {
81
+ adaptive: true,
82
+ manual: true,
83
+ canDisable: true,
84
+ effort: EFFORT_WITHOUT_XHIGH,
85
+ effortWhenDisabled: EFFORT_WITHOUT_XHIGH,
86
+ };
49
87
  }
50
88
  // 4.5 and earlier are manual-only. Opus 4.5 is the one that also takes
51
- // effort, where effort shapes the answer and the budget sets depth.
89
+ // effort, where effort shapes the answer and the budget sets depth — and it
90
+ // takes only the first three levels: `xhigh` did not exist yet and `max`
91
+ // is rejected there.
52
92
  const isOpus45 = family === 'opus' && major === 4 && minor === 5;
53
- return { ...MANUAL_ONLY, effort: isOpus45 };
93
+ const base = isOpus45 ? EFFORT_BASE : NO_EFFORT;
94
+ return { ...MANUAL_ONLY, effort: base, effortWhenDisabled: base };
54
95
  }
55
96
  /**
56
97
  * Turn a declared intent into a body this model accepts, or into nothing.
@@ -95,20 +136,33 @@ export function resolveThinkingBody(thinking, capability) {
95
136
  /**
96
137
  * Whether `effort` may ride on this request.
97
138
  *
98
- * One interaction the table alone does not cover: on Opus 5 and later,
99
- * `thinking: {type: "disabled"}` is accepted at effort `high` or below and
100
- * **rejected at `xhigh`/`max`**, enforced per request. Rather than encode
101
- * "Opus 5 and later" as a second version comparison, this refuses the
102
- * combination on every model that can disable thinking — the pairing is
103
- * incoherent anyway, since it asks a model not to think and then to think as
104
- * hard as possible.
139
+ * Two things get checked, and the second used to be missed entirely.
140
+ *
141
+ * The LEVEL has to be one this model has. The ceiling moved twice — `xhigh`
142
+ * arrived with 4.7, and `max` does not exist below 4.6 — so `capability.effort`
143
+ * is a set rather than a flag. It was a flag, which meant `xhigh` on a 4.6 and
144
+ * `max` on a 4.5 were forwarded to a vendor that rejects an unknown level
145
+ * rather than clamping it. Dropping the field is right where the level does
146
+ * not exist: `effort` shapes an answer the model will still produce, so a
147
+ * request without it is the same request at the model's own default, whereas
148
+ * refusing would fail a call that has a correct answer.
149
+ *
150
+ * The COMBINATION has to be legal, and the legal set is per model rather than
151
+ * universal. Opus 5 accepts `thinking: {type: "disabled"}` at `high` or below
152
+ * and **rejects it at `xhigh`/`max`** — so this asks the capability for the set
153
+ * that applies when thinking is off, instead of the set that applies generally.
154
+ *
155
+ * That distinction was earned. The rule started as a blanket refusal on every
156
+ * model that can disable thinking, on the reasoning that the pairing is
157
+ * incoherent anyway — asking a model not to think and then to think as hard as
158
+ * possible. Measured, Sonnet 5 and Opus 4.8 both accept it, so the blanket rule
159
+ * was discarding an effort the caller asked for and the wire would have
160
+ * honoured. Incoherent-looking is not the same as rejected.
105
161
  */
106
162
  export function resolveEffort(effort, thinkingBody, capability) {
107
- if (effort === undefined || !capability.effort)
163
+ if (effort === undefined)
108
164
  return undefined;
109
- if (thinkingBody?.type === 'disabled' && (effort === 'xhigh' || effort === 'max')) {
110
- return undefined;
111
- }
112
- return effort;
165
+ const allowed = thinkingBody?.type === 'disabled' ? capability.effortWhenDisabled : capability.effort;
166
+ return allowed.includes(effort) ? effort : undefined;
113
167
  }
114
168
  //# sourceMappingURL=thinking-capability.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"thinking-capability.js","sourceRoot":"","sources":["../src/thinking-capability.ts"],"names":[],"mappings":"AAsCA,MAAM,WAAW,GAAuB;IACvC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,IAAI;IAChB,MAAM,EAAE,KAAK;CACb,CAAA;AAED;;;;;;;GAOG;AACH,SAAS,UAAU,CAAC,KAAa;IAChC,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAA;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAC7B,2FAA2F,CAC3F,CAAA;IACD,IAAI,CAAC,KAA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CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;AACrD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namzu/anthropic",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Anthropic LLM provider for @namzu/sdk via the official @anthropic-ai/sdk. Messages API with streaming, tool-use, and extended thinking support.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "type": "module",
@@ -37,14 +37,14 @@
37
37
  "@anthropic-ai/sdk": "^0.115.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "@namzu/sdk": ">=1.3.0"
40
+ "@namzu/sdk": ">=6.0.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@biomejs/biome": "^1.9.4",
44
44
  "@types/node": "^22.19.17",
45
45
  "typescript": "^5.5.0",
46
46
  "vitest": "^3.2.6",
47
- "@namzu/sdk": "^5.0.0"
47
+ "@namzu/sdk": "^6.0.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsc --build",
@@ -18,27 +18,53 @@ import {
18
18
  * prose would be the thing that drifts.
19
19
  */
20
20
 
21
- /** [model, adaptive, manual, canDisable, effort] */
22
- const TABLE: readonly [string, boolean, boolean, boolean, boolean][] = [
23
- ['claude-fable-5', true, false, false, true],
24
- ['claude-mythos-5', true, false, false, true],
25
- ['claude-mythos-preview', true, true, false, true],
26
- ['claude-opus-5', true, false, true, true],
27
- ['claude-opus-4-8', true, false, true, true],
28
- ['claude-opus-4-7', true, false, true, true],
29
- ['claude-sonnet-5', true, false, true, true],
30
- ['claude-opus-4-6', true, true, true, true],
31
- ['claude-sonnet-4-6', true, true, true, true],
32
- ['claude-opus-4-5', false, true, true, true],
33
- ['claude-haiku-4-5', false, true, true, false],
34
- ['claude-sonnet-4-5', false, true, true, false],
35
- ['claude-opus-4-1', false, true, true, false],
21
+ const ALL = ['low', 'medium', 'high', 'xhigh', 'max']
22
+ /** 4.6 has `max` but not `xhigh` — `xhigh` arrived with 4.7. */
23
+ const NO_XHIGH = ['low', 'medium', 'high', 'max']
24
+ /** 4.5 has neither. */
25
+ const BASE = ['low', 'medium', 'high']
26
+ const NONE: string[] = []
27
+
28
+ /**
29
+ * [model, adaptive, manual, canDisable, effort levels]
30
+ *
31
+ * Every currently-served model, plus the legacy ones a gateway may still be
32
+ * pointed at. `effort` is the accepted LEVELS, not a flag: the ceiling moved
33
+ * twice, so a boolean could not say that `xhigh` is rejected on 4.6 and `max`
34
+ * is rejected on 4.5 — which is exactly what it failed to say.
35
+ */
36
+ const CAPPED = BASE // opus 5+ with thinking off
37
+ const TABLE: readonly [string, boolean, boolean, boolean, string[], string[]][] = [
38
+ // Always-on families: thinking cannot be switched off at any version.
39
+ ['claude-fable-5', true, false, false, ALL, ALL],
40
+ ['claude-mythos-5', true, false, false, ALL, ALL],
41
+ ['claude-mythos-preview', true, true, false, ALL, ALL],
42
+ // 4.7 and later: adaptive only, and it can still be disabled.
43
+ ['claude-opus-5', true, false, true, ALL, CAPPED],
44
+ ['claude-sonnet-5', true, false, true, ALL, ALL],
45
+ ['claude-opus-4-8', true, false, true, ALL, ALL],
46
+ ['claude-opus-4-7', true, false, true, ALL, ALL],
47
+ // 4.6: both modes, manual deprecated but working — and no `xhigh`.
48
+ ['claude-opus-4-6', true, true, true, NO_XHIGH, NO_XHIGH],
49
+ ['claude-sonnet-4-6', true, true, true, NO_XHIGH, NO_XHIGH],
50
+ // 4.5 and earlier: manual only. Opus 4.5 is the one that takes effort,
51
+ // and only the first three levels.
52
+ ['claude-opus-4-5', false, true, true, BASE, BASE],
53
+ ['claude-haiku-4-5', false, true, true, NONE, NONE],
54
+ ['claude-sonnet-4-5', false, true, true, NONE, NONE],
55
+ ['claude-opus-4-1', false, true, true, NONE, NONE],
36
56
  ]
37
57
 
38
58
  describe('what each model accepts', () => {
39
- for (const [model, adaptive, manual, canDisable, effort] of TABLE) {
59
+ for (const [model, adaptive, manual, canDisable, effort, effortWhenDisabled] of TABLE) {
40
60
  it(`resolves ${model}`, () => {
41
- expect(resolveThinkingCapability(model)).toEqual({ adaptive, manual, canDisable, effort })
61
+ expect(resolveThinkingCapability(model)).toEqual({
62
+ adaptive,
63
+ manual,
64
+ canDisable,
65
+ effort,
66
+ effortWhenDisabled,
67
+ })
42
68
  })
43
69
  }
44
70
 
@@ -53,6 +79,21 @@ describe('what each model accepts', () => {
53
79
  })
54
80
  })
55
81
 
82
+ it('does not read a date suffix as the minor version', () => {
83
+ // The row this table did not have. Every dated id it listed carried a
84
+ // REAL minor (`4-5-20250929`), so the `<family>-<major>-<DATE>` shape —
85
+ // a dated id naming no minor — was never exercised, and the matcher
86
+ // parsed its date as minor 20250514. That compared as enormously newer
87
+ // than 4.1, so these two were classified adaptive-only and had their
88
+ // caller's thinking budget silently discarded.
89
+ for (const model of ['claude-sonnet-4-20250514', 'claude-opus-4-20250514']) {
90
+ expect(resolveThinkingCapability(model), model).toMatchObject({
91
+ adaptive: false,
92
+ manual: true,
93
+ })
94
+ }
95
+ })
96
+
56
97
  it('treats an unrecognised model as manual-only', () => {
57
98
  // The pre-existing behaviour, and the safe answer for a name this
58
99
  // table has not seen: an older model behind a gateway keeps working,
@@ -62,7 +103,8 @@ describe('what each model accepts', () => {
62
103
  adaptive: false,
63
104
  manual: true,
64
105
  canDisable: true,
65
- effort: false,
106
+ effort: [],
107
+ effortWhenDisabled: [],
66
108
  })
67
109
  })
68
110
  })
@@ -140,11 +182,49 @@ describe('when effort rides along', () => {
140
182
  expect(resolveEffort('high', { type: 'enabled', budget_tokens: 8000 }, opus45)).toBe('high')
141
183
  })
142
184
 
143
- it('refuses the combination the vendor rejects', () => {
144
- // Thinking off at effort xhigh/max is a 400 on Opus 5 and later, and
145
- // is incoherent anyway: do not think, and think as hard as possible.
146
- expect(resolveEffort('xhigh', { type: 'disabled' }, adaptiveOnly)).toBeUndefined()
147
- expect(resolveEffort('max', { type: 'disabled' }, adaptiveOnly)).toBeUndefined()
148
- expect(resolveEffort('high', { type: 'disabled' }, adaptiveOnly)).toBe('high')
185
+ it('caps effort with thinking off only where the wire caps it', () => {
186
+ // This rule used to be blanket: thinking off at `xhigh`/`max` was
187
+ // refused on every model that can disable thinking, reasoning that the
188
+ // pairing is incoherent anyway. Measured against the live API, that was
189
+ // too wide — only the Opus 5 family rejects it:
190
+ //
191
+ // claude-opus-5 + disabled + max -> 400 "not supported when thinking is disabled"
192
+ // claude-sonnet-5 + disabled + max -> accepted
193
+ // claude-opus-4-8 + disabled + max -> accepted
194
+ //
195
+ // So the blanket rule was dropping an effort the caller asked for and
196
+ // the wire would have honoured. Looking incoherent is not the same as
197
+ // being rejected, and only the wire decides which.
198
+ const opus5 = resolveThinkingCapability('claude-opus-5')
199
+ expect(resolveEffort('max', { type: 'disabled' }, opus5)).toBeUndefined()
200
+ expect(resolveEffort('xhigh', { type: 'disabled' }, opus5)).toBeUndefined()
201
+ expect(resolveEffort('high', { type: 'disabled' }, opus5)).toBe('high')
202
+ // …and uncapped with thinking on, on the same model.
203
+ expect(resolveEffort('max', { type: 'adaptive' }, opus5)).toBe('max')
204
+
205
+ // `adaptiveOnly` here is Sonnet 5, which the wire does not cap.
206
+ expect(resolveEffort('max', { type: 'disabled' }, adaptiveOnly)).toBe('max')
207
+ })
208
+
209
+ it('drops a level this model does not have', () => {
210
+ // The ceiling moved twice, so "does this model take effort?" was never
211
+ // a yes/no question. While it was modelled as one, `xhigh` on a 4.6 and
212
+ // `max` on a 4.5 went to the wire, and the vendor rejects an unknown
213
+ // level rather than clamping it.
214
+ const v46 = resolveThinkingCapability('claude-opus-4-6')
215
+ expect(resolveEffort('xhigh', { type: 'adaptive' }, v46)).toBeUndefined()
216
+ expect(resolveEffort('max', { type: 'adaptive' }, v46)).toBe('max')
217
+
218
+ const opus45 = resolveThinkingCapability('claude-opus-4-5')
219
+ expect(resolveEffort('max', { type: 'enabled' }, opus45)).toBeUndefined()
220
+ expect(resolveEffort('xhigh', { type: 'enabled' }, opus45)).toBeUndefined()
221
+ expect(resolveEffort('high', { type: 'enabled' }, opus45)).toBe('high')
222
+ })
223
+
224
+ it('takes every level on a current model', () => {
225
+ const opus5 = resolveThinkingCapability('claude-opus-5')
226
+ for (const level of ['low', 'medium', 'high', 'xhigh', 'max'] as const) {
227
+ expect(resolveEffort(level, { type: 'adaptive' }, opus5), level).toBe(level)
228
+ }
149
229
  })
150
230
  })
@@ -0,0 +1,125 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import {
4
+ resolveEffort,
5
+ resolveThinkingBody,
6
+ resolveThinkingCapability,
7
+ } from '../thinking-capability.js'
8
+
9
+ /**
10
+ * The capability table, checked against the wire it describes.
11
+ *
12
+ * `thinking-capability.ts` encodes which thinking modes and which `effort`
13
+ * levels each model accepts. Every version of that table so far was
14
+ * transcribed from documentation, and the last transcription was wrong twice —
15
+ * it modelled `effort` as a boolean when the accepted levels are a set, so
16
+ * `xhigh` on a 4.6 and `max` on a 4.5 were forwarded to a wire that rejects an
17
+ * unknown level rather than clamping it.
18
+ *
19
+ * A table about a wire is only as good as the wire says it is. These tests ask.
20
+ *
21
+ * Skipped without a key. Deliberately narrow: two current models, cheap
22
+ * requests (`max_tokens: 1`), and only the rows that would silently rot.
23
+ */
24
+
25
+ const KEY = process.env.ANTHROPIC_API_KEY
26
+
27
+ /** Cheap and current: one adaptive-only model, one manual-only model. */
28
+ const ADAPTIVE_MODEL = process.env.NAMZU_WIRE_TEST_MODEL ?? 'claude-sonnet-5'
29
+ const CAPPED_MODEL = 'claude-opus-5'
30
+ const MANUAL_MODEL = 'claude-haiku-4-5'
31
+
32
+ async function send(model: string, extra: Record<string, unknown>): Promise<string | true> {
33
+ const res = await fetch('https://api.anthropic.com/v1/messages', {
34
+ method: 'POST',
35
+ headers: {
36
+ 'x-api-key': KEY as string,
37
+ 'anthropic-version': '2023-06-01',
38
+ 'content-type': 'application/json',
39
+ },
40
+ body: JSON.stringify({
41
+ model,
42
+ max_tokens: 1,
43
+ messages: [{ role: 'user', content: 'hi' }],
44
+ ...extra,
45
+ }),
46
+ })
47
+ if (res.ok) return true
48
+ const body: unknown = await res.json().catch(() => ({}))
49
+ return (body as { error?: { message?: string } } | null)?.error?.message ?? `HTTP ${res.status}`
50
+ }
51
+
52
+ describe.skipIf(!KEY)('the effort levels the table claims are the ones the wire takes', () => {
53
+ it.each(['low', 'medium', 'high', 'xhigh', 'max'] as const)(
54
+ '%s is accepted on a current model, and the table says so',
55
+ async (level) => {
56
+ const capability = resolveThinkingCapability(ADAPTIVE_MODEL)
57
+ expect(capability.effort, `table omits ${level}`).toContain(level)
58
+
59
+ const resolved = resolveEffort(level, { type: 'adaptive' }, capability)
60
+ expect(resolved, 'resolver dropped a level the table allows').toBe(level)
61
+
62
+ const result = await send(ADAPTIVE_MODEL, {
63
+ thinking: { type: 'adaptive' },
64
+ output_config: { effort: level },
65
+ })
66
+ expect(result).toBe(true)
67
+ },
68
+ 120_000,
69
+ )
70
+
71
+ it('drops effort on a model that takes none, and the wire agrees it would have failed', async () => {
72
+ const capability = resolveThinkingCapability(MANUAL_MODEL)
73
+ expect(capability.effort).toEqual([])
74
+ expect(resolveEffort('high', { type: 'enabled' }, capability)).toBeUndefined()
75
+
76
+ // The half that matters: had the resolver NOT dropped it, this is what
77
+ // the wire would have said. A table claiming "no effort here" is only
78
+ // worth something if sending effort really does fail.
79
+ const result = await send(MANUAL_MODEL, { output_config: { effort: 'high' } })
80
+ expect(result).not.toBe(true)
81
+ }, 120_000)
82
+ })
83
+
84
+ describe.skipIf(!KEY)('the thinking body the resolver builds is one the wire accepts', () => {
85
+ it('adaptive, on a model the table calls adaptive-only', async () => {
86
+ const capability = resolveThinkingCapability(ADAPTIVE_MODEL)
87
+ expect(capability.adaptive).toBe(true)
88
+
89
+ const body = resolveThinkingBody({ type: 'adaptive' }, capability)
90
+ expect(await send(ADAPTIVE_MODEL, { thinking: body })).toBe(true)
91
+ }, 120_000)
92
+
93
+ it('rewrites a manual intent rather than sending one the model refuses', async () => {
94
+ // The resolver turns `enabled` into `adaptive` where manual is rejected.
95
+ // If it did not, this is the request that would go out — so both halves
96
+ // are asserted: what we send is accepted, and what we avoided is not.
97
+ const capability = resolveThinkingCapability(ADAPTIVE_MODEL)
98
+ const body = resolveThinkingBody({ type: 'enabled', budgetTokens: 2048 }, capability)
99
+ expect(body).toEqual({ type: 'adaptive' })
100
+
101
+ expect(await send(ADAPTIVE_MODEL, { thinking: body })).toBe(true)
102
+ expect(
103
+ await send(ADAPTIVE_MODEL, { thinking: { type: 'enabled', budget_tokens: 2048 } }),
104
+ ).not.toBe(true)
105
+ }, 120_000)
106
+
107
+ it('caps effort with thinking off only where the wire actually caps it', async () => {
108
+ // Both directions, because the first version of this rule was too wide.
109
+ const capped = resolveThinkingCapability(CAPPED_MODEL)
110
+ const disabledOnCapped = resolveThinkingBody({ type: 'disabled' }, capped)
111
+ expect(resolveEffort('max', disabledOnCapped, capped)).toBeUndefined()
112
+ expect(resolveEffort('high', disabledOnCapped, capped)).toBe('high')
113
+ expect(
114
+ await send(CAPPED_MODEL, { thinking: disabledOnCapped, output_config: { effort: 'max' } }),
115
+ ).not.toBe(true)
116
+
117
+ // …and a model the wire does NOT cap keeps the level the caller asked for.
118
+ const open = resolveThinkingCapability(ADAPTIVE_MODEL)
119
+ const disabledOnOpen = resolveThinkingBody({ type: 'disabled' }, open)
120
+ expect(resolveEffort('max', disabledOnOpen, open)).toBe('max')
121
+ expect(
122
+ await send(ADAPTIVE_MODEL, { thinking: disabledOnOpen, output_config: { effort: 'max' } }),
123
+ ).toBe(true)
124
+ }, 120_000)
125
+ })