@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.
Files changed (43) hide show
  1. package/dist/AnthropicClient.d.ts +40 -66
  2. package/dist/AnthropicClient.d.ts.map +1 -1
  3. package/dist/AnthropicClient.js +12 -14
  4. package/dist/AnthropicClient.js.map +1 -1
  5. package/dist/AnthropicConfig.d.ts +46 -10
  6. package/dist/AnthropicConfig.d.ts.map +1 -1
  7. package/dist/AnthropicConfig.js +31 -7
  8. package/dist/AnthropicConfig.js.map +1 -1
  9. package/dist/AnthropicError.d.ts +128 -37
  10. package/dist/AnthropicError.d.ts.map +1 -1
  11. package/dist/AnthropicError.js +1 -1
  12. package/dist/AnthropicLanguageModel.d.ts +281 -66
  13. package/dist/AnthropicLanguageModel.d.ts.map +1 -1
  14. package/dist/AnthropicLanguageModel.js +50 -14
  15. package/dist/AnthropicLanguageModel.js.map +1 -1
  16. package/dist/AnthropicTelemetry.d.ts +23 -16
  17. package/dist/AnthropicTelemetry.d.ts.map +1 -1
  18. package/dist/AnthropicTelemetry.js +6 -4
  19. package/dist/AnthropicTelemetry.js.map +1 -1
  20. package/dist/AnthropicTool.d.ts +298 -138
  21. package/dist/AnthropicTool.d.ts.map +1 -1
  22. package/dist/AnthropicTool.js +141 -87
  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 +52 -8
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +52 -8
  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 +41 -67
  36. package/src/AnthropicConfig.ts +47 -11
  37. package/src/AnthropicError.ts +130 -37
  38. package/src/AnthropicLanguageModel.ts +274 -33
  39. package/src/AnthropicTelemetry.ts +24 -17
  40. package/src/AnthropicTool.ts +293 -133
  41. package/src/Generated.ts +3751 -1815
  42. package/src/index.ts +52 -8
  43. package/src/internal/errors.ts +9 -7
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
@@ -10,12 +10,30 @@
10
10
  * Provides a type-safe, Effect-based client for Anthropic operations including
11
11
  * messages and streaming responses.
12
12
  *
13
- * @since 1.0.0
13
+ * @since 4.0.0
14
14
  */
15
15
  export * as AnthropicClient from "./AnthropicClient.ts"
16
16
 
17
17
  /**
18
- * @since 1.0.0
18
+ * The `AnthropicConfig` module provides contextual configuration for the
19
+ * Anthropic AI provider integration. It is used to customize the generated
20
+ * Anthropic HTTP client without changing individual request code.
21
+ *
22
+ * **Common tasks**
23
+ *
24
+ * - Provide a shared `HttpClient` transformation for Anthropic requests
25
+ * - Add provider-specific concerns such as request instrumentation, proxying,
26
+ * retries, or header manipulation
27
+ * - Scope a client transformation to a single effect with {@link withClientTransform}
28
+ *
29
+ * **Gotchas**
30
+ *
31
+ * - Configuration is read from the Effect context, so overrides only apply to
32
+ * effects run inside the configured scope
33
+ * - `withClientTransform` replaces the current `transformClient` value while
34
+ * preserving any other Anthropic configuration fields
35
+ *
36
+ * @since 4.0.0
19
37
  */
20
38
  export * as AnthropicConfig from "./AnthropicConfig.ts"
21
39
 
@@ -25,12 +43,38 @@ export * as AnthropicConfig from "./AnthropicConfig.ts"
25
43
  * Provides Anthropic-specific metadata fields for AI error types through module
26
44
  * augmentation, enabling typed access to Anthropic error details.
27
45
  *
28
- * @since 1.0.0
46
+ * @since 4.0.0
29
47
  */
30
48
  export * as AnthropicError from "./AnthropicError.ts"
31
49
 
32
50
  /**
33
- * @since 1.0.0
51
+ * The `AnthropicLanguageModel` module provides the Anthropic implementation of
52
+ * Effect AI's `LanguageModel` service. It turns Effect AI prompts, tools, files,
53
+ * reasoning parts, and provider options into Anthropic Messages API requests,
54
+ * and converts Anthropic responses and streams back into Effect AI response
55
+ * parts with Anthropic-specific metadata.
56
+ *
57
+ * **When to use**
58
+ *
59
+ * - Create an Anthropic-backed model with {@link model}
60
+ * - Build or provide a `LanguageModel.LanguageModel` layer with {@link layer}
61
+ * or {@link make}
62
+ * - Supply default request options through {@link Config}
63
+ * - Override configuration for a scoped operation with {@link withConfigOverride}
64
+ * - Attach Anthropic provider options for prompt caching, document citations,
65
+ * reasoning signatures, MCP metadata, and server-side tools
66
+ *
67
+ * **Gotchas**
68
+ *
69
+ * - Prompt files are translated to Anthropic image or document blocks; only the
70
+ * supported media types can be sent to the provider.
71
+ * - Structured output support depends on the selected Claude model, so this
72
+ * module may use Anthropic's native structured output or fall back to a JSON
73
+ * response tool.
74
+ * - Some features require Anthropic beta headers, which are added
75
+ * automatically from the selected tools, files, and model capabilities.
76
+ *
77
+ * @since 4.0.0
34
78
  */
35
79
  export * as AnthropicLanguageModel from "./AnthropicLanguageModel.ts"
36
80
 
@@ -41,7 +85,7 @@ export * as AnthropicLanguageModel from "./AnthropicLanguageModel.ts"
41
85
  * semantic conventions, extending the base GenAI attributes with Anthropic-specific
42
86
  * request and response metadata.
43
87
  *
44
- * @since 1.0.0
88
+ * @since 4.0.0
45
89
  */
46
90
  export * as AnthropicTelemetry from "./AnthropicTelemetry.ts"
47
91
 
@@ -51,11 +95,11 @@ export * as AnthropicTelemetry from "./AnthropicTelemetry.ts"
51
95
  * Provides tools that are natively supported by Anthropic's API, including
52
96
  * Bash, Code Execution, Computer Use, Memory, and Text Editor functionality.
53
97
  *
54
- * @since 1.0.0
98
+ * @since 4.0.0
55
99
  */
56
100
  export * as AnthropicTool from "./AnthropicTool.ts"
57
101
 
58
102
  /**
59
- * @since 1.0.0
103
+ * @since 4.0.0
60
104
  */
61
105
  export * as Generated from "./Generated.ts"
@@ -190,8 +190,8 @@ export const parseRateLimitHeaders = (headers: Record<string, string>) => {
190
190
  let retryAfter: Duration.Duration | undefined
191
191
  if (Predicate.isNotUndefined(retryAfterRaw)) {
192
192
  const parsed = Number.parse(retryAfterRaw)
193
- if (Predicate.isNotUndefined(parsed)) {
194
- retryAfter = Duration.seconds(parsed)
193
+ if (Option.isSome(parsed)) {
194
+ retryAfter = Duration.seconds(parsed.value)
195
195
  }
196
196
  }
197
197
  const requestsLimitRaw = headers["anthropic-ratelimit-requests-limit"]
@@ -200,13 +200,15 @@ export const parseRateLimitHeaders = (headers: Record<string, string>) => {
200
200
  const tokensRemainingRaw = headers["anthropic-ratelimit-tokens-remaining"]
201
201
  return {
202
202
  retryAfter,
203
- requestsLimit: Predicate.isNotUndefined(requestsLimitRaw) ? Number.parse(requestsLimitRaw) ?? null : null,
203
+ requestsLimit: Predicate.isNotUndefined(requestsLimitRaw) ? Option.getOrNull(Number.parse(requestsLimitRaw)) : null,
204
204
  requestsRemaining: Predicate.isNotUndefined(requestsRemainingRaw)
205
- ? Number.parse(requestsRemainingRaw) ?? null
205
+ ? Option.getOrNull(Number.parse(requestsRemainingRaw))
206
206
  : null,
207
207
  requestsReset: headers["anthropic-ratelimit-requests-reset"] ?? null,
208
- tokensLimit: Predicate.isNotUndefined(tokensLimitRaw) ? Number.parse(tokensLimitRaw) ?? null : null,
209
- tokensRemaining: Predicate.isNotUndefined(tokensRemainingRaw) ? Number.parse(tokensRemainingRaw) ?? null : null,
208
+ tokensLimit: Predicate.isNotUndefined(tokensLimitRaw) ? Option.getOrNull(Number.parse(tokensLimitRaw)) : null,
209
+ tokensRemaining: Predicate.isNotUndefined(tokensRemainingRaw)
210
+ ? Option.getOrNull(Number.parse(tokensRemainingRaw))
211
+ : null,
210
212
  tokensReset: headers["anthropic-ratelimit-tokens-reset"] ?? null
211
213
  }
212
214
  }
@@ -222,7 +224,7 @@ export const buildHttpRequestDetails = (
222
224
  method: request.method,
223
225
  url: request.url,
224
226
  urlParams: Array.from(request.urlParams),
225
- hash: request.hash,
227
+ hash: Option.getOrUndefined(request.hash),
226
228
  headers: Redactable.redact(request.headers) as Record<string, string>
227
229
  })
228
230