@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
@@ -5,26 +5,30 @@ import * as Telemetry from "effect/unstable/ai/Telemetry";
5
5
  * The attributes used to describe telemetry in the context of Generative
6
6
  * Artificial Intelligence (GenAI) Models requests and responses.
7
7
  *
8
- * {@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}
8
+ * **Details**
9
+ *
10
+ * These attributes follow the OpenTelemetry generative AI semantic
11
+ * conventions:
12
+ * https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
9
13
  *
10
- * @since 1.0.0
11
14
  * @category models
15
+ * @since 4.0.0
12
16
  */
13
17
  export type AnthropicTelemetryAttributes = Simplify<Telemetry.GenAITelemetryAttributes & Telemetry.AttributesWithPrefix<RequestAttributes, "gen_ai.anthropic.request"> & Telemetry.AttributesWithPrefix<ResponseAttributes, "gen_ai.anthropic.response">>;
14
18
  /**
15
19
  * All telemetry attributes which are part of the GenAI specification,
16
20
  * including the Anthropic-specific attributes.
17
21
  *
18
- * @since 1.0.0
19
22
  * @category models
23
+ * @since 4.0.0
20
24
  */
21
25
  export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes;
22
26
  /**
23
27
  * Telemetry attributes which are part of the GenAI specification and are
24
28
  * namespaced by `gen_ai.anthropic.request`.
25
29
  *
26
- * @since 1.0.0
27
30
  * @category models
31
+ * @since 4.0.0
28
32
  */
29
33
  export interface RequestAttributes {
30
34
  /**
@@ -40,8 +44,8 @@ export interface RequestAttributes {
40
44
  * Telemetry attributes which are part of the GenAI specification and are
41
45
  * namespaced by `gen_ai.anthropic.response`.
42
46
  *
43
- * @since 1.0.0
44
47
  * @category models
48
+ * @since 4.0.0
45
49
  */
46
50
  export interface ResponseAttributes {
47
51
  /**
@@ -58,8 +62,10 @@ export interface ResponseAttributes {
58
62
  readonly cacheReadInputTokens?: number | null | undefined;
59
63
  }
60
64
  /**
61
- * @since 1.0.0
65
+ * Options accepted by `addGenAIAnnotations`, combining standard GenAI telemetry attributes with optional Anthropic request and response attributes.
66
+ *
62
67
  * @category models
68
+ * @since 4.0.0
63
69
  */
64
70
  export type AnthropicTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
65
71
  anthropic?: {
@@ -71,30 +77,51 @@ export type AnthropicTelemetryAttributeOptions = Telemetry.GenAITelemetryAttribu
71
77
  * Applies the specified Anthropic GenAI telemetry attributes to the provided
72
78
  * `Span`.
73
79
  *
74
- * **NOTE**: This method will mutate the `Span` **in-place**.
80
+ * **When to use**
81
+ *
82
+ * Use to annotate an Anthropic model span with standard GenAI telemetry
83
+ * attributes and Anthropic-specific request or response metadata.
75
84
  *
76
- * @since 1.0.0
77
- * @category utilities
85
+ * **Gotchas**
86
+ *
87
+ * This method mutates the `Span` in place.
88
+ *
89
+ * @category utils
90
+ * @since 4.0.0
78
91
  */
79
92
  export declare const addGenAIAnnotations: {
80
93
  /**
81
94
  * Applies the specified Anthropic GenAI telemetry attributes to the provided
82
95
  * `Span`.
83
96
  *
84
- * **NOTE**: This method will mutate the `Span` **in-place**.
97
+ * **When to use**
98
+ *
99
+ * Use to annotate an Anthropic model span with standard GenAI telemetry
100
+ * attributes and Anthropic-specific request or response metadata.
85
101
  *
86
- * @since 1.0.0
87
- * @category utilities
102
+ * **Gotchas**
103
+ *
104
+ * This method mutates the `Span` in place.
105
+ *
106
+ * @category utils
107
+ * @since 4.0.0
88
108
  */
89
109
  (options: AnthropicTelemetryAttributeOptions): (span: Span) => void;
90
110
  /**
91
111
  * Applies the specified Anthropic GenAI telemetry attributes to the provided
92
112
  * `Span`.
93
113
  *
94
- * **NOTE**: This method will mutate the `Span` **in-place**.
114
+ * **When to use**
115
+ *
116
+ * Use to annotate an Anthropic model span with standard GenAI telemetry
117
+ * attributes and Anthropic-specific request or response metadata.
118
+ *
119
+ * **Gotchas**
120
+ *
121
+ * This method mutates the `Span` in place.
95
122
  *
96
- * @since 1.0.0
97
- * @category utilities
123
+ * @category utils
124
+ * @since 4.0.0
98
125
  */
99
126
  (span: Span, options: AnthropicTelemetryAttributeOptions): void;
100
127
  };
@@ -1 +1 @@
1
- {"version":3,"file":"AnthropicTelemetry.d.ts","sourceRoot":"","sources":["../src/AnthropicTelemetry.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAA;AAEzD;;;;;;;;GAQG;AACH,MAAM,MAAM,4BAA4B,GAAG,QAAQ,CAC/C,SAAS,CAAC,wBAAwB,GAClC,SAAS,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,GAC7E,SAAS,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,2BAA2B,CAAC,CAClF,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,GAAG,iBAAiB,GAAG,kBAAkB,CAAA;AAE5F;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;IACtD;;OAEG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAC1D;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC/C;;OAEG;IACH,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC7D;;OAEG;IACH,QAAQ,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AO,GAAG,IAAI,GAAG,SAAS,CAAA;IACtD;;OAEG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAC1D;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC/C;;OAEG;IACH,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC7D;;OAEG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAC1D;AAED;;;;;GAKG;AACH,MAAM,MAAM,kCAAkC,GAAG,SAAS,CAAC,8BAA8B,GAAG;IAC1F,SAAS,CAAC,EAAE;QACV,OAAO,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAA;QACvC,QAAQ,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAA;KAC1C,GAAG,SAAS,CAAA;CACd,CAAA;AASD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;;;;;;;;;;;;;OAeG;IACH,CAAC,OAAO,EAAE,kCAAkC,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IACnE;;;;;;;;;;;;;;;OAeG;IACH,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,kCAAkC,GAAG,IAAI,CAAA;CAW/D,CAAA"}
@@ -1,11 +1,40 @@
1
1
  /**
2
- * Anthropic telemetry attributes for OpenTelemetry integration.
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
- * 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
+ * **Mental model**
7
8
  *
8
- * @since 1.0.0
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";
@@ -16,10 +45,17 @@ const addAnthropicResponseAttributes = /*#__PURE__*/Telemetry.addSpanAttributes(
16
45
  * Applies the specified Anthropic GenAI telemetry attributes to the provided
17
46
  * `Span`.
18
47
  *
19
- * **NOTE**: This method will mutate the `Span` **in-place**.
48
+ * **When to use**
49
+ *
50
+ * Use to annotate an Anthropic model span with standard GenAI telemetry
51
+ * attributes and Anthropic-specific request or response metadata.
52
+ *
53
+ * **Gotchas**
54
+ *
55
+ * This method mutates the `Span` in place.
20
56
  *
21
- * @since 1.0.0
22
- * @category utilities
57
+ * @category utils
58
+ * @since 4.0.0
23
59
  */
24
60
  export const addGenAIAnnotations = /*#__PURE__*/dual(2, (span, options) => {
25
61
  Telemetry.addGenAIAnnotations(span, options);
@@ -1 +1 @@
1
- {"version":3,"file":"AnthropicTelemetry.js","names":["dual","String","Telemetry","addAnthropicRequestAttributes","addSpanAttributes","camelToSnake","addAnthropicResponseAttributes","addGenAIAnnotations","span","options","anthropic","request","response"],"sources":["../src/AnthropicTelemetry.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;AASA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAGvC,OAAO,KAAKC,SAAS,MAAM,8BAA8B;AA6EzD,MAAMC,6BAA6B,gBAAGD,SAAS,CAACE,iBAAiB,CAAC,0BAA0B,EAAEH,MAAM,CAACI,YAAY,CAEhH;AACD,MAAMC,8BAA8B,gBAAGJ,SAAS,CAACE,iBAAiB,CAAC,2BAA2B,EAAEH,MAAM,CAACI,YAAY,CAElH;AAED;;;;;;;;;AASA,OAAO,MAAME,mBAAmB,gBAqB5BP,IAAI,CAAC,CAAC,EAAE,CAACQ,IAAU,EAAEC,OAA2C,KAAI;EACtEP,SAAS,CAACK,mBAAmB,CAACC,IAAI,EAAEC,OAAO,CAAC;EAC5C,IAAIA,OAAO,CAACC,SAAS,IAAI,IAAI,EAAE;IAC7B,IAAID,OAAO,CAACC,SAAS,CAACC,OAAO,IAAI,IAAI,EAAE;MACrCR,6BAA6B,CAACK,IAAI,EAAEC,OAAO,CAACC,SAAS,CAACC,OAAO,CAAC;IAChE;IACA,IAAIF,OAAO,CAACC,SAAS,CAACE,QAAQ,IAAI,IAAI,EAAE;MACtCN,8BAA8B,CAACE,IAAI,EAAEC,OAAO,CAACC,SAAS,CAACE,QAAQ,CAAC;IAClE;EACF;AACF,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"AnthropicTelemetry.js","names":["dual","String","Telemetry","addAnthropicRequestAttributes","addSpanAttributes","camelToSnake","addAnthropicResponseAttributes","addGenAIAnnotations","span","options","anthropic","request","response"],"sources":["../src/AnthropicTelemetry.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAGvC,OAAO,KAAKC,SAAS,MAAM,8BAA8B;AAmFzD,MAAMC,6BAA6B,gBAAGD,SAAS,CAACE,iBAAiB,CAAC,0BAA0B,EAAEH,MAAM,CAACI,YAAY,CAEhH;AACD,MAAMC,8BAA8B,gBAAGJ,SAAS,CAACE,iBAAiB,CAAC,2BAA2B,EAAEH,MAAM,CAACI,YAAY,CAElH;AAED;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAME,mBAAmB,gBAmC5BP,IAAI,CAAC,CAAC,EAAE,CAACQ,IAAU,EAAEC,OAA2C,KAAI;EACtEP,SAAS,CAACK,mBAAmB,CAACC,IAAI,EAAEC,OAAO,CAAC;EAC5C,IAAIA,OAAO,CAACC,SAAS,IAAI,IAAI,EAAE;IAC7B,IAAID,OAAO,CAACC,SAAS,CAACC,OAAO,IAAI,IAAI,EAAE;MACrCR,6BAA6B,CAACK,IAAI,EAAEC,OAAO,CAACC,SAAS,CAACC,OAAO,CAAC;IAChE;IACA,IAAIF,OAAO,CAACC,SAAS,CAACE,QAAQ,IAAI,IAAI,EAAE;MACtCN,8BAA8B,CAACE,IAAI,EAAEC,OAAO,CAACC,SAAS,CAACE,QAAQ,CAAC;IAClE;EACF;AACF,CAAC,CAAC","ignoreList":[]}