@effect/ai-anthropic 4.0.0-beta.8 → 4.0.0-beta.80
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 +92 -69
- package/dist/AnthropicClient.d.ts.map +1 -1
- package/dist/AnthropicClient.js +51 -19
- package/dist/AnthropicClient.js.map +1 -1
- package/dist/AnthropicConfig.d.ts +55 -10
- package/dist/AnthropicConfig.d.ts.map +1 -1
- package/dist/AnthropicConfig.js +30 -7
- package/dist/AnthropicConfig.js.map +1 -1
- package/dist/AnthropicError.d.ts +136 -37
- package/dist/AnthropicError.d.ts.map +1 -1
- package/dist/AnthropicError.js +1 -1
- package/dist/AnthropicLanguageModel.d.ts +362 -52
- package/dist/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.js +88 -21
- package/dist/AnthropicLanguageModel.js.map +1 -1
- package/dist/AnthropicTelemetry.d.ts +43 -16
- package/dist/AnthropicTelemetry.d.ts.map +1 -1
- package/dist/AnthropicTelemetry.js +15 -9
- package/dist/AnthropicTelemetry.js.map +1 -1
- package/dist/AnthropicTool.d.ts +1223 -289
- package/dist/AnthropicTool.d.ts.map +1 -1
- package/dist/AnthropicTool.js +859 -201
- 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 +8 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -29
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +7 -7
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/AnthropicClient.ts +97 -74
- package/src/AnthropicConfig.ts +56 -11
- package/src/AnthropicError.ts +138 -37
- package/src/AnthropicLanguageModel.ts +395 -43
- package/src/AnthropicTelemetry.ts +48 -22
- package/src/AnthropicTool.ts +1216 -282
- package/src/Generated.ts +1 -1
- package/src/index.ts +8 -29
- package/src/internal/errors.ts +9 -7
package/src/AnthropicClient.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `AnthropicClient` module defines the low-level Effect service for
|
|
3
|
+
* Anthropic's Messages API. It builds a generated Anthropic HTTP client with
|
|
4
|
+
* authentication headers, API version headers, response decoding, and error
|
|
5
|
+
* mapping, then exposes helpers for regular and streaming message requests.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
* messages and streaming responses.
|
|
6
|
-
*
|
|
7
|
-
* @since 1.0.0
|
|
7
|
+
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
9
|
import * as Array from "effect/Array"
|
|
10
10
|
import type * as Config from "effect/Config"
|
|
11
|
+
import * as Context from "effect/Context"
|
|
11
12
|
import * as Effect from "effect/Effect"
|
|
12
13
|
import { identity } from "effect/Function"
|
|
13
14
|
import * as Layer from "effect/Layer"
|
|
14
15
|
import * as Predicate from "effect/Predicate"
|
|
15
16
|
import * as Redacted from "effect/Redacted"
|
|
16
17
|
import * as Schema from "effect/Schema"
|
|
17
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
18
18
|
import * as Stream from "effect/Stream"
|
|
19
19
|
import type * as AiError from "effect/unstable/ai/AiError"
|
|
20
20
|
import * as Sse from "effect/unstable/encoding/Sse"
|
|
@@ -33,26 +33,20 @@ import * as Errors from "./internal/errors.ts"
|
|
|
33
33
|
// =============================================================================
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* Provides methods for interacting with Anthropic's Messages API, including
|
|
39
|
-
* both synchronous and streaming message creation.
|
|
36
|
+
* Represents the Anthropic client service with methods for the Messages API, including regular and streaming message
|
|
37
|
+
* creation.
|
|
40
38
|
*
|
|
41
|
-
* @since 1.0.0
|
|
42
39
|
* @category models
|
|
40
|
+
* @since 4.0.0
|
|
43
41
|
*/
|
|
44
42
|
export interface Service {
|
|
45
43
|
/**
|
|
46
|
-
* The underlying generated Anthropic client
|
|
47
|
-
* endpoints.
|
|
44
|
+
* The underlying generated Anthropic client that exposes all API endpoints.
|
|
48
45
|
*/
|
|
49
46
|
readonly client: Generated.AnthropicClient
|
|
50
47
|
|
|
51
48
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* Executes an HTTP request and decodes the Server-Sent Events response
|
|
55
|
-
* using the provided schema.
|
|
49
|
+
* Executes a low-level streaming HTTP request and decodes the Server-Sent Events response using the provided schema.
|
|
56
50
|
*/
|
|
57
51
|
readonly streamRequest: <
|
|
58
52
|
Type extends {
|
|
@@ -70,10 +64,7 @@ export interface Service {
|
|
|
70
64
|
>
|
|
71
65
|
|
|
72
66
|
/**
|
|
73
|
-
* Creates a message using the Anthropic Messages API.
|
|
74
|
-
*
|
|
75
|
-
* Sends a structured list of input messages and returns the model's
|
|
76
|
-
* generated response. All errors are mapped to the unified `AiError` type.
|
|
67
|
+
* Creates a message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
77
68
|
*/
|
|
78
69
|
readonly createMessage: (options: {
|
|
79
70
|
readonly payload: typeof Generated.BetaCreateMessageParams.Encoded
|
|
@@ -84,12 +75,12 @@ export interface Service {
|
|
|
84
75
|
>
|
|
85
76
|
|
|
86
77
|
/**
|
|
87
|
-
* Creates a streaming message using the Anthropic Messages API.
|
|
78
|
+
* Creates a streaming message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
88
79
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
80
|
+
* **Details**
|
|
81
|
+
*
|
|
82
|
+
* The returned Effect yields the HTTP response and a stream of events as the model generates its response. The stream
|
|
83
|
+
* automatically terminates when a `message_stop` event is received.
|
|
93
84
|
*/
|
|
94
85
|
readonly createMessageStream: (options: {
|
|
95
86
|
readonly payload: Omit<typeof Generated.BetaCreateMessageParams.Encoded, "stream">
|
|
@@ -101,8 +92,9 @@ export interface Service {
|
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
/**
|
|
104
|
-
* Represents an event received from the Anthropic Messages API during a
|
|
105
|
-
*
|
|
95
|
+
* Represents an event received from the Anthropic Messages API during a streaming request.
|
|
96
|
+
*
|
|
97
|
+
* **Details**
|
|
106
98
|
*
|
|
107
99
|
* Events include:
|
|
108
100
|
* - `message_start`: Initial event containing message metadata
|
|
@@ -113,8 +105,8 @@ export interface Service {
|
|
|
113
105
|
* - `content_block_stop`: End of a content block
|
|
114
106
|
* - `error`: Error events with type and message
|
|
115
107
|
*
|
|
116
|
-
* @since 1.0.0
|
|
117
108
|
* @category models
|
|
109
|
+
* @since 4.0.0
|
|
118
110
|
*/
|
|
119
111
|
export type MessageStreamEvent =
|
|
120
112
|
| typeof Generated.BetaMessageStartEvent.Type
|
|
@@ -130,12 +122,21 @@ export type MessageStreamEvent =
|
|
|
130
122
|
// =============================================================================
|
|
131
123
|
|
|
132
124
|
/**
|
|
133
|
-
* Service
|
|
125
|
+
* Service tag for the Anthropic client.
|
|
126
|
+
*
|
|
127
|
+
* **When to use**
|
|
128
|
+
*
|
|
129
|
+
* Use when accessing or providing the Anthropic client service through Effect's
|
|
130
|
+
* context.
|
|
134
131
|
*
|
|
135
|
-
* @
|
|
136
|
-
* @
|
|
132
|
+
* @see {@link make} for constructing an Anthropic client effectfully
|
|
133
|
+
* @see {@link layer} for providing a client from explicit options
|
|
134
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
135
|
+
*
|
|
136
|
+
* @category services
|
|
137
|
+
* @since 4.0.0
|
|
137
138
|
*/
|
|
138
|
-
export class AnthropicClient extends
|
|
139
|
+
export class AnthropicClient extends Context.Service<AnthropicClient, Service>()(
|
|
139
140
|
"@effect/ai-anthropic/AnthropicClient"
|
|
140
141
|
) {}
|
|
141
142
|
|
|
@@ -144,43 +145,50 @@ export class AnthropicClient extends ServiceMap.Service<AnthropicClient, Service
|
|
|
144
145
|
// =============================================================================
|
|
145
146
|
|
|
146
147
|
/**
|
|
147
|
-
* Configuration
|
|
148
|
+
* Configuration for creating an Anthropic client.
|
|
148
149
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
150
|
+
* **When to use**
|
|
151
|
+
*
|
|
152
|
+
* Use when the Anthropic client settings are already available as values and
|
|
153
|
+
* should be passed directly to `make` or `layer`.
|
|
154
|
+
*
|
|
155
|
+
* **Details**
|
|
156
|
+
*
|
|
157
|
+
* These options configure the base Anthropic URL, the `x-api-key`
|
|
158
|
+
* authentication header, the `anthropic-version` header, and an optional
|
|
159
|
+
* transformation of the underlying `HttpClient`.
|
|
160
|
+
*
|
|
161
|
+
* @see {@link make} for constructing an Anthropic client from explicit options
|
|
162
|
+
* @see {@link layer} for providing an Anthropic client from explicit options
|
|
163
|
+
* @see {@link layerConfig} for loading Anthropic client settings from `Config`
|
|
164
|
+
*
|
|
165
|
+
* @category options
|
|
166
|
+
* @since 4.0.0
|
|
151
167
|
*/
|
|
152
168
|
export type Options = {
|
|
153
169
|
/**
|
|
154
|
-
* The Anthropic API key for authentication.
|
|
155
|
-
*
|
|
156
|
-
* If not provided, requests will be made without authentication (useful for
|
|
157
|
-
* proxied setups or testing).
|
|
170
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
171
|
+
* useful for proxied setups or testing.
|
|
158
172
|
*/
|
|
159
173
|
readonly apiKey?: Redacted.Redacted<string> | undefined
|
|
160
174
|
|
|
161
175
|
/**
|
|
162
|
-
* The base URL for the Anthropic API.
|
|
163
|
-
*
|
|
164
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
176
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
165
177
|
*
|
|
166
178
|
* @default "https://api.anthropic.com"
|
|
167
179
|
*/
|
|
168
180
|
readonly apiUrl?: string | undefined
|
|
169
181
|
|
|
170
182
|
/**
|
|
171
|
-
* The Anthropic API version header value.
|
|
172
|
-
*
|
|
173
|
-
* Controls which version of the API to use. See Anthropic's versioning
|
|
174
|
-
* documentation for available versions and their features.
|
|
183
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
175
184
|
*
|
|
176
185
|
* @default "2023-06-01"
|
|
177
186
|
*/
|
|
178
187
|
readonly apiVersion?: string | undefined
|
|
179
188
|
|
|
180
189
|
/**
|
|
181
|
-
* Optional transformer for the underlying HTTP client
|
|
182
|
-
*
|
|
183
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
190
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
191
|
+
* handling.
|
|
184
192
|
*/
|
|
185
193
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
|
|
186
194
|
}
|
|
@@ -196,16 +204,22 @@ const RedactedAnthropicHeaders = {
|
|
|
196
204
|
/**
|
|
197
205
|
* Creates an Anthropic client service with the given options.
|
|
198
206
|
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* - Request/response transformations via `AnthropicConfig`
|
|
207
|
+
* **When to use**
|
|
208
|
+
*
|
|
209
|
+
* Use when you have explicit configuration values and need an `Effect` that
|
|
210
|
+
* constructs the Anthropic client service, rather than providing it as a `Layer`.
|
|
204
211
|
*
|
|
205
|
-
*
|
|
212
|
+
* **Details**
|
|
213
|
+
*
|
|
214
|
+
* The client handles API key authentication via the `x-api-key` header, API versioning via the `anthropic-version`
|
|
215
|
+
* header, error mapping to the unified `AiError` type, and request/response transformations via `AnthropicConfig`. It
|
|
216
|
+
* requires an `HttpClient` in the context.
|
|
217
|
+
*
|
|
218
|
+
* @see {@link layer} for providing the client as a `Layer` from explicit options
|
|
219
|
+
* @see {@link layerConfig} for providing the client as a `Layer` with `Config`-based settings
|
|
206
220
|
*
|
|
207
|
-
* @since 1.0.0
|
|
208
221
|
* @category constructors
|
|
222
|
+
* @since 4.0.0
|
|
209
223
|
*/
|
|
210
224
|
export const make = Effect.fnUntraced(
|
|
211
225
|
function*(options: Options): Effect.fn.Return<Service, never, HttpClient.HttpClient> {
|
|
@@ -352,8 +366,16 @@ export const make = Effect.fnUntraced(
|
|
|
352
366
|
/**
|
|
353
367
|
* Creates a layer for the Anthropic client with the given options.
|
|
354
368
|
*
|
|
355
|
-
*
|
|
369
|
+
* **When to use**
|
|
370
|
+
*
|
|
371
|
+
* Use when you already have explicit `Options` values, such as an API key or
|
|
372
|
+
* custom API URL, and want to provide `AnthropicClient` as a `Layer`.
|
|
373
|
+
*
|
|
374
|
+
* @see {@link make} for constructing the client service effectfully
|
|
375
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
376
|
+
*
|
|
356
377
|
* @category layers
|
|
378
|
+
* @since 4.0.0
|
|
357
379
|
*/
|
|
358
380
|
export const layer = (options: Options): Layer.Layer<AnthropicClient, never, HttpClient.HttpClient> =>
|
|
359
381
|
Layer.effect(AnthropicClient, make(options))
|
|
@@ -362,41 +384,42 @@ export const layer = (options: Options): Layer.Layer<AnthropicClient, never, Htt
|
|
|
362
384
|
* Creates a layer for the Anthropic client, loading the requisite configuration
|
|
363
385
|
* via Effect's `Config` module.
|
|
364
386
|
*
|
|
365
|
-
*
|
|
387
|
+
* **When to use**
|
|
388
|
+
*
|
|
389
|
+
* Use when you want to provide the Anthropic client as a `Layer` with
|
|
390
|
+
* configuration loaded from Effect's `Config` module, such as from environment
|
|
391
|
+
* variables or a secrets provider.
|
|
392
|
+
*
|
|
393
|
+
* @see {@link layer} for providing the client from explicit options instead of `Config`
|
|
394
|
+
* @see {@link make} for constructing the client service effectfully
|
|
395
|
+
*
|
|
366
396
|
* @category layers
|
|
397
|
+
* @since 4.0.0
|
|
367
398
|
*/
|
|
368
399
|
export const layerConfig = (options?: {
|
|
369
400
|
/**
|
|
370
|
-
* The Anthropic API key for authentication.
|
|
371
|
-
*
|
|
372
|
-
* If not provided, requests will be made without authentication (useful for
|
|
373
|
-
* proxied setups or testing).
|
|
401
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
402
|
+
* useful for proxied setups or testing.
|
|
374
403
|
*/
|
|
375
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
404
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined
|
|
376
405
|
|
|
377
406
|
/**
|
|
378
|
-
* The base URL for the Anthropic API.
|
|
379
|
-
*
|
|
380
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
407
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
381
408
|
*
|
|
382
409
|
* @default "https://api.anthropic.com"
|
|
383
410
|
*/
|
|
384
411
|
readonly apiUrl?: Config.Config<string> | undefined
|
|
385
412
|
|
|
386
413
|
/**
|
|
387
|
-
* The Anthropic API version header value.
|
|
388
|
-
*
|
|
389
|
-
* Controls which version of the API to use. See Anthropic's versioning
|
|
390
|
-
* documentation for available versions and their features.
|
|
414
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
391
415
|
*
|
|
392
416
|
* @default "2023-06-01"
|
|
393
417
|
*/
|
|
394
418
|
readonly apiVersion?: Config.Config<string> | undefined
|
|
395
419
|
|
|
396
420
|
/**
|
|
397
|
-
* Optional transformer for the underlying HTTP client
|
|
398
|
-
*
|
|
399
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
421
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
422
|
+
* handling.
|
|
400
423
|
*/
|
|
401
424
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
|
|
402
425
|
}): Layer.Layer<AnthropicClient, Config.ConfigError, HttpClient.HttpClient> =>
|
package/src/AnthropicConfig.ts
CHANGED
|
@@ -1,35 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `AnthropicConfig` module lets a workflow temporarily customize the HTTP
|
|
3
|
+
* client used by generated Anthropic requests. It is used by
|
|
4
|
+
* `AnthropicClient` when request helpers run, so code can add middleware,
|
|
5
|
+
* logging, or other client changes without rebuilding the client layer.
|
|
6
|
+
*
|
|
7
|
+
* @since 4.0.0
|
|
3
8
|
*/
|
|
9
|
+
import * as Context from "effect/Context"
|
|
4
10
|
import * as Effect from "effect/Effect"
|
|
5
11
|
import { dual } from "effect/Function"
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
7
12
|
import type { HttpClient } from "effect/unstable/http/HttpClient"
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
|
-
*
|
|
15
|
+
* Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
|
|
16
|
+
*
|
|
17
|
+
* **When to use**
|
|
18
|
+
*
|
|
19
|
+
* Use when you need to provide or read Anthropic client configuration through
|
|
20
|
+
* Effect's context from a layer or integration.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
23
|
+
*
|
|
11
24
|
* @category services
|
|
25
|
+
* @since 4.0.0
|
|
12
26
|
*/
|
|
13
|
-
export class AnthropicConfig extends
|
|
27
|
+
export class AnthropicConfig extends Context.Service<
|
|
14
28
|
AnthropicConfig,
|
|
15
29
|
AnthropicConfig.Service
|
|
16
30
|
>()("@effect/ai-anthropic/AnthropicConfig") {
|
|
17
31
|
/**
|
|
18
|
-
*
|
|
32
|
+
* Gets the configured Anthropic service from the current context when present.
|
|
33
|
+
*
|
|
34
|
+
* @since 4.0.0
|
|
19
35
|
*/
|
|
20
36
|
static readonly getOrUndefined: Effect.Effect<typeof AnthropicConfig.Service | undefined> = Effect.map(
|
|
21
|
-
Effect.
|
|
37
|
+
Effect.context<never>(),
|
|
22
38
|
(services) => services.mapUnsafe.get(AnthropicConfig.key)
|
|
23
39
|
)
|
|
24
40
|
}
|
|
25
41
|
|
|
26
42
|
/**
|
|
27
|
-
*
|
|
43
|
+
* Namespace containing types associated with the `AnthropicConfig` service.
|
|
44
|
+
*
|
|
45
|
+
* @since 4.0.0
|
|
28
46
|
*/
|
|
29
47
|
export declare namespace AnthropicConfig {
|
|
30
48
|
/**
|
|
31
|
-
*
|
|
49
|
+
* Configuration provided through `AnthropicConfig`.
|
|
50
|
+
*
|
|
51
|
+
* **Details**
|
|
52
|
+
*
|
|
53
|
+
* Use `transformClient` to wrap or replace the `HttpClient` used by generated Anthropic API requests.
|
|
54
|
+
*
|
|
32
55
|
* @category models
|
|
56
|
+
* @since 4.0.0
|
|
33
57
|
*/
|
|
34
58
|
export interface Service {
|
|
35
59
|
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
|
|
@@ -37,18 +61,39 @@ export declare namespace AnthropicConfig {
|
|
|
37
61
|
}
|
|
38
62
|
|
|
39
63
|
/**
|
|
40
|
-
*
|
|
64
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
65
|
+
*
|
|
66
|
+
* **When to use**
|
|
67
|
+
*
|
|
68
|
+
* Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
|
|
69
|
+
* specific scope of an effectful program.
|
|
70
|
+
*
|
|
41
71
|
* @category configuration
|
|
72
|
+
* @since 4.0.0
|
|
42
73
|
*/
|
|
43
74
|
export const withClientTransform: {
|
|
44
75
|
/**
|
|
45
|
-
*
|
|
76
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
77
|
+
*
|
|
78
|
+
* **When to use**
|
|
79
|
+
*
|
|
80
|
+
* Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
|
|
81
|
+
* specific scope of an effectful program.
|
|
82
|
+
*
|
|
46
83
|
* @category configuration
|
|
84
|
+
* @since 4.0.0
|
|
47
85
|
*/
|
|
48
86
|
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
|
|
49
87
|
/**
|
|
50
|
-
*
|
|
88
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
89
|
+
*
|
|
90
|
+
* **When to use**
|
|
91
|
+
*
|
|
92
|
+
* Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
|
|
93
|
+
* specific scope of an effectful program.
|
|
94
|
+
*
|
|
51
95
|
* @category configuration
|
|
96
|
+
* @since 4.0.0
|
|
52
97
|
*/
|
|
53
98
|
<A, E, R>(
|
|
54
99
|
self: Effect.Effect<A, E, R>,
|
package/src/AnthropicError.ts
CHANGED
|
@@ -4,14 +4,22 @@
|
|
|
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
|
-
*
|
|
13
|
+
* **Details**
|
|
14
|
+
*
|
|
15
|
+
* Contains the Anthropic error type and request identifier copied from provider
|
|
16
|
+
* error responses when available. Either field may be `null` when Anthropic
|
|
17
|
+
* does not include it or the response cannot be decoded.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link AnthropicRateLimitMetadata} for rate-limit responses that also include parsed Anthropic rate-limit headers
|
|
20
|
+
*
|
|
14
21
|
* @category models
|
|
22
|
+
* @since 4.0.0
|
|
15
23
|
*/
|
|
16
24
|
export type AnthropicErrorMetadata = {
|
|
17
25
|
/**
|
|
@@ -27,11 +35,12 @@ export type AnthropicErrorMetadata = {
|
|
|
27
35
|
/**
|
|
28
36
|
* Anthropic-specific rate limit metadata fields.
|
|
29
37
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
38
|
+
* **Details**
|
|
39
|
+
*
|
|
40
|
+
* Extends base error metadata with rate limit-specific information from Anthropic's rate limit headers.
|
|
32
41
|
*
|
|
33
|
-
* @since 1.0.0
|
|
34
42
|
* @category models
|
|
43
|
+
* @since 4.0.0
|
|
35
44
|
*/
|
|
36
45
|
export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
|
|
37
46
|
/**
|
|
@@ -61,51 +70,143 @@ export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
|
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
declare module "effect/unstable/ai/AiError" {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Anthropic metadata attached to `RateLimitError` values.
|
|
75
|
+
*
|
|
76
|
+
* **Details**
|
|
77
|
+
*
|
|
78
|
+
* Includes request identifiers, Anthropic error types, and parsed request or token limit headers when the provider rejects a request due to rate limits.
|
|
79
|
+
*
|
|
80
|
+
* @category configuration
|
|
81
|
+
* @since 4.0.0
|
|
82
|
+
*/
|
|
83
|
+
export interface RateLimitErrorMetadata {
|
|
84
|
+
readonly anthropic?: AnthropicRateLimitMetadata | null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Anthropic metadata attached to `QuotaExhaustedError` values.
|
|
89
|
+
*
|
|
90
|
+
* **Details**
|
|
91
|
+
*
|
|
92
|
+
* Captures the Anthropic error type and request identifier for failures where the account or workspace has exhausted its available quota.
|
|
93
|
+
*
|
|
94
|
+
* @category configuration
|
|
95
|
+
* @since 4.0.0
|
|
96
|
+
*/
|
|
97
|
+
export interface QuotaExhaustedErrorMetadata {
|
|
98
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Anthropic metadata attached to `AuthenticationError` values.
|
|
103
|
+
*
|
|
104
|
+
* **Details**
|
|
105
|
+
*
|
|
106
|
+
* Preserves Anthropic error details for missing, invalid, or unauthorized API credentials while keeping the error in the shared AI error model.
|
|
107
|
+
*
|
|
108
|
+
* @category configuration
|
|
109
|
+
* @since 4.0.0
|
|
110
|
+
*/
|
|
111
|
+
export interface AuthenticationErrorMetadata {
|
|
112
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
68
113
|
}
|
|
69
114
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Anthropic metadata attached to `ContentPolicyError` values.
|
|
117
|
+
*
|
|
118
|
+
* **Details**
|
|
119
|
+
*
|
|
120
|
+
* Records Anthropic error details returned when a request or response is rejected by Anthropic safety or content policy enforcement.
|
|
121
|
+
*
|
|
122
|
+
* @category configuration
|
|
123
|
+
* @since 4.0.0
|
|
124
|
+
*/
|
|
125
|
+
export interface ContentPolicyErrorMetadata {
|
|
126
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
74
127
|
}
|
|
75
128
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Anthropic metadata attached to `InvalidRequestError` values.
|
|
131
|
+
*
|
|
132
|
+
* **Details**
|
|
133
|
+
*
|
|
134
|
+
* Provides the Anthropic error type and request identifier for malformed or unsupported requests rejected before model execution.
|
|
135
|
+
*
|
|
136
|
+
* @category configuration
|
|
137
|
+
* @since 4.0.0
|
|
138
|
+
*/
|
|
139
|
+
export interface InvalidRequestErrorMetadata {
|
|
140
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
80
141
|
}
|
|
81
142
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Anthropic metadata attached to `InternalProviderError` values.
|
|
145
|
+
*
|
|
146
|
+
* **Details**
|
|
147
|
+
*
|
|
148
|
+
* Preserves Anthropic request correlation data for provider-side failures that should be reported or investigated with Anthropic support.
|
|
149
|
+
*
|
|
150
|
+
* @category configuration
|
|
151
|
+
* @since 4.0.0
|
|
152
|
+
*/
|
|
153
|
+
export interface InternalProviderErrorMetadata {
|
|
154
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
86
155
|
}
|
|
87
156
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Anthropic metadata attached to `InvalidOutputError` values.
|
|
159
|
+
*
|
|
160
|
+
* **Details**
|
|
161
|
+
*
|
|
162
|
+
* Describes Anthropic-specific context for responses that could not be decoded or interpreted as valid AI output.
|
|
163
|
+
*
|
|
164
|
+
* @category configuration
|
|
165
|
+
* @since 4.0.0
|
|
166
|
+
*/
|
|
167
|
+
export interface InvalidOutputErrorMetadata {
|
|
168
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
92
169
|
}
|
|
93
170
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Anthropic metadata attached to `StructuredOutputError` values.
|
|
173
|
+
*
|
|
174
|
+
* **Details**
|
|
175
|
+
*
|
|
176
|
+
* Captures Anthropic error details for structured-output failures, including request correlation data useful when diagnosing schema-related responses.
|
|
177
|
+
*
|
|
178
|
+
* @category configuration
|
|
179
|
+
* @since 4.0.0
|
|
180
|
+
*/
|
|
181
|
+
export interface StructuredOutputErrorMetadata {
|
|
182
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
98
183
|
}
|
|
99
184
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Anthropic metadata attached to `UnsupportedSchemaError` values.
|
|
187
|
+
*
|
|
188
|
+
* **Details**
|
|
189
|
+
*
|
|
190
|
+
* Provides Anthropic error details for schemas that cannot be represented by or submitted to the Anthropic API.
|
|
191
|
+
*
|
|
192
|
+
* @category configuration
|
|
193
|
+
* @since 4.0.0
|
|
194
|
+
*/
|
|
195
|
+
export interface UnsupportedSchemaErrorMetadata {
|
|
196
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
104
197
|
}
|
|
105
198
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Anthropic metadata attached to `UnknownError` values.
|
|
201
|
+
*
|
|
202
|
+
* **Details**
|
|
203
|
+
*
|
|
204
|
+
* Retains the Anthropic error type and request identifier when a provider response cannot be classified as a more specific AI error.
|
|
205
|
+
*
|
|
206
|
+
* @category configuration
|
|
207
|
+
* @since 4.0.0
|
|
208
|
+
*/
|
|
209
|
+
export interface UnknownErrorMetadata {
|
|
210
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
110
211
|
}
|
|
111
212
|
}
|