@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.
- package/CHANGELOG.md +76 -0
- package/dist/client.d.ts +15 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +18 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/package.json +12 -2
- package/src/client.ts +21 -0
- package/src/index.ts +18 -0
- 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__/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 -254
- 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__/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 -312
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import { DuplicateProviderError, ProviderRegistry } from '@namzu/sdk';
|
|
2
|
-
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
-
import { AnthropicProvider } from '../client.js';
|
|
4
|
-
import { ANTHROPIC_CAPABILITIES, registerAnthropic } from '../index.js';
|
|
5
|
-
// Ensure a clean slate between tests. The sdk pre-registers 'mock' on import
|
|
6
|
-
// via its sideEffects whitelist; we only need to clear 'anthropic' to make
|
|
7
|
-
// re-registration deterministic across tests.
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
if (ProviderRegistry.isSupported('anthropic')) {
|
|
10
|
-
ProviderRegistry.unregister('anthropic');
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
describe('@namzu/anthropic', () => {
|
|
14
|
-
describe('registerAnthropic()', () => {
|
|
15
|
-
it("adds 'anthropic' to the ProviderRegistry", () => {
|
|
16
|
-
expect(ProviderRegistry.isSupported('anthropic')).toBe(false);
|
|
17
|
-
registerAnthropic();
|
|
18
|
-
expect(ProviderRegistry.isSupported('anthropic')).toBe(true);
|
|
19
|
-
expect(ProviderRegistry.listTypes()).toContain('anthropic');
|
|
20
|
-
});
|
|
21
|
-
it('throws DuplicateProviderError when called twice without options', () => {
|
|
22
|
-
registerAnthropic();
|
|
23
|
-
expect(() => registerAnthropic()).toThrowError(DuplicateProviderError);
|
|
24
|
-
});
|
|
25
|
-
it('allows re-registration when { replace: true } is passed', () => {
|
|
26
|
-
registerAnthropic();
|
|
27
|
-
expect(() => registerAnthropic({ replace: true })).not.toThrow();
|
|
28
|
-
expect(ProviderRegistry.isSupported('anthropic')).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
it('exposes capabilities through the registry after registration', () => {
|
|
31
|
-
registerAnthropic();
|
|
32
|
-
const caps = ProviderRegistry.getCapabilities('anthropic');
|
|
33
|
-
expect(caps).toEqual(ANTHROPIC_CAPABILITIES);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe('ANTHROPIC_CAPABILITIES', () => {
|
|
37
|
-
it('declares the expected capability flags', () => {
|
|
38
|
-
expect(ANTHROPIC_CAPABILITIES).toEqual({
|
|
39
|
-
supportsTools: true,
|
|
40
|
-
supportsStreaming: true,
|
|
41
|
-
supportsFunctionCalling: true,
|
|
42
|
-
supportsVision: true,
|
|
43
|
-
supportsDocuments: true,
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
it('is exposed on the provider instance for runtime negotiation', () => {
|
|
47
|
-
const provider = new AnthropicProvider({ apiKey: 'test-key' });
|
|
48
|
-
expect(provider.capabilities).toEqual(ANTHROPIC_CAPABILITIES);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe('AnthropicProvider', () => {
|
|
52
|
-
it('constructs with an apiKey and exposes provider identity', () => {
|
|
53
|
-
const provider = new AnthropicProvider({ apiKey: 'test-key' });
|
|
54
|
-
expect(provider.id).toBe('anthropic');
|
|
55
|
-
expect(provider.name).toBe('Anthropic');
|
|
56
|
-
});
|
|
57
|
-
it('throws when constructed without an apiKey or authToken', () => {
|
|
58
|
-
expect(() => new AnthropicProvider({})).toThrow(/apiKey.*or.*authToken.*required/);
|
|
59
|
-
});
|
|
60
|
-
it('accepts an authToken instead of an apiKey (OAuth path)', () => {
|
|
61
|
-
const provider = new AnthropicProvider({ authToken: 'cc-oauth-token' });
|
|
62
|
-
expect(provider.id).toBe('anthropic');
|
|
63
|
-
});
|
|
64
|
-
it('creates via ProviderRegistry.create with the registered type', () => {
|
|
65
|
-
registerAnthropic();
|
|
66
|
-
const { provider, capabilities } = ProviderRegistry.create({
|
|
67
|
-
type: 'anthropic',
|
|
68
|
-
apiKey: 'test-key',
|
|
69
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
70
|
-
});
|
|
71
|
-
expect(provider.id).toBe('anthropic');
|
|
72
|
-
expect(capabilities).toEqual(ANTHROPIC_CAPABILITIES);
|
|
73
|
-
});
|
|
74
|
-
it('does not enforce a provider-local stream idle timeout by default', async () => {
|
|
75
|
-
const provider = new AnthropicProvider({
|
|
76
|
-
apiKey: 'test-key',
|
|
77
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
78
|
-
});
|
|
79
|
-
provider.client = {
|
|
80
|
-
messages: {
|
|
81
|
-
create: async () => delayedAnthropicStream(10),
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
const chunks = [];
|
|
85
|
-
for await (const chunk of provider.chatStream({
|
|
86
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
87
|
-
messages: [{ role: 'user', content: 'hello' }],
|
|
88
|
-
maxTokens: 100,
|
|
89
|
-
})) {
|
|
90
|
-
chunks.push(chunk);
|
|
91
|
-
}
|
|
92
|
-
expect(chunks.length).toBeGreaterThan(0);
|
|
93
|
-
});
|
|
94
|
-
it('supports an opt-in stream idle timeout for deployments that need it', async () => {
|
|
95
|
-
const provider = new AnthropicProvider({
|
|
96
|
-
apiKey: 'test-key',
|
|
97
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
98
|
-
streamIdleTimeoutMs: 1,
|
|
99
|
-
});
|
|
100
|
-
provider.client = {
|
|
101
|
-
messages: {
|
|
102
|
-
create: async () => delayedAnthropicStream(20),
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
const drain = async () => {
|
|
106
|
-
for await (const _chunk of provider.chatStream({
|
|
107
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
108
|
-
messages: [{ role: 'user', content: 'hello' }],
|
|
109
|
-
maxTokens: 100,
|
|
110
|
-
})) {
|
|
111
|
-
// Drain the stream.
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
await expect(drain()).rejects.toThrow(/stream idle/);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
describe('AnthropicProvider — buildCreateParams', () => {
|
|
119
|
-
const buildParams = (provider, params, stream = false) => provider.buildCreateParams(params, stream);
|
|
120
|
-
const makeProvider = () => new AnthropicProvider({
|
|
121
|
-
apiKey: 'test-key',
|
|
122
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
123
|
-
});
|
|
124
|
-
const tools = [
|
|
125
|
-
{
|
|
126
|
-
type: 'function',
|
|
127
|
-
function: {
|
|
128
|
-
name: 'alpha',
|
|
129
|
-
description: 'first',
|
|
130
|
-
parameters: { type: 'object' },
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
type: 'function',
|
|
135
|
-
function: {
|
|
136
|
-
name: 'beta',
|
|
137
|
-
description: 'second',
|
|
138
|
-
parameters: { type: 'object' },
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
];
|
|
142
|
-
describe('tool_choice mapping', () => {
|
|
143
|
-
it("maps 'none' to the first-class {type:'none'} while KEEPING the tools param", () => {
|
|
144
|
-
const body = buildParams(makeProvider(), {
|
|
145
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
146
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
147
|
-
tools,
|
|
148
|
-
toolChoice: 'none',
|
|
149
|
-
});
|
|
150
|
-
expect(body.tool_choice).toEqual({ type: 'none' });
|
|
151
|
-
expect(body.tools).toHaveLength(2);
|
|
152
|
-
});
|
|
153
|
-
it("maps 'auto' → auto, 'required' → any, and function → tool", () => {
|
|
154
|
-
const base = {
|
|
155
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
156
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
157
|
-
tools,
|
|
158
|
-
};
|
|
159
|
-
expect(buildParams(makeProvider(), { ...base, toolChoice: 'auto' }).tool_choice).toEqual({
|
|
160
|
-
type: 'auto',
|
|
161
|
-
});
|
|
162
|
-
expect(buildParams(makeProvider(), { ...base, toolChoice: 'required' }).tool_choice).toEqual({
|
|
163
|
-
type: 'any',
|
|
164
|
-
});
|
|
165
|
-
expect(buildParams(makeProvider(), {
|
|
166
|
-
...base,
|
|
167
|
-
toolChoice: { type: 'function', function: { name: 'alpha' } },
|
|
168
|
-
}).tool_choice).toEqual({ type: 'tool', name: 'alpha' });
|
|
169
|
-
});
|
|
170
|
-
it('omits tool_choice entirely when no tools are present', () => {
|
|
171
|
-
const body = buildParams(makeProvider(), {
|
|
172
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
173
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
174
|
-
toolChoice: 'none',
|
|
175
|
-
});
|
|
176
|
-
expect(body.tools).toBeUndefined();
|
|
177
|
-
expect(body.tool_choice).toBeUndefined();
|
|
178
|
-
});
|
|
179
|
-
it('maps parallelToolCalls:false to disable_parallel_tool_use on tool_choice', () => {
|
|
180
|
-
const body = buildParams(makeProvider(), {
|
|
181
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
182
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
183
|
-
tools,
|
|
184
|
-
parallelToolCalls: false,
|
|
185
|
-
});
|
|
186
|
-
expect(body.tool_choice).toEqual({
|
|
187
|
-
type: 'auto',
|
|
188
|
-
disable_parallel_tool_use: true,
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
describe('strict tool input mapping', () => {
|
|
193
|
-
const base = (model) => ({
|
|
194
|
-
model,
|
|
195
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
196
|
-
tools,
|
|
197
|
-
enforceToolInputSchema: ['alpha'],
|
|
198
|
-
});
|
|
199
|
-
it.each([
|
|
200
|
-
'claude-haiku-4-5-20251001',
|
|
201
|
-
'claude-sonnet-4-6',
|
|
202
|
-
'claude-opus-5',
|
|
203
|
-
'anthropic/claude-fable-5',
|
|
204
|
-
'claude-mythos-preview',
|
|
205
|
-
])('enables only named tools for supported model %s', (model) => {
|
|
206
|
-
const body = buildParams(makeProvider(), base(model));
|
|
207
|
-
expect(body.tools?.[0]).toMatchObject({ name: 'alpha', strict: true });
|
|
208
|
-
expect(body.tools?.[1]).toEqual({
|
|
209
|
-
name: 'beta',
|
|
210
|
-
description: 'second',
|
|
211
|
-
input_schema: { type: 'object' },
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
it.each([
|
|
215
|
-
'claude-3-5-sonnet-20241022',
|
|
216
|
-
'proxy-production-alias',
|
|
217
|
-
'proxy-production-claude-opus-5-legacy',
|
|
218
|
-
'not-claude-sonnet-4-5-compatible',
|
|
219
|
-
'claude-mythos-preview-shadow',
|
|
220
|
-
])('falls back to runtime validation for unsupported or unknown model %s', (model) => {
|
|
221
|
-
const body = buildParams(makeProvider(), base(model));
|
|
222
|
-
expect(JSON.stringify(body.tools)).not.toContain('"strict"');
|
|
223
|
-
});
|
|
224
|
-
it('uses the per-call model instead of the configured default in auto mode', () => {
|
|
225
|
-
const provider = new AnthropicProvider({
|
|
226
|
-
apiKey: 'test-key',
|
|
227
|
-
model: 'claude-opus-5',
|
|
228
|
-
});
|
|
229
|
-
const body = buildParams(provider, base('proxy-production-alias'));
|
|
230
|
-
expect(JSON.stringify(body.tools)).not.toContain('"strict"');
|
|
231
|
-
});
|
|
232
|
-
it('supports explicit on/off overrides for compatible aliases and proxies', () => {
|
|
233
|
-
const on = new AnthropicProvider({
|
|
234
|
-
apiKey: 'test-key',
|
|
235
|
-
model: 'proxy-production-alias',
|
|
236
|
-
strictToolUse: 'on',
|
|
237
|
-
});
|
|
238
|
-
expect(buildParams(on, {
|
|
239
|
-
...base(''),
|
|
240
|
-
model: '',
|
|
241
|
-
}).tools?.[0]).toMatchObject({ strict: true });
|
|
242
|
-
const off = new AnthropicProvider({
|
|
243
|
-
apiKey: 'test-key',
|
|
244
|
-
model: 'claude-opus-5',
|
|
245
|
-
strictToolUse: 'off',
|
|
246
|
-
});
|
|
247
|
-
expect(JSON.stringify(buildParams(off, base('claude-opus-5')).tools)).not.toContain('"strict"');
|
|
248
|
-
});
|
|
249
|
-
it('ignores empty and unknown enforcement names', () => {
|
|
250
|
-
for (const names of [[], ['unknown_tool']]) {
|
|
251
|
-
const body = buildParams(makeProvider(), {
|
|
252
|
-
...base('claude-opus-5'),
|
|
253
|
-
enforceToolInputSchema: names,
|
|
254
|
-
});
|
|
255
|
-
expect(JSON.stringify(body.tools)).not.toContain('"strict"');
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
it('serializes the reviewed model schema unchanged without unsupported constraints', () => {
|
|
259
|
-
const schema = {
|
|
260
|
-
type: 'object',
|
|
261
|
-
properties: {
|
|
262
|
-
path: { type: 'string' },
|
|
263
|
-
old_string: { type: 'string' },
|
|
264
|
-
new_string: { type: 'string' },
|
|
265
|
-
replace_all: { type: 'boolean' },
|
|
266
|
-
},
|
|
267
|
-
required: ['path', 'old_string', 'new_string'],
|
|
268
|
-
additionalProperties: false,
|
|
269
|
-
};
|
|
270
|
-
const body = buildParams(makeProvider(), {
|
|
271
|
-
model: 'claude-opus-5',
|
|
272
|
-
messages: [{ role: 'user', content: 'append' }],
|
|
273
|
-
tools: [
|
|
274
|
-
{
|
|
275
|
-
type: 'function',
|
|
276
|
-
function: {
|
|
277
|
-
name: 'edit',
|
|
278
|
-
description: 'Edit',
|
|
279
|
-
parameters: schema,
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
enforceToolInputSchema: ['edit'],
|
|
284
|
-
});
|
|
285
|
-
expect(body.tools?.[0]).toEqual({
|
|
286
|
-
name: 'edit',
|
|
287
|
-
description: 'Edit',
|
|
288
|
-
input_schema: schema,
|
|
289
|
-
strict: true,
|
|
290
|
-
});
|
|
291
|
-
expect(JSON.stringify(body.tools)).not.toContain('"minimum"');
|
|
292
|
-
});
|
|
293
|
-
it('coexists with cache_control on the tools-array tail', () => {
|
|
294
|
-
const body = buildParams(makeProvider(), {
|
|
295
|
-
...base('claude-opus-5'),
|
|
296
|
-
enforceToolInputSchema: ['beta'],
|
|
297
|
-
cacheControl: { type: 'auto' },
|
|
298
|
-
});
|
|
299
|
-
expect(body.tools?.[0]).not.toHaveProperty('strict');
|
|
300
|
-
expect(body.tools?.[1]).toMatchObject({
|
|
301
|
-
name: 'beta',
|
|
302
|
-
strict: true,
|
|
303
|
-
cache_control: { type: 'ephemeral' },
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
describe('prompt caching', () => {
|
|
308
|
-
const cachedParams = () => ({
|
|
309
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
310
|
-
messages: [
|
|
311
|
-
{ role: 'system', content: 'STATIC PREFIX', cacheHint: 'cache' },
|
|
312
|
-
{ role: 'system', content: 'DYNAMIC SEGMENT', cacheHint: 'ephemeral' },
|
|
313
|
-
{ role: 'user', content: 'hello' },
|
|
314
|
-
],
|
|
315
|
-
tools,
|
|
316
|
-
cacheControl: { type: 'auto' },
|
|
317
|
-
});
|
|
318
|
-
it('emits zero cache_control blocks when cacheControl is not requested', () => {
|
|
319
|
-
const params = cachedParams();
|
|
320
|
-
params.cacheControl = undefined;
|
|
321
|
-
const body = buildParams(makeProvider(), params);
|
|
322
|
-
expect(JSON.stringify(body)).not.toContain('cache_control');
|
|
323
|
-
// System still arrives as cacheHint-preserving blocks.
|
|
324
|
-
expect(body.system).toEqual([
|
|
325
|
-
{ type: 'text', text: 'STATIC PREFIX' },
|
|
326
|
-
{ type: 'text', text: 'DYNAMIC SEGMENT' },
|
|
327
|
-
]);
|
|
328
|
-
});
|
|
329
|
-
it('preserves system segment boundaries and marks only the cache-tagged block', () => {
|
|
330
|
-
const body = buildParams(makeProvider(), cachedParams());
|
|
331
|
-
expect(body.system).toEqual([
|
|
332
|
-
{
|
|
333
|
-
type: 'text',
|
|
334
|
-
text: 'STATIC PREFIX',
|
|
335
|
-
cache_control: { type: 'ephemeral' },
|
|
336
|
-
},
|
|
337
|
-
{ type: 'text', text: 'DYNAMIC SEGMENT' },
|
|
338
|
-
]);
|
|
339
|
-
});
|
|
340
|
-
it('marks the tools-array tail and the last message block', () => {
|
|
341
|
-
const body = buildParams(makeProvider(), cachedParams());
|
|
342
|
-
const bodyTools = body.tools;
|
|
343
|
-
expect(bodyTools[0]?.cache_control).toBeUndefined();
|
|
344
|
-
expect(bodyTools[1]?.cache_control).toEqual({ type: 'ephemeral' });
|
|
345
|
-
const messages = body.messages;
|
|
346
|
-
expect(messages[messages.length - 1]?.content).toEqual([
|
|
347
|
-
{ type: 'text', text: 'hello', cache_control: { type: 'ephemeral' } },
|
|
348
|
-
]);
|
|
349
|
-
});
|
|
350
|
-
it('places the final breakpoint on the last tool_result block of a tool turn', () => {
|
|
351
|
-
const params = cachedParams();
|
|
352
|
-
params.messages = [
|
|
353
|
-
{ role: 'system', content: 'STATIC PREFIX', cacheHint: 'cache' },
|
|
354
|
-
{ role: 'user', content: 'run the tool' },
|
|
355
|
-
{
|
|
356
|
-
role: 'assistant',
|
|
357
|
-
content: null,
|
|
358
|
-
toolCalls: [
|
|
359
|
-
{
|
|
360
|
-
id: 'tu_1',
|
|
361
|
-
type: 'function',
|
|
362
|
-
function: { name: 'alpha', arguments: '{}' },
|
|
363
|
-
},
|
|
364
|
-
],
|
|
365
|
-
},
|
|
366
|
-
{ role: 'tool', content: 'tool says hi', toolCallId: 'tu_1' },
|
|
367
|
-
];
|
|
368
|
-
const body = buildParams(makeProvider(), params);
|
|
369
|
-
const messages = body.messages;
|
|
370
|
-
expect(messages[messages.length - 1]?.content).toEqual([
|
|
371
|
-
{
|
|
372
|
-
type: 'tool_result',
|
|
373
|
-
tool_use_id: 'tu_1',
|
|
374
|
-
content: 'tool says hi',
|
|
375
|
-
cache_control: { type: 'ephemeral' },
|
|
376
|
-
},
|
|
377
|
-
]);
|
|
378
|
-
});
|
|
379
|
-
it('keeps the Claude Code identity block FIRST on the OAuth path', () => {
|
|
380
|
-
const provider = new AnthropicProvider({ authToken: 'cc-oauth-token' });
|
|
381
|
-
const body = buildParams(provider, cachedParams());
|
|
382
|
-
const system = body.system;
|
|
383
|
-
expect(system[0]?.text).toMatch(/^You are Claude Code/);
|
|
384
|
-
expect(system[0]?.cache_control).toBeUndefined();
|
|
385
|
-
expect(system[1]).toEqual({
|
|
386
|
-
type: 'text',
|
|
387
|
-
text: 'STATIC PREFIX',
|
|
388
|
-
cache_control: { type: 'ephemeral' },
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
async function* delayedAnthropicStream(delayMs) {
|
|
394
|
-
yield {
|
|
395
|
-
type: 'message_start',
|
|
396
|
-
message: {
|
|
397
|
-
id: 'msg_test',
|
|
398
|
-
usage: { input_tokens: 1, output_tokens: 0 },
|
|
399
|
-
},
|
|
400
|
-
};
|
|
401
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
402
|
-
yield {
|
|
403
|
-
type: 'content_block_start',
|
|
404
|
-
index: 0,
|
|
405
|
-
content_block: { type: 'text' },
|
|
406
|
-
};
|
|
407
|
-
yield {
|
|
408
|
-
type: 'content_block_delta',
|
|
409
|
-
index: 0,
|
|
410
|
-
delta: { type: 'text_delta', text: 'ok' },
|
|
411
|
-
};
|
|
412
|
-
yield {
|
|
413
|
-
type: 'content_block_stop',
|
|
414
|
-
index: 0,
|
|
415
|
-
};
|
|
416
|
-
yield {
|
|
417
|
-
type: 'message_delta',
|
|
418
|
-
delta: { stop_reason: 'end_turn' },
|
|
419
|
-
usage: { output_tokens: 1 },
|
|
420
|
-
};
|
|
421
|
-
yield {
|
|
422
|
-
type: 'message_stop',
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
//# sourceMappingURL=anthropic.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.test.js","sourceRoot":"","sources":["../../src/__tests__/anthropic.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAErE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,E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,EAAE,CAAA;YAChD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzB,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,eAAe;gBACrB,aAAa,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;aACpC,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAAC,OAAe;IACrD,MAAM;QACL,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE;YACR,EAAE,EAAE,UAAU;YACd,KAAK,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE;SAC5C;KACD,CAAA;IACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAC5D,MAAM;QACL,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,CAAC;QACR,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;KAC/B,CAAA;IACD,MAAM;QACL,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE;KACzC,CAAA;IACD,MAAM;QACL,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,CAAC;KACR,CAAA;IACD,MAAM;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE;QAClC,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE;KAC3B,CAAA;IACD,MAAM;QACL,IAAI,EAAE,cAAc;KACpB,CAAA;AACF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"background-delegation.live.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/background-delegation.live.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { CompletionInbox, ToolRegistry, buildCoordinatorTools, drainQuery, runAgent, } from '@namzu/sdk';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { AnthropicProvider } from '../client.js';
|
|
4
|
-
/**
|
|
5
|
-
* Does a real model actually receive a worker it stopped waiting for?
|
|
6
|
-
*
|
|
7
|
-
* Everything else about this mechanism is tested against fakes: the inbox
|
|
8
|
-
* queues what nobody claimed, the tools claim what they deliver, the loop
|
|
9
|
-
* drains the rest into the transcript. All of it can be true and the feature
|
|
10
|
-
* still useless, because the part that decides whether it works is whether a
|
|
11
|
-
* MODEL reads the notification and acts on it — and no fake can answer that.
|
|
12
|
-
*
|
|
13
|
-
* So this runs the whole thing against the live API: a real supervisor model,
|
|
14
|
-
* a real worker model, a background launch, and an assertion that the answer
|
|
15
|
-
* the supervisor finally gives contains something only the worker knew.
|
|
16
|
-
*
|
|
17
|
-
* The gateway here is deliberately hand-rolled over `runAgent` rather than
|
|
18
|
-
* the kernel's `LocalTaskGateway`. That is the shape a host implements, so it
|
|
19
|
-
* doubles as proof that the inbox needs nothing from a gateway beyond the
|
|
20
|
-
* `onTaskCompleted` every gateway already has.
|
|
21
|
-
*
|
|
22
|
-
* Skipped without a key. Run with:
|
|
23
|
-
*
|
|
24
|
-
* ANTHROPIC_API_KEY=… pnpm --filter @namzu/anthropic test
|
|
25
|
-
*/
|
|
26
|
-
const KEY = process.env.ANTHROPIC_API_KEY;
|
|
27
|
-
const MODEL = process.env.NAMZU_WIRE_TEST_MODEL ?? 'claude-haiku-4-5';
|
|
28
|
-
/** The fact only the worker can know, so its presence proves delivery. */
|
|
29
|
-
const SECRET = 'PELICAN-7731';
|
|
30
|
-
function provider() {
|
|
31
|
-
return new AnthropicProvider({ apiKey: KEY, model: MODEL });
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* A host-shaped gateway: spawns a real child run per task and announces it.
|
|
35
|
-
*
|
|
36
|
-
* Nothing here is kernel code. It implements `TaskGateway` the way an
|
|
37
|
-
* embedding application does, which is the point — the inbox attaches to it
|
|
38
|
-
* unchanged.
|
|
39
|
-
*/
|
|
40
|
-
function liveGateway() {
|
|
41
|
-
const handles = new Map();
|
|
42
|
-
const settled = new Map();
|
|
43
|
-
const listeners = new Set();
|
|
44
|
-
let seq = 0;
|
|
45
|
-
return {
|
|
46
|
-
async createTask({ agentId, prompt }) {
|
|
47
|
-
seq += 1;
|
|
48
|
-
const taskId = `tsk_live_${seq}`;
|
|
49
|
-
const handle = {
|
|
50
|
-
taskId: taskId,
|
|
51
|
-
agentId,
|
|
52
|
-
state: 'running',
|
|
53
|
-
createdAt: Date.now(),
|
|
54
|
-
};
|
|
55
|
-
handles.set(taskId, handle);
|
|
56
|
-
settled.set(taskId, runAgent({
|
|
57
|
-
provider: provider(),
|
|
58
|
-
model: MODEL,
|
|
59
|
-
prompt,
|
|
60
|
-
instructions: 'Answer in one short sentence. Do not explain yourself.',
|
|
61
|
-
maxIterations: 2,
|
|
62
|
-
tokenBudget: 20_000,
|
|
63
|
-
}).then((run) => {
|
|
64
|
-
const done = {
|
|
65
|
-
...handle,
|
|
66
|
-
state: 'completed',
|
|
67
|
-
completedAt: Date.now(),
|
|
68
|
-
result: {
|
|
69
|
-
status: 'completed',
|
|
70
|
-
result: run.output ?? '',
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
handles.set(taskId, done);
|
|
74
|
-
for (const cb of listeners)
|
|
75
|
-
cb(done);
|
|
76
|
-
return done;
|
|
77
|
-
}));
|
|
78
|
-
return handle;
|
|
79
|
-
},
|
|
80
|
-
waitForTask: async (taskId) => {
|
|
81
|
-
const pending = settled.get(taskId);
|
|
82
|
-
if (!pending)
|
|
83
|
-
throw new Error(`no task ${taskId}`);
|
|
84
|
-
return pending;
|
|
85
|
-
},
|
|
86
|
-
continueTask: async () => undefined,
|
|
87
|
-
cancelTask: () => undefined,
|
|
88
|
-
getTask: (taskId) => handles.get(taskId),
|
|
89
|
-
listTasks: () => [...handles.values()],
|
|
90
|
-
onTaskCompleted: (cb) => {
|
|
91
|
-
listeners.add(cb);
|
|
92
|
-
return () => listeners.delete(cb);
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
describe.skipIf(!KEY)('a background worker reaches a real supervisor', () => {
|
|
97
|
-
it('delivers the result through the transcript, with no polling', async () => {
|
|
98
|
-
const gateway = liveGateway();
|
|
99
|
-
const inbox = new CompletionInbox();
|
|
100
|
-
inbox.attach(gateway);
|
|
101
|
-
const tools = new ToolRegistry();
|
|
102
|
-
for (const tool of buildCoordinatorTools({
|
|
103
|
-
gateway,
|
|
104
|
-
completionInbox: inbox,
|
|
105
|
-
workingDirectory: process.cwd(),
|
|
106
|
-
allowedAgentIds: ['lookup'],
|
|
107
|
-
})) {
|
|
108
|
-
tools.register(tool);
|
|
109
|
-
}
|
|
110
|
-
const run = await drainQuery({
|
|
111
|
-
provider: provider(),
|
|
112
|
-
tools,
|
|
113
|
-
completionInbox: inbox,
|
|
114
|
-
agentId: 'supervisor',
|
|
115
|
-
agentName: 'Supervisor',
|
|
116
|
-
messages: [
|
|
117
|
-
{
|
|
118
|
-
role: 'user',
|
|
119
|
-
content: [
|
|
120
|
-
'Delegate to the "lookup" agent, in the BACKGROUND (background: true), this exact prompt:',
|
|
121
|
-
`"Reply with exactly this token and nothing else: ${SECRET}"`,
|
|
122
|
-
'',
|
|
123
|
-
'Do not wait for it with wait_for_task and do not list tasks in a loop.',
|
|
124
|
-
'After launching it, just say "launched" and stop.',
|
|
125
|
-
'Its result will arrive on its own; when it does, reply with the token you received.',
|
|
126
|
-
].join('\n'),
|
|
127
|
-
timestamp: Date.now(),
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
workingDirectory: process.cwd(),
|
|
131
|
-
runConfig: {
|
|
132
|
-
model: MODEL,
|
|
133
|
-
timeoutMs: 180_000,
|
|
134
|
-
tokenBudget: 200_000,
|
|
135
|
-
maxIterations: 6,
|
|
136
|
-
maxResponseTokens: 1_024,
|
|
137
|
-
},
|
|
138
|
-
sessionId: 'ses_live_delegation',
|
|
139
|
-
threadId: 'thd_live_delegation',
|
|
140
|
-
projectId: 'prj_live_delegation',
|
|
141
|
-
tenantId: 'tnt_live_delegation',
|
|
142
|
-
});
|
|
143
|
-
const transcript = run.messages
|
|
144
|
-
.filter((m) => m.role === 'user')
|
|
145
|
-
.map((m) => (typeof m.content === 'string' ? m.content : JSON.stringify(m.content)))
|
|
146
|
-
.join('\n');
|
|
147
|
-
// 1. The notification actually landed in the supervisor's transcript.
|
|
148
|
-
expect(transcript, 'no task-notification reached the transcript').toContain('task-notification');
|
|
149
|
-
expect(transcript).toContain(SECRET);
|
|
150
|
-
// 2. The model read it. This is the half no fake can establish: the
|
|
151
|
-
// worker's token appears in the supervisor's own final answer, and
|
|
152
|
-
// the supervisor never had it any other way.
|
|
153
|
-
expect(run.result ?? '', 'the supervisor never used what it was told').toContain(SECRET);
|
|
154
|
-
// 3. It got there without polling, which is the whole complaint the
|
|
155
|
-
// fix answers — `agent_task_list` in a sleep loop was the only move
|
|
156
|
-
// on the board before this.
|
|
157
|
-
const listCalls = (run.steps ?? [])
|
|
158
|
-
.flatMap((s) => s.toolCalls ?? [])
|
|
159
|
-
.filter((c) => c.function.name === 'agent_task_list');
|
|
160
|
-
expect(listCalls.length, 'the model still had to poll').toBe(0);
|
|
161
|
-
}, 300_000);
|
|
162
|
-
it('still delivers the result inline when the launch is not backgrounded', async () => {
|
|
163
|
-
// The path `dc16d58` protects: a blocking launch answers as its own
|
|
164
|
-
// tool_result, and must NOT also arrive as an envelope.
|
|
165
|
-
const gateway = liveGateway();
|
|
166
|
-
const inbox = new CompletionInbox();
|
|
167
|
-
inbox.attach(gateway);
|
|
168
|
-
const tools = new ToolRegistry();
|
|
169
|
-
for (const tool of buildCoordinatorTools({
|
|
170
|
-
gateway,
|
|
171
|
-
completionInbox: inbox,
|
|
172
|
-
workingDirectory: process.cwd(),
|
|
173
|
-
allowedAgentIds: ['lookup'],
|
|
174
|
-
})) {
|
|
175
|
-
tools.register(tool);
|
|
176
|
-
}
|
|
177
|
-
const run = await drainQuery({
|
|
178
|
-
provider: provider(),
|
|
179
|
-
tools,
|
|
180
|
-
completionInbox: inbox,
|
|
181
|
-
agentId: 'supervisor',
|
|
182
|
-
agentName: 'Supervisor',
|
|
183
|
-
messages: [
|
|
184
|
-
{
|
|
185
|
-
role: 'user',
|
|
186
|
-
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.`,
|
|
187
|
-
timestamp: Date.now(),
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
workingDirectory: process.cwd(),
|
|
191
|
-
runConfig: {
|
|
192
|
-
model: MODEL,
|
|
193
|
-
timeoutMs: 180_000,
|
|
194
|
-
tokenBudget: 200_000,
|
|
195
|
-
maxIterations: 6,
|
|
196
|
-
maxResponseTokens: 1_024,
|
|
197
|
-
},
|
|
198
|
-
sessionId: 'ses_live_delegation',
|
|
199
|
-
threadId: 'thd_live_delegation',
|
|
200
|
-
projectId: 'prj_live_delegation',
|
|
201
|
-
tenantId: 'tnt_live_delegation',
|
|
202
|
-
});
|
|
203
|
-
expect(run.result ?? '').toContain(SECRET);
|
|
204
|
-
const transcript = run.messages
|
|
205
|
-
.filter((m) => m.role === 'user')
|
|
206
|
-
.map((m) => (typeof m.content === 'string' ? m.content : JSON.stringify(m.content)))
|
|
207
|
-
.join('\n');
|
|
208
|
-
// Delivered once, as a tool_result — no duplicate envelope.
|
|
209
|
-
expect(transcript, 'the blocking result was announced a second time').not.toContain('task-notification');
|
|
210
|
-
}, 300_000);
|
|
211
|
-
});
|
|
212
|
-
//# sourceMappingURL=background-delegation.live.test.js.map
|