@effect-uai/anthropic 0.2.0 → 0.4.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/dist/Anthropic.d.mts +94 -0
- package/dist/Anthropic.d.mts.map +1 -0
- package/dist/Anthropic.mjs +226 -0
- package/dist/Anthropic.mjs.map +1 -0
- package/dist/codec.d.mts +142 -0
- package/dist/codec.d.mts.map +1 -0
- package/dist/codec.mjs +354 -0
- package/dist/codec.mjs.map +1 -0
- package/dist/index.d.mts +5 -438
- package/dist/index.mjs +5 -649
- package/dist/models.d.mts +25 -0
- package/dist/models.d.mts.map +1 -0
- package/dist/models.mjs +1 -0
- package/dist/streamEvents.d.mts +196 -0
- package/dist/streamEvents.d.mts.map +1 -0
- package/dist/streamEvents.mjs +152 -0
- package/dist/streamEvents.mjs.map +1 -0
- package/package.json +16 -12
- package/src/Anthropic.ts +49 -54
- package/src/codec.ts +104 -109
- package/src/index.ts +2 -2
- package/src/streamEvents.ts +27 -25
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/codec.mjs
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
|
+
import { Array, Encoding, Match, Option, Order, Result, Schema, pipe } from "effect";
|
|
3
|
+
import { JsonParseError } from "@effect-uai/core/JSONL";
|
|
4
|
+
//#region src/codec.ts
|
|
5
|
+
var codec_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
WireContentBlock: () => WireContentBlock,
|
|
7
|
+
accumulatorToTurn: () => accumulatorToTurn,
|
|
8
|
+
appendInputJsonDelta: () => appendInputJsonDelta,
|
|
9
|
+
appendSignatureDelta: () => appendSignatureDelta,
|
|
10
|
+
appendTextDelta: () => appendTextDelta,
|
|
11
|
+
appendThinkingDelta: () => appendThinkingDelta,
|
|
12
|
+
buildRequestBody: () => buildRequestBody,
|
|
13
|
+
emptyAccumulator: () => emptyAccumulator,
|
|
14
|
+
mergeUsage: () => mergeUsage,
|
|
15
|
+
setStopReason: () => setStopReason,
|
|
16
|
+
startBlock: () => startBlock
|
|
17
|
+
});
|
|
18
|
+
const WireTextBlock = Schema.Struct({
|
|
19
|
+
type: Schema.Literal("text"),
|
|
20
|
+
text: Schema.String
|
|
21
|
+
});
|
|
22
|
+
const WireToolUseBlock = Schema.Struct({
|
|
23
|
+
type: Schema.Literal("tool_use"),
|
|
24
|
+
id: Schema.String,
|
|
25
|
+
name: Schema.String,
|
|
26
|
+
input: Schema.Unknown
|
|
27
|
+
});
|
|
28
|
+
const WireThinkingBlock = Schema.Struct({
|
|
29
|
+
type: Schema.Literal("thinking"),
|
|
30
|
+
thinking: Schema.String,
|
|
31
|
+
signature: Schema.optional(Schema.String)
|
|
32
|
+
});
|
|
33
|
+
const WireRedactedThinkingBlock = Schema.Struct({
|
|
34
|
+
type: Schema.Literal("redacted_thinking"),
|
|
35
|
+
data: Schema.String
|
|
36
|
+
});
|
|
37
|
+
const WireContentBlock = Schema.Union([
|
|
38
|
+
WireTextBlock,
|
|
39
|
+
WireToolUseBlock,
|
|
40
|
+
WireThinkingBlock,
|
|
41
|
+
WireRedactedThinkingBlock
|
|
42
|
+
]);
|
|
43
|
+
Schema.Struct({
|
|
44
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
45
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
46
|
+
cache_creation_input_tokens: Schema.optional(Schema.NullOr(Schema.Number)),
|
|
47
|
+
cache_read_input_tokens: Schema.optional(Schema.NullOr(Schema.Number))
|
|
48
|
+
});
|
|
49
|
+
const blockText = Match.type().pipe(Match.discriminatorsExhaustive("type")({
|
|
50
|
+
input_text: (b) => b.text,
|
|
51
|
+
input_image: () => "",
|
|
52
|
+
output_text: (b) => b.text,
|
|
53
|
+
refusal: (b) => b.text
|
|
54
|
+
}));
|
|
55
|
+
const messageText = (message) => message.content.map(blockText).join("");
|
|
56
|
+
const imageSourceToWire = Match.type().pipe(Match.tag("url", (s) => ({
|
|
57
|
+
type: "url",
|
|
58
|
+
url: s.url
|
|
59
|
+
})), Match.tag("base64", (s) => ({
|
|
60
|
+
type: "base64",
|
|
61
|
+
media_type: s.mimeType,
|
|
62
|
+
data: s.base64
|
|
63
|
+
})), Match.tag("bytes", (s) => ({
|
|
64
|
+
type: "base64",
|
|
65
|
+
media_type: s.mimeType,
|
|
66
|
+
data: Encoding.encodeBase64(s.bytes)
|
|
67
|
+
})), Match.exhaustive);
|
|
68
|
+
const userContentBlock = (block) => Match.value(block).pipe(Match.discriminatorsExhaustive("type")({
|
|
69
|
+
input_text: (b) => b.text.length === 0 ? Result.failVoid : Result.succeed({
|
|
70
|
+
type: "text",
|
|
71
|
+
text: b.text
|
|
72
|
+
}),
|
|
73
|
+
input_image: (b) => Result.succeed({
|
|
74
|
+
type: "image",
|
|
75
|
+
source: imageSourceToWire(b.source)
|
|
76
|
+
}),
|
|
77
|
+
output_text: () => Result.failVoid,
|
|
78
|
+
refusal: () => Result.failVoid
|
|
79
|
+
}));
|
|
80
|
+
const parseJson = (s) => Result.try({
|
|
81
|
+
try: () => JSON.parse(s),
|
|
82
|
+
catch: (cause) => new JsonParseError({
|
|
83
|
+
line: s,
|
|
84
|
+
cause
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
const roleBucket = (item) => Match.value(item).pipe(Match.discriminatorsExhaustive("type")({
|
|
88
|
+
message: (m) => m.role,
|
|
89
|
+
function_call: () => "assistant",
|
|
90
|
+
function_call_output: () => "user",
|
|
91
|
+
reasoning: () => "assistant"
|
|
92
|
+
}));
|
|
93
|
+
const itemToUserBlocks = (item) => Match.value(item).pipe(Match.discriminatorsExhaustive("type")({
|
|
94
|
+
message: (m) => m.role === "user" ? pipe(m.content, Array.filterMap(userContentBlock)) : [],
|
|
95
|
+
function_call: () => [],
|
|
96
|
+
function_call_output: (o) => [{
|
|
97
|
+
type: "tool_result",
|
|
98
|
+
tool_use_id: o.call_id,
|
|
99
|
+
content: o.output
|
|
100
|
+
}],
|
|
101
|
+
reasoning: () => []
|
|
102
|
+
}));
|
|
103
|
+
const itemToAssistantBlocks = (item) => Match.value(item).pipe(Match.discriminatorsExhaustive("type")({
|
|
104
|
+
message: (m) => {
|
|
105
|
+
const text = messageText(m);
|
|
106
|
+
return Result.succeed(m.role === "assistant" && text.length > 0 ? [{
|
|
107
|
+
type: "text",
|
|
108
|
+
text
|
|
109
|
+
}] : []);
|
|
110
|
+
},
|
|
111
|
+
function_call: (f) => pipe(parseJson(f.arguments), Result.map((input) => [{
|
|
112
|
+
type: "tool_use",
|
|
113
|
+
id: f.call_id,
|
|
114
|
+
name: f.name,
|
|
115
|
+
input
|
|
116
|
+
}])),
|
|
117
|
+
function_call_output: () => Result.succeed([]),
|
|
118
|
+
reasoning: (r) => {
|
|
119
|
+
const blocks = r.summary !== void 0 ? [{
|
|
120
|
+
type: "thinking",
|
|
121
|
+
thinking: r.summary,
|
|
122
|
+
...r.signature !== void 0 && { signature: r.signature }
|
|
123
|
+
}] : r.signature !== void 0 ? [{
|
|
124
|
+
type: "redacted_thinking",
|
|
125
|
+
data: r.signature
|
|
126
|
+
}] : [];
|
|
127
|
+
return Result.succeed(blocks);
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
const flushAcc = (acc) => Option.match(acc.currentRole, {
|
|
131
|
+
onNone: () => acc.messages,
|
|
132
|
+
onSome: (role) => role === "user" && acc.userBuf.length > 0 ? [...acc.messages, {
|
|
133
|
+
role: "user",
|
|
134
|
+
content: acc.userBuf
|
|
135
|
+
}] : role === "assistant" && acc.assistantBuf.length > 0 ? [...acc.messages, {
|
|
136
|
+
role: "assistant",
|
|
137
|
+
content: acc.assistantBuf
|
|
138
|
+
}] : acc.messages
|
|
139
|
+
});
|
|
140
|
+
const appendUser = (acc, blocks) => blocks.length === 0 ? acc : Option.isSome(acc.currentRole) && acc.currentRole.value === "user" ? {
|
|
141
|
+
...acc,
|
|
142
|
+
userBuf: [...acc.userBuf, ...blocks]
|
|
143
|
+
} : {
|
|
144
|
+
messages: flushAcc(acc),
|
|
145
|
+
currentRole: Option.some("user"),
|
|
146
|
+
userBuf: blocks,
|
|
147
|
+
assistantBuf: []
|
|
148
|
+
};
|
|
149
|
+
const appendAssistant = (acc, blocks) => blocks.length === 0 ? acc : Option.isSome(acc.currentRole) && acc.currentRole.value === "assistant" ? {
|
|
150
|
+
...acc,
|
|
151
|
+
assistantBuf: [...acc.assistantBuf, ...blocks]
|
|
152
|
+
} : {
|
|
153
|
+
messages: flushAcc(acc),
|
|
154
|
+
currentRole: Option.some("assistant"),
|
|
155
|
+
userBuf: [],
|
|
156
|
+
assistantBuf: blocks
|
|
157
|
+
};
|
|
158
|
+
const groupStep = (acc, item) => {
|
|
159
|
+
const bucket = roleBucket(item);
|
|
160
|
+
if (bucket === "system") return Result.succeed(acc);
|
|
161
|
+
if (bucket === "user") return Result.succeed(appendUser(acc, itemToUserBlocks(item)));
|
|
162
|
+
return pipe(itemToAssistantBlocks(item), Result.map((blocks) => appendAssistant(acc, blocks)));
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Group consecutive same-role items into Anthropic-shaped messages.
|
|
166
|
+
* Anthropic requires strict user/assistant alternation; consecutive items
|
|
167
|
+
* from the same role are folded into one message's `content`. Fails if any
|
|
168
|
+
* `function_call.arguments` is not valid JSON, since Anthropic's wire shape
|
|
169
|
+
* requires an object input.
|
|
170
|
+
*/
|
|
171
|
+
const groupedMessages = (history) => {
|
|
172
|
+
const initial = Result.succeed({
|
|
173
|
+
messages: [],
|
|
174
|
+
currentRole: Option.none(),
|
|
175
|
+
userBuf: [],
|
|
176
|
+
assistantBuf: []
|
|
177
|
+
});
|
|
178
|
+
return pipe(Array.reduce(history, initial, (acc, item) => Result.flatMap(acc, (a) => groupStep(a, item))), Result.map(flushAcc));
|
|
179
|
+
};
|
|
180
|
+
const isSystemMessage = (item) => item.type === "message" && item.role === "system";
|
|
181
|
+
const systemFromHistory = (history) => {
|
|
182
|
+
const texts = pipe(history, Array.filterMap((item) => isSystemMessage(item) ? Result.succeed(messageText(item)) : Result.failVoid), Array.filter((s) => s.length > 0));
|
|
183
|
+
return texts.length === 0 ? Option.none() : Option.some(texts.join("\n"));
|
|
184
|
+
};
|
|
185
|
+
const buildRequestBody = (params) => pipe(groupedMessages(params.history), Result.map((messages) => ({
|
|
186
|
+
model: params.model,
|
|
187
|
+
messages,
|
|
188
|
+
max_tokens: params.maxTokens,
|
|
189
|
+
...Option.match(systemFromHistory(params.history), {
|
|
190
|
+
onNone: () => ({}),
|
|
191
|
+
onSome: (system) => ({ system })
|
|
192
|
+
}),
|
|
193
|
+
...Option.match(params.temperature, {
|
|
194
|
+
onNone: () => ({}),
|
|
195
|
+
onSome: (temperature) => ({ temperature })
|
|
196
|
+
}),
|
|
197
|
+
...Option.match(params.topP, {
|
|
198
|
+
onNone: () => ({}),
|
|
199
|
+
onSome: (top_p) => ({ top_p })
|
|
200
|
+
}),
|
|
201
|
+
...Option.match(params.topK, {
|
|
202
|
+
onNone: () => ({}),
|
|
203
|
+
onSome: (top_k) => ({ top_k })
|
|
204
|
+
}),
|
|
205
|
+
...Option.match(params.stopSequences, {
|
|
206
|
+
onNone: () => ({}),
|
|
207
|
+
onSome: (stop_sequences) => ({ stop_sequences })
|
|
208
|
+
}),
|
|
209
|
+
...Option.match(params.thinking, {
|
|
210
|
+
onNone: () => ({}),
|
|
211
|
+
onSome: (thinking) => ({ thinking })
|
|
212
|
+
}),
|
|
213
|
+
...Option.match(params.tools, {
|
|
214
|
+
onNone: () => ({}),
|
|
215
|
+
onSome: (tools) => ({ tools })
|
|
216
|
+
}),
|
|
217
|
+
...Option.match(params.toolChoice, {
|
|
218
|
+
onNone: () => ({}),
|
|
219
|
+
onSome: (tool_choice) => ({ tool_choice })
|
|
220
|
+
}),
|
|
221
|
+
...Option.match(params.userId, {
|
|
222
|
+
onNone: () => ({}),
|
|
223
|
+
onSome: (user_id) => ({ metadata: { user_id } })
|
|
224
|
+
}),
|
|
225
|
+
...Option.match(params.outputConfig, {
|
|
226
|
+
onNone: () => ({}),
|
|
227
|
+
onSome: (output_config) => ({ output_config })
|
|
228
|
+
}),
|
|
229
|
+
stream: true
|
|
230
|
+
})));
|
|
231
|
+
const emptyBlock = (type) => ({
|
|
232
|
+
type,
|
|
233
|
+
text: "",
|
|
234
|
+
inputJson: "",
|
|
235
|
+
thinking: "",
|
|
236
|
+
signature: "",
|
|
237
|
+
id: Option.none(),
|
|
238
|
+
name: Option.none(),
|
|
239
|
+
redactedData: Option.none()
|
|
240
|
+
});
|
|
241
|
+
const emptyAccumulator = {
|
|
242
|
+
blocks: {},
|
|
243
|
+
stopReason: Option.none(),
|
|
244
|
+
usage: {}
|
|
245
|
+
};
|
|
246
|
+
const replaceBlock = (acc, index, block) => ({
|
|
247
|
+
...acc,
|
|
248
|
+
blocks: {
|
|
249
|
+
...acc.blocks,
|
|
250
|
+
[index]: block
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const updateBlock = (acc, index, patch) => replaceBlock(acc, index, patch(acc.blocks[index] ?? emptyBlock("text")));
|
|
254
|
+
const startBlock = (acc, index, block) => Match.value(block).pipe(Match.discriminatorsExhaustive("type")({
|
|
255
|
+
text: () => replaceBlock(acc, index, emptyBlock("text")),
|
|
256
|
+
tool_use: (b) => replaceBlock(acc, index, {
|
|
257
|
+
...emptyBlock("tool_use"),
|
|
258
|
+
id: Option.some(b.id),
|
|
259
|
+
name: Option.some(b.name),
|
|
260
|
+
inputJson: typeof b.input === "string" ? b.input : ""
|
|
261
|
+
}),
|
|
262
|
+
thinking: () => replaceBlock(acc, index, emptyBlock("thinking")),
|
|
263
|
+
redacted_thinking: (b) => replaceBlock(acc, index, {
|
|
264
|
+
...emptyBlock("redacted_thinking"),
|
|
265
|
+
redactedData: Option.some(b.data)
|
|
266
|
+
})
|
|
267
|
+
}));
|
|
268
|
+
const appendTextDelta = (acc, index, text) => updateBlock(acc, index, (b) => ({
|
|
269
|
+
...b,
|
|
270
|
+
text: b.text + text
|
|
271
|
+
}));
|
|
272
|
+
const appendInputJsonDelta = (acc, index, partial) => updateBlock(acc, index, (b) => ({
|
|
273
|
+
...b,
|
|
274
|
+
inputJson: b.inputJson + partial
|
|
275
|
+
}));
|
|
276
|
+
const appendThinkingDelta = (acc, index, thinking) => updateBlock(acc, index, (b) => ({
|
|
277
|
+
...b,
|
|
278
|
+
thinking: b.thinking + thinking
|
|
279
|
+
}));
|
|
280
|
+
const appendSignatureDelta = (acc, index, signature) => updateBlock(acc, index, (b) => ({
|
|
281
|
+
...b,
|
|
282
|
+
signature: b.signature + signature
|
|
283
|
+
}));
|
|
284
|
+
const setStopReason = (acc, reason) => ({
|
|
285
|
+
...acc,
|
|
286
|
+
stopReason: Option.some(reason)
|
|
287
|
+
});
|
|
288
|
+
const cachedFromWire = (wire) => Option.fromNullishOr(wire.cache_read_input_tokens);
|
|
289
|
+
const mergeUsage = (acc, wire) => {
|
|
290
|
+
const cached = cachedFromWire(wire);
|
|
291
|
+
const usage = {
|
|
292
|
+
...acc.usage,
|
|
293
|
+
...wire.input_tokens !== void 0 && { input_tokens: wire.input_tokens },
|
|
294
|
+
...wire.output_tokens !== void 0 && { output_tokens: wire.output_tokens },
|
|
295
|
+
...wire.input_tokens !== void 0 && wire.output_tokens !== void 0 && { total_tokens: wire.input_tokens + wire.output_tokens },
|
|
296
|
+
...Option.match(cached, {
|
|
297
|
+
onNone: () => ({}),
|
|
298
|
+
onSome: (cached_tokens) => ({ input_tokens_details: { cached_tokens } })
|
|
299
|
+
})
|
|
300
|
+
};
|
|
301
|
+
return {
|
|
302
|
+
...acc,
|
|
303
|
+
usage
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
const stopReasonFromAnthropic = (reason) => Option.match(reason, {
|
|
307
|
+
onNone: () => "stop",
|
|
308
|
+
onSome: (r) => Match.value(r).pipe(Match.when("tool_use", () => "tool_calls"), Match.when("max_tokens", () => "max_tokens"), Match.orElse(() => "stop"))
|
|
309
|
+
});
|
|
310
|
+
const blocksByIndex = (acc) => pipe(Object.keys(acc.blocks), Array.map((k) => Number(k)), Array.sort(Order.Number), Array.map((i) => acc.blocks[i]));
|
|
311
|
+
const blockToItems = (block) => Match.value(block.type).pipe(Match.when("text", () => block.text.length === 0 ? [] : [{
|
|
312
|
+
type: "message",
|
|
313
|
+
role: "assistant",
|
|
314
|
+
content: [{
|
|
315
|
+
type: "output_text",
|
|
316
|
+
text: block.text
|
|
317
|
+
}]
|
|
318
|
+
}]), Match.when("tool_use", () => [{
|
|
319
|
+
type: "function_call",
|
|
320
|
+
call_id: Option.getOrElse(block.id, () => ""),
|
|
321
|
+
name: Option.getOrElse(block.name, () => ""),
|
|
322
|
+
arguments: block.inputJson
|
|
323
|
+
}]), Match.when("thinking", () => [{
|
|
324
|
+
type: "reasoning",
|
|
325
|
+
...block.thinking.length > 0 && { summary: block.thinking },
|
|
326
|
+
...block.signature.length > 0 && { signature: block.signature }
|
|
327
|
+
}]), Match.when("redacted_thinking", () => [{
|
|
328
|
+
type: "reasoning",
|
|
329
|
+
...Option.match(block.redactedData, {
|
|
330
|
+
onNone: () => ({}),
|
|
331
|
+
onSome: (signature) => ({ signature })
|
|
332
|
+
})
|
|
333
|
+
}]), Match.exhaustive);
|
|
334
|
+
const mergeStep = (acc, item) => {
|
|
335
|
+
const last = Array.last(acc.out);
|
|
336
|
+
if (Option.isSome(last) && last.value.type === "message" && last.value.role === "assistant" && item.type === "message" && item.role === "assistant") {
|
|
337
|
+
const merged = {
|
|
338
|
+
...last.value,
|
|
339
|
+
content: [...last.value.content, ...item.content]
|
|
340
|
+
};
|
|
341
|
+
return { out: [...acc.out.slice(0, -1), merged] };
|
|
342
|
+
}
|
|
343
|
+
return { out: [...acc.out, item] };
|
|
344
|
+
};
|
|
345
|
+
const mergeAdjacentAssistantText = (items) => Array.reduce(items, { out: [] }, mergeStep).out;
|
|
346
|
+
const accumulatorToTurn = (acc) => ({
|
|
347
|
+
items: pipe(blocksByIndex(acc), Array.flatMap(blockToItems), mergeAdjacentAssistantText),
|
|
348
|
+
usage: acc.usage,
|
|
349
|
+
stop_reason: stopReasonFromAnthropic(acc.stopReason)
|
|
350
|
+
});
|
|
351
|
+
//#endregion
|
|
352
|
+
export { WireContentBlock, accumulatorToTurn, appendInputJsonDelta, appendSignatureDelta, appendTextDelta, appendThinkingDelta, buildRequestBody, emptyAccumulator, mergeUsage, setStopReason, startBlock, codec_exports as t };
|
|
353
|
+
|
|
354
|
+
//# sourceMappingURL=codec.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.mjs","names":["Arr"],"sources":["../src/codec.ts"],"sourcesContent":["import { Array as Arr, Encoding, Match, Option, Order, Result, Schema, pipe } from \"effect\"\nimport * as Items from \"@effect-uai/core/Items\"\nimport { JsonParseError } from \"@effect-uai/core/JSONL\"\nimport type { Turn } from \"@effect-uai/core/Turn\"\n\n// ---------------------------------------------------------------------------\n// Wire schemas - subset of Anthropic Messages API we consume.\n// Reference: https://platform.claude.com/docs/en/api/messages\n// ---------------------------------------------------------------------------\n\nconst WireTextBlock = Schema.Struct({\n type: Schema.Literal(\"text\"),\n text: Schema.String,\n})\n\nconst WireToolUseBlock = Schema.Struct({\n type: Schema.Literal(\"tool_use\"),\n id: Schema.String,\n name: Schema.String,\n input: Schema.Unknown,\n})\n\nconst WireThinkingBlock = Schema.Struct({\n type: Schema.Literal(\"thinking\"),\n thinking: Schema.String,\n signature: Schema.optional(Schema.String),\n})\n\nconst WireRedactedThinkingBlock = Schema.Struct({\n type: Schema.Literal(\"redacted_thinking\"),\n data: Schema.String,\n})\n\nexport const WireContentBlock = Schema.Union([\n WireTextBlock,\n WireToolUseBlock,\n WireThinkingBlock,\n WireRedactedThinkingBlock,\n])\nexport type WireContentBlock = typeof WireContentBlock.Type\n\nconst WireUsage = Schema.Struct({\n input_tokens: Schema.optional(Schema.Number),\n output_tokens: Schema.optional(Schema.Number),\n cache_creation_input_tokens: Schema.optional(Schema.NullOr(Schema.Number)),\n cache_read_input_tokens: Schema.optional(Schema.NullOr(Schema.Number)),\n})\nexport type WireUsage = typeof WireUsage.Type\n\n// ---------------------------------------------------------------------------\n// History → request body\n// ---------------------------------------------------------------------------\n\ntype RequestTextContent = {\n readonly type: \"text\"\n readonly text: string\n}\n\ntype RequestToolResultContent = {\n readonly type: \"tool_result\"\n readonly tool_use_id: string\n readonly content: string\n}\n\ntype RequestToolUseContent = {\n readonly type: \"tool_use\"\n readonly id: string\n readonly name: string\n readonly input: unknown\n}\n\ntype RequestThinkingContent = {\n readonly type: \"thinking\"\n readonly thinking: string\n readonly signature?: string\n}\n\ntype RequestRedactedThinkingContent = {\n readonly type: \"redacted_thinking\"\n readonly data: string\n}\n\ntype RequestImageContent = {\n readonly type: \"image\"\n readonly source:\n | { readonly type: \"url\"; readonly url: string }\n | { readonly type: \"base64\"; readonly media_type: string; readonly data: string }\n}\n\ntype RequestUserContentBlock = RequestTextContent | RequestToolResultContent | RequestImageContent\n\ntype RequestAssistantContentBlock =\n | RequestTextContent\n | RequestToolUseContent\n | RequestThinkingContent\n | RequestRedactedThinkingContent\n\ntype RequestUserMessage = {\n readonly role: \"user\"\n readonly content: ReadonlyArray<RequestUserContentBlock>\n}\n\ntype RequestAssistantMessage = {\n readonly role: \"assistant\"\n readonly content: ReadonlyArray<RequestAssistantContentBlock>\n}\n\ntype RequestMessage = RequestUserMessage | RequestAssistantMessage\n\nconst blockText = Match.type<Items.ContentBlock>().pipe(\n Match.discriminatorsExhaustive(\"type\")({\n input_text: (b) => b.text,\n input_image: () => \"\",\n output_text: (b) => b.text,\n refusal: (b) => b.text,\n }),\n)\n\nconst messageText = (message: Items.Message): string => message.content.map(blockText).join(\"\")\n\nconst imageSourceToWire = Match.type<Items.InputImage[\"source\"]>().pipe(\n Match.tag(\"url\", (s): RequestImageContent[\"source\"] => ({ type: \"url\", url: s.url })),\n Match.tag(\"base64\", (s): RequestImageContent[\"source\"] => ({\n type: \"base64\",\n media_type: s.mimeType,\n data: s.base64,\n })),\n Match.tag(\"bytes\", (s): RequestImageContent[\"source\"] => ({\n type: \"base64\",\n media_type: s.mimeType,\n data: Encoding.encodeBase64(s.bytes),\n })),\n Match.exhaustive,\n)\n\nconst userContentBlock = (\n block: Items.ContentBlock,\n): Result.Result<RequestUserContentBlock, void> =>\n Match.value(block).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n input_text: (b) =>\n b.text.length === 0\n ? Result.failVoid\n : Result.succeed({ type: \"text\" as const, text: b.text }),\n input_image: (b) =>\n Result.succeed({ type: \"image\" as const, source: imageSourceToWire(b.source) }),\n // Assistant content; never appears on a user message in practice. Skip.\n output_text: () => Result.failVoid,\n refusal: () => Result.failVoid,\n }),\n )\n\nconst parseJson = (s: string): Result.Result<unknown, JsonParseError> =>\n Result.try({\n try: () => JSON.parse(s) as unknown,\n catch: (cause) => new JsonParseError({ line: s, cause }),\n })\n\ntype RoleBucket = \"user\" | \"assistant\" | \"system\"\n\nconst roleBucket = (item: Items.Item): RoleBucket =>\n Match.value(item).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n message: (m) => m.role,\n function_call: () => \"assistant\" as const,\n function_call_output: () => \"user\" as const,\n reasoning: () => \"assistant\" as const,\n }),\n )\n\nconst itemToUserBlocks = (item: Items.Item): ReadonlyArray<RequestUserContentBlock> =>\n Match.value(item).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n message: (m): ReadonlyArray<RequestUserContentBlock> =>\n m.role === \"user\" ? pipe(m.content, Arr.filterMap(userContentBlock)) : [],\n function_call: (): ReadonlyArray<RequestUserContentBlock> => [],\n function_call_output: (o): ReadonlyArray<RequestUserContentBlock> => [\n { type: \"tool_result\", tool_use_id: o.call_id, content: o.output },\n ],\n reasoning: (): ReadonlyArray<RequestUserContentBlock> => [],\n }),\n )\n\nconst itemToAssistantBlocks = (\n item: Items.Item,\n): Result.Result<ReadonlyArray<RequestAssistantContentBlock>, JsonParseError> =>\n Match.value(item).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n message: (m): Result.Result<ReadonlyArray<RequestAssistantContentBlock>, JsonParseError> => {\n const text = messageText(m)\n return Result.succeed(\n m.role === \"assistant\" && text.length > 0 ? [{ type: \"text\", text }] : [],\n )\n },\n function_call: (f) =>\n pipe(\n parseJson(f.arguments),\n Result.map(\n (input): ReadonlyArray<RequestAssistantContentBlock> => [\n { type: \"tool_use\", id: f.call_id, name: f.name, input },\n ],\n ),\n ),\n function_call_output: (): Result.Result<\n ReadonlyArray<RequestAssistantContentBlock>,\n JsonParseError\n > => Result.succeed([]),\n reasoning: (r) => {\n const blocks: ReadonlyArray<RequestAssistantContentBlock> =\n r.summary !== undefined\n ? [\n {\n type: \"thinking\",\n thinking: r.summary,\n ...(r.signature !== undefined && { signature: r.signature }),\n },\n ]\n : r.signature !== undefined\n ? [{ type: \"redacted_thinking\", data: r.signature }]\n : []\n return Result.succeed(blocks)\n },\n }),\n )\n\ntype GroupAcc = {\n readonly messages: ReadonlyArray<RequestMessage>\n readonly currentRole: Option.Option<\"user\" | \"assistant\">\n readonly userBuf: ReadonlyArray<RequestUserContentBlock>\n readonly assistantBuf: ReadonlyArray<RequestAssistantContentBlock>\n}\n\nconst flushAcc = (acc: GroupAcc): ReadonlyArray<RequestMessage> =>\n Option.match(acc.currentRole, {\n onNone: () => acc.messages,\n onSome: (role) =>\n role === \"user\" && acc.userBuf.length > 0\n ? [...acc.messages, { role: \"user\", content: acc.userBuf }]\n : role === \"assistant\" && acc.assistantBuf.length > 0\n ? [...acc.messages, { role: \"assistant\", content: acc.assistantBuf }]\n : acc.messages,\n })\n\nconst appendUser = (acc: GroupAcc, blocks: ReadonlyArray<RequestUserContentBlock>): GroupAcc =>\n blocks.length === 0\n ? acc\n : Option.isSome(acc.currentRole) && acc.currentRole.value === \"user\"\n ? { ...acc, userBuf: [...acc.userBuf, ...blocks] }\n : {\n messages: flushAcc(acc),\n currentRole: Option.some(\"user\"),\n userBuf: blocks,\n assistantBuf: [],\n }\n\nconst appendAssistant = (\n acc: GroupAcc,\n blocks: ReadonlyArray<RequestAssistantContentBlock>,\n): GroupAcc =>\n blocks.length === 0\n ? acc\n : Option.isSome(acc.currentRole) && acc.currentRole.value === \"assistant\"\n ? { ...acc, assistantBuf: [...acc.assistantBuf, ...blocks] }\n : {\n messages: flushAcc(acc),\n currentRole: Option.some(\"assistant\"),\n userBuf: [],\n assistantBuf: blocks,\n }\n\nconst groupStep = (acc: GroupAcc, item: Items.Item): Result.Result<GroupAcc, JsonParseError> => {\n const bucket = roleBucket(item)\n if (bucket === \"system\") return Result.succeed(acc)\n if (bucket === \"user\") {\n return Result.succeed(appendUser(acc, itemToUserBlocks(item)))\n }\n return pipe(\n itemToAssistantBlocks(item),\n Result.map((blocks) => appendAssistant(acc, blocks)),\n )\n}\n\n/**\n * Group consecutive same-role items into Anthropic-shaped messages.\n * Anthropic requires strict user/assistant alternation; consecutive items\n * from the same role are folded into one message's `content`. Fails if any\n * `function_call.arguments` is not valid JSON, since Anthropic's wire shape\n * requires an object input.\n */\nconst groupedMessages = (\n history: ReadonlyArray<Items.Item>,\n): Result.Result<ReadonlyArray<RequestMessage>, JsonParseError> => {\n const initial: Result.Result<GroupAcc, JsonParseError> = Result.succeed({\n messages: [],\n currentRole: Option.none(),\n userBuf: [],\n assistantBuf: [],\n })\n return pipe(\n Arr.reduce(history, initial, (acc, item) => Result.flatMap(acc, (a) => groupStep(a, item))),\n Result.map(flushAcc),\n )\n}\n\nconst isSystemMessage = (item: Items.Item): item is Items.Message =>\n item.type === \"message\" && item.role === \"system\"\n\nconst systemFromHistory = (history: ReadonlyArray<Items.Item>): Option.Option<string> => {\n const texts = pipe(\n history,\n Arr.filterMap((item) =>\n isSystemMessage(item) ? Result.succeed(messageText(item)) : Result.failVoid,\n ),\n Arr.filter((s) => s.length > 0),\n )\n return texts.length === 0 ? Option.none() : Option.some(texts.join(\"\\n\"))\n}\n\nexport type ThinkingConfig = {\n readonly type: \"enabled\"\n readonly budget_tokens: number\n}\n\nexport type RequestBody = {\n readonly model: string\n readonly messages: ReadonlyArray<RequestMessage>\n readonly max_tokens: number\n readonly system?: string\n readonly temperature?: number\n readonly top_p?: number\n readonly top_k?: number\n readonly stop_sequences?: ReadonlyArray<string>\n readonly thinking?: ThinkingConfig\n readonly tools?: ReadonlyArray<Record<string, unknown>>\n readonly tool_choice?: Record<string, unknown>\n readonly metadata?: { readonly user_id: string }\n readonly output_config?: Record<string, unknown>\n readonly stream: true\n}\n\nexport const buildRequestBody = (params: {\n readonly model: string\n readonly history: ReadonlyArray<Items.Item>\n readonly maxTokens: number\n readonly temperature: Option.Option<number>\n readonly topP: Option.Option<number>\n readonly topK: Option.Option<number>\n readonly stopSequences: Option.Option<ReadonlyArray<string>>\n readonly thinking: Option.Option<ThinkingConfig>\n readonly tools: Option.Option<ReadonlyArray<Record<string, unknown>>>\n readonly toolChoice: Option.Option<Record<string, unknown>>\n readonly userId: Option.Option<string>\n readonly outputConfig: Option.Option<Record<string, unknown>>\n}): Result.Result<RequestBody, JsonParseError> =>\n pipe(\n groupedMessages(params.history),\n Result.map(\n (messages): RequestBody => ({\n model: params.model,\n messages,\n max_tokens: params.maxTokens,\n ...Option.match(systemFromHistory(params.history), {\n onNone: () => ({}),\n onSome: (system) => ({ system }),\n }),\n ...Option.match(params.temperature, {\n onNone: () => ({}),\n onSome: (temperature) => ({ temperature }),\n }),\n ...Option.match(params.topP, {\n onNone: () => ({}),\n onSome: (top_p) => ({ top_p }),\n }),\n ...Option.match(params.topK, {\n onNone: () => ({}),\n onSome: (top_k) => ({ top_k }),\n }),\n ...Option.match(params.stopSequences, {\n onNone: () => ({}),\n onSome: (stop_sequences) => ({ stop_sequences }),\n }),\n ...Option.match(params.thinking, {\n onNone: () => ({}),\n onSome: (thinking) => ({ thinking }),\n }),\n ...Option.match(params.tools, {\n onNone: () => ({}),\n onSome: (tools) => ({ tools }),\n }),\n ...Option.match(params.toolChoice, {\n onNone: () => ({}),\n onSome: (tool_choice) => ({ tool_choice }),\n }),\n ...Option.match(params.userId, {\n onNone: () => ({}),\n onSome: (user_id) => ({ metadata: { user_id } }),\n }),\n ...Option.match(params.outputConfig, {\n onNone: () => ({}),\n onSome: (output_config) => ({ output_config }),\n }),\n stream: true,\n }),\n ),\n )\n\n// ---------------------------------------------------------------------------\n// Stream-level state - assemble content blocks index-by-index, then emit\n// our `Items.Item[]` when `message_stop` lands.\n// ---------------------------------------------------------------------------\n\ntype BlockBuffer = {\n readonly type: WireContentBlock[\"type\"]\n readonly text: string\n readonly inputJson: string\n readonly thinking: string\n readonly signature: string\n readonly id: Option.Option<string>\n readonly name: Option.Option<string>\n readonly redactedData: Option.Option<string>\n}\n\nconst emptyBlock = (type: WireContentBlock[\"type\"]): BlockBuffer => ({\n type,\n text: \"\",\n inputJson: \"\",\n thinking: \"\",\n signature: \"\",\n id: Option.none(),\n name: Option.none(),\n redactedData: Option.none(),\n})\n\nexport type Accumulator = {\n readonly blocks: Readonly<Record<number, BlockBuffer>>\n readonly stopReason: Option.Option<string>\n readonly usage: Items.Usage\n}\n\nexport const emptyAccumulator: Accumulator = {\n blocks: {},\n stopReason: Option.none(),\n usage: {},\n}\n\nconst replaceBlock = (acc: Accumulator, index: number, block: BlockBuffer): Accumulator => ({\n ...acc,\n blocks: { ...acc.blocks, [index]: block },\n})\n\nconst updateBlock = (\n acc: Accumulator,\n index: number,\n patch: (block: BlockBuffer) => BlockBuffer,\n): Accumulator => replaceBlock(acc, index, patch(acc.blocks[index] ?? emptyBlock(\"text\")))\n\nexport const startBlock = (acc: Accumulator, index: number, block: WireContentBlock): Accumulator =>\n Match.value(block).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n text: () => replaceBlock(acc, index, emptyBlock(\"text\")),\n tool_use: (b) =>\n replaceBlock(acc, index, {\n ...emptyBlock(\"tool_use\"),\n id: Option.some(b.id),\n name: Option.some(b.name),\n inputJson: typeof b.input === \"string\" ? b.input : \"\",\n }),\n thinking: () => replaceBlock(acc, index, emptyBlock(\"thinking\")),\n redacted_thinking: (b) =>\n replaceBlock(acc, index, {\n ...emptyBlock(\"redacted_thinking\"),\n redactedData: Option.some(b.data),\n }),\n }),\n )\n\nexport const appendTextDelta = (acc: Accumulator, index: number, text: string): Accumulator =>\n updateBlock(acc, index, (b) => ({ ...b, text: b.text + text }))\n\nexport const appendInputJsonDelta = (\n acc: Accumulator,\n index: number,\n partial: string,\n): Accumulator => updateBlock(acc, index, (b) => ({ ...b, inputJson: b.inputJson + partial }))\n\nexport const appendThinkingDelta = (\n acc: Accumulator,\n index: number,\n thinking: string,\n): Accumulator => updateBlock(acc, index, (b) => ({ ...b, thinking: b.thinking + thinking }))\n\nexport const appendSignatureDelta = (\n acc: Accumulator,\n index: number,\n signature: string,\n): Accumulator => updateBlock(acc, index, (b) => ({ ...b, signature: b.signature + signature }))\n\nexport const setStopReason = (acc: Accumulator, reason: string): Accumulator => ({\n ...acc,\n stopReason: Option.some(reason),\n})\n\nconst cachedFromWire = (wire: WireUsage): Option.Option<number> =>\n Option.fromNullishOr(wire.cache_read_input_tokens)\n\nexport const mergeUsage = (acc: Accumulator, wire: WireUsage): Accumulator => {\n const cached = cachedFromWire(wire)\n const usage: Items.Usage = {\n ...acc.usage,\n ...(wire.input_tokens !== undefined && { input_tokens: wire.input_tokens }),\n ...(wire.output_tokens !== undefined && { output_tokens: wire.output_tokens }),\n ...(wire.input_tokens !== undefined &&\n wire.output_tokens !== undefined && {\n total_tokens: wire.input_tokens + wire.output_tokens,\n }),\n ...Option.match(cached, {\n onNone: () => ({}),\n onSome: (cached_tokens) => ({ input_tokens_details: { cached_tokens } }),\n }),\n }\n return { ...acc, usage }\n}\n\nconst stopReasonFromAnthropic = (reason: Option.Option<string>): Turn[\"stop_reason\"] =>\n Option.match(reason, {\n onNone: () => \"stop\" as const,\n onSome: (r) =>\n Match.value(r).pipe(\n Match.when(\"tool_use\", () => \"tool_calls\" as const),\n Match.when(\"max_tokens\", () => \"max_tokens\" as const),\n Match.orElse(() => \"stop\" as const),\n ),\n })\n\nconst blocksByIndex = (acc: Accumulator): ReadonlyArray<BlockBuffer> =>\n pipe(\n Object.keys(acc.blocks),\n Arr.map((k) => Number(k)),\n Arr.sort(Order.Number),\n Arr.map((i) => acc.blocks[i]!),\n )\n\nconst blockToItems = (block: BlockBuffer): ReadonlyArray<Items.Item> =>\n Match.value(block.type).pipe(\n Match.when(\n \"text\",\n (): ReadonlyArray<Items.Item> =>\n block.text.length === 0\n ? []\n : [\n {\n type: \"message\",\n role: \"assistant\",\n content: [{ type: \"output_text\", text: block.text }],\n },\n ],\n ),\n Match.when(\n \"tool_use\",\n (): ReadonlyArray<Items.Item> => [\n {\n type: \"function_call\",\n call_id: Option.getOrElse(block.id, () => \"\"),\n name: Option.getOrElse(block.name, () => \"\"),\n arguments: block.inputJson,\n },\n ],\n ),\n Match.when(\n \"thinking\",\n (): ReadonlyArray<Items.Item> => [\n {\n type: \"reasoning\",\n ...(block.thinking.length > 0 && { summary: block.thinking }),\n ...(block.signature.length > 0 && { signature: block.signature }),\n },\n ],\n ),\n Match.when(\n \"redacted_thinking\",\n (): ReadonlyArray<Items.Item> => [\n {\n type: \"reasoning\",\n ...Option.match(block.redactedData, {\n onNone: () => ({}),\n onSome: (signature) => ({ signature }),\n }),\n },\n ],\n ),\n Match.exhaustive,\n )\n\ntype MergeAcc = {\n readonly out: ReadonlyArray<Items.Item>\n}\n\nconst mergeStep = (acc: MergeAcc, item: Items.Item): MergeAcc => {\n const last = Arr.last(acc.out)\n if (\n Option.isSome(last) &&\n last.value.type === \"message\" &&\n last.value.role === \"assistant\" &&\n item.type === \"message\" &&\n item.role === \"assistant\"\n ) {\n const merged: Items.Message = {\n ...last.value,\n content: [...last.value.content, ...item.content],\n }\n return { out: [...acc.out.slice(0, -1), merged] }\n }\n return { out: [...acc.out, item] }\n}\n\nconst mergeAdjacentAssistantText = (items: ReadonlyArray<Items.Item>): ReadonlyArray<Items.Item> =>\n Arr.reduce(items, { out: [] } as MergeAcc, mergeStep).out\n\nexport const accumulatorToTurn = (acc: Accumulator): Turn => ({\n items: pipe(blocksByIndex(acc), Arr.flatMap(blockToItems), mergeAdjacentAssistantText),\n usage: acc.usage,\n stop_reason: stopReasonFromAnthropic(acc.stopReason),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;AAUA,MAAM,gBAAgB,OAAO,OAAO;CAClC,MAAM,OAAO,QAAQ,OAAO;CAC5B,MAAM,OAAO;CACd,CAAC;AAEF,MAAM,mBAAmB,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,WAAW;CAChC,IAAI,OAAO;CACX,MAAM,OAAO;CACb,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,oBAAoB,OAAO,OAAO;CACtC,MAAM,OAAO,QAAQ,WAAW;CAChC,UAAU,OAAO;CACjB,WAAW,OAAO,SAAS,OAAO,OAAO;CAC1C,CAAC;AAEF,MAAM,4BAA4B,OAAO,OAAO;CAC9C,MAAM,OAAO,QAAQ,oBAAoB;CACzC,MAAM,OAAO;CACd,CAAC;AAEF,MAAa,mBAAmB,OAAO,MAAM;CAC3C;CACA;CACA;CACA;CACD,CAAC;AAGgB,OAAO,OAAO;CAC9B,cAAc,OAAO,SAAS,OAAO,OAAO;CAC5C,eAAe,OAAO,SAAS,OAAO,OAAO;CAC7C,6BAA6B,OAAO,SAAS,OAAO,OAAO,OAAO,OAAO,CAAC;CAC1E,yBAAyB,OAAO,SAAS,OAAO,OAAO,OAAO,OAAO,CAAC;CACvE,CAAC;AA+DF,MAAM,YAAY,MAAM,MAA0B,CAAC,KACjD,MAAM,yBAAyB,OAAO,CAAC;CACrC,aAAa,MAAM,EAAE;CACrB,mBAAmB;CACnB,cAAc,MAAM,EAAE;CACtB,UAAU,MAAM,EAAE;CACnB,CAAC,CACH;AAED,MAAM,eAAe,YAAmC,QAAQ,QAAQ,IAAI,UAAU,CAAC,KAAK,GAAG;AAE/F,MAAM,oBAAoB,MAAM,MAAkC,CAAC,KACjE,MAAM,IAAI,QAAQ,OAAsC;C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