@namzu/anthropic 1.2.0 → 1.3.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 +280 -0
- package/dist/__tests__/anthropic.test.js +1 -0
- package/dist/__tests__/anthropic.test.js.map +1 -1
- package/dist/__tests__/block-shape-guard.test.d.ts +2 -0
- package/dist/__tests__/block-shape-guard.test.d.ts.map +1 -0
- package/dist/__tests__/block-shape-guard.test.js +218 -0
- package/dist/__tests__/block-shape-guard.test.js.map +1 -0
- package/dist/__tests__/cache-anchors.test.d.ts +2 -0
- package/dist/__tests__/cache-anchors.test.d.ts.map +1 -0
- package/dist/__tests__/cache-anchors.test.js +220 -0
- package/dist/__tests__/cache-anchors.test.js.map +1 -0
- package/dist/__tests__/citations.test.d.ts +2 -0
- package/dist/__tests__/citations.test.d.ts.map +1 -0
- package/dist/__tests__/citations.test.js +189 -0
- package/dist/__tests__/citations.test.js.map +1 -0
- package/dist/__tests__/content-blocks.test.d.ts +2 -0
- package/dist/__tests__/content-blocks.test.d.ts.map +1 -0
- package/dist/__tests__/content-blocks.test.js +131 -0
- package/dist/__tests__/content-blocks.test.js.map +1 -0
- package/dist/__tests__/document-input.test.d.ts +2 -0
- package/dist/__tests__/document-input.test.d.ts.map +1 -0
- package/dist/__tests__/document-input.test.js +98 -0
- package/dist/__tests__/document-input.test.js.map +1 -0
- package/dist/__tests__/reasoning-close.test.d.ts +2 -0
- package/dist/__tests__/reasoning-close.test.d.ts.map +1 -0
- package/dist/__tests__/reasoning-close.test.js +219 -0
- package/dist/__tests__/reasoning-close.test.js.map +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +174 -3
- package/dist/client.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/anthropic.test.ts +1 -0
- package/src/__tests__/block-shape-guard.test.ts +256 -0
- package/src/__tests__/cache-anchors.test.ts +262 -0
- package/src/__tests__/citations.test.ts +218 -0
- package/src/__tests__/content-blocks.test.ts +153 -0
- package/src/__tests__/document-input.test.ts +131 -0
- package/src/__tests__/reasoning-close.test.ts +262 -0
- package/src/client.ts +241 -7
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { AnthropicProvider } from '../client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Where the cache breakpoints land decides what the next iteration pays.
|
|
5
|
+
*
|
|
6
|
+
* Two anchors, and they do different jobs. The SYSTEM anchor sits on the
|
|
7
|
+
* last block the prompt builder tagged `'cache'`, so tools plus the static
|
|
8
|
+
* system prefix are cached and the per-run dynamic segment behind it is
|
|
9
|
+
* not. The MESSAGE anchor sits on the last block of the last non-empty
|
|
10
|
+
* message, so the whole conversation prefix is cached for an iteration
|
|
11
|
+
* that only appends.
|
|
12
|
+
*
|
|
13
|
+
* Both are invisible when wrong: a breakpoint one block too early caches
|
|
14
|
+
* less than it could, one too late caches a segment that changes every run
|
|
15
|
+
* and is never read back. Neither shows up as a failure — only as a bill.
|
|
16
|
+
*/
|
|
17
|
+
function bodyCapturer() {
|
|
18
|
+
const seen = {};
|
|
19
|
+
const provider = new AnthropicProvider({ apiKey: 'test-key' });
|
|
20
|
+
provider.client = {
|
|
21
|
+
messages: {
|
|
22
|
+
create: vi.fn(async (body) => {
|
|
23
|
+
seen.body = body;
|
|
24
|
+
return (async function* () {
|
|
25
|
+
yield { type: 'message_start', message: { id: 'msg_1' } };
|
|
26
|
+
})();
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
return { provider, seen };
|
|
31
|
+
}
|
|
32
|
+
async function bodyFor(params) {
|
|
33
|
+
const { provider, seen } = bodyCapturer();
|
|
34
|
+
for await (const _chunk of provider.chatStream({
|
|
35
|
+
model: 'm',
|
|
36
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
37
|
+
// Anchors are placed only when the caller asked for caching.
|
|
38
|
+
cacheControl: { type: 'ephemeral' },
|
|
39
|
+
...params,
|
|
40
|
+
})) {
|
|
41
|
+
// drain
|
|
42
|
+
}
|
|
43
|
+
return seen.body ?? {};
|
|
44
|
+
}
|
|
45
|
+
function systemBlocks(body) {
|
|
46
|
+
return (body.system ?? []);
|
|
47
|
+
}
|
|
48
|
+
function messageBlocks(body) {
|
|
49
|
+
const messages = body.messages;
|
|
50
|
+
const last = messages.at(-1)?.content;
|
|
51
|
+
return Array.isArray(last) ? last : [];
|
|
52
|
+
}
|
|
53
|
+
const TAGGED_SYSTEM = [
|
|
54
|
+
{ role: 'system', content: 'static rules', cacheHint: 'cache' },
|
|
55
|
+
{ role: 'system', content: 'run-specific context', cacheHint: 'ephemeral' },
|
|
56
|
+
{ role: 'user', content: 'go' },
|
|
57
|
+
];
|
|
58
|
+
describe('the system anchor sits at the end of the cacheable prefix', () => {
|
|
59
|
+
it('marks the last cache-tagged block, not the last block', async () => {
|
|
60
|
+
const body = await bodyFor({
|
|
61
|
+
messages: TAGGED_SYSTEM,
|
|
62
|
+
});
|
|
63
|
+
const blocks = systemBlocks(body);
|
|
64
|
+
expect(blocks[0]).toMatchObject({ text: 'static rules' });
|
|
65
|
+
expect(blocks[0]?.cache_control).toEqual({ type: 'ephemeral' });
|
|
66
|
+
// The dynamic segment changes every run, so caching it writes an
|
|
67
|
+
// entry nothing ever reads back.
|
|
68
|
+
expect(blocks[1]?.cache_control).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
it('marks the later of two cache-tagged blocks', async () => {
|
|
71
|
+
const body = await bodyFor({
|
|
72
|
+
messages: [
|
|
73
|
+
{ role: 'system', content: 'first', cacheHint: 'cache' },
|
|
74
|
+
{ role: 'system', content: 'second', cacheHint: 'cache' },
|
|
75
|
+
{ role: 'user', content: 'go' },
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
const blocks = systemBlocks(body);
|
|
79
|
+
expect(blocks[0]?.cache_control).toBeUndefined();
|
|
80
|
+
expect(blocks[1]?.cache_control).toEqual({ type: 'ephemeral' });
|
|
81
|
+
});
|
|
82
|
+
it('anchors nothing when no block was tagged for caching', async () => {
|
|
83
|
+
const body = await bodyFor({
|
|
84
|
+
messages: [
|
|
85
|
+
{ role: 'system', content: 'untagged' },
|
|
86
|
+
{ role: 'user', content: 'go' },
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
expect(systemBlocks(body).some((b) => b.cache_control)).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
it('keeps one block per system message, so the boundaries survive', async () => {
|
|
92
|
+
const body = await bodyFor({
|
|
93
|
+
messages: TAGGED_SYSTEM,
|
|
94
|
+
});
|
|
95
|
+
expect(systemBlocks(body).map((b) => b.text)).toEqual(['static rules', 'run-specific context']);
|
|
96
|
+
});
|
|
97
|
+
it('sends no system field at all when there are no system messages', async () => {
|
|
98
|
+
const body = await bodyFor({
|
|
99
|
+
messages: [{ role: 'user', content: 'go' }],
|
|
100
|
+
});
|
|
101
|
+
expect(body.system).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('the message anchor sits at the end of the conversation prefix', () => {
|
|
105
|
+
it('promotes a trailing string message to a block so it can carry one', async () => {
|
|
106
|
+
const body = await bodyFor({
|
|
107
|
+
messages: [
|
|
108
|
+
{ role: 'user', content: 'first' },
|
|
109
|
+
{ role: 'assistant', content: 'second' },
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
expect(messageBlocks(body).at(-1)).toMatchObject({
|
|
113
|
+
type: 'text',
|
|
114
|
+
text: 'second',
|
|
115
|
+
cache_control: { type: 'ephemeral' },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
it('marks the last block of an already-blocked message', async () => {
|
|
119
|
+
const body = await bodyFor({
|
|
120
|
+
messages: [
|
|
121
|
+
{
|
|
122
|
+
role: 'user',
|
|
123
|
+
content: 'look',
|
|
124
|
+
attachments: [{ type: 'image', data: 'AAAA', mediaType: 'image/png' }],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
const blocks = messageBlocks(body);
|
|
129
|
+
expect(blocks.at(-1)?.type).toBe('image');
|
|
130
|
+
expect(blocks.at(-1)?.cache_control).toEqual({ type: 'ephemeral' });
|
|
131
|
+
expect(blocks[0]?.cache_control).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
it('skips an empty trailing message and anchors the one before it', async () => {
|
|
134
|
+
const body = await bodyFor({
|
|
135
|
+
messages: [
|
|
136
|
+
{ role: 'user', content: 'real content' },
|
|
137
|
+
{ role: 'assistant', content: '' },
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
const messages = body.messages;
|
|
141
|
+
const anchored = messages.filter((m) => Array.isArray(m.content) && m.content.some((b) => b.cache_control));
|
|
142
|
+
// An empty message has no block to hold the anchor, so anchoring it
|
|
143
|
+
// would drop the breakpoint entirely.
|
|
144
|
+
expect(anchored).toHaveLength(1);
|
|
145
|
+
expect((anchored[0]?.content)[0]?.text).toBe('real content');
|
|
146
|
+
});
|
|
147
|
+
it('places exactly one message anchor', async () => {
|
|
148
|
+
const body = await bodyFor({
|
|
149
|
+
messages: [
|
|
150
|
+
{ role: 'user', content: 'a' },
|
|
151
|
+
{ role: 'assistant', content: 'b' },
|
|
152
|
+
{ role: 'user', content: 'c' },
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
const messages = body.messages;
|
|
156
|
+
const anchors = messages
|
|
157
|
+
.flatMap((m) => (Array.isArray(m.content) ? m.content : []))
|
|
158
|
+
.filter((b) => b.cache_control);
|
|
159
|
+
expect(anchors).toHaveLength(1);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe('cache usage is read back off the wire', () => {
|
|
163
|
+
it('reports reads and writes separately, not folded into prompt tokens', async () => {
|
|
164
|
+
const { provider } = bodyCapturer();
|
|
165
|
+
provider.client = {
|
|
166
|
+
messages: {
|
|
167
|
+
create: vi.fn(async () => (async function* () {
|
|
168
|
+
yield {
|
|
169
|
+
type: 'message_start',
|
|
170
|
+
message: {
|
|
171
|
+
id: 'msg_1',
|
|
172
|
+
usage: {
|
|
173
|
+
input_tokens: 10,
|
|
174
|
+
output_tokens: 2,
|
|
175
|
+
cache_read_input_tokens: 900,
|
|
176
|
+
cache_creation_input_tokens: 40,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
})()),
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
const chunks = [];
|
|
184
|
+
for await (const chunk of provider.chatStream({
|
|
185
|
+
model: 'm',
|
|
186
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
187
|
+
})) {
|
|
188
|
+
chunks.push(chunk);
|
|
189
|
+
}
|
|
190
|
+
// The two are priced differently, so folding either into
|
|
191
|
+
// promptTokens would misreport what the run actually cost.
|
|
192
|
+
expect(chunks[0]?.usage).toMatchObject({
|
|
193
|
+
promptTokens: 10,
|
|
194
|
+
cachedTokens: 900,
|
|
195
|
+
cacheWriteTokens: 40,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
it('reads absent cache counters as zero rather than undefined', async () => {
|
|
199
|
+
const { provider } = bodyCapturer();
|
|
200
|
+
provider.client = {
|
|
201
|
+
messages: {
|
|
202
|
+
create: vi.fn(async () => (async function* () {
|
|
203
|
+
yield {
|
|
204
|
+
type: 'message_start',
|
|
205
|
+
message: { id: 'm', usage: { input_tokens: 5, output_tokens: 1 } },
|
|
206
|
+
};
|
|
207
|
+
})()),
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
const chunks = [];
|
|
211
|
+
for await (const chunk of provider.chatStream({
|
|
212
|
+
model: 'm',
|
|
213
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
214
|
+
})) {
|
|
215
|
+
chunks.push(chunk);
|
|
216
|
+
}
|
|
217
|
+
expect(chunks[0]?.usage).toMatchObject({ cachedTokens: 0, cacheWriteTokens: 0 });
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
//# sourceMappingURL=cache-anchors.test.js.map
|
|
@@ -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AE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,EAAE;qBAClE,CAAA;gBACF,CAAC,CAAC,EAAE,CACJ;aACD;SACD,CAAA;QAED,MAAM,MAAM,GAAG,EAAE,CAAA;QACjB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,CAAC,UAAU,CAAC;YAC7C,KAAK,EAAE,GAAG;YACV,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;SACnB,CAAC,EAAE,CAAC;YAC5B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,CAAC,CAAA;IACjF,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citations.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/citations.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,189 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citations.test.js","sourceRoot":"","sources":["../../src/__tests__/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,EAAE,CAAC;YACvC,QAAQ;QACT,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,QAAyD,CAAA;QACrF,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,EAAE,CAAA;IACrE,CAAC;IAED,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAChE,MAAM,CAAC,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IACrF,CAAC,CAAC,CAAA;IAEF,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-blocks.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/content-blocks.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,131 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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