@effect/ai-anthropic 0.4.1 → 0.5.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/AnthropicLanguageModel/package.json +6 -0
- package/dist/cjs/AnthropicClient.js +128 -96
- package/dist/cjs/AnthropicClient.js.map +1 -1
- package/dist/cjs/AnthropicConfig.js +2 -2
- package/dist/cjs/AnthropicConfig.js.map +1 -1
- package/dist/cjs/AnthropicLanguageModel.js +496 -0
- package/dist/cjs/AnthropicLanguageModel.js.map +1 -0
- package/dist/cjs/AnthropicTokenizer.js +7 -10
- package/dist/cjs/AnthropicTokenizer.js.map +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/internal/utilities.js +24 -0
- package/dist/cjs/internal/utilities.js.map +1 -0
- package/dist/dts/AnthropicClient.d.ts +9 -64
- package/dist/dts/AnthropicClient.d.ts.map +1 -1
- package/dist/dts/AnthropicConfig.d.ts +5 -6
- package/dist/dts/AnthropicConfig.d.ts.map +1 -1
- package/dist/dts/{AnthropicCompletions.d.ts → AnthropicLanguageModel.d.ts} +30 -22
- package/dist/dts/AnthropicLanguageModel.d.ts.map +1 -0
- package/dist/dts/AnthropicTokenizer.d.ts +2 -2
- package/dist/dts/AnthropicTokenizer.d.ts.map +1 -1
- package/dist/dts/index.d.ts +2 -2
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/utilities.d.ts +2 -0
- package/dist/dts/internal/utilities.d.ts.map +1 -0
- package/dist/esm/AnthropicClient.js +127 -94
- package/dist/esm/AnthropicClient.js.map +1 -1
- package/dist/esm/AnthropicConfig.js +2 -2
- package/dist/esm/AnthropicConfig.js.map +1 -1
- package/dist/esm/AnthropicLanguageModel.js +484 -0
- package/dist/esm/AnthropicLanguageModel.js.map +1 -0
- package/dist/esm/AnthropicTokenizer.js +7 -10
- package/dist/esm/AnthropicTokenizer.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/utilities.js +15 -0
- package/dist/esm/internal/utilities.js.map +1 -0
- package/package.json +10 -10
- package/src/AnthropicClient.ts +197 -162
- package/src/AnthropicConfig.ts +7 -8
- package/src/AnthropicLanguageModel.ts +591 -0
- package/src/AnthropicTokenizer.ts +31 -19
- package/src/index.ts +2 -2
- package/src/internal/utilities.ts +18 -0
- package/AnthropicCompletions/package.json +0 -6
- package/dist/cjs/AnthropicCompletions.js +0 -358
- package/dist/cjs/AnthropicCompletions.js.map +0 -1
- package/dist/dts/AnthropicCompletions.d.ts.map +0 -1
- package/dist/esm/AnthropicCompletions.js +0 -345
- package/dist/esm/AnthropicCompletions.js.map +0 -1
- package/src/AnthropicCompletions.ts +0 -468
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/ai-anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Effect modules for working with AI apis",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@anthropic-ai/tokenizer": "^0.0.4"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@effect/ai": "^0.
|
|
17
|
+
"@effect/ai": "^0.15.0",
|
|
18
18
|
"@effect/experimental": "^0.45.1",
|
|
19
19
|
"@effect/platform": "^0.81.1",
|
|
20
20
|
"effect": "^3.14.22"
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
"import": "./dist/esm/AnthropicClient.js",
|
|
38
38
|
"default": "./dist/cjs/AnthropicClient.js"
|
|
39
39
|
},
|
|
40
|
-
"./AnthropicCompletions": {
|
|
41
|
-
"types": "./dist/dts/AnthropicCompletions.d.ts",
|
|
42
|
-
"import": "./dist/esm/AnthropicCompletions.js",
|
|
43
|
-
"default": "./dist/cjs/AnthropicCompletions.js"
|
|
44
|
-
},
|
|
45
40
|
"./AnthropicConfig": {
|
|
46
41
|
"types": "./dist/dts/AnthropicConfig.d.ts",
|
|
47
42
|
"import": "./dist/esm/AnthropicConfig.js",
|
|
48
43
|
"default": "./dist/cjs/AnthropicConfig.js"
|
|
49
44
|
},
|
|
45
|
+
"./AnthropicLanguageModel": {
|
|
46
|
+
"types": "./dist/dts/AnthropicLanguageModel.d.ts",
|
|
47
|
+
"import": "./dist/esm/AnthropicLanguageModel.js",
|
|
48
|
+
"default": "./dist/cjs/AnthropicLanguageModel.js"
|
|
49
|
+
},
|
|
50
50
|
"./AnthropicTokenizer": {
|
|
51
51
|
"types": "./dist/dts/AnthropicTokenizer.d.ts",
|
|
52
52
|
"import": "./dist/esm/AnthropicTokenizer.js",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"AnthropicClient": [
|
|
69
69
|
"./dist/dts/AnthropicClient.d.ts"
|
|
70
70
|
],
|
|
71
|
-
"AnthropicCompletions": [
|
|
72
|
-
"./dist/dts/AnthropicCompletions.d.ts"
|
|
73
|
-
],
|
|
74
71
|
"AnthropicConfig": [
|
|
75
72
|
"./dist/dts/AnthropicConfig.d.ts"
|
|
76
73
|
],
|
|
74
|
+
"AnthropicLanguageModel": [
|
|
75
|
+
"./dist/dts/AnthropicLanguageModel.d.ts"
|
|
76
|
+
],
|
|
77
77
|
"AnthropicTokenizer": [
|
|
78
78
|
"./dist/dts/AnthropicTokenizer.d.ts"
|
|
79
79
|
],
|
package/src/AnthropicClient.ts
CHANGED
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
import * as AiError from "@effect/ai/AiError"
|
|
5
|
-
import * as
|
|
5
|
+
import * as AiInput from "@effect/ai/AiInput"
|
|
6
6
|
import * as AiResponse from "@effect/ai/AiResponse"
|
|
7
|
-
import * as AiRole from "@effect/ai/AiRole"
|
|
8
7
|
import * as Sse from "@effect/experimental/Sse"
|
|
9
8
|
import * as HttpBody from "@effect/platform/HttpBody"
|
|
10
9
|
import * as HttpClient from "@effect/platform/HttpClient"
|
|
11
10
|
import type * as HttpClientError from "@effect/platform/HttpClientError"
|
|
12
11
|
import * as HttpClientRequest from "@effect/platform/HttpClientRequest"
|
|
13
|
-
import * as Chunk from "effect/Chunk"
|
|
14
12
|
import * as Config from "effect/Config"
|
|
15
13
|
import type { ConfigError } from "effect/ConfigError"
|
|
16
14
|
import * as Context from "effect/Context"
|
|
17
|
-
import * as Data from "effect/Data"
|
|
18
15
|
import * as Effect from "effect/Effect"
|
|
19
16
|
import { identity } from "effect/Function"
|
|
20
17
|
import * as Layer from "effect/Layer"
|
|
21
18
|
import * as Option from "effect/Option"
|
|
19
|
+
import * as Predicate from "effect/Predicate"
|
|
22
20
|
import * as Redacted from "effect/Redacted"
|
|
23
21
|
import * as Stream from "effect/Stream"
|
|
24
|
-
import type { Mutable } from "effect/Types"
|
|
25
22
|
import { AnthropicConfig } from "./AnthropicConfig.js"
|
|
26
23
|
import * as Generated from "./Generated.js"
|
|
24
|
+
import * as InternalUtilities from "./internal/utilities.js"
|
|
25
|
+
|
|
26
|
+
const constDisableValidation = { disableValidation: true } as const
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* @since 1.0.0
|
|
30
|
-
* @category
|
|
30
|
+
* @category Context
|
|
31
31
|
*/
|
|
32
32
|
export class AnthropicClient extends Context.Tag(
|
|
33
33
|
"@effect/ai-openai/AnthropicClient"
|
|
@@ -35,12 +35,11 @@ export class AnthropicClient extends Context.Tag(
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @since 1.0.0
|
|
38
|
-
* @category models
|
|
39
38
|
*/
|
|
40
39
|
export declare namespace AnthropicClient {
|
|
41
40
|
/**
|
|
42
41
|
* @since 1.0.0
|
|
43
|
-
* @category
|
|
42
|
+
* @category Models
|
|
44
43
|
*/
|
|
45
44
|
export interface Service {
|
|
46
45
|
readonly client: Generated.Client
|
|
@@ -49,13 +48,13 @@ export declare namespace AnthropicClient {
|
|
|
49
48
|
) => Stream.Stream<A, HttpClientError.HttpClientError>
|
|
50
49
|
readonly stream: (
|
|
51
50
|
request: StreamCompletionRequest
|
|
52
|
-
) => Stream.Stream<
|
|
51
|
+
) => Stream.Stream<AiResponse.AiResponse, HttpClientError.HttpClientError>
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
/**
|
|
57
56
|
* @since 1.0.0
|
|
58
|
-
* @category
|
|
57
|
+
* @category Constructors
|
|
59
58
|
*/
|
|
60
59
|
export const make = (options: {
|
|
61
60
|
readonly apiKey?: Redacted.Redacted | undefined
|
|
@@ -71,9 +70,19 @@ export const make = (options: {
|
|
|
71
70
|
const httpClient = (yield* HttpClient.HttpClient).pipe(
|
|
72
71
|
HttpClient.mapRequest((request) =>
|
|
73
72
|
request.pipe(
|
|
74
|
-
HttpClientRequest.prependUrl(
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
HttpClientRequest.prependUrl(
|
|
74
|
+
options.apiUrl ?? "https://api.anthropic.com"
|
|
75
|
+
),
|
|
76
|
+
options.apiKey
|
|
77
|
+
? HttpClientRequest.setHeader(
|
|
78
|
+
"x-api-key",
|
|
79
|
+
Redacted.value(options.apiKey)
|
|
80
|
+
)
|
|
81
|
+
: identity,
|
|
82
|
+
HttpClientRequest.setHeader(
|
|
83
|
+
"anthropic-version",
|
|
84
|
+
options.anthropicVersion ?? "2023-06-01"
|
|
85
|
+
),
|
|
77
86
|
HttpClientRequest.acceptJson
|
|
78
87
|
)
|
|
79
88
|
),
|
|
@@ -99,100 +108,195 @@ export const make = (options: {
|
|
|
99
108
|
)
|
|
100
109
|
const stream = (request: StreamCompletionRequest) =>
|
|
101
110
|
Stream.suspend(() => {
|
|
102
|
-
const
|
|
111
|
+
const toolCalls = {} as Record<number, RawToolCall>
|
|
112
|
+
let finishReason: AiResponse.FinishReason = "unknown"
|
|
113
|
+
let reasoning:
|
|
114
|
+
| {
|
|
115
|
+
readonly content: Array<string>
|
|
116
|
+
readonly signature?: string
|
|
117
|
+
}
|
|
118
|
+
| undefined = undefined
|
|
119
|
+
let usage: AiResponse.Usage = {
|
|
120
|
+
inputTokens: 0,
|
|
121
|
+
outputTokens: 0,
|
|
122
|
+
totalTokens: 0,
|
|
123
|
+
reasoningTokens: 0,
|
|
124
|
+
cacheReadInputTokens: 0,
|
|
125
|
+
cacheWriteInputTokens: 0
|
|
126
|
+
}
|
|
127
|
+
const metadata: Record<string, unknown> = {}
|
|
103
128
|
return streamRequest<MessageStreamEvent>(
|
|
104
129
|
HttpClientRequest.post("/v1/messages", {
|
|
105
130
|
body: HttpBody.unsafeJson({ ...request, stream: true })
|
|
106
131
|
})
|
|
107
132
|
).pipe(
|
|
108
|
-
Stream.
|
|
109
|
-
const parts: Array<
|
|
133
|
+
Stream.filterMapEffect((chunk) => {
|
|
134
|
+
const parts: Array<AiResponse.Part> = []
|
|
110
135
|
switch (chunk.type) {
|
|
111
136
|
case "message_start": {
|
|
112
|
-
usage
|
|
113
|
-
|
|
114
|
-
|
|
137
|
+
usage = {
|
|
138
|
+
inputTokens: chunk.message.usage.input_tokens,
|
|
139
|
+
outputTokens: chunk.message.usage.output_tokens,
|
|
140
|
+
totalTokens: chunk.message.usage.input_tokens +
|
|
141
|
+
chunk.message.usage.output_tokens,
|
|
142
|
+
reasoningTokens: 0,
|
|
143
|
+
cacheWriteInputTokens: chunk.message.usage.cache_creation_input_tokens ?? 0,
|
|
144
|
+
cacheReadInputTokens: chunk.message.usage.cache_read_input_tokens ?? 0
|
|
145
|
+
}
|
|
146
|
+
parts.push(
|
|
147
|
+
new AiResponse.MetadataPart(
|
|
148
|
+
{
|
|
149
|
+
id: chunk.message.id,
|
|
150
|
+
model: chunk.message.model
|
|
151
|
+
},
|
|
152
|
+
constDisableValidation
|
|
153
|
+
)
|
|
154
|
+
)
|
|
115
155
|
break
|
|
116
156
|
}
|
|
117
157
|
case "message_delta": {
|
|
118
|
-
usage
|
|
119
|
-
|
|
120
|
-
|
|
158
|
+
usage = {
|
|
159
|
+
...usage,
|
|
160
|
+
outputTokens: chunk.usage.output_tokens
|
|
161
|
+
}
|
|
162
|
+
if (Predicate.isNotNullable(chunk.delta.stop_sequence)) {
|
|
163
|
+
metadata.stopSequence = chunk.delta.stop_sequence
|
|
164
|
+
}
|
|
165
|
+
finishReason = InternalUtilities.resolveFinishReason(chunk.delta.stop_reason)
|
|
121
166
|
break
|
|
122
167
|
}
|
|
123
168
|
case "message_stop": {
|
|
169
|
+
parts.push(
|
|
170
|
+
new AiResponse.FinishPart({
|
|
171
|
+
usage,
|
|
172
|
+
reason: finishReason,
|
|
173
|
+
providerMetadata: { [InternalUtilities.ProviderMetadataKey]: metadata }
|
|
174
|
+
}, constDisableValidation)
|
|
175
|
+
)
|
|
124
176
|
break
|
|
125
177
|
}
|
|
126
178
|
case "content_block_start": {
|
|
127
179
|
const content = chunk.content_block
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
180
|
+
switch (content.type) {
|
|
181
|
+
case "text": {
|
|
182
|
+
break
|
|
183
|
+
}
|
|
184
|
+
case "thinking": {
|
|
185
|
+
reasoning = { content: [content.thinking] }
|
|
186
|
+
break
|
|
187
|
+
}
|
|
188
|
+
case "tool_use": {
|
|
189
|
+
toolCalls[chunk.index] = {
|
|
190
|
+
id: content.id,
|
|
191
|
+
name: content.name,
|
|
192
|
+
params: ""
|
|
193
|
+
}
|
|
194
|
+
break
|
|
195
|
+
}
|
|
196
|
+
case "redacted_thinking": {
|
|
197
|
+
parts.push(
|
|
198
|
+
new AiResponse.RedactedReasoningPart(
|
|
199
|
+
{ redactedText: content.data },
|
|
200
|
+
constDisableValidation
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
break
|
|
204
|
+
}
|
|
135
205
|
}
|
|
136
206
|
break
|
|
137
207
|
}
|
|
138
208
|
case "content_block_delta": {
|
|
139
209
|
switch (chunk.delta.type) {
|
|
140
|
-
|
|
141
|
-
|
|
210
|
+
case "text_delta": {
|
|
211
|
+
parts.push(
|
|
212
|
+
new AiResponse.TextPart(
|
|
213
|
+
{ text: chunk.delta.text },
|
|
214
|
+
constDisableValidation
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
break
|
|
218
|
+
}
|
|
219
|
+
case "thinking_delta": {
|
|
220
|
+
if (Predicate.isNotUndefined(reasoning)) {
|
|
221
|
+
reasoning.content.push(chunk.delta.thinking)
|
|
222
|
+
}
|
|
223
|
+
break
|
|
224
|
+
}
|
|
225
|
+
case "signature_delta": {
|
|
226
|
+
if (Predicate.isNotUndefined(reasoning)) {
|
|
227
|
+
reasoning = {
|
|
228
|
+
...reasoning,
|
|
229
|
+
signature: chunk.delta.signature
|
|
230
|
+
}
|
|
231
|
+
}
|
|
142
232
|
break
|
|
143
233
|
}
|
|
144
234
|
case "input_json_delta": {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
})
|
|
235
|
+
const tool = toolCalls[chunk.index]
|
|
236
|
+
if (Predicate.isNotUndefined(tool)) {
|
|
237
|
+
tool.params += chunk.delta.partial_json
|
|
238
|
+
}
|
|
150
239
|
break
|
|
151
240
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
_tag: "Content",
|
|
155
|
-
content: chunk.delta.text
|
|
156
|
-
})
|
|
241
|
+
// TODO: add support for citations (?)
|
|
242
|
+
case "citations_delta": {
|
|
157
243
|
break
|
|
158
244
|
}
|
|
159
245
|
}
|
|
160
246
|
break
|
|
161
247
|
}
|
|
162
248
|
case "content_block_stop": {
|
|
163
|
-
if (
|
|
164
|
-
const
|
|
249
|
+
if (Predicate.isNotUndefined(toolCalls[chunk.index])) {
|
|
250
|
+
const tool = toolCalls[chunk.index]
|
|
165
251
|
try {
|
|
166
|
-
const
|
|
167
|
-
parts.push(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
252
|
+
const params = JSON.parse(tool.params)
|
|
253
|
+
parts.push(
|
|
254
|
+
new AiResponse.ToolCallPart({
|
|
255
|
+
id: AiInput.ToolCallId.make(tool.id),
|
|
256
|
+
name: tool.name,
|
|
257
|
+
params
|
|
258
|
+
}, constDisableValidation)
|
|
259
|
+
)
|
|
260
|
+
delete toolCalls[chunk.index]
|
|
173
261
|
// eslint-disable-next-line no-empty
|
|
174
262
|
} catch {}
|
|
175
263
|
}
|
|
264
|
+
if (Predicate.isNotUndefined(reasoning)) {
|
|
265
|
+
parts.push(
|
|
266
|
+
new AiResponse.ReasoningPart({
|
|
267
|
+
reasoningText: reasoning.content.join(""),
|
|
268
|
+
signature: reasoning.signature
|
|
269
|
+
}, constDisableValidation)
|
|
270
|
+
)
|
|
271
|
+
reasoning = undefined
|
|
272
|
+
}
|
|
176
273
|
break
|
|
177
274
|
}
|
|
178
275
|
case "error": {
|
|
179
|
-
return
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
276
|
+
return Option.some(
|
|
277
|
+
Effect.die(
|
|
278
|
+
new AiError.AiError({
|
|
279
|
+
module: "AnthropicClient",
|
|
280
|
+
method: "stream",
|
|
281
|
+
description: `${chunk.error.type}: ${chunk.error.message}`
|
|
282
|
+
})
|
|
283
|
+
)
|
|
185
284
|
)
|
|
186
285
|
}
|
|
187
286
|
}
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
287
|
+
return parts.length === 0
|
|
288
|
+
? Option.none()
|
|
289
|
+
: Option.some(
|
|
290
|
+
Effect.succeed(
|
|
291
|
+
AiResponse.AiResponse.make(
|
|
292
|
+
{
|
|
293
|
+
parts
|
|
294
|
+
},
|
|
295
|
+
constDisableValidation
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
)
|
|
299
|
+
})
|
|
196
300
|
)
|
|
197
301
|
})
|
|
198
302
|
return AnthropicClient.of({ client, streamRequest, stream })
|
|
@@ -200,7 +304,7 @@ export const make = (options: {
|
|
|
200
304
|
|
|
201
305
|
/**
|
|
202
306
|
* @since 1.0.0
|
|
203
|
-
* @category
|
|
307
|
+
* @category Layers
|
|
204
308
|
*/
|
|
205
309
|
export const layer = (options: {
|
|
206
310
|
readonly apiKey?: Redacted.Redacted | undefined
|
|
@@ -209,15 +313,15 @@ export const layer = (options: {
|
|
|
209
313
|
readonly transformClient?: (
|
|
210
314
|
client: HttpClient.HttpClient
|
|
211
315
|
) => HttpClient.HttpClient
|
|
212
|
-
}): Layer.Layer<
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
316
|
+
}): Layer.Layer<
|
|
317
|
+
AnthropicClient,
|
|
318
|
+
never,
|
|
319
|
+
HttpClient.HttpClient
|
|
320
|
+
> => Layer.effect(AnthropicClient, make(options))
|
|
217
321
|
|
|
218
322
|
/**
|
|
219
323
|
* @since 1.0.0
|
|
220
|
-
* @category
|
|
324
|
+
* @category Layers
|
|
221
325
|
*/
|
|
222
326
|
export const layerConfig = (
|
|
223
327
|
options: Config.Config.Wrap<{
|
|
@@ -228,16 +332,19 @@ export const layerConfig = (
|
|
|
228
332
|
client: HttpClient.HttpClient
|
|
229
333
|
) => HttpClient.HttpClient
|
|
230
334
|
}>
|
|
231
|
-
): Layer.Layer<
|
|
335
|
+
): Layer.Layer<
|
|
336
|
+
AnthropicClient,
|
|
337
|
+
ConfigError,
|
|
338
|
+
HttpClient.HttpClient
|
|
339
|
+
> =>
|
|
232
340
|
Config.unwrap(options).pipe(
|
|
233
341
|
Effect.flatMap(make),
|
|
234
|
-
Layer.effect(AnthropicClient)
|
|
235
|
-
Layer.merge(AiModels.layer)
|
|
342
|
+
Layer.effect(AnthropicClient)
|
|
236
343
|
)
|
|
237
344
|
|
|
238
345
|
/**
|
|
239
346
|
* @since 1.0.0
|
|
240
|
-
* @category
|
|
347
|
+
* @category Models
|
|
241
348
|
*/
|
|
242
349
|
export type StreamCompletionRequest = Omit<
|
|
243
350
|
typeof Generated.CreateMessageParams.Encoded,
|
|
@@ -280,9 +387,7 @@ interface MessageStopEvent {
|
|
|
280
387
|
interface ContentBlockStartEvent {
|
|
281
388
|
readonly type: "content_block_start"
|
|
282
389
|
readonly index: number
|
|
283
|
-
readonly content_block:
|
|
284
|
-
| typeof Generated.ResponseTextBlock.Encoded
|
|
285
|
-
| typeof Generated.ResponseToolUseBlock.Encoded
|
|
390
|
+
readonly content_block: typeof Generated.ContentBlock.Encoded
|
|
286
391
|
}
|
|
287
392
|
|
|
288
393
|
interface ContentBlockDeltaEvent {
|
|
@@ -291,7 +396,9 @@ interface ContentBlockDeltaEvent {
|
|
|
291
396
|
readonly delta:
|
|
292
397
|
| CitationsDelta
|
|
293
398
|
| InputJsonContentBlockDelta
|
|
399
|
+
| SignatureDelta
|
|
294
400
|
| TextContentBlockDelta
|
|
401
|
+
| ThinkingDelta
|
|
295
402
|
}
|
|
296
403
|
|
|
297
404
|
interface CitationsDelta {
|
|
@@ -306,11 +413,21 @@ interface InputJsonContentBlockDelta {
|
|
|
306
413
|
readonly partial_json: string
|
|
307
414
|
}
|
|
308
415
|
|
|
416
|
+
interface SignatureDelta {
|
|
417
|
+
readonly type: "signature_delta"
|
|
418
|
+
readonly signature: string
|
|
419
|
+
}
|
|
420
|
+
|
|
309
421
|
interface TextContentBlockDelta {
|
|
310
422
|
readonly type: "text_delta"
|
|
311
423
|
readonly text: string
|
|
312
424
|
}
|
|
313
425
|
|
|
426
|
+
interface ThinkingDelta {
|
|
427
|
+
readonly type: "thinking_delta"
|
|
428
|
+
readonly thinking: string
|
|
429
|
+
}
|
|
430
|
+
|
|
314
431
|
interface ContentBlockStopEvent {
|
|
315
432
|
readonly type: "content_block_stop"
|
|
316
433
|
readonly index: number
|
|
@@ -332,90 +449,8 @@ interface ErrorEvent {
|
|
|
332
449
|
}
|
|
333
450
|
}
|
|
334
451
|
|
|
335
|
-
|
|
336
|
-
* @since 1.0.0
|
|
337
|
-
* @category models
|
|
338
|
-
*/
|
|
339
|
-
export class StreamChunk extends Data.Class<{
|
|
340
|
-
readonly parts: Array<StreamChunkPart>
|
|
341
|
-
}> {
|
|
342
|
-
/**
|
|
343
|
-
* @since 1.0.0
|
|
344
|
-
*/
|
|
345
|
-
get text(): Option.Option<string> {
|
|
346
|
-
return this.parts[0]?._tag === "Content"
|
|
347
|
-
? Option.some(this.parts[0].content)
|
|
348
|
-
: Option.none()
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* @since 1.0.0
|
|
352
|
-
*/
|
|
353
|
-
get asAiResponse(): AiResponse.AiResponse {
|
|
354
|
-
if (this.parts.length === 0) {
|
|
355
|
-
return AiResponse.AiResponse.fromText({
|
|
356
|
-
role: AiRole.model,
|
|
357
|
-
content: ""
|
|
358
|
-
})
|
|
359
|
-
}
|
|
360
|
-
const part = this.parts[0]
|
|
361
|
-
switch (part._tag) {
|
|
362
|
-
case "Content":
|
|
363
|
-
return AiResponse.AiResponse.fromText({
|
|
364
|
-
role: AiRole.model,
|
|
365
|
-
content: part.content
|
|
366
|
-
})
|
|
367
|
-
case "ToolCall":
|
|
368
|
-
return new AiResponse.AiResponse({
|
|
369
|
-
role: AiRole.model,
|
|
370
|
-
parts: Chunk.of(
|
|
371
|
-
AiResponse.ToolCallPart.fromUnknown({
|
|
372
|
-
id: part.id,
|
|
373
|
-
name: part.name,
|
|
374
|
-
params: part.arguments
|
|
375
|
-
})
|
|
376
|
-
)
|
|
377
|
-
})
|
|
378
|
-
case "Usage":
|
|
379
|
-
return AiResponse.AiResponse.empty
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* @since 1.0.0
|
|
386
|
-
* @category models
|
|
387
|
-
*/
|
|
388
|
-
export type StreamChunkPart = ContentPart | ToolCallPart | UsagePart
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* @since 1.0.0
|
|
392
|
-
* @category models
|
|
393
|
-
*/
|
|
394
|
-
export interface ContentPart {
|
|
395
|
-
readonly _tag: "Content"
|
|
396
|
-
readonly content: string
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* @since 1.0.0
|
|
401
|
-
* @category models
|
|
402
|
-
*/
|
|
403
|
-
export interface ToolCallPart {
|
|
404
|
-
readonly _tag: "ToolCall"
|
|
452
|
+
type RawToolCall = {
|
|
405
453
|
readonly id: string
|
|
406
454
|
readonly name: string
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* @since 1.0.0
|
|
412
|
-
* @category models
|
|
413
|
-
*/
|
|
414
|
-
export interface UsagePart {
|
|
415
|
-
readonly _tag: "Usage"
|
|
416
|
-
readonly id: string
|
|
417
|
-
readonly model: string
|
|
418
|
-
readonly inputTokens: number
|
|
419
|
-
readonly outputTokens: number
|
|
420
|
-
readonly finishReasons: ReadonlyArray<string>
|
|
455
|
+
params: string
|
|
421
456
|
}
|
package/src/AnthropicConfig.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { dual } from "effect/Function"
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @since 1.0.0
|
|
11
|
-
* @category
|
|
11
|
+
* @category Context
|
|
12
12
|
*/
|
|
13
13
|
export class AnthropicConfig extends Context.Tag("@effect/ai-openai/AnthropicConfig")<
|
|
14
14
|
AnthropicConfig,
|
|
@@ -25,12 +25,11 @@ export class AnthropicConfig extends Context.Tag("@effect/ai-openai/AnthropicCon
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @since 1.0.0
|
|
28
|
-
* @category models
|
|
29
28
|
*/
|
|
30
29
|
export declare namespace AnthropicConfig {
|
|
31
30
|
/**
|
|
32
31
|
* @since 1.0.0
|
|
33
|
-
* @category
|
|
32
|
+
* @category Models
|
|
34
33
|
*/
|
|
35
34
|
export interface Service {
|
|
36
35
|
readonly transformClient?: (client: HttpClient) => HttpClient
|
|
@@ -39,17 +38,17 @@ export declare namespace AnthropicConfig {
|
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* @since 1.0.0
|
|
42
|
-
* @category
|
|
41
|
+
* @category Configuration
|
|
43
42
|
*/
|
|
44
43
|
export const withClientTransform: {
|
|
45
44
|
/**
|
|
46
45
|
* @since 1.0.0
|
|
47
|
-
* @category
|
|
46
|
+
* @category Configuration
|
|
48
47
|
*/
|
|
49
48
|
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
|
|
50
49
|
/**
|
|
51
50
|
* @since 1.0.0
|
|
52
|
-
* @category
|
|
51
|
+
* @category Configuration
|
|
53
52
|
*/
|
|
54
53
|
<A, E, R>(
|
|
55
54
|
self: Effect.Effect<A, E, R>,
|
|
@@ -58,12 +57,12 @@ export const withClientTransform: {
|
|
|
58
57
|
} = dual<
|
|
59
58
|
/**
|
|
60
59
|
* @since 1.0.0
|
|
61
|
-
* @category
|
|
60
|
+
* @category Configuration
|
|
62
61
|
*/
|
|
63
62
|
(transform: (client: HttpClient) => HttpClient) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
64
63
|
/**
|
|
65
64
|
* @since 1.0.0
|
|
66
|
-
* @category
|
|
65
|
+
* @category Configuration
|
|
67
66
|
*/
|
|
68
67
|
<A, E, R>(
|
|
69
68
|
self: Effect.Effect<A, E, R>,
|