@effect/ai-anthropic 4.0.0-beta.70 → 4.0.0-beta.72
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 +51 -2
- package/dist/AnthropicClient.d.ts.map +1 -1
- package/dist/AnthropicClient.js +64 -4
- package/dist/AnthropicClient.js.map +1 -1
- package/dist/AnthropicConfig.d.ts +22 -0
- package/dist/AnthropicConfig.d.ts.map +1 -1
- package/dist/AnthropicConfig.js +12 -0
- package/dist/AnthropicConfig.js.map +1 -1
- package/dist/AnthropicError.d.ts +8 -0
- package/dist/AnthropicError.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.d.ts +105 -7
- package/dist/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.js +55 -5
- package/dist/AnthropicLanguageModel.js.map +1 -1
- package/dist/AnthropicTelemetry.d.ts +21 -1
- package/dist/AnthropicTelemetry.d.ts.map +1 -1
- package/dist/AnthropicTelemetry.js +38 -4
- package/dist/AnthropicTelemetry.js.map +1 -1
- package/dist/AnthropicTool.d.ts +940 -165
- package/dist/AnthropicTool.d.ts.map +1 -1
- package/dist/AnthropicTool.js +760 -123
- package/dist/AnthropicTool.js.map +1 -1
- package/dist/index.d.ts +0 -65
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -65
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/AnthropicClient.ts +80 -5
- package/src/AnthropicConfig.ts +22 -0
- package/src/AnthropicError.ts +8 -0
- package/src/AnthropicLanguageModel.ts +135 -9
- package/src/AnthropicTelemetry.ts +54 -5
- package/src/AnthropicTool.ts +938 -163
- package/src/index.ts +0 -65
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* **When to use**
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* Use when create an Anthropic-backed model with {@link model}
|
|
11
11
|
* - Build or provide a `LanguageModel.LanguageModel` layer with {@link layer}
|
|
12
12
|
* or {@link make}
|
|
13
13
|
* - Supply default request options through {@link Config}
|
|
@@ -60,7 +60,13 @@ import type * as Generated from "./Generated.ts"
|
|
|
60
60
|
import * as InternalUtilities from "./internal/utilities.ts"
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Known Anthropic Claude model identifiers exposed by the generated Anthropic schema.
|
|
64
|
+
*
|
|
65
|
+
* **Details**
|
|
66
|
+
*
|
|
67
|
+
* The Anthropic language model constructors accept `Model` values and custom
|
|
68
|
+
* string model ids, so this type is best used for autocomplete and type checking
|
|
69
|
+
* of known Claude ids.
|
|
64
70
|
*
|
|
65
71
|
* @category models
|
|
66
72
|
* @since 4.0.0
|
|
@@ -72,7 +78,12 @@ export type Model = typeof Generated.Model.Type
|
|
|
72
78
|
// =============================================================================
|
|
73
79
|
|
|
74
80
|
/**
|
|
75
|
-
*
|
|
81
|
+
* Context service for Anthropic language model configuration.
|
|
82
|
+
*
|
|
83
|
+
* **When to use**
|
|
84
|
+
*
|
|
85
|
+
* Use when you need to provide or override Anthropic model configuration on a
|
|
86
|
+
* per-request basis via `Context.Service`.
|
|
76
87
|
*
|
|
77
88
|
* **Details**
|
|
78
89
|
*
|
|
@@ -202,7 +213,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
202
213
|
*
|
|
203
214
|
* **When to use**
|
|
204
215
|
*
|
|
205
|
-
* Use these options to control how text blocks are sent to Anthropic.
|
|
216
|
+
* Use when you use these options to control how text blocks are sent to Anthropic.
|
|
206
217
|
*
|
|
207
218
|
* @category request
|
|
208
219
|
* @since 4.0.0
|
|
@@ -283,7 +294,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
283
294
|
*
|
|
284
295
|
* **When to use**
|
|
285
296
|
*
|
|
286
|
-
*
|
|
297
|
+
* Use when storing additional document metadata as text or stringified JSON.
|
|
287
298
|
*/
|
|
288
299
|
readonly documentContext?: string | null
|
|
289
300
|
} | null
|
|
@@ -634,7 +645,15 @@ declare module "effect/unstable/ai/Response" {
|
|
|
634
645
|
// =============================================================================
|
|
635
646
|
|
|
636
647
|
/**
|
|
637
|
-
* Creates an Anthropic
|
|
648
|
+
* Creates an Anthropic model descriptor that can be provided with `Effect.provide`.
|
|
649
|
+
*
|
|
650
|
+
* **When to use**
|
|
651
|
+
*
|
|
652
|
+
* Use when you want an Anthropic Claude model value that carries provider and
|
|
653
|
+
* model metadata and can be supplied directly to an Effect program.
|
|
654
|
+
*
|
|
655
|
+
* @see {@link layer} for creating a `LanguageModel.LanguageModel` layer directly
|
|
656
|
+
* @see {@link make} for constructing the language model service effectfully
|
|
638
657
|
*
|
|
639
658
|
* @category constructors
|
|
640
659
|
* @since 4.0.0
|
|
@@ -646,7 +665,21 @@ export const model = (
|
|
|
646
665
|
AiModel.make("anthropic", model, layer({ model, config }))
|
|
647
666
|
|
|
648
667
|
/**
|
|
649
|
-
* Creates an Anthropic
|
|
668
|
+
* Creates an Anthropic `LanguageModel` service from a model identifier and optional request defaults.
|
|
669
|
+
*
|
|
670
|
+
* **When to use**
|
|
671
|
+
*
|
|
672
|
+
* Use when an Effect needs to construct a `LanguageModel.Service` value backed
|
|
673
|
+
* by `AnthropicClient`.
|
|
674
|
+
*
|
|
675
|
+
* **Details**
|
|
676
|
+
*
|
|
677
|
+
* The returned effect requires `AnthropicClient`. Request defaults from the
|
|
678
|
+
* `config` option are merged with any `Config` service in the context, with
|
|
679
|
+
* context values taking precedence.
|
|
680
|
+
*
|
|
681
|
+
* @see {@link layer} for providing the service as a `Layer`
|
|
682
|
+
* @see {@link model} for creating a model descriptor for `AiModel.provide`
|
|
650
683
|
*
|
|
651
684
|
* @category constructors
|
|
652
685
|
* @since 4.0.0
|
|
@@ -735,6 +768,15 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
|
|
|
735
768
|
/**
|
|
736
769
|
* Creates a layer for the Anthropic language model.
|
|
737
770
|
*
|
|
771
|
+
* **When to use**
|
|
772
|
+
*
|
|
773
|
+
* Use when composing application layers and you want Anthropic to satisfy
|
|
774
|
+
* `LanguageModel.LanguageModel` while supplying `AnthropicClient` from another
|
|
775
|
+
* layer.
|
|
776
|
+
*
|
|
777
|
+
* @see {@link make} for constructing the language model service effectfully
|
|
778
|
+
* @see {@link model} for creating a model service directly
|
|
779
|
+
*
|
|
738
780
|
* @category layers
|
|
739
781
|
* @since 4.0.0
|
|
740
782
|
*/
|
|
@@ -747,6 +789,20 @@ export const layer = (options: {
|
|
|
747
789
|
/**
|
|
748
790
|
* Provides config overrides for Anthropic language model operations.
|
|
749
791
|
*
|
|
792
|
+
* **When to use**
|
|
793
|
+
*
|
|
794
|
+
* Use to apply Anthropic request configuration to one effect without changing
|
|
795
|
+
* the model's default configuration.
|
|
796
|
+
*
|
|
797
|
+
* **Details**
|
|
798
|
+
*
|
|
799
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
800
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
801
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
802
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
803
|
+
*
|
|
804
|
+
* @see {@link Config} for available Anthropic request configuration fields
|
|
805
|
+
*
|
|
750
806
|
* @category configuration
|
|
751
807
|
* @since 4.0.0
|
|
752
808
|
*/
|
|
@@ -754,6 +810,20 @@ export const withConfigOverride: {
|
|
|
754
810
|
/**
|
|
755
811
|
* Provides config overrides for Anthropic language model operations.
|
|
756
812
|
*
|
|
813
|
+
* **When to use**
|
|
814
|
+
*
|
|
815
|
+
* Use to apply Anthropic request configuration to one effect without changing
|
|
816
|
+
* the model's default configuration.
|
|
817
|
+
*
|
|
818
|
+
* **Details**
|
|
819
|
+
*
|
|
820
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
821
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
822
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
823
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
824
|
+
*
|
|
825
|
+
* @see {@link Config} for available Anthropic request configuration fields
|
|
826
|
+
*
|
|
757
827
|
* @category configuration
|
|
758
828
|
* @since 4.0.0
|
|
759
829
|
*/
|
|
@@ -761,6 +831,20 @@ export const withConfigOverride: {
|
|
|
761
831
|
/**
|
|
762
832
|
* Provides config overrides for Anthropic language model operations.
|
|
763
833
|
*
|
|
834
|
+
* **When to use**
|
|
835
|
+
*
|
|
836
|
+
* Use to apply Anthropic request configuration to one effect without changing
|
|
837
|
+
* the model's default configuration.
|
|
838
|
+
*
|
|
839
|
+
* **Details**
|
|
840
|
+
*
|
|
841
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
842
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
843
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
844
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
845
|
+
*
|
|
846
|
+
* @see {@link Config} for available Anthropic request configuration fields
|
|
847
|
+
*
|
|
764
848
|
* @category configuration
|
|
765
849
|
* @since 4.0.0
|
|
766
850
|
*/
|
|
@@ -769,6 +853,20 @@ export const withConfigOverride: {
|
|
|
769
853
|
/**
|
|
770
854
|
* Provides config overrides for Anthropic language model operations.
|
|
771
855
|
*
|
|
856
|
+
* **When to use**
|
|
857
|
+
*
|
|
858
|
+
* Use to apply Anthropic request configuration to one effect without changing
|
|
859
|
+
* the model's default configuration.
|
|
860
|
+
*
|
|
861
|
+
* **Details**
|
|
862
|
+
*
|
|
863
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
864
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
865
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
866
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
867
|
+
*
|
|
868
|
+
* @see {@link Config} for available Anthropic request configuration fields
|
|
869
|
+
*
|
|
772
870
|
* @category configuration
|
|
773
871
|
* @since 4.0.0
|
|
774
872
|
*/
|
|
@@ -776,6 +874,20 @@ export const withConfigOverride: {
|
|
|
776
874
|
/**
|
|
777
875
|
* Provides config overrides for Anthropic language model operations.
|
|
778
876
|
*
|
|
877
|
+
* **When to use**
|
|
878
|
+
*
|
|
879
|
+
* Use to apply Anthropic request configuration to one effect without changing
|
|
880
|
+
* the model's default configuration.
|
|
881
|
+
*
|
|
882
|
+
* **Details**
|
|
883
|
+
*
|
|
884
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
885
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
886
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
887
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
888
|
+
*
|
|
889
|
+
* @see {@link Config} for available Anthropic request configuration fields
|
|
890
|
+
*
|
|
779
891
|
* @category configuration
|
|
780
892
|
* @since 4.0.0
|
|
781
893
|
*/
|
|
@@ -1195,7 +1307,21 @@ const prepareMessages = Effect.fnUntraced(
|
|
|
1195
1307
|
// =============================================================================
|
|
1196
1308
|
|
|
1197
1309
|
/**
|
|
1198
|
-
*
|
|
1310
|
+
* Encoded Anthropic custom tool definition that can be sent in a Messages API request.
|
|
1311
|
+
*
|
|
1312
|
+
* **When to use**
|
|
1313
|
+
*
|
|
1314
|
+
* Use when you need to type or inspect the provider-specific request payload for
|
|
1315
|
+
* a custom Anthropic tool.
|
|
1316
|
+
*
|
|
1317
|
+
* **Details**
|
|
1318
|
+
*
|
|
1319
|
+
* This type aliases the encoded `Generated.BetaTool` schema used for Effect
|
|
1320
|
+
* user-defined and dynamic tools after conversion. It contains the tool `name`,
|
|
1321
|
+
* optional `description`, and `input_schema`, plus Anthropic-specific fields
|
|
1322
|
+
* such as `strict` and `cache_control`.
|
|
1323
|
+
*
|
|
1324
|
+
* @see {@link AnthropicProviderDefinedTool} for the request shape used by Anthropic built-in provider tools
|
|
1199
1325
|
*
|
|
1200
1326
|
* @category tools
|
|
1201
1327
|
* @since 4.0.0
|
|
@@ -2779,7 +2905,7 @@ const groupMessages = (prompt: Prompt.Prompt): Array<ContentGroup> => {
|
|
|
2779
2905
|
}
|
|
2780
2906
|
|
|
2781
2907
|
/**
|
|
2782
|
-
* Checks
|
|
2908
|
+
* Checks whether data is a URL (either a URL object or a URL string).
|
|
2783
2909
|
*/
|
|
2784
2910
|
const isUrlData = (
|
|
2785
2911
|
data: typeof Prompt.FilePart.Type["data"]
|
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Anthropic
|
|
2
|
+
* The `AnthropicTelemetry` module adds Anthropic-specific attributes to the
|
|
3
|
+
* provider-neutral GenAI telemetry model. It keeps the standard
|
|
4
|
+
* `Telemetry.addGenAIAnnotations` attributes and adds Anthropic request and
|
|
5
|
+
* response metadata under the `gen_ai.anthropic.*` OpenTelemetry namespaces.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
+
* **Mental model**
|
|
8
|
+
*
|
|
9
|
+
* - Standard GenAI attributes come from `effect/unstable/ai/Telemetry`
|
|
10
|
+
* - Anthropic request attributes are written under
|
|
11
|
+
* `gen_ai.anthropic.request.*`
|
|
12
|
+
* - Anthropic response attributes are written under
|
|
13
|
+
* `gen_ai.anthropic.response.*`
|
|
14
|
+
* - Attribute option keys are written in camelCase and converted to
|
|
15
|
+
* OpenTelemetry snake_case attribute names
|
|
16
|
+
* - {@link addGenAIAnnotations} mutates the supplied span by adding any
|
|
17
|
+
* non-nullish attributes from the option object
|
|
18
|
+
*
|
|
19
|
+
* **Common tasks**
|
|
20
|
+
*
|
|
21
|
+
* - Use {@link AnthropicTelemetryAttributes} when typing the complete set of
|
|
22
|
+
* standard and Anthropic-specific span attributes
|
|
23
|
+
* - Pass `anthropic.request` data for options such as extended thinking and
|
|
24
|
+
* thinking budget tokens
|
|
25
|
+
* - Pass `anthropic.response` data for response details such as stop reason and
|
|
26
|
+
* cache token counts
|
|
27
|
+
* - Use {@link addGenAIAnnotations} from an Anthropic model span to keep
|
|
28
|
+
* standard GenAI and provider-specific annotations together
|
|
29
|
+
*
|
|
30
|
+
* **Gotchas**
|
|
31
|
+
*
|
|
32
|
+
* - This module only annotates spans; it does not start spans or export traces
|
|
33
|
+
* - Null and undefined attribute values are skipped instead of being written
|
|
34
|
+
* - The helper accepts both direct and data-last forms because it is built with
|
|
35
|
+
* `dual`
|
|
7
36
|
*
|
|
8
37
|
* @since 4.0.0
|
|
9
38
|
*/
|
|
@@ -17,7 +46,12 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
|
|
|
17
46
|
* The attributes used to describe telemetry in the context of Generative
|
|
18
47
|
* Artificial Intelligence (GenAI) Models requests and responses.
|
|
19
48
|
*
|
|
20
|
-
*
|
|
49
|
+
* **Details**
|
|
50
|
+
*
|
|
51
|
+
* These attributes follow the OpenTelemetry generative AI semantic
|
|
52
|
+
* conventions:
|
|
53
|
+
* https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
|
|
54
|
+
*
|
|
21
55
|
* @category models
|
|
22
56
|
* @since 4.0.0
|
|
23
57
|
*/
|
|
@@ -100,6 +134,11 @@ const addAnthropicResponseAttributes = Telemetry.addSpanAttributes("gen_ai.anthr
|
|
|
100
134
|
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
101
135
|
* `Span`.
|
|
102
136
|
*
|
|
137
|
+
* **When to use**
|
|
138
|
+
*
|
|
139
|
+
* Use to annotate an Anthropic model span with standard GenAI telemetry
|
|
140
|
+
* attributes and Anthropic-specific request or response metadata.
|
|
141
|
+
*
|
|
103
142
|
* **Gotchas**
|
|
104
143
|
*
|
|
105
144
|
* This method mutates the `Span` in place.
|
|
@@ -112,6 +151,11 @@ export const addGenAIAnnotations: {
|
|
|
112
151
|
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
113
152
|
* `Span`.
|
|
114
153
|
*
|
|
154
|
+
* **When to use**
|
|
155
|
+
*
|
|
156
|
+
* Use to annotate an Anthropic model span with standard GenAI telemetry
|
|
157
|
+
* attributes and Anthropic-specific request or response metadata.
|
|
158
|
+
*
|
|
115
159
|
* **Gotchas**
|
|
116
160
|
*
|
|
117
161
|
* This method mutates the `Span` in place.
|
|
@@ -124,6 +168,11 @@ export const addGenAIAnnotations: {
|
|
|
124
168
|
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
125
169
|
* `Span`.
|
|
126
170
|
*
|
|
171
|
+
* **When to use**
|
|
172
|
+
*
|
|
173
|
+
* Use to annotate an Anthropic model span with standard GenAI telemetry
|
|
174
|
+
* attributes and Anthropic-specific request or response metadata.
|
|
175
|
+
*
|
|
127
176
|
* **Gotchas**
|
|
128
177
|
*
|
|
129
178
|
* This method mutates the `Span` in place.
|