@namzu/anthropic 2.0.1 → 3.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/dist/__tests__/background-delegation.live.test.d.ts +2 -0
  3. package/dist/__tests__/background-delegation.live.test.d.ts.map +1 -0
  4. package/dist/__tests__/background-delegation.live.test.js +212 -0
  5. package/dist/__tests__/background-delegation.live.test.js.map +1 -0
  6. package/dist/__tests__/thinking-capability.test.js +49 -21
  7. package/dist/__tests__/thinking-capability.test.js.map +1 -1
  8. package/dist/__tests__/thinking-contract.live.test.d.ts +2 -0
  9. package/dist/__tests__/thinking-contract.live.test.d.ts.map +1 -0
  10. package/dist/__tests__/thinking-contract.live.test.js +97 -0
  11. package/dist/__tests__/thinking-contract.live.test.js.map +1 -0
  12. package/dist/__tests__/wire-contract.live.test.d.ts +2 -0
  13. package/dist/__tests__/wire-contract.live.test.d.ts.map +1 -0
  14. package/dist/__tests__/wire-contract.live.test.js +254 -0
  15. package/dist/__tests__/wire-contract.live.test.js.map +1 -0
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +15 -3
  18. package/dist/client.js.map +1 -1
  19. package/dist/thinking-capability.d.ts +26 -6
  20. package/dist/thinking-capability.d.ts.map +1 -1
  21. package/dist/thinking-capability.js +73 -16
  22. package/dist/thinking-capability.js.map +1 -1
  23. package/package.json +3 -3
  24. package/src/__tests__/background-delegation.live.test.ts +243 -0
  25. package/src/__tests__/thinking-capability.test.ts +51 -22
  26. package/src/__tests__/thinking-contract.live.test.ts +125 -0
  27. package/src/__tests__/wire-contract.live.test.ts +312 -0
  28. package/src/client.ts +18 -2
  29. package/src/thinking-capability.ts +89 -16
@@ -0,0 +1,312 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import {
4
+ findDraft07Only,
5
+ findStrictSchemaViolations,
6
+ getBuiltinTools,
7
+ renderToolSchema,
8
+ toSchemaDialect,
9
+ } from '@namzu/sdk'
10
+
11
+ /**
12
+ * The test that would have caught both outages.
13
+ *
14
+ * Every other test in this repo renders a schema and asserts something about
15
+ * the object. Both production breakages were schemas that looked fine as
16
+ * objects and were rejected by the wire:
17
+ *
18
+ * - `edit.insertLine` used `oneOf`, which strict tool use refuses.
19
+ * - `read.readRange` is a Zod tuple, which renders draft-07 `items: [a, b]`
20
+ * while this wire requires draft 2020-12 — rejected with `strict` unset,
21
+ * so a guard scoped to strict never saw it.
22
+ *
23
+ * Neither could fail offline, because neither was wrong offline. So this one
24
+ * talks to the real API.
25
+ *
26
+ * It asks the cheapest question that still exercises schema validation:
27
+ * `max_tokens: 1` and a one-word prompt. Validation happens before generation,
28
+ * so a rejected schema costs nothing and an accepted one costs a single token.
29
+ *
30
+ * Skipped without a key, so CI stays green where none is configured. Run it
31
+ * with:
32
+ *
33
+ * ANTHROPIC_API_KEY=… pnpm --filter @namzu/anthropic test
34
+ */
35
+
36
+ const KEY = process.env.ANTHROPIC_API_KEY
37
+ const MODEL = process.env.NAMZU_WIRE_TEST_MODEL ?? 'claude-haiku-4-5'
38
+
39
+ interface WireResult {
40
+ readonly ok: boolean
41
+ readonly status: number
42
+ readonly message: string
43
+ }
44
+
45
+ async function offerTools(tools: unknown[]): Promise<WireResult> {
46
+ const res = await fetch('https://api.anthropic.com/v1/messages', {
47
+ method: 'POST',
48
+ headers: {
49
+ 'x-api-key': KEY as string,
50
+ 'anthropic-version': '2023-06-01',
51
+ 'content-type': 'application/json',
52
+ },
53
+ body: JSON.stringify({
54
+ model: MODEL,
55
+ max_tokens: 1,
56
+ messages: [{ role: 'user', content: 'hi' }],
57
+ tools,
58
+ }),
59
+ })
60
+ const body: unknown = await res.json().catch(() => ({}))
61
+ const message =
62
+ (body as { error?: { message?: string } } | null)?.error?.message ?? (res.ok ? '' : 'unknown')
63
+ return { ok: res.ok, status: res.status, message }
64
+ }
65
+
66
+ /** A tool as this driver would put it on the wire. */
67
+ function wireTool(name: string, schema: Record<string, unknown>, strict: boolean): unknown {
68
+ return {
69
+ name,
70
+ description: 'contract probe',
71
+ input_schema: toSchemaDialect(schema, '2020-12'),
72
+ ...(strict ? { strict: true } : {}),
73
+ }
74
+ }
75
+
76
+ describe.skipIf(!KEY)('every shipped tool is expressible on this wire', () => {
77
+ const tools = getBuiltinTools()
78
+
79
+ it('offers all of them in one request, the way a real run does', async () => {
80
+ // One request with the whole toolset, because that is the shape that
81
+ // broke: the wire rejects the WHOLE request for one bad schema, so a
82
+ // per-tool loop would pass while a real run still died.
83
+ const payload = tools.map((t) =>
84
+ wireTool(
85
+ t.name,
86
+ (t.modelInputSchema as Record<string, unknown> | undefined) ??
87
+ renderToolSchema(t.inputSchema),
88
+ Boolean(t.enforceModelInput),
89
+ ),
90
+ )
91
+
92
+ const result = await offerTools(payload)
93
+ expect(result.ok, `HTTP ${result.status}: ${result.message}`).toBe(true)
94
+ }, 180_000)
95
+
96
+ it.each(tools.map((t) => [t.name, t] as const))(
97
+ '%s alone',
98
+ async (name, tool) => {
99
+ // And individually, so a failure names the tool instead of the batch.
100
+ const schema =
101
+ (tool.modelInputSchema as Record<string, unknown> | undefined) ??
102
+ renderToolSchema(tool.inputSchema)
103
+ const result = await offerTools([wireTool(name, schema, Boolean(tool.enforceModelInput))])
104
+ expect(result.ok, `HTTP ${result.status}: ${result.message}`).toBe(true)
105
+ },
106
+ 180_000,
107
+ )
108
+ })
109
+
110
+ describe.skipIf(!KEY)('the dialect conversion is what makes the difference', () => {
111
+ it('rejects the draft-07 tuple and accepts the converted one', async () => {
112
+ // Pins the actual mechanism rather than trusting that conversion helped.
113
+ // If the wire ever starts accepting draft-07 tuples this test says so,
114
+ // and if it ever stops accepting `prefixItems` it says that too.
115
+ const draft07 = {
116
+ type: 'object',
117
+ properties: {
118
+ range: {
119
+ type: 'array',
120
+ minItems: 2,
121
+ maxItems: 2,
122
+ items: [{ type: 'integer' }, { type: 'integer' }],
123
+ },
124
+ },
125
+ }
126
+
127
+ const before = await offerTools([{ name: 'probe', description: 'p', input_schema: draft07 }])
128
+ expect(before.ok).toBe(false)
129
+ expect(before.message).toMatch(/2020-12/)
130
+
131
+ const after = await offerTools([
132
+ { name: 'probe', description: 'p', input_schema: toSchemaDialect(draft07, '2020-12') },
133
+ ])
134
+ expect(after.ok, `HTTP ${after.status}: ${after.message}`).toBe(true)
135
+ }, 180_000)
136
+ })
137
+
138
+ /**
139
+ * The strict subset, measured rather than read.
140
+ *
141
+ * `findStrictSchemaViolations` carries a deny-list, and the first version of it
142
+ * was derived from prose. It was wrong in both directions: it refused
143
+ * `minLength`/`maxLength`, which this wire accepts, so it would have blocked
144
+ * working tools; and it permitted `prefixItems`, which this wire rejects, so it
145
+ * would have vouched for a broken one. A deny-list nobody probed is a guess in
146
+ * a confident tone.
147
+ *
148
+ * This block is where the list comes from. Each row is one request; a row that
149
+ * changes means the subset moved, and the deny-list has to move with it.
150
+ */
151
+ const STRICT_SUBSET: readonly (readonly [string, Record<string, unknown>, boolean])[] = [
152
+ ['minLength/maxLength', { type: 'string', minLength: 1, maxLength: 9 }, true],
153
+ ['pattern', { type: 'string', pattern: '^a+$' }, true],
154
+ ['format', { type: 'string', format: 'uri' }, true],
155
+ ['enum', { type: 'string', enum: ['a', 'b'] }, true],
156
+ ['anyOf', { anyOf: [{ type: 'integer' }, { const: 'end' }] }, true],
157
+ // `minItems` is a bound on the VALUE, not a rejected keyword: 0 and 1 pass,
158
+ // anything above does not. A blanket denial would refuse the ordinary
159
+ // spelling of a non-empty array.
160
+ ['minItems: 0', { type: 'array', items: { type: 'string' }, minItems: 0 }, true],
161
+ ['minItems: 1', { type: 'array', items: { type: 'string' }, minItems: 1 }, true],
162
+ ['minItems: 2', { type: 'array', items: { type: 'string' }, minItems: 2 }, false],
163
+ ['maxItems', { type: 'array', items: { type: 'string' }, maxItems: 3 }, false],
164
+ ['uniqueItems', { type: 'array', items: { type: 'string' }, uniqueItems: true }, false],
165
+ ['minimum', { type: 'integer', minimum: 0 }, false],
166
+ ['oneOf', { oneOf: [{ type: 'integer' }, { const: 'end' }] }, false],
167
+ ['not', { not: { type: 'null' } }, false],
168
+ // The one that interacts with the dialect fix: a tuple is unexpressible
169
+ // under strict in EITHER spelling, so converting it only changes the error.
170
+ ['prefixItems', { type: 'array', prefixItems: [{ type: 'integer' }] }, false],
171
+ ]
172
+
173
+ describe.skipIf(!KEY)('the strict subset is what the deny-list says it is', () => {
174
+ it.each(STRICT_SUBSET.map(([label, schema, accepted]) => [label, schema, accepted] as const))(
175
+ 'strict + %s',
176
+ async (label, propSchema, accepted) => {
177
+ const result = await offerTools([
178
+ {
179
+ name: 'probe',
180
+ description: 'p',
181
+ strict: true,
182
+ input_schema: {
183
+ type: 'object',
184
+ properties: { f: propSchema },
185
+ required: ['f'],
186
+ additionalProperties: false,
187
+ },
188
+ },
189
+ ])
190
+ expect(result.ok, `${label}: HTTP ${result.status}: ${result.message}`).toBe(accepted)
191
+
192
+ // And the offline check has to agree with the wire, which is the
193
+ // whole point of pinning both in one place.
194
+ expect(findStrictSchemaViolations({ properties: { f: propSchema } }).length === 0).toBe(
195
+ accepted,
196
+ )
197
+ },
198
+ 180_000,
199
+ )
200
+
201
+ it('rejects the draft-07 tuple before it ever gets to the strict question', async () => {
202
+ // Dialect first, subset second. This is why a guard scoped to strict
203
+ // could not have caught `read.readRange`: the tuple is refused with
204
+ // `strict` unset too.
205
+ const tuple = {
206
+ type: 'object',
207
+ properties: { f: { type: 'array', items: [{ type: 'integer' }, { type: 'integer' }] } },
208
+ }
209
+ const result = await offerTools([{ name: 'probe', description: 'p', input_schema: tuple }])
210
+
211
+ expect(result.ok).toBe(false)
212
+ expect(result.message).toMatch(/2020-12/)
213
+ }, 180_000)
214
+ })
215
+
216
+ describe.skipIf(!KEY)('the positional shape a bridged tool now emits', () => {
217
+ it('is accepted once converted', async () => {
218
+ // The MCP adapter emits a tuple ONLY where the server pinned the arity
219
+ // and closed the tail, because that renders as bounded `prefixItems`.
220
+ // The narrowness is the design rather than caution: a tool schema this
221
+ // wire refuses fails the WHOLE request instead of degrading one tool,
222
+ // so a faithful conversion it will not take is strictly worse than a
223
+ // lossy one it will.
224
+ //
225
+ // The refusal half of this pair is already asserted above, on the
226
+ // unconverted spelling — so this says something the sweep does not:
227
+ // that the shape we CHOSE to emit is one the wire takes.
228
+ const pinned = {
229
+ type: 'object',
230
+ properties: {
231
+ pair: {
232
+ type: 'array',
233
+ minItems: 2,
234
+ maxItems: 2,
235
+ items: [{ type: 'string' }, { type: 'number' }],
236
+ },
237
+ },
238
+ required: ['pair'],
239
+ additionalProperties: false,
240
+ }
241
+
242
+ const result = await offerTools([wireTool('pinned_pair', pinned, false)])
243
+ expect(result.ok, result.message).toBe(true)
244
+ }, 180_000)
245
+ })
246
+
247
+ describe.skipIf(!KEY)('effort is a per-model SET, and this wire says so itself', () => {
248
+ async function withEffort(model: string, effort: string): Promise<WireResult> {
249
+ const res = await fetch('https://api.anthropic.com/v1/messages', {
250
+ method: 'POST',
251
+ headers: {
252
+ 'x-api-key': KEY as string,
253
+ 'anthropic-version': '2023-06-01',
254
+ 'content-type': 'application/json',
255
+ },
256
+ body: JSON.stringify({
257
+ model,
258
+ max_tokens: 16,
259
+ messages: [{ role: 'user', content: 'Say OK.' }],
260
+ output_config: { effort },
261
+ }),
262
+ })
263
+ const body: unknown = await res.json().catch(() => ({}))
264
+ const message =
265
+ (body as { error?: { message?: string } } | null)?.error?.message ?? (res.ok ? '' : 'unknown')
266
+ return { ok: res.ok, status: res.status, message }
267
+ }
268
+
269
+ it('takes all five levels on a model the table says has all five', async () => {
270
+ for (const effort of ['low', 'medium', 'high', 'xhigh', 'max']) {
271
+ const result = await withEffort('claude-sonnet-5', effort)
272
+ expect(result.ok, `${effort}: ${result.message}`).toBe(true)
273
+ }
274
+ }, 180_000)
275
+
276
+ it('refuses a level a model lacks, and names the set it has', async () => {
277
+ // The pairing the capability table exists to express: `max` WITHOUT
278
+ // `xhigh`. A boolean could not have said this, and reading the levels
279
+ // as a ladder — where anything taking the top rung takes the one below
280
+ // — gets it backwards. That reading is how a row in that table came to
281
+ // claim a level this wire rejects.
282
+ const refused = await withEffort('claude-sonnet-4-6', 'xhigh')
283
+ expect(refused.ok).toBe(false)
284
+ expect(refused.message).toContain('xhigh')
285
+
286
+ const accepted = await withEffort('claude-sonnet-4-6', 'max')
287
+ expect(accepted.ok, accepted.message).toBe(true)
288
+ }, 180_000)
289
+ })
290
+
291
+ describe('what can be checked without a key', () => {
292
+ it('leaves no draft-07-only construct in any shipped tool', () => {
293
+ // The offline half of the same guarantee, so a contributor without a
294
+ // key still gets the signal — just not the proof.
295
+ for (const tool of getBuiltinTools()) {
296
+ const schema =
297
+ (tool.modelInputSchema as Record<string, unknown> | undefined) ??
298
+ renderToolSchema(tool.inputSchema)
299
+ const converted = toSchemaDialect(schema, '2020-12')
300
+ expect(findDraft07Only(converted), tool.name).toEqual([])
301
+ }
302
+ })
303
+
304
+ it('still finds one before conversion, so the sweep is not vacuous', () => {
305
+ // `read` renders a Zod tuple. If this ever stops finding anything, the
306
+ // test above has quietly become a tautology.
307
+ const withTuple = getBuiltinTools().filter(
308
+ (t) => !t.modelInputSchema && findDraft07Only(renderToolSchema(t.inputSchema)).length > 0,
309
+ )
310
+ expect(withTuple.map((t) => t.name)).toContain('read')
311
+ })
312
+ })
package/src/client.ts CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  isProviderRequestError,
21
21
  modelVersionAtLeast,
22
22
  providerVendorError,
23
+ toSchemaDialect,
23
24
  toolResultToText,
24
25
  } from '@namzu/sdk'
25
26
  import {
@@ -375,7 +376,16 @@ function toAnthropicTools(
375
376
  return {
376
377
  name: t.function.name,
377
378
  description: t.function.description ?? '',
378
- input_schema: t.function.parameters ?? { type: 'object' },
379
+ // This wire parses draft 2020-12, and the renderer emits draft-07.
380
+ // The two disagree about tuples — draft-07 puts the positional
381
+ // schemas in `items`, 2020-12 in `prefixItems` — and the wire
382
+ // rejects the WHOLE request for it, not the one field. Converting
383
+ // here rather than in the renderer keeps the dialect where the
384
+ // knowledge is: only this file knows which wire it is talking to.
385
+ input_schema: toSchemaDialect(
386
+ (t.function.parameters as Record<string, unknown> | undefined) ?? { type: 'object' },
387
+ '2020-12',
388
+ ),
379
389
  ...(strict ? { strict: true } : {}),
380
390
  }
381
391
  })
@@ -730,7 +740,13 @@ export class AnthropicProvider implements LLMProvider {
730
740
  // A sibling of `thinking`, not a field inside it — and gated on the
731
741
  // model, since only some accept it at all.
732
742
  const effort = resolveEffort(params.effort, thinkingBody, capability)
733
- if (effort) body.output_config = { effort }
743
+ // Merged rather than assigned. `output_config` is a shared envelope on
744
+ // this wire — a structured-output format and a task budget live in it
745
+ // too, and `responseFormat` already exists on the params unhandled
746
+ // here. Assigning would mean whoever wires the next one silently
747
+ // deletes effort, or has effort silently delete theirs, depending only
748
+ // on which line ran last.
749
+ if (effort) body.output_config = { ...(body.output_config as object | undefined), effort }
734
750
  if (params.temperature !== undefined) body.temperature = params.temperature
735
751
  if (params.topP !== undefined) body.top_p = params.topP
736
752
  if (params.topK !== undefined) body.top_k = params.topK
@@ -57,6 +57,21 @@ export interface ThinkingCapability {
57
57
  readonly canDisable: boolean
58
58
  /** Which `effort` levels this model accepts; empty means none. */
59
59
  readonly effort: EffortLevels
60
+ /**
61
+ * The levels still accepted when thinking is switched off.
62
+ *
63
+ * Usually the same set. The Opus 5 family is the exception: it refuses
64
+ * `xhigh` and `max` alongside `thinking: {type:"disabled"}` — *"effort 'max'
65
+ * is not supported when thinking is disabled"* — while accepting `high`.
66
+ *
67
+ * This started as a blanket rule applied to every model that can disable
68
+ * thinking, on the reasoning that the pairing is incoherent anyway. Measured,
69
+ * that was too wide: Sonnet 5 and Opus 4.8 both accept `disabled` + `max`,
70
+ * so the blanket rule was silently dropping an effort the caller asked for
71
+ * and the wire would have honoured. Incoherent-looking is not the same as
72
+ * rejected, and only the wire gets to say which.
73
+ */
74
+ readonly effortWhenDisabled: EffortLevels
60
75
  }
61
76
 
62
77
  const MANUAL_ONLY: ThinkingCapability = {
@@ -64,6 +79,7 @@ const MANUAL_ONLY: ThinkingCapability = {
64
79
  manual: true,
65
80
  canDisable: true,
66
81
  effort: NO_EFFORT,
82
+ effortWhenDisabled: NO_EFFORT,
67
83
  }
68
84
 
69
85
  /**
@@ -91,7 +107,34 @@ export function resolveThinkingCapability(model: string): ThinkingCapability {
91
107
  // parser can compare, and it is the one model supporting both modes while
92
108
  // refusing to be switched off.
93
109
  if (/^(?:anthropic\/)?claude-mythos-preview$/.test(normalized)) {
94
- return { adaptive: true, manual: true, canDisable: false, effort: FULL_EFFORT }
110
+ return {
111
+ adaptive: true,
112
+ manual: true,
113
+ canDisable: false,
114
+ // `max` but NOT `xhigh` — the combination it is easy to assume
115
+ // away, because reading the levels as a ladder makes anything
116
+ // accepting the top rung look like it accepts the one below. That
117
+ // reading is what put all five levels on this row, and it sends a
118
+ // level the wire refuses.
119
+ //
120
+ // SOURCED, NOT MEASURED, and the distinction is recorded because
121
+ // this file has been wrong from exactly this evidence class
122
+ // before. The reference states this model's availability twice: it
123
+ // is in the `max` list both times and in the `xhigh` list neither,
124
+ // and it says outright that some models supporting `max` do not
125
+ // support `xhigh`. The model is not reachable from the tenant used
126
+ // for the live contract suite (404), so no probe can confirm it
127
+ // here.
128
+ //
129
+ // What IS measured is that the pairing exists and this wire reports
130
+ // it exactly this way — `claude-sonnet-4-6` answers `xhigh` with
131
+ // "This model does not support effort level 'xhigh'. Supported
132
+ // levels: high, low, max, medium." and accepts `max`. So the row
133
+ // below is not a guess about a shape nobody has seen; it is a
134
+ // documented instance of a shape the wire demonstrably has.
135
+ effort: EFFORT_WITHOUT_XHIGH,
136
+ effortWhenDisabled: EFFORT_WITHOUT_XHIGH,
137
+ }
95
138
  }
96
139
 
97
140
  const parsed = parseVersionedModelId(model, MODEL_ID_GRAMMAR)
@@ -101,17 +144,42 @@ export function resolveThinkingCapability(model: string): ThinkingCapability {
101
144
 
102
145
  // Always-on families: thinking cannot be disabled at any version.
103
146
  if (family === 'fable' || family === 'mythos') {
104
- return { adaptive: true, manual: false, canDisable: false, effort: FULL_EFFORT }
147
+ return {
148
+ adaptive: true,
149
+ manual: false,
150
+ canDisable: false,
151
+ effort: FULL_EFFORT,
152
+ effortWhenDisabled: FULL_EFFORT,
153
+ }
105
154
  }
106
155
 
107
156
  // 4.7 and later dropped manual mode outright.
108
157
  if (major > 4 || (major === 4 && minor >= 7)) {
109
- return { adaptive: true, manual: false, canDisable: true, effort: FULL_EFFORT }
158
+ // The Opus 5 family alone caps effort while thinking is off. Measured,
159
+ // not inferred: `claude-opus-5` refuses `disabled` + `xhigh`/`max` and
160
+ // accepts `disabled` + `high`, while `claude-sonnet-5` and
161
+ // `claude-opus-4-8` accept `disabled` + `max`. A version comparison of
162
+ // "5 and later" would have caught Sonnet 5 too and dropped an effort
163
+ // that wire honours.
164
+ const opus5Plus = family === 'opus' && major >= 5
165
+ return {
166
+ adaptive: true,
167
+ manual: false,
168
+ canDisable: true,
169
+ effort: FULL_EFFORT,
170
+ effortWhenDisabled: opus5Plus ? EFFORT_BASE : FULL_EFFORT,
171
+ }
110
172
  }
111
173
 
112
174
  // 4.6 accepts both; manual is deprecated there but still functional.
113
175
  if (major === 4 && minor === 6) {
114
- return { adaptive: true, manual: true, canDisable: true, effort: EFFORT_WITHOUT_XHIGH }
176
+ return {
177
+ adaptive: true,
178
+ manual: true,
179
+ canDisable: true,
180
+ effort: EFFORT_WITHOUT_XHIGH,
181
+ effortWhenDisabled: EFFORT_WITHOUT_XHIGH,
182
+ }
115
183
  }
116
184
 
117
185
  // 4.5 and earlier are manual-only. Opus 4.5 is the one that also takes
@@ -119,7 +187,8 @@ export function resolveThinkingCapability(model: string): ThinkingCapability {
119
187
  // takes only the first three levels: `xhigh` did not exist yet and `max`
120
188
  // is rejected there.
121
189
  const isOpus45 = family === 'opus' && major === 4 && minor === 5
122
- return { ...MANUAL_ONLY, effort: isOpus45 ? EFFORT_BASE : NO_EFFORT }
190
+ const base = isOpus45 ? EFFORT_BASE : NO_EFFORT
191
+ return { ...MANUAL_ONLY, effort: base, effortWhenDisabled: base }
123
192
  }
124
193
 
125
194
  /** The `thinking` body value, or `undefined` to send no thinking field. */
@@ -189,21 +258,25 @@ export function resolveThinkingBody(
189
258
  * request without it is the same request at the model's own default, whereas
190
259
  * refusing would fail a call that has a correct answer.
191
260
  *
192
- * The COMBINATION has to be legal. On Opus 5 and later,
193
- * `thinking: {type: "disabled"}` is accepted at effort `high` or below and
194
- * **rejected at `xhigh`/`max`**, enforced per request. Rather than encode
195
- * "Opus 5 and later" as a second version comparison, this refuses the pairing
196
- * on every model that can disable thinking — it is incoherent anyway, since it
197
- * asks a model not to think and then to think as hard as possible.
261
+ * The COMBINATION has to be legal, and the legal set is per model rather than
262
+ * universal. Opus 5 accepts `thinking: {type: "disabled"}` at `high` or below
263
+ * and **rejects it at `xhigh`/`max`** — so this asks the capability for the set
264
+ * that applies when thinking is off, instead of the set that applies generally.
265
+ *
266
+ * That distinction was earned. The rule started as a blanket refusal on every
267
+ * model that can disable thinking, on the reasoning that the pairing is
268
+ * incoherent anyway — asking a model not to think and then to think as hard as
269
+ * possible. Measured, Sonnet 5 and Opus 4.8 both accept it, so the blanket rule
270
+ * was discarding an effort the caller asked for and the wire would have
271
+ * honoured. Incoherent-looking is not the same as rejected.
198
272
  */
199
273
  export function resolveEffort(
200
274
  effort: ReasoningEffort | undefined,
201
275
  thinkingBody: ResolvedThinkingBody,
202
276
  capability: ThinkingCapability,
203
277
  ): ReasoningEffort | undefined {
204
- if (effort === undefined || !capability.effort.includes(effort)) return undefined
205
- if (thinkingBody?.type === 'disabled' && (effort === 'xhigh' || effort === 'max')) {
206
- return undefined
207
- }
208
- return effort
278
+ if (effort === undefined) return undefined
279
+ const allowed =
280
+ thinkingBody?.type === 'disabled' ? capability.effortWhenDisabled : capability.effort
281
+ return allowed.includes(effort) ? effort : undefined
209
282
  }