@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.
- package/CHANGELOG.md +122 -0
- package/dist/__tests__/background-delegation.live.test.d.ts +2 -0
- package/dist/__tests__/background-delegation.live.test.d.ts.map +1 -0
- package/dist/__tests__/background-delegation.live.test.js +212 -0
- package/dist/__tests__/background-delegation.live.test.js.map +1 -0
- package/dist/__tests__/thinking-capability.test.js +49 -21
- package/dist/__tests__/thinking-capability.test.js.map +1 -1
- package/dist/__tests__/thinking-contract.live.test.d.ts +2 -0
- package/dist/__tests__/thinking-contract.live.test.d.ts.map +1 -0
- package/dist/__tests__/thinking-contract.live.test.js +97 -0
- package/dist/__tests__/thinking-contract.live.test.js.map +1 -0
- package/dist/__tests__/wire-contract.live.test.d.ts +2 -0
- package/dist/__tests__/wire-contract.live.test.d.ts.map +1 -0
- package/dist/__tests__/wire-contract.live.test.js +254 -0
- package/dist/__tests__/wire-contract.live.test.js.map +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -3
- package/dist/client.js.map +1 -1
- package/dist/thinking-capability.d.ts +26 -6
- package/dist/thinking-capability.d.ts.map +1 -1
- package/dist/thinking-capability.js +73 -16
- package/dist/thinking-capability.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/background-delegation.live.test.ts +243 -0
- package/src/__tests__/thinking-capability.test.ts +51 -22
- package/src/__tests__/thinking-contract.live.test.ts +125 -0
- package/src/__tests__/wire-contract.live.test.ts +312 -0
- package/src/client.ts +18 -2
- package/src/thinking-capability.ts +89 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking-capability.js","sourceRoot":"","sources":["../src/thinking-capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AA4ClD,MAAM,SAAS,GAAiB,EAAE,CAAA;AAClC,+DAA+D;AAC/D,MAAM,WAAW,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
1
1
|
{
|
|
2
2
|
"name": "@namzu/anthropic",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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": ">=
|
|
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": "^
|
|
47
|
+
"@namzu/sdk": "^7.0.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc --build",
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CompletionInbox,
|
|
3
|
+
ToolRegistry,
|
|
4
|
+
buildCoordinatorTools,
|
|
5
|
+
drainQuery,
|
|
6
|
+
runAgent,
|
|
7
|
+
} from '@namzu/sdk'
|
|
8
|
+
import type { TaskGateway, TaskHandle } from '@namzu/sdk'
|
|
9
|
+
import { describe, expect, it } from 'vitest'
|
|
10
|
+
|
|
11
|
+
import { AnthropicProvider } from '../client.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Does a real model actually receive a worker it stopped waiting for?
|
|
15
|
+
*
|
|
16
|
+
* Everything else about this mechanism is tested against fakes: the inbox
|
|
17
|
+
* queues what nobody claimed, the tools claim what they deliver, the loop
|
|
18
|
+
* drains the rest into the transcript. All of it can be true and the feature
|
|
19
|
+
* still useless, because the part that decides whether it works is whether a
|
|
20
|
+
* MODEL reads the notification and acts on it — and no fake can answer that.
|
|
21
|
+
*
|
|
22
|
+
* So this runs the whole thing against the live API: a real supervisor model,
|
|
23
|
+
* a real worker model, a background launch, and an assertion that the answer
|
|
24
|
+
* the supervisor finally gives contains something only the worker knew.
|
|
25
|
+
*
|
|
26
|
+
* The gateway here is deliberately hand-rolled over `runAgent` rather than
|
|
27
|
+
* the kernel's `LocalTaskGateway`. That is the shape a host implements, so it
|
|
28
|
+
* doubles as proof that the inbox needs nothing from a gateway beyond the
|
|
29
|
+
* `onTaskCompleted` every gateway already has.
|
|
30
|
+
*
|
|
31
|
+
* Skipped without a key. Run 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
|
+
/** The fact only the worker can know, so its presence proves delivery. */
|
|
40
|
+
const SECRET = 'PELICAN-7731'
|
|
41
|
+
|
|
42
|
+
function provider(): AnthropicProvider {
|
|
43
|
+
return new AnthropicProvider({ apiKey: KEY as string, model: MODEL })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A host-shaped gateway: spawns a real child run per task and announces it.
|
|
48
|
+
*
|
|
49
|
+
* Nothing here is kernel code. It implements `TaskGateway` the way an
|
|
50
|
+
* embedding application does, which is the point — the inbox attaches to it
|
|
51
|
+
* unchanged.
|
|
52
|
+
*/
|
|
53
|
+
function liveGateway(): TaskGateway {
|
|
54
|
+
const handles = new Map<string, TaskHandle>()
|
|
55
|
+
const settled = new Map<string, Promise<TaskHandle>>()
|
|
56
|
+
const listeners = new Set<(h: TaskHandle) => void>()
|
|
57
|
+
let seq = 0
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
async createTask({ agentId, prompt }) {
|
|
61
|
+
seq += 1
|
|
62
|
+
const taskId = `tsk_live_${seq}`
|
|
63
|
+
const handle: TaskHandle = {
|
|
64
|
+
taskId: taskId as TaskHandle['taskId'],
|
|
65
|
+
agentId,
|
|
66
|
+
state: 'running',
|
|
67
|
+
createdAt: Date.now(),
|
|
68
|
+
}
|
|
69
|
+
handles.set(taskId, handle)
|
|
70
|
+
|
|
71
|
+
settled.set(
|
|
72
|
+
taskId,
|
|
73
|
+
runAgent({
|
|
74
|
+
provider: provider(),
|
|
75
|
+
model: MODEL,
|
|
76
|
+
prompt,
|
|
77
|
+
instructions: 'Answer in one short sentence. Do not explain yourself.',
|
|
78
|
+
maxIterations: 2,
|
|
79
|
+
tokenBudget: 20_000,
|
|
80
|
+
}).then((run) => {
|
|
81
|
+
const done: TaskHandle = {
|
|
82
|
+
...handle,
|
|
83
|
+
state: 'completed',
|
|
84
|
+
completedAt: Date.now(),
|
|
85
|
+
result: {
|
|
86
|
+
status: 'completed',
|
|
87
|
+
result: run.output ?? '',
|
|
88
|
+
} as TaskHandle['result'],
|
|
89
|
+
}
|
|
90
|
+
handles.set(taskId, done)
|
|
91
|
+
for (const cb of listeners) cb(done)
|
|
92
|
+
return done
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
return handle
|
|
97
|
+
},
|
|
98
|
+
waitForTask: async (taskId) => {
|
|
99
|
+
const pending = settled.get(taskId)
|
|
100
|
+
if (!pending) throw new Error(`no task ${taskId}`)
|
|
101
|
+
return pending
|
|
102
|
+
},
|
|
103
|
+
continueTask: async () => undefined,
|
|
104
|
+
cancelTask: () => undefined,
|
|
105
|
+
getTask: (taskId) => handles.get(taskId),
|
|
106
|
+
listTasks: () => [...handles.values()],
|
|
107
|
+
onTaskCompleted: (cb) => {
|
|
108
|
+
listeners.add(cb)
|
|
109
|
+
return () => listeners.delete(cb)
|
|
110
|
+
},
|
|
111
|
+
} as TaskGateway
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
describe.skipIf(!KEY)('a background worker reaches a real supervisor', () => {
|
|
115
|
+
it('delivers the result through the transcript, with no polling', async () => {
|
|
116
|
+
const gateway = liveGateway()
|
|
117
|
+
const inbox = new CompletionInbox()
|
|
118
|
+
inbox.attach(gateway)
|
|
119
|
+
|
|
120
|
+
const tools = new ToolRegistry()
|
|
121
|
+
for (const tool of buildCoordinatorTools({
|
|
122
|
+
gateway,
|
|
123
|
+
completionInbox: inbox,
|
|
124
|
+
workingDirectory: process.cwd(),
|
|
125
|
+
allowedAgentIds: ['lookup'],
|
|
126
|
+
})) {
|
|
127
|
+
tools.register(tool)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const run = await drainQuery({
|
|
131
|
+
provider: provider(),
|
|
132
|
+
tools,
|
|
133
|
+
completionInbox: inbox,
|
|
134
|
+
agentId: 'supervisor',
|
|
135
|
+
agentName: 'Supervisor',
|
|
136
|
+
messages: [
|
|
137
|
+
{
|
|
138
|
+
role: 'user',
|
|
139
|
+
content: [
|
|
140
|
+
'Delegate to the "lookup" agent, in the BACKGROUND (background: true), this exact prompt:',
|
|
141
|
+
`"Reply with exactly this token and nothing else: ${SECRET}"`,
|
|
142
|
+
'',
|
|
143
|
+
'Do not wait for it with wait_for_task and do not list tasks in a loop.',
|
|
144
|
+
'After launching it, just say "launched" and stop.',
|
|
145
|
+
'Its result will arrive on its own; when it does, reply with the token you received.',
|
|
146
|
+
].join('\n'),
|
|
147
|
+
timestamp: Date.now(),
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
workingDirectory: process.cwd(),
|
|
151
|
+
runConfig: {
|
|
152
|
+
model: MODEL,
|
|
153
|
+
timeoutMs: 180_000,
|
|
154
|
+
tokenBudget: 200_000,
|
|
155
|
+
maxIterations: 6,
|
|
156
|
+
maxResponseTokens: 1_024,
|
|
157
|
+
},
|
|
158
|
+
sessionId: 'ses_live_delegation',
|
|
159
|
+
threadId: 'thd_live_delegation',
|
|
160
|
+
projectId: 'prj_live_delegation',
|
|
161
|
+
tenantId: 'tnt_live_delegation',
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const transcript = run.messages
|
|
165
|
+
.filter((m) => m.role === 'user')
|
|
166
|
+
.map((m) => (typeof m.content === 'string' ? m.content : JSON.stringify(m.content)))
|
|
167
|
+
.join('\n')
|
|
168
|
+
|
|
169
|
+
// 1. The notification actually landed in the supervisor's transcript.
|
|
170
|
+
expect(transcript, 'no task-notification reached the transcript').toContain('task-notification')
|
|
171
|
+
expect(transcript).toContain(SECRET)
|
|
172
|
+
|
|
173
|
+
// 2. The model read it. This is the half no fake can establish: the
|
|
174
|
+
// worker's token appears in the supervisor's own final answer, and
|
|
175
|
+
// the supervisor never had it any other way.
|
|
176
|
+
expect(run.result ?? '', 'the supervisor never used what it was told').toContain(SECRET)
|
|
177
|
+
|
|
178
|
+
// 3. It got there without polling, which is the whole complaint the
|
|
179
|
+
// fix answers — `agent_task_list` in a sleep loop was the only move
|
|
180
|
+
// on the board before this.
|
|
181
|
+
const listCalls = (run.steps ?? [])
|
|
182
|
+
.flatMap((s) => s.toolCalls ?? [])
|
|
183
|
+
.filter((c) => c.function.name === 'agent_task_list')
|
|
184
|
+
expect(listCalls.length, 'the model still had to poll').toBe(0)
|
|
185
|
+
}, 300_000)
|
|
186
|
+
|
|
187
|
+
it('still delivers the result inline when the launch is not backgrounded', async () => {
|
|
188
|
+
// The path `dc16d58` protects: a blocking launch answers as its own
|
|
189
|
+
// tool_result, and must NOT also arrive as an envelope.
|
|
190
|
+
const gateway = liveGateway()
|
|
191
|
+
const inbox = new CompletionInbox()
|
|
192
|
+
inbox.attach(gateway)
|
|
193
|
+
|
|
194
|
+
const tools = new ToolRegistry()
|
|
195
|
+
for (const tool of buildCoordinatorTools({
|
|
196
|
+
gateway,
|
|
197
|
+
completionInbox: inbox,
|
|
198
|
+
workingDirectory: process.cwd(),
|
|
199
|
+
allowedAgentIds: ['lookup'],
|
|
200
|
+
})) {
|
|
201
|
+
tools.register(tool)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const run = await drainQuery({
|
|
205
|
+
provider: provider(),
|
|
206
|
+
tools,
|
|
207
|
+
completionInbox: inbox,
|
|
208
|
+
agentId: 'supervisor',
|
|
209
|
+
agentName: 'Supervisor',
|
|
210
|
+
messages: [
|
|
211
|
+
{
|
|
212
|
+
role: 'user',
|
|
213
|
+
content: `Use create_task on the "lookup" agent with this prompt: "Reply with exactly this token and nothing else: ${SECRET}". Do NOT set background. Then report the token it returned.`,
|
|
214
|
+
timestamp: Date.now(),
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
workingDirectory: process.cwd(),
|
|
218
|
+
runConfig: {
|
|
219
|
+
model: MODEL,
|
|
220
|
+
timeoutMs: 180_000,
|
|
221
|
+
tokenBudget: 200_000,
|
|
222
|
+
maxIterations: 6,
|
|
223
|
+
maxResponseTokens: 1_024,
|
|
224
|
+
},
|
|
225
|
+
sessionId: 'ses_live_delegation',
|
|
226
|
+
threadId: 'thd_live_delegation',
|
|
227
|
+
projectId: 'prj_live_delegation',
|
|
228
|
+
tenantId: 'tnt_live_delegation',
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
expect(run.result ?? '').toContain(SECRET)
|
|
232
|
+
|
|
233
|
+
const transcript = run.messages
|
|
234
|
+
.filter((m) => m.role === 'user')
|
|
235
|
+
.map((m) => (typeof m.content === 'string' ? m.content : JSON.stringify(m.content)))
|
|
236
|
+
.join('\n')
|
|
237
|
+
|
|
238
|
+
// Delivered once, as a tool_result — no duplicate envelope.
|
|
239
|
+
expect(transcript, 'the blocking result was announced a second time').not.toContain(
|
|
240
|
+
'task-notification',
|
|
241
|
+
)
|
|
242
|
+
}, 300_000)
|
|
243
|
+
})
|
|
@@ -33,31 +33,43 @@ const NONE: string[] = []
|
|
|
33
33
|
* twice, so a boolean could not say that `xhigh` is rejected on 4.6 and `max`
|
|
34
34
|
* is rejected on 4.5 — which is exactly what it failed to say.
|
|
35
35
|
*/
|
|
36
|
-
const
|
|
36
|
+
const CAPPED = BASE // opus 5+ with thinking off
|
|
37
|
+
const TABLE: readonly [string, boolean, boolean, boolean, string[], string[]][] = [
|
|
37
38
|
// Always-on families: thinking cannot be switched off at any version.
|
|
38
|
-
['claude-fable-5', true, false, false, ALL],
|
|
39
|
-
['claude-mythos-5', true, false, false, ALL],
|
|
40
|
-
|
|
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],
|
|
41
47
|
// 4.7 and later: adaptive only, and it can still be disabled.
|
|
42
|
-
['claude-opus-5', true, false, true, ALL],
|
|
43
|
-
['claude-sonnet-5', true, false, true, ALL],
|
|
44
|
-
['claude-opus-4-8', true, false, true, ALL],
|
|
45
|
-
['claude-opus-4-7', true, false, true, ALL],
|
|
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],
|
|
46
52
|
// 4.6: both modes, manual deprecated but working — and no `xhigh`.
|
|
47
|
-
['claude-opus-4-6', true, true, true, NO_XHIGH],
|
|
48
|
-
['claude-sonnet-4-6', true, true, true, 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],
|
|
49
55
|
// 4.5 and earlier: manual only. Opus 4.5 is the one that takes effort,
|
|
50
56
|
// and only the first three levels.
|
|
51
|
-
['claude-opus-4-5', false, true, true, BASE],
|
|
52
|
-
['claude-haiku-4-5', false, true, true, NONE],
|
|
53
|
-
['claude-sonnet-4-5', false, true, true, NONE],
|
|
54
|
-
['claude-opus-4-1', false, true, true, NONE],
|
|
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],
|
|
55
61
|
]
|
|
56
62
|
|
|
57
63
|
describe('what each model accepts', () => {
|
|
58
|
-
for (const [model, adaptive, manual, canDisable, effort] of TABLE) {
|
|
64
|
+
for (const [model, adaptive, manual, canDisable, effort, effortWhenDisabled] of TABLE) {
|
|
59
65
|
it(`resolves ${model}`, () => {
|
|
60
|
-
expect(resolveThinkingCapability(model)).toEqual({
|
|
66
|
+
expect(resolveThinkingCapability(model)).toEqual({
|
|
67
|
+
adaptive,
|
|
68
|
+
manual,
|
|
69
|
+
canDisable,
|
|
70
|
+
effort,
|
|
71
|
+
effortWhenDisabled,
|
|
72
|
+
})
|
|
61
73
|
})
|
|
62
74
|
}
|
|
63
75
|
|
|
@@ -97,6 +109,7 @@ describe('what each model accepts', () => {
|
|
|
97
109
|
manual: true,
|
|
98
110
|
canDisable: true,
|
|
99
111
|
effort: [],
|
|
112
|
+
effortWhenDisabled: [],
|
|
100
113
|
})
|
|
101
114
|
})
|
|
102
115
|
})
|
|
@@ -174,12 +187,28 @@ describe('when effort rides along', () => {
|
|
|
174
187
|
expect(resolveEffort('high', { type: 'enabled', budget_tokens: 8000 }, opus45)).toBe('high')
|
|
175
188
|
})
|
|
176
189
|
|
|
177
|
-
it('
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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')
|
|
183
212
|
})
|
|
184
213
|
|
|
185
214
|
it('drops a level this model does not have', () => {
|
|
@@ -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
|
+
})
|