@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.
- package/dist/AnthropicClient.d.ts +89 -66
- package/dist/AnthropicClient.d.ts.map +1 -1
- package/dist/AnthropicClient.js +75 -17
- package/dist/AnthropicClient.js.map +1 -1
- package/dist/AnthropicConfig.d.ts +68 -10
- package/dist/AnthropicConfig.d.ts.map +1 -1
- package/dist/AnthropicConfig.js +43 -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 +384 -71
- package/dist/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.js +102 -16
- package/dist/AnthropicLanguageModel.js.map +1 -1
- package/dist/AnthropicTelemetry.d.ts +42 -15
- package/dist/AnthropicTelemetry.d.ts.map +1 -1
- package/dist/AnthropicTelemetry.js +44 -8
- package/dist/AnthropicTelemetry.js.map +1 -1
- package/dist/AnthropicTool.d.ts +1116 -183
- package/dist/AnthropicTool.d.ts.map +1 -1
- package/dist/AnthropicTool.js +818 -129
- 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 +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 +119 -70
- package/src/AnthropicConfig.ts +69 -11
- package/src/AnthropicError.ts +138 -37
- package/src/AnthropicLanguageModel.ts +405 -38
- package/src/AnthropicTelemetry.ts +76 -20
- package/src/AnthropicTool.ts +1109 -176
- package/src/Generated.ts +3751 -1815
- package/src/index.ts +8 -29
- package/src/internal/errors.ts +9 -7
|
@@ -1,11 +1,40 @@
|
|
|
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
|
-
* semantic conventions, extending the base GenAI attributes with Anthropic-specific
|
|
6
|
-
* request and response metadata.
|
|
7
|
+
* **Mental model**
|
|
7
8
|
*
|
|
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`
|
|
36
|
+
*
|
|
37
|
+
* @since 4.0.0
|
|
9
38
|
*/
|
|
10
39
|
import { dual } from "effect/Function"
|
|
11
40
|
import * as String from "effect/String"
|
|
@@ -17,10 +46,14 @@ 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/
|
|
21
54
|
*
|
|
22
|
-
* @since 1.0.0
|
|
23
55
|
* @category models
|
|
56
|
+
* @since 4.0.0
|
|
24
57
|
*/
|
|
25
58
|
export type AnthropicTelemetryAttributes = Simplify<
|
|
26
59
|
& Telemetry.GenAITelemetryAttributes
|
|
@@ -32,8 +65,8 @@ export type AnthropicTelemetryAttributes = Simplify<
|
|
|
32
65
|
* All telemetry attributes which are part of the GenAI specification,
|
|
33
66
|
* including the Anthropic-specific attributes.
|
|
34
67
|
*
|
|
35
|
-
* @since 1.0.0
|
|
36
68
|
* @category models
|
|
69
|
+
* @since 4.0.0
|
|
37
70
|
*/
|
|
38
71
|
export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes
|
|
39
72
|
|
|
@@ -41,8 +74,8 @@ export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & Respon
|
|
|
41
74
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
42
75
|
* namespaced by `gen_ai.anthropic.request`.
|
|
43
76
|
*
|
|
44
|
-
* @since 1.0.0
|
|
45
77
|
* @category models
|
|
78
|
+
* @since 4.0.0
|
|
46
79
|
*/
|
|
47
80
|
export interface RequestAttributes {
|
|
48
81
|
/**
|
|
@@ -59,8 +92,8 @@ export interface RequestAttributes {
|
|
|
59
92
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
60
93
|
* namespaced by `gen_ai.anthropic.response`.
|
|
61
94
|
*
|
|
62
|
-
* @since 1.0.0
|
|
63
95
|
* @category models
|
|
96
|
+
* @since 4.0.0
|
|
64
97
|
*/
|
|
65
98
|
export interface ResponseAttributes {
|
|
66
99
|
/**
|
|
@@ -78,8 +111,10 @@ export interface ResponseAttributes {
|
|
|
78
111
|
}
|
|
79
112
|
|
|
80
113
|
/**
|
|
81
|
-
*
|
|
114
|
+
* Options accepted by `addGenAIAnnotations`, combining standard GenAI telemetry attributes with optional Anthropic request and response attributes.
|
|
115
|
+
*
|
|
82
116
|
* @category models
|
|
117
|
+
* @since 4.0.0
|
|
83
118
|
*/
|
|
84
119
|
export type AnthropicTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
|
|
85
120
|
anthropic?: {
|
|
@@ -99,30 +134,51 @@ const addAnthropicResponseAttributes = Telemetry.addSpanAttributes("gen_ai.anthr
|
|
|
99
134
|
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
100
135
|
* `Span`.
|
|
101
136
|
*
|
|
102
|
-
* **
|
|
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.
|
|
103
141
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
142
|
+
* **Gotchas**
|
|
143
|
+
*
|
|
144
|
+
* This method mutates the `Span` in place.
|
|
145
|
+
*
|
|
146
|
+
* @category utils
|
|
147
|
+
* @since 4.0.0
|
|
106
148
|
*/
|
|
107
149
|
export const addGenAIAnnotations: {
|
|
108
150
|
/**
|
|
109
151
|
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
110
152
|
* `Span`.
|
|
111
153
|
*
|
|
112
|
-
* **
|
|
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
|
+
*
|
|
159
|
+
* **Gotchas**
|
|
113
160
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
161
|
+
* This method mutates the `Span` in place.
|
|
162
|
+
*
|
|
163
|
+
* @category utils
|
|
164
|
+
* @since 4.0.0
|
|
116
165
|
*/
|
|
117
166
|
(options: AnthropicTelemetryAttributeOptions): (span: Span) => void
|
|
118
167
|
/**
|
|
119
168
|
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
120
169
|
* `Span`.
|
|
121
170
|
*
|
|
122
|
-
* **
|
|
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
|
+
*
|
|
176
|
+
* **Gotchas**
|
|
177
|
+
*
|
|
178
|
+
* This method mutates the `Span` in place.
|
|
123
179
|
*
|
|
124
|
-
* @
|
|
125
|
-
* @
|
|
180
|
+
* @category utils
|
|
181
|
+
* @since 4.0.0
|
|
126
182
|
*/
|
|
127
183
|
(span: Span, options: AnthropicTelemetryAttributeOptions): void
|
|
128
184
|
} = dual(2, (span: Span, options: AnthropicTelemetryAttributeOptions) => {
|