@effect/ai-openai-compat 4.0.0-rc.117 → 4.0.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.
- package/AGENTS.md +4 -4
- package/CLAUDE.md +4 -4
- package/README.md +15 -4
- package/ai-docs/package.json +1 -1
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +1 -1
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +1 -1
- package/ai-docs/src/03_stream/30_encoding.ts +1 -1
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +2 -2
- package/ai-docs/src/08_observability/index.md +1 -1
- package/ai-docs/src/40_sql/10_basics.ts +2 -2
- package/ai-docs/src/40_sql/index.md +1 -1
- package/ai-docs/src/50_http-client/10_basics.ts +1 -1
- package/ai-docs/src/51_http-server/10_basics.ts +2 -2
- package/ai-docs/src/51_http-server/20_testing.ts +2 -2
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +1 -1
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +1 -1
- package/ai-docs/src/60_child-process/index.md +1 -1
- package/ai-docs/src/70_cli/10_basics.ts +1 -1
- package/ai-docs/src/70_cli/index.md +1 -1
- package/ai-docs/src/71_ai/10_language-model.ts +2 -2
- package/ai-docs/src/71_ai/20_tools.ts +2 -2
- package/ai-docs/src/71_ai/30_chat.ts +2 -2
- package/ai-docs/src/80_cluster/10_entities.ts +3 -3
- package/dist/OpenAiClient.d.ts +61 -9
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +13 -16
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +1 -1
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +10 -11
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -1
- package/dist/OpenAiEmbeddingModel.js +9 -3
- package/dist/OpenAiEmbeddingModel.js.map +1 -1
- package/dist/OpenAiError.d.ts +1 -1
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.d.ts +27 -14
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +17 -8
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +9 -1
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +1 -1
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +1 -1
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/OpenAiClient.ts +53 -8
- package/src/OpenAiConfig.ts +1 -1
- package/src/OpenAiEmbeddingModel.ts +14 -3
- package/src/OpenAiError.ts +1 -1
- package/src/OpenAiLanguageModel.ts +44 -14
- package/src/OpenAiTelemetry.ts +1 -1
- package/src/index.ts +3 -0
- package/src/internal/errors.ts +6 -6
- package/src/internal/utilities.ts +1 -1
|
@@ -6,13 +6,23 @@
|
|
|
6
6
|
* or streaming chat completion results back into Effect AI response content and
|
|
7
7
|
* metadata.
|
|
8
8
|
*
|
|
9
|
+
* @stability unstable
|
|
9
10
|
* @since 4.0.0
|
|
10
11
|
*/
|
|
12
|
+
import * as AiError from "effect/ai/AiError"
|
|
13
|
+
import * as LanguageModel from "effect/ai/LanguageModel"
|
|
14
|
+
import * as AiModel from "effect/ai/Model"
|
|
15
|
+
import { toCodecOpenAI } from "effect/ai/OpenAiStructuredOutput"
|
|
16
|
+
import type * as Prompt from "effect/ai/Prompt"
|
|
17
|
+
import type * as Response from "effect/ai/Response"
|
|
18
|
+
import * as Tool from "effect/ai/Tool"
|
|
11
19
|
import * as Context from "effect/Context"
|
|
12
20
|
import * as DateTime from "effect/DateTime"
|
|
13
21
|
import * as Effect from "effect/Effect"
|
|
14
|
-
import * as
|
|
22
|
+
import * as Base64 from "effect/encoding/Base64"
|
|
15
23
|
import { dual } from "effect/Function"
|
|
24
|
+
import type * as HttpClientRequest from "effect/http/HttpClientRequest"
|
|
25
|
+
import type * as HttpClientResponse from "effect/http/HttpClientResponse"
|
|
16
26
|
import * as Layer from "effect/Layer"
|
|
17
27
|
import * as Option from "effect/Option"
|
|
18
28
|
import * as Predicate from "effect/Predicate"
|
|
@@ -23,15 +33,6 @@ import * as AST from "effect/SchemaAST"
|
|
|
23
33
|
import * as Stream from "effect/Stream"
|
|
24
34
|
import type { Span } from "effect/Tracer"
|
|
25
35
|
import type { DeepMutable, Simplify } from "effect/Types"
|
|
26
|
-
import * as AiError from "effect/unstable/ai/AiError"
|
|
27
|
-
import * as LanguageModel from "effect/unstable/ai/LanguageModel"
|
|
28
|
-
import * as AiModel from "effect/unstable/ai/Model"
|
|
29
|
-
import { toCodecOpenAI } from "effect/unstable/ai/OpenAiStructuredOutput"
|
|
30
|
-
import type * as Prompt from "effect/unstable/ai/Prompt"
|
|
31
|
-
import type * as Response from "effect/unstable/ai/Response"
|
|
32
|
-
import * as Tool from "effect/unstable/ai/Tool"
|
|
33
|
-
import type * as HttpClientRequest from "effect/unstable/http/HttpClientRequest"
|
|
34
|
-
import type * as HttpClientResponse from "effect/unstable/http/HttpClientResponse"
|
|
35
36
|
import * as InternalUtilities from "./internal/utilities.ts"
|
|
36
37
|
import {
|
|
37
38
|
type Annotation,
|
|
@@ -111,6 +112,7 @@ type ModelConfig = Omit<ConfigOptions, "model"> & { readonly [x: string]: unknow
|
|
|
111
112
|
*
|
|
112
113
|
* @see {@link withConfigOverride} for scoping language model request overrides
|
|
113
114
|
*
|
|
115
|
+
* @stability unstable
|
|
114
116
|
* @category services
|
|
115
117
|
* @since 4.0.0
|
|
116
118
|
*/
|
|
@@ -123,10 +125,11 @@ export class Config extends Context.Service<
|
|
|
123
125
|
// Provider Options / Metadata
|
|
124
126
|
// =============================================================================
|
|
125
127
|
|
|
126
|
-
declare module "effect/
|
|
128
|
+
declare module "effect/ai/Prompt" {
|
|
127
129
|
/**
|
|
128
130
|
* OpenAI-compatible options for file prompt parts.
|
|
129
131
|
*
|
|
132
|
+
* @stability unstable
|
|
130
133
|
* @category models
|
|
131
134
|
* @since 4.0.0
|
|
132
135
|
*/
|
|
@@ -145,6 +148,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
145
148
|
/**
|
|
146
149
|
* OpenAI-compatible options for reasoning prompt parts.
|
|
147
150
|
*
|
|
151
|
+
* @stability unstable
|
|
148
152
|
* @category models
|
|
149
153
|
* @since 4.0.0
|
|
150
154
|
*/
|
|
@@ -169,6 +173,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
169
173
|
/**
|
|
170
174
|
* OpenAI-compatible options for assistant tool-call prompt parts.
|
|
171
175
|
*
|
|
176
|
+
* @stability unstable
|
|
172
177
|
* @category models
|
|
173
178
|
* @since 4.0.0
|
|
174
179
|
*/
|
|
@@ -191,6 +196,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
191
196
|
/**
|
|
192
197
|
* OpenAI-compatible options for tool-result prompt parts.
|
|
193
198
|
*
|
|
199
|
+
* @stability unstable
|
|
194
200
|
* @category models
|
|
195
201
|
* @since 4.0.0
|
|
196
202
|
*/
|
|
@@ -213,6 +219,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
213
219
|
/**
|
|
214
220
|
* OpenAI-compatible options for text prompt parts.
|
|
215
221
|
*
|
|
222
|
+
* @stability unstable
|
|
216
223
|
* @category models
|
|
217
224
|
* @since 4.0.0
|
|
218
225
|
*/
|
|
@@ -237,10 +244,11 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
237
244
|
}
|
|
238
245
|
}
|
|
239
246
|
|
|
240
|
-
declare module "effect/
|
|
247
|
+
declare module "effect/ai/Response" {
|
|
241
248
|
/**
|
|
242
249
|
* OpenAI-compatible metadata attached to a complete text response part.
|
|
243
250
|
*
|
|
251
|
+
* @stability unstable
|
|
244
252
|
* @category models
|
|
245
253
|
* @since 4.0.0
|
|
246
254
|
*/
|
|
@@ -273,6 +281,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
273
281
|
/**
|
|
274
282
|
* OpenAI-compatible metadata emitted when a streamed text part starts.
|
|
275
283
|
*
|
|
284
|
+
* @stability unstable
|
|
276
285
|
* @category models
|
|
277
286
|
* @since 4.0.0
|
|
278
287
|
*/
|
|
@@ -291,6 +300,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
291
300
|
/**
|
|
292
301
|
* OpenAI-compatible metadata emitted when a streamed text part ends.
|
|
293
302
|
*
|
|
303
|
+
* @stability unstable
|
|
294
304
|
* @category models
|
|
295
305
|
* @since 4.0.0
|
|
296
306
|
*/
|
|
@@ -313,6 +323,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
313
323
|
/**
|
|
314
324
|
* OpenAI-compatible metadata attached to a complete reasoning response part.
|
|
315
325
|
*
|
|
326
|
+
* @stability unstable
|
|
316
327
|
* @category models
|
|
317
328
|
* @since 4.0.0
|
|
318
329
|
*/
|
|
@@ -335,6 +346,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
335
346
|
/**
|
|
336
347
|
* OpenAI-compatible metadata emitted when a streamed reasoning part starts.
|
|
337
348
|
*
|
|
349
|
+
* @stability unstable
|
|
338
350
|
* @category models
|
|
339
351
|
* @since 4.0.0
|
|
340
352
|
*/
|
|
@@ -357,6 +369,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
357
369
|
/**
|
|
358
370
|
* OpenAI-compatible metadata emitted for a streamed reasoning delta.
|
|
359
371
|
*
|
|
372
|
+
* @stability unstable
|
|
360
373
|
* @category models
|
|
361
374
|
* @since 4.0.0
|
|
362
375
|
*/
|
|
@@ -375,6 +388,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
375
388
|
/**
|
|
376
389
|
* OpenAI-compatible metadata emitted when a streamed reasoning part ends.
|
|
377
390
|
*
|
|
391
|
+
* @stability unstable
|
|
378
392
|
* @category models
|
|
379
393
|
* @since 4.0.0
|
|
380
394
|
*/
|
|
@@ -397,6 +411,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
397
411
|
/**
|
|
398
412
|
* OpenAI-compatible metadata attached to tool-call response parts.
|
|
399
413
|
*
|
|
414
|
+
* @stability unstable
|
|
400
415
|
* @category models
|
|
401
416
|
* @since 4.0.0
|
|
402
417
|
*/
|
|
@@ -415,6 +430,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
415
430
|
/**
|
|
416
431
|
* OpenAI-compatible metadata attached to document source citations.
|
|
417
432
|
*
|
|
433
|
+
* @stability unstable
|
|
418
434
|
* @category models
|
|
419
435
|
* @since 4.0.0
|
|
420
436
|
*/
|
|
@@ -471,6 +487,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
471
487
|
/**
|
|
472
488
|
* OpenAI-compatible metadata attached to URL source citations.
|
|
473
489
|
*
|
|
490
|
+
* @stability unstable
|
|
474
491
|
* @category models
|
|
475
492
|
* @since 4.0.0
|
|
476
493
|
*/
|
|
@@ -497,6 +514,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
497
514
|
/**
|
|
498
515
|
* OpenAI-compatible metadata attached to finish response parts.
|
|
499
516
|
*
|
|
517
|
+
* @stability unstable
|
|
500
518
|
* @category models
|
|
501
519
|
* @since 4.0.0
|
|
502
520
|
*/
|
|
@@ -528,6 +546,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
528
546
|
* @see {@link layer} for creating a `LanguageModel.LanguageModel` layer directly
|
|
529
547
|
* @see {@link make} for constructing the language model service effectfully
|
|
530
548
|
*
|
|
549
|
+
* @stability unstable
|
|
531
550
|
* @category constructors
|
|
532
551
|
* @since 4.0.0
|
|
533
552
|
*/
|
|
@@ -566,6 +585,7 @@ export const model = (
|
|
|
566
585
|
* @see {@link layer} for providing the service as a `Layer`
|
|
567
586
|
* @see {@link model} for creating a model descriptor for `AiModel.provide`
|
|
568
587
|
*
|
|
588
|
+
* @stability unstable
|
|
569
589
|
* @category constructors
|
|
570
590
|
* @since 4.0.0
|
|
571
591
|
*/
|
|
@@ -675,6 +695,7 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
|
|
|
675
695
|
* @see {@link make} for constructing the language model service effectfully
|
|
676
696
|
* @see {@link model} for creating an AI model descriptor
|
|
677
697
|
*
|
|
698
|
+
* @stability unstable
|
|
678
699
|
* @category layers
|
|
679
700
|
* @since 4.0.0
|
|
680
701
|
*/
|
|
@@ -699,6 +720,7 @@ export const layer = (options: {
|
|
|
699
720
|
*
|
|
700
721
|
* @see {@link Config} for the configuration shape
|
|
701
722
|
*
|
|
723
|
+
* @stability unstable
|
|
702
724
|
* @category configuration
|
|
703
725
|
* @since 4.0.0
|
|
704
726
|
*/
|
|
@@ -718,6 +740,7 @@ export const withConfigOverride: {
|
|
|
718
740
|
*
|
|
719
741
|
* @see {@link Config} for the configuration shape
|
|
720
742
|
*
|
|
743
|
+
* @stability unstable
|
|
721
744
|
* @category configuration
|
|
722
745
|
* @since 4.0.0
|
|
723
746
|
*/
|
|
@@ -737,6 +760,7 @@ export const withConfigOverride: {
|
|
|
737
760
|
*
|
|
738
761
|
* @see {@link Config} for the configuration shape
|
|
739
762
|
*
|
|
763
|
+
* @stability unstable
|
|
740
764
|
* @category configuration
|
|
741
765
|
* @since 4.0.0
|
|
742
766
|
*/
|
|
@@ -757,6 +781,7 @@ export const withConfigOverride: {
|
|
|
757
781
|
*
|
|
758
782
|
* @see {@link Config} for the configuration shape
|
|
759
783
|
*
|
|
784
|
+
* @stability unstable
|
|
760
785
|
* @category configuration
|
|
761
786
|
* @since 4.0.0
|
|
762
787
|
*/
|
|
@@ -776,6 +801,7 @@ export const withConfigOverride: {
|
|
|
776
801
|
*
|
|
777
802
|
* @see {@link Config} for the configuration shape
|
|
778
803
|
*
|
|
804
|
+
* @stability unstable
|
|
779
805
|
* @category configuration
|
|
780
806
|
* @since 4.0.0
|
|
781
807
|
*/
|
|
@@ -861,7 +887,7 @@ const prepareMessages = Effect.fnUntraced(
|
|
|
861
887
|
const imageUrl = part.data instanceof URL
|
|
862
888
|
? part.data.toString()
|
|
863
889
|
: part.data instanceof Uint8Array
|
|
864
|
-
? `data:${mediaType};base64,${
|
|
890
|
+
? `data:${mediaType};base64,${Base64.encode(part.data)}`
|
|
865
891
|
: /^(data:|https?:\/\/)/i.test(part.data)
|
|
866
892
|
? part.data
|
|
867
893
|
: `data:${mediaType};base64,${part.data}`
|
|
@@ -877,7 +903,7 @@ const prepareMessages = Effect.fnUntraced(
|
|
|
877
903
|
}
|
|
878
904
|
|
|
879
905
|
if (part.data instanceof Uint8Array) {
|
|
880
|
-
const base64 =
|
|
906
|
+
const base64 = Base64.encode(part.data)
|
|
881
907
|
const fileName = part.fileName ?? `part-${index}.pdf`
|
|
882
908
|
const fileData = `data:application/pdf;base64,${base64}`
|
|
883
909
|
content.push({ type: "input_file", filename: fileName, file_data: fileData })
|
|
@@ -1515,6 +1541,10 @@ const transformToolCallParams = Effect.fnUntraced(function*<Tools extends Readon
|
|
|
1515
1541
|
})
|
|
1516
1542
|
}
|
|
1517
1543
|
|
|
1544
|
+
if (Tool.isDynamic(tool) && tool.jsonSchema !== undefined) {
|
|
1545
|
+
return toolParams
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1518
1548
|
const { codec } = yield* tryCodecTransform(tool.parametersSchema, "makeResponse")
|
|
1519
1549
|
|
|
1520
1550
|
// Normalize valid parameters; leave invalid ones for Toolkit.
|
package/src/OpenAiTelemetry.ts
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
|
+
import * as Telemetry from "effect/ai/Telemetry"
|
|
9
10
|
import { dual } from "effect/Function"
|
|
10
11
|
import * as String from "effect/String"
|
|
11
12
|
import type { Span } from "effect/Tracer"
|
|
12
13
|
import type { Simplify } from "effect/Types"
|
|
13
|
-
import * as Telemetry from "effect/unstable/ai/Telemetry"
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The attributes used to describe telemetry in the context of Generative
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
+
* @stability unstable
|
|
8
9
|
* @since 4.0.0
|
|
9
10
|
*/
|
|
10
11
|
export * as OpenAiClient from "./OpenAiClient.ts"
|
|
@@ -15,6 +16,7 @@ export * as OpenAiClient from "./OpenAiClient.ts"
|
|
|
15
16
|
export * as OpenAiConfig from "./OpenAiConfig.ts"
|
|
16
17
|
|
|
17
18
|
/**
|
|
19
|
+
* @stability unstable
|
|
18
20
|
* @since 4.0.0
|
|
19
21
|
*/
|
|
20
22
|
export * as OpenAiEmbeddingModel from "./OpenAiEmbeddingModel.ts"
|
|
@@ -25,6 +27,7 @@ export * as OpenAiEmbeddingModel from "./OpenAiEmbeddingModel.ts"
|
|
|
25
27
|
export * as OpenAiError from "./OpenAiError.ts"
|
|
26
28
|
|
|
27
29
|
/**
|
|
30
|
+
* @stability unstable
|
|
28
31
|
* @since 4.0.0
|
|
29
32
|
*/
|
|
30
33
|
export * as OpenAiLanguageModel from "./OpenAiLanguageModel.ts"
|
package/src/internal/errors.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import * as AiError from "effect/ai/AiError"
|
|
2
|
+
import type * as Response from "effect/ai/Response"
|
|
1
3
|
import * as Arr from "effect/Array"
|
|
2
4
|
import * as Duration from "effect/Duration"
|
|
3
5
|
import * as Effect from "effect/Effect"
|
|
6
|
+
import type * as Sse from "effect/encoding/Sse"
|
|
4
7
|
import { dual } from "effect/Function"
|
|
8
|
+
import type * as HttpClientError from "effect/http/HttpClientError"
|
|
9
|
+
import type * as HttpClientRequest from "effect/http/HttpClientRequest"
|
|
10
|
+
import type * as HttpClientResponse from "effect/http/HttpClientResponse"
|
|
5
11
|
import * as Number from "effect/Number"
|
|
6
12
|
import * as Option from "effect/Option"
|
|
7
13
|
import * as Redactable from "effect/Redactable"
|
|
8
14
|
import * as Schema from "effect/Schema"
|
|
9
15
|
import * as SchemaTransformation from "effect/SchemaTransformation"
|
|
10
16
|
import * as String from "effect/String"
|
|
11
|
-
import * as AiError from "effect/unstable/ai/AiError"
|
|
12
|
-
import type * as Response from "effect/unstable/ai/Response"
|
|
13
|
-
import type * as Sse from "effect/unstable/encoding/Sse"
|
|
14
|
-
import type * as HttpClientError from "effect/unstable/http/HttpClientError"
|
|
15
|
-
import type * as HttpClientRequest from "effect/unstable/http/HttpClientRequest"
|
|
16
|
-
import type * as HttpClientResponse from "effect/unstable/http/HttpClientResponse"
|
|
17
17
|
import type { OpenAiErrorMetadata } from "../OpenAiError.ts"
|
|
18
18
|
|
|
19
19
|
/** @internal */
|