@namzu/anthropic 3.0.1 → 3.1.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 (77) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/dist/client.d.ts +15 -1
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +18 -0
  5. package/dist/client.js.map +1 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +8 -0
  9. package/dist/index.js.map +1 -1
  10. package/package.json +12 -2
  11. package/src/client.ts +21 -0
  12. package/src/index.ts +18 -0
  13. package/dist/__tests__/anthropic.test.d.ts +0 -2
  14. package/dist/__tests__/anthropic.test.d.ts.map +0 -1
  15. package/dist/__tests__/anthropic.test.js +0 -425
  16. package/dist/__tests__/anthropic.test.js.map +0 -1
  17. package/dist/__tests__/background-delegation.live.test.d.ts +0 -2
  18. package/dist/__tests__/background-delegation.live.test.d.ts.map +0 -1
  19. package/dist/__tests__/background-delegation.live.test.js +0 -212
  20. package/dist/__tests__/background-delegation.live.test.js.map +0 -1
  21. package/dist/__tests__/block-shape-guard.test.d.ts +0 -2
  22. package/dist/__tests__/block-shape-guard.test.d.ts.map +0 -1
  23. package/dist/__tests__/block-shape-guard.test.js +0 -218
  24. package/dist/__tests__/block-shape-guard.test.js.map +0 -1
  25. package/dist/__tests__/cache-anchors.test.d.ts +0 -2
  26. package/dist/__tests__/cache-anchors.test.d.ts.map +0 -1
  27. package/dist/__tests__/cache-anchors.test.js +0 -220
  28. package/dist/__tests__/cache-anchors.test.js.map +0 -1
  29. package/dist/__tests__/citations.test.d.ts +0 -2
  30. package/dist/__tests__/citations.test.d.ts.map +0 -1
  31. package/dist/__tests__/citations.test.js +0 -189
  32. package/dist/__tests__/citations.test.js.map +0 -1
  33. package/dist/__tests__/content-blocks.test.d.ts +0 -2
  34. package/dist/__tests__/content-blocks.test.d.ts.map +0 -1
  35. package/dist/__tests__/content-blocks.test.js +0 -131
  36. package/dist/__tests__/content-blocks.test.js.map +0 -1
  37. package/dist/__tests__/document-input.test.d.ts +0 -2
  38. package/dist/__tests__/document-input.test.d.ts.map +0 -1
  39. package/dist/__tests__/document-input.test.js +0 -98
  40. package/dist/__tests__/document-input.test.js.map +0 -1
  41. package/dist/__tests__/error-taxonomy.test.d.ts +0 -16
  42. package/dist/__tests__/error-taxonomy.test.d.ts.map +0 -1
  43. package/dist/__tests__/error-taxonomy.test.js +0 -242
  44. package/dist/__tests__/error-taxonomy.test.js.map +0 -1
  45. package/dist/__tests__/reasoning-close.test.d.ts +0 -2
  46. package/dist/__tests__/reasoning-close.test.d.ts.map +0 -1
  47. package/dist/__tests__/reasoning-close.test.js +0 -219
  48. package/dist/__tests__/reasoning-close.test.js.map +0 -1
  49. package/dist/__tests__/thinking-capability.test.d.ts +0 -2
  50. package/dist/__tests__/thinking-capability.test.d.ts.map +0 -1
  51. package/dist/__tests__/thinking-capability.test.js +0 -206
  52. package/dist/__tests__/thinking-capability.test.js.map +0 -1
  53. package/dist/__tests__/thinking-contract.live.test.d.ts +0 -2
  54. package/dist/__tests__/thinking-contract.live.test.d.ts.map +0 -1
  55. package/dist/__tests__/thinking-contract.live.test.js +0 -97
  56. package/dist/__tests__/thinking-contract.live.test.js.map +0 -1
  57. package/dist/__tests__/thinking-request-body.test.d.ts +0 -2
  58. package/dist/__tests__/thinking-request-body.test.d.ts.map +0 -1
  59. package/dist/__tests__/thinking-request-body.test.js +0 -90
  60. package/dist/__tests__/thinking-request-body.test.js.map +0 -1
  61. package/dist/__tests__/wire-contract.live.test.d.ts +0 -2
  62. package/dist/__tests__/wire-contract.live.test.d.ts.map +0 -1
  63. package/dist/__tests__/wire-contract.live.test.js +0 -254
  64. package/dist/__tests__/wire-contract.live.test.js.map +0 -1
  65. package/src/__tests__/anthropic.test.ts +0 -490
  66. package/src/__tests__/background-delegation.live.test.ts +0 -243
  67. package/src/__tests__/block-shape-guard.test.ts +0 -256
  68. package/src/__tests__/cache-anchors.test.ts +0 -262
  69. package/src/__tests__/citations.test.ts +0 -218
  70. package/src/__tests__/content-blocks.test.ts +0 -153
  71. package/src/__tests__/document-input.test.ts +0 -131
  72. package/src/__tests__/error-taxonomy.test.ts +0 -274
  73. package/src/__tests__/reasoning-close.test.ts +0 -262
  74. package/src/__tests__/thinking-capability.test.ts +0 -235
  75. package/src/__tests__/thinking-contract.live.test.ts +0 -125
  76. package/src/__tests__/thinking-request-body.test.ts +0 -111
  77. package/src/__tests__/wire-contract.live.test.ts +0 -312
@@ -1,235 +0,0 @@
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 driver mapped `enabled` straight through and everything else to
11
- * `disabled`. On a current model that is not a degraded request, it is a
12
- * failed one: `thinking.type.enabled` is rejected with a 400 from 4.7 onward,
13
- * `adaptive` is rejected on 4.5 and earlier, and the always-on models reject
14
- * `disabled`.
15
- *
16
- * The table below is transcribed from the vendor's per-model reference, one
17
- * case per row, because that table IS the specification — a summary of it in
18
- * prose would be the thing that drifts.
19
- */
20
-
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
- // The preview takes `max` and NOT `xhigh`, which is the pairing it is easy
42
- // to assume away — the reference says outright that some models supporting
43
- // `max` do not support `xhigh`, and this is one. Reading the levels as a
44
- // ladder is what put ALL on this row originally, and a ladder reading sends
45
- // a level the wire rejects.
46
- ['claude-mythos-preview', true, true, false, NO_XHIGH, NO_XHIGH],
47
- // 4.7 and later: adaptive only, and it can still be disabled.
48
- ['claude-opus-5', true, false, true, ALL, CAPPED],
49
- ['claude-sonnet-5', true, false, true, ALL, ALL],
50
- ['claude-opus-4-8', true, false, true, ALL, ALL],
51
- ['claude-opus-4-7', true, false, true, ALL, ALL],
52
- // 4.6: both modes, manual deprecated but working — and no `xhigh`.
53
- ['claude-opus-4-6', true, true, true, NO_XHIGH, NO_XHIGH],
54
- ['claude-sonnet-4-6', true, true, true, NO_XHIGH, NO_XHIGH],
55
- // 4.5 and earlier: manual only. Opus 4.5 is the one that takes effort,
56
- // and only the first three levels.
57
- ['claude-opus-4-5', false, true, true, BASE, BASE],
58
- ['claude-haiku-4-5', false, true, true, NONE, NONE],
59
- ['claude-sonnet-4-5', false, true, true, NONE, NONE],
60
- ['claude-opus-4-1', false, true, true, NONE, NONE],
61
- ]
62
-
63
- describe('what each model accepts', () => {
64
- for (const [model, adaptive, manual, canDisable, effort, effortWhenDisabled] of TABLE) {
65
- it(`resolves ${model}`, () => {
66
- expect(resolveThinkingCapability(model)).toEqual({
67
- adaptive,
68
- manual,
69
- canDisable,
70
- effort,
71
- effortWhenDisabled,
72
- })
73
- })
74
- }
75
-
76
- it('tolerates a vendor prefix and a date suffix', () => {
77
- expect(resolveThinkingCapability('anthropic/claude-sonnet-5')).toMatchObject({
78
- adaptive: true,
79
- manual: false,
80
- })
81
- expect(resolveThinkingCapability('claude-sonnet-4-5-20250929')).toMatchObject({
82
- adaptive: false,
83
- manual: true,
84
- })
85
- })
86
-
87
- it('does not read a date suffix as the minor version', () => {
88
- // The row this table did not have. Every dated id it listed carried a
89
- // REAL minor (`4-5-20250929`), so the `<family>-<major>-<DATE>` shape —
90
- // a dated id naming no minor — was never exercised, and the matcher
91
- // parsed its date as minor 20250514. That compared as enormously newer
92
- // than 4.1, so these two were classified adaptive-only and had their
93
- // caller's thinking budget silently discarded.
94
- for (const model of ['claude-sonnet-4-20250514', 'claude-opus-4-20250514']) {
95
- expect(resolveThinkingCapability(model), model).toMatchObject({
96
- adaptive: false,
97
- manual: true,
98
- })
99
- }
100
- })
101
-
102
- it('treats an unrecognised model as manual-only', () => {
103
- // The pre-existing behaviour, and the safe answer for a name this
104
- // table has not seen: an older model behind a gateway keeps working,
105
- // and a newer one fails with the vendor's own clear 400 rather than
106
- // with a request this driver quietly rewrote.
107
- expect(resolveThinkingCapability('some-gateway/mystery-model')).toEqual({
108
- adaptive: false,
109
- manual: true,
110
- canDisable: true,
111
- effort: [],
112
- effortWhenDisabled: [],
113
- })
114
- })
115
- })
116
-
117
- describe('turning an intent into a body this model accepts', () => {
118
- const adaptiveOnly = resolveThinkingCapability('claude-sonnet-5')
119
- const manualOnly = resolveThinkingCapability('claude-sonnet-4-5')
120
- const alwaysOn = resolveThinkingCapability('claude-fable-5')
121
-
122
- it('sends adaptive to an adaptive model', () => {
123
- expect(resolveThinkingBody({ type: 'adaptive' }, adaptiveOnly)).toEqual({ type: 'adaptive' })
124
- })
125
-
126
- it('rewrites a manual intent to adaptive where manual is rejected', () => {
127
- // The caller asked to think. This model's way of thinking is adaptive,
128
- // and the budget has no meaning there, so it goes.
129
- expect(resolveThinkingBody({ type: 'enabled', budgetTokens: 10_000 }, adaptiveOnly)).toEqual({
130
- type: 'adaptive',
131
- })
132
- })
133
-
134
- it('rewrites an adaptive intent to manual where adaptive is rejected', () => {
135
- expect(resolveThinkingBody({ type: 'adaptive' }, manualOnly)).toEqual({ type: 'enabled' })
136
- })
137
-
138
- it('keeps the budget on a model that has budgets', () => {
139
- expect(resolveThinkingBody({ type: 'enabled', budgetTokens: 10_000 }, manualOnly)).toEqual({
140
- type: 'enabled',
141
- budget_tokens: 10_000,
142
- })
143
- })
144
-
145
- it('carries display through, which is the whole reason thinking text arrives', () => {
146
- // It defaults to `omitted` on newer models, so a caller who wants to
147
- // show reasoning and never serializes this gets empty blocks.
148
- expect(resolveThinkingBody({ type: 'adaptive', display: 'summarized' }, adaptiveOnly)).toEqual({
149
- type: 'adaptive',
150
- display: 'summarized',
151
- })
152
- })
153
-
154
- it('omits the field entirely when a model cannot be told to stop thinking', () => {
155
- // Not an error: failing here teaches nothing the vendor 400 would not,
156
- // and it breaks a caller whose config spans models. No field means the
157
- // model's documented default, which is the closest honest reading.
158
- expect(resolveThinkingBody({ type: 'disabled' }, alwaysOn)).toBeUndefined()
159
- })
160
-
161
- it('honours disable where it is accepted', () => {
162
- expect(resolveThinkingBody({ type: 'disabled' }, adaptiveOnly)).toEqual({ type: 'disabled' })
163
- })
164
-
165
- it('sends nothing when the caller asked for nothing', () => {
166
- expect(resolveThinkingBody(undefined, adaptiveOnly)).toBeUndefined()
167
- })
168
- })
169
-
170
- describe('when effort rides along', () => {
171
- const adaptiveOnly = resolveThinkingCapability('claude-sonnet-5')
172
- const noEffort = resolveThinkingCapability('claude-sonnet-4-5')
173
-
174
- it('passes effort to a model that takes it', () => {
175
- expect(resolveEffort('high', { type: 'adaptive' }, adaptiveOnly)).toBe('high')
176
- })
177
-
178
- it('drops effort on a model that does not', () => {
179
- expect(resolveEffort('high', { type: 'enabled' }, noEffort)).toBeUndefined()
180
- })
181
-
182
- it('keeps effort on the one manual model that accepts it', () => {
183
- // Opus 4.5: effort shapes the answer, the budget sets thinking depth,
184
- // and both are meant to be set. So effort is not adaptive-only and
185
- // must not be gated on the mode.
186
- const opus45 = resolveThinkingCapability('claude-opus-4-5')
187
- expect(resolveEffort('high', { type: 'enabled', budget_tokens: 8000 }, opus45)).toBe('high')
188
- })
189
-
190
- it('caps effort with thinking off only where the wire caps it', () => {
191
- // This rule used to be blanket: thinking off at `xhigh`/`max` was
192
- // refused on every model that can disable thinking, reasoning that the
193
- // pairing is incoherent anyway. Measured against the live API, that was
194
- // too wide — only the Opus 5 family rejects it:
195
- //
196
- // claude-opus-5 + disabled + max -> 400 "not supported when thinking is disabled"
197
- // claude-sonnet-5 + disabled + max -> accepted
198
- // claude-opus-4-8 + disabled + max -> accepted
199
- //
200
- // So the blanket rule was dropping an effort the caller asked for and
201
- // the wire would have honoured. Looking incoherent is not the same as
202
- // being rejected, and only the wire decides which.
203
- const opus5 = resolveThinkingCapability('claude-opus-5')
204
- expect(resolveEffort('max', { type: 'disabled' }, opus5)).toBeUndefined()
205
- expect(resolveEffort('xhigh', { type: 'disabled' }, opus5)).toBeUndefined()
206
- expect(resolveEffort('high', { type: 'disabled' }, opus5)).toBe('high')
207
- // …and uncapped with thinking on, on the same model.
208
- expect(resolveEffort('max', { type: 'adaptive' }, opus5)).toBe('max')
209
-
210
- // `adaptiveOnly` here is Sonnet 5, which the wire does not cap.
211
- expect(resolveEffort('max', { type: 'disabled' }, adaptiveOnly)).toBe('max')
212
- })
213
-
214
- it('drops a level this model does not have', () => {
215
- // The ceiling moved twice, so "does this model take effort?" was never
216
- // a yes/no question. While it was modelled as one, `xhigh` on a 4.6 and
217
- // `max` on a 4.5 went to the wire, and the vendor rejects an unknown
218
- // level rather than clamping it.
219
- const v46 = resolveThinkingCapability('claude-opus-4-6')
220
- expect(resolveEffort('xhigh', { type: 'adaptive' }, v46)).toBeUndefined()
221
- expect(resolveEffort('max', { type: 'adaptive' }, v46)).toBe('max')
222
-
223
- const opus45 = resolveThinkingCapability('claude-opus-4-5')
224
- expect(resolveEffort('max', { type: 'enabled' }, opus45)).toBeUndefined()
225
- expect(resolveEffort('xhigh', { type: 'enabled' }, opus45)).toBeUndefined()
226
- expect(resolveEffort('high', { type: 'enabled' }, opus45)).toBe('high')
227
- })
228
-
229
- it('takes every level on a current model', () => {
230
- const opus5 = resolveThinkingCapability('claude-opus-5')
231
- for (const level of ['low', 'medium', 'high', 'xhigh', 'max'] as const) {
232
- expect(resolveEffort(level, { type: 'adaptive' }, opus5), level).toBe(level)
233
- }
234
- })
235
- })
@@ -1,125 +0,0 @@
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
- })
@@ -1,111 +0,0 @@
1
- import type { ChatCompletionParams } from '@namzu/sdk'
2
- import { describe, expect, it, vi } from 'vitest'
3
-
4
- import { AnthropicProvider } from '../client.js'
5
-
6
- /**
7
- * The resolver's own tests pass whether or not the client calls it. These
8
- * drive the real `chatStream` and read the body that would have gone on the
9
- * wire, because "declared, typed, exported, and never sent" is precisely the
10
- * defect being fixed here — `display` had been on `ThinkingConfig` all along
11
- * and the request builder dropped it.
12
- */
13
-
14
- async function bodyFor(params: Partial<ChatCompletionParams>): Promise<Record<string, unknown>> {
15
- const seen: { body?: Record<string, unknown> } = {}
16
- const provider = new AnthropicProvider({ apiKey: 'test-key' })
17
- ;(provider as unknown as { client: { messages: { create: unknown } } }).client = {
18
- messages: {
19
- create: vi.fn(async (body: Record<string, unknown>) => {
20
- seen.body = body
21
- return (async function* () {
22
- yield { type: 'message_start', message: { id: 'msg_1' } }
23
- })()
24
- }),
25
- },
26
- }
27
- for await (const _chunk of provider.chatStream({
28
- model: 'claude-sonnet-5',
29
- messages: [{ role: 'user', content: 'hi' }],
30
- ...params,
31
- } as ChatCompletionParams)) {
32
- // drain
33
- }
34
- return seen.body ?? {}
35
- }
36
-
37
- describe('the thinking configuration that reaches the wire', () => {
38
- it('sends adaptive to a model that only accepts adaptive', async () => {
39
- const body = await bodyFor({ model: 'claude-sonnet-5', thinking: { type: 'adaptive' } })
40
-
41
- expect(body.thinking).toEqual({ type: 'adaptive' })
42
- })
43
-
44
- it('does not send a manual budget to a model that rejects manual mode', async () => {
45
- // This is the failure being fixed: the old builder passed `enabled`
46
- // straight through, and the vendor answers that with a 400.
47
- const body = await bodyFor({
48
- model: 'claude-sonnet-5',
49
- thinking: { type: 'enabled', budgetTokens: 10_000 },
50
- })
51
-
52
- expect(body.thinking).toEqual({ type: 'adaptive' })
53
- expect(JSON.stringify(body)).not.toContain('budget_tokens')
54
- })
55
-
56
- it('still sends a manual budget to a manual model', async () => {
57
- const body = await bodyFor({
58
- model: 'claude-sonnet-4-5',
59
- thinking: { type: 'enabled', budgetTokens: 10_000 },
60
- })
61
-
62
- expect(body.thinking).toEqual({ type: 'enabled', budget_tokens: 10_000 })
63
- })
64
-
65
- it('serializes display, without which the thinking text comes back empty', async () => {
66
- const body = await bodyFor({
67
- model: 'claude-sonnet-5',
68
- thinking: { type: 'adaptive', display: 'summarized' },
69
- })
70
-
71
- expect(body.thinking).toEqual({ type: 'adaptive', display: 'summarized' })
72
- })
73
-
74
- it('sends effort beside thinking, not inside it', async () => {
75
- const body = await bodyFor({
76
- model: 'claude-sonnet-5',
77
- thinking: { type: 'adaptive' },
78
- effort: 'xhigh',
79
- })
80
-
81
- expect(body.output_config).toEqual({ effort: 'xhigh' })
82
- expect(body.thinking).toEqual({ type: 'adaptive' })
83
- })
84
-
85
- it('sends effort even with no thinking configuration at all', async () => {
86
- // Effort shapes the whole response, so it is not conditional on a
87
- // thinking block being present.
88
- const body = await bodyFor({ model: 'claude-sonnet-5', effort: 'low' })
89
-
90
- expect(body.output_config).toEqual({ effort: 'low' })
91
- })
92
-
93
- it('drops effort on a model that does not accept it', async () => {
94
- const body = await bodyFor({ model: 'claude-sonnet-4-5', effort: 'high' })
95
-
96
- expect(body.output_config).toBeUndefined()
97
- })
98
-
99
- it('omits thinking entirely on a model that cannot be told to stop', async () => {
100
- const body = await bodyFor({ model: 'claude-fable-5', thinking: { type: 'disabled' } })
101
-
102
- expect(body.thinking).toBeUndefined()
103
- })
104
-
105
- it('sends no thinking field when the caller configured none', async () => {
106
- const body = await bodyFor({ model: 'claude-sonnet-5' })
107
-
108
- expect(body.thinking).toBeUndefined()
109
- expect(body.output_config).toBeUndefined()
110
- })
111
- })