@effect/ai-openai-compat 4.0.0-beta.66 → 4.0.0-beta.68
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/OpenAiClient.d.ts +181 -42
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +42 -6
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +56 -8
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +35 -4
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +14 -9
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -1
- package/dist/OpenAiEmbeddingModel.js +9 -6
- package/dist/OpenAiEmbeddingModel.js.map +1 -1
- package/dist/OpenAiError.d.ts +85 -3
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiError.js +14 -1
- package/dist/OpenAiLanguageModel.d.ts +209 -12
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +9 -7
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +17 -14
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +3 -3
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/index.d.ts +63 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -7
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/OpenAiClient.ts +205 -43
- package/src/OpenAiConfig.ts +56 -8
- package/src/OpenAiEmbeddingModel.ts +16 -11
- package/src/OpenAiError.ts +85 -3
- package/src/OpenAiLanguageModel.ts +212 -15
- package/src/OpenAiTelemetry.ts +18 -15
- package/src/index.ts +63 -7
package/src/OpenAiError.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiError` module defines OpenAI-specific metadata that can be
|
|
3
|
+
* attached to the shared `AiError` error types used by the AI packages. It is
|
|
4
|
+
* primarily used by OpenAI-compatible clients to preserve provider details
|
|
5
|
+
* such as error codes, error types, request IDs, and rate limit headers while
|
|
6
|
+
* still exposing errors through the provider-neutral Effect AI error model.
|
|
7
|
+
*
|
|
8
|
+
* Use this module when mapping OpenAI API failures into `AiError` values and
|
|
9
|
+
* when consumers need enough structured metadata to debug failed requests,
|
|
10
|
+
* inspect quota or rate limit responses, or correlate an error with OpenAI
|
|
11
|
+
* support. The exported types are metadata shapes only; the module augmentation
|
|
12
|
+
* makes those shapes available on the corresponding shared AI error metadata
|
|
13
|
+
* interfaces without defining new runtime error classes.
|
|
14
|
+
*
|
|
15
|
+
* @since 4.0.0
|
|
3
16
|
*/
|
|
4
17
|
|
|
5
18
|
/**
|
|
6
19
|
* OpenAI-specific error metadata fields.
|
|
7
20
|
*
|
|
8
|
-
* @since 1.0.0
|
|
9
21
|
* @category models
|
|
22
|
+
* @since 4.0.0
|
|
10
23
|
*/
|
|
11
24
|
export type OpenAiErrorMetadata = {
|
|
12
25
|
/**
|
|
@@ -29,8 +42,8 @@ export type OpenAiErrorMetadata = {
|
|
|
29
42
|
* Extends base error metadata with rate limit specific information from
|
|
30
43
|
* OpenAI's rate limit headers.
|
|
31
44
|
*
|
|
32
|
-
* @since 1.0.0
|
|
33
45
|
* @category models
|
|
46
|
+
* @since 4.0.0
|
|
34
47
|
*/
|
|
35
48
|
export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
|
|
36
49
|
/**
|
|
@@ -52,42 +65,111 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
|
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
declare module "effect/unstable/ai/AiError" {
|
|
68
|
+
/**
|
|
69
|
+
* Metadata attached to rate limit errors returned by OpenAI-compatible APIs.
|
|
70
|
+
*
|
|
71
|
+
* @category models
|
|
72
|
+
* @since 4.0.0
|
|
73
|
+
*/
|
|
55
74
|
export interface RateLimitErrorMetadata {
|
|
56
75
|
readonly openai?: OpenAiRateLimitMetadata | null
|
|
57
76
|
}
|
|
58
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Metadata attached when an OpenAI-compatible provider reports that quota or
|
|
80
|
+
* billing limits have been exhausted.
|
|
81
|
+
*
|
|
82
|
+
* @category models
|
|
83
|
+
* @since 4.0.0
|
|
84
|
+
*/
|
|
59
85
|
export interface QuotaExhaustedErrorMetadata {
|
|
60
86
|
readonly openai?: OpenAiErrorMetadata | null
|
|
61
87
|
}
|
|
62
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Metadata attached to authentication failures from OpenAI-compatible APIs,
|
|
91
|
+
* such as invalid, missing, or unauthorized API credentials.
|
|
92
|
+
*
|
|
93
|
+
* @category models
|
|
94
|
+
* @since 4.0.0
|
|
95
|
+
*/
|
|
63
96
|
export interface AuthenticationErrorMetadata {
|
|
64
97
|
readonly openai?: OpenAiErrorMetadata | null
|
|
65
98
|
}
|
|
66
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Metadata attached when an OpenAI-compatible provider rejects content because
|
|
102
|
+
* it violates a safety or usage policy.
|
|
103
|
+
*
|
|
104
|
+
* @category models
|
|
105
|
+
* @since 4.0.0
|
|
106
|
+
*/
|
|
67
107
|
export interface ContentPolicyErrorMetadata {
|
|
68
108
|
readonly openai?: OpenAiErrorMetadata | null
|
|
69
109
|
}
|
|
70
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Metadata attached to malformed or unsupported requests rejected by an
|
|
113
|
+
* OpenAI-compatible API before model execution.
|
|
114
|
+
*
|
|
115
|
+
* @category models
|
|
116
|
+
* @since 4.0.0
|
|
117
|
+
*/
|
|
71
118
|
export interface InvalidRequestErrorMetadata {
|
|
72
119
|
readonly openai?: OpenAiErrorMetadata | null
|
|
73
120
|
}
|
|
74
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Metadata attached to unexpected server-side failures reported by an
|
|
124
|
+
* OpenAI-compatible provider.
|
|
125
|
+
*
|
|
126
|
+
* @category models
|
|
127
|
+
* @since 4.0.0
|
|
128
|
+
*/
|
|
75
129
|
export interface InternalProviderErrorMetadata {
|
|
76
130
|
readonly openai?: OpenAiErrorMetadata | null
|
|
77
131
|
}
|
|
78
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Metadata attached when an OpenAI-compatible response cannot be converted
|
|
135
|
+
* into the expected AI package output shape.
|
|
136
|
+
*
|
|
137
|
+
* @category models
|
|
138
|
+
* @since 4.0.0
|
|
139
|
+
*/
|
|
79
140
|
export interface InvalidOutputErrorMetadata {
|
|
80
141
|
readonly openai?: OpenAiErrorMetadata | null
|
|
81
142
|
}
|
|
82
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Metadata attached when an OpenAI-compatible structured output response does
|
|
146
|
+
* not satisfy the requested schema or parsing constraints.
|
|
147
|
+
*
|
|
148
|
+
* @category models
|
|
149
|
+
* @since 4.0.0
|
|
150
|
+
*/
|
|
83
151
|
export interface StructuredOutputErrorMetadata {
|
|
84
152
|
readonly openai?: OpenAiErrorMetadata | null
|
|
85
153
|
}
|
|
86
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Metadata attached when an OpenAI-compatible provider cannot support the
|
|
157
|
+
* schema supplied for structured output or tool definitions.
|
|
158
|
+
*
|
|
159
|
+
* @category models
|
|
160
|
+
* @since 4.0.0
|
|
161
|
+
*/
|
|
87
162
|
export interface UnsupportedSchemaErrorMetadata {
|
|
88
163
|
readonly openai?: OpenAiErrorMetadata | null
|
|
89
164
|
}
|
|
90
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Metadata attached when an OpenAI-compatible error response cannot be mapped
|
|
168
|
+
* to a more specific shared AI error category.
|
|
169
|
+
*
|
|
170
|
+
* @category models
|
|
171
|
+
* @since 4.0.0
|
|
172
|
+
*/
|
|
91
173
|
export interface UnknownErrorMetadata {
|
|
92
174
|
readonly openai?: OpenAiErrorMetadata | null
|
|
93
175
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Provides a LanguageModel implementation for OpenAI's chat completions API,
|
|
5
5
|
* supporting text generation, structured output, tool calling, and streaming.
|
|
6
6
|
*
|
|
7
|
-
* @since
|
|
7
|
+
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
9
|
import * as Context from "effect/Context"
|
|
10
10
|
import * as DateTime from "effect/DateTime"
|
|
@@ -61,8 +61,8 @@ type ImageDetail = "auto" | "low" | "high"
|
|
|
61
61
|
/**
|
|
62
62
|
* Service definition for OpenAI language model configuration.
|
|
63
63
|
*
|
|
64
|
-
* @since 1.0.0
|
|
65
64
|
* @category context
|
|
65
|
+
* @since 4.0.0
|
|
66
66
|
*/
|
|
67
67
|
export class Config extends Context.Service<
|
|
68
68
|
Config,
|
|
@@ -112,7 +112,16 @@ export class Config extends Context.Service<
|
|
|
112
112
|
// =============================================================================
|
|
113
113
|
|
|
114
114
|
declare module "effect/unstable/ai/Prompt" {
|
|
115
|
+
/**
|
|
116
|
+
* OpenAI-compatible options for file prompt parts.
|
|
117
|
+
*
|
|
118
|
+
* @category request
|
|
119
|
+
* @since 4.0.0
|
|
120
|
+
*/
|
|
115
121
|
export interface FilePartOptions extends ProviderOptions {
|
|
122
|
+
/**
|
|
123
|
+
* Provider-specific file options for OpenAI-compatible APIs.
|
|
124
|
+
*/
|
|
116
125
|
readonly openai?: {
|
|
117
126
|
/**
|
|
118
127
|
* The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`. Defaults to `auto`.
|
|
@@ -121,7 +130,16 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
121
130
|
} | null
|
|
122
131
|
}
|
|
123
132
|
|
|
133
|
+
/**
|
|
134
|
+
* OpenAI-compatible options for reasoning prompt parts.
|
|
135
|
+
*
|
|
136
|
+
* @category request
|
|
137
|
+
* @since 4.0.0
|
|
138
|
+
*/
|
|
124
139
|
export interface ReasoningPartOptions extends ProviderOptions {
|
|
140
|
+
/**
|
|
141
|
+
* Provider-specific reasoning options for OpenAI-compatible APIs.
|
|
142
|
+
*/
|
|
125
143
|
readonly openai?: {
|
|
126
144
|
/**
|
|
127
145
|
* The ID of the item to reference.
|
|
@@ -136,40 +154,67 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
136
154
|
} | null
|
|
137
155
|
}
|
|
138
156
|
|
|
157
|
+
/**
|
|
158
|
+
* OpenAI-compatible options for assistant tool-call prompt parts.
|
|
159
|
+
*
|
|
160
|
+
* @category request
|
|
161
|
+
* @since 4.0.0
|
|
162
|
+
*/
|
|
139
163
|
export interface ToolCallPartOptions extends ProviderOptions {
|
|
164
|
+
/**
|
|
165
|
+
* Provider-specific tool-call options for OpenAI-compatible APIs.
|
|
166
|
+
*/
|
|
140
167
|
readonly openai?: {
|
|
141
168
|
/**
|
|
142
169
|
* The ID of the item to reference.
|
|
143
170
|
*/
|
|
144
171
|
readonly itemId?: string | null
|
|
145
172
|
/**
|
|
146
|
-
* The status
|
|
173
|
+
* The status to send for the tool-call item.
|
|
147
174
|
*/
|
|
148
175
|
readonly status?: MessageStatus | null
|
|
149
176
|
} | null
|
|
150
177
|
}
|
|
151
178
|
|
|
179
|
+
/**
|
|
180
|
+
* OpenAI-compatible options for tool-result prompt parts.
|
|
181
|
+
*
|
|
182
|
+
* @category request
|
|
183
|
+
* @since 4.0.0
|
|
184
|
+
*/
|
|
152
185
|
export interface ToolResultPartOptions extends ProviderOptions {
|
|
186
|
+
/**
|
|
187
|
+
* Provider-specific tool-result options for OpenAI-compatible APIs.
|
|
188
|
+
*/
|
|
153
189
|
readonly openai?: {
|
|
154
190
|
/**
|
|
155
191
|
* The ID of the item to reference.
|
|
156
192
|
*/
|
|
157
193
|
readonly itemId?: string | null
|
|
158
194
|
/**
|
|
159
|
-
* The status
|
|
195
|
+
* The status to send for the tool-result item.
|
|
160
196
|
*/
|
|
161
197
|
readonly status?: MessageStatus | null
|
|
162
198
|
} | null
|
|
163
199
|
}
|
|
164
200
|
|
|
201
|
+
/**
|
|
202
|
+
* OpenAI-compatible options for text prompt parts.
|
|
203
|
+
*
|
|
204
|
+
* @category request
|
|
205
|
+
* @since 4.0.0
|
|
206
|
+
*/
|
|
165
207
|
export interface TextPartOptions extends ProviderOptions {
|
|
208
|
+
/**
|
|
209
|
+
* Provider-specific text options for OpenAI-compatible APIs.
|
|
210
|
+
*/
|
|
166
211
|
readonly openai?: {
|
|
167
212
|
/**
|
|
168
213
|
* The ID of the item to reference.
|
|
169
214
|
*/
|
|
170
215
|
readonly itemId?: string | null
|
|
171
216
|
/**
|
|
172
|
-
* The status
|
|
217
|
+
* The status to send for the text item.
|
|
173
218
|
*/
|
|
174
219
|
readonly status?: MessageStatus | null
|
|
175
220
|
/**
|
|
@@ -181,8 +226,20 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
181
226
|
}
|
|
182
227
|
|
|
183
228
|
declare module "effect/unstable/ai/Response" {
|
|
229
|
+
/**
|
|
230
|
+
* OpenAI-compatible metadata attached to a complete text response part.
|
|
231
|
+
*
|
|
232
|
+
* @category response
|
|
233
|
+
* @since 4.0.0
|
|
234
|
+
*/
|
|
184
235
|
export interface TextPartMetadata extends ProviderMetadata {
|
|
236
|
+
/**
|
|
237
|
+
* Provider-specific metadata returned for the text part.
|
|
238
|
+
*/
|
|
185
239
|
readonly openai?: {
|
|
240
|
+
/**
|
|
241
|
+
* The OpenAI item ID associated with the text part.
|
|
242
|
+
*/
|
|
186
243
|
readonly itemId?: string | null
|
|
187
244
|
/**
|
|
188
245
|
* If the model emits a refusal content part, the refusal explanation
|
|
@@ -191,7 +248,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
191
248
|
*/
|
|
192
249
|
readonly refusal?: string | null
|
|
193
250
|
/**
|
|
194
|
-
* The status
|
|
251
|
+
* The status returned for the text item.
|
|
195
252
|
*/
|
|
196
253
|
readonly status?: MessageStatus | null
|
|
197
254
|
/**
|
|
@@ -201,55 +258,163 @@ declare module "effect/unstable/ai/Response" {
|
|
|
201
258
|
}
|
|
202
259
|
}
|
|
203
260
|
|
|
261
|
+
/**
|
|
262
|
+
* OpenAI-compatible metadata emitted when a streamed text part starts.
|
|
263
|
+
*
|
|
264
|
+
* @category response
|
|
265
|
+
* @since 4.0.0
|
|
266
|
+
*/
|
|
204
267
|
export interface TextStartPartMetadata extends ProviderMetadata {
|
|
268
|
+
/**
|
|
269
|
+
* Provider-specific metadata returned for the streamed text start.
|
|
270
|
+
*/
|
|
205
271
|
readonly openai?: {
|
|
272
|
+
/**
|
|
273
|
+
* The OpenAI item ID associated with the streamed text part.
|
|
274
|
+
*/
|
|
206
275
|
readonly itemId?: string | null
|
|
207
276
|
} | null
|
|
208
277
|
}
|
|
209
278
|
|
|
279
|
+
/**
|
|
280
|
+
* OpenAI-compatible metadata emitted when a streamed text part ends.
|
|
281
|
+
*
|
|
282
|
+
* @category response
|
|
283
|
+
* @since 4.0.0
|
|
284
|
+
*/
|
|
210
285
|
export interface TextEndPartMetadata extends ProviderMetadata {
|
|
286
|
+
/**
|
|
287
|
+
* Provider-specific metadata returned for the streamed text end.
|
|
288
|
+
*/
|
|
211
289
|
readonly openai?: {
|
|
290
|
+
/**
|
|
291
|
+
* The OpenAI item ID associated with the streamed text part.
|
|
292
|
+
*/
|
|
212
293
|
readonly itemId?: string | null
|
|
294
|
+
/**
|
|
295
|
+
* The annotations collected for the completed streamed text part.
|
|
296
|
+
*/
|
|
213
297
|
readonly annotations?: ReadonlyArray<Annotation> | null
|
|
214
298
|
} | null
|
|
215
299
|
}
|
|
216
300
|
|
|
301
|
+
/**
|
|
302
|
+
* OpenAI-compatible metadata attached to a complete reasoning response part.
|
|
303
|
+
*
|
|
304
|
+
* @category response
|
|
305
|
+
* @since 4.0.0
|
|
306
|
+
*/
|
|
217
307
|
export interface ReasoningPartMetadata extends ProviderMetadata {
|
|
308
|
+
/**
|
|
309
|
+
* Provider-specific metadata returned for the reasoning part.
|
|
310
|
+
*/
|
|
218
311
|
readonly openai?: {
|
|
312
|
+
/**
|
|
313
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
314
|
+
*/
|
|
219
315
|
readonly itemId?: string | null
|
|
316
|
+
/**
|
|
317
|
+
* Encrypted reasoning content that can be sent back in later requests.
|
|
318
|
+
*/
|
|
220
319
|
readonly encryptedContent?: string | null
|
|
221
320
|
} | null
|
|
222
321
|
}
|
|
223
322
|
|
|
323
|
+
/**
|
|
324
|
+
* OpenAI-compatible metadata emitted when a streamed reasoning part starts.
|
|
325
|
+
*
|
|
326
|
+
* @category response
|
|
327
|
+
* @since 4.0.0
|
|
328
|
+
*/
|
|
224
329
|
export interface ReasoningStartPartMetadata extends ProviderMetadata {
|
|
330
|
+
/**
|
|
331
|
+
* Provider-specific metadata returned for the streamed reasoning start.
|
|
332
|
+
*/
|
|
225
333
|
readonly openai?: {
|
|
334
|
+
/**
|
|
335
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
336
|
+
*/
|
|
226
337
|
readonly itemId?: string | null
|
|
338
|
+
/**
|
|
339
|
+
* Encrypted reasoning content that can be sent back in later requests.
|
|
340
|
+
*/
|
|
227
341
|
readonly encryptedContent?: string | null
|
|
228
342
|
} | null
|
|
229
343
|
}
|
|
230
344
|
|
|
345
|
+
/**
|
|
346
|
+
* OpenAI-compatible metadata emitted for a streamed reasoning delta.
|
|
347
|
+
*
|
|
348
|
+
* @category response
|
|
349
|
+
* @since 4.0.0
|
|
350
|
+
*/
|
|
231
351
|
export interface ReasoningDeltaPartMetadata extends ProviderMetadata {
|
|
352
|
+
/**
|
|
353
|
+
* Provider-specific metadata returned for the streamed reasoning delta.
|
|
354
|
+
*/
|
|
232
355
|
readonly openai?: {
|
|
356
|
+
/**
|
|
357
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
358
|
+
*/
|
|
233
359
|
readonly itemId?: string | null
|
|
234
360
|
} | null
|
|
235
361
|
}
|
|
236
362
|
|
|
363
|
+
/**
|
|
364
|
+
* OpenAI-compatible metadata emitted when a streamed reasoning part ends.
|
|
365
|
+
*
|
|
366
|
+
* @category response
|
|
367
|
+
* @since 4.0.0
|
|
368
|
+
*/
|
|
237
369
|
export interface ReasoningEndPartMetadata extends ProviderMetadata {
|
|
370
|
+
/**
|
|
371
|
+
* Provider-specific metadata returned for the streamed reasoning end.
|
|
372
|
+
*/
|
|
238
373
|
readonly openai?: {
|
|
374
|
+
/**
|
|
375
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
376
|
+
*/
|
|
239
377
|
readonly itemId?: string | null
|
|
378
|
+
/**
|
|
379
|
+
* Encrypted reasoning content that can be sent back in later requests.
|
|
380
|
+
*/
|
|
240
381
|
readonly encryptedContent?: string
|
|
241
382
|
} | null
|
|
242
383
|
}
|
|
243
384
|
|
|
385
|
+
/**
|
|
386
|
+
* OpenAI-compatible metadata attached to tool-call response parts.
|
|
387
|
+
*
|
|
388
|
+
* @category response
|
|
389
|
+
* @since 4.0.0
|
|
390
|
+
*/
|
|
244
391
|
export interface ToolCallPartMetadata extends ProviderMetadata {
|
|
392
|
+
/**
|
|
393
|
+
* Provider-specific metadata returned for the tool call.
|
|
394
|
+
*/
|
|
245
395
|
readonly openai?: {
|
|
396
|
+
/**
|
|
397
|
+
* The OpenAI item ID associated with the tool call.
|
|
398
|
+
*/
|
|
246
399
|
readonly itemId?: string | null
|
|
247
400
|
} | null
|
|
248
401
|
}
|
|
249
402
|
|
|
403
|
+
/**
|
|
404
|
+
* OpenAI-compatible metadata attached to document source citations.
|
|
405
|
+
*
|
|
406
|
+
* @category response
|
|
407
|
+
* @since 4.0.0
|
|
408
|
+
*/
|
|
250
409
|
export interface DocumentSourcePartMetadata extends ProviderMetadata {
|
|
410
|
+
/**
|
|
411
|
+
* Provider-specific citation metadata for OpenAI-compatible APIs.
|
|
412
|
+
*/
|
|
251
413
|
readonly openai?:
|
|
252
414
|
| {
|
|
415
|
+
/**
|
|
416
|
+
* Identifies a citation to an uploaded file.
|
|
417
|
+
*/
|
|
253
418
|
readonly type: "file_citation"
|
|
254
419
|
/**
|
|
255
420
|
* The index of the file in the list of files.
|
|
@@ -261,6 +426,9 @@ declare module "effect/unstable/ai/Response" {
|
|
|
261
426
|
readonly fileId: string
|
|
262
427
|
}
|
|
263
428
|
| {
|
|
429
|
+
/**
|
|
430
|
+
* Identifies a citation to a generated file path.
|
|
431
|
+
*/
|
|
264
432
|
readonly type: "file_path"
|
|
265
433
|
/**
|
|
266
434
|
* The index of the file in the list of files.
|
|
@@ -272,6 +440,9 @@ declare module "effect/unstable/ai/Response" {
|
|
|
272
440
|
readonly fileId: string
|
|
273
441
|
}
|
|
274
442
|
| {
|
|
443
|
+
/**
|
|
444
|
+
* Identifies a citation to a file inside a container.
|
|
445
|
+
*/
|
|
275
446
|
readonly type: "container_file_citation"
|
|
276
447
|
/**
|
|
277
448
|
* The ID of the file.
|
|
@@ -285,8 +456,20 @@ declare module "effect/unstable/ai/Response" {
|
|
|
285
456
|
| null
|
|
286
457
|
}
|
|
287
458
|
|
|
459
|
+
/**
|
|
460
|
+
* OpenAI-compatible metadata attached to URL source citations.
|
|
461
|
+
*
|
|
462
|
+
* @category response
|
|
463
|
+
* @since 4.0.0
|
|
464
|
+
*/
|
|
288
465
|
export interface UrlSourcePartMetadata extends ProviderMetadata {
|
|
466
|
+
/**
|
|
467
|
+
* Provider-specific URL citation metadata for OpenAI-compatible APIs.
|
|
468
|
+
*/
|
|
289
469
|
readonly openai?: {
|
|
470
|
+
/**
|
|
471
|
+
* Identifies a citation to a URL.
|
|
472
|
+
*/
|
|
290
473
|
readonly type: "url_citation"
|
|
291
474
|
/**
|
|
292
475
|
* The index of the first character of the URL citation in the message.
|
|
@@ -299,8 +482,20 @@ declare module "effect/unstable/ai/Response" {
|
|
|
299
482
|
} | null
|
|
300
483
|
}
|
|
301
484
|
|
|
485
|
+
/**
|
|
486
|
+
* OpenAI-compatible metadata attached to finish response parts.
|
|
487
|
+
*
|
|
488
|
+
* @category response
|
|
489
|
+
* @since 4.0.0
|
|
490
|
+
*/
|
|
302
491
|
export interface FinishPartMetadata extends ProviderMetadata {
|
|
492
|
+
/**
|
|
493
|
+
* Provider-specific metadata returned when generation finishes.
|
|
494
|
+
*/
|
|
303
495
|
readonly openai?: {
|
|
496
|
+
/**
|
|
497
|
+
* The service tier reported by the OpenAI-compatible provider.
|
|
498
|
+
*/
|
|
304
499
|
readonly serviceTier?: "default" | "auto" | "flex" | "scale" | "priority" | null
|
|
305
500
|
} | null
|
|
306
501
|
}
|
|
@@ -311,8 +506,10 @@ declare module "effect/unstable/ai/Response" {
|
|
|
311
506
|
// =============================================================================
|
|
312
507
|
|
|
313
508
|
/**
|
|
314
|
-
*
|
|
509
|
+
* Creates an AI model descriptor for an OpenAI-compatible language model.
|
|
510
|
+
*
|
|
315
511
|
* @category constructors
|
|
512
|
+
* @since 4.0.0
|
|
316
513
|
*/
|
|
317
514
|
export const model = (
|
|
318
515
|
model: string,
|
|
@@ -322,7 +519,7 @@ export const model = (
|
|
|
322
519
|
|
|
323
520
|
// TODO
|
|
324
521
|
// /**
|
|
325
|
-
// * @since
|
|
522
|
+
// * @since 4.0.0
|
|
326
523
|
// * @category constructors
|
|
327
524
|
// */
|
|
328
525
|
// export const modelWithTokenizer = (
|
|
@@ -334,8 +531,8 @@ export const model = (
|
|
|
334
531
|
/**
|
|
335
532
|
* Creates an OpenAI language model service.
|
|
336
533
|
*
|
|
337
|
-
* @since 1.0.0
|
|
338
534
|
* @category constructors
|
|
535
|
+
* @since 4.0.0
|
|
339
536
|
*/
|
|
340
537
|
export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
|
|
341
538
|
readonly model: string
|
|
@@ -433,8 +630,8 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
|
|
|
433
630
|
/**
|
|
434
631
|
* Creates a layer for the OpenAI language model.
|
|
435
632
|
*
|
|
436
|
-
* @since 1.0.0
|
|
437
633
|
* @category layers
|
|
634
|
+
* @since 4.0.0
|
|
438
635
|
*/
|
|
439
636
|
export const layer = (options: {
|
|
440
637
|
readonly model: string
|
|
@@ -445,37 +642,37 @@ export const layer = (options: {
|
|
|
445
642
|
/**
|
|
446
643
|
* Provides config overrides for OpenAI language model operations.
|
|
447
644
|
*
|
|
448
|
-
* @since 1.0.0
|
|
449
645
|
* @category configuration
|
|
646
|
+
* @since 4.0.0
|
|
450
647
|
*/
|
|
451
648
|
export const withConfigOverride: {
|
|
452
649
|
/**
|
|
453
650
|
* Provides config overrides for OpenAI language model operations.
|
|
454
651
|
*
|
|
455
|
-
* @since 1.0.0
|
|
456
652
|
* @category configuration
|
|
653
|
+
* @since 4.0.0
|
|
457
654
|
*/
|
|
458
655
|
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
|
|
459
656
|
/**
|
|
460
657
|
* Provides config overrides for OpenAI language model operations.
|
|
461
658
|
*
|
|
462
|
-
* @since 1.0.0
|
|
463
659
|
* @category configuration
|
|
660
|
+
* @since 4.0.0
|
|
464
661
|
*/
|
|
465
662
|
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
|
|
466
663
|
} = dual<
|
|
467
664
|
/**
|
|
468
665
|
* Provides config overrides for OpenAI language model operations.
|
|
469
666
|
*
|
|
470
|
-
* @since 1.0.0
|
|
471
667
|
* @category configuration
|
|
668
|
+
* @since 4.0.0
|
|
472
669
|
*/
|
|
473
670
|
(overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
|
|
474
671
|
/**
|
|
475
672
|
* Provides config overrides for OpenAI language model operations.
|
|
476
673
|
*
|
|
477
|
-
* @since 1.0.0
|
|
478
674
|
* @category configuration
|
|
675
|
+
* @since 4.0.0
|
|
479
676
|
*/
|
|
480
677
|
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
|
|
481
678
|
>(2, (self, overrides) =>
|
package/src/OpenAiTelemetry.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* semantic conventions, extending the base GenAI attributes with OpenAI-specific
|
|
6
6
|
* request and response metadata.
|
|
7
7
|
*
|
|
8
|
-
* @since
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
import { dual } from "effect/Function"
|
|
11
11
|
import * as String from "effect/String"
|
|
@@ -19,8 +19,8 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
|
|
|
19
19
|
*
|
|
20
20
|
* {@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}
|
|
21
21
|
*
|
|
22
|
-
* @since 1.0.0
|
|
23
22
|
* @category models
|
|
23
|
+
* @since 4.0.0
|
|
24
24
|
*/
|
|
25
25
|
export type OpenAiTelemetryAttributes = Simplify<
|
|
26
26
|
& Telemetry.GenAITelemetryAttributes
|
|
@@ -32,8 +32,8 @@ export type OpenAiTelemetryAttributes = Simplify<
|
|
|
32
32
|
* All telemetry attributes which are part of the GenAI specification,
|
|
33
33
|
* including the OpenAi-specific attributes.
|
|
34
34
|
*
|
|
35
|
-
* @since 1.0.0
|
|
36
35
|
* @category models
|
|
36
|
+
* @since 4.0.0
|
|
37
37
|
*/
|
|
38
38
|
export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes
|
|
39
39
|
|
|
@@ -41,8 +41,8 @@ export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & Respon
|
|
|
41
41
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
42
42
|
* namespaced by `gen_ai.openai.request`.
|
|
43
43
|
*
|
|
44
|
-
* @since 1.0.0
|
|
45
44
|
* @category models
|
|
45
|
+
* @since 4.0.0
|
|
46
46
|
*/
|
|
47
47
|
export interface RequestAttributes {
|
|
48
48
|
/**
|
|
@@ -59,8 +59,8 @@ export interface RequestAttributes {
|
|
|
59
59
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
60
60
|
* namespaced by `gen_ai.openai.response`.
|
|
61
61
|
*
|
|
62
|
-
* @since 1.0.0
|
|
63
62
|
* @category models
|
|
63
|
+
* @since 4.0.0
|
|
64
64
|
*/
|
|
65
65
|
export interface ResponseAttributes {
|
|
66
66
|
/**
|
|
@@ -81,8 +81,8 @@ export interface ResponseAttributes {
|
|
|
81
81
|
* If one of them applies, then the respective value **MUST** be used;
|
|
82
82
|
* otherwise, a custom value **MAY** be used.
|
|
83
83
|
*
|
|
84
|
-
* @since 1.0.0
|
|
85
84
|
* @category models
|
|
85
|
+
* @since 4.0.0
|
|
86
86
|
*/
|
|
87
87
|
export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
|
|
88
88
|
|
|
@@ -93,14 +93,17 @@ export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
|
|
|
93
93
|
* If one of them applies, then the respective value **MUST** be used;
|
|
94
94
|
* otherwise, a custom value **MAY** be used.
|
|
95
95
|
*
|
|
96
|
-
* @since 1.0.0
|
|
97
96
|
* @category models
|
|
97
|
+
* @since 4.0.0
|
|
98
98
|
*/
|
|
99
99
|
export type WellKnownServiceTier = "auto" | "default"
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
102
|
+
* Options accepted by `addGenAIAnnotations`, combining standard GenAI telemetry
|
|
103
|
+
* attributes with optional OpenAI-compatible request and response attributes.
|
|
104
|
+
*
|
|
105
|
+
* @category models
|
|
106
|
+
* @since 4.0.0
|
|
104
107
|
*/
|
|
105
108
|
export type OpenAiTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
|
|
106
109
|
openai?: {
|
|
@@ -122,8 +125,8 @@ const addOpenAiResponseAttributes = Telemetry.addSpanAttributes("gen_ai.openai.r
|
|
|
122
125
|
*
|
|
123
126
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
124
127
|
*
|
|
125
|
-
* @
|
|
126
|
-
* @since
|
|
128
|
+
* @category tracing
|
|
129
|
+
* @since 4.0.0
|
|
127
130
|
*/
|
|
128
131
|
export const addGenAIAnnotations: {
|
|
129
132
|
/**
|
|
@@ -132,8 +135,8 @@ export const addGenAIAnnotations: {
|
|
|
132
135
|
*
|
|
133
136
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
134
137
|
*
|
|
135
|
-
* @
|
|
136
|
-
* @since
|
|
138
|
+
* @category tracing
|
|
139
|
+
* @since 4.0.0
|
|
137
140
|
*/
|
|
138
141
|
(options: OpenAiTelemetryAttributeOptions): (span: Span) => void
|
|
139
142
|
/**
|
|
@@ -142,8 +145,8 @@ export const addGenAIAnnotations: {
|
|
|
142
145
|
*
|
|
143
146
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
144
147
|
*
|
|
145
|
-
* @
|
|
146
|
-
* @since
|
|
148
|
+
* @category tracing
|
|
149
|
+
* @since 4.0.0
|
|
147
150
|
*/
|
|
148
151
|
(span: Span, options: OpenAiTelemetryAttributeOptions): void
|
|
149
152
|
} = dual(2, (span: Span, options: OpenAiTelemetryAttributeOptions) => {
|