@effect/ai-anthropic 0.23.0 → 4.0.0-beta.0
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 +196 -0
- package/dist/AnthropicClient.d.ts.map +1 -0
- package/dist/AnthropicClient.js +142 -0
- package/dist/AnthropicClient.js.map +1 -0
- package/dist/{dts/AnthropicConfig.d.ts → AnthropicConfig.d.ts} +9 -9
- package/dist/AnthropicConfig.d.ts.map +1 -0
- package/dist/{esm/AnthropicConfig.js → AnthropicConfig.js} +8 -5
- package/dist/AnthropicConfig.js.map +1 -0
- package/dist/AnthropicError.d.ts +102 -0
- package/dist/AnthropicError.d.ts.map +1 -0
- package/dist/AnthropicError.js +10 -0
- package/dist/AnthropicError.js.map +1 -0
- package/dist/AnthropicLanguageModel.d.ts +522 -0
- package/dist/AnthropicLanguageModel.d.ts.map +1 -0
- package/dist/AnthropicLanguageModel.js +2107 -0
- package/dist/AnthropicLanguageModel.js.map +1 -0
- package/dist/AnthropicTelemetry.d.ts +101 -0
- package/dist/AnthropicTelemetry.d.ts.map +1 -0
- package/dist/AnthropicTelemetry.js +35 -0
- package/dist/AnthropicTelemetry.js.map +1 -0
- package/dist/AnthropicTool.d.ts +2153 -0
- package/dist/AnthropicTool.d.ts.map +1 -0
- package/dist/AnthropicTool.js +1168 -0
- package/dist/AnthropicTool.js.map +1 -0
- package/dist/Generated.d.ts +25233 -0
- package/dist/Generated.d.ts.map +1 -0
- package/dist/Generated.js +7649 -0
- package/dist/Generated.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/errors.d.ts +2 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +344 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/{dts/internal → internal}/utilities.d.ts.map +1 -1
- package/dist/internal/utilities.js.map +1 -0
- package/package.json +45 -81
- package/src/AnthropicClient.ts +327 -683
- package/src/AnthropicConfig.ts +20 -34
- package/src/AnthropicError.ts +111 -0
- package/src/AnthropicLanguageModel.ts +2039 -993
- package/src/AnthropicTelemetry.ts +138 -0
- package/src/AnthropicTool.ts +1500 -475
- package/src/Generated.ts +9798 -6359
- package/src/index.ts +38 -6
- package/src/internal/errors.ts +368 -0
- package/src/internal/utilities.ts +1 -1
- package/AnthropicClient/package.json +0 -6
- package/AnthropicConfig/package.json +0 -6
- package/AnthropicLanguageModel/package.json +0 -6
- package/AnthropicTokenizer/package.json +0 -6
- package/AnthropicTool/package.json +0 -6
- package/Generated/package.json +0 -6
- package/README.md +0 -5
- package/dist/cjs/AnthropicClient.js +0 -344
- package/dist/cjs/AnthropicClient.js.map +0 -1
- package/dist/cjs/AnthropicConfig.js +0 -30
- package/dist/cjs/AnthropicConfig.js.map +0 -1
- package/dist/cjs/AnthropicLanguageModel.js +0 -1322
- package/dist/cjs/AnthropicLanguageModel.js.map +0 -1
- package/dist/cjs/AnthropicTokenizer.js +0 -52
- package/dist/cjs/AnthropicTokenizer.js.map +0 -1
- package/dist/cjs/AnthropicTool.js +0 -461
- package/dist/cjs/AnthropicTool.js.map +0 -1
- package/dist/cjs/Generated.js +0 -6578
- package/dist/cjs/Generated.js.map +0 -1
- package/dist/cjs/index.js +0 -20
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internal/utilities.js +0 -29
- package/dist/cjs/internal/utilities.js.map +0 -1
- package/dist/dts/AnthropicClient.d.ts +0 -730
- package/dist/dts/AnthropicClient.d.ts.map +0 -1
- package/dist/dts/AnthropicConfig.d.ts.map +0 -1
- package/dist/dts/AnthropicLanguageModel.d.ts +0 -304
- package/dist/dts/AnthropicLanguageModel.d.ts.map +0 -1
- package/dist/dts/AnthropicTokenizer.d.ts +0 -13
- package/dist/dts/AnthropicTokenizer.d.ts.map +0 -1
- package/dist/dts/AnthropicTool.d.ts +0 -548
- package/dist/dts/AnthropicTool.d.ts.map +0 -1
- package/dist/dts/Generated.d.ts +0 -12504
- package/dist/dts/Generated.d.ts.map +0 -1
- package/dist/dts/index.d.ts +0 -25
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/esm/AnthropicClient.js +0 -317
- package/dist/esm/AnthropicClient.js.map +0 -1
- package/dist/esm/AnthropicConfig.js.map +0 -1
- package/dist/esm/AnthropicLanguageModel.js +0 -1309
- package/dist/esm/AnthropicLanguageModel.js.map +0 -1
- package/dist/esm/AnthropicTokenizer.js +0 -44
- package/dist/esm/AnthropicTokenizer.js.map +0 -1
- package/dist/esm/AnthropicTool.js +0 -452
- package/dist/esm/AnthropicTool.js.map +0 -1
- package/dist/esm/Generated.js +0 -6247
- package/dist/esm/Generated.js.map +0 -1
- package/dist/esm/index.js +0 -25
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internal/utilities.js.map +0 -1
- package/dist/esm/package.json +0 -4
- package/index/package.json +0 -6
- package/src/AnthropicTokenizer.ts +0 -59
- /package/dist/{dts/internal → internal}/utilities.d.ts +0 -0
- /package/dist/{esm/internal → internal}/utilities.js +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic telemetry attributes for OpenTelemetry integration.
|
|
3
|
+
*
|
|
4
|
+
* Provides Anthropic-specific GenAI telemetry attributes following OpenTelemetry
|
|
5
|
+
* semantic conventions, extending the base GenAI attributes with Anthropic-specific
|
|
6
|
+
* request and response metadata.
|
|
7
|
+
*
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
import { dual } from "effect/Function"
|
|
11
|
+
import * as String from "effect/String"
|
|
12
|
+
import type { Span } from "effect/Tracer"
|
|
13
|
+
import type { Simplify } from "effect/Types"
|
|
14
|
+
import * as Telemetry from "effect/unstable/ai/Telemetry"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The attributes used to describe telemetry in the context of Generative
|
|
18
|
+
* Artificial Intelligence (GenAI) Models requests and responses.
|
|
19
|
+
*
|
|
20
|
+
* {@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}
|
|
21
|
+
*
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
* @category models
|
|
24
|
+
*/
|
|
25
|
+
export type AnthropicTelemetryAttributes = Simplify<
|
|
26
|
+
& Telemetry.GenAITelemetryAttributes
|
|
27
|
+
& Telemetry.AttributesWithPrefix<RequestAttributes, "gen_ai.anthropic.request">
|
|
28
|
+
& Telemetry.AttributesWithPrefix<ResponseAttributes, "gen_ai.anthropic.response">
|
|
29
|
+
>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* All telemetry attributes which are part of the GenAI specification,
|
|
33
|
+
* including the Anthropic-specific attributes.
|
|
34
|
+
*
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
* @category models
|
|
37
|
+
*/
|
|
38
|
+
export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Telemetry attributes which are part of the GenAI specification and are
|
|
42
|
+
* namespaced by `gen_ai.anthropic.request`.
|
|
43
|
+
*
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
* @category models
|
|
46
|
+
*/
|
|
47
|
+
export interface RequestAttributes {
|
|
48
|
+
/**
|
|
49
|
+
* Whether extended thinking is enabled.
|
|
50
|
+
*/
|
|
51
|
+
readonly extendedThinking?: boolean | null | undefined
|
|
52
|
+
/**
|
|
53
|
+
* The budget tokens for extended thinking.
|
|
54
|
+
*/
|
|
55
|
+
readonly thinkingBudgetTokens?: number | null | undefined
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Telemetry attributes which are part of the GenAI specification and are
|
|
60
|
+
* namespaced by `gen_ai.anthropic.response`.
|
|
61
|
+
*
|
|
62
|
+
* @since 1.0.0
|
|
63
|
+
* @category models
|
|
64
|
+
*/
|
|
65
|
+
export interface ResponseAttributes {
|
|
66
|
+
/**
|
|
67
|
+
* The stop reason from the response.
|
|
68
|
+
*/
|
|
69
|
+
readonly stopReason?: string | null | undefined
|
|
70
|
+
/**
|
|
71
|
+
* Number of cache creation input tokens.
|
|
72
|
+
*/
|
|
73
|
+
readonly cacheCreationInputTokens?: number | null | undefined
|
|
74
|
+
/**
|
|
75
|
+
* Number of cache read input tokens.
|
|
76
|
+
*/
|
|
77
|
+
readonly cacheReadInputTokens?: number | null | undefined
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
* @category models
|
|
83
|
+
*/
|
|
84
|
+
export type AnthropicTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
|
|
85
|
+
anthropic?: {
|
|
86
|
+
request?: RequestAttributes | undefined
|
|
87
|
+
response?: ResponseAttributes | undefined
|
|
88
|
+
} | undefined
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const addAnthropicRequestAttributes = Telemetry.addSpanAttributes("gen_ai.anthropic.request", String.camelToSnake)<
|
|
92
|
+
RequestAttributes
|
|
93
|
+
>
|
|
94
|
+
const addAnthropicResponseAttributes = Telemetry.addSpanAttributes("gen_ai.anthropic.response", String.camelToSnake)<
|
|
95
|
+
ResponseAttributes
|
|
96
|
+
>
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
100
|
+
* `Span`.
|
|
101
|
+
*
|
|
102
|
+
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
103
|
+
*
|
|
104
|
+
* @since 1.0.0
|
|
105
|
+
* @category utilities
|
|
106
|
+
*/
|
|
107
|
+
export const addGenAIAnnotations: {
|
|
108
|
+
/**
|
|
109
|
+
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
110
|
+
* `Span`.
|
|
111
|
+
*
|
|
112
|
+
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
113
|
+
*
|
|
114
|
+
* @since 1.0.0
|
|
115
|
+
* @category utilities
|
|
116
|
+
*/
|
|
117
|
+
(options: AnthropicTelemetryAttributeOptions): (span: Span) => void
|
|
118
|
+
/**
|
|
119
|
+
* Applies the specified Anthropic GenAI telemetry attributes to the provided
|
|
120
|
+
* `Span`.
|
|
121
|
+
*
|
|
122
|
+
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
123
|
+
*
|
|
124
|
+
* @since 1.0.0
|
|
125
|
+
* @category utilities
|
|
126
|
+
*/
|
|
127
|
+
(span: Span, options: AnthropicTelemetryAttributeOptions): void
|
|
128
|
+
} = dual(2, (span: Span, options: AnthropicTelemetryAttributeOptions) => {
|
|
129
|
+
Telemetry.addGenAIAnnotations(span, options)
|
|
130
|
+
if (options.anthropic != null) {
|
|
131
|
+
if (options.anthropic.request != null) {
|
|
132
|
+
addAnthropicRequestAttributes(span, options.anthropic.request)
|
|
133
|
+
}
|
|
134
|
+
if (options.anthropic.response != null) {
|
|
135
|
+
addAnthropicResponseAttributes(span, options.anthropic.response)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
})
|