@namzu/anthropic 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +30 -3
- package/dist/client.js.map +1 -1
- package/package.json +12 -2
- package/src/client.ts +33 -3
- package/dist/__tests__/anthropic.test.d.ts +0 -2
- package/dist/__tests__/anthropic.test.d.ts.map +0 -1
- package/dist/__tests__/anthropic.test.js +0 -425
- package/dist/__tests__/anthropic.test.js.map +0 -1
- package/dist/__tests__/background-delegation.live.test.d.ts +0 -2
- package/dist/__tests__/background-delegation.live.test.d.ts.map +0 -1
- package/dist/__tests__/background-delegation.live.test.js +0 -212
- package/dist/__tests__/background-delegation.live.test.js.map +0 -1
- package/dist/__tests__/block-shape-guard.test.d.ts +0 -2
- package/dist/__tests__/block-shape-guard.test.d.ts.map +0 -1
- package/dist/__tests__/block-shape-guard.test.js +0 -218
- package/dist/__tests__/block-shape-guard.test.js.map +0 -1
- package/dist/__tests__/cache-anchors.test.d.ts +0 -2
- package/dist/__tests__/cache-anchors.test.d.ts.map +0 -1
- package/dist/__tests__/cache-anchors.test.js +0 -220
- package/dist/__tests__/cache-anchors.test.js.map +0 -1
- package/dist/__tests__/citations.test.d.ts +0 -2
- package/dist/__tests__/citations.test.d.ts.map +0 -1
- package/dist/__tests__/citations.test.js +0 -189
- package/dist/__tests__/citations.test.js.map +0 -1
- package/dist/__tests__/content-blocks.test.d.ts +0 -2
- package/dist/__tests__/content-blocks.test.d.ts.map +0 -1
- package/dist/__tests__/content-blocks.test.js +0 -131
- package/dist/__tests__/content-blocks.test.js.map +0 -1
- package/dist/__tests__/document-input.test.d.ts +0 -2
- package/dist/__tests__/document-input.test.d.ts.map +0 -1
- package/dist/__tests__/document-input.test.js +0 -98
- package/dist/__tests__/document-input.test.js.map +0 -1
- package/dist/__tests__/effort-levels-are-askable.test.d.ts +0 -2
- package/dist/__tests__/effort-levels-are-askable.test.d.ts.map +0 -1
- package/dist/__tests__/effort-levels-are-askable.test.js +0 -74
- package/dist/__tests__/effort-levels-are-askable.test.js.map +0 -1
- package/dist/__tests__/error-taxonomy.test.d.ts +0 -16
- package/dist/__tests__/error-taxonomy.test.d.ts.map +0 -1
- package/dist/__tests__/error-taxonomy.test.js +0 -242
- package/dist/__tests__/error-taxonomy.test.js.map +0 -1
- package/dist/__tests__/reasoning-close.test.d.ts +0 -2
- package/dist/__tests__/reasoning-close.test.d.ts.map +0 -1
- package/dist/__tests__/reasoning-close.test.js +0 -219
- package/dist/__tests__/reasoning-close.test.js.map +0 -1
- package/dist/__tests__/thinking-capability.test.d.ts +0 -2
- package/dist/__tests__/thinking-capability.test.d.ts.map +0 -1
- package/dist/__tests__/thinking-capability.test.js +0 -206
- package/dist/__tests__/thinking-capability.test.js.map +0 -1
- package/dist/__tests__/thinking-contract.live.test.d.ts +0 -2
- package/dist/__tests__/thinking-contract.live.test.d.ts.map +0 -1
- package/dist/__tests__/thinking-contract.live.test.js +0 -97
- package/dist/__tests__/thinking-contract.live.test.js.map +0 -1
- package/dist/__tests__/thinking-request-body.test.d.ts +0 -2
- package/dist/__tests__/thinking-request-body.test.d.ts.map +0 -1
- package/dist/__tests__/thinking-request-body.test.js +0 -90
- package/dist/__tests__/thinking-request-body.test.js.map +0 -1
- package/dist/__tests__/wire-contract.live.test.d.ts +0 -2
- package/dist/__tests__/wire-contract.live.test.d.ts.map +0 -1
- package/dist/__tests__/wire-contract.live.test.js +0 -272
- package/dist/__tests__/wire-contract.live.test.js.map +0 -1
- package/src/__tests__/anthropic.test.ts +0 -490
- package/src/__tests__/background-delegation.live.test.ts +0 -243
- package/src/__tests__/block-shape-guard.test.ts +0 -256
- package/src/__tests__/cache-anchors.test.ts +0 -262
- package/src/__tests__/citations.test.ts +0 -218
- package/src/__tests__/content-blocks.test.ts +0 -153
- package/src/__tests__/document-input.test.ts +0 -131
- package/src/__tests__/effort-levels-are-askable.test.ts +0 -86
- package/src/__tests__/error-taxonomy.test.ts +0 -274
- package/src/__tests__/reasoning-close.test.ts +0 -262
- package/src/__tests__/thinking-capability.test.ts +0 -235
- package/src/__tests__/thinking-contract.live.test.ts +0 -125
- package/src/__tests__/thinking-request-body.test.ts +0 -111
- package/src/__tests__/wire-contract.live.test.ts +0 -331
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import type { ChatCompletionParams, StreamChunk } from '@namzu/sdk'
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { AnthropicProvider } from '../client.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Extended thinking was fully specified in the SDK and entirely absent
|
|
8
|
-
* from this driver.
|
|
9
|
-
*
|
|
10
|
-
* The stream chunk carried a `reasoning` channel whose own comment named
|
|
11
|
-
* the bug — "`thinking_delta` and `signature_delta` fell through the
|
|
12
|
-
* driver's `default: // ignore`" — the run's aggregator bucketed fragments
|
|
13
|
-
* by index and closed them on `done`, and `ReasoningBlock` recorded the
|
|
14
|
-
* signature with a note that replaying it unchanged is mandatory. The
|
|
15
|
-
* driver requested no thinking, parsed none, and replayed none.
|
|
16
|
-
*
|
|
17
|
-
* The close matters as much as the content. A block is only complete once
|
|
18
|
-
* its signature has arrived, and the signature arrives last: without a
|
|
19
|
-
* `done` the aggregator cannot tell a finished block from one still
|
|
20
|
-
* streaming, and a block replayed without its signature invalidates the
|
|
21
|
-
* whole conversation upstream — not just that block.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
function providerOver(events: unknown[], seen: { body?: Record<string, unknown> } = {}) {
|
|
25
|
-
const provider = new AnthropicProvider({ apiKey: 'test-key' })
|
|
26
|
-
;(provider as unknown as { client: { messages: { create: unknown } } }).client = {
|
|
27
|
-
messages: {
|
|
28
|
-
create: vi.fn(async (body: Record<string, unknown>) => {
|
|
29
|
-
seen.body = body
|
|
30
|
-
return (async function* () {
|
|
31
|
-
for (const event of events) yield event
|
|
32
|
-
})()
|
|
33
|
-
}),
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
return provider
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function chunksOf(events: unknown[]): Promise<StreamChunk[]> {
|
|
40
|
-
const out: StreamChunk[] = []
|
|
41
|
-
for await (const chunk of providerOver(events).chatStream({
|
|
42
|
-
model: 'm',
|
|
43
|
-
messages: [{ role: 'user', content: 'q' }],
|
|
44
|
-
} as ChatCompletionParams)) {
|
|
45
|
-
out.push(chunk)
|
|
46
|
-
}
|
|
47
|
-
return out
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const THINKING_STREAM = [
|
|
51
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
52
|
-
{ type: 'content_block_start', index: 0, content_block: { type: 'thinking' } },
|
|
53
|
-
{
|
|
54
|
-
type: 'content_block_delta',
|
|
55
|
-
index: 0,
|
|
56
|
-
delta: { type: 'thinking_delta', thinking: 'step one' },
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
type: 'content_block_delta',
|
|
60
|
-
index: 0,
|
|
61
|
-
delta: { type: 'thinking_delta', thinking: ' then two' },
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
type: 'content_block_delta',
|
|
65
|
-
index: 0,
|
|
66
|
-
delta: { type: 'signature_delta', signature: 'sig-abc' },
|
|
67
|
-
},
|
|
68
|
-
{ type: 'content_block_stop', index: 0 },
|
|
69
|
-
{ type: 'content_block_start', index: 1, content_block: { type: 'text' } },
|
|
70
|
-
{ type: 'content_block_delta', index: 1, delta: { type: 'text_delta', text: 'the answer' } },
|
|
71
|
-
{ type: 'message_delta', delta: { stop_reason: 'end_turn' } },
|
|
72
|
-
]
|
|
73
|
-
|
|
74
|
-
function reasoningOf(chunks: StreamChunk[]) {
|
|
75
|
-
return chunks.map((c) => c.delta.reasoning).filter((r): r is NonNullable<typeof r> => Boolean(r))
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
describe('a reasoning block streams, then closes', () => {
|
|
79
|
-
it('opens the block with its kind', async () => {
|
|
80
|
-
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
81
|
-
|
|
82
|
-
expect(reasoning[0]).toMatchObject({ index: 0, type: 'thinking' })
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('carries each fragment through in order', async () => {
|
|
86
|
-
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
87
|
-
|
|
88
|
-
expect(reasoning.map((r) => r.text).filter(Boolean)).toEqual(['step one', ' then two'])
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('carries the signature, which arrives once at the end', async () => {
|
|
92
|
-
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
93
|
-
|
|
94
|
-
expect(reasoning.find((r) => r.signature)?.signature).toBe('sig-abc')
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('closes the block so the aggregator knows the signature has landed', async () => {
|
|
98
|
-
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
99
|
-
|
|
100
|
-
expect(reasoning.at(-1)).toEqual({ index: 0, done: true })
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('closes it before the text block starts, not after', async () => {
|
|
104
|
-
const chunks = await chunksOf(THINKING_STREAM)
|
|
105
|
-
const closeAt = chunks.findIndex((c) => c.delta.reasoning?.done)
|
|
106
|
-
const textAt = chunks.findIndex((c) => c.delta.content === 'the answer')
|
|
107
|
-
|
|
108
|
-
expect(closeAt).toBeGreaterThan(-1)
|
|
109
|
-
expect(closeAt).toBeLessThan(textAt)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('does not leak reasoning into the visible text', async () => {
|
|
113
|
-
const chunks = await chunksOf(THINKING_STREAM)
|
|
114
|
-
|
|
115
|
-
expect(chunks.map((c) => c.delta.content).filter(Boolean)).toEqual(['the answer'])
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('groups two blocks by their own index', async () => {
|
|
119
|
-
const reasoning = reasoningOf(
|
|
120
|
-
await chunksOf([
|
|
121
|
-
{ type: 'message_start', message: { id: 'm' } },
|
|
122
|
-
{ type: 'content_block_start', index: 0, content_block: { type: 'thinking' } },
|
|
123
|
-
{ type: 'content_block_delta', index: 0, delta: { type: 'thinking_delta', thinking: 'a' } },
|
|
124
|
-
{ type: 'content_block_stop', index: 0 },
|
|
125
|
-
{ type: 'content_block_start', index: 1, content_block: { type: 'thinking' } },
|
|
126
|
-
{ type: 'content_block_delta', index: 1, delta: { type: 'thinking_delta', thinking: 'b' } },
|
|
127
|
-
{ type: 'content_block_stop', index: 1 },
|
|
128
|
-
]),
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
expect(reasoning.filter((r) => r.done).map((r) => r.index)).toEqual([0, 1])
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('carries a redacted block as an opaque payload rather than text', async () => {
|
|
135
|
-
const reasoning = reasoningOf(
|
|
136
|
-
await chunksOf([
|
|
137
|
-
{ type: 'message_start', message: { id: 'm' } },
|
|
138
|
-
{
|
|
139
|
-
type: 'content_block_start',
|
|
140
|
-
index: 0,
|
|
141
|
-
content_block: { type: 'redacted_thinking', data: 'opaque-bytes' },
|
|
142
|
-
},
|
|
143
|
-
{ type: 'content_block_stop', index: 0 },
|
|
144
|
-
]),
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
expect(reasoning[0]).toMatchObject({ type: 'redacted_thinking', encrypted: 'opaque-bytes' })
|
|
148
|
-
expect(reasoning[0]?.text).toBeUndefined()
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('still closes a tool call, which shares the same stop event', async () => {
|
|
152
|
-
const chunks = await chunksOf([
|
|
153
|
-
{ type: 'message_start', message: { id: 'm' } },
|
|
154
|
-
{
|
|
155
|
-
type: 'content_block_start',
|
|
156
|
-
index: 0,
|
|
157
|
-
content_block: { type: 'tool_use', id: 'call_1', name: 'read' },
|
|
158
|
-
},
|
|
159
|
-
{ type: 'content_block_stop', index: 0 },
|
|
160
|
-
])
|
|
161
|
-
|
|
162
|
-
expect(chunks.some((c) => c.delta.toolCallEnd?.id === 'call_1')).toBe(true)
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
describe('thinking can be asked for', () => {
|
|
167
|
-
async function bodyFor(thinking: unknown): Promise<Record<string, unknown>> {
|
|
168
|
-
const seen: { body?: Record<string, unknown> } = {}
|
|
169
|
-
const provider = providerOver([{ type: 'message_start', message: { id: 'm' } }], seen)
|
|
170
|
-
for await (const _chunk of provider.chatStream({
|
|
171
|
-
model: 'm',
|
|
172
|
-
messages: [{ role: 'user', content: 'q' }],
|
|
173
|
-
...(thinking !== undefined ? { thinking } : {}),
|
|
174
|
-
} as ChatCompletionParams)) {
|
|
175
|
-
// drain
|
|
176
|
-
}
|
|
177
|
-
return seen.body ?? {}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
it('sends the budget the caller set', async () => {
|
|
181
|
-
expect(await bodyFor({ type: 'enabled', budgetTokens: 4096 })).toMatchObject({
|
|
182
|
-
thinking: { type: 'enabled', budget_tokens: 4096 },
|
|
183
|
-
})
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
it('enables it without a budget when none was named', async () => {
|
|
187
|
-
expect((await bodyFor({ type: 'enabled' })).thinking).toEqual({ type: 'enabled' })
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
it('can turn it off on a model where it is on by default', async () => {
|
|
191
|
-
expect((await bodyFor({ type: 'disabled' })).thinking).toEqual({ type: 'disabled' })
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('says nothing at all when the caller did not ask', async () => {
|
|
195
|
-
expect(await bodyFor(undefined)).not.toHaveProperty('thinking')
|
|
196
|
-
})
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
describe('a reasoned turn is replayed verbatim on the next request', () => {
|
|
200
|
-
async function messagesFor(assistant: Record<string, unknown>) {
|
|
201
|
-
const seen: { body?: Record<string, unknown> } = {}
|
|
202
|
-
const provider = providerOver([{ type: 'message_start', message: { id: 'm' } }], seen)
|
|
203
|
-
for await (const _chunk of provider.chatStream({
|
|
204
|
-
model: 'm',
|
|
205
|
-
messages: [{ role: 'user', content: 'q' }, assistant, { role: 'user', content: 'and then?' }],
|
|
206
|
-
} as unknown as ChatCompletionParams)) {
|
|
207
|
-
// drain
|
|
208
|
-
}
|
|
209
|
-
return seen.body?.messages as Array<{ role: string; content: unknown }>
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
it('replays the block with its signature intact', async () => {
|
|
213
|
-
const messages = await messagesFor({
|
|
214
|
-
role: 'assistant',
|
|
215
|
-
content: 'because of that',
|
|
216
|
-
reasoning: [{ type: 'thinking', text: 'step one', signature: 'sig-abc' }],
|
|
217
|
-
})
|
|
218
|
-
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
219
|
-
|
|
220
|
-
expect(blocks[0]).toEqual({ type: 'thinking', thinking: 'step one', signature: 'sig-abc' })
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('puts the reasoning first, as the wire requires', async () => {
|
|
224
|
-
const messages = await messagesFor({
|
|
225
|
-
role: 'assistant',
|
|
226
|
-
content: 'because of that',
|
|
227
|
-
reasoning: [{ type: 'thinking', text: 'step one', signature: 'sig' }],
|
|
228
|
-
})
|
|
229
|
-
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
230
|
-
|
|
231
|
-
expect(blocks.map((b) => b.type)).toEqual(['thinking', 'text'])
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
it('replays it ahead of a tool call too', async () => {
|
|
235
|
-
const messages = await messagesFor({
|
|
236
|
-
role: 'assistant',
|
|
237
|
-
content: null,
|
|
238
|
-
reasoning: [{ type: 'thinking', text: 'i should read it', signature: 'sig' }],
|
|
239
|
-
toolCalls: [{ id: 'call_1', type: 'function', function: { name: 'read', arguments: '{}' } }],
|
|
240
|
-
})
|
|
241
|
-
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
242
|
-
|
|
243
|
-
expect(blocks.map((b) => b.type)).toEqual(['thinking', 'tool_use'])
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
it('replays a redacted block as its opaque payload', async () => {
|
|
247
|
-
const messages = await messagesFor({
|
|
248
|
-
role: 'assistant',
|
|
249
|
-
content: 'answer',
|
|
250
|
-
reasoning: [{ type: 'redacted_thinking', encrypted: 'opaque-bytes' }],
|
|
251
|
-
})
|
|
252
|
-
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
253
|
-
|
|
254
|
-
expect(blocks[0]).toEqual({ type: 'redacted_thinking', data: 'opaque-bytes' })
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
it('leaves an assistant turn that did not reason as a plain string', async () => {
|
|
258
|
-
const messages = await messagesFor({ role: 'assistant', content: 'just an answer' })
|
|
259
|
-
|
|
260
|
-
expect(messages[1]?.content).toBe('just an answer')
|
|
261
|
-
})
|
|
262
|
-
})
|
|
@@ -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
|
-
})
|