@effect/ai 0.14.1 → 0.16.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 (134) hide show
  1. package/AiEmbeddingModel/package.json +6 -0
  2. package/AiLanguageModel/package.json +6 -0
  3. package/AiTool/package.json +6 -0
  4. package/dist/cjs/AiChat.js +65 -86
  5. package/dist/cjs/AiChat.js.map +1 -1
  6. package/dist/cjs/{Embeddings.js → AiEmbeddingModel.js} +12 -12
  7. package/dist/cjs/AiEmbeddingModel.js.map +1 -0
  8. package/dist/cjs/AiError.js +8 -1
  9. package/dist/cjs/AiError.js.map +1 -1
  10. package/dist/cjs/AiInput.js +335 -248
  11. package/dist/cjs/AiInput.js.map +1 -1
  12. package/dist/cjs/AiLanguageModel.js +311 -0
  13. package/dist/cjs/AiLanguageModel.js.map +1 -0
  14. package/dist/cjs/AiModel.js +11 -5
  15. package/dist/cjs/AiModel.js.map +1 -1
  16. package/dist/cjs/AiPlan.js +10 -3
  17. package/dist/cjs/AiPlan.js.map +1 -1
  18. package/dist/cjs/AiResponse.js +481 -165
  19. package/dist/cjs/AiResponse.js.map +1 -1
  20. package/dist/cjs/AiTelemetry.js +10 -3
  21. package/dist/cjs/AiTelemetry.js.map +1 -1
  22. package/dist/cjs/AiTool.js +93 -0
  23. package/dist/cjs/AiTool.js.map +1 -0
  24. package/dist/cjs/AiToolkit.js +121 -98
  25. package/dist/cjs/AiToolkit.js.map +1 -1
  26. package/dist/cjs/Tokenizer.js +14 -16
  27. package/dist/cjs/Tokenizer.js.map +1 -1
  28. package/dist/cjs/index.js +7 -9
  29. package/dist/cjs/internal/aiPlan.js +6 -9
  30. package/dist/cjs/internal/aiPlan.js.map +1 -1
  31. package/dist/cjs/internal/common.js +22 -0
  32. package/dist/cjs/internal/common.js.map +1 -0
  33. package/dist/dts/AiChat.d.ts +58 -44
  34. package/dist/dts/AiChat.d.ts.map +1 -1
  35. package/dist/dts/{Embeddings.d.ts → AiEmbeddingModel.d.ts} +13 -14
  36. package/dist/dts/AiEmbeddingModel.d.ts.map +1 -0
  37. package/dist/dts/AiError.d.ts +4 -3
  38. package/dist/dts/AiError.d.ts.map +1 -1
  39. package/dist/dts/AiInput.d.ts +441 -146
  40. package/dist/dts/AiInput.d.ts.map +1 -1
  41. package/dist/dts/AiLanguageModel.d.ts +263 -0
  42. package/dist/dts/AiLanguageModel.d.ts.map +1 -0
  43. package/dist/dts/AiModel.d.ts +21 -20
  44. package/dist/dts/AiModel.d.ts.map +1 -1
  45. package/dist/dts/AiPlan.d.ts +90 -26
  46. package/dist/dts/AiPlan.d.ts.map +1 -1
  47. package/dist/dts/AiResponse.d.ts +711 -100
  48. package/dist/dts/AiResponse.d.ts.map +1 -1
  49. package/dist/dts/AiTelemetry.d.ts +175 -157
  50. package/dist/dts/AiTelemetry.d.ts.map +1 -1
  51. package/dist/dts/AiTool.d.ts +288 -0
  52. package/dist/dts/AiTool.d.ts.map +1 -0
  53. package/dist/dts/AiToolkit.d.ts +50 -111
  54. package/dist/dts/AiToolkit.d.ts.map +1 -1
  55. package/dist/dts/Tokenizer.d.ts +8 -6
  56. package/dist/dts/Tokenizer.d.ts.map +1 -1
  57. package/dist/dts/index.d.ts +8 -12
  58. package/dist/dts/index.d.ts.map +1 -1
  59. package/dist/dts/internal/common.d.ts +2 -0
  60. package/dist/dts/internal/common.d.ts.map +1 -0
  61. package/dist/esm/AiChat.js +62 -83
  62. package/dist/esm/AiChat.js.map +1 -1
  63. package/dist/esm/{Embeddings.js → AiEmbeddingModel.js} +10 -10
  64. package/dist/esm/AiEmbeddingModel.js.map +1 -0
  65. package/dist/esm/AiError.js +8 -1
  66. package/dist/esm/AiError.js.map +1 -1
  67. package/dist/esm/AiInput.js +316 -238
  68. package/dist/esm/AiInput.js.map +1 -1
  69. package/dist/esm/AiLanguageModel.js +300 -0
  70. package/dist/esm/AiLanguageModel.js.map +1 -0
  71. package/dist/esm/AiModel.js +11 -5
  72. package/dist/esm/AiModel.js.map +1 -1
  73. package/dist/esm/AiPlan.js +8 -2
  74. package/dist/esm/AiPlan.js.map +1 -1
  75. package/dist/esm/AiResponse.js +467 -162
  76. package/dist/esm/AiResponse.js.map +1 -1
  77. package/dist/esm/AiTelemetry.js +8 -2
  78. package/dist/esm/AiTelemetry.js.map +1 -1
  79. package/dist/esm/AiTool.js +82 -0
  80. package/dist/esm/AiTool.js.map +1 -0
  81. package/dist/esm/AiToolkit.js +118 -96
  82. package/dist/esm/AiToolkit.js.map +1 -1
  83. package/dist/esm/Tokenizer.js +14 -16
  84. package/dist/esm/Tokenizer.js.map +1 -1
  85. package/dist/esm/index.js +8 -12
  86. package/dist/esm/index.js.map +1 -1
  87. package/dist/esm/internal/aiPlan.js +4 -7
  88. package/dist/esm/internal/aiPlan.js.map +1 -1
  89. package/dist/esm/internal/common.js +14 -0
  90. package/dist/esm/internal/common.js.map +1 -0
  91. package/package.json +28 -36
  92. package/src/AiChat.ts +182 -207
  93. package/src/{Embeddings.ts → AiEmbeddingModel.ts} +19 -18
  94. package/src/AiError.ts +8 -1
  95. package/src/AiInput.ts +434 -313
  96. package/src/AiLanguageModel.ts +569 -0
  97. package/src/AiModel.ts +47 -29
  98. package/src/AiPlan.ts +102 -30
  99. package/src/AiResponse.ts +743 -187
  100. package/src/AiTelemetry.ts +214 -197
  101. package/src/AiTool.ts +496 -0
  102. package/src/AiToolkit.ts +200 -240
  103. package/src/Tokenizer.ts +18 -22
  104. package/src/index.ts +9 -14
  105. package/src/internal/aiPlan.ts +12 -14
  106. package/src/internal/common.ts +12 -0
  107. package/AiModels/package.json +0 -6
  108. package/AiRole/package.json +0 -6
  109. package/Completions/package.json +0 -6
  110. package/Embeddings/package.json +0 -6
  111. package/dist/cjs/AiModels.js +0 -54
  112. package/dist/cjs/AiModels.js.map +0 -1
  113. package/dist/cjs/AiRole.js +0 -106
  114. package/dist/cjs/AiRole.js.map +0 -1
  115. package/dist/cjs/Completions.js +0 -256
  116. package/dist/cjs/Completions.js.map +0 -1
  117. package/dist/cjs/Embeddings.js.map +0 -1
  118. package/dist/dts/AiModels.d.ts +0 -34
  119. package/dist/dts/AiModels.d.ts.map +0 -1
  120. package/dist/dts/AiRole.d.ts +0 -111
  121. package/dist/dts/AiRole.d.ts.map +0 -1
  122. package/dist/dts/Completions.d.ts +0 -128
  123. package/dist/dts/Completions.d.ts.map +0 -1
  124. package/dist/dts/Embeddings.d.ts.map +0 -1
  125. package/dist/esm/AiModels.js +0 -44
  126. package/dist/esm/AiModels.js.map +0 -1
  127. package/dist/esm/AiRole.js +0 -93
  128. package/dist/esm/AiRole.js.map +0 -1
  129. package/dist/esm/Completions.js +0 -245
  130. package/dist/esm/Completions.js.map +0 -1
  131. package/dist/esm/Embeddings.js.map +0 -1
  132. package/src/AiModels.ts +0 -77
  133. package/src/AiRole.ts +0 -122
  134. package/src/Completions.ts +0 -434
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
-
4
+ import * as Context from "effect/Context"
5
5
  import { dual } from "effect/Function"
6
6
  import * as Predicate from "effect/Predicate"
7
7
  import * as String from "effect/String"
8
8
  import type { Span } from "effect/Tracer"
9
9
  import type { Simplify } from "effect/Types"
10
+ import type { AiLanguageModelOptions } from "./AiLanguageModel.js"
11
+ import type { AiResponse } from "./AiResponse.js"
10
12
 
11
13
  /**
12
14
  * The attributes used to describe telemetry in the context of Generative
@@ -15,219 +17,213 @@ import type { Simplify } from "effect/Types"
15
17
  * {@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}
16
18
  *
17
19
  * @since 1.0.0
18
- * @category models
20
+ * @category Models
19
21
  */
20
22
  export type GenAITelemetryAttributes = Simplify<
21
- & GenAI.AttributesWithPrefix<GenAI.BaseAttributes, "gen_ai">
22
- & GenAI.AttributesWithPrefix<GenAI.OperationAttributes, "gen_ai.operation">
23
- & GenAI.AttributesWithPrefix<GenAI.TokenAttributes, "gen_ai.token">
24
- & GenAI.AttributesWithPrefix<GenAI.UsageAttributes, "gen_ai.usage">
25
- & GenAI.AttributesWithPrefix<GenAI.RequestAttributes, "gen_ai.request">
26
- & GenAI.AttributesWithPrefix<GenAI.ResponseAttributes, "gen_ai.response">
23
+ & AttributesWithPrefix<BaseAttributes, "gen_ai">
24
+ & AttributesWithPrefix<OperationAttributes, "gen_ai.operation">
25
+ & AttributesWithPrefix<TokenAttributes, "gen_ai.token">
26
+ & AttributesWithPrefix<UsageAttributes, "gen_ai.usage">
27
+ & AttributesWithPrefix<RequestAttributes, "gen_ai.request">
28
+ & AttributesWithPrefix<ResponseAttributes, "gen_ai.response">
27
29
  >
28
30
 
29
31
  /**
32
+ * All telemetry attributes which are part of the GenAI specification.
33
+ *
34
+ * @since 1.0.0
35
+ * @category Models
36
+ */
37
+ export type AllAttributes =
38
+ & BaseAttributes
39
+ & OperationAttributes
40
+ & TokenAttributes
41
+ & UsageAttributes
42
+ & RequestAttributes
43
+ & ResponseAttributes
44
+
45
+ /**
46
+ * Telemetry attributes which are part of the GenAI specification and are
47
+ * namespaced by `gen_ai`.
48
+ *
30
49
  * @since 1.0.0
31
- * @category models
50
+ * @category Models
32
51
  */
33
- export declare namespace GenAI {
52
+ export interface BaseAttributes {
34
53
  /**
35
- * All telemetry attributes which are part of the GenAI specification.
36
- *
37
- * @since 1.0.0
38
- * @category models
54
+ * The Generative AI product as identified by the client or server
55
+ * instrumentation.
39
56
  */
40
- export type AllAttributes =
41
- & BaseAttributes
42
- & OperationAttributes
43
- & TokenAttributes
44
- & UsageAttributes
45
- & RequestAttributes
46
- & ResponseAttributes
57
+ readonly system?: (string & {}) | WellKnownSystem | null | undefined
58
+ }
59
+
60
+ /**
61
+ * Telemetry attributes which are part of the GenAI specification and are
62
+ * namespaced by `gen_ai.operation`.
63
+ *
64
+ * @since 1.0.0
65
+ * @category Models
66
+ */
67
+ export interface OperationAttributes {
68
+ readonly name?: (string & {}) | WellKnownOperationName | null | undefined
69
+ }
70
+
71
+ /**
72
+ * Telemetry attributes which are part of the GenAI specification and are
73
+ * namespaced by `gen_ai.token`.
74
+ *
75
+ * @since 1.0.0
76
+ * @category Models
77
+ */
78
+ export interface TokenAttributes {
79
+ readonly type?: string | null | undefined
80
+ }
81
+
82
+ /**
83
+ * Telemetry attributes which are part of the GenAI specification and are
84
+ * namespaced by `gen_ai.usage`.
85
+ *
86
+ * @since 1.0.0
87
+ * @category Models
88
+ */
89
+ export interface UsageAttributes {
90
+ readonly inputTokens?: number | null | undefined
91
+ readonly outputTokens?: number | null | undefined
92
+ }
47
93
 
94
+ /**
95
+ * Telemetry attributes which are part of the GenAI specification and are
96
+ * namespaced by `gen_ai.request`.
97
+ *
98
+ * @since 1.0.0
99
+ * @category Models
100
+ */
101
+ export interface RequestAttributes {
48
102
  /**
49
- * Telemetry attributes which are part of the GenAI specification and are
50
- * namespaced by `gen_ai`.
51
- *
52
- * @since 1.0.0
53
- * @category models
103
+ * The name of the GenAI model a request is being made to.
54
104
  */
55
- export interface BaseAttributes {
56
- /**
57
- * The Generative AI product as identified by the client or server
58
- * instrumentation.
59
- */
60
- readonly system?: (string & {}) | WellKnownSystem | null | undefined
61
- }
62
-
105
+ readonly model?: string | null | undefined
63
106
  /**
64
- * Telemetry attributes which are part of the GenAI specification and are
65
- * namespaced by `gen_ai.operation`.
66
- *
67
- * @since 1.0.0
68
- * @category models
107
+ * The temperature setting for the GenAI request.
69
108
  */
70
- export interface OperationAttributes {
71
- readonly name?: (string & {}) | WellKnownOperationName | null | undefined
72
- }
73
-
109
+ readonly temperature?: number | null | undefined
74
110
  /**
75
- * Telemetry attributes which are part of the GenAI specification and are
76
- * namespaced by `gen_ai.token`.
77
- *
78
- * @since 1.0.0
79
- * @category models
111
+ * The temperature setting for the GenAI request.
80
112
  */
81
- export interface TokenAttributes {
82
- readonly type?: string | null | undefined
83
- }
84
-
113
+ readonly topK?: number | null | undefined
85
114
  /**
86
- * Telemetry attributes which are part of the GenAI specification and are
87
- * namespaced by `gen_ai.usage`.
88
- *
89
- * @since 1.0.0
90
- * @category models
115
+ * The top_k sampling setting for the GenAI request.
91
116
  */
92
- export interface UsageAttributes {
93
- readonly inputTokens?: number | null | undefined
94
- readonly outputTokens?: number | null | undefined
95
- }
96
-
117
+ readonly topP?: number | null | undefined
97
118
  /**
98
- * Telemetry attributes which are part of the GenAI specification and are
99
- * namespaced by `gen_ai.request`.
100
- *
101
- * @since 1.0.0
102
- * @category models
119
+ * The top_p sampling setting for the GenAI request.
103
120
  */
104
- export interface RequestAttributes {
105
- /**
106
- * The name of the GenAI model a request is being made to.
107
- */
108
- readonly model?: string | null | undefined
109
- /**
110
- * The temperature setting for the GenAI request.
111
- */
112
- readonly temperature?: number | null | undefined
113
- /**
114
- * The temperature setting for the GenAI request.
115
- */
116
- readonly topK?: number | null | undefined
117
- /**
118
- * The top_k sampling setting for the GenAI request.
119
- */
120
- readonly topP?: number | null | undefined
121
- /**
122
- * The top_p sampling setting for the GenAI request.
123
- */
124
- readonly maxTokens?: number | null | undefined
125
- /**
126
- * The encoding formats requested in an embeddings operation, if specified.
127
- */
128
- readonly encodingFormats?: ReadonlyArray<string> | null | undefined
129
- /**
130
- * List of sequences that the model will use to stop generating further
131
- * tokens.
132
- */
133
- readonly stopSequences?: ReadonlyArray<string> | null | undefined
134
- /**
135
- * The frequency penalty setting for the GenAI request.
136
- */
137
- readonly frequencyPenalty?: number | null | undefined
138
- /**
139
- * The presence penalty setting for the GenAI request.
140
- */
141
- readonly presencePenalty?: number | null | undefined
142
- /**
143
- * The seed setting for the GenAI request. Requests with same seed value
144
- * are more likely to return same result.
145
- */
146
- readonly seed?: number | null | undefined
147
- }
148
-
121
+ readonly maxTokens?: number | null | undefined
149
122
  /**
150
- * Telemetry attributes which are part of the GenAI specification and are
151
- * namespaced by `gen_ai.response`.
152
- *
153
- * @since 1.0.0
154
- * @category models
123
+ * The encoding formats requested in an embeddings operation, if specified.
155
124
  */
156
- export interface ResponseAttributes {
157
- /**
158
- * The unique identifier for the completion.
159
- */
160
- readonly id?: string | null | undefined
161
- /**
162
- * The name of the model that generated the response.
163
- */
164
- readonly model?: string | null | undefined
165
- /**
166
- * Array of reasons the model stopped generating tokens, corresponding to
167
- * each generation received.
168
- */
169
- readonly finishReasons?: ReadonlyArray<string> | null | undefined
170
- }
171
-
125
+ readonly encodingFormats?: ReadonlyArray<string> | null | undefined
172
126
  /**
173
- * The `gen_ai.operation.name` attribute has the following list of well-known
174
- * values.
175
- *
176
- * If one of them applies, then the respective value **MUST** be used;
177
- * otherwise, a custom value **MAY** be used.
178
- *
179
- * @since 1.0.0
180
- * @category models
127
+ * List of sequences that the model will use to stop generating further
128
+ * tokens.
181
129
  */
182
- export type WellKnownOperationName = "chat" | "embeddings" | "text_completion"
183
-
130
+ readonly stopSequences?: ReadonlyArray<string> | null | undefined
184
131
  /**
185
- * The `gen_ai.system` attribute has the following list of well-known values.
186
- *
187
- * If one of them applies, then the respective value **MUST** be used;
188
- * otherwise, a custom value **MAY** be used.
189
- *
190
- * @since 1.0.0
191
- * @category models
132
+ * The frequency penalty setting for the GenAI request.
192
133
  */
193
- export type WellKnownSystem =
194
- | "anthropic"
195
- | "aws.bedrock"
196
- | "az.ai.inference"
197
- | "az.ai.openai"
198
- | "cohere"
199
- | "deepseek"
200
- | "gemini"
201
- | "groq"
202
- | "ibm.watsonx.ai"
203
- | "mistral_ai"
204
- | "openai"
205
- | "perplexity"
206
- | "vertex_ai"
207
- | "xai"
208
-
134
+ readonly frequencyPenalty?: number | null | undefined
209
135
  /**
210
- * @since 1.0.0
211
- * @category models
136
+ * The presence penalty setting for the GenAI request.
212
137
  */
213
- export type AttributesWithPrefix<Attributes extends Record<string, any>, Prefix extends string> = {
214
- [Name in keyof Attributes as `${Prefix}.${FormatAttributeName<Name>}`]: Attributes[Name]
215
- }
138
+ readonly presencePenalty?: number | null | undefined
139
+ /**
140
+ * The seed setting for the GenAI request. Requests with same seed value
141
+ * are more likely to return same result.
142
+ */
143
+ readonly seed?: number | null | undefined
144
+ }
216
145
 
146
+ /**
147
+ * Telemetry attributes which are part of the GenAI specification and are
148
+ * namespaced by `gen_ai.response`.
149
+ *
150
+ * @since 1.0.0
151
+ * @category Models
152
+ */
153
+ export interface ResponseAttributes {
217
154
  /**
218
- * @since 1.0.0
219
- * @category models
155
+ * The unique identifier for the completion.
156
+ */
157
+ readonly id?: string | null | undefined
158
+ /**
159
+ * The name of the model that generated the response.
220
160
  */
221
- export type FormatAttributeName<T extends string | number | symbol> = T extends string ?
222
- T extends `${infer First}${infer Rest}`
223
- ? `${First extends Uppercase<First> ? "_" : ""}${Lowercase<First>}${FormatAttributeName<Rest>}`
224
- : T :
225
- never
161
+ readonly model?: string | null | undefined
162
+ /**
163
+ * Array of reasons the model stopped generating tokens, corresponding to
164
+ * each generation received.
165
+ */
166
+ readonly finishReasons?: ReadonlyArray<string> | null | undefined
167
+ }
168
+
169
+ /**
170
+ * The `gen_ai.operation.name` attribute has the following list of well-known
171
+ * values.
172
+ *
173
+ * If one of them applies, then the respective value **MUST** be used;
174
+ * otherwise, a custom value **MAY** be used.
175
+ *
176
+ * @since 1.0.0
177
+ * @category Models
178
+ */
179
+ export type WellKnownOperationName = "chat" | "embeddings" | "text_completion"
180
+
181
+ /**
182
+ * The `gen_ai.system` attribute has the following list of well-known values.
183
+ *
184
+ * If one of them applies, then the respective value **MUST** be used;
185
+ * otherwise, a custom value **MAY** be used.
186
+ *
187
+ * @since 1.0.0
188
+ * @category Models
189
+ */
190
+ export type WellKnownSystem =
191
+ | "anthropic"
192
+ | "aws.bedrock"
193
+ | "az.ai.inference"
194
+ | "az.ai.openai"
195
+ | "cohere"
196
+ | "deepseek"
197
+ | "gemini"
198
+ | "groq"
199
+ | "ibm.watsonx.ai"
200
+ | "mistral_ai"
201
+ | "openai"
202
+ | "perplexity"
203
+ | "vertex_ai"
204
+ | "xai"
205
+
206
+ /**
207
+ * @since 1.0.0
208
+ * @category Models
209
+ */
210
+ export type AttributesWithPrefix<Attributes extends Record<string, any>, Prefix extends string> = {
211
+ [Name in keyof Attributes as `${Prefix}.${FormatAttributeName<Name>}`]: Attributes[Name]
226
212
  }
227
213
 
228
214
  /**
229
215
  * @since 1.0.0
230
- * @category utilities
216
+ * @category Utility Types
217
+ */
218
+ export type FormatAttributeName<T extends string | number | symbol> = T extends string ?
219
+ T extends `${infer First}${infer Rest}`
220
+ ? `${First extends Uppercase<First> ? "_" : ""}${Lowercase<First>}${FormatAttributeName<Rest>}`
221
+ : T :
222
+ never
223
+
224
+ /**
225
+ * @since 1.0.0
226
+ * @category Utilities
231
227
  */
232
228
  export const addSpanAttributes = (
233
229
  keyPrefix: string,
@@ -241,23 +237,23 @@ export const addSpanAttributes = (
241
237
  }
242
238
  }
243
239
 
244
- const addSpanBaseAttributes = addSpanAttributes("gen_ai", String.camelToSnake)<GenAI.BaseAttributes>
245
- const addSpanOperationAttributes = addSpanAttributes("gen_ai.operation", String.camelToSnake)<GenAI.OperationAttributes>
246
- const addSpanRequestAttributes = addSpanAttributes("gen_ai.request", String.camelToSnake)<GenAI.RequestAttributes>
247
- const addSpanResponseAttributes = addSpanAttributes("gen_ai.response", String.camelToSnake)<GenAI.ResponseAttributes>
248
- const addSpanTokenAttributes = addSpanAttributes("gen_ai.token", String.camelToSnake)<GenAI.TokenAttributes>
249
- const addSpanUsageAttributes = addSpanAttributes("gen_ai.usage", String.camelToSnake)<GenAI.UsageAttributes>
240
+ const addSpanBaseAttributes = addSpanAttributes("gen_ai", String.camelToSnake)<BaseAttributes>
241
+ const addSpanOperationAttributes = addSpanAttributes("gen_ai.operation", String.camelToSnake)<OperationAttributes>
242
+ const addSpanRequestAttributes = addSpanAttributes("gen_ai.request", String.camelToSnake)<RequestAttributes>
243
+ const addSpanResponseAttributes = addSpanAttributes("gen_ai.response", String.camelToSnake)<ResponseAttributes>
244
+ const addSpanTokenAttributes = addSpanAttributes("gen_ai.token", String.camelToSnake)<TokenAttributes>
245
+ const addSpanUsageAttributes = addSpanAttributes("gen_ai.usage", String.camelToSnake)<UsageAttributes>
250
246
 
251
247
  /**
252
248
  * @since 1.0.0
253
- * @since models
249
+ * @since Models
254
250
  */
255
- export type GenAITelemetryAttributeOptions = GenAI.BaseAttributes & {
256
- readonly operation?: GenAI.OperationAttributes | undefined
257
- readonly request?: GenAI.RequestAttributes | undefined
258
- readonly response?: GenAI.ResponseAttributes | undefined
259
- readonly token?: GenAI.TokenAttributes | undefined
260
- readonly usage?: GenAI.UsageAttributes | undefined
251
+ export type GenAITelemetryAttributeOptions = BaseAttributes & {
252
+ readonly operation?: OperationAttributes | undefined
253
+ readonly request?: RequestAttributes | undefined
254
+ readonly response?: ResponseAttributes | undefined
255
+ readonly token?: TokenAttributes | undefined
256
+ readonly usage?: UsageAttributes | undefined
261
257
  }
262
258
 
263
259
  /**
@@ -266,7 +262,7 @@ export type GenAITelemetryAttributeOptions = GenAI.BaseAttributes & {
266
262
  * **NOTE**: This method will mutate the `Span` **in-place**.
267
263
  *
268
264
  * @since 1.0.0
269
- * @since utilities
265
+ * @since Utilities
270
266
  */
271
267
  export const addGenAIAnnotations: {
272
268
  /**
@@ -275,7 +271,7 @@ export const addGenAIAnnotations: {
275
271
  * **NOTE**: This method will mutate the `Span` **in-place**.
276
272
  *
277
273
  * @since 1.0.0
278
- * @since utilities
274
+ * @since Utilities
279
275
  */
280
276
  (options: GenAITelemetryAttributeOptions): (span: Span) => void
281
277
  /**
@@ -284,7 +280,7 @@ export const addGenAIAnnotations: {
284
280
  * **NOTE**: This method will mutate the `Span` **in-place**.
285
281
  *
286
282
  * @since 1.0.0
287
- * @since utilities
283
+ * @since Utilities
288
284
  */
289
285
  (span: Span, options: GenAITelemetryAttributeOptions): void
290
286
  } = dual<
@@ -294,7 +290,7 @@ export const addGenAIAnnotations: {
294
290
  * **NOTE**: This method will mutate the `Span` **in-place**.
295
291
  *
296
292
  * @since 1.0.0
297
- * @since utilities
293
+ * @since Utilities
298
294
  */
299
295
  (options: GenAITelemetryAttributeOptions) => (span: Span) => void,
300
296
  /**
@@ -303,7 +299,7 @@ export const addGenAIAnnotations: {
303
299
  * **NOTE**: This method will mutate the `Span` **in-place**.
304
300
  *
305
301
  * @since 1.0.0
306
- * @since utilities
302
+ * @since Utilities
307
303
  */
308
304
  (span: Span, options: GenAITelemetryAttributeOptions) => void
309
305
  >(2, (span, options) => {
@@ -314,3 +310,24 @@ export const addGenAIAnnotations: {
314
310
  if (Predicate.isNotNullable(options.token)) addSpanTokenAttributes(span, options.token)
315
311
  if (Predicate.isNotNullable(options.usage)) addSpanUsageAttributes(span, options.usage)
316
312
  })
313
+
314
+ /**
315
+ * Represents a method which receives the elements of the request / response to
316
+ * a large language model and can be used to modify the span used to trace the
317
+ * API call.
318
+ *
319
+ * @since 1.0.0
320
+ * @category Models
321
+ */
322
+ export interface SpanTransformer {
323
+ (options: AiLanguageModelOptions & { readonly response: AiResponse }): void
324
+ }
325
+
326
+ /**
327
+ * @since 1.0.0
328
+ * @category Context
329
+ */
330
+ export class CurrentSpanTransformer extends Context.Tag("@effect/ai/AiTelemetry/CurrentSpanTransformer")<
331
+ CurrentSpanTransformer,
332
+ SpanTransformer
333
+ >() {}