@effect/ai-openai 4.0.0-beta.7 → 4.0.0-beta.71

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 (58) hide show
  1. package/dist/Generated.d.ts +66734 -37723
  2. package/dist/Generated.d.ts.map +1 -1
  3. package/dist/Generated.js +1 -1
  4. package/dist/Generated.js.map +1 -1
  5. package/dist/OpenAiClient.d.ts +167 -27
  6. package/dist/OpenAiClient.d.ts.map +1 -1
  7. package/dist/OpenAiClient.js +337 -44
  8. package/dist/OpenAiClient.js.map +1 -1
  9. package/dist/OpenAiClientGenerated.d.ts +91 -0
  10. package/dist/OpenAiClientGenerated.d.ts.map +1 -0
  11. package/dist/OpenAiClientGenerated.js +84 -0
  12. package/dist/OpenAiClientGenerated.js.map +1 -0
  13. package/dist/OpenAiConfig.d.ts +114 -10
  14. package/dist/OpenAiConfig.d.ts.map +1 -1
  15. package/dist/OpenAiConfig.js +68 -7
  16. package/dist/OpenAiConfig.js.map +1 -1
  17. package/dist/OpenAiEmbeddingModel.d.ts +213 -0
  18. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  19. package/dist/OpenAiEmbeddingModel.js +219 -0
  20. package/dist/OpenAiEmbeddingModel.js.map +1 -0
  21. package/dist/OpenAiError.d.ts +168 -35
  22. package/dist/OpenAiError.d.ts.map +1 -1
  23. package/dist/OpenAiError.js +1 -1
  24. package/dist/OpenAiLanguageModel.d.ts +384 -62
  25. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  26. package/dist/OpenAiLanguageModel.js +416 -166
  27. package/dist/OpenAiLanguageModel.js.map +1 -1
  28. package/dist/OpenAiSchema.d.ts +2298 -0
  29. package/dist/OpenAiSchema.d.ts.map +1 -0
  30. package/dist/OpenAiSchema.js +814 -0
  31. package/dist/OpenAiSchema.js.map +1 -0
  32. package/dist/OpenAiTelemetry.d.ts +59 -18
  33. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  34. package/dist/OpenAiTelemetry.js +35 -8
  35. package/dist/OpenAiTelemetry.js.map +1 -1
  36. package/dist/OpenAiTool.d.ts +157 -62
  37. package/dist/OpenAiTool.d.ts.map +1 -1
  38. package/dist/OpenAiTool.js +134 -39
  39. package/dist/OpenAiTool.js.map +1 -1
  40. package/dist/index.d.ts +19 -33
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +19 -33
  43. package/dist/index.js.map +1 -1
  44. package/dist/internal/errors.js +4 -4
  45. package/dist/internal/errors.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/Generated.ts +9858 -5044
  48. package/src/OpenAiClient.ts +513 -95
  49. package/src/OpenAiClientGenerated.ts +202 -0
  50. package/src/OpenAiConfig.ts +115 -11
  51. package/src/OpenAiEmbeddingModel.ts +357 -0
  52. package/src/OpenAiError.ts +170 -35
  53. package/src/OpenAiLanguageModel.ts +802 -167
  54. package/src/OpenAiSchema.ts +1289 -0
  55. package/src/OpenAiTelemetry.ts +81 -23
  56. package/src/OpenAiTool.ts +135 -40
  57. package/src/index.ts +22 -33
  58. package/src/internal/errors.ts +6 -4
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @since 4.0.0
3
+ */
4
+ import * as Array from "effect/Array";
5
+ import * as Context from "effect/Context";
6
+ import * as Effect from "effect/Effect";
7
+ import { identity } from "effect/Function";
8
+ import * as Function from "effect/Function";
9
+ import * as Layer from "effect/Layer";
10
+ import * as Predicate from "effect/Predicate";
11
+ import * as Redacted from "effect/Redacted";
12
+ import * as Headers from "effect/unstable/http/Headers";
13
+ import * as HttpClient from "effect/unstable/http/HttpClient";
14
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
15
+ import * as Generated from "./Generated.js";
16
+ import { OpenAiConfig } from "./OpenAiConfig.js";
17
+ // =============================================================================
18
+ // Service Identifier
19
+ // =============================================================================
20
+ /**
21
+ * Service identifier for the generated OpenAI client.
22
+ *
23
+ * @since 4.0.0
24
+ * @category service
25
+ */
26
+ export class OpenAiClientGenerated extends /*#__PURE__*/Context.Service()("@effect/ai-openai/OpenAiClientGenerated") {}
27
+ const RedactedOpenAiHeaders = {
28
+ OpenAiOrganization: "OpenAI-Organization",
29
+ OpenAiProject: "OpenAI-Project"
30
+ };
31
+ // =============================================================================
32
+ // Constructor
33
+ // =============================================================================
34
+ /**
35
+ * Creates a generated OpenAI client service with the given options.
36
+ *
37
+ * @since 4.0.0
38
+ * @category constructors
39
+ */
40
+ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
41
+ const baseClient = yield* HttpClient.HttpClient;
42
+ const apiUrl = options.apiUrl ?? "https://api.openai.com/v1";
43
+ const httpClient = baseClient.pipe(HttpClient.mapRequest(Function.flow(HttpClientRequest.prependUrl(apiUrl), options.apiKey ? HttpClientRequest.bearerToken(Redacted.value(options.apiKey)) : identity, options.organizationId ? HttpClientRequest.setHeader(RedactedOpenAiHeaders.OpenAiOrganization, Redacted.value(options.organizationId)) : identity, options.projectId ? HttpClientRequest.setHeader(RedactedOpenAiHeaders.OpenAiProject, Redacted.value(options.projectId)) : identity, HttpClientRequest.acceptJson)), options.transformClient ? options.transformClient : identity);
44
+ return Generated.make(httpClient, {
45
+ transformClient: Effect.fnUntraced(function* (client) {
46
+ const config = yield* OpenAiConfig.getOrUndefined;
47
+ if (Predicate.isNotUndefined(config?.transformClient)) {
48
+ return config.transformClient(client);
49
+ }
50
+ return client;
51
+ })
52
+ });
53
+ }, /*#__PURE__*/Effect.updateService(Headers.CurrentRedactedNames, /*#__PURE__*/Array.appendAll(/*#__PURE__*/Object.values(RedactedOpenAiHeaders))));
54
+ // =============================================================================
55
+ // Layers
56
+ // =============================================================================
57
+ /**
58
+ * Creates a layer for the generated OpenAI client with the given options.
59
+ *
60
+ * @since 4.0.0
61
+ * @category layers
62
+ */
63
+ export const layer = options => Layer.effect(OpenAiClientGenerated, make(options));
64
+ /**
65
+ * Creates a layer for the generated OpenAI client, loading the requisite
66
+ * configuration via Effect's `Config` module.
67
+ *
68
+ * @since 4.0.0
69
+ * @category layers
70
+ */
71
+ export const layerConfig = options => Layer.effect(OpenAiClientGenerated, Effect.gen(function* () {
72
+ const apiKey = Predicate.isNotUndefined(options?.apiKey) ? yield* options.apiKey : undefined;
73
+ const apiUrl = Predicate.isNotUndefined(options?.apiUrl) ? yield* options.apiUrl : undefined;
74
+ const organizationId = Predicate.isNotUndefined(options?.organizationId) ? yield* options.organizationId : undefined;
75
+ const projectId = Predicate.isNotUndefined(options?.projectId) ? yield* options.projectId : undefined;
76
+ return yield* make({
77
+ apiKey,
78
+ apiUrl,
79
+ organizationId,
80
+ projectId,
81
+ transformClient: options?.transformClient
82
+ });
83
+ }));
84
+ //# sourceMappingURL=OpenAiClientGenerated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAiClientGenerated.js","names":["Array","Context","Effect","identity","Function","Layer","Predicate","Redacted","Headers","HttpClient","HttpClientRequest","Generated","OpenAiConfig","OpenAiClientGenerated","Service","RedactedOpenAiHeaders","OpenAiOrganization","OpenAiProject","make","fnUntraced","options","baseClient","apiUrl","httpClient","pipe","mapRequest","flow","prependUrl","apiKey","bearerToken","value","organizationId","setHeader","projectId","acceptJson","transformClient","client","config","getOrUndefined","isNotUndefined","updateService","CurrentRedactedNames","appendAll","Object","values","layer","effect","layerConfig","gen","undefined"],"sources":["../src/OpenAiClientGenerated.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,OAAO,MAAM,8BAA8B;AACvD,OAAO,KAA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,SAAS,CAACiC,cAAc,CAACnB,OAAO,EAAEa,SAAS,CAAC,GAC1D,OAAOb,OAAO,CAACa,SAAS,GAC1BgB,SAAS;EACX,OAAO,OAAO/B,IAAI,CAAC;IACjBU,MAAM;IACNN,MAAM;IACNS,cAAc;IACdE,SAAS;IACTE,eAAe,EAAEf,OAAO,EAAEe;GAC3B,CAAC;AACJ,CAAC,CAAC,CACH","ignoreList":[]}
@@ -1,45 +1,149 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenAiConfig` module carries request-time configuration for the
3
+ * `@effect/ai-openai` package through Effect's context. It currently exposes a
4
+ * scoped HTTP client transform used by OpenAI request helpers when they execute
5
+ * provider calls.
6
+ *
7
+ * **Mental model**
8
+ *
9
+ * Client constructors set the baseline HTTP client for an OpenAI service.
10
+ * `OpenAiConfig` is for narrower dynamic scopes: wrap an effect with
11
+ * {@link withClientTransform} and OpenAI requests evaluated inside that effect
12
+ * see the transformed `HttpClient`. Leaving the scope restores the previous
13
+ * configuration.
14
+ *
15
+ * **Common tasks**
16
+ *
17
+ * - Add request middleware, tracing, retry policy, proxy routing, or test
18
+ * interception around a group of OpenAI calls.
19
+ * - Apply a temporary HTTP client transform without rebuilding the OpenAI
20
+ * service layer.
21
+ * - Share one transform across all OpenAI helpers executed inside the same
22
+ * Effect scope.
23
+ *
24
+ * **Gotchas**
25
+ *
26
+ * - Only one `transformClient` value is stored in the scoped config. Compose
27
+ * transforms into a single `HttpClient => HttpClient` function when multiple
28
+ * behaviors should apply.
29
+ * - The transform affects OpenAI requests that read this contextual config; it
30
+ * does not mutate an already constructed HTTP client globally.
31
+ *
32
+ * @since 4.0.0
3
33
  */
34
+ import * as Context from "effect/Context";
4
35
  import * as Effect from "effect/Effect";
5
- import * as ServiceMap from "effect/ServiceMap";
6
36
  import type { HttpClient } from "effect/unstable/http/HttpClient";
7
- declare const OpenAiConfig_base: ServiceMap.ServiceClass<OpenAiConfig, "@effect/ai-openai/OpenAiConfig", OpenAiConfig.Service>;
37
+ declare const OpenAiConfig_base: Context.ServiceClass<OpenAiConfig, "@effect/ai-openai/OpenAiConfig", OpenAiConfig.Service>;
8
38
  /**
9
- * @since 1.0.0
39
+ * Context service carrying scoped OpenAI configuration for provider
40
+ * operations.
41
+ *
42
+ * **When to use**
43
+ *
44
+ * Use to provide scoped OpenAI client configuration, such as an HTTP client
45
+ * transform, to OpenAI provider operations without passing it through each call.
46
+ *
47
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
48
+ *
10
49
  * @category services
50
+ * @since 4.0.0
11
51
  */
12
52
  export declare class OpenAiConfig extends OpenAiConfig_base {
13
53
  /**
14
- * @since 1.0.0
54
+ * Gets the configured OpenAI service from the current context when present.
55
+ *
56
+ * @since 4.0.0
15
57
  */
16
58
  static readonly getOrUndefined: Effect.Effect<typeof OpenAiConfig.Service | undefined>;
17
59
  }
18
60
  /**
19
- * @since 1.0.0
61
+ * Types used by the `OpenAiConfig` context service.
62
+ *
63
+ * @since 4.0.0
20
64
  */
21
65
  export declare namespace OpenAiConfig {
22
66
  /**
23
- * @since 1.0.
67
+ * Configuration values read by OpenAI provider operations when executing
68
+ * requests.
69
+ *
24
70
  * @category models
71
+ * @since 4.0.0
25
72
  */
26
73
  interface Service {
27
74
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
28
75
  }
29
76
  }
30
77
  /**
31
- * @since 1.0.0
78
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
79
+ * operations.
80
+ *
81
+ * **When to use**
82
+ *
83
+ * Use when a single effect or workflow needs temporary OpenAI HTTP client
84
+ * customization without rebuilding the client layer.
85
+ *
86
+ * **Details**
87
+ *
88
+ * Supports both data-first and data-last forms. The transform is stored in the
89
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
90
+ * running the supplied effect.
91
+ *
92
+ * **Gotchas**
93
+ *
94
+ * If a transform is already present in the scoped config, this helper replaces
95
+ * it. Compose transforms manually when both should apply.
96
+ *
32
97
  * @category configuration
98
+ * @since 4.0.0
33
99
  */
34
100
  export declare const withClientTransform: {
35
101
  /**
36
- * @since 1.0.0
102
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
103
+ * operations.
104
+ *
105
+ * **When to use**
106
+ *
107
+ * Use when a single effect or workflow needs temporary OpenAI HTTP client
108
+ * customization without rebuilding the client layer.
109
+ *
110
+ * **Details**
111
+ *
112
+ * Supports both data-first and data-last forms. The transform is stored in the
113
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
114
+ * running the supplied effect.
115
+ *
116
+ * **Gotchas**
117
+ *
118
+ * If a transform is already present in the scoped config, this helper replaces
119
+ * it. Compose transforms manually when both should apply.
120
+ *
37
121
  * @category configuration
122
+ * @since 4.0.0
38
123
  */
39
124
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
40
125
  /**
41
- * @since 1.0.0
126
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
127
+ * operations.
128
+ *
129
+ * **When to use**
130
+ *
131
+ * Use when a single effect or workflow needs temporary OpenAI HTTP client
132
+ * customization without rebuilding the client layer.
133
+ *
134
+ * **Details**
135
+ *
136
+ * Supports both data-first and data-last forms. The transform is stored in the
137
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
138
+ * running the supplied effect.
139
+ *
140
+ * **Gotchas**
141
+ *
142
+ * If a transform is already present in the scoped config, this helper replaces
143
+ * it. Compose transforms manually when both should apply.
144
+ *
42
145
  * @category configuration
146
+ * @since 4.0.0
43
147
  */
44
148
  <A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
45
149
  };
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAiConfig.d.ts","sourceRoot":"","sources":["../src/OpenAiConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,O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context. It currently exposes a
4
+ * scoped HTTP client transform used by OpenAI request helpers when they execute
5
+ * provider calls.
6
+ *
7
+ * **Mental model**
8
+ *
9
+ * Client constructors set the baseline HTTP client for an OpenAI service.
10
+ * `OpenAiConfig` is for narrower dynamic scopes: wrap an effect with
11
+ * {@link withClientTransform} and OpenAI requests evaluated inside that effect
12
+ * see the transformed `HttpClient`. Leaving the scope restores the previous
13
+ * configuration.
14
+ *
15
+ * **Common tasks**
16
+ *
17
+ * - Add request middleware, tracing, retry policy, proxy routing, or test
18
+ * interception around a group of OpenAI calls.
19
+ * - Apply a temporary HTTP client transform without rebuilding the OpenAI
20
+ * service layer.
21
+ * - Share one transform across all OpenAI helpers executed inside the same
22
+ * Effect scope.
23
+ *
24
+ * **Gotchas**
25
+ *
26
+ * - Only one `transformClient` value is stored in the scoped config. Compose
27
+ * transforms into a single `HttpClient => HttpClient` function when multiple
28
+ * behaviors should apply.
29
+ * - The transform affects OpenAI requests that read this contextual config; it
30
+ * does not mutate an already constructed HTTP client globally.
31
+ *
32
+ * @since 4.0.0
3
33
  */
34
+ import * as Context from "effect/Context";
4
35
  import * as Effect from "effect/Effect";
5
36
  import { dual } from "effect/Function";
6
- import * as ServiceMap from "effect/ServiceMap";
7
37
  /**
8
- * @since 1.0.0
38
+ * Context service carrying scoped OpenAI configuration for provider
39
+ * operations.
40
+ *
41
+ * **When to use**
42
+ *
43
+ * Use to provide scoped OpenAI client configuration, such as an HTTP client
44
+ * transform, to OpenAI provider operations without passing it through each call.
45
+ *
46
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
47
+ *
9
48
  * @category services
49
+ * @since 4.0.0
10
50
  */
11
- export class OpenAiConfig extends /*#__PURE__*/ServiceMap.Service()("@effect/ai-openai/OpenAiConfig") {
51
+ export class OpenAiConfig extends /*#__PURE__*/Context.Service()("@effect/ai-openai/OpenAiConfig") {
12
52
  /**
13
- * @since 1.0.0
53
+ * Gets the configured OpenAI service from the current context when present.
54
+ *
55
+ * @since 4.0.0
14
56
  */
15
- static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.services(), context => context.mapUnsafe.get(OpenAiConfig.key));
57
+ static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), context => context.mapUnsafe.get(OpenAiConfig.key));
16
58
  }
17
59
  /**
18
- * @since 1.0.0
60
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
61
+ * operations.
62
+ *
63
+ * **When to use**
64
+ *
65
+ * Use when a single effect or workflow needs temporary OpenAI HTTP client
66
+ * customization without rebuilding the client layer.
67
+ *
68
+ * **Details**
69
+ *
70
+ * Supports both data-first and data-last forms. The transform is stored in the
71
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
72
+ * running the supplied effect.
73
+ *
74
+ * **Gotchas**
75
+ *
76
+ * If a transform is already present in the scoped config, this helper replaces
77
+ * it. Compose transforms manually when both should apply.
78
+ *
19
79
  * @category configuration
80
+ * @since 4.0.0
20
81
  */
21
82
  export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(OpenAiConfig.getOrUndefined, config => Effect.provideService(self, OpenAiConfig, {
22
83
  ...config,
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAiConfig.js","names":["Effect","dual","ServiceMap","OpenAiConfig","Service","getOrUndefined","map","services","context","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/OpenAiConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAG/C;;;;AAIA,OAAM,MAAOC,YAAa,sBAAQD,UAAU,CAACE,OAAO,EAGjD,CAAC,gCAAgC,CAAC;EACnC;;;EAGA,OAAgBC,cAAc,gBAA2DL,MAAM,CAACM,GAAG,cACjGN,MAAM,CAACO,QAAQ,EAAS,EACvBC,OAAO,IAAKA,OAAO,CAACC,SAAS,CAACC,GAAG,CAACP,YAAY,CAACQ,GAAG,CAAC,CACrD;;AAgBH;;;;AAIA,OAAO,MAAMC,mBAAmB,gBAc5BX,IAAI,CAAC,CAAC,EAAE,CACVY,IAA4B,EAC5BC,eAAmD,KAEnDd,MAAM,CAACe,OAAO,CACZZ,YAAY,CAACE,cAAc,EAC1BW,MAAM,IAAKhB,MAAM,CAACiB,cAAc,CAACJ,IAAI,EAAEV,YAAY,EAAE;EAAE,GAAGa,MAAM;EAAEF;AAAe,CAAE,CAAC,CACtF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"OpenAiConfig.js","names":["Context","Effect","dual","OpenAiConfig","Service","getOrUndefined","map","context","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/OpenAiConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;;;;;;;;;AAcA,OAAM,MAAOC,YAAa,sBAAQH,OAAO,CAACI,OAAO,EAG9C,CAAC,gCAAgC,CAAC;EACnC;;;;;EAKA,OAAgBC,cAAc,gBAA2DJ,MAAM,CAACK,GAAG,cACjGL,MAAM,CAACM,OAAO,EAAS,EACtBA,OAAO,IAAKA,OAAO,CAACC,SAAS,CAACC,GAAG,CAACN,YAAY,CAACO,GAAG,CAAC,CACrD;;AAqBH;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,MAAMC,mBAAmB,gBAoD5BT,IAAI,CAAC,CAAC,EAAE,CACVU,IAA4B,EAC5BC,eAAmD,KAEnDZ,MAAM,CAACa,OAAO,CACZX,YAAY,CAACE,cAAc,EAC1BU,MAAM,IAAKd,MAAM,CAACe,cAAc,CAACJ,IAAI,EAAET,YAAY,EAAE;EAAE,GAAGY,MAAM;EAAEF;AAAe,CAAE,CAAC,CACtF,CAAC","ignoreList":[]}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * The `OpenAiEmbeddingModel` module provides the OpenAI implementation of
3
+ * Effect AI's `EmbeddingModel` service. It adapts the OpenAI embeddings
4
+ * endpoint into Effect AI's batch embedding interface, preserving input order
5
+ * and returning numeric vectors for each requested input.
6
+ *
7
+ * **Mental model**
8
+ *
9
+ * `OpenAiClient` owns transport, authentication, and provider request
10
+ * execution. This module owns embedding-specific configuration, response
11
+ * validation, and the `EmbeddingModel.EmbeddingModel` layer. Use {@link model}
12
+ * when you want an `AiModel` descriptor that also provides the configured
13
+ * embedding dimensions, or {@link layer} / {@link make} when the dimensions are
14
+ * managed separately.
15
+ *
16
+ * **Common tasks**
17
+ *
18
+ * - Provide an OpenAI-backed `EmbeddingModel.EmbeddingModel` from an existing
19
+ * `OpenAiClient`
20
+ * - Configure the OpenAI embedding model id, dimensions, encoding format, and
21
+ * other create-embedding request fields
22
+ * - Scope per-request defaults with {@link Config} and
23
+ * {@link withConfigOverride}
24
+ *
25
+ * **Gotchas**
26
+ *
27
+ * - The service expects OpenAI to return floating-point embedding arrays.
28
+ * Requesting base64 embeddings causes an `InvalidOutputError`.
29
+ * - Provider results are checked for missing, duplicate, or out-of-range
30
+ * indexes before they are exposed as Effect AI embedding results.
31
+ *
32
+ * @since 4.0.0
33
+ */
34
+ import * as Context from "effect/Context";
35
+ import * as Effect from "effect/Effect";
36
+ import * as Layer from "effect/Layer";
37
+ import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
38
+ import * as AiModel from "effect/unstable/ai/Model";
39
+ import { OpenAiClient } from "./OpenAiClient.ts";
40
+ /**
41
+ * Model identifiers supported by OpenAI's embeddings API.
42
+ *
43
+ * @category models
44
+ * @since 4.0.0
45
+ */
46
+ export type Model = "text-embedding-ada-002" | "text-embedding-3-small" | "text-embedding-3-large";
47
+ declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai/OpenAiEmbeddingModel/Config", {
48
+ readonly [x: string]: unknown;
49
+ readonly encoding_format?: "float" | "base64";
50
+ readonly dimensions?: number;
51
+ readonly user?: string;
52
+ readonly model?: string;
53
+ }>;
54
+ /**
55
+ * Service definition for OpenAI embedding model configuration.
56
+ *
57
+ * **When to use**
58
+ *
59
+ * Use when embedding requests need scoped OpenAI request defaults or overrides
60
+ * from Effect context.
61
+ *
62
+ * **Details**
63
+ *
64
+ * The service stores the OpenAI create-embedding request payload without
65
+ * `input`, carrying options such as `model`, `dimensions`, `encoding_format`,
66
+ * and `user`.
67
+ *
68
+ * @see {@link withConfigOverride} for scoping embedding request overrides
69
+ *
70
+ * @category services
71
+ * @since 4.0.0
72
+ */
73
+ export declare class Config extends Config_base {
74
+ }
75
+ /**
76
+ * Creates an `AiModel` for an OpenAI embedding model with its configured vector dimensions.
77
+ *
78
+ * **When to use**
79
+ *
80
+ * Use to provide an OpenAI `EmbeddingModel` and its `Dimensions` service to an
81
+ * Effect program.
82
+ *
83
+ * @see {@link layer} for providing only the embedding model service
84
+ * @see {@link withConfigOverride} for scoped request configuration overrides
85
+ *
86
+ * @category constructors
87
+ * @since 4.0.0
88
+ */
89
+ export declare const model: (model: (string & {}) | Model, options: {
90
+ readonly dimensions: number;
91
+ readonly config?: Omit<typeof Config.Service, "model" | "dimensions">;
92
+ }) => AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient>;
93
+ /**
94
+ * Creates an OpenAI embedding model service.
95
+ *
96
+ * **When to use**
97
+ *
98
+ * Use to construct the `EmbeddingModel.Service` effectfully when
99
+ * `OpenAiClient` is already available in the environment or when the service
100
+ * value is needed directly.
101
+ *
102
+ * **Details**
103
+ *
104
+ * The `model` option is sent with each embedding request. Constructor `config`
105
+ * supplies create-embedding request fields other than `model` and `input`, and
106
+ * scoped overrides from `withConfigOverride` are merged last for each request.
107
+ *
108
+ * **Gotchas**
109
+ *
110
+ * The service expects numeric embedding vectors. It fails with
111
+ * `InvalidOutputError` when the provider returns base64 embeddings,
112
+ * out-of-range indexes, duplicate indexes, or an unexpected number of
113
+ * embeddings.
114
+ *
115
+ * @see {@link layer} for providing the embedding model service as a layer
116
+ * @see {@link model} for creating an `AiModel` that also provides dimensions
117
+ * @see {@link withConfigOverride} for scoped request configuration overrides
118
+ *
119
+ * @category constructors
120
+ * @since 4.0.0
121
+ */
122
+ export declare const make: (args_0: {
123
+ readonly model: (string & {}) | Model;
124
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined;
125
+ }) => Effect.Effect<EmbeddingModel.Service, never, OpenAiClient>;
126
+ /**
127
+ * Creates a layer for the OpenAI embedding model.
128
+ *
129
+ * **When to use**
130
+ *
131
+ * Use when composing application layers and you want OpenAI to satisfy
132
+ * `EmbeddingModel.EmbeddingModel` while supplying `OpenAiClient` from another
133
+ * layer.
134
+ *
135
+ * **Gotchas**
136
+ *
137
+ * Use the default floating-point embedding format. The service expects numeric
138
+ * vectors and fails with `InvalidOutputError` if OpenAI returns base64
139
+ * embeddings.
140
+ *
141
+ * @see {@link make} for constructing the embedding model service effectfully
142
+ * @see {@link model} for creating an `AiModel` that also provides embedding dimensions
143
+ *
144
+ * @category layers
145
+ * @since 4.0.0
146
+ */
147
+ export declare const layer: (options: {
148
+ readonly model: (string & {}) | Model;
149
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined;
150
+ }) => Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient>;
151
+ /**
152
+ * Provides config overrides for OpenAI embedding model operations.
153
+ *
154
+ * **When to use**
155
+ *
156
+ * Use when a single effect or workflow needs scoped OpenAI embedding request
157
+ * defaults without rebuilding the embedding model service.
158
+ *
159
+ * **Details**
160
+ *
161
+ * Supports both data-first and data-last forms. Existing scoped config is read
162
+ * first, then the provided overrides are applied so override fields take
163
+ * precedence.
164
+ *
165
+ * @see {@link Config} for the scoped embedding request configuration service
166
+ *
167
+ * @category configuration
168
+ * @since 4.0.0
169
+ */
170
+ export declare const withConfigOverride: {
171
+ /**
172
+ * Provides config overrides for OpenAI embedding model operations.
173
+ *
174
+ * **When to use**
175
+ *
176
+ * Use when a single effect or workflow needs scoped OpenAI embedding request
177
+ * defaults without rebuilding the embedding model service.
178
+ *
179
+ * **Details**
180
+ *
181
+ * Supports both data-first and data-last forms. Existing scoped config is read
182
+ * first, then the provided overrides are applied so override fields take
183
+ * precedence.
184
+ *
185
+ * @see {@link Config} for the scoped embedding request configuration service
186
+ *
187
+ * @category configuration
188
+ * @since 4.0.0
189
+ */
190
+ (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
191
+ /**
192
+ * Provides config overrides for OpenAI embedding model operations.
193
+ *
194
+ * **When to use**
195
+ *
196
+ * Use when a single effect or workflow needs scoped OpenAI embedding request
197
+ * defaults without rebuilding the embedding model service.
198
+ *
199
+ * **Details**
200
+ *
201
+ * Supports both data-first and data-last forms. Existing scoped config is read
202
+ * first, then the provided overrides are applied so override fields take
203
+ * precedence.
204
+ *
205
+ * @see {@link Config} for the scoped embedding request configuration service
206
+ *
207
+ * @category configuration
208
+ * @since 4.0.0
209
+ */
210
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>;
211
+ };
212
+ export {};
213
+ //# sourceMappingURL=OpenAiEmbeddingModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAiEmbeddingModel.d.ts","sourceRoot":"","sources":["../src/OpenAiEmbeddingModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,cAAc,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,OAAO,MAAM,0BAA0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