@namzu/anthropic 3.0.1 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/dist/client.d.ts +15 -1
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +18 -0
  5. package/dist/client.js.map +1 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +8 -0
  9. package/dist/index.js.map +1 -1
  10. package/package.json +12 -2
  11. package/src/client.ts +21 -0
  12. package/src/index.ts +18 -0
  13. package/dist/__tests__/anthropic.test.d.ts +0 -2
  14. package/dist/__tests__/anthropic.test.d.ts.map +0 -1
  15. package/dist/__tests__/anthropic.test.js +0 -425
  16. package/dist/__tests__/anthropic.test.js.map +0 -1
  17. package/dist/__tests__/background-delegation.live.test.d.ts +0 -2
  18. package/dist/__tests__/background-delegation.live.test.d.ts.map +0 -1
  19. package/dist/__tests__/background-delegation.live.test.js +0 -212
  20. package/dist/__tests__/background-delegation.live.test.js.map +0 -1
  21. package/dist/__tests__/block-shape-guard.test.d.ts +0 -2
  22. package/dist/__tests__/block-shape-guard.test.d.ts.map +0 -1
  23. package/dist/__tests__/block-shape-guard.test.js +0 -218
  24. package/dist/__tests__/block-shape-guard.test.js.map +0 -1
  25. package/dist/__tests__/cache-anchors.test.d.ts +0 -2
  26. package/dist/__tests__/cache-anchors.test.d.ts.map +0 -1
  27. package/dist/__tests__/cache-anchors.test.js +0 -220
  28. package/dist/__tests__/cache-anchors.test.js.map +0 -1
  29. package/dist/__tests__/citations.test.d.ts +0 -2
  30. package/dist/__tests__/citations.test.d.ts.map +0 -1
  31. package/dist/__tests__/citations.test.js +0 -189
  32. package/dist/__tests__/citations.test.js.map +0 -1
  33. package/dist/__tests__/content-blocks.test.d.ts +0 -2
  34. package/dist/__tests__/content-blocks.test.d.ts.map +0 -1
  35. package/dist/__tests__/content-blocks.test.js +0 -131
  36. package/dist/__tests__/content-blocks.test.js.map +0 -1
  37. package/dist/__tests__/document-input.test.d.ts +0 -2
  38. package/dist/__tests__/document-input.test.d.ts.map +0 -1
  39. package/dist/__tests__/document-input.test.js +0 -98
  40. package/dist/__tests__/document-input.test.js.map +0 -1
  41. package/dist/__tests__/error-taxonomy.test.d.ts +0 -16
  42. package/dist/__tests__/error-taxonomy.test.d.ts.map +0 -1
  43. package/dist/__tests__/error-taxonomy.test.js +0 -242
  44. package/dist/__tests__/error-taxonomy.test.js.map +0 -1
  45. package/dist/__tests__/reasoning-close.test.d.ts +0 -2
  46. package/dist/__tests__/reasoning-close.test.d.ts.map +0 -1
  47. package/dist/__tests__/reasoning-close.test.js +0 -219
  48. package/dist/__tests__/reasoning-close.test.js.map +0 -1
  49. package/dist/__tests__/thinking-capability.test.d.ts +0 -2
  50. package/dist/__tests__/thinking-capability.test.d.ts.map +0 -1
  51. package/dist/__tests__/thinking-capability.test.js +0 -206
  52. package/dist/__tests__/thinking-capability.test.js.map +0 -1
  53. package/dist/__tests__/thinking-contract.live.test.d.ts +0 -2
  54. package/dist/__tests__/thinking-contract.live.test.d.ts.map +0 -1
  55. package/dist/__tests__/thinking-contract.live.test.js +0 -97
  56. package/dist/__tests__/thinking-contract.live.test.js.map +0 -1
  57. package/dist/__tests__/thinking-request-body.test.d.ts +0 -2
  58. package/dist/__tests__/thinking-request-body.test.d.ts.map +0 -1
  59. package/dist/__tests__/thinking-request-body.test.js +0 -90
  60. package/dist/__tests__/thinking-request-body.test.js.map +0 -1
  61. package/dist/__tests__/wire-contract.live.test.d.ts +0 -2
  62. package/dist/__tests__/wire-contract.live.test.d.ts.map +0 -1
  63. package/dist/__tests__/wire-contract.live.test.js +0 -254
  64. package/dist/__tests__/wire-contract.live.test.js.map +0 -1
  65. package/src/__tests__/anthropic.test.ts +0 -490
  66. package/src/__tests__/background-delegation.live.test.ts +0 -243
  67. package/src/__tests__/block-shape-guard.test.ts +0 -256
  68. package/src/__tests__/cache-anchors.test.ts +0 -262
  69. package/src/__tests__/citations.test.ts +0 -218
  70. package/src/__tests__/content-blocks.test.ts +0 -153
  71. package/src/__tests__/document-input.test.ts +0 -131
  72. package/src/__tests__/error-taxonomy.test.ts +0 -274
  73. package/src/__tests__/reasoning-close.test.ts +0 -262
  74. package/src/__tests__/thinking-capability.test.ts +0 -235
  75. package/src/__tests__/thinking-contract.live.test.ts +0 -125
  76. package/src/__tests__/thinking-request-body.test.ts +0 -111
  77. package/src/__tests__/wire-contract.live.test.ts +0 -312
@@ -1,312 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
-
3
- import {
4
- findDraft07Only,
5
- findStrictSchemaViolations,
6
- getBuiltinTools,
7
- renderToolSchema,
8
- toSchemaDialect,
9
- } from '@namzu/sdk'
10
-
11
- /**
12
- * The test that would have caught both outages.
13
- *
14
- * Every other test in this repo renders a schema and asserts something about
15
- * the object. Both production breakages were schemas that looked fine as
16
- * objects and were rejected by the wire:
17
- *
18
- * - `edit.insertLine` used `oneOf`, which strict tool use refuses.
19
- * - `read.readRange` is a Zod tuple, which renders draft-07 `items: [a, b]`
20
- * while this wire requires draft 2020-12 — rejected with `strict` unset,
21
- * so a guard scoped to strict never saw it.
22
- *
23
- * Neither could fail offline, because neither was wrong offline. So this one
24
- * talks to the real API.
25
- *
26
- * It asks the cheapest question that still exercises schema validation:
27
- * `max_tokens: 1` and a one-word prompt. Validation happens before generation,
28
- * so a rejected schema costs nothing and an accepted one costs a single token.
29
- *
30
- * Skipped without a key, so CI stays green where none is configured. Run it
31
- * with:
32
- *
33
- * ANTHROPIC_API_KEY=… pnpm --filter @namzu/anthropic test
34
- */
35
-
36
- const KEY = process.env.ANTHROPIC_API_KEY
37
- const MODEL = process.env.NAMZU_WIRE_TEST_MODEL ?? 'claude-haiku-4-5'
38
-
39
- interface WireResult {
40
- readonly ok: boolean
41
- readonly status: number
42
- readonly message: string
43
- }
44
-
45
- async function offerTools(tools: unknown[]): Promise<WireResult> {
46
- const res = await fetch('https://api.anthropic.com/v1/messages', {
47
- method: 'POST',
48
- headers: {
49
- 'x-api-key': KEY as string,
50
- 'anthropic-version': '2023-06-01',
51
- 'content-type': 'application/json',
52
- },
53
- body: JSON.stringify({
54
- model: MODEL,
55
- max_tokens: 1,
56
- messages: [{ role: 'user', content: 'hi' }],
57
- tools,
58
- }),
59
- })
60
- const body: unknown = await res.json().catch(() => ({}))
61
- const message =
62
- (body as { error?: { message?: string } } | null)?.error?.message ?? (res.ok ? '' : 'unknown')
63
- return { ok: res.ok, status: res.status, message }
64
- }
65
-
66
- /** A tool as this driver would put it on the wire. */
67
- function wireTool(name: string, schema: Record<string, unknown>, strict: boolean): unknown {
68
- return {
69
- name,
70
- description: 'contract probe',
71
- input_schema: toSchemaDialect(schema, '2020-12'),
72
- ...(strict ? { strict: true } : {}),
73
- }
74
- }
75
-
76
- describe.skipIf(!KEY)('every shipped tool is expressible on this wire', () => {
77
- const tools = getBuiltinTools()
78
-
79
- it('offers all of them in one request, the way a real run does', async () => {
80
- // One request with the whole toolset, because that is the shape that
81
- // broke: the wire rejects the WHOLE request for one bad schema, so a
82
- // per-tool loop would pass while a real run still died.
83
- const payload = tools.map((t) =>
84
- wireTool(
85
- t.name,
86
- (t.modelInputSchema as Record<string, unknown> | undefined) ??
87
- renderToolSchema(t.inputSchema),
88
- Boolean(t.enforceModelInput),
89
- ),
90
- )
91
-
92
- const result = await offerTools(payload)
93
- expect(result.ok, `HTTP ${result.status}: ${result.message}`).toBe(true)
94
- }, 180_000)
95
-
96
- it.each(tools.map((t) => [t.name, t] as const))(
97
- '%s alone',
98
- async (name, tool) => {
99
- // And individually, so a failure names the tool instead of the batch.
100
- const schema =
101
- (tool.modelInputSchema as Record<string, unknown> | undefined) ??
102
- renderToolSchema(tool.inputSchema)
103
- const result = await offerTools([wireTool(name, schema, Boolean(tool.enforceModelInput))])
104
- expect(result.ok, `HTTP ${result.status}: ${result.message}`).toBe(true)
105
- },
106
- 180_000,
107
- )
108
- })
109
-
110
- describe.skipIf(!KEY)('the dialect conversion is what makes the difference', () => {
111
- it('rejects the draft-07 tuple and accepts the converted one', async () => {
112
- // Pins the actual mechanism rather than trusting that conversion helped.
113
- // If the wire ever starts accepting draft-07 tuples this test says so,
114
- // and if it ever stops accepting `prefixItems` it says that too.
115
- const draft07 = {
116
- type: 'object',
117
- properties: {
118
- range: {
119
- type: 'array',
120
- minItems: 2,
121
- maxItems: 2,
122
- items: [{ type: 'integer' }, { type: 'integer' }],
123
- },
124
- },
125
- }
126
-
127
- const before = await offerTools([{ name: 'probe', description: 'p', input_schema: draft07 }])
128
- expect(before.ok).toBe(false)
129
- expect(before.message).toMatch(/2020-12/)
130
-
131
- const after = await offerTools([
132
- { name: 'probe', description: 'p', input_schema: toSchemaDialect(draft07, '2020-12') },
133
- ])
134
- expect(after.ok, `HTTP ${after.status}: ${after.message}`).toBe(true)
135
- }, 180_000)
136
- })
137
-
138
- /**
139
- * The strict subset, measured rather than read.
140
- *
141
- * `findStrictSchemaViolations` carries a deny-list, and the first version of it
142
- * was derived from prose. It was wrong in both directions: it refused
143
- * `minLength`/`maxLength`, which this wire accepts, so it would have blocked
144
- * working tools; and it permitted `prefixItems`, which this wire rejects, so it
145
- * would have vouched for a broken one. A deny-list nobody probed is a guess in
146
- * a confident tone.
147
- *
148
- * This block is where the list comes from. Each row is one request; a row that
149
- * changes means the subset moved, and the deny-list has to move with it.
150
- */
151
- const STRICT_SUBSET: readonly (readonly [string, Record<string, unknown>, boolean])[] = [
152
- ['minLength/maxLength', { type: 'string', minLength: 1, maxLength: 9 }, true],
153
- ['pattern', { type: 'string', pattern: '^a+$' }, true],
154
- ['format', { type: 'string', format: 'uri' }, true],
155
- ['enum', { type: 'string', enum: ['a', 'b'] }, true],
156
- ['anyOf', { anyOf: [{ type: 'integer' }, { const: 'end' }] }, true],
157
- // `minItems` is a bound on the VALUE, not a rejected keyword: 0 and 1 pass,
158
- // anything above does not. A blanket denial would refuse the ordinary
159
- // spelling of a non-empty array.
160
- ['minItems: 0', { type: 'array', items: { type: 'string' }, minItems: 0 }, true],
161
- ['minItems: 1', { type: 'array', items: { type: 'string' }, minItems: 1 }, true],
162
- ['minItems: 2', { type: 'array', items: { type: 'string' }, minItems: 2 }, false],
163
- ['maxItems', { type: 'array', items: { type: 'string' }, maxItems: 3 }, false],
164
- ['uniqueItems', { type: 'array', items: { type: 'string' }, uniqueItems: true }, false],
165
- ['minimum', { type: 'integer', minimum: 0 }, false],
166
- ['oneOf', { oneOf: [{ type: 'integer' }, { const: 'end' }] }, false],
167
- ['not', { not: { type: 'null' } }, false],
168
- // The one that interacts with the dialect fix: a tuple is unexpressible
169
- // under strict in EITHER spelling, so converting it only changes the error.
170
- ['prefixItems', { type: 'array', prefixItems: [{ type: 'integer' }] }, false],
171
- ]
172
-
173
- describe.skipIf(!KEY)('the strict subset is what the deny-list says it is', () => {
174
- it.each(STRICT_SUBSET.map(([label, schema, accepted]) => [label, schema, accepted] as const))(
175
- 'strict + %s',
176
- async (label, propSchema, accepted) => {
177
- const result = await offerTools([
178
- {
179
- name: 'probe',
180
- description: 'p',
181
- strict: true,
182
- input_schema: {
183
- type: 'object',
184
- properties: { f: propSchema },
185
- required: ['f'],
186
- additionalProperties: false,
187
- },
188
- },
189
- ])
190
- expect(result.ok, `${label}: HTTP ${result.status}: ${result.message}`).toBe(accepted)
191
-
192
- // And the offline check has to agree with the wire, which is the
193
- // whole point of pinning both in one place.
194
- expect(findStrictSchemaViolations({ properties: { f: propSchema } }).length === 0).toBe(
195
- accepted,
196
- )
197
- },
198
- 180_000,
199
- )
200
-
201
- it('rejects the draft-07 tuple before it ever gets to the strict question', async () => {
202
- // Dialect first, subset second. This is why a guard scoped to strict
203
- // could not have caught `read.readRange`: the tuple is refused with
204
- // `strict` unset too.
205
- const tuple = {
206
- type: 'object',
207
- properties: { f: { type: 'array', items: [{ type: 'integer' }, { type: 'integer' }] } },
208
- }
209
- const result = await offerTools([{ name: 'probe', description: 'p', input_schema: tuple }])
210
-
211
- expect(result.ok).toBe(false)
212
- expect(result.message).toMatch(/2020-12/)
213
- }, 180_000)
214
- })
215
-
216
- describe.skipIf(!KEY)('the positional shape a bridged tool now emits', () => {
217
- it('is accepted once converted', async () => {
218
- // The MCP adapter emits a tuple ONLY where the server pinned the arity
219
- // and closed the tail, because that renders as bounded `prefixItems`.
220
- // The narrowness is the design rather than caution: a tool schema this
221
- // wire refuses fails the WHOLE request instead of degrading one tool,
222
- // so a faithful conversion it will not take is strictly worse than a
223
- // lossy one it will.
224
- //
225
- // The refusal half of this pair is already asserted above, on the
226
- // unconverted spelling — so this says something the sweep does not:
227
- // that the shape we CHOSE to emit is one the wire takes.
228
- const pinned = {
229
- type: 'object',
230
- properties: {
231
- pair: {
232
- type: 'array',
233
- minItems: 2,
234
- maxItems: 2,
235
- items: [{ type: 'string' }, { type: 'number' }],
236
- },
237
- },
238
- required: ['pair'],
239
- additionalProperties: false,
240
- }
241
-
242
- const result = await offerTools([wireTool('pinned_pair', pinned, false)])
243
- expect(result.ok, result.message).toBe(true)
244
- }, 180_000)
245
- })
246
-
247
- describe.skipIf(!KEY)('effort is a per-model SET, and this wire says so itself', () => {
248
- async function withEffort(model: string, effort: string): Promise<WireResult> {
249
- const res = await fetch('https://api.anthropic.com/v1/messages', {
250
- method: 'POST',
251
- headers: {
252
- 'x-api-key': KEY as string,
253
- 'anthropic-version': '2023-06-01',
254
- 'content-type': 'application/json',
255
- },
256
- body: JSON.stringify({
257
- model,
258
- max_tokens: 16,
259
- messages: [{ role: 'user', content: 'Say OK.' }],
260
- output_config: { effort },
261
- }),
262
- })
263
- const body: unknown = await res.json().catch(() => ({}))
264
- const message =
265
- (body as { error?: { message?: string } } | null)?.error?.message ?? (res.ok ? '' : 'unknown')
266
- return { ok: res.ok, status: res.status, message }
267
- }
268
-
269
- it('takes all five levels on a model the table says has all five', async () => {
270
- for (const effort of ['low', 'medium', 'high', 'xhigh', 'max']) {
271
- const result = await withEffort('claude-sonnet-5', effort)
272
- expect(result.ok, `${effort}: ${result.message}`).toBe(true)
273
- }
274
- }, 180_000)
275
-
276
- it('refuses a level a model lacks, and names the set it has', async () => {
277
- // The pairing the capability table exists to express: `max` WITHOUT
278
- // `xhigh`. A boolean could not have said this, and reading the levels
279
- // as a ladder — where anything taking the top rung takes the one below
280
- // — gets it backwards. That reading is how a row in that table came to
281
- // claim a level this wire rejects.
282
- const refused = await withEffort('claude-sonnet-4-6', 'xhigh')
283
- expect(refused.ok).toBe(false)
284
- expect(refused.message).toContain('xhigh')
285
-
286
- const accepted = await withEffort('claude-sonnet-4-6', 'max')
287
- expect(accepted.ok, accepted.message).toBe(true)
288
- }, 180_000)
289
- })
290
-
291
- describe('what can be checked without a key', () => {
292
- it('leaves no draft-07-only construct in any shipped tool', () => {
293
- // The offline half of the same guarantee, so a contributor without a
294
- // key still gets the signal — just not the proof.
295
- for (const tool of getBuiltinTools()) {
296
- const schema =
297
- (tool.modelInputSchema as Record<string, unknown> | undefined) ??
298
- renderToolSchema(tool.inputSchema)
299
- const converted = toSchemaDialect(schema, '2020-12')
300
- expect(findDraft07Only(converted), tool.name).toEqual([])
301
- }
302
- })
303
-
304
- it('still finds one before conversion, so the sweep is not vacuous', () => {
305
- // `read` renders a Zod tuple. If this ever stops finding anything, the
306
- // test above has quietly become a tautology.
307
- const withTuple = getBuiltinTools().filter(
308
- (t) => !t.modelInputSchema && findDraft07Only(renderToolSchema(t.inputSchema)).length > 0,
309
- )
310
- expect(withTuple.map((t) => t.name)).toContain('read')
311
- })
312
- })