@namzu/anthropic 1.1.2 → 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 +289 -0
- package/README.md +10 -0
- package/dist/__tests__/anthropic.test.js +144 -6
- 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 +203 -11
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/anthropic.test.ts +175 -12
- 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 +278 -14
- package/src/types.ts +6 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { ChatCompletionParams } from '@namzu/sdk'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { ANTHROPIC_CAPABILITIES, AnthropicProvider } from '../client.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The driver declared `supportsDocuments: true` and had no document branch.
|
|
8
|
+
*
|
|
9
|
+
* Every attachment was mapped as an image block carrying the attachment's
|
|
10
|
+
* media type, so a PDF went up as `{ type: 'image', source: { media_type:
|
|
11
|
+
* 'application/pdf' } }` — a shape the API rejects. The capability set said
|
|
12
|
+
* documents worked, the SDK carried a `DocumentAttachment` type with a page
|
|
13
|
+
* of documentation about why native handling is worth having, and the one
|
|
14
|
+
* line that would have used it was never written.
|
|
15
|
+
*
|
|
16
|
+
* The native block is not a nicety: it buys page structure, the provider's
|
|
17
|
+
* own extraction, and the citations that make an answer checkable.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const PDF = 'JVBERi0xLjQKJSVFT0Y='
|
|
21
|
+
|
|
22
|
+
function providerCapturing(seen: { body?: Record<string, unknown> }): AnthropicProvider {
|
|
23
|
+
const provider = new AnthropicProvider({ apiKey: 'test-key' })
|
|
24
|
+
// The vendor client is the only seam; replace its one method.
|
|
25
|
+
;(provider as unknown as { client: { messages: { create: unknown } } }).client = {
|
|
26
|
+
messages: {
|
|
27
|
+
create: vi.fn(async (body: Record<string, unknown>) => {
|
|
28
|
+
seen.body = body
|
|
29
|
+
return (async function* () {
|
|
30
|
+
yield { type: 'message_start', message: { id: 'msg_1' } }
|
|
31
|
+
yield { type: 'message_delta', delta: { stop_reason: 'end_turn' } }
|
|
32
|
+
})()
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
return provider
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function bodyFor(params: Partial<ChatCompletionParams>): Promise<Record<string, unknown>> {
|
|
40
|
+
const seen: { body?: Record<string, unknown> } = {}
|
|
41
|
+
const provider = providerCapturing(seen)
|
|
42
|
+
for await (const _chunk of provider.chatStream({
|
|
43
|
+
model: 'm',
|
|
44
|
+
messages: [{ role: 'user', content: 'summarize this' }],
|
|
45
|
+
...params,
|
|
46
|
+
} as ChatCompletionParams)) {
|
|
47
|
+
// drain
|
|
48
|
+
}
|
|
49
|
+
return seen.body ?? {}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The first user message's content blocks, as sent. */
|
|
53
|
+
function blocksOf(body: Record<string, unknown>): Record<string, unknown>[] {
|
|
54
|
+
const messages = body.messages as Array<{ content: unknown }>
|
|
55
|
+
return messages[0]?.content as Record<string, unknown>[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function withAttachments(attachments: unknown[]): Partial<ChatCompletionParams> {
|
|
59
|
+
return {
|
|
60
|
+
messages: [{ role: 'user', content: 'summarize this', attachments }],
|
|
61
|
+
} as unknown as Partial<ChatCompletionParams>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('a document attachment reaches the wire as a document', () => {
|
|
65
|
+
it('sends a document block, not an image block', async () => {
|
|
66
|
+
const body = await bodyFor(
|
|
67
|
+
withAttachments([{ type: 'document', data: PDF, mediaType: 'application/pdf' }]),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
const doc = blocksOf(body).find((b) => b.type === 'document')
|
|
71
|
+
expect(doc?.source).toEqual({ type: 'base64', media_type: 'application/pdf', data: PDF })
|
|
72
|
+
// The bug in one assertion: it used to be an image block.
|
|
73
|
+
expect(blocksOf(body).some((b) => b.type === 'image')).toBe(false)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('keeps the prose ahead of the document', async () => {
|
|
77
|
+
const body = await bodyFor(
|
|
78
|
+
withAttachments([{ type: 'document', data: PDF, mediaType: 'application/pdf' }]),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
expect(blocksOf(body)[0]).toMatchObject({ type: 'text', text: 'summarize this' })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('carries the name so the model can refer to the file', async () => {
|
|
85
|
+
const body = await bodyFor(
|
|
86
|
+
withAttachments([
|
|
87
|
+
{ type: 'document', data: PDF, mediaType: 'application/pdf', name: 'lease.pdf' },
|
|
88
|
+
]),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
expect(blocksOf(body).find((b) => b.type === 'document')?.title).toBe('lease.pdf')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('omits the title when the caller supplied no name', async () => {
|
|
95
|
+
const body = await bodyFor(
|
|
96
|
+
withAttachments([{ type: 'document', data: PDF, mediaType: 'application/pdf' }]),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
expect(blocksOf(body).find((b) => b.type === 'document')).not.toHaveProperty('title')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('still maps an image attachment as an image', async () => {
|
|
103
|
+
const body = await bodyFor(
|
|
104
|
+
withAttachments([{ type: 'image', data: 'AAAA', mediaType: 'image/png' }]),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
expect(blocksOf(body).find((b) => b.type === 'image')?.source).toEqual({
|
|
108
|
+
type: 'base64',
|
|
109
|
+
media_type: 'image/png',
|
|
110
|
+
data: 'AAAA',
|
|
111
|
+
})
|
|
112
|
+
expect(blocksOf(body).some((b) => b.type === 'document')).toBe(false)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('carries both kinds in one message, in the order given', async () => {
|
|
116
|
+
const body = await bodyFor(
|
|
117
|
+
withAttachments([
|
|
118
|
+
{ type: 'document', data: PDF, mediaType: 'application/pdf' },
|
|
119
|
+
{ type: 'image', data: 'AAAA', mediaType: 'image/png' },
|
|
120
|
+
]),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
expect(blocksOf(body).map((b) => b.type)).toEqual(['text', 'document', 'image'])
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('the capability claim matches the mapper', () => {
|
|
128
|
+
it('declares document support, which is now true', () => {
|
|
129
|
+
expect(ANTHROPIC_CAPABILITIES.supportsDocuments).toBe(true)
|
|
130
|
+
})
|
|
131
|
+
})
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import type { ChatCompletionParams, StreamChunk } from '@namzu/sdk'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { AnthropicProvider } from '../client.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Extended thinking was fully specified in the SDK and entirely absent
|
|
8
|
+
* from this driver.
|
|
9
|
+
*
|
|
10
|
+
* The stream chunk carried a `reasoning` channel whose own comment named
|
|
11
|
+
* the bug — "`thinking_delta` and `signature_delta` fell through the
|
|
12
|
+
* driver's `default: // ignore`" — the run's aggregator bucketed fragments
|
|
13
|
+
* by index and closed them on `done`, and `ReasoningBlock` recorded the
|
|
14
|
+
* signature with a note that replaying it unchanged is mandatory. The
|
|
15
|
+
* driver requested no thinking, parsed none, and replayed none.
|
|
16
|
+
*
|
|
17
|
+
* The close matters as much as the content. A block is only complete once
|
|
18
|
+
* its signature has arrived, and the signature arrives last: without a
|
|
19
|
+
* `done` the aggregator cannot tell a finished block from one still
|
|
20
|
+
* streaming, and a block replayed without its signature invalidates the
|
|
21
|
+
* whole conversation upstream — not just that block.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function providerOver(events: unknown[], seen: { body?: Record<string, unknown> } = {}) {
|
|
25
|
+
const provider = new AnthropicProvider({ apiKey: 'test-key' })
|
|
26
|
+
;(provider as unknown as { client: { messages: { create: unknown } } }).client = {
|
|
27
|
+
messages: {
|
|
28
|
+
create: vi.fn(async (body: Record<string, unknown>) => {
|
|
29
|
+
seen.body = body
|
|
30
|
+
return (async function* () {
|
|
31
|
+
for (const event of events) yield event
|
|
32
|
+
})()
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
return provider
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function chunksOf(events: unknown[]): Promise<StreamChunk[]> {
|
|
40
|
+
const out: StreamChunk[] = []
|
|
41
|
+
for await (const chunk of providerOver(events).chatStream({
|
|
42
|
+
model: 'm',
|
|
43
|
+
messages: [{ role: 'user', content: 'q' }],
|
|
44
|
+
} as ChatCompletionParams)) {
|
|
45
|
+
out.push(chunk)
|
|
46
|
+
}
|
|
47
|
+
return out
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const THINKING_STREAM = [
|
|
51
|
+
{ type: 'message_start', message: { id: 'msg_1' } },
|
|
52
|
+
{ type: 'content_block_start', index: 0, content_block: { type: 'thinking' } },
|
|
53
|
+
{
|
|
54
|
+
type: 'content_block_delta',
|
|
55
|
+
index: 0,
|
|
56
|
+
delta: { type: 'thinking_delta', thinking: 'step one' },
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'content_block_delta',
|
|
60
|
+
index: 0,
|
|
61
|
+
delta: { type: 'thinking_delta', thinking: ' then two' },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'content_block_delta',
|
|
65
|
+
index: 0,
|
|
66
|
+
delta: { type: 'signature_delta', signature: 'sig-abc' },
|
|
67
|
+
},
|
|
68
|
+
{ type: 'content_block_stop', index: 0 },
|
|
69
|
+
{ type: 'content_block_start', index: 1, content_block: { type: 'text' } },
|
|
70
|
+
{ type: 'content_block_delta', index: 1, delta: { type: 'text_delta', text: 'the answer' } },
|
|
71
|
+
{ type: 'message_delta', delta: { stop_reason: 'end_turn' } },
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
function reasoningOf(chunks: StreamChunk[]) {
|
|
75
|
+
return chunks.map((c) => c.delta.reasoning).filter((r): r is NonNullable<typeof r> => Boolean(r))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe('a reasoning block streams, then closes', () => {
|
|
79
|
+
it('opens the block with its kind', async () => {
|
|
80
|
+
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
81
|
+
|
|
82
|
+
expect(reasoning[0]).toMatchObject({ index: 0, type: 'thinking' })
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('carries each fragment through in order', async () => {
|
|
86
|
+
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
87
|
+
|
|
88
|
+
expect(reasoning.map((r) => r.text).filter(Boolean)).toEqual(['step one', ' then two'])
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('carries the signature, which arrives once at the end', async () => {
|
|
92
|
+
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
93
|
+
|
|
94
|
+
expect(reasoning.find((r) => r.signature)?.signature).toBe('sig-abc')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('closes the block so the aggregator knows the signature has landed', async () => {
|
|
98
|
+
const reasoning = reasoningOf(await chunksOf(THINKING_STREAM))
|
|
99
|
+
|
|
100
|
+
expect(reasoning.at(-1)).toEqual({ index: 0, done: true })
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('closes it before the text block starts, not after', async () => {
|
|
104
|
+
const chunks = await chunksOf(THINKING_STREAM)
|
|
105
|
+
const closeAt = chunks.findIndex((c) => c.delta.reasoning?.done)
|
|
106
|
+
const textAt = chunks.findIndex((c) => c.delta.content === 'the answer')
|
|
107
|
+
|
|
108
|
+
expect(closeAt).toBeGreaterThan(-1)
|
|
109
|
+
expect(closeAt).toBeLessThan(textAt)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('does not leak reasoning into the visible text', async () => {
|
|
113
|
+
const chunks = await chunksOf(THINKING_STREAM)
|
|
114
|
+
|
|
115
|
+
expect(chunks.map((c) => c.delta.content).filter(Boolean)).toEqual(['the answer'])
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('groups two blocks by their own index', async () => {
|
|
119
|
+
const reasoning = reasoningOf(
|
|
120
|
+
await chunksOf([
|
|
121
|
+
{ type: 'message_start', message: { id: 'm' } },
|
|
122
|
+
{ type: 'content_block_start', index: 0, content_block: { type: 'thinking' } },
|
|
123
|
+
{ type: 'content_block_delta', index: 0, delta: { type: 'thinking_delta', thinking: 'a' } },
|
|
124
|
+
{ type: 'content_block_stop', index: 0 },
|
|
125
|
+
{ type: 'content_block_start', index: 1, content_block: { type: 'thinking' } },
|
|
126
|
+
{ type: 'content_block_delta', index: 1, delta: { type: 'thinking_delta', thinking: 'b' } },
|
|
127
|
+
{ type: 'content_block_stop', index: 1 },
|
|
128
|
+
]),
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
expect(reasoning.filter((r) => r.done).map((r) => r.index)).toEqual([0, 1])
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('carries a redacted block as an opaque payload rather than text', async () => {
|
|
135
|
+
const reasoning = reasoningOf(
|
|
136
|
+
await chunksOf([
|
|
137
|
+
{ type: 'message_start', message: { id: 'm' } },
|
|
138
|
+
{
|
|
139
|
+
type: 'content_block_start',
|
|
140
|
+
index: 0,
|
|
141
|
+
content_block: { type: 'redacted_thinking', data: 'opaque-bytes' },
|
|
142
|
+
},
|
|
143
|
+
{ type: 'content_block_stop', index: 0 },
|
|
144
|
+
]),
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
expect(reasoning[0]).toMatchObject({ type: 'redacted_thinking', encrypted: 'opaque-bytes' })
|
|
148
|
+
expect(reasoning[0]?.text).toBeUndefined()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('still closes a tool call, which shares the same stop event', async () => {
|
|
152
|
+
const chunks = await chunksOf([
|
|
153
|
+
{ type: 'message_start', message: { id: 'm' } },
|
|
154
|
+
{
|
|
155
|
+
type: 'content_block_start',
|
|
156
|
+
index: 0,
|
|
157
|
+
content_block: { type: 'tool_use', id: 'call_1', name: 'read' },
|
|
158
|
+
},
|
|
159
|
+
{ type: 'content_block_stop', index: 0 },
|
|
160
|
+
])
|
|
161
|
+
|
|
162
|
+
expect(chunks.some((c) => c.delta.toolCallEnd?.id === 'call_1')).toBe(true)
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
describe('thinking can be asked for', () => {
|
|
167
|
+
async function bodyFor(thinking: unknown): Promise<Record<string, unknown>> {
|
|
168
|
+
const seen: { body?: Record<string, unknown> } = {}
|
|
169
|
+
const provider = providerOver([{ type: 'message_start', message: { id: 'm' } }], seen)
|
|
170
|
+
for await (const _chunk of provider.chatStream({
|
|
171
|
+
model: 'm',
|
|
172
|
+
messages: [{ role: 'user', content: 'q' }],
|
|
173
|
+
...(thinking !== undefined ? { thinking } : {}),
|
|
174
|
+
} as ChatCompletionParams)) {
|
|
175
|
+
// drain
|
|
176
|
+
}
|
|
177
|
+
return seen.body ?? {}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
it('sends the budget the caller set', async () => {
|
|
181
|
+
expect(await bodyFor({ type: 'enabled', budgetTokens: 4096 })).toMatchObject({
|
|
182
|
+
thinking: { type: 'enabled', budget_tokens: 4096 },
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('enables it without a budget when none was named', async () => {
|
|
187
|
+
expect((await bodyFor({ type: 'enabled' })).thinking).toEqual({ type: 'enabled' })
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('can turn it off on a model where it is on by default', async () => {
|
|
191
|
+
expect((await bodyFor({ type: 'disabled' })).thinking).toEqual({ type: 'disabled' })
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('says nothing at all when the caller did not ask', async () => {
|
|
195
|
+
expect(await bodyFor(undefined)).not.toHaveProperty('thinking')
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
describe('a reasoned turn is replayed verbatim on the next request', () => {
|
|
200
|
+
async function messagesFor(assistant: Record<string, unknown>) {
|
|
201
|
+
const seen: { body?: Record<string, unknown> } = {}
|
|
202
|
+
const provider = providerOver([{ type: 'message_start', message: { id: 'm' } }], seen)
|
|
203
|
+
for await (const _chunk of provider.chatStream({
|
|
204
|
+
model: 'm',
|
|
205
|
+
messages: [{ role: 'user', content: 'q' }, assistant, { role: 'user', content: 'and then?' }],
|
|
206
|
+
} as unknown as ChatCompletionParams)) {
|
|
207
|
+
// drain
|
|
208
|
+
}
|
|
209
|
+
return seen.body?.messages as Array<{ role: string; content: unknown }>
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
it('replays the block with its signature intact', async () => {
|
|
213
|
+
const messages = await messagesFor({
|
|
214
|
+
role: 'assistant',
|
|
215
|
+
content: 'because of that',
|
|
216
|
+
reasoning: [{ type: 'thinking', text: 'step one', signature: 'sig-abc' }],
|
|
217
|
+
})
|
|
218
|
+
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
219
|
+
|
|
220
|
+
expect(blocks[0]).toEqual({ type: 'thinking', thinking: 'step one', signature: 'sig-abc' })
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('puts the reasoning first, as the wire requires', async () => {
|
|
224
|
+
const messages = await messagesFor({
|
|
225
|
+
role: 'assistant',
|
|
226
|
+
content: 'because of that',
|
|
227
|
+
reasoning: [{ type: 'thinking', text: 'step one', signature: 'sig' }],
|
|
228
|
+
})
|
|
229
|
+
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
230
|
+
|
|
231
|
+
expect(blocks.map((b) => b.type)).toEqual(['thinking', 'text'])
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('replays it ahead of a tool call too', async () => {
|
|
235
|
+
const messages = await messagesFor({
|
|
236
|
+
role: 'assistant',
|
|
237
|
+
content: null,
|
|
238
|
+
reasoning: [{ type: 'thinking', text: 'i should read it', signature: 'sig' }],
|
|
239
|
+
toolCalls: [{ id: 'call_1', type: 'function', function: { name: 'read', arguments: '{}' } }],
|
|
240
|
+
})
|
|
241
|
+
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
242
|
+
|
|
243
|
+
expect(blocks.map((b) => b.type)).toEqual(['thinking', 'tool_use'])
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('replays a redacted block as its opaque payload', async () => {
|
|
247
|
+
const messages = await messagesFor({
|
|
248
|
+
role: 'assistant',
|
|
249
|
+
content: 'answer',
|
|
250
|
+
reasoning: [{ type: 'redacted_thinking', encrypted: 'opaque-bytes' }],
|
|
251
|
+
})
|
|
252
|
+
const blocks = messages[1]?.content as Record<string, unknown>[]
|
|
253
|
+
|
|
254
|
+
expect(blocks[0]).toEqual({ type: 'redacted_thinking', data: 'opaque-bytes' })
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('leaves an assistant turn that did not reason as a plain string', async () => {
|
|
258
|
+
const messages = await messagesFor({ role: 'assistant', content: 'just an answer' })
|
|
259
|
+
|
|
260
|
+
expect(messages[1]?.content).toBe('just an answer')
|
|
261
|
+
})
|
|
262
|
+
})
|