@effect/ai-anthropic 4.0.0-beta.7 → 4.0.0-beta.71

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.
Files changed (43) hide show
  1. package/dist/AnthropicClient.d.ts +89 -66
  2. package/dist/AnthropicClient.d.ts.map +1 -1
  3. package/dist/AnthropicClient.js +75 -17
  4. package/dist/AnthropicClient.js.map +1 -1
  5. package/dist/AnthropicConfig.d.ts +68 -10
  6. package/dist/AnthropicConfig.d.ts.map +1 -1
  7. package/dist/AnthropicConfig.js +43 -7
  8. package/dist/AnthropicConfig.js.map +1 -1
  9. package/dist/AnthropicError.d.ts +136 -37
  10. package/dist/AnthropicError.d.ts.map +1 -1
  11. package/dist/AnthropicError.js +1 -1
  12. package/dist/AnthropicLanguageModel.d.ts +384 -71
  13. package/dist/AnthropicLanguageModel.d.ts.map +1 -1
  14. package/dist/AnthropicLanguageModel.js +102 -16
  15. package/dist/AnthropicLanguageModel.js.map +1 -1
  16. package/dist/AnthropicTelemetry.d.ts +42 -15
  17. package/dist/AnthropicTelemetry.d.ts.map +1 -1
  18. package/dist/AnthropicTelemetry.js +44 -8
  19. package/dist/AnthropicTelemetry.js.map +1 -1
  20. package/dist/AnthropicTool.d.ts +1116 -183
  21. package/dist/AnthropicTool.d.ts.map +1 -1
  22. package/dist/AnthropicTool.js +818 -129
  23. package/dist/AnthropicTool.js.map +1 -1
  24. package/dist/Generated.d.ts +11661 -5260
  25. package/dist/Generated.d.ts.map +1 -1
  26. package/dist/Generated.js +2318 -915
  27. package/dist/Generated.js.map +1 -1
  28. package/dist/index.d.ts +8 -29
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +8 -29
  31. package/dist/index.js.map +1 -1
  32. package/dist/internal/errors.js +7 -7
  33. package/dist/internal/errors.js.map +1 -1
  34. package/package.json +3 -3
  35. package/src/AnthropicClient.ts +119 -70
  36. package/src/AnthropicConfig.ts +69 -11
  37. package/src/AnthropicError.ts +138 -37
  38. package/src/AnthropicLanguageModel.ts +405 -38
  39. package/src/AnthropicTelemetry.ts +76 -20
  40. package/src/AnthropicTool.ts +1109 -176
  41. package/src/Generated.ts +3751 -1815
  42. package/src/index.ts +8 -29
  43. package/src/internal/errors.ts +9 -7
@@ -1,35 +1,72 @@
1
1
  /**
2
- * @since 1.0.0
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
- * @since 1.0.0
28
+ * Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
29
+ *
30
+ * **When to use**
31
+ *
32
+ * Use when a layer or integration needs to provide or read Anthropic client
33
+ * configuration through Effect's context.
34
+ *
35
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
36
+ *
11
37
  * @category services
38
+ * @since 4.0.0
12
39
  */
13
- export class AnthropicConfig extends ServiceMap.Service<
40
+ export class AnthropicConfig extends Context.Service<
14
41
  AnthropicConfig,
15
42
  AnthropicConfig.Service
16
43
  >()("@effect/ai-anthropic/AnthropicConfig") {
17
44
  /**
18
- * @since 1.0.0
45
+ * Gets the configured Anthropic service from the current context when present.
46
+ *
47
+ * @since 4.0.0
19
48
  */
20
49
  static readonly getOrUndefined: Effect.Effect<typeof AnthropicConfig.Service | undefined> = Effect.map(
21
- Effect.services<never>(),
50
+ Effect.context<never>(),
22
51
  (services) => services.mapUnsafe.get(AnthropicConfig.key)
23
52
  )
24
53
  }
25
54
 
26
55
  /**
27
- * @since 1.0.0
56
+ * Namespace containing types associated with the `AnthropicConfig` service.
57
+ *
58
+ * @since 4.0.0
28
59
  */
29
60
  export declare namespace AnthropicConfig {
30
61
  /**
31
- * @since 1.0.0
62
+ * Configuration provided through `AnthropicConfig`.
63
+ *
64
+ * **Details**
65
+ *
66
+ * Use `transformClient` to wrap or replace the `HttpClient` used by generated Anthropic API requests.
67
+ *
32
68
  * @category models
69
+ * @since 4.0.0
33
70
  */
34
71
  export interface Service {
35
72
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
@@ -37,18 +74,39 @@ export declare namespace AnthropicConfig {
37
74
  }
38
75
 
39
76
  /**
40
- * @since 1.0.0
77
+ * Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
78
+ *
79
+ * **When to use**
80
+ *
81
+ * Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
82
+ * specific scope of an effectful program.
83
+ *
41
84
  * @category configuration
85
+ * @since 4.0.0
42
86
  */
43
87
  export const withClientTransform: {
44
88
  /**
45
- * @since 1.0.0
89
+ * Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
90
+ *
91
+ * **When to use**
92
+ *
93
+ * Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
94
+ * specific scope of an effectful program.
95
+ *
46
96
  * @category configuration
97
+ * @since 4.0.0
47
98
  */
48
99
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
49
100
  /**
50
- * @since 1.0.0
101
+ * Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
102
+ *
103
+ * **When to use**
104
+ *
105
+ * Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
106
+ * specific scope of an effectful program.
107
+ *
51
108
  * @category configuration
109
+ * @since 4.0.0
52
110
  */
53
111
  <A, E, R>(
54
112
  self: Effect.Effect<A, E, R>,
@@ -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 1.0.0
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
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
- * Extends base error metadata with rate limit specific information from
31
- * Anthropic's rate limit headers.
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
- export interface RateLimitError {
65
- readonly metadata: {
66
- readonly anthropic?: AnthropicRateLimitMetadata | null
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
- export interface QuotaExhaustedError {
71
- readonly metadata: {
72
- readonly anthropic?: AnthropicErrorMetadata | null
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
- export interface AuthenticationError {
77
- readonly metadata: {
78
- readonly anthropic?: AnthropicErrorMetadata | null
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
- export interface ContentPolicyError {
83
- readonly metadata: {
84
- readonly anthropic?: AnthropicErrorMetadata | null
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
- export interface InvalidRequestError {
89
- readonly metadata: {
90
- readonly anthropic?: AnthropicErrorMetadata | null
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
- export interface InternalProviderError {
95
- readonly metadata: {
96
- readonly anthropic?: AnthropicErrorMetadata | null
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
- export interface InvalidOutputError {
101
- readonly metadata: {
102
- readonly anthropic?: AnthropicErrorMetadata | null
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
- export interface UnknownError {
107
- readonly metadata: {
108
- readonly anthropic?: AnthropicErrorMetadata | null
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
  }