@effect-uai/anthropic 0.1.0 → 0.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/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/src/codec.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Array as Arr, Match, Option, Order, Result, Schema, pipe } from "effect"
|
|
1
|
+
import { Array as Arr, Encoding, Match, Option, Order, Result, Schema, pipe } from "effect"
|
|
2
2
|
import * as Items from "@effect-uai/core/Items"
|
|
3
3
|
import { JsonParseError } from "@effect-uai/core/JSONL"
|
|
4
|
-
import { matchType } from "@effect-uai/core/Match"
|
|
5
4
|
import type { Turn } from "@effect-uai/core/Turn"
|
|
6
5
|
|
|
7
6
|
// ---------------------------------------------------------------------------
|
|
@@ -52,36 +51,36 @@ export type WireUsage = typeof WireUsage.Type
|
|
|
52
51
|
// History → request body
|
|
53
52
|
// ---------------------------------------------------------------------------
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
type RequestTextContent = {
|
|
56
55
|
readonly type: "text"
|
|
57
56
|
readonly text: string
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
type RequestToolResultContent = {
|
|
61
60
|
readonly type: "tool_result"
|
|
62
61
|
readonly tool_use_id: string
|
|
63
62
|
readonly content: string
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
type RequestToolUseContent = {
|
|
67
66
|
readonly type: "tool_use"
|
|
68
67
|
readonly id: string
|
|
69
68
|
readonly name: string
|
|
70
69
|
readonly input: unknown
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
type RequestThinkingContent = {
|
|
74
73
|
readonly type: "thinking"
|
|
75
74
|
readonly thinking: string
|
|
76
75
|
readonly signature?: string
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
type RequestRedactedThinkingContent = {
|
|
80
79
|
readonly type: "redacted_thinking"
|
|
81
80
|
readonly data: string
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
|
|
83
|
+
type RequestImageContent = {
|
|
85
84
|
readonly type: "image"
|
|
86
85
|
readonly source:
|
|
87
86
|
| { readonly type: "url"; readonly url: string }
|
|
@@ -96,12 +95,12 @@ type RequestAssistantContentBlock =
|
|
|
96
95
|
| RequestThinkingContent
|
|
97
96
|
| RequestRedactedThinkingContent
|
|
98
97
|
|
|
99
|
-
|
|
98
|
+
type RequestUserMessage = {
|
|
100
99
|
readonly role: "user"
|
|
101
100
|
readonly content: ReadonlyArray<RequestUserContentBlock>
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
|
|
103
|
+
type RequestAssistantMessage = {
|
|
105
104
|
readonly role: "assistant"
|
|
106
105
|
readonly content: ReadonlyArray<RequestAssistantContentBlock>
|
|
107
106
|
}
|
|
@@ -109,41 +108,46 @@ interface RequestAssistantMessage {
|
|
|
109
108
|
type RequestMessage = RequestUserMessage | RequestAssistantMessage
|
|
110
109
|
|
|
111
110
|
const blockText = Match.type<Items.ContentBlock>().pipe(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
Match.discriminatorsExhaustive("type")({
|
|
112
|
+
input_text: (b) => b.text,
|
|
113
|
+
input_image: () => "",
|
|
114
|
+
output_text: (b) => b.text,
|
|
115
|
+
refusal: (b) => b.text,
|
|
116
|
+
}),
|
|
117
117
|
)
|
|
118
118
|
|
|
119
119
|
const messageText = (message: Items.Message): string => message.content.map(blockText).join("")
|
|
120
120
|
|
|
121
|
+
const imageSourceToWire = Match.type<Items.InputImage["source"]>().pipe(
|
|
122
|
+
Match.tag("url", (s): RequestImageContent["source"] => ({ type: "url", url: s.url })),
|
|
123
|
+
Match.tag("base64", (s): RequestImageContent["source"] => ({
|
|
124
|
+
type: "base64",
|
|
125
|
+
media_type: s.mimeType,
|
|
126
|
+
data: s.base64,
|
|
127
|
+
})),
|
|
128
|
+
Match.tag("bytes", (s): RequestImageContent["source"] => ({
|
|
129
|
+
type: "base64",
|
|
130
|
+
media_type: s.mimeType,
|
|
131
|
+
data: Encoding.encodeBase64(s.bytes),
|
|
132
|
+
})),
|
|
133
|
+
Match.exhaustive,
|
|
134
|
+
)
|
|
135
|
+
|
|
121
136
|
const userContentBlock = (
|
|
122
137
|
block: Items.ContentBlock,
|
|
123
138
|
): Result.Result<RequestUserContentBlock, void> =>
|
|
124
139
|
Match.value(block).pipe(
|
|
125
|
-
|
|
126
|
-
b
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
: {
|
|
137
|
-
type: "base64" as const,
|
|
138
|
-
media_type: b.source.media_type,
|
|
139
|
-
data: b.source.data,
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
|
-
),
|
|
143
|
-
// Assistant content; never appears on a user message in practice. Skip.
|
|
144
|
-
matchType("output_text", () => Result.failVoid),
|
|
145
|
-
matchType("refusal", () => Result.failVoid),
|
|
146
|
-
Match.exhaustive,
|
|
140
|
+
Match.discriminatorsExhaustive("type")({
|
|
141
|
+
input_text: (b) =>
|
|
142
|
+
b.text.length === 0
|
|
143
|
+
? Result.failVoid
|
|
144
|
+
: Result.succeed({ type: "text" as const, text: b.text }),
|
|
145
|
+
input_image: (b) =>
|
|
146
|
+
Result.succeed({ type: "image" as const, source: imageSourceToWire(b.source) }),
|
|
147
|
+
// Assistant content; never appears on a user message in practice. Skip.
|
|
148
|
+
output_text: () => Result.failVoid,
|
|
149
|
+
refusal: () => Result.failVoid,
|
|
150
|
+
}),
|
|
147
151
|
)
|
|
148
152
|
|
|
149
153
|
const parseJson = (s: string): Result.Result<unknown, JsonParseError> =>
|
|
@@ -156,78 +160,70 @@ type RoleBucket = "user" | "assistant" | "system"
|
|
|
156
160
|
|
|
157
161
|
const roleBucket = (item: Items.Item): RoleBucket =>
|
|
158
162
|
Match.value(item).pipe(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
Match.discriminatorsExhaustive("type")({
|
|
164
|
+
message: (m) => m.role,
|
|
165
|
+
function_call: () => "assistant" as const,
|
|
166
|
+
function_call_output: () => "user" as const,
|
|
167
|
+
reasoning: () => "assistant" as const,
|
|
168
|
+
}),
|
|
164
169
|
)
|
|
165
170
|
|
|
166
171
|
const itemToUserBlocks = (item: Items.Item): ReadonlyArray<RequestUserContentBlock> =>
|
|
167
172
|
Match.value(item).pipe(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
(m): ReadonlyArray<RequestUserContentBlock> =>
|
|
173
|
+
Match.discriminatorsExhaustive("type")({
|
|
174
|
+
message: (m): ReadonlyArray<RequestUserContentBlock> =>
|
|
171
175
|
m.role === "user" ? pipe(m.content, Arr.filterMap(userContentBlock)) : [],
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
matchType(
|
|
175
|
-
"function_call_output",
|
|
176
|
-
(o): ReadonlyArray<RequestUserContentBlock> => [
|
|
176
|
+
function_call: (): ReadonlyArray<RequestUserContentBlock> => [],
|
|
177
|
+
function_call_output: (o): ReadonlyArray<RequestUserContentBlock> => [
|
|
177
178
|
{ type: "tool_result", tool_use_id: o.call_id, content: o.output },
|
|
178
179
|
],
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
Match.exhaustive,
|
|
180
|
+
reasoning: (): ReadonlyArray<RequestUserContentBlock> => [],
|
|
181
|
+
}),
|
|
182
182
|
)
|
|
183
183
|
|
|
184
184
|
const itemToAssistantBlocks = (
|
|
185
185
|
item: Items.Item,
|
|
186
186
|
): Result.Result<ReadonlyArray<RequestAssistantContentBlock>, JsonParseError> =>
|
|
187
187
|
Match.value(item).pipe(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
(m): Result.Result<ReadonlyArray<RequestAssistantContentBlock>, JsonParseError> => {
|
|
188
|
+
Match.discriminatorsExhaustive("type")({
|
|
189
|
+
message: (m): Result.Result<ReadonlyArray<RequestAssistantContentBlock>, JsonParseError> => {
|
|
191
190
|
const text = messageText(m)
|
|
192
191
|
return Result.succeed(
|
|
193
192
|
m.role === "assistant" && text.length > 0 ? [{ type: "text", text }] : [],
|
|
194
193
|
)
|
|
195
194
|
},
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
195
|
+
function_call: (f) =>
|
|
196
|
+
pipe(
|
|
197
|
+
parseJson(f.arguments),
|
|
198
|
+
Result.map(
|
|
199
|
+
(input): ReadonlyArray<RequestAssistantContentBlock> => [
|
|
200
|
+
{ type: "tool_use", id: f.call_id, name: f.name, input },
|
|
201
|
+
],
|
|
202
|
+
),
|
|
204
203
|
),
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
()
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
: []
|
|
225
|
-
return Result.succeed(blocks)
|
|
204
|
+
function_call_output: (): Result.Result<
|
|
205
|
+
ReadonlyArray<RequestAssistantContentBlock>,
|
|
206
|
+
JsonParseError
|
|
207
|
+
> => Result.succeed([]),
|
|
208
|
+
reasoning: (r) => {
|
|
209
|
+
const blocks: ReadonlyArray<RequestAssistantContentBlock> =
|
|
210
|
+
r.summary !== undefined
|
|
211
|
+
? [
|
|
212
|
+
{
|
|
213
|
+
type: "thinking",
|
|
214
|
+
thinking: r.summary,
|
|
215
|
+
...(r.signature !== undefined && { signature: r.signature }),
|
|
216
|
+
},
|
|
217
|
+
]
|
|
218
|
+
: r.signature !== undefined
|
|
219
|
+
? [{ type: "redacted_thinking", data: r.signature }]
|
|
220
|
+
: []
|
|
221
|
+
return Result.succeed(blocks)
|
|
222
|
+
},
|
|
226
223
|
}),
|
|
227
|
-
Match.exhaustive,
|
|
228
224
|
)
|
|
229
225
|
|
|
230
|
-
|
|
226
|
+
type GroupAcc = {
|
|
231
227
|
readonly messages: ReadonlyArray<RequestMessage>
|
|
232
228
|
readonly currentRole: Option.Option<"user" | "assistant">
|
|
233
229
|
readonly userBuf: ReadonlyArray<RequestUserContentBlock>
|
|
@@ -320,12 +316,12 @@ const systemFromHistory = (history: ReadonlyArray<Items.Item>): Option.Option<st
|
|
|
320
316
|
return texts.length === 0 ? Option.none() : Option.some(texts.join("\n"))
|
|
321
317
|
}
|
|
322
318
|
|
|
323
|
-
export
|
|
319
|
+
export type ThinkingConfig = {
|
|
324
320
|
readonly type: "enabled"
|
|
325
321
|
readonly budget_tokens: number
|
|
326
322
|
}
|
|
327
323
|
|
|
328
|
-
export
|
|
324
|
+
export type RequestBody = {
|
|
329
325
|
readonly model: string
|
|
330
326
|
readonly messages: ReadonlyArray<RequestMessage>
|
|
331
327
|
readonly max_tokens: number
|
|
@@ -413,7 +409,7 @@ export const buildRequestBody = (params: {
|
|
|
413
409
|
// our `Items.Item[]` when `message_stop` lands.
|
|
414
410
|
// ---------------------------------------------------------------------------
|
|
415
411
|
|
|
416
|
-
|
|
412
|
+
type BlockBuffer = {
|
|
417
413
|
readonly type: WireContentBlock["type"]
|
|
418
414
|
readonly text: string
|
|
419
415
|
readonly inputJson: string
|
|
@@ -435,7 +431,7 @@ const emptyBlock = (type: WireContentBlock["type"]): BlockBuffer => ({
|
|
|
435
431
|
redactedData: Option.none(),
|
|
436
432
|
})
|
|
437
433
|
|
|
438
|
-
export
|
|
434
|
+
export type Accumulator = {
|
|
439
435
|
readonly blocks: Readonly<Record<number, BlockBuffer>>
|
|
440
436
|
readonly stopReason: Option.Option<string>
|
|
441
437
|
readonly usage: Items.Usage
|
|
@@ -460,23 +456,22 @@ const updateBlock = (
|
|
|
460
456
|
|
|
461
457
|
export const startBlock = (acc: Accumulator, index: number, block: WireContentBlock): Accumulator =>
|
|
462
458
|
Match.value(block).pipe(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
),
|
|
479
|
-
Match.exhaustive,
|
|
459
|
+
Match.discriminatorsExhaustive("type")({
|
|
460
|
+
text: () => replaceBlock(acc, index, emptyBlock("text")),
|
|
461
|
+
tool_use: (b) =>
|
|
462
|
+
replaceBlock(acc, index, {
|
|
463
|
+
...emptyBlock("tool_use"),
|
|
464
|
+
id: Option.some(b.id),
|
|
465
|
+
name: Option.some(b.name),
|
|
466
|
+
inputJson: typeof b.input === "string" ? b.input : "",
|
|
467
|
+
}),
|
|
468
|
+
thinking: () => replaceBlock(acc, index, emptyBlock("thinking")),
|
|
469
|
+
redacted_thinking: (b) =>
|
|
470
|
+
replaceBlock(acc, index, {
|
|
471
|
+
...emptyBlock("redacted_thinking"),
|
|
472
|
+
redactedData: Option.some(b.data),
|
|
473
|
+
}),
|
|
474
|
+
}),
|
|
480
475
|
)
|
|
481
476
|
|
|
482
477
|
export const appendTextDelta = (acc: Accumulator, index: number, text: string): Accumulator =>
|
|
@@ -596,7 +591,7 @@ const blockToItems = (block: BlockBuffer): ReadonlyArray<Items.Item> =>
|
|
|
596
591
|
Match.exhaustive,
|
|
597
592
|
)
|
|
598
593
|
|
|
599
|
-
|
|
594
|
+
type MergeAcc = {
|
|
600
595
|
readonly out: ReadonlyArray<Items.Item>
|
|
601
596
|
}
|
|
602
597
|
|
package/src/index.ts
CHANGED
package/src/streamEvents.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Match, Schema } from "effect"
|
|
2
|
-
import { matchType } from "@effect-uai/core/Match"
|
|
3
2
|
import {
|
|
4
3
|
type Accumulator,
|
|
5
4
|
WireContentBlock,
|
|
@@ -155,31 +154,34 @@ const mergeOptionalUsage = (acc: Accumulator, wire: WireUsage | undefined): Accu
|
|
|
155
154
|
|
|
156
155
|
export const applyEvent = (acc: Accumulator, event: ProviderEvent): Accumulator =>
|
|
157
156
|
Match.value(event).pipe(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
157
|
+
Match.discriminatorsExhaustive("type")({
|
|
158
|
+
message_start: (e) => mergeOptionalUsage(acc, e.message.usage),
|
|
159
|
+
content_block_start: (e) => startBlock(acc, e.index, e.content_block),
|
|
160
|
+
content_block_delta: (e) =>
|
|
161
|
+
Match.value(e.delta).pipe(
|
|
162
|
+
Match.discriminatorsExhaustive("type")({
|
|
163
|
+
text_delta: (d) => appendTextDelta(acc, e.index, d.text),
|
|
164
|
+
input_json_delta: (d) => appendInputJsonDelta(acc, e.index, d.partial_json),
|
|
165
|
+
thinking_delta: (d) => appendThinkingDelta(acc, e.index, d.thinking),
|
|
166
|
+
signature_delta: (d) => appendSignatureDelta(acc, e.index, d.signature),
|
|
167
|
+
}),
|
|
168
|
+
),
|
|
169
|
+
content_block_stop: () => acc,
|
|
170
|
+
message_delta: (e) => {
|
|
171
|
+
const withUsage = mergeOptionalUsage(acc, e.usage)
|
|
172
|
+
const reason = e.delta.stop_reason
|
|
173
|
+
return reason === undefined || reason === null
|
|
174
|
+
? withUsage
|
|
175
|
+
: setStopReason(withUsage, reason)
|
|
176
|
+
},
|
|
177
|
+
message_stop: () => acc,
|
|
178
|
+
ping: () => acc,
|
|
179
|
+
error: () => acc,
|
|
180
|
+
// No silent drops: unknown wire events flow through `streamNative` but
|
|
181
|
+
// produce no accumulator change. Step 3 (canonical `other` event) will
|
|
182
|
+
// also forward them to `TurnEvent`.
|
|
183
|
+
_unknown: () => acc,
|
|
174
184
|
}),
|
|
175
|
-
matchType("message_stop", () => acc),
|
|
176
|
-
matchType("ping", () => acc),
|
|
177
|
-
matchType("error", () => acc),
|
|
178
|
-
// No silent drops: unknown wire events flow through `streamNative` but
|
|
179
|
-
// produce no accumulator change. Step 3 (canonical `other` event) will
|
|
180
|
-
// also forward them to `TurnEvent`.
|
|
181
|
-
matchType("_unknown", () => acc),
|
|
182
|
-
Match.exhaustive,
|
|
183
185
|
)
|
|
184
186
|
|
|
185
187
|
// ---------------------------------------------------------------------------
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/codec.ts","../src/models.ts","../src/streamEvents.ts","../src/Anthropic.ts"],"mappings":";;;;;;;;;;;;cAkCa,gBAAA,EAAgB,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;;KAMjB,gBAAA,UAA0B,gBAAA,CAAiB,IAAA;AAAA,cAEjD,SAAA,EAAS,MAAA,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OE,WAAA,SACX,CAAA,EAAG,MAAA,CAAO,MAAA,CAAO,aAAA,EAAe,CAAA,EAAG,CAAA,MAClC,MAAA,CAAO,MAAA,CAAO,SAAA,EAAW,CAAA,EAAG,CAAA;;;;cAmBlB,IAAA,GAAQ,GAAA,EAAK,MAAA,KAAS,MAAA,CAAO,MAAA,CAAO,gBAAA,SAAyB,UAAA,CAAW,UAAA;;;;;;;;cAkBxE,KAAA,GACX,GAAA,EAAK,MAAA,KACJ,KAAA,CAAM,KAAA,CAAM,SAAA,GAAY,aAAA,SAAsB,UAAA,CAAW,UAAA"}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Arr"],"sources":["../src/codec.ts","../src/streamEvents.ts","../src/Anthropic.ts"],"sourcesContent":["import { Array as Arr, Match, Option, Order, Result, Schema, pipe } from \"effect\"\nimport * as Items from \"@effect-uai/core/Items\"\nimport { JsonParseError } from \"@effect-uai/core/JSONL\"\nimport { matchType } from \"@effect-uai/core/Match\"\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\ninterface RequestTextContent {\n readonly type: \"text\"\n readonly text: string\n}\n\ninterface RequestToolResultContent {\n readonly type: \"tool_result\"\n readonly tool_use_id: string\n readonly content: string\n}\n\ninterface RequestToolUseContent {\n readonly type: \"tool_use\"\n readonly id: string\n readonly name: string\n readonly input: unknown\n}\n\ninterface RequestThinkingContent {\n readonly type: \"thinking\"\n readonly thinking: string\n readonly signature?: string\n}\n\ninterface RequestRedactedThinkingContent {\n readonly type: \"redacted_thinking\"\n readonly data: string\n}\n\ninterface 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\ninterface RequestUserMessage {\n readonly role: \"user\"\n readonly content: ReadonlyArray<RequestUserContentBlock>\n}\n\ninterface 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 matchType(\"input_text\", (b) => b.text),\n matchType(\"input_image\", () => \"\"),\n matchType(\"output_text\", (b) => b.text),\n matchType(\"refusal\", (b) => b.text),\n Match.exhaustive,\n)\n\nconst messageText = (message: Items.Message): string => message.content.map(blockText).join(\"\")\n\nconst userContentBlock = (\n block: Items.ContentBlock,\n): Result.Result<RequestUserContentBlock, void> =>\n Match.value(block).pipe(\n matchType(\"input_text\", (b) =>\n b.text.length === 0\n ? Result.failVoid\n : Result.succeed({ type: \"text\" as const, text: b.text }),\n ),\n matchType(\"input_image\", (b) =>\n Result.succeed({\n type: \"image\" as const,\n source:\n b.source._tag === \"url\"\n ? { type: \"url\" as const, url: b.source.url }\n : {\n type: \"base64\" as const,\n media_type: b.source.media_type,\n data: b.source.data,\n },\n }),\n ),\n // Assistant content; never appears on a user message in practice. Skip.\n matchType(\"output_text\", () => Result.failVoid),\n matchType(\"refusal\", () => Result.failVoid),\n Match.exhaustive,\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 matchType(\"message\", (m) => m.role),\n matchType(\"function_call\", () => \"assistant\" as const),\n matchType(\"function_call_output\", () => \"user\" as const),\n matchType(\"reasoning\", () => \"assistant\" as const),\n Match.exhaustive,\n )\n\nconst itemToUserBlocks = (item: Items.Item): ReadonlyArray<RequestUserContentBlock> =>\n Match.value(item).pipe(\n matchType(\n \"message\",\n (m): ReadonlyArray<RequestUserContentBlock> =>\n m.role === \"user\" ? pipe(m.content, Arr.filterMap(userContentBlock)) : [],\n ),\n matchType(\"function_call\", (): ReadonlyArray<RequestUserContentBlock> => []),\n matchType(\n \"function_call_output\",\n (o): ReadonlyArray<RequestUserContentBlock> => [\n { type: \"tool_result\", tool_use_id: o.call_id, content: o.output },\n ],\n ),\n matchType(\"reasoning\", (): ReadonlyArray<RequestUserContentBlock> => []),\n Match.exhaustive,\n )\n\nconst itemToAssistantBlocks = (\n item: Items.Item,\n): Result.Result<ReadonlyArray<RequestAssistantContentBlock>, JsonParseError> =>\n Match.value(item).pipe(\n matchType(\n \"message\",\n (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 ),\n matchType(\"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 ),\n matchType(\n \"function_call_output\",\n (): Result.Result<ReadonlyArray<RequestAssistantContentBlock>, JsonParseError> =>\n Result.succeed([]),\n ),\n matchType(\"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 Match.exhaustive,\n )\n\ninterface 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 interface ThinkingConfig {\n readonly type: \"enabled\"\n readonly budget_tokens: number\n}\n\nexport interface 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\ninterface 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 interface 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 matchType(\"text\", () => replaceBlock(acc, index, emptyBlock(\"text\"))),\n matchType(\"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 ),\n matchType(\"thinking\", () => replaceBlock(acc, index, emptyBlock(\"thinking\"))),\n matchType(\"redacted_thinking\", (b) =>\n replaceBlock(acc, index, {\n ...emptyBlock(\"redacted_thinking\"),\n redactedData: Option.some(b.data),\n }),\n ),\n Match.exhaustive,\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\ninterface 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","import { Match, Schema } from \"effect\"\nimport { matchType } from \"@effect-uai/core/Match\"\nimport {\n type Accumulator,\n WireContentBlock,\n type WireUsage,\n appendInputJsonDelta,\n appendSignatureDelta,\n appendTextDelta,\n appendThinkingDelta,\n mergeUsage,\n setStopReason,\n startBlock,\n} from \"./codec.js\"\n\n// ---------------------------------------------------------------------------\n// Wire schemas for the SSE events we map onto our `Accumulator`. Anthropic's\n// streaming protocol uses named SSE events; we match on the inner JSON\n// `type` field which mirrors the event name.\n// ---------------------------------------------------------------------------\n\nconst WireMessageStartUsage = 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})\n\nconst MessageStart = Schema.Struct({\n type: Schema.Literal(\"message_start\"),\n message: Schema.Struct({\n id: Schema.optional(Schema.String),\n usage: Schema.optional(WireMessageStartUsage),\n }),\n})\n\nconst ContentBlockStart = Schema.Struct({\n type: Schema.Literal(\"content_block_start\"),\n index: Schema.Number,\n content_block: WireContentBlock,\n})\n\nconst TextDelta = Schema.Struct({\n type: Schema.Literal(\"text_delta\"),\n text: Schema.String,\n})\n\nconst InputJsonDelta = Schema.Struct({\n type: Schema.Literal(\"input_json_delta\"),\n partial_json: Schema.String,\n})\n\nconst ThinkingDelta = Schema.Struct({\n type: Schema.Literal(\"thinking_delta\"),\n thinking: Schema.String,\n})\n\nconst SignatureDelta = Schema.Struct({\n type: Schema.Literal(\"signature_delta\"),\n signature: Schema.String,\n})\n\nconst Delta = Schema.Union([TextDelta, InputJsonDelta, ThinkingDelta, SignatureDelta])\n\nconst ContentBlockDelta = Schema.Struct({\n type: Schema.Literal(\"content_block_delta\"),\n index: Schema.Number,\n delta: Delta,\n})\n\nconst ContentBlockStop = Schema.Struct({\n type: Schema.Literal(\"content_block_stop\"),\n index: Schema.Number,\n})\n\nconst MessageDelta = Schema.Struct({\n type: Schema.Literal(\"message_delta\"),\n delta: Schema.Struct({\n stop_reason: Schema.optional(Schema.NullOr(Schema.String)),\n stop_sequence: Schema.optional(Schema.NullOr(Schema.String)),\n }),\n usage: Schema.optional(WireMessageStartUsage),\n})\n\nconst MessageStop = Schema.Struct({\n type: Schema.Literal(\"message_stop\"),\n})\n\nconst Ping = Schema.Struct({\n type: Schema.Literal(\"ping\"),\n})\n\nconst ErrorEvent = Schema.Struct({\n type: Schema.Literal(\"error\"),\n error: Schema.optional(\n Schema.Struct({\n type: Schema.optional(Schema.String),\n message: Schema.optional(Schema.String),\n }),\n ),\n})\n\n/**\n * Catch-all variant for wire events that fail to decode against any known\n * schema, plus events that fail to JSON-parse. The decoder never produces\n * this directly - it's synthesized by `sseEventToProviderEvent` when\n * `decodeKnown` fails.\n */\nconst Unknown = Schema.Struct({\n type: Schema.Literal(\"_unknown\"),\n raw: Schema.Unknown,\n})\n\n/**\n * Internal: union of variants we actually know how to decode from the wire.\n * Used as the decode target; failures are caught and re-emitted as `Unknown`.\n */\nexport const KnownProviderEvent = Schema.Union([\n MessageStart,\n ContentBlockStart,\n ContentBlockDelta,\n ContentBlockStop,\n MessageDelta,\n MessageStop,\n Ping,\n ErrorEvent,\n])\n\n/**\n * Public: every event the native stream can emit. Discriminated on `type`.\n * The `_unknown` branch closes the cardinality so downstream `Match.exhaustive`\n * cannot silently miss a wire event we didn't model.\n */\nexport const ProviderEvent = Schema.Union([\n MessageStart,\n ContentBlockStart,\n ContentBlockDelta,\n ContentBlockStop,\n MessageDelta,\n MessageStop,\n Ping,\n ErrorEvent,\n Unknown,\n])\nexport type ProviderEvent = typeof ProviderEvent.Type\n\n// ---------------------------------------------------------------------------\n// Apply event → Accumulator. Pure: the mapping never fails. Caller wires\n// this into `Stream.mapAccum` and emits text/turn_complete deltas based on\n// the diff.\n// ---------------------------------------------------------------------------\n\nconst mergeOptionalUsage = (acc: Accumulator, wire: WireUsage | undefined): Accumulator =>\n wire === undefined ? acc : mergeUsage(acc, wire)\n\nexport const applyEvent = (acc: Accumulator, event: ProviderEvent): Accumulator =>\n Match.value(event).pipe(\n matchType(\"message_start\", (e) => mergeOptionalUsage(acc, e.message.usage)),\n matchType(\"content_block_start\", (e) => startBlock(acc, e.index, e.content_block)),\n matchType(\"content_block_delta\", (e) =>\n Match.value(e.delta).pipe(\n matchType(\"text_delta\", (d) => appendTextDelta(acc, e.index, d.text)),\n matchType(\"input_json_delta\", (d) => appendInputJsonDelta(acc, e.index, d.partial_json)),\n matchType(\"thinking_delta\", (d) => appendThinkingDelta(acc, e.index, d.thinking)),\n matchType(\"signature_delta\", (d) => appendSignatureDelta(acc, e.index, d.signature)),\n Match.exhaustive,\n ),\n ),\n matchType(\"content_block_stop\", () => acc),\n matchType(\"message_delta\", (e) => {\n const withUsage = mergeOptionalUsage(acc, e.usage)\n const reason = e.delta.stop_reason\n return reason === undefined || reason === null ? withUsage : setStopReason(withUsage, reason)\n }),\n matchType(\"message_stop\", () => acc),\n matchType(\"ping\", () => acc),\n matchType(\"error\", () => acc),\n // No silent drops: unknown wire events flow through `streamNative` but\n // produce no accumulator change. Step 3 (canonical `other` event) will\n // also forward them to `TurnEvent`.\n matchType(\"_unknown\", () => acc),\n Match.exhaustive,\n )\n\n// ---------------------------------------------------------------------------\n// Helpers for producing TurnEvent from a step.\n// ---------------------------------------------------------------------------\n\nexport const isTextDeltaEvent = (\n event: ProviderEvent,\n): event is Extract<\n ProviderEvent,\n { type: \"content_block_delta\"; delta: { type: \"text_delta\" } }\n> => event.type === \"content_block_delta\" && event.delta.type === \"text_delta\"\n\nexport const isThinkingDeltaEvent = (\n event: ProviderEvent,\n): event is Extract<\n ProviderEvent,\n { type: \"content_block_delta\"; delta: { type: \"thinking_delta\" } }\n> => event.type === \"content_block_delta\" && event.delta.type === \"thinking_delta\"\n\nexport const isInputJsonDeltaEvent = (\n event: ProviderEvent,\n): event is Extract<\n ProviderEvent,\n { type: \"content_block_delta\"; delta: { type: \"input_json_delta\" } }\n> => event.type === \"content_block_delta\" && event.delta.type === \"input_json_delta\"\n\nexport const isToolUseStartEvent = (\n event: ProviderEvent,\n): event is Extract<\n ProviderEvent,\n { type: \"content_block_start\"; content_block: { type: \"tool_use\" } }\n> => event.type === \"content_block_start\" && event.content_block.type === \"tool_use\"\n\nexport const isMessageStop = (event: ProviderEvent): boolean => event.type === \"message_stop\"\n\nexport const isErrorEvent = (\n event: ProviderEvent,\n): event is Extract<ProviderEvent, { type: \"error\" }> => event.type === \"error\"\n","import {\n Context,\n Effect,\n Layer,\n Match,\n Option,\n Redacted,\n Result,\n Schema,\n Stream,\n pipe,\n} from \"effect\"\nimport { HttpClient, HttpClientRequest } from \"effect/unstable/http\"\nimport * as AiError from \"@effect-uai/core/AiError\"\nimport {\n type CommonRequest,\n LanguageModel,\n type LanguageModelService,\n} from \"@effect-uai/core/LanguageModel\"\nimport { matchType } from \"@effect-uai/core/Match\"\nimport * as SSE from \"@effect-uai/core/SSE\"\nimport type { TurnEvent } from \"@effect-uai/core/Turn\"\nimport {\n type Accumulator,\n type ThinkingConfig,\n accumulatorToTurn,\n buildRequestBody,\n emptyAccumulator,\n} from \"./codec.js\"\nimport type { AnthropicModel } from \"./models.js\"\nimport { KnownProviderEvent, ProviderEvent, applyEvent } from \"./streamEvents.js\"\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface AnthropicRequest extends Omit<CommonRequest, \"model\"> {\n /**\n * Narrows `CommonRequest.model` (`string`) to the typed `AnthropicModel`\n * literal union for autocomplete.\n */\n readonly model: AnthropicModel\n /**\n * Top-K nucleus sampling parameter. Anthropic-specific; not exposed on the\n * common surface.\n */\n readonly topK?: number\n /** Stop sequences that abort generation when matched. */\n readonly stopSequences?: ReadonlyArray<string>\n /**\n * Extended thinking configuration. `0` budget is equivalent to disabled.\n * Only the `claude-sonnet-4-x`, `claude-haiku-4-x`, and pre-Opus-4.7\n * model lines support extended thinking.\n */\n readonly thinking?: ThinkingConfig\n /**\n * `metadata.user_id` on the wire. End-user tracking identifier.\n */\n readonly user?: string\n}\n\nexport interface AnthropicService {\n /**\n * Stream the provider's native event vocabulary (post-SSE-decode).\n * Use this when you need full vendor fidelity (e.g. `signature_delta` for\n * encrypted reasoning state). For provider-portable code, use `streamTurn`.\n */\n readonly streamNative: (\n request: AnthropicRequest,\n ) => Stream.Stream<ProviderEvent, AiError.AiError>\n /**\n * Stream canonical `TurnEvent`s. Implemented as\n * `streamNative |> toCanonical`.\n */\n readonly streamTurn: (request: AnthropicRequest) => Stream.Stream<TurnEvent, AiError.AiError>\n /**\n * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.\n * Stateful (threads an `Accumulator` for tool-call lookup and\n * accumulator-to-Turn assembly).\n */\n readonly toCanonical: <E, R>(\n s: Stream.Stream<ProviderEvent, E, R>,\n ) => Stream.Stream<TurnEvent, E, R>\n}\n\n/**\n * Provider-typed service tag. Yield this when you want Anthropic-specific\n * options (`topK`, `stopSequences`, `thinking`); yield the generic\n * `LanguageModel` tag for provider-portable code. Both are registered by\n * `layer`.\n */\nexport class Anthropic extends Context.Service<Anthropic, AnthropicService>()(\n \"@betalyra/effect-uai/providers/anthropic/Anthropic\",\n) {}\n\nexport interface Config {\n readonly apiKey: Redacted.Redacted\n readonly baseUrl?: string\n /**\n * Default `max_tokens` for requests that don't override via\n * `request.maxOutputTokens`. Anthropic requires this field; we default to\n * 4096 if neither is set.\n */\n readonly defaultMaxTokens?: number\n}\n\nconst ANTHROPIC_VERSION = \"2023-06-01\"\nconst STRUCTURED_OUTPUTS_BETA = \"structured-outputs-2025-11-13\"\nconst FALLBACK_MAX_TOKENS = 4096\n\nconst outputConfig = (request: AnthropicRequest): Option.Option<Record<string, unknown>> =>\n pipe(\n Option.fromUndefinedOr(request.structured),\n Option.map((format) => ({\n format: {\n type: \"json_schema\",\n schema: format.schema[\"~standard\"].jsonSchema.input({ target: \"draft-2020-12\" }),\n },\n })),\n )\n\nconst resolvedMaxTokens = (cfg: Config, request: AnthropicRequest): number =>\n request.maxOutputTokens ?? cfg.defaultMaxTokens ?? FALLBACK_MAX_TOKENS\n\nconst toolDescriptors = (\n request: AnthropicRequest,\n): Option.Option<ReadonlyArray<Record<string, unknown>>> =>\n request.tools !== undefined && request.tools.length > 0\n ? Option.some(\n request.tools.map((t) => ({\n name: t.name,\n description: t.description,\n input_schema: t.inputSchema,\n })),\n )\n : Option.none()\n\nconst toolChoiceWire = (request: AnthropicRequest): Option.Option<Record<string, unknown>> =>\n pipe(\n Option.fromUndefinedOr(request.toolChoice),\n Option.map((choice) =>\n choice === \"auto\"\n ? { type: \"auto\" }\n : choice === \"required\"\n ? { type: \"any\" }\n : choice === \"none\"\n ? { type: \"none\" }\n : { type: \"tool\", name: choice.name },\n ),\n )\n\n// ---------------------------------------------------------------------------\n// SSE event → ProviderEvent\n// ---------------------------------------------------------------------------\n\nconst decodeKnown = Schema.decodeUnknownEffect(KnownProviderEvent)\n\nconst makeUnknown = (raw: unknown): ProviderEvent => ({ type: \"_unknown\", raw })\n\n/**\n * Parse one SSE event's `data` payload into a typed `ProviderEvent`. Never\n * fails: JSON-parse and schema-decode failures both produce a synthesized\n * `_unknown` event so consumers of `streamNative` never silently miss a\n * wire event we didn't model.\n */\nconst sseEventToProviderEvent = (ev: SSE.Event): Effect.Effect<ProviderEvent> =>\n Effect.try({\n try: () => JSON.parse(ev.data) as unknown,\n catch: () => ev.data,\n }).pipe(\n Effect.flatMap((parsed) =>\n decodeKnown(parsed).pipe(Effect.orElseSucceed(() => makeUnknown(parsed))),\n ),\n Effect.orElseSucceed(() => makeUnknown(ev.data)),\n )\n\n// ---------------------------------------------------------------------------\n// Per-event derivation of TurnEvents. Drives off the new accumulator and the\n// raw event, since some deltas (`tool_call_args_delta`) need the call_id\n// which lives on the accumulator's per-index block.\n// ---------------------------------------------------------------------------\n\nconst deltasFromEvent = (next: Accumulator, event: ProviderEvent): ReadonlyArray<TurnEvent> =>\n Match.value(event).pipe(\n matchType(\"content_block_start\", (e) =>\n e.content_block.type === \"tool_use\"\n ? [\n {\n type: \"tool_call_start\" as const,\n call_id: e.content_block.id,\n name: e.content_block.name,\n },\n ]\n : [],\n ),\n matchType(\"content_block_delta\", (e) =>\n Match.value(e.delta).pipe(\n matchType(\"text_delta\", (d) => [{ type: \"text_delta\" as const, text: d.text }]),\n matchType(\"thinking_delta\", (d) => [\n { type: \"reasoning_delta\" as const, text: d.thinking, kind: \"trace\" as const },\n ]),\n matchType(\"input_json_delta\", (d) => {\n const block = next.blocks[e.index]\n if (block === undefined) return []\n const callId = Option.getOrElse(block.id, () => \"\")\n return callId.length === 0\n ? []\n : [\n {\n type: \"tool_call_args_delta\" as const,\n call_id: callId,\n delta: d.partial_json,\n },\n ]\n }),\n // Encrypted reasoning state - flows through `streamNative` but has\n // no canonical representation.\n matchType(\"signature_delta\", () => []),\n Match.exhaustive,\n ),\n ),\n matchType(\"message_start\", (e) =>\n e.message.usage === undefined ? [] : [{ type: \"usage_update\" as const, usage: next.usage }],\n ),\n matchType(\"message_delta\", (e) =>\n e.usage === undefined ? [] : [{ type: \"usage_update\" as const, usage: next.usage }],\n ),\n matchType(\"message_stop\", () => [\n { type: \"turn_complete\" as const, turn: accumulatorToTurn(next) },\n ]),\n matchType(\"content_block_stop\", () => []),\n matchType(\"ping\", () => []),\n matchType(\"error\", () => []),\n matchType(\"_unknown\", () => []),\n Match.exhaustive,\n )\n\n// ---------------------------------------------------------------------------\n// Service implementation\n// ---------------------------------------------------------------------------\n\nconst httpStatusError = (status: number, body: string): AiError.AiError => {\n const provider = \"anthropic\"\n const raw = body\n if (status === 429) return new AiError.RateLimited({ provider, raw })\n if (status === 408 || status === 504) return new AiError.Timeout({ provider, raw })\n if (status === 401) return new AiError.AuthFailed({ provider, subtype: \"auth\", raw })\n if (status === 403) return new AiError.AuthFailed({ provider, subtype: \"permission\", raw })\n if (status === 402) return new AiError.AuthFailed({ provider, subtype: \"billing\", raw })\n if (status === 413) return new AiError.ContextLengthExceeded({ provider, raw })\n if (status === 529) return new AiError.Unavailable({ provider, status, raw })\n if (status >= 500) return new AiError.Unavailable({ provider, status, raw })\n return new AiError.InvalidRequest({ provider, raw })\n}\n\nconst buildNativeStream = (cfg: Config) => {\n const baseUrl = cfg.baseUrl ?? \"https://api.anthropic.com\"\n const url = `${baseUrl}/v1/messages`\n return (\n request: AnthropicRequest,\n ): Stream.Stream<ProviderEvent, AiError.AiError, HttpClient.HttpClient> =>\n Stream.unwrap(\n Effect.gen(function* () {\n const structured = outputConfig(request)\n const bodyResult = buildRequestBody({\n model: request.model,\n history: request.history,\n maxTokens: resolvedMaxTokens(cfg, request),\n temperature: Option.fromUndefinedOr(request.temperature),\n topP: Option.fromUndefinedOr(request.topP),\n topK: Option.fromUndefinedOr(request.topK),\n stopSequences: Option.fromUndefinedOr(request.stopSequences),\n thinking: Option.fromUndefinedOr(request.thinking),\n tools: toolDescriptors(request),\n toolChoice: toolChoiceWire(request),\n userId: Option.fromUndefinedOr(request.user),\n outputConfig: structured,\n })\n\n const body = yield* Result.match(bodyResult, {\n onFailure: (cause) =>\n Effect.fail(\n new AiError.InvalidRequest({\n provider: \"anthropic\",\n param: \"input.function_call.arguments\",\n raw: cause,\n }),\n ),\n onSuccess: (b) => Effect.succeed(b),\n })\n\n const client = yield* HttpClient.HttpClient\n const baseRequest = HttpClientRequest.post(url).pipe(\n HttpClientRequest.setHeader(\"x-api-key\", Redacted.value(cfg.apiKey)),\n HttpClientRequest.setHeader(\"anthropic-version\", ANTHROPIC_VERSION),\n HttpClientRequest.bodyJsonUnsafe(body),\n HttpClientRequest.accept(\"text/event-stream\"),\n )\n const httpRequest = Option.isSome(structured)\n ? baseRequest.pipe(HttpClientRequest.setHeader(\"anthropic-beta\", STRUCTURED_OUTPUTS_BETA))\n : baseRequest\n const response = yield* client\n .execute(httpRequest)\n .pipe(\n Effect.mapError(\n (cause): AiError.AiError =>\n new AiError.Unavailable({ provider: \"anthropic\", raw: cause }),\n ),\n )\n if (response.status >= 400) {\n const text = yield* response.text.pipe(Effect.orElseSucceed(() => \"\"))\n return Stream.fail(httpStatusError(response.status, text))\n }\n\n return response.stream.pipe(\n Stream.mapError(\n (cause): AiError.AiError =>\n new AiError.Unavailable({ provider: \"anthropic\", raw: cause }),\n ),\n SSE.fromBytes,\n Stream.mapEffect(sseEventToProviderEvent),\n Stream.flatMap((event) =>\n event.type === \"error\"\n ? Stream.fail(new AiError.Unavailable({ provider: \"anthropic\", raw: event }))\n : Stream.succeed(event),\n ),\n )\n }),\n )\n}\n\n/**\n * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.\n * Threads a fresh `Accumulator` per stream so tool-call lookup and\n * `accumulatorToTurn` assembly work correctly across the run.\n */\nexport const toCanonical = <E, R>(\n s: Stream.Stream<ProviderEvent, E, R>,\n): Stream.Stream<TurnEvent, E, R> =>\n s.pipe(\n Stream.mapAccum(\n () => emptyAccumulator,\n (acc, event) => {\n const next = applyEvent(acc, event)\n const deltas = deltasFromEvent(next, event)\n return [next, deltas] as const\n },\n ),\n )\n\n// ---------------------------------------------------------------------------\n// Constructors\n// ---------------------------------------------------------------------------\n\n/**\n * Build an `AnthropicService` value. For Layer-based setup, prefer `layer`.\n */\nexport const make = (cfg: Config): Effect.Effect<AnthropicService, never, HttpClient.HttpClient> =>\n Effect.map(HttpClient.HttpClient.asEffect(), (client) => {\n const streamNative: AnthropicService[\"streamNative\"] = (request) =>\n buildNativeStream(cfg)(request).pipe(Stream.provideService(HttpClient.HttpClient, client))\n return {\n streamNative,\n streamTurn: (request) => toCanonical(streamNative(request)),\n toCanonical,\n }\n })\n\n/**\n * Layer that registers both the provider-specific `Anthropic` tag and the\n * generic `LanguageModel` tag, sharing one underlying implementation.\n *\n * The generic tag accepts `CommonRequest`; the typed tag accepts the full\n * `AnthropicRequest` surface.\n */\nexport const layer = (\n cfg: Config,\n): Layer.Layer<Anthropic | LanguageModel, never, HttpClient.HttpClient> => {\n const typed = Layer.effect(Anthropic, make(cfg))\n const generic = Layer.effect(\n LanguageModel,\n Effect.map(\n make(cfg),\n (s): LanguageModelService => ({\n streamTurn: (request) => s.streamTurn(request as AnthropicRequest),\n }),\n ),\n )\n return Layer.merge(typed, generic)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWA,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,UAAU,eAAe,MAAM,EAAE,KAAK,EACtC,UAAU,qBAAqB,GAAG,EAClC,UAAU,gBAAgB,MAAM,EAAE,KAAK,EACvC,U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