@effect/ai-anthropic 4.0.0-beta.7 → 4.0.0-beta.70
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 +40 -66
- package/dist/AnthropicClient.d.ts.map +1 -1
- package/dist/AnthropicClient.js +12 -14
- package/dist/AnthropicClient.js.map +1 -1
- package/dist/AnthropicConfig.d.ts +46 -10
- package/dist/AnthropicConfig.d.ts.map +1 -1
- package/dist/AnthropicConfig.js +31 -7
- package/dist/AnthropicConfig.js.map +1 -1
- package/dist/AnthropicError.d.ts +128 -37
- package/dist/AnthropicError.d.ts.map +1 -1
- package/dist/AnthropicError.js +1 -1
- package/dist/AnthropicLanguageModel.d.ts +281 -66
- package/dist/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.js +50 -14
- package/dist/AnthropicLanguageModel.js.map +1 -1
- package/dist/AnthropicTelemetry.d.ts +23 -16
- package/dist/AnthropicTelemetry.d.ts.map +1 -1
- package/dist/AnthropicTelemetry.js +6 -4
- package/dist/AnthropicTelemetry.js.map +1 -1
- package/dist/AnthropicTool.d.ts +298 -138
- package/dist/AnthropicTool.d.ts.map +1 -1
- package/dist/AnthropicTool.js +141 -87
- package/dist/AnthropicTool.js.map +1 -1
- package/dist/Generated.d.ts +11661 -5260
- package/dist/Generated.d.ts.map +1 -1
- package/dist/Generated.js +2318 -915
- package/dist/Generated.js.map +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/dist/internal/errors.js +7 -7
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/AnthropicClient.ts +41 -67
- package/src/AnthropicConfig.ts +47 -11
- package/src/AnthropicError.ts +130 -37
- package/src/AnthropicLanguageModel.ts +274 -33
- package/src/AnthropicTelemetry.ts +24 -17
- package/src/AnthropicTool.ts +293 -133
- package/src/Generated.ts +3751 -1815
- package/src/index.ts +52 -8
- package/src/internal/errors.ts +9 -7
package/src/AnthropicConfig.ts
CHANGED
|
@@ -1,35 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `AnthropicConfig` module provides contextual configuration for the
|
|
3
|
+
* Anthropic AI provider integration. It is used to customize the generated
|
|
4
|
+
* Anthropic HTTP client without changing individual request code.
|
|
5
|
+
*
|
|
6
|
+
* **Common tasks**
|
|
7
|
+
*
|
|
8
|
+
* - Provide a shared `HttpClient` transformation for Anthropic requests
|
|
9
|
+
* - Add provider-specific concerns such as request instrumentation, proxying,
|
|
10
|
+
* retries, or header manipulation
|
|
11
|
+
* - Scope a client transformation to a single effect with {@link withClientTransform}
|
|
12
|
+
*
|
|
13
|
+
* **Gotchas**
|
|
14
|
+
*
|
|
15
|
+
* - Configuration is read from the Effect context, so overrides only apply to
|
|
16
|
+
* effects run inside the configured scope
|
|
17
|
+
* - `withClientTransform` replaces the current `transformClient` value while
|
|
18
|
+
* preserving any other Anthropic configuration fields
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
22
|
+
import * as Context from "effect/Context"
|
|
4
23
|
import * as Effect from "effect/Effect"
|
|
5
24
|
import { dual } from "effect/Function"
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
7
25
|
import type { HttpClient } from "effect/unstable/http/HttpClient"
|
|
8
26
|
|
|
9
27
|
/**
|
|
10
|
-
*
|
|
28
|
+
* Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
|
|
29
|
+
*
|
|
11
30
|
* @category services
|
|
31
|
+
* @since 4.0.0
|
|
12
32
|
*/
|
|
13
|
-
export class AnthropicConfig extends
|
|
33
|
+
export class AnthropicConfig extends Context.Service<
|
|
14
34
|
AnthropicConfig,
|
|
15
35
|
AnthropicConfig.Service
|
|
16
36
|
>()("@effect/ai-anthropic/AnthropicConfig") {
|
|
17
37
|
/**
|
|
18
|
-
*
|
|
38
|
+
* Gets the configured Anthropic service from the current context when present.
|
|
39
|
+
*
|
|
40
|
+
* @since 4.0.0
|
|
19
41
|
*/
|
|
20
42
|
static readonly getOrUndefined: Effect.Effect<typeof AnthropicConfig.Service | undefined> = Effect.map(
|
|
21
|
-
Effect.
|
|
43
|
+
Effect.context<never>(),
|
|
22
44
|
(services) => services.mapUnsafe.get(AnthropicConfig.key)
|
|
23
45
|
)
|
|
24
46
|
}
|
|
25
47
|
|
|
26
48
|
/**
|
|
27
|
-
*
|
|
49
|
+
* Namespace containing types associated with the `AnthropicConfig` service.
|
|
50
|
+
*
|
|
51
|
+
* @since 4.0.0
|
|
28
52
|
*/
|
|
29
53
|
export declare namespace AnthropicConfig {
|
|
30
54
|
/**
|
|
31
|
-
*
|
|
55
|
+
* Configuration provided through `AnthropicConfig`.
|
|
56
|
+
*
|
|
57
|
+
* **Details**
|
|
58
|
+
*
|
|
59
|
+
* Use `transformClient` to wrap or replace the `HttpClient` used by generated Anthropic API requests.
|
|
60
|
+
*
|
|
32
61
|
* @category models
|
|
62
|
+
* @since 4.0.0
|
|
33
63
|
*/
|
|
34
64
|
export interface Service {
|
|
35
65
|
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
|
|
@@ -37,18 +67,24 @@ export declare namespace AnthropicConfig {
|
|
|
37
67
|
}
|
|
38
68
|
|
|
39
69
|
/**
|
|
40
|
-
*
|
|
70
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
71
|
+
*
|
|
41
72
|
* @category configuration
|
|
73
|
+
* @since 4.0.0
|
|
42
74
|
*/
|
|
43
75
|
export const withClientTransform: {
|
|
44
76
|
/**
|
|
45
|
-
*
|
|
77
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
78
|
+
*
|
|
46
79
|
* @category configuration
|
|
80
|
+
* @since 4.0.0
|
|
47
81
|
*/
|
|
48
82
|
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
|
|
49
83
|
/**
|
|
50
|
-
*
|
|
84
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
85
|
+
*
|
|
51
86
|
* @category configuration
|
|
87
|
+
* @since 4.0.0
|
|
52
88
|
*/
|
|
53
89
|
<A, E, R>(
|
|
54
90
|
self: Effect.Effect<A, E, R>,
|
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
|
/**
|
|
@@ -27,11 +27,12 @@ export type AnthropicErrorMetadata = {
|
|
|
27
27
|
/**
|
|
28
28
|
* Anthropic-specific rate limit metadata fields.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* **Details**
|
|
31
|
+
*
|
|
32
|
+
* Extends base error metadata with rate limit-specific information from Anthropic's rate limit headers.
|
|
32
33
|
*
|
|
33
|
-
* @since 1.0.0
|
|
34
34
|
* @category models
|
|
35
|
+
* @since 4.0.0
|
|
35
36
|
*/
|
|
36
37
|
export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
|
|
37
38
|
/**
|
|
@@ -61,51 +62,143 @@ export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
declare module "effect/unstable/ai/AiError" {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Anthropic metadata attached to `RateLimitError` values.
|
|
67
|
+
*
|
|
68
|
+
* **Details**
|
|
69
|
+
*
|
|
70
|
+
* Includes request identifiers, Anthropic error types, and parsed request or token limit headers when the provider rejects a request due to rate limits.
|
|
71
|
+
*
|
|
72
|
+
* @category configuration
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
export interface RateLimitErrorMetadata {
|
|
76
|
+
readonly anthropic?: AnthropicRateLimitMetadata | null
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Anthropic metadata attached to `QuotaExhaustedError` values.
|
|
81
|
+
*
|
|
82
|
+
* **Details**
|
|
83
|
+
*
|
|
84
|
+
* Captures the Anthropic error type and request identifier for failures where the account or workspace has exhausted its available quota.
|
|
85
|
+
*
|
|
86
|
+
* @category configuration
|
|
87
|
+
* @since 4.0.0
|
|
88
|
+
*/
|
|
89
|
+
export interface QuotaExhaustedErrorMetadata {
|
|
90
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
74
91
|
}
|
|
75
92
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Anthropic metadata attached to `AuthenticationError` values.
|
|
95
|
+
*
|
|
96
|
+
* **Details**
|
|
97
|
+
*
|
|
98
|
+
* Preserves Anthropic error details for missing, invalid, or unauthorized API credentials while keeping the error in the shared AI error model.
|
|
99
|
+
*
|
|
100
|
+
* @category configuration
|
|
101
|
+
* @since 4.0.0
|
|
102
|
+
*/
|
|
103
|
+
export interface AuthenticationErrorMetadata {
|
|
104
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
80
105
|
}
|
|
81
106
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Anthropic metadata attached to `ContentPolicyError` values.
|
|
109
|
+
*
|
|
110
|
+
* **Details**
|
|
111
|
+
*
|
|
112
|
+
* Records Anthropic error details returned when a request or response is rejected by Anthropic safety or content policy enforcement.
|
|
113
|
+
*
|
|
114
|
+
* @category configuration
|
|
115
|
+
* @since 4.0.0
|
|
116
|
+
*/
|
|
117
|
+
export interface ContentPolicyErrorMetadata {
|
|
118
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
86
119
|
}
|
|
87
120
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Anthropic metadata attached to `InvalidRequestError` values.
|
|
123
|
+
*
|
|
124
|
+
* **Details**
|
|
125
|
+
*
|
|
126
|
+
* Provides the Anthropic error type and request identifier for malformed or unsupported requests rejected before model execution.
|
|
127
|
+
*
|
|
128
|
+
* @category configuration
|
|
129
|
+
* @since 4.0.0
|
|
130
|
+
*/
|
|
131
|
+
export interface InvalidRequestErrorMetadata {
|
|
132
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
92
133
|
}
|
|
93
134
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Anthropic metadata attached to `InternalProviderError` values.
|
|
137
|
+
*
|
|
138
|
+
* **Details**
|
|
139
|
+
*
|
|
140
|
+
* Preserves Anthropic request correlation data for provider-side failures that should be reported or investigated with Anthropic support.
|
|
141
|
+
*
|
|
142
|
+
* @category configuration
|
|
143
|
+
* @since 4.0.0
|
|
144
|
+
*/
|
|
145
|
+
export interface InternalProviderErrorMetadata {
|
|
146
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
98
147
|
}
|
|
99
148
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Anthropic metadata attached to `InvalidOutputError` values.
|
|
151
|
+
*
|
|
152
|
+
* **Details**
|
|
153
|
+
*
|
|
154
|
+
* Describes Anthropic-specific context for responses that could not be decoded or interpreted as valid AI output.
|
|
155
|
+
*
|
|
156
|
+
* @category configuration
|
|
157
|
+
* @since 4.0.0
|
|
158
|
+
*/
|
|
159
|
+
export interface InvalidOutputErrorMetadata {
|
|
160
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Anthropic metadata attached to `StructuredOutputError` values.
|
|
165
|
+
*
|
|
166
|
+
* **Details**
|
|
167
|
+
*
|
|
168
|
+
* Captures Anthropic error details for structured-output failures, including request correlation data useful when diagnosing schema-related responses.
|
|
169
|
+
*
|
|
170
|
+
* @category configuration
|
|
171
|
+
* @since 4.0.0
|
|
172
|
+
*/
|
|
173
|
+
export interface StructuredOutputErrorMetadata {
|
|
174
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
104
175
|
}
|
|
105
176
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Anthropic metadata attached to `UnsupportedSchemaError` values.
|
|
179
|
+
*
|
|
180
|
+
* **Details**
|
|
181
|
+
*
|
|
182
|
+
* Provides Anthropic error details for schemas that cannot be represented by or submitted to the Anthropic API.
|
|
183
|
+
*
|
|
184
|
+
* @category configuration
|
|
185
|
+
* @since 4.0.0
|
|
186
|
+
*/
|
|
187
|
+
export interface UnsupportedSchemaErrorMetadata {
|
|
188
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Anthropic metadata attached to `UnknownError` values.
|
|
193
|
+
*
|
|
194
|
+
* **Details**
|
|
195
|
+
*
|
|
196
|
+
* Retains the Anthropic error type and request identifier when a provider response cannot be classified as a more specific AI error.
|
|
197
|
+
*
|
|
198
|
+
* @category configuration
|
|
199
|
+
* @since 4.0.0
|
|
200
|
+
*/
|
|
201
|
+
export interface UnknownErrorMetadata {
|
|
202
|
+
readonly anthropic?: AnthropicErrorMetadata | null
|
|
110
203
|
}
|
|
111
204
|
}
|