@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.
Files changed (104) hide show
  1. package/dist/AnthropicClient.d.ts +196 -0
  2. package/dist/AnthropicClient.d.ts.map +1 -0
  3. package/dist/AnthropicClient.js +142 -0
  4. package/dist/AnthropicClient.js.map +1 -0
  5. package/dist/{dts/AnthropicConfig.d.ts → AnthropicConfig.d.ts} +9 -9
  6. package/dist/AnthropicConfig.d.ts.map +1 -0
  7. package/dist/{esm/AnthropicConfig.js → AnthropicConfig.js} +8 -5
  8. package/dist/AnthropicConfig.js.map +1 -0
  9. package/dist/AnthropicError.d.ts +102 -0
  10. package/dist/AnthropicError.d.ts.map +1 -0
  11. package/dist/AnthropicError.js +10 -0
  12. package/dist/AnthropicError.js.map +1 -0
  13. package/dist/AnthropicLanguageModel.d.ts +522 -0
  14. package/dist/AnthropicLanguageModel.d.ts.map +1 -0
  15. package/dist/AnthropicLanguageModel.js +2107 -0
  16. package/dist/AnthropicLanguageModel.js.map +1 -0
  17. package/dist/AnthropicTelemetry.d.ts +101 -0
  18. package/dist/AnthropicTelemetry.d.ts.map +1 -0
  19. package/dist/AnthropicTelemetry.js +35 -0
  20. package/dist/AnthropicTelemetry.js.map +1 -0
  21. package/dist/AnthropicTool.d.ts +2153 -0
  22. package/dist/AnthropicTool.d.ts.map +1 -0
  23. package/dist/AnthropicTool.js +1168 -0
  24. package/dist/AnthropicTool.js.map +1 -0
  25. package/dist/Generated.d.ts +25233 -0
  26. package/dist/Generated.d.ts.map +1 -0
  27. package/dist/Generated.js +7649 -0
  28. package/dist/Generated.js.map +1 -0
  29. package/dist/index.d.ts +53 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +54 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/internal/errors.d.ts +2 -0
  34. package/dist/internal/errors.d.ts.map +1 -0
  35. package/dist/internal/errors.js +344 -0
  36. package/dist/internal/errors.js.map +1 -0
  37. package/dist/{dts/internal → internal}/utilities.d.ts.map +1 -1
  38. package/dist/internal/utilities.js.map +1 -0
  39. package/package.json +45 -81
  40. package/src/AnthropicClient.ts +327 -683
  41. package/src/AnthropicConfig.ts +20 -34
  42. package/src/AnthropicError.ts +111 -0
  43. package/src/AnthropicLanguageModel.ts +2039 -993
  44. package/src/AnthropicTelemetry.ts +138 -0
  45. package/src/AnthropicTool.ts +1500 -475
  46. package/src/Generated.ts +9798 -6359
  47. package/src/index.ts +38 -6
  48. package/src/internal/errors.ts +368 -0
  49. package/src/internal/utilities.ts +1 -1
  50. package/AnthropicClient/package.json +0 -6
  51. package/AnthropicConfig/package.json +0 -6
  52. package/AnthropicLanguageModel/package.json +0 -6
  53. package/AnthropicTokenizer/package.json +0 -6
  54. package/AnthropicTool/package.json +0 -6
  55. package/Generated/package.json +0 -6
  56. package/README.md +0 -5
  57. package/dist/cjs/AnthropicClient.js +0 -344
  58. package/dist/cjs/AnthropicClient.js.map +0 -1
  59. package/dist/cjs/AnthropicConfig.js +0 -30
  60. package/dist/cjs/AnthropicConfig.js.map +0 -1
  61. package/dist/cjs/AnthropicLanguageModel.js +0 -1322
  62. package/dist/cjs/AnthropicLanguageModel.js.map +0 -1
  63. package/dist/cjs/AnthropicTokenizer.js +0 -52
  64. package/dist/cjs/AnthropicTokenizer.js.map +0 -1
  65. package/dist/cjs/AnthropicTool.js +0 -461
  66. package/dist/cjs/AnthropicTool.js.map +0 -1
  67. package/dist/cjs/Generated.js +0 -6578
  68. package/dist/cjs/Generated.js.map +0 -1
  69. package/dist/cjs/index.js +0 -20
  70. package/dist/cjs/index.js.map +0 -1
  71. package/dist/cjs/internal/utilities.js +0 -29
  72. package/dist/cjs/internal/utilities.js.map +0 -1
  73. package/dist/dts/AnthropicClient.d.ts +0 -730
  74. package/dist/dts/AnthropicClient.d.ts.map +0 -1
  75. package/dist/dts/AnthropicConfig.d.ts.map +0 -1
  76. package/dist/dts/AnthropicLanguageModel.d.ts +0 -304
  77. package/dist/dts/AnthropicLanguageModel.d.ts.map +0 -1
  78. package/dist/dts/AnthropicTokenizer.d.ts +0 -13
  79. package/dist/dts/AnthropicTokenizer.d.ts.map +0 -1
  80. package/dist/dts/AnthropicTool.d.ts +0 -548
  81. package/dist/dts/AnthropicTool.d.ts.map +0 -1
  82. package/dist/dts/Generated.d.ts +0 -12504
  83. package/dist/dts/Generated.d.ts.map +0 -1
  84. package/dist/dts/index.d.ts +0 -25
  85. package/dist/dts/index.d.ts.map +0 -1
  86. package/dist/esm/AnthropicClient.js +0 -317
  87. package/dist/esm/AnthropicClient.js.map +0 -1
  88. package/dist/esm/AnthropicConfig.js.map +0 -1
  89. package/dist/esm/AnthropicLanguageModel.js +0 -1309
  90. package/dist/esm/AnthropicLanguageModel.js.map +0 -1
  91. package/dist/esm/AnthropicTokenizer.js +0 -44
  92. package/dist/esm/AnthropicTokenizer.js.map +0 -1
  93. package/dist/esm/AnthropicTool.js +0 -452
  94. package/dist/esm/AnthropicTool.js.map +0 -1
  95. package/dist/esm/Generated.js +0 -6247
  96. package/dist/esm/Generated.js.map +0 -1
  97. package/dist/esm/index.js +0 -25
  98. package/dist/esm/index.js.map +0 -1
  99. package/dist/esm/internal/utilities.js.map +0 -1
  100. package/dist/esm/package.json +0 -4
  101. package/index/package.json +0 -6
  102. package/src/AnthropicTokenizer.ts +0 -59
  103. /package/dist/{dts/internal → internal}/utilities.d.ts +0 -0
  104. /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
+ })