@effect/ai-anthropic 4.0.0-beta.66 → 4.0.0-beta.68
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/AnthropicClient.d.ts +8 -8
- package/dist/AnthropicClient.js +6 -6
- package/dist/AnthropicConfig.d.ts +43 -8
- package/dist/AnthropicConfig.d.ts.map +1 -1
- package/dist/AnthropicConfig.js +28 -4
- package/dist/AnthropicConfig.js.map +1 -1
- package/dist/AnthropicError.d.ts +93 -3
- package/dist/AnthropicError.d.ts.map +1 -1
- package/dist/AnthropicError.js +1 -1
- package/dist/AnthropicLanguageModel.d.ts +181 -10
- package/dist/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.js +32 -6
- package/dist/AnthropicLanguageModel.js.map +1 -1
- package/dist/AnthropicTelemetry.d.ts +13 -11
- package/dist/AnthropicTelemetry.d.ts.map +1 -1
- package/dist/AnthropicTelemetry.js +3 -3
- package/dist/AnthropicTelemetry.js.map +1 -1
- package/dist/AnthropicTool.d.ts +224 -118
- package/dist/AnthropicTool.d.ts.map +1 -1
- package/dist/AnthropicTool.js +76 -72
- package/dist/AnthropicTool.js.map +1 -1
- package/dist/Generated.d.ts +1 -1
- package/dist/Generated.js +1 -1
- package/dist/index.d.ts +52 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/AnthropicClient.ts +9 -9
- package/src/AnthropicConfig.ts +43 -8
- package/src/AnthropicError.ts +93 -3
- package/src/AnthropicLanguageModel.ts +210 -13
- package/src/AnthropicTelemetry.ts +14 -12
- package/src/AnthropicTool.ts +224 -118
- package/src/Generated.ts +1 -1
- package/src/index.ts +52 -8
package/src/AnthropicError.ts
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
* Provides Anthropic-specific metadata fields for AI error types through module
|
|
5
5
|
* augmentation, enabling typed access to Anthropic error details.
|
|
6
6
|
*
|
|
7
|
-
* @since
|
|
7
|
+
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Anthropic-specific error metadata fields.
|
|
12
12
|
*
|
|
13
|
-
* @since 1.0.0
|
|
14
13
|
* @category models
|
|
14
|
+
* @since 4.0.0
|
|
15
15
|
*/
|
|
16
16
|
export type AnthropicErrorMetadata = {
|
|
17
17
|
/**
|
|
@@ -30,8 +30,8 @@ export type AnthropicErrorMetadata = {
|
|
|
30
30
|
* Extends base error metadata with rate limit specific information from
|
|
31
31
|
* Anthropic's rate limit headers.
|
|
32
32
|
*
|
|
33
|
-
* @since 1.0.0
|
|
34
33
|
* @category models
|
|
34
|
+
* @since 4.0.0
|
|
35
35
|
*/
|
|
36
36
|
export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
|
|
37
37
|
/**
|
|
@@ -61,42 +61,132 @@ export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
declare module "effect/unstable/ai/AiError" {
|
|
64
|
+
/**
|
|
65
|
+
* Anthropic metadata attached to `RateLimitError` values.
|
|
66
|
+
*
|
|
67
|
+
* Includes request identifiers, Anthropic error types, and parsed request or
|
|
68
|
+
* token limit headers when the provider rejects a request due to rate limits.
|
|
69
|
+
*
|
|
70
|
+
* @category configuration
|
|
71
|
+
* @since 4.0.0
|
|
72
|
+
*/
|
|
64
73
|
export interface RateLimitErrorMetadata {
|
|
65
74
|
readonly anthropic?: AnthropicRateLimitMetadata | null
|
|
66
75
|
}
|
|
67
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Anthropic metadata attached to `QuotaExhaustedError` values.
|
|
79
|
+
*
|
|
80
|
+
* Captures the Anthropic error type and request identifier for failures where
|
|
81
|
+
* the account or workspace has exhausted its available quota.
|
|
82
|
+
*
|
|
83
|
+
* @category configuration
|
|
84
|
+
* @since 4.0.0
|
|
85
|
+
*/
|
|
68
86
|
export interface QuotaExhaustedErrorMetadata {
|
|
69
87
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
70
88
|
}
|
|
71
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Anthropic metadata attached to `AuthenticationError` values.
|
|
92
|
+
*
|
|
93
|
+
* Preserves Anthropic error details for missing, invalid, or unauthorized API
|
|
94
|
+
* credentials while keeping the error in the shared AI error model.
|
|
95
|
+
*
|
|
96
|
+
* @category configuration
|
|
97
|
+
* @since 4.0.0
|
|
98
|
+
*/
|
|
72
99
|
export interface AuthenticationErrorMetadata {
|
|
73
100
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
74
101
|
}
|
|
75
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Anthropic metadata attached to `ContentPolicyError` values.
|
|
105
|
+
*
|
|
106
|
+
* Records Anthropic error details returned when a request or response is
|
|
107
|
+
* rejected by Anthropic safety or content policy enforcement.
|
|
108
|
+
*
|
|
109
|
+
* @category configuration
|
|
110
|
+
* @since 4.0.0
|
|
111
|
+
*/
|
|
76
112
|
export interface ContentPolicyErrorMetadata {
|
|
77
113
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
78
114
|
}
|
|
79
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Anthropic metadata attached to `InvalidRequestError` values.
|
|
118
|
+
*
|
|
119
|
+
* Provides the Anthropic error type and request identifier for malformed or
|
|
120
|
+
* unsupported requests rejected before model execution.
|
|
121
|
+
*
|
|
122
|
+
* @category configuration
|
|
123
|
+
* @since 4.0.0
|
|
124
|
+
*/
|
|
80
125
|
export interface InvalidRequestErrorMetadata {
|
|
81
126
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
82
127
|
}
|
|
83
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Anthropic metadata attached to `InternalProviderError` values.
|
|
131
|
+
*
|
|
132
|
+
* Preserves Anthropic request correlation data for provider-side failures
|
|
133
|
+
* that should be reported or investigated with Anthropic support.
|
|
134
|
+
*
|
|
135
|
+
* @category configuration
|
|
136
|
+
* @since 4.0.0
|
|
137
|
+
*/
|
|
84
138
|
export interface InternalProviderErrorMetadata {
|
|
85
139
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
86
140
|
}
|
|
87
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Anthropic metadata attached to `InvalidOutputError` values.
|
|
144
|
+
*
|
|
145
|
+
* Describes Anthropic-specific context for responses that could not be
|
|
146
|
+
* decoded or interpreted as valid AI output.
|
|
147
|
+
*
|
|
148
|
+
* @category configuration
|
|
149
|
+
* @since 4.0.0
|
|
150
|
+
*/
|
|
88
151
|
export interface InvalidOutputErrorMetadata {
|
|
89
152
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
90
153
|
}
|
|
91
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Anthropic metadata attached to `StructuredOutputError` values.
|
|
157
|
+
*
|
|
158
|
+
* Captures Anthropic error details for structured-output failures, including
|
|
159
|
+
* request correlation data useful when diagnosing schema-related responses.
|
|
160
|
+
*
|
|
161
|
+
* @category configuration
|
|
162
|
+
* @since 4.0.0
|
|
163
|
+
*/
|
|
92
164
|
export interface StructuredOutputErrorMetadata {
|
|
93
165
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
94
166
|
}
|
|
95
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Anthropic metadata attached to `UnsupportedSchemaError` values.
|
|
170
|
+
*
|
|
171
|
+
* Provides Anthropic error details for schemas that cannot be represented by
|
|
172
|
+
* or submitted to the Anthropic API.
|
|
173
|
+
*
|
|
174
|
+
* @category configuration
|
|
175
|
+
* @since 4.0.0
|
|
176
|
+
*/
|
|
96
177
|
export interface UnsupportedSchemaErrorMetadata {
|
|
97
178
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
98
179
|
}
|
|
99
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Anthropic metadata attached to `UnknownError` values.
|
|
183
|
+
*
|
|
184
|
+
* Retains the Anthropic error type and request identifier when a provider
|
|
185
|
+
* response cannot be classified as a more specific AI error.
|
|
186
|
+
*
|
|
187
|
+
* @category configuration
|
|
188
|
+
* @since 4.0.0
|
|
189
|
+
*/
|
|
100
190
|
export interface UnknownErrorMetadata {
|
|
101
191
|
readonly anthropic?: AnthropicErrorMetadata | null
|
|
102
192
|
}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `AnthropicLanguageModel` module provides the Anthropic implementation of
|
|
3
|
+
* Effect AI's `LanguageModel` service. It turns Effect AI prompts, tools, files,
|
|
4
|
+
* reasoning parts, and provider options into Anthropic Messages API requests,
|
|
5
|
+
* and converts Anthropic responses and streams back into Effect AI response
|
|
6
|
+
* parts with Anthropic-specific metadata.
|
|
7
|
+
*
|
|
8
|
+
* **Common tasks**
|
|
9
|
+
*
|
|
10
|
+
* - Create an Anthropic-backed model with {@link model}
|
|
11
|
+
* - Build or provide a `LanguageModel.LanguageModel` layer with {@link layer}
|
|
12
|
+
* or {@link make}
|
|
13
|
+
* - Supply default request options through {@link Config}
|
|
14
|
+
* - Override configuration for a scoped operation with {@link withConfigOverride}
|
|
15
|
+
* - Attach Anthropic provider options for prompt caching, document citations,
|
|
16
|
+
* reasoning signatures, MCP metadata, and server-side tools
|
|
17
|
+
*
|
|
18
|
+
* **Gotchas**
|
|
19
|
+
*
|
|
20
|
+
* - Prompt files are translated to Anthropic image or document blocks; only the
|
|
21
|
+
* supported media types can be sent to the provider.
|
|
22
|
+
* - Structured output support depends on the selected Claude model, so this
|
|
23
|
+
* module may use Anthropic's native structured output or fall back to a JSON
|
|
24
|
+
* response tool.
|
|
25
|
+
* - Some features require Anthropic beta headers, which are added
|
|
26
|
+
* automatically from the selected tools, files, and model capabilities.
|
|
27
|
+
*
|
|
28
|
+
* @since 4.0.0
|
|
3
29
|
*/
|
|
4
30
|
/** @effect-diagnostics preferSchemaOverJson:skip-file */
|
|
5
31
|
import * as Arr from "effect/Array"
|
|
@@ -36,8 +62,8 @@ import * as InternalUtilities from "./internal/utilities.ts"
|
|
|
36
62
|
/**
|
|
37
63
|
* The available Anthropic Claude model identifiers.
|
|
38
64
|
*
|
|
39
|
-
* @since 1.0.0
|
|
40
65
|
* @category models
|
|
66
|
+
* @since 4.0.0
|
|
41
67
|
*/
|
|
42
68
|
export type Model = typeof Generated.Model.Type
|
|
43
69
|
|
|
@@ -51,8 +77,8 @@ export type Model = typeof Generated.Model.Type
|
|
|
51
77
|
* This service can be used to provide default configuration values or to
|
|
52
78
|
* override configuration on a per-request basis.
|
|
53
79
|
*
|
|
54
|
-
* @since 1.0.0
|
|
55
80
|
* @category configuration
|
|
81
|
+
* @since 4.0.0
|
|
56
82
|
*/
|
|
57
83
|
export class Config extends Context.Service<
|
|
58
84
|
Config,
|
|
@@ -87,6 +113,15 @@ export class Config extends Context.Service<
|
|
|
87
113
|
// =============================================================================
|
|
88
114
|
|
|
89
115
|
declare module "effect/unstable/ai/Prompt" {
|
|
116
|
+
/**
|
|
117
|
+
* Anthropic-specific options for system messages.
|
|
118
|
+
*
|
|
119
|
+
* These options are used when translating system messages into Anthropic
|
|
120
|
+
* request content.
|
|
121
|
+
*
|
|
122
|
+
* @category request
|
|
123
|
+
* @since 4.0.0
|
|
124
|
+
*/
|
|
90
125
|
export interface SystemMessageOptions extends ProviderOptions {
|
|
91
126
|
readonly anthropic?: {
|
|
92
127
|
/**
|
|
@@ -96,6 +131,15 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
96
131
|
} | null
|
|
97
132
|
}
|
|
98
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Anthropic-specific options for user messages.
|
|
136
|
+
*
|
|
137
|
+
* These options are used when translating user messages into Anthropic
|
|
138
|
+
* request content.
|
|
139
|
+
*
|
|
140
|
+
* @category request
|
|
141
|
+
* @since 4.0.0
|
|
142
|
+
*/
|
|
99
143
|
export interface UserMessageOptions extends ProviderOptions {
|
|
100
144
|
readonly anthropic?: {
|
|
101
145
|
/**
|
|
@@ -105,6 +149,15 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
105
149
|
} | null
|
|
106
150
|
}
|
|
107
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Anthropic-specific options for assistant messages.
|
|
154
|
+
*
|
|
155
|
+
* These options are used when replaying assistant messages in Anthropic
|
|
156
|
+
* conversation history.
|
|
157
|
+
*
|
|
158
|
+
* @category request
|
|
159
|
+
* @since 4.0.0
|
|
160
|
+
*/
|
|
108
161
|
export interface AssistantMessageOptions extends ProviderOptions {
|
|
109
162
|
readonly anthropic?: {
|
|
110
163
|
/**
|
|
@@ -114,6 +167,15 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
114
167
|
} | null
|
|
115
168
|
}
|
|
116
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Anthropic-specific options for tool messages.
|
|
172
|
+
*
|
|
173
|
+
* These options are used when converting tool results into Anthropic user
|
|
174
|
+
* content blocks.
|
|
175
|
+
*
|
|
176
|
+
* @category request
|
|
177
|
+
* @since 4.0.0
|
|
178
|
+
*/
|
|
117
179
|
export interface ToolMessageOptions extends ProviderOptions {
|
|
118
180
|
readonly anthropic?: {
|
|
119
181
|
/**
|
|
@@ -123,6 +185,14 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
123
185
|
} | null
|
|
124
186
|
}
|
|
125
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Anthropic-specific options for text prompt parts.
|
|
190
|
+
*
|
|
191
|
+
* Use these options to control how text blocks are sent to Anthropic.
|
|
192
|
+
*
|
|
193
|
+
* @category request
|
|
194
|
+
* @since 4.0.0
|
|
195
|
+
*/
|
|
126
196
|
export interface TextPartOptions extends ProviderOptions {
|
|
127
197
|
readonly anthropic?: {
|
|
128
198
|
/**
|
|
@@ -132,6 +202,15 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
132
202
|
} | null
|
|
133
203
|
}
|
|
134
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Anthropic-specific options for reasoning prompt parts.
|
|
207
|
+
*
|
|
208
|
+
* Preserves Claude thinking metadata when reasoning content is sent back to
|
|
209
|
+
* Anthropic in later turns.
|
|
210
|
+
*
|
|
211
|
+
* @category request
|
|
212
|
+
* @since 4.0.0
|
|
213
|
+
*/
|
|
135
214
|
export interface ReasoningPartOptions extends ProviderOptions {
|
|
136
215
|
readonly anthropic?: {
|
|
137
216
|
readonly info?: {
|
|
@@ -156,6 +235,15 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
156
235
|
} | null
|
|
157
236
|
}
|
|
158
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Anthropic-specific options for file prompt parts.
|
|
240
|
+
*
|
|
241
|
+
* Controls document metadata, citations, and prompt caching for files sent to
|
|
242
|
+
* Anthropic.
|
|
243
|
+
*
|
|
244
|
+
* @category request
|
|
245
|
+
* @since 4.0.0
|
|
246
|
+
*/
|
|
159
247
|
export interface FilePartOptions extends ProviderOptions {
|
|
160
248
|
readonly anthropic?: {
|
|
161
249
|
/**
|
|
@@ -181,6 +269,15 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
181
269
|
} | null
|
|
182
270
|
}
|
|
183
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Anthropic-specific options for tool call prompt parts.
|
|
274
|
+
*
|
|
275
|
+
* Carries Anthropic tool caller metadata, MCP metadata, and cache control for
|
|
276
|
+
* tool use blocks.
|
|
277
|
+
*
|
|
278
|
+
* @category request
|
|
279
|
+
* @since 4.0.0
|
|
280
|
+
*/
|
|
184
281
|
export interface ToolCallPartOptions extends ProviderOptions {
|
|
185
282
|
readonly anthropic?: {
|
|
186
283
|
readonly caller?: {
|
|
@@ -203,6 +300,14 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
203
300
|
} | null
|
|
204
301
|
}
|
|
205
302
|
|
|
303
|
+
/**
|
|
304
|
+
* Anthropic-specific options for tool result prompt parts.
|
|
305
|
+
*
|
|
306
|
+
* Controls Anthropic prompt caching for tool result content.
|
|
307
|
+
*
|
|
308
|
+
* @category request
|
|
309
|
+
* @since 4.0.0
|
|
310
|
+
*/
|
|
206
311
|
export interface ToolResultPartOptions extends ProviderOptions {
|
|
207
312
|
readonly anthropic?: {
|
|
208
313
|
/**
|
|
@@ -212,6 +317,14 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
212
317
|
} | null
|
|
213
318
|
}
|
|
214
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Anthropic-specific options for tool approval request prompt parts.
|
|
322
|
+
*
|
|
323
|
+
* Controls prompt caching for human approval requests in conversations.
|
|
324
|
+
*
|
|
325
|
+
* @category request
|
|
326
|
+
* @since 4.0.0
|
|
327
|
+
*/
|
|
215
328
|
export interface ToolApprovalRequestPartOptions extends ProviderOptions {
|
|
216
329
|
readonly anthropic?: {
|
|
217
330
|
/**
|
|
@@ -221,6 +334,14 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
221
334
|
} | null
|
|
222
335
|
}
|
|
223
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Anthropic-specific options for tool approval response prompt parts.
|
|
339
|
+
*
|
|
340
|
+
* Controls prompt caching for human approval responses in conversations.
|
|
341
|
+
*
|
|
342
|
+
* @category request
|
|
343
|
+
* @since 4.0.0
|
|
344
|
+
*/
|
|
224
345
|
export interface ToolApprovalResponsePartOptions extends ProviderOptions {
|
|
225
346
|
readonly anthropic?: {
|
|
226
347
|
/**
|
|
@@ -232,6 +353,15 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
232
353
|
}
|
|
233
354
|
|
|
234
355
|
declare module "effect/unstable/ai/Response" {
|
|
356
|
+
/**
|
|
357
|
+
* Anthropic metadata attached when a reasoning block begins.
|
|
358
|
+
*
|
|
359
|
+
* Includes Claude thinking metadata needed to continue reasoning-aware
|
|
360
|
+
* conversations.
|
|
361
|
+
*
|
|
362
|
+
* @category response
|
|
363
|
+
* @since 4.0.0
|
|
364
|
+
*/
|
|
235
365
|
export interface ReasoningStartPartMetadata extends ProviderMetadata {
|
|
236
366
|
readonly anthropic?: {
|
|
237
367
|
readonly info?: {
|
|
@@ -252,6 +382,14 @@ declare module "effect/unstable/ai/Response" {
|
|
|
252
382
|
} | null
|
|
253
383
|
}
|
|
254
384
|
|
|
385
|
+
/**
|
|
386
|
+
* Anthropic metadata attached to streaming reasoning deltas.
|
|
387
|
+
*
|
|
388
|
+
* Includes the signature for streamed Claude thinking content when available.
|
|
389
|
+
*
|
|
390
|
+
* @category response
|
|
391
|
+
* @since 4.0.0
|
|
392
|
+
*/
|
|
255
393
|
export interface ReasoningDeltaPartMetadata extends ProviderMetadata {
|
|
256
394
|
readonly anthropic?: {
|
|
257
395
|
readonly info?: {
|
|
@@ -265,6 +403,14 @@ declare module "effect/unstable/ai/Response" {
|
|
|
265
403
|
} | null
|
|
266
404
|
}
|
|
267
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Anthropic metadata attached to completed reasoning parts.
|
|
408
|
+
*
|
|
409
|
+
* Preserves Claude thinking or redacted thinking information for later turns.
|
|
410
|
+
*
|
|
411
|
+
* @category response
|
|
412
|
+
* @since 4.0.0
|
|
413
|
+
*/
|
|
268
414
|
export interface ReasoningPartMetadata extends ProviderMetadata {
|
|
269
415
|
readonly anthropic?: {
|
|
270
416
|
readonly info?: {
|
|
@@ -285,6 +431,15 @@ declare module "effect/unstable/ai/Response" {
|
|
|
285
431
|
} | null
|
|
286
432
|
}
|
|
287
433
|
|
|
434
|
+
/**
|
|
435
|
+
* Anthropic metadata attached to tool call response parts.
|
|
436
|
+
*
|
|
437
|
+
* Identifies Anthropic caller details and MCP tool metadata emitted by the
|
|
438
|
+
* provider.
|
|
439
|
+
*
|
|
440
|
+
* @category response
|
|
441
|
+
* @since 4.0.0
|
|
442
|
+
*/
|
|
288
443
|
export interface ToolCallPartMetadata extends ProviderMetadata {
|
|
289
444
|
readonly anthropic?: {
|
|
290
445
|
readonly caller?: {
|
|
@@ -303,6 +458,15 @@ declare module "effect/unstable/ai/Response" {
|
|
|
303
458
|
} | null
|
|
304
459
|
}
|
|
305
460
|
|
|
461
|
+
/**
|
|
462
|
+
* Anthropic metadata attached to tool result response parts.
|
|
463
|
+
*
|
|
464
|
+
* Identifies MCP tool metadata associated with provider-executed tool
|
|
465
|
+
* results.
|
|
466
|
+
*
|
|
467
|
+
* @category response
|
|
468
|
+
* @since 4.0.0
|
|
469
|
+
*/
|
|
306
470
|
export interface ToolResultPartMetadata extends ProviderMetadata {
|
|
307
471
|
readonly anthropic?: {
|
|
308
472
|
/**
|
|
@@ -317,6 +481,14 @@ declare module "effect/unstable/ai/Response" {
|
|
|
317
481
|
} | null
|
|
318
482
|
}
|
|
319
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Anthropic metadata for document citations in model responses.
|
|
486
|
+
*
|
|
487
|
+
* Records the cited document span by character position or page number.
|
|
488
|
+
*
|
|
489
|
+
* @category response
|
|
490
|
+
* @since 4.0.0
|
|
491
|
+
*/
|
|
320
492
|
export interface DocumentSourcePartMetadata extends ProviderMetadata {
|
|
321
493
|
readonly anthropic?: {
|
|
322
494
|
readonly source: "document"
|
|
@@ -351,6 +523,14 @@ declare module "effect/unstable/ai/Response" {
|
|
|
351
523
|
} | null
|
|
352
524
|
}
|
|
353
525
|
|
|
526
|
+
/**
|
|
527
|
+
* Anthropic metadata for URL and web citations in model responses.
|
|
528
|
+
*
|
|
529
|
+
* Records cited URL text or web-search source freshness information.
|
|
530
|
+
*
|
|
531
|
+
* @category response
|
|
532
|
+
* @since 4.0.0
|
|
533
|
+
*/
|
|
354
534
|
export interface UrlSourcePartMetadata extends ProviderMetadata {
|
|
355
535
|
readonly anthropic?: {
|
|
356
536
|
readonly source: "url"
|
|
@@ -370,6 +550,15 @@ declare module "effect/unstable/ai/Response" {
|
|
|
370
550
|
} | null
|
|
371
551
|
}
|
|
372
552
|
|
|
553
|
+
/**
|
|
554
|
+
* Anthropic metadata attached to the finish part of a response.
|
|
555
|
+
*
|
|
556
|
+
* Includes container state, context management information, stop details, and
|
|
557
|
+
* token usage reported by Anthropic.
|
|
558
|
+
*
|
|
559
|
+
* @category response
|
|
560
|
+
* @since 4.0.0
|
|
561
|
+
*/
|
|
373
562
|
export interface FinishPartMetadata extends ProviderMetadata {
|
|
374
563
|
readonly anthropic?: {
|
|
375
564
|
readonly container: typeof Generated.BetaContainer.Encoded | null
|
|
@@ -379,6 +568,14 @@ declare module "effect/unstable/ai/Response" {
|
|
|
379
568
|
} | null
|
|
380
569
|
}
|
|
381
570
|
|
|
571
|
+
/**
|
|
572
|
+
* Anthropic metadata attached to error response parts.
|
|
573
|
+
*
|
|
574
|
+
* Includes the provider request identifier when Anthropic returns one.
|
|
575
|
+
*
|
|
576
|
+
* @category response
|
|
577
|
+
* @since 4.0.0
|
|
578
|
+
*/
|
|
382
579
|
export interface ErrorPartMetadata extends ProviderMetadata {
|
|
383
580
|
readonly anthropic?: {
|
|
384
581
|
requestId?: string | null
|
|
@@ -393,8 +590,8 @@ declare module "effect/unstable/ai/Response" {
|
|
|
393
590
|
/**
|
|
394
591
|
* Creates an Anthropic language model that can be used with `AiModel.provide`.
|
|
395
592
|
*
|
|
396
|
-
* @since 1.0.0
|
|
397
593
|
* @category constructors
|
|
594
|
+
* @since 4.0.0
|
|
398
595
|
*/
|
|
399
596
|
export const model = (
|
|
400
597
|
model: (string & {}) | Model,
|
|
@@ -405,8 +602,8 @@ export const model = (
|
|
|
405
602
|
/**
|
|
406
603
|
* Creates an Anthropic language model service.
|
|
407
604
|
*
|
|
408
|
-
* @since 1.0.0
|
|
409
605
|
* @category constructors
|
|
606
|
+
* @since 4.0.0
|
|
410
607
|
*/
|
|
411
608
|
export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
|
|
412
609
|
readonly model: (string & {}) | Model
|
|
@@ -492,8 +689,8 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
|
|
|
492
689
|
/**
|
|
493
690
|
* Creates a layer for the Anthropic language model.
|
|
494
691
|
*
|
|
495
|
-
* @since 1.0.0
|
|
496
692
|
* @category layers
|
|
693
|
+
* @since 4.0.0
|
|
497
694
|
*/
|
|
498
695
|
export const layer = (options: {
|
|
499
696
|
readonly model: (string & {}) | Model
|
|
@@ -504,37 +701,37 @@ export const layer = (options: {
|
|
|
504
701
|
/**
|
|
505
702
|
* Provides config overrides for Anthropic language model operations.
|
|
506
703
|
*
|
|
507
|
-
* @since 1.0.0
|
|
508
704
|
* @category configuration
|
|
705
|
+
* @since 4.0.0
|
|
509
706
|
*/
|
|
510
707
|
export const withConfigOverride: {
|
|
511
708
|
/**
|
|
512
709
|
* Provides config overrides for Anthropic language model operations.
|
|
513
710
|
*
|
|
514
|
-
* @since 1.0.0
|
|
515
711
|
* @category configuration
|
|
712
|
+
* @since 4.0.0
|
|
516
713
|
*/
|
|
517
714
|
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
|
|
518
715
|
/**
|
|
519
716
|
* Provides config overrides for Anthropic language model operations.
|
|
520
717
|
*
|
|
521
|
-
* @since 1.0.0
|
|
522
718
|
* @category configuration
|
|
719
|
+
* @since 4.0.0
|
|
523
720
|
*/
|
|
524
721
|
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
|
|
525
722
|
} = dual<
|
|
526
723
|
/**
|
|
527
724
|
* Provides config overrides for Anthropic language model operations.
|
|
528
725
|
*
|
|
529
|
-
* @since 1.0.0
|
|
530
726
|
* @category configuration
|
|
727
|
+
* @since 4.0.0
|
|
531
728
|
*/
|
|
532
729
|
(overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
|
|
533
730
|
/**
|
|
534
731
|
* Provides config overrides for Anthropic language model operations.
|
|
535
732
|
*
|
|
536
|
-
* @since 1.0.0
|
|
537
733
|
* @category configuration
|
|
734
|
+
* @since 4.0.0
|
|
538
735
|
*/
|
|
539
736
|
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
|
|
540
737
|
>(2, (self, overrides) =>
|
|
@@ -954,8 +1151,8 @@ const prepareMessages = Effect.fnUntraced(
|
|
|
954
1151
|
/**
|
|
955
1152
|
* Represents a user-defined tool that can be passed to the Anthropic API.
|
|
956
1153
|
*
|
|
957
|
-
* @since 1.0.0
|
|
958
1154
|
* @category tools
|
|
1155
|
+
* @since 4.0.0
|
|
959
1156
|
*/
|
|
960
1157
|
export type AnthropicUserDefinedTool = typeof Generated.BetaTool.Encoded
|
|
961
1158
|
|
|
@@ -965,8 +1162,8 @@ export type AnthropicUserDefinedTool = typeof Generated.BetaTool.Encoded
|
|
|
965
1162
|
* These include Anthropic's built-in tools like computer use, code execution,
|
|
966
1163
|
* web search, and text editing.
|
|
967
1164
|
*
|
|
968
|
-
* @since 1.0.0
|
|
969
1165
|
* @category tools
|
|
1166
|
+
* @since 4.0.0
|
|
970
1167
|
*/
|
|
971
1168
|
export type AnthropicProviderDefinedTool =
|
|
972
1169
|
| typeof Generated.BetaBashTool_20241022.Encoded
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* semantic conventions, extending the base GenAI attributes with Anthropic-specific
|
|
6
6
|
* request and response metadata.
|
|
7
7
|
*
|
|
8
|
-
* @since
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
import { dual } from "effect/Function"
|
|
11
11
|
import * as String from "effect/String"
|
|
@@ -19,8 +19,8 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
|
|
|
19
19
|
*
|
|
20
20
|
* {@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}
|
|
21
21
|
*
|
|
22
|
-
* @since 1.0.0
|
|
23
22
|
* @category models
|
|
23
|
+
* @since 4.0.0
|
|
24
24
|
*/
|
|
25
25
|
export type AnthropicTelemetryAttributes = Simplify<
|
|
26
26
|
& Telemetry.GenAITelemetryAttributes
|
|
@@ -32,8 +32,8 @@ export type AnthropicTelemetryAttributes = Simplify<
|
|
|
32
32
|
* All telemetry attributes which are part of the GenAI specification,
|
|
33
33
|
* including the Anthropic-specific attributes.
|
|
34
34
|
*
|
|
35
|
-
* @since 1.0.0
|
|
36
35
|
* @category models
|
|
36
|
+
* @since 4.0.0
|
|
37
37
|
*/
|
|
38
38
|
export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes
|
|
39
39
|
|
|
@@ -41,8 +41,8 @@ export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & Respon
|
|
|
41
41
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
42
42
|
* namespaced by `gen_ai.anthropic.request`.
|
|
43
43
|
*
|
|
44
|
-
* @since 1.0.0
|
|
45
44
|
* @category models
|
|
45
|
+
* @since 4.0.0
|
|
46
46
|
*/
|
|
47
47
|
export interface RequestAttributes {
|
|
48
48
|
/**
|
|
@@ -59,8 +59,8 @@ export interface RequestAttributes {
|
|
|
59
59
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
60
60
|
* namespaced by `gen_ai.anthropic.response`.
|
|
61
61
|
*
|
|
62
|
-
* @since 1.0.0
|
|
63
62
|
* @category models
|
|
63
|
+
* @since 4.0.0
|
|
64
64
|
*/
|
|
65
65
|
export interface ResponseAttributes {
|
|
66
66
|
/**
|
|
@@ -78,8 +78,10 @@ export interface ResponseAttributes {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Options accepted by `addGenAIAnnotations`, combining standard GenAI telemetry attributes with optional Anthropic request and response attributes.
|
|
82
|
+
*
|
|
82
83
|
* @category models
|
|
84
|
+
* @since 4.0.0
|
|
83
85
|
*/
|
|
84
86
|
export type AnthropicTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
|
|
85
87
|
anthropic?: {
|
|
@@ -101,8 +103,8 @@ const addAnthropicResponseAttributes = Telemetry.addSpanAttributes("gen_ai.anthr
|
|
|
101
103
|
*
|
|
102
104
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
103
105
|
*
|
|
104
|
-
* @
|
|
105
|
-
* @
|
|
106
|
+
* @category utils
|
|
107
|
+
* @since 4.0.0
|
|
106
108
|
*/
|
|
107
109
|
export const addGenAIAnnotations: {
|
|
108
110
|
/**
|
|
@@ -111,8 +113,8 @@ export const addGenAIAnnotations: {
|
|
|
111
113
|
*
|
|
112
114
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
113
115
|
*
|
|
114
|
-
* @
|
|
115
|
-
* @
|
|
116
|
+
* @category utils
|
|
117
|
+
* @since 4.0.0
|
|
116
118
|
*/
|
|
117
119
|
(options: AnthropicTelemetryAttributeOptions): (span: Span) => void
|
|
118
120
|
/**
|
|
@@ -121,8 +123,8 @@ export const addGenAIAnnotations: {
|
|
|
121
123
|
*
|
|
122
124
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
123
125
|
*
|
|
124
|
-
* @
|
|
125
|
-
* @
|
|
126
|
+
* @category utils
|
|
127
|
+
* @since 4.0.0
|
|
126
128
|
*/
|
|
127
129
|
(span: Span, options: AnthropicTelemetryAttributeOptions): void
|
|
128
130
|
} = dual(2, (span: Span, options: AnthropicTelemetryAttributeOptions) => {
|