@effect/ai-anthropic 4.0.0-beta.8 → 4.0.0-beta.81
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 +93 -74
- 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 +114 -104
- 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,47 +33,31 @@ 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
|
-
readonly streamRequest: <
|
|
58
|
-
|
|
59
|
-
readonly id?: string | undefined
|
|
60
|
-
readonly event: string
|
|
61
|
-
readonly data: string
|
|
62
|
-
},
|
|
63
|
-
DecodingServices
|
|
64
|
-
>(
|
|
65
|
-
schema: Schema.Decoder<Type, DecodingServices>
|
|
51
|
+
readonly streamRequest: <S extends Sse.EventCodec>(
|
|
52
|
+
schema: S
|
|
66
53
|
) => (request: HttpClientRequest.HttpClientRequest) => Stream.Stream<
|
|
67
|
-
Type,
|
|
54
|
+
S["Type"],
|
|
68
55
|
HttpClientError.HttpClientError | Schema.SchemaError | Sse.Retry,
|
|
69
|
-
DecodingServices
|
|
56
|
+
S["DecodingServices"]
|
|
70
57
|
>
|
|
71
58
|
|
|
72
59
|
/**
|
|
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.
|
|
60
|
+
* Creates a message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
77
61
|
*/
|
|
78
62
|
readonly createMessage: (options: {
|
|
79
63
|
readonly payload: typeof Generated.BetaCreateMessageParams.Encoded
|
|
@@ -84,12 +68,12 @@ export interface Service {
|
|
|
84
68
|
>
|
|
85
69
|
|
|
86
70
|
/**
|
|
87
|
-
* Creates a streaming message using the Anthropic Messages API.
|
|
71
|
+
* Creates a streaming message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
72
|
+
*
|
|
73
|
+
* **Details**
|
|
88
74
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* when a `message_stop` event is received. All errors are mapped to the
|
|
92
|
-
* unified `AiError` type.
|
|
75
|
+
* The returned Effect yields the HTTP response and a stream of events as the model generates its response. The stream
|
|
76
|
+
* automatically terminates when a `message_stop` event is received.
|
|
93
77
|
*/
|
|
94
78
|
readonly createMessageStream: (options: {
|
|
95
79
|
readonly payload: Omit<typeof Generated.BetaCreateMessageParams.Encoded, "stream">
|
|
@@ -101,8 +85,9 @@ export interface Service {
|
|
|
101
85
|
}
|
|
102
86
|
|
|
103
87
|
/**
|
|
104
|
-
* Represents an event received from the Anthropic Messages API during a
|
|
105
|
-
*
|
|
88
|
+
* Represents an event received from the Anthropic Messages API during a streaming request.
|
|
89
|
+
*
|
|
90
|
+
* **Details**
|
|
106
91
|
*
|
|
107
92
|
* Events include:
|
|
108
93
|
* - `message_start`: Initial event containing message metadata
|
|
@@ -113,8 +98,8 @@ export interface Service {
|
|
|
113
98
|
* - `content_block_stop`: End of a content block
|
|
114
99
|
* - `error`: Error events with type and message
|
|
115
100
|
*
|
|
116
|
-
* @since 1.0.0
|
|
117
101
|
* @category models
|
|
102
|
+
* @since 4.0.0
|
|
118
103
|
*/
|
|
119
104
|
export type MessageStreamEvent =
|
|
120
105
|
| typeof Generated.BetaMessageStartEvent.Type
|
|
@@ -130,12 +115,21 @@ export type MessageStreamEvent =
|
|
|
130
115
|
// =============================================================================
|
|
131
116
|
|
|
132
117
|
/**
|
|
133
|
-
* Service
|
|
118
|
+
* Service tag for the Anthropic client.
|
|
119
|
+
*
|
|
120
|
+
* **When to use**
|
|
121
|
+
*
|
|
122
|
+
* Use when accessing or providing the Anthropic client service through Effect's
|
|
123
|
+
* context.
|
|
124
|
+
*
|
|
125
|
+
* @see {@link make} for constructing an Anthropic client effectfully
|
|
126
|
+
* @see {@link layer} for providing a client from explicit options
|
|
127
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
134
128
|
*
|
|
135
|
-
* @
|
|
136
|
-
* @
|
|
129
|
+
* @category services
|
|
130
|
+
* @since 4.0.0
|
|
137
131
|
*/
|
|
138
|
-
export class AnthropicClient extends
|
|
132
|
+
export class AnthropicClient extends Context.Service<AnthropicClient, Service>()(
|
|
139
133
|
"@effect/ai-anthropic/AnthropicClient"
|
|
140
134
|
) {}
|
|
141
135
|
|
|
@@ -144,43 +138,50 @@ export class AnthropicClient extends ServiceMap.Service<AnthropicClient, Service
|
|
|
144
138
|
// =============================================================================
|
|
145
139
|
|
|
146
140
|
/**
|
|
147
|
-
* Configuration
|
|
141
|
+
* Configuration for creating an Anthropic client.
|
|
148
142
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
143
|
+
* **When to use**
|
|
144
|
+
*
|
|
145
|
+
* Use when the Anthropic client settings are already available as values and
|
|
146
|
+
* should be passed directly to `make` or `layer`.
|
|
147
|
+
*
|
|
148
|
+
* **Details**
|
|
149
|
+
*
|
|
150
|
+
* These options configure the base Anthropic URL, the `x-api-key`
|
|
151
|
+
* authentication header, the `anthropic-version` header, and an optional
|
|
152
|
+
* transformation of the underlying `HttpClient`.
|
|
153
|
+
*
|
|
154
|
+
* @see {@link make} for constructing an Anthropic client from explicit options
|
|
155
|
+
* @see {@link layer} for providing an Anthropic client from explicit options
|
|
156
|
+
* @see {@link layerConfig} for loading Anthropic client settings from `Config`
|
|
157
|
+
*
|
|
158
|
+
* @category options
|
|
159
|
+
* @since 4.0.0
|
|
151
160
|
*/
|
|
152
161
|
export type Options = {
|
|
153
162
|
/**
|
|
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).
|
|
163
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
164
|
+
* useful for proxied setups or testing.
|
|
158
165
|
*/
|
|
159
166
|
readonly apiKey?: Redacted.Redacted<string> | undefined
|
|
160
167
|
|
|
161
168
|
/**
|
|
162
|
-
* The base URL for the Anthropic API.
|
|
163
|
-
*
|
|
164
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
169
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
165
170
|
*
|
|
166
171
|
* @default "https://api.anthropic.com"
|
|
167
172
|
*/
|
|
168
173
|
readonly apiUrl?: string | undefined
|
|
169
174
|
|
|
170
175
|
/**
|
|
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.
|
|
176
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
175
177
|
*
|
|
176
178
|
* @default "2023-06-01"
|
|
177
179
|
*/
|
|
178
180
|
readonly apiVersion?: string | undefined
|
|
179
181
|
|
|
180
182
|
/**
|
|
181
|
-
* Optional transformer for the underlying HTTP client
|
|
182
|
-
*
|
|
183
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
183
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
184
|
+
* handling.
|
|
184
185
|
*/
|
|
185
186
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
|
|
186
187
|
}
|
|
@@ -196,16 +197,22 @@ const RedactedAnthropicHeaders = {
|
|
|
196
197
|
/**
|
|
197
198
|
* Creates an Anthropic client service with the given options.
|
|
198
199
|
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
200
|
+
* **When to use**
|
|
201
|
+
*
|
|
202
|
+
* Use when you have explicit configuration values and need an `Effect` that
|
|
203
|
+
* constructs the Anthropic client service, rather than providing it as a `Layer`.
|
|
204
|
+
*
|
|
205
|
+
* **Details**
|
|
204
206
|
*
|
|
205
|
-
*
|
|
207
|
+
* The client handles API key authentication via the `x-api-key` header, API versioning via the `anthropic-version`
|
|
208
|
+
* header, error mapping to the unified `AiError` type, and request/response transformations via `AnthropicConfig`. It
|
|
209
|
+
* requires an `HttpClient` in the context.
|
|
210
|
+
*
|
|
211
|
+
* @see {@link layer} for providing the client as a `Layer` from explicit options
|
|
212
|
+
* @see {@link layerConfig} for providing the client as a `Layer` with `Config`-based settings
|
|
206
213
|
*
|
|
207
|
-
* @since 1.0.0
|
|
208
214
|
* @category constructors
|
|
215
|
+
* @since 4.0.0
|
|
209
216
|
*/
|
|
210
217
|
export const make = Effect.fnUntraced(
|
|
211
218
|
function*(options: Options): Effect.fn.Return<Service, never, HttpClient.HttpClient> {
|
|
@@ -243,25 +250,19 @@ export const make = Effect.fnUntraced(
|
|
|
243
250
|
|
|
244
251
|
const httpClientOk = HttpClient.filterStatusOk(httpClient)
|
|
245
252
|
|
|
246
|
-
const streamRequest =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
httpClientOk.execute(request).pipe(
|
|
260
|
-
Effect.map((response) => response.stream),
|
|
261
|
-
Stream.unwrap,
|
|
262
|
-
Stream.decodeText,
|
|
263
|
-
Stream.pipeThroughChannel(Sse.decodeSchema(schema))
|
|
264
|
-
)
|
|
253
|
+
const streamRequest =
|
|
254
|
+
<S extends Sse.EventCodec>(schema: S) =>
|
|
255
|
+
(request: HttpClientRequest.HttpClientRequest): Stream.Stream<
|
|
256
|
+
S["Type"],
|
|
257
|
+
HttpClientError.HttpClientError | Schema.SchemaError | Sse.Retry,
|
|
258
|
+
S["DecodingServices"]
|
|
259
|
+
> =>
|
|
260
|
+
httpClientOk.execute(request).pipe(
|
|
261
|
+
Effect.map((response) => response.stream),
|
|
262
|
+
Stream.unwrap,
|
|
263
|
+
Stream.decodeText,
|
|
264
|
+
Stream.pipeThroughChannel(Sse.decodeSchema(schema))
|
|
265
|
+
)
|
|
265
266
|
|
|
266
267
|
const createMessage = (options: {
|
|
267
268
|
readonly payload: typeof Generated.BetaCreateMessageParams.Encoded
|
|
@@ -352,8 +353,16 @@ export const make = Effect.fnUntraced(
|
|
|
352
353
|
/**
|
|
353
354
|
* Creates a layer for the Anthropic client with the given options.
|
|
354
355
|
*
|
|
355
|
-
*
|
|
356
|
+
* **When to use**
|
|
357
|
+
*
|
|
358
|
+
* Use when you already have explicit `Options` values, such as an API key or
|
|
359
|
+
* custom API URL, and want to provide `AnthropicClient` as a `Layer`.
|
|
360
|
+
*
|
|
361
|
+
* @see {@link make} for constructing the client service effectfully
|
|
362
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
363
|
+
*
|
|
356
364
|
* @category layers
|
|
365
|
+
* @since 4.0.0
|
|
357
366
|
*/
|
|
358
367
|
export const layer = (options: Options): Layer.Layer<AnthropicClient, never, HttpClient.HttpClient> =>
|
|
359
368
|
Layer.effect(AnthropicClient, make(options))
|
|
@@ -362,41 +371,42 @@ export const layer = (options: Options): Layer.Layer<AnthropicClient, never, Htt
|
|
|
362
371
|
* Creates a layer for the Anthropic client, loading the requisite configuration
|
|
363
372
|
* via Effect's `Config` module.
|
|
364
373
|
*
|
|
365
|
-
*
|
|
374
|
+
* **When to use**
|
|
375
|
+
*
|
|
376
|
+
* Use when you want to provide the Anthropic client as a `Layer` with
|
|
377
|
+
* configuration loaded from Effect's `Config` module, such as from environment
|
|
378
|
+
* variables or a secrets provider.
|
|
379
|
+
*
|
|
380
|
+
* @see {@link layer} for providing the client from explicit options instead of `Config`
|
|
381
|
+
* @see {@link make} for constructing the client service effectfully
|
|
382
|
+
*
|
|
366
383
|
* @category layers
|
|
384
|
+
* @since 4.0.0
|
|
367
385
|
*/
|
|
368
386
|
export const layerConfig = (options?: {
|
|
369
387
|
/**
|
|
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).
|
|
388
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
389
|
+
* useful for proxied setups or testing.
|
|
374
390
|
*/
|
|
375
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
391
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined
|
|
376
392
|
|
|
377
393
|
/**
|
|
378
|
-
* The base URL for the Anthropic API.
|
|
379
|
-
*
|
|
380
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
394
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
381
395
|
*
|
|
382
396
|
* @default "https://api.anthropic.com"
|
|
383
397
|
*/
|
|
384
398
|
readonly apiUrl?: Config.Config<string> | undefined
|
|
385
399
|
|
|
386
400
|
/**
|
|
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.
|
|
401
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
391
402
|
*
|
|
392
403
|
* @default "2023-06-01"
|
|
393
404
|
*/
|
|
394
405
|
readonly apiVersion?: Config.Config<string> | undefined
|
|
395
406
|
|
|
396
407
|
/**
|
|
397
|
-
* Optional transformer for the underlying HTTP client
|
|
398
|
-
*
|
|
399
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
408
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
409
|
+
* handling.
|
|
400
410
|
*/
|
|
401
411
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
|
|
402
412
|
}): 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
|
}
|