@effect/ai-openai-compat 4.0.4 → 4.0.5
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/ai-docs/src/52_graphql/10_basics.ts +19 -13
- package/ai-docs/src/52_graphql/30_batching.ts +6 -4
- package/ai-docs/src/52_graphql/40_aliased-batching.ts +6 -4
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +3 -2
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiError.d.ts +10 -10
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.d.ts +16 -16
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +19 -15
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/internal/errors.js +5 -5
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/OpenAiClient.ts +3 -2
- package/src/OpenAiError.ts +10 -10
- package/src/OpenAiLanguageModel.ts +37 -31
- package/src/internal/errors.ts +5 -5
|
@@ -16,6 +16,7 @@ import { toCodecOpenAI } from "effect/ai/OpenAiStructuredOutput"
|
|
|
16
16
|
import type * as Prompt from "effect/ai/Prompt"
|
|
17
17
|
import type * as Response from "effect/ai/Response"
|
|
18
18
|
import * as Tool from "effect/ai/Tool"
|
|
19
|
+
import * as Arr from "effect/Array"
|
|
19
20
|
import * as Context from "effect/Context"
|
|
20
21
|
import * as DateTime from "effect/DateTime"
|
|
21
22
|
import * as Effect from "effect/Effect"
|
|
@@ -134,7 +135,7 @@ declare module "effect/ai/Prompt" {
|
|
|
134
135
|
/**
|
|
135
136
|
* Provider-specific file options for OpenAI-compatible APIs.
|
|
136
137
|
*/
|
|
137
|
-
readonly openai?: {
|
|
138
|
+
readonly "openai-compat"?: {
|
|
138
139
|
/**
|
|
139
140
|
* The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`. Defaults to `auto`.
|
|
140
141
|
*/
|
|
@@ -153,7 +154,7 @@ declare module "effect/ai/Prompt" {
|
|
|
153
154
|
/**
|
|
154
155
|
* Provider-specific reasoning options for OpenAI-compatible APIs.
|
|
155
156
|
*/
|
|
156
|
-
readonly openai?: {
|
|
157
|
+
readonly "openai-compat"?: {
|
|
157
158
|
/**
|
|
158
159
|
* The ID of the item to reference.
|
|
159
160
|
*/
|
|
@@ -184,7 +185,7 @@ declare module "effect/ai/Prompt" {
|
|
|
184
185
|
/**
|
|
185
186
|
* Provider-specific tool-call options for OpenAI-compatible APIs.
|
|
186
187
|
*/
|
|
187
|
-
readonly openai?: {
|
|
188
|
+
readonly "openai-compat"?: {
|
|
188
189
|
/**
|
|
189
190
|
* The ID of the item to reference.
|
|
190
191
|
*/
|
|
@@ -211,7 +212,7 @@ declare module "effect/ai/Prompt" {
|
|
|
211
212
|
/**
|
|
212
213
|
* Provider-specific tool-result options for OpenAI-compatible APIs.
|
|
213
214
|
*/
|
|
214
|
-
readonly openai?: {
|
|
215
|
+
readonly "openai-compat"?: {
|
|
215
216
|
/**
|
|
216
217
|
* The ID of the item to reference.
|
|
217
218
|
*/
|
|
@@ -234,7 +235,7 @@ declare module "effect/ai/Prompt" {
|
|
|
234
235
|
/**
|
|
235
236
|
* Provider-specific text options for OpenAI-compatible APIs.
|
|
236
237
|
*/
|
|
237
|
-
readonly openai?: {
|
|
238
|
+
readonly "openai-compat"?: {
|
|
238
239
|
/**
|
|
239
240
|
* The ID of the item to reference.
|
|
240
241
|
*/
|
|
@@ -263,7 +264,7 @@ declare module "effect/ai/Response" {
|
|
|
263
264
|
/**
|
|
264
265
|
* Provider-specific metadata returned for the text part.
|
|
265
266
|
*/
|
|
266
|
-
readonly openai?: {
|
|
267
|
+
readonly "openai-compat"?: {
|
|
267
268
|
/**
|
|
268
269
|
* The OpenAI item ID associated with the text part.
|
|
269
270
|
*/
|
|
@@ -296,7 +297,7 @@ declare module "effect/ai/Response" {
|
|
|
296
297
|
/**
|
|
297
298
|
* Provider-specific metadata returned for the streamed text start.
|
|
298
299
|
*/
|
|
299
|
-
readonly openai?: {
|
|
300
|
+
readonly "openai-compat"?: {
|
|
300
301
|
/**
|
|
301
302
|
* The OpenAI item ID associated with the streamed text part.
|
|
302
303
|
*/
|
|
@@ -315,7 +316,7 @@ declare module "effect/ai/Response" {
|
|
|
315
316
|
/**
|
|
316
317
|
* Provider-specific metadata returned for the streamed text end.
|
|
317
318
|
*/
|
|
318
|
-
readonly openai?: {
|
|
319
|
+
readonly "openai-compat"?: {
|
|
319
320
|
/**
|
|
320
321
|
* The OpenAI item ID associated with the streamed text part.
|
|
321
322
|
*/
|
|
@@ -338,7 +339,7 @@ declare module "effect/ai/Response" {
|
|
|
338
339
|
/**
|
|
339
340
|
* Provider-specific metadata returned for the reasoning part.
|
|
340
341
|
*/
|
|
341
|
-
readonly openai?: {
|
|
342
|
+
readonly "openai-compat"?: {
|
|
342
343
|
/**
|
|
343
344
|
* The OpenAI item ID associated with the reasoning part.
|
|
344
345
|
*/
|
|
@@ -365,7 +366,7 @@ declare module "effect/ai/Response" {
|
|
|
365
366
|
/**
|
|
366
367
|
* Provider-specific metadata returned for the streamed reasoning start.
|
|
367
368
|
*/
|
|
368
|
-
readonly openai?: {
|
|
369
|
+
readonly "openai-compat"?: {
|
|
369
370
|
/**
|
|
370
371
|
* The OpenAI item ID associated with the reasoning part.
|
|
371
372
|
*/
|
|
@@ -392,7 +393,7 @@ declare module "effect/ai/Response" {
|
|
|
392
393
|
/**
|
|
393
394
|
* Provider-specific metadata returned for the streamed reasoning delta.
|
|
394
395
|
*/
|
|
395
|
-
readonly openai?: {
|
|
396
|
+
readonly "openai-compat"?: {
|
|
396
397
|
/**
|
|
397
398
|
* The OpenAI item ID associated with the reasoning part.
|
|
398
399
|
*/
|
|
@@ -411,7 +412,7 @@ declare module "effect/ai/Response" {
|
|
|
411
412
|
/**
|
|
412
413
|
* Provider-specific metadata returned for the streamed reasoning end.
|
|
413
414
|
*/
|
|
414
|
-
readonly openai?: {
|
|
415
|
+
readonly "openai-compat"?: {
|
|
415
416
|
/**
|
|
416
417
|
* The OpenAI item ID associated with the reasoning part.
|
|
417
418
|
*/
|
|
@@ -434,7 +435,7 @@ declare module "effect/ai/Response" {
|
|
|
434
435
|
/**
|
|
435
436
|
* Provider-specific metadata returned for the tool call.
|
|
436
437
|
*/
|
|
437
|
-
readonly openai?: {
|
|
438
|
+
readonly "openai-compat"?: {
|
|
438
439
|
/**
|
|
439
440
|
* The OpenAI item ID associated with the tool call.
|
|
440
441
|
*/
|
|
@@ -457,7 +458,7 @@ declare module "effect/ai/Response" {
|
|
|
457
458
|
/**
|
|
458
459
|
* Provider-specific citation metadata for OpenAI-compatible APIs.
|
|
459
460
|
*/
|
|
460
|
-
readonly openai?:
|
|
461
|
+
readonly "openai-compat"?:
|
|
461
462
|
| {
|
|
462
463
|
/**
|
|
463
464
|
* Identifies a citation to an uploaded file.
|
|
@@ -514,7 +515,7 @@ declare module "effect/ai/Response" {
|
|
|
514
515
|
/**
|
|
515
516
|
* Provider-specific URL citation metadata for OpenAI-compatible APIs.
|
|
516
517
|
*/
|
|
517
|
-
readonly openai?: {
|
|
518
|
+
readonly "openai-compat"?: {
|
|
518
519
|
/**
|
|
519
520
|
* Identifies a citation to a URL.
|
|
520
521
|
*/
|
|
@@ -541,7 +542,7 @@ declare module "effect/ai/Response" {
|
|
|
541
542
|
/**
|
|
542
543
|
* Provider-specific metadata returned when generation finishes.
|
|
543
544
|
*/
|
|
544
|
-
readonly openai?: {
|
|
545
|
+
readonly "openai-compat"?: {
|
|
545
546
|
/**
|
|
546
547
|
* The service tier reported by the OpenAI-compatible provider.
|
|
547
548
|
*/
|
|
@@ -945,7 +946,7 @@ const prepareMessages = Effect.fnUntraced(
|
|
|
945
946
|
|
|
946
947
|
case "reasoning": {
|
|
947
948
|
reasoning += part.text
|
|
948
|
-
reasoningField ??= part.options
|
|
949
|
+
reasoningField ??= part.options["openai-compat"]?.reasoningField ?? undefined
|
|
949
950
|
break
|
|
950
951
|
}
|
|
951
952
|
|
|
@@ -1081,7 +1082,7 @@ const makeResponse = Effect.fnUntraced(
|
|
|
1081
1082
|
const reasoningField = getResponseReasoningField(message)
|
|
1082
1083
|
const reasoning = reasoningField !== undefined ? message[reasoningField] : undefined
|
|
1083
1084
|
if (reasoningField !== undefined && Predicate.isNotNullish(reasoning) && reasoning.length > 0) {
|
|
1084
|
-
parts.push({ type: "reasoning", text: reasoning, metadata: { openai: { reasoningField } } })
|
|
1085
|
+
parts.push({ type: "reasoning", text: reasoning, metadata: { "openai-compat": { reasoningField } } })
|
|
1085
1086
|
}
|
|
1086
1087
|
|
|
1087
1088
|
if (
|
|
@@ -1115,7 +1116,7 @@ const makeResponse = Effect.fnUntraced(
|
|
|
1115
1116
|
name: toolName,
|
|
1116
1117
|
params,
|
|
1117
1118
|
metadata: {
|
|
1118
|
-
openai: {
|
|
1119
|
+
"openai-compat": {
|
|
1119
1120
|
...makeItemIdMetadata(toolCall.id),
|
|
1120
1121
|
...makeExtraContentMetadata(toolCall.extra_content ?? undefined)
|
|
1121
1122
|
}
|
|
@@ -1136,7 +1137,7 @@ const makeResponse = Effect.fnUntraced(
|
|
|
1136
1137
|
reason: finishReason,
|
|
1137
1138
|
usage: getUsage(rawResponse.usage),
|
|
1138
1139
|
response: buildHttpResponseDetails(response),
|
|
1139
|
-
...(serviceTier !== undefined && { metadata: { openai: { serviceTier } } })
|
|
1140
|
+
...(serviceTier !== undefined && { metadata: { "openai-compat": { serviceTier } } })
|
|
1140
1141
|
})
|
|
1141
1142
|
|
|
1142
1143
|
return parts
|
|
@@ -1180,7 +1181,7 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1180
1181
|
parts.push({
|
|
1181
1182
|
type: "reasoning-end",
|
|
1182
1183
|
id: reasoningId,
|
|
1183
|
-
metadata: { openai: { ...makeItemIdMetadata(reasoningId) } }
|
|
1184
|
+
metadata: { "openai-compat": { ...makeItemIdMetadata(reasoningId) } }
|
|
1184
1185
|
})
|
|
1185
1186
|
}
|
|
1186
1187
|
|
|
@@ -1188,7 +1189,7 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1188
1189
|
parts.push({
|
|
1189
1190
|
type: "text-end",
|
|
1190
1191
|
id: textId,
|
|
1191
|
-
metadata: { openai: { ...makeItemIdMetadata(textId) } }
|
|
1192
|
+
metadata: { "openai-compat": { ...makeItemIdMetadata(textId) } }
|
|
1192
1193
|
})
|
|
1193
1194
|
}
|
|
1194
1195
|
|
|
@@ -1214,7 +1215,7 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1214
1215
|
name: toolCall.name,
|
|
1215
1216
|
params,
|
|
1216
1217
|
metadata: {
|
|
1217
|
-
openai: {
|
|
1218
|
+
"openai-compat": {
|
|
1218
1219
|
...makeItemIdMetadata(toolCall.id),
|
|
1219
1220
|
...makeExtraContentMetadata(toolCall.extraContent)
|
|
1220
1221
|
}
|
|
@@ -1230,7 +1231,7 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1230
1231
|
usage: getUsage(usage),
|
|
1231
1232
|
response: buildHttpResponseDetails(response),
|
|
1232
1233
|
...(normalizedServiceTier !== undefined
|
|
1233
|
-
? { metadata: { openai: { serviceTier: normalizedServiceTier } } }
|
|
1234
|
+
? { metadata: { "openai-compat": { serviceTier: normalizedServiceTier } } }
|
|
1234
1235
|
: undefined)
|
|
1235
1236
|
})
|
|
1236
1237
|
return parts
|
|
@@ -1277,7 +1278,7 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1277
1278
|
parts.push({
|
|
1278
1279
|
type: "reasoning-start",
|
|
1279
1280
|
id: reasoningId,
|
|
1280
|
-
metadata: { openai: { ...makeItemIdMetadata(reasoningId), reasoningField } }
|
|
1281
|
+
metadata: { "openai-compat": { ...makeItemIdMetadata(reasoningId), reasoningField } }
|
|
1281
1282
|
})
|
|
1282
1283
|
}
|
|
1283
1284
|
parts.push({ type: "reasoning-delta", id: reasoningId, delta: reasoningDelta })
|
|
@@ -1289,7 +1290,7 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1289
1290
|
parts.push({
|
|
1290
1291
|
type: "reasoning-end",
|
|
1291
1292
|
id: reasoningId,
|
|
1292
|
-
metadata: { openai: { ...makeItemIdMetadata(reasoningId) } }
|
|
1293
|
+
metadata: { "openai-compat": { ...makeItemIdMetadata(reasoningId) } }
|
|
1293
1294
|
})
|
|
1294
1295
|
}
|
|
1295
1296
|
|
|
@@ -1298,7 +1299,7 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1298
1299
|
parts.push({
|
|
1299
1300
|
type: "text-start",
|
|
1300
1301
|
id: textId,
|
|
1301
|
-
metadata: { openai: { ...makeItemIdMetadata(textId) } }
|
|
1302
|
+
metadata: { "openai-compat": { ...makeItemIdMetadata(textId) } }
|
|
1302
1303
|
})
|
|
1303
1304
|
}
|
|
1304
1305
|
parts.push({ type: "text-delta", id: textId, delta: choice.delta.content })
|
|
@@ -1344,7 +1345,8 @@ const makeStreamResponse = Effect.fnUntraced(
|
|
|
1344
1345
|
|
|
1345
1346
|
return parts
|
|
1346
1347
|
})),
|
|
1347
|
-
Stream.
|
|
1348
|
+
Stream.filter(Arr.isArrayNonEmpty),
|
|
1349
|
+
Stream.flattenArray
|
|
1348
1350
|
)
|
|
1349
1351
|
}
|
|
1350
1352
|
)
|
|
@@ -1404,7 +1406,7 @@ const annotateStreamResponse = (span: Span, part: Response.StreamPartEncoded) =>
|
|
|
1404
1406
|
})
|
|
1405
1407
|
}
|
|
1406
1408
|
if (part.type === "finish") {
|
|
1407
|
-
const serviceTier = (part.metadata as any)?.openai?.serviceTier as string | undefined
|
|
1409
|
+
const serviceTier = (part.metadata as any)?.["openai-compat"]?.serviceTier as string | undefined
|
|
1408
1410
|
addGenAIAnnotations(span, {
|
|
1409
1411
|
response: {
|
|
1410
1412
|
finishReasons: [part.reason]
|
|
@@ -1745,6 +1747,10 @@ const toChatMessageContent = (
|
|
|
1745
1747
|
return content
|
|
1746
1748
|
}
|
|
1747
1749
|
|
|
1750
|
+
if (content.length === 1 && content[0].type === "input_text") {
|
|
1751
|
+
return content[0].text
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1748
1754
|
const parts: Array<ChatCompletionContentPart> = []
|
|
1749
1755
|
|
|
1750
1756
|
for (const part of content) {
|
|
@@ -1804,7 +1810,7 @@ const isFileId = (data: string, config: typeof Config.Service): boolean =>
|
|
|
1804
1810
|
|
|
1805
1811
|
const getExtraContent = (
|
|
1806
1812
|
part: Prompt.ToolCallPart
|
|
1807
|
-
): Schema.JsonObject | null => part.options
|
|
1813
|
+
): Schema.JsonObject | null => part.options["openai-compat"]?.extraContent ?? null
|
|
1808
1814
|
|
|
1809
1815
|
/**
|
|
1810
1816
|
* The chat message field carrying reasoning text. Providers differ: DeepSeek,
|
|
@@ -1823,7 +1829,7 @@ const getResponseReasoningField = (message: {
|
|
|
1823
1829
|
? "reasoning_content"
|
|
1824
1830
|
: undefined
|
|
1825
1831
|
|
|
1826
|
-
const getImageDetail = (part: Prompt.FilePart): ImageDetail => part.options
|
|
1832
|
+
const getImageDetail = (part: Prompt.FilePart): ImageDetail => part.options["openai-compat"]?.imageDetail ?? "auto"
|
|
1827
1833
|
|
|
1828
1834
|
const makeItemIdMetadata = (itemId: string | undefined) => itemId !== undefined ? { itemId } : undefined
|
|
1829
1835
|
|
package/src/internal/errors.ts
CHANGED
|
@@ -230,7 +230,7 @@ export const mapStatusCodeToReason = ({ status, headers, message, metadata, http
|
|
|
230
230
|
case 400:
|
|
231
231
|
return new AiError.InvalidRequestError({
|
|
232
232
|
description: errorDescription,
|
|
233
|
-
metadata: { openai: metadata },
|
|
233
|
+
metadata: { "openai-compat": metadata },
|
|
234
234
|
http
|
|
235
235
|
})
|
|
236
236
|
case 401:
|
|
@@ -250,14 +250,14 @@ export const mapStatusCodeToReason = ({ status, headers, message, metadata, http
|
|
|
250
250
|
case 404:
|
|
251
251
|
return new AiError.InvalidRequestError({
|
|
252
252
|
description: errorDescription,
|
|
253
|
-
metadata: { openai: metadata },
|
|
253
|
+
metadata: { "openai-compat": metadata },
|
|
254
254
|
http
|
|
255
255
|
})
|
|
256
256
|
case 409:
|
|
257
257
|
case 422:
|
|
258
258
|
return new AiError.InvalidRequestError({
|
|
259
259
|
description: errorDescription,
|
|
260
|
-
metadata: { openai: metadata },
|
|
260
|
+
metadata: { "openai-compat": metadata },
|
|
261
261
|
http
|
|
262
262
|
})
|
|
263
263
|
case 429: {
|
|
@@ -268,7 +268,7 @@ export const mapStatusCodeToReason = ({ status, headers, message, metadata, http
|
|
|
268
268
|
metadata.errorType?.includes("exhausted")
|
|
269
269
|
) {
|
|
270
270
|
return new AiError.QuotaExhaustedError({
|
|
271
|
-
metadata: { openai: metadata },
|
|
271
|
+
metadata: { "openai-compat": metadata },
|
|
272
272
|
http
|
|
273
273
|
})
|
|
274
274
|
}
|
|
@@ -276,7 +276,7 @@ export const mapStatusCodeToReason = ({ status, headers, message, metadata, http
|
|
|
276
276
|
return new AiError.RateLimitError({
|
|
277
277
|
retryAfter,
|
|
278
278
|
metadata: {
|
|
279
|
-
openai: {
|
|
279
|
+
"openai-compat": {
|
|
280
280
|
...metadata,
|
|
281
281
|
...rateLimitMetadata
|
|
282
282
|
}
|