@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,189 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { AnthropicProvider } from '../client.js';
|
|
3
|
-
/**
|
|
4
|
-
* The whole citation path existed except the two ends that touch a real
|
|
5
|
-
* provider.
|
|
6
|
-
*
|
|
7
|
-
* The SDK had the `Citation` type, the stream chunk carried a slot for it,
|
|
8
|
-
* the run's stream aggregator collected them onto the assistant message,
|
|
9
|
-
* and the iteration attached them to the turn. Only the mock provider ever
|
|
10
|
-
* emitted one. This driver neither asked for citations nor parsed them, so
|
|
11
|
-
* in a real run the slot was always empty: an answer about a contract
|
|
12
|
-
* arrived as prose, and checking it meant reading the contract again.
|
|
13
|
-
*
|
|
14
|
-
* The location stays a union on purpose. A provider that segments by
|
|
15
|
-
* character offset has no page number, and inventing one would make an
|
|
16
|
-
* uncheckable citation look checkable.
|
|
17
|
-
*/
|
|
18
|
-
const PDF = 'JVBERi0xLjQKJSVFT0Y=';
|
|
19
|
-
function providerOver(events, seen = {}) {
|
|
20
|
-
const provider = new AnthropicProvider({ apiKey: 'test-key' });
|
|
21
|
-
provider.client = {
|
|
22
|
-
messages: {
|
|
23
|
-
create: vi.fn(async (body) => {
|
|
24
|
-
seen.body = body;
|
|
25
|
-
return (async function* () {
|
|
26
|
-
for (const event of events)
|
|
27
|
-
yield event;
|
|
28
|
-
})();
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
return provider;
|
|
33
|
-
}
|
|
34
|
-
async function chunksOf(events) {
|
|
35
|
-
const provider = providerOver(events);
|
|
36
|
-
const out = [];
|
|
37
|
-
for await (const chunk of provider.chatStream({
|
|
38
|
-
model: 'm',
|
|
39
|
-
messages: [{ role: 'user', content: 'q' }],
|
|
40
|
-
})) {
|
|
41
|
-
out.push(chunk);
|
|
42
|
-
}
|
|
43
|
-
return out;
|
|
44
|
-
}
|
|
45
|
-
function citationEvent(citation) {
|
|
46
|
-
return {
|
|
47
|
-
type: 'content_block_delta',
|
|
48
|
-
index: 0,
|
|
49
|
-
delta: { type: 'citations_delta', citation },
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const PAGE_CITATION = {
|
|
53
|
-
type: 'page_location',
|
|
54
|
-
cited_text: 'the term is five years',
|
|
55
|
-
document_index: 0,
|
|
56
|
-
document_title: 'lease.pdf',
|
|
57
|
-
start_page_number: 3,
|
|
58
|
-
end_page_number: 3,
|
|
59
|
-
};
|
|
60
|
-
describe('a cited passage reaches the caller', () => {
|
|
61
|
-
it('emits the citation on the chunk delta', async () => {
|
|
62
|
-
const chunks = await chunksOf([
|
|
63
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
64
|
-
citationEvent(PAGE_CITATION),
|
|
65
|
-
{ type: 'message_delta', delta: { stop_reason: 'end_turn' } },
|
|
66
|
-
]);
|
|
67
|
-
const cited = chunks.find((c) => c.delta.citation)?.delta.citation;
|
|
68
|
-
expect(cited?.citedText).toBe('the term is five years');
|
|
69
|
-
expect(cited?.documentIndex).toBe(0);
|
|
70
|
-
expect(cited?.documentTitle).toBe('lease.pdf');
|
|
71
|
-
expect(cited?.location).toEqual({ kind: 'page', start: 3, end: 3 });
|
|
72
|
-
});
|
|
73
|
-
it('does not emit it as text — a citation is not prose', async () => {
|
|
74
|
-
const chunks = await chunksOf([
|
|
75
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
76
|
-
citationEvent(PAGE_CITATION),
|
|
77
|
-
]);
|
|
78
|
-
expect(chunks.some((c) => c.delta.content)).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
it('reads a character-offset citation as char, not as a page', async () => {
|
|
81
|
-
const chunks = await chunksOf([
|
|
82
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
83
|
-
citationEvent({
|
|
84
|
-
cited_text: 'clause 4',
|
|
85
|
-
document_index: 1,
|
|
86
|
-
start_char_index: 120,
|
|
87
|
-
end_char_index: 148,
|
|
88
|
-
}),
|
|
89
|
-
]);
|
|
90
|
-
expect(chunks.find((c) => c.delta.citation)?.delta.citation?.location).toEqual({
|
|
91
|
-
kind: 'char',
|
|
92
|
-
start: 120,
|
|
93
|
-
end: 148,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it('reads a block citation as block', async () => {
|
|
97
|
-
const chunks = await chunksOf([
|
|
98
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
99
|
-
citationEvent({
|
|
100
|
-
cited_text: 'row 7',
|
|
101
|
-
document_index: 0,
|
|
102
|
-
start_block_index: 7,
|
|
103
|
-
end_block_index: 8,
|
|
104
|
-
}),
|
|
105
|
-
]);
|
|
106
|
-
expect(chunks.find((c) => c.delta.citation)?.delta.citation?.location).toEqual({
|
|
107
|
-
kind: 'block',
|
|
108
|
-
start: 7,
|
|
109
|
-
end: 8,
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
it('carries several citations through in order', async () => {
|
|
113
|
-
const chunks = await chunksOf([
|
|
114
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
115
|
-
citationEvent({ ...PAGE_CITATION, cited_text: 'first' }),
|
|
116
|
-
{ type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: ' and ' } },
|
|
117
|
-
citationEvent({ ...PAGE_CITATION, cited_text: 'second' }),
|
|
118
|
-
]);
|
|
119
|
-
expect(chunks.filter((c) => c.delta.citation).map((c) => c.delta.citation?.citedText)).toEqual([
|
|
120
|
-
'first',
|
|
121
|
-
'second',
|
|
122
|
-
]);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
describe('a citation that cannot be checked is dropped, not guessed', () => {
|
|
126
|
-
it('drops one with no location, rather than inventing a page', async () => {
|
|
127
|
-
const chunks = await chunksOf([
|
|
128
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
129
|
-
citationEvent({ cited_text: 'somewhere', document_index: 0 }),
|
|
130
|
-
]);
|
|
131
|
-
// A citation that looks checkable and is not is worse than none:
|
|
132
|
-
// the reader follows it to a page number nobody measured.
|
|
133
|
-
expect(chunks.some((c) => c.delta.citation)).toBe(false);
|
|
134
|
-
});
|
|
135
|
-
it('drops one with no text', async () => {
|
|
136
|
-
const chunks = await chunksOf([
|
|
137
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
138
|
-
citationEvent({ document_index: 0, start_page_number: 1, end_page_number: 1 }),
|
|
139
|
-
]);
|
|
140
|
-
expect(chunks.some((c) => c.delta.citation)).toBe(false);
|
|
141
|
-
});
|
|
142
|
-
it('leaves the rest of the stream intact around a dropped one', async () => {
|
|
143
|
-
const chunks = await chunksOf([
|
|
144
|
-
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
145
|
-
citationEvent({ cited_text: 'no location' }),
|
|
146
|
-
{ type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: 'answer' } },
|
|
147
|
-
{ type: 'message_delta', delta: { stop_reason: 'end_turn' } },
|
|
148
|
-
]);
|
|
149
|
-
expect(chunks.map((c) => c.delta.content).filter(Boolean)).toEqual(['answer']);
|
|
150
|
-
expect(chunks.at(-1)?.finishReason).toBe('stop');
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe('citations are requested only when the caller asked to check the answer', () => {
|
|
154
|
-
async function documentBlockFor(citations) {
|
|
155
|
-
const seen = {};
|
|
156
|
-
const provider = providerOver([{ type: 'message_start', message: { id: 'm' } }], seen);
|
|
157
|
-
for await (const _chunk of provider.chatStream({
|
|
158
|
-
model: 'm',
|
|
159
|
-
messages: [
|
|
160
|
-
{
|
|
161
|
-
role: 'user',
|
|
162
|
-
content: 'summarize',
|
|
163
|
-
attachments: [
|
|
164
|
-
{
|
|
165
|
-
type: 'document',
|
|
166
|
-
data: PDF,
|
|
167
|
-
mediaType: 'application/pdf',
|
|
168
|
-
...(citations !== undefined ? { citations } : {}),
|
|
169
|
-
},
|
|
170
|
-
],
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
})) {
|
|
174
|
-
// drain
|
|
175
|
-
}
|
|
176
|
-
const messages = seen.body?.messages;
|
|
177
|
-
return messages[0]?.content.find((b) => b.type === 'document') ?? {};
|
|
178
|
-
}
|
|
179
|
-
it('enables them when the attachment asked for them', async () => {
|
|
180
|
-
expect(await documentBlockFor(true)).toMatchObject({ citations: { enabled: true } });
|
|
181
|
-
});
|
|
182
|
-
it('leaves them off by default — they are not free', async () => {
|
|
183
|
-
expect(await documentBlockFor()).not.toHaveProperty('citations');
|
|
184
|
-
});
|
|
185
|
-
it('leaves them off when explicitly declined', async () => {
|
|
186
|
-
expect(await documentBlockFor(false)).not.toHaveProperty('citations');
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
//# sourceMappingURL=citations.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"citations.test.js","sourceRoot":"","sources":["../../src/__tests__/citations.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD;;;;;;;;;;;;;;GAcG;AAEH,MAAM,GAAG,GAAG,sBAAsB,CAAA;AAElC,SAAS,YAAY,CACpB,MAAiB,EACjB,OAA2C,EAAE;IAE7C,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAC7D;IAAC,QAAqE,CAAC,MAAM,GAAG;QAChF,QAAQ,EAAE;YACT,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,IAA6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AEF,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAC/D,MAAM,CAAC,MAAM,gBAAgB,EAAE,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,CAAC,MAAM,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACtE,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"content-blocks.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/content-blocks.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { AnthropicProvider } from '../client.js';
|
|
3
|
-
/**
|
|
4
|
-
* A tool result carrying an image used to be `JSON.stringify`d.
|
|
5
|
-
*
|
|
6
|
-
* So a screenshot reached the model as a wall of quoted base64 — the exact
|
|
7
|
-
* thing the SDK's degrade helper exists to prevent, and pure waste besides:
|
|
8
|
-
* the model paid for every character and could read none of them. This wire
|
|
9
|
-
* carries image blocks inside a tool result natively; the mapper simply
|
|
10
|
-
* never used the shape.
|
|
11
|
-
*
|
|
12
|
-
* The degrade path still matters for what this wire genuinely cannot take.
|
|
13
|
-
* A document inside a tool result becomes the named placeholder rather than
|
|
14
|
-
* an invented image block, because the wrong block fails the whole request
|
|
15
|
-
* instead of just that part of it.
|
|
16
|
-
*/
|
|
17
|
-
const PNG = 'iVBORw0KGgo=';
|
|
18
|
-
function bodyCapturer() {
|
|
19
|
-
const seen = {};
|
|
20
|
-
const provider = new AnthropicProvider({ apiKey: 'test-key' });
|
|
21
|
-
provider.client = {
|
|
22
|
-
messages: {
|
|
23
|
-
create: vi.fn(async (body) => {
|
|
24
|
-
seen.body = body;
|
|
25
|
-
return (async function* () {
|
|
26
|
-
yield { type: 'message_start', message: { id: 'msg_1' } };
|
|
27
|
-
})();
|
|
28
|
-
}),
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
return { provider, seen };
|
|
32
|
-
}
|
|
33
|
-
async function toolResultFor(content) {
|
|
34
|
-
const { provider, seen } = bodyCapturer();
|
|
35
|
-
for await (const _chunk of provider.chatStream({
|
|
36
|
-
model: 'm',
|
|
37
|
-
messages: [
|
|
38
|
-
{ role: 'user', content: 'take a shot' },
|
|
39
|
-
{
|
|
40
|
-
role: 'assistant',
|
|
41
|
-
content: null,
|
|
42
|
-
toolCalls: [
|
|
43
|
-
{ id: 'call_1', type: 'function', function: { name: 'screenshot', arguments: '{}' } },
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
{ role: 'tool', toolCallId: 'call_1', content },
|
|
47
|
-
],
|
|
48
|
-
})) {
|
|
49
|
-
// drain
|
|
50
|
-
}
|
|
51
|
-
const messages = seen.body?.messages;
|
|
52
|
-
const block = messages
|
|
53
|
-
.flatMap((m) => (Array.isArray(m.content) ? m.content : []))
|
|
54
|
-
.find((b) => b.type === 'tool_result');
|
|
55
|
-
return block ?? {};
|
|
56
|
-
}
|
|
57
|
-
describe('an image in a tool result is sent as an image', () => {
|
|
58
|
-
it('carries the payload as a native image block', async () => {
|
|
59
|
-
const result = await toolResultFor([
|
|
60
|
-
{ type: 'text', text: 'captured' },
|
|
61
|
-
{ type: 'image', mediaType: 'image/png', data: PNG },
|
|
62
|
-
]);
|
|
63
|
-
const blocks = result.content;
|
|
64
|
-
expect(blocks.find((b) => b.type === 'image')?.source).toEqual({
|
|
65
|
-
type: 'base64',
|
|
66
|
-
media_type: 'image/png',
|
|
67
|
-
data: PNG,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
it('does not stringify the payload into text', async () => {
|
|
71
|
-
const result = await toolResultFor([{ type: 'image', mediaType: 'image/png', data: PNG }]);
|
|
72
|
-
// The bug in one assertion: the content used to be a JSON string
|
|
73
|
-
// with the base64 quoted inside it.
|
|
74
|
-
expect(typeof result.content).not.toBe('string');
|
|
75
|
-
expect(JSON.stringify(result.content)).not.toContain('\\"data\\"');
|
|
76
|
-
});
|
|
77
|
-
it('keeps the text alongside the image, in order', async () => {
|
|
78
|
-
const result = await toolResultFor([
|
|
79
|
-
{ type: 'text', text: 'captured' },
|
|
80
|
-
{ type: 'image', mediaType: 'image/png', data: PNG },
|
|
81
|
-
]);
|
|
82
|
-
const blocks = result.content;
|
|
83
|
-
expect(blocks.map((b) => b.type)).toEqual(['text', 'image']);
|
|
84
|
-
expect(blocks[0]?.text).toBe('captured');
|
|
85
|
-
});
|
|
86
|
-
it('carries several images', async () => {
|
|
87
|
-
const result = await toolResultFor([
|
|
88
|
-
{ type: 'image', mediaType: 'image/png', data: PNG },
|
|
89
|
-
{ type: 'image', mediaType: 'image/jpeg', data: 'other' },
|
|
90
|
-
]);
|
|
91
|
-
const blocks = result.content;
|
|
92
|
-
expect(blocks.filter((b) => b.type === 'image')).toHaveLength(2);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('what this wire cannot carry degrades to a named placeholder', () => {
|
|
96
|
-
it('describes a document rather than inventing an image block', async () => {
|
|
97
|
-
const result = await toolResultFor([
|
|
98
|
-
{ type: 'document', mediaType: 'application/pdf', data: 'JVBER', name: 'lease.pdf' },
|
|
99
|
-
]);
|
|
100
|
-
const blocks = result.content;
|
|
101
|
-
expect(blocks[0]?.type).toBe('text');
|
|
102
|
-
expect(blocks[0]?.text).toContain('lease.pdf');
|
|
103
|
-
expect(blocks[0]?.text).toContain('application/pdf');
|
|
104
|
-
// A block the wire rejects fails the request, not just the block.
|
|
105
|
-
expect(blocks.some((b) => b.type === 'image')).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
it('says how big it was, so the model knows what it is missing', async () => {
|
|
108
|
-
const result = await toolResultFor([
|
|
109
|
-
{ type: 'document', mediaType: 'application/pdf', data: 'A'.repeat(4096) },
|
|
110
|
-
]);
|
|
111
|
-
const blocks = result.content;
|
|
112
|
-
expect(blocks[0]?.text).toMatch(/\d+(\.\d+)? (B|KB|MB)/);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe('the plain cases are unchanged', () => {
|
|
116
|
-
it('sends a string result as a string', async () => {
|
|
117
|
-
expect(await toolResultFor('just text')).toMatchObject({ content: 'just text' });
|
|
118
|
-
});
|
|
119
|
-
it('sends text-only blocks as a text block', async () => {
|
|
120
|
-
const result = await toolResultFor([{ type: 'text', text: 'only words' }]);
|
|
121
|
-
const blocks = result.content;
|
|
122
|
-
expect(blocks).toEqual([{ type: 'text', text: 'only words' }]);
|
|
123
|
-
});
|
|
124
|
-
it('sends an empty string rather than an empty array, which is rejected', async () => {
|
|
125
|
-
expect(await toolResultFor([])).toMatchObject({ content: '' });
|
|
126
|
-
});
|
|
127
|
-
it('keeps the tool call id it answers', async () => {
|
|
128
|
-
expect(await toolResultFor('x')).toMatchObject({ tool_use_id: 'call_1' });
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
//# sourceMappingURL=content-blocks.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"content-blocks.test.js","sourceRoot":"","sources":["../../src/__tests__/content-blocks.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD;;;;;;;;;;;;;GAaG;AAEH,MAAM,GAAG,GAAG,cAAc,CAAA;AAE1B,SAAS,YAAY;IACpB,MAAM,IAAI,GAAuC,EAAE,CAAA;IACnD,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAC7D;IAAC,QAAqE,CAAC,MAAM,GAAG;QAChF,QAAQ,EAAE;YACT,M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AC,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAA;IACjF,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAA;QAC1E,MAAM,MAAM,GAAG,MAAM,CAAC,OAAoC,CAAA;QAE1D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qEAAqE,EAAE,KAAK,IAAI,EAAE;QACpF,MAAM,CAAC,MAAM,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,CAAC,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1E,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"document-input.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/document-input.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { ANTHROPIC_CAPABILITIES, AnthropicProvider } from '../client.js';
|
|
3
|
-
/**
|
|
4
|
-
* The driver declared `supportsDocuments: true` and had no document branch.
|
|
5
|
-
*
|
|
6
|
-
* Every attachment was mapped as an image block carrying the attachment's
|
|
7
|
-
* media type, so a PDF went up as `{ type: 'image', source: { media_type:
|
|
8
|
-
* 'application/pdf' } }` — a shape the API rejects. The capability set said
|
|
9
|
-
* documents worked, the SDK carried a `DocumentAttachment` type with a page
|
|
10
|
-
* of documentation about why native handling is worth having, and the one
|
|
11
|
-
* line that would have used it was never written.
|
|
12
|
-
*
|
|
13
|
-
* The native block is not a nicety: it buys page structure, the provider's
|
|
14
|
-
* own extraction, and the citations that make an answer checkable.
|
|
15
|
-
*/
|
|
16
|
-
const PDF = 'JVBERi0xLjQKJSVFT0Y=';
|
|
17
|
-
function providerCapturing(seen) {
|
|
18
|
-
const provider = new AnthropicProvider({ apiKey: 'test-key' });
|
|
19
|
-
provider.client = {
|
|
20
|
-
messages: {
|
|
21
|
-
create: vi.fn(async (body) => {
|
|
22
|
-
seen.body = body;
|
|
23
|
-
return (async function* () {
|
|
24
|
-
yield { type: 'message_start', message: { id: 'msg_1' } };
|
|
25
|
-
yield { type: 'message_delta', delta: { stop_reason: 'end_turn' } };
|
|
26
|
-
})();
|
|
27
|
-
}),
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
return provider;
|
|
31
|
-
}
|
|
32
|
-
async function bodyFor(params) {
|
|
33
|
-
const seen = {};
|
|
34
|
-
const provider = providerCapturing(seen);
|
|
35
|
-
for await (const _chunk of provider.chatStream({
|
|
36
|
-
model: 'm',
|
|
37
|
-
messages: [{ role: 'user', content: 'summarize this' }],
|
|
38
|
-
...params,
|
|
39
|
-
})) {
|
|
40
|
-
// drain
|
|
41
|
-
}
|
|
42
|
-
return seen.body ?? {};
|
|
43
|
-
}
|
|
44
|
-
/** The first user message's content blocks, as sent. */
|
|
45
|
-
function blocksOf(body) {
|
|
46
|
-
const messages = body.messages;
|
|
47
|
-
return messages[0]?.content;
|
|
48
|
-
}
|
|
49
|
-
function withAttachments(attachments) {
|
|
50
|
-
return {
|
|
51
|
-
messages: [{ role: 'user', content: 'summarize this', attachments }],
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
describe('a document attachment reaches the wire as a document', () => {
|
|
55
|
-
it('sends a document block, not an image block', async () => {
|
|
56
|
-
const body = await bodyFor(withAttachments([{ type: 'document', data: PDF, mediaType: 'application/pdf' }]));
|
|
57
|
-
const doc = blocksOf(body).find((b) => b.type === 'document');
|
|
58
|
-
expect(doc?.source).toEqual({ type: 'base64', media_type: 'application/pdf', data: PDF });
|
|
59
|
-
// The bug in one assertion: it used to be an image block.
|
|
60
|
-
expect(blocksOf(body).some((b) => b.type === 'image')).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
it('keeps the prose ahead of the document', async () => {
|
|
63
|
-
const body = await bodyFor(withAttachments([{ type: 'document', data: PDF, mediaType: 'application/pdf' }]));
|
|
64
|
-
expect(blocksOf(body)[0]).toMatchObject({ type: 'text', text: 'summarize this' });
|
|
65
|
-
});
|
|
66
|
-
it('carries the name so the model can refer to the file', async () => {
|
|
67
|
-
const body = await bodyFor(withAttachments([
|
|
68
|
-
{ type: 'document', data: PDF, mediaType: 'application/pdf', name: 'lease.pdf' },
|
|
69
|
-
]));
|
|
70
|
-
expect(blocksOf(body).find((b) => b.type === 'document')?.title).toBe('lease.pdf');
|
|
71
|
-
});
|
|
72
|
-
it('omits the title when the caller supplied no name', async () => {
|
|
73
|
-
const body = await bodyFor(withAttachments([{ type: 'document', data: PDF, mediaType: 'application/pdf' }]));
|
|
74
|
-
expect(blocksOf(body).find((b) => b.type === 'document')).not.toHaveProperty('title');
|
|
75
|
-
});
|
|
76
|
-
it('still maps an image attachment as an image', async () => {
|
|
77
|
-
const body = await bodyFor(withAttachments([{ type: 'image', data: 'AAAA', mediaType: 'image/png' }]));
|
|
78
|
-
expect(blocksOf(body).find((b) => b.type === 'image')?.source).toEqual({
|
|
79
|
-
type: 'base64',
|
|
80
|
-
media_type: 'image/png',
|
|
81
|
-
data: 'AAAA',
|
|
82
|
-
});
|
|
83
|
-
expect(blocksOf(body).some((b) => b.type === 'document')).toBe(false);
|
|
84
|
-
});
|
|
85
|
-
it('carries both kinds in one message, in the order given', async () => {
|
|
86
|
-
const body = await bodyFor(withAttachments([
|
|
87
|
-
{ type: 'document', data: PDF, mediaType: 'application/pdf' },
|
|
88
|
-
{ type: 'image', data: 'AAAA', mediaType: 'image/png' },
|
|
89
|
-
]));
|
|
90
|
-
expect(blocksOf(body).map((b) => b.type)).toEqual(['text', 'document', 'image']);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
describe('the capability claim matches the mapper', () => {
|
|
94
|
-
it('declares document support, which is now true', () => {
|
|
95
|
-
expect(ANTHROPIC_CAPABILITIES.supportsDocuments).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
//# sourceMappingURL=document-input.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"document-input.test.js","sourceRoot":"","sources":["../../src/__tests__/document-input.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAExE;;;;;;;;;;;;GAYG;AAEH,MAAM,GAAG,GAAG,sBAAsB,CAAA;AAElC,SAAS,iBAAiB,CAAC,IAAwC;IAClE,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAE7D;IAAC,QAAqE,CAAC,MAAM,GAAG;QAChF,QAAQ,EAAE;YACT,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,IAA6B,EAAE,EAAE;gBACrD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;gBAChB,OAAO,CAAC,KAAK,SAAS,CAAC;oBACtB,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,CAAA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E;QACtE,MAAM,IAAI,GAAG,MAAM,OAAO,CACzB,eAAe,CAAC;YACf,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,iBAAiB,EAAE;YAC7D,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE;SACvD,CAAC,CACF,CAAA;QAED,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;IACjF,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACxD,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5D,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"effort-levels-are-askable.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/effort-levels-are-askable.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { AnthropicProvider } from '../client.js';
|
|
3
|
-
/**
|
|
4
|
-
* A caller building an effort control has to offer the levels a model actually
|
|
5
|
-
* accepts, and only those, because effort is REFUSED rather than clamped: a
|
|
6
|
-
* level a model does not have makes the vendor reject the request, so a picker
|
|
7
|
-
* offering the wrong one produces a run that fails at the start.
|
|
8
|
-
*
|
|
9
|
-
* The driver already knew the answer and kept it to itself. Every option open
|
|
10
|
-
* to a caller without it was bad: offer all five and break some models, offer
|
|
11
|
-
* the intersection and hide the levels that are most of the reason to build the
|
|
12
|
-
* control, or copy the table — which looks fine and is worst, because the
|
|
13
|
-
* ceiling has moved twice and a copy goes stale SILENTLY, surfacing as a vendor
|
|
14
|
-
* rejection rather than a failing build.
|
|
15
|
-
*/
|
|
16
|
-
const provider = () => new AnthropicProvider({ apiKey: 'sk-ant-test', model: 'claude-sonnet-5' });
|
|
17
|
-
describe('a caller can ask which levels a model takes', () => {
|
|
18
|
-
it('answers per model rather than per provider', () => {
|
|
19
|
-
// Three eras, three different answers. If this ever collapses to one
|
|
20
|
-
// set, the method has been reduced to a constant and the question it
|
|
21
|
-
// exists to answer has stopped being asked.
|
|
22
|
-
const p = provider();
|
|
23
|
-
const modern = p.effortLevelsFor('claude-opus-5');
|
|
24
|
-
const midRange = p.effortLevelsFor('claude-sonnet-4-6');
|
|
25
|
-
const legacy = p.effortLevelsFor('claude-opus-4-5');
|
|
26
|
-
expect(modern).toContain('xhigh');
|
|
27
|
-
expect(midRange).not.toContain('xhigh');
|
|
28
|
-
expect(midRange).toContain('max');
|
|
29
|
-
expect(legacy).not.toContain('max');
|
|
30
|
-
const distinct = new Set([modern, midRange, legacy].map((s) => [...s].sort().join(',')));
|
|
31
|
-
expect(distinct.size, 'the three eras must not answer alike').toBe(3);
|
|
32
|
-
});
|
|
33
|
-
it('reports an empty set rather than nothing for a model with no levels', () => {
|
|
34
|
-
// A real answer, and different from the method being absent. Absent
|
|
35
|
-
// means the driver has no effort concept at all; empty means it does
|
|
36
|
-
// and this model has none.
|
|
37
|
-
expect(provider().effortLevelsFor('claude-haiku-4-5')).toEqual([]);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe('the answer depends on the thinking configuration you will send', () => {
|
|
41
|
-
it('narrows for the family that caps effort while thinking is off', () => {
|
|
42
|
-
// The trap this signature exists to remove. A caller reading a single
|
|
43
|
-
// `effort` array, rendering a picker, and then also sending
|
|
44
|
-
// `thinking: disabled` produces a combination the vendor rejects — on
|
|
45
|
-
// exactly one family, which is why it survives casual testing.
|
|
46
|
-
const p = provider();
|
|
47
|
-
const withThinking = p.effortLevelsFor('claude-opus-5', { type: 'adaptive' });
|
|
48
|
-
const withoutThinking = p.effortLevelsFor('claude-opus-5', { type: 'disabled' });
|
|
49
|
-
expect(withThinking).toContain('max');
|
|
50
|
-
expect(withoutThinking).not.toContain('max');
|
|
51
|
-
expect(withoutThinking).not.toContain('xhigh');
|
|
52
|
-
expect(withoutThinking).toContain('high');
|
|
53
|
-
});
|
|
54
|
-
it('does not narrow for a sibling that accepts the full set either way', () => {
|
|
55
|
-
// Measured, not inferred: the cap belongs to one family, and a version
|
|
56
|
-
// comparison of "5 and later" would have caught this model too and
|
|
57
|
-
// hidden levels the wire honours.
|
|
58
|
-
const p = provider();
|
|
59
|
-
expect(p.effortLevelsFor('claude-sonnet-5', { type: 'disabled' })).toContain('max');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('the resolver is reachable for the fuller picture', () => {
|
|
63
|
-
it('is exported from the package entry, not only its own module', async () => {
|
|
64
|
-
// The whole report was that the answer existed and could not be
|
|
65
|
-
// reached. A caller that also needs to know whether thinking can be
|
|
66
|
-
// switched off at all reads the capability directly.
|
|
67
|
-
const entry = await import('../index.js');
|
|
68
|
-
expect(typeof entry.resolveThinkingCapability).toBe('function');
|
|
69
|
-
const capability = entry.resolveThinkingCapability('claude-opus-5');
|
|
70
|
-
expect(capability.effort.length).toBeGreaterThan(0);
|
|
71
|
-
expect(typeof capability.canDisable).toBe('boolean');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
//# sourceMappingURL=effort-levels-are-askable.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"effort-levels-are-askable.test.js","sourceRoot":"","sources":["../../src/__tests__/effort-levels-are-askable.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,iBAAiB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CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;IACjE,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC5E,gEAAgE;QAChE,oEAAoE;QACpE,qDAAqD;QACrD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAA;QAEzC,MAAM,CAAC,OAAO,KAAK,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC/D,MAAM,UAAU,GAAG,KAAK,CAAC,yBAAyB,CAAC,eAAe,CAAC,CAAA;QACnE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;QACnD,MAAM,CAAC,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACrD,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider error taxonomy — Anthropic driver.
|
|
3
|
-
*
|
|
4
|
-
* The driver hands the request to the vendor SDK and lets whatever the SDK
|
|
5
|
-
* rejects with escape verbatim (`RateLimitError`, `BadRequestError`, …).
|
|
6
|
-
* Those are vendor types: a caller cannot classify them without importing
|
|
7
|
-
* `@anthropic-ai/sdk`, so nothing downstream can distinguish a throttle
|
|
8
|
-
* from a context overflow from a bad request.
|
|
9
|
-
*
|
|
10
|
-
* Transport seam: `AnthropicConfig.baseURL` — the tests point the SDK at a
|
|
11
|
-
* loopback server that answers with a scripted status/headers/body. This
|
|
12
|
-
* exercises the REAL vendor client (including its own internal retries,
|
|
13
|
-
* which this group must not disturb).
|
|
14
|
-
*/
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=error-taxonomy.test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error-taxonomy.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/error-taxonomy.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|