@effect/ai-openai-compat 4.0.0-beta.10 → 4.0.0-beta.100

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 (41) hide show
  1. package/dist/OpenAiClient.d.ts +264 -52
  2. package/dist/OpenAiClient.d.ts.map +1 -1
  3. package/dist/OpenAiClient.js +97 -9
  4. package/dist/OpenAiClient.js.map +1 -1
  5. package/dist/OpenAiConfig.d.ts +68 -10
  6. package/dist/OpenAiConfig.d.ts.map +1 -1
  7. package/dist/OpenAiConfig.js +36 -7
  8. package/dist/OpenAiConfig.js.map +1 -1
  9. package/dist/OpenAiEmbeddingModel.d.ts +193 -0
  10. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  11. package/dist/OpenAiEmbeddingModel.js +187 -0
  12. package/dist/OpenAiEmbeddingModel.js.map +1 -0
  13. package/dist/OpenAiError.d.ts +109 -35
  14. package/dist/OpenAiError.d.ts.map +1 -1
  15. package/dist/OpenAiError.js +14 -1
  16. package/dist/OpenAiLanguageModel.d.ts +363 -50
  17. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  18. package/dist/OpenAiLanguageModel.js +158 -33
  19. package/dist/OpenAiLanguageModel.js.map +1 -1
  20. package/dist/OpenAiTelemetry.d.ts +76 -26
  21. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  22. package/dist/OpenAiTelemetry.js +22 -10
  23. package/dist/OpenAiTelemetry.js.map +1 -1
  24. package/dist/index.d.ts +10 -17
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +10 -17
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal/errors.js +4 -4
  29. package/dist/internal/errors.js.map +1 -1
  30. package/dist/internal/utilities.js +0 -6
  31. package/dist/internal/utilities.js.map +1 -1
  32. package/package.json +5 -6
  33. package/src/OpenAiClient.ts +273 -50
  34. package/src/OpenAiConfig.ts +69 -11
  35. package/src/OpenAiEmbeddingModel.ts +322 -0
  36. package/src/OpenAiError.ts +111 -35
  37. package/src/OpenAiLanguageModel.ts +468 -88
  38. package/src/OpenAiTelemetry.ts +81 -32
  39. package/src/index.ts +11 -17
  40. package/src/internal/errors.ts +4 -4
  41. package/src/internal/utilities.ts +0 -9
@@ -0,0 +1,193 @@
1
+ /**
2
+ * The `OpenAiEmbeddingModel` module adapts OpenAI-compatible embeddings
3
+ * endpoints to Effect's embedding model service. It sends embedding requests
4
+ * through {@link OpenAiClient}, exposes constructors for layers and `AiModel`
5
+ * values, supports scoped request configuration overrides, and checks that the
6
+ * provider returns one numeric vector for each requested input.
7
+ *
8
+ * @since 4.0.0
9
+ */
10
+ import * as Context from "effect/Context";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ import type { Simplify } from "effect/Types";
14
+ import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
15
+ import * as AiModel from "effect/unstable/ai/Model";
16
+ import type { CreateEmbeddingRequestJson } from "./OpenAiClient.ts";
17
+ import { OpenAiClient } from "./OpenAiClient.ts";
18
+ /**
19
+ * A model identifier accepted by an OpenAI-compatible embeddings endpoint.
20
+ *
21
+ * @category models
22
+ * @since 4.0.0
23
+ */
24
+ export type Model = string;
25
+ type ConfigOptions = Simplify<Partial<Omit<CreateEmbeddingRequestJson, "input">>>;
26
+ type ModelConfig = Omit<ConfigOptions, "model"> & {
27
+ readonly [x: string]: unknown;
28
+ };
29
+ declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai-compat/OpenAiEmbeddingModel/Config", {
30
+ readonly model?: string;
31
+ readonly encoding_format?: "float" | "base64" | undefined;
32
+ readonly dimensions?: number | undefined;
33
+ readonly user?: string | undefined;
34
+ } & {
35
+ readonly [x: string]: unknown;
36
+ }>;
37
+ /**
38
+ * Context service for OpenAI embedding model configuration.
39
+ *
40
+ * **When to use**
41
+ *
42
+ * Use when you need to provide shared default request options for
43
+ * OpenAI-compatible embedding operations through the Effect context, such as
44
+ * `dimensions`, `encoding_format`, or `user`.
45
+ *
46
+ * **Details**
47
+ *
48
+ * The service stores the embedding request payload without `input`. Requests
49
+ * combine the selected model, layer or constructor config, and scoped context
50
+ * config, with scoped context config taking precedence.
51
+ *
52
+ * @see {@link withConfigOverride} for scoping embedding request overrides
53
+ *
54
+ * @category context
55
+ * @since 4.0.0
56
+ */
57
+ export declare class Config extends Config_base {
58
+ }
59
+ /**
60
+ * Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
61
+ *
62
+ * **When to use**
63
+ *
64
+ * Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
65
+ * service to an Effect program.
66
+ *
67
+ * @see {@link layer} for providing only the embedding model service
68
+ * @see {@link withConfigOverride} for scoped request configuration overrides
69
+ *
70
+ * @category constructors
71
+ * @since 4.0.0
72
+ */
73
+ export declare const model: (model: string, options: Omit<ConfigOptions, "model" | "dimensions"> & {
74
+ readonly dimensions: number;
75
+ readonly [x: string]: unknown;
76
+ }) => AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient>;
77
+ /**
78
+ * Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
79
+ *
80
+ * **When to use**
81
+ *
82
+ * Use when you need to build or provide an `EmbeddingModel` service directly
83
+ * from an existing `OpenAiClient`.
84
+ *
85
+ * **Details**
86
+ *
87
+ * The service sends embedding requests through `OpenAiClient.createEmbedding`.
88
+ * Request config is merged as the selected model, constructor config, then
89
+ * scoped `Config`, so scoped overrides take precedence. Provider usage
90
+ * `prompt_tokens` is exposed as `usage.inputTokens`.
91
+ *
92
+ * **Gotchas**
93
+ *
94
+ * Provider responses must contain one numeric vector for every requested input
95
+ * with unique, in-range `index` values; otherwise embedding operations fail with
96
+ * `AiError.InvalidOutputError`.
97
+ *
98
+ * @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
99
+ * @see {@link layer} for providing the service as a `Layer`
100
+ * @see {@link withConfigOverride} for scoping embedding request overrides
101
+ *
102
+ * @category constructors
103
+ * @since 4.0.0
104
+ */
105
+ export declare const make: (args_0: {
106
+ readonly model: string;
107
+ readonly config?: ModelConfig | undefined;
108
+ }) => Effect.Effect<EmbeddingModel.Service, never, OpenAiClient>;
109
+ /**
110
+ * Creates a layer for an OpenAI-compatible embedding model service.
111
+ *
112
+ * **When to use**
113
+ *
114
+ * Use when composing application layers and you want an OpenAI-compatible
115
+ * embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
116
+ * supplying `OpenAiClient` from another layer.
117
+ *
118
+ * @see {@link make} for constructing the embedding model service effectfully
119
+ * @see {@link model} for creating an `AiModel` with configured dimensions
120
+ *
121
+ * @category layers
122
+ * @since 4.0.0
123
+ */
124
+ export declare const layer: (options: {
125
+ readonly model: string;
126
+ readonly config?: ModelConfig | undefined;
127
+ }) => Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient>;
128
+ /**
129
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
130
+ *
131
+ * **When to use**
132
+ *
133
+ * Use to apply embedding request options to one effect without changing the
134
+ * model's default configuration.
135
+ *
136
+ * **Details**
137
+ *
138
+ * The overrides are merged with any existing `Config` service for the duration
139
+ * of the supplied effect. Fields in `overrides` take precedence over existing
140
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
141
+ * and `withConfigOverride(effect, overrides)`.
142
+ *
143
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
144
+ *
145
+ * @category configuration
146
+ * @since 4.0.0
147
+ */
148
+ export declare const withConfigOverride: {
149
+ /**
150
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
151
+ *
152
+ * **When to use**
153
+ *
154
+ * Use to apply embedding request options to one effect without changing the
155
+ * model's default configuration.
156
+ *
157
+ * **Details**
158
+ *
159
+ * The overrides are merged with any existing `Config` service for the duration
160
+ * of the supplied effect. Fields in `overrides` take precedence over existing
161
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
162
+ * and `withConfigOverride(effect, overrides)`.
163
+ *
164
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
165
+ *
166
+ * @category configuration
167
+ * @since 4.0.0
168
+ */
169
+ (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
170
+ /**
171
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
172
+ *
173
+ * **When to use**
174
+ *
175
+ * Use to apply embedding request options to one effect without changing the
176
+ * model's default configuration.
177
+ *
178
+ * **Details**
179
+ *
180
+ * The overrides are merged with any existing `Config` service for the duration
181
+ * of the supplied effect. Fields in `overrides` take precedence over existing
182
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
183
+ * and `withConfigOverride(effect, overrides)`.
184
+ *
185
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
186
+ *
187
+ * @category configuration
188
+ * @since 4.0.0
189
+ */
190
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>;
191
+ };
192
+ export {};
193
+ //# sourceMappingURL=OpenAiEmbeddingModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAiEmbeddingModel.d.ts","sourceRoot":"","sources":["../src/OpenAiEmbeddingModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAE5C,OAAO,KAAK,cAAc,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAA;AACnD,OAAO,KAAK,EAAsB,0BAA0B,EAAE,MAAM,mBAAmB,CAAA;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;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,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;IACtH;;;;;;;;;;;;;;;;;;;OAmBG;IACH,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;CAoDhH,CAAA"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * The `OpenAiEmbeddingModel` module adapts OpenAI-compatible embeddings
3
+ * endpoints to Effect's embedding model service. It sends embedding requests
4
+ * through {@link OpenAiClient}, exposes constructors for layers and `AiModel`
5
+ * values, supports scoped request configuration overrides, and checks that the
6
+ * provider returns one numeric vector for each requested input.
7
+ *
8
+ * @since 4.0.0
9
+ */
10
+ import * as Context from "effect/Context";
11
+ import * as Effect from "effect/Effect";
12
+ import { dual } from "effect/Function";
13
+ import * as Layer from "effect/Layer";
14
+ import * as AiError from "effect/unstable/ai/AiError";
15
+ import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
16
+ import * as AiModel from "effect/unstable/ai/Model";
17
+ import { OpenAiClient } from "./OpenAiClient.js";
18
+ /**
19
+ * Context service for OpenAI embedding model configuration.
20
+ *
21
+ * **When to use**
22
+ *
23
+ * Use when you need to provide shared default request options for
24
+ * OpenAI-compatible embedding operations through the Effect context, such as
25
+ * `dimensions`, `encoding_format`, or `user`.
26
+ *
27
+ * **Details**
28
+ *
29
+ * The service stores the embedding request payload without `input`. Requests
30
+ * combine the selected model, layer or constructor config, and scoped context
31
+ * config, with scoped context config taking precedence.
32
+ *
33
+ * @see {@link withConfigOverride} for scoping embedding request overrides
34
+ *
35
+ * @category context
36
+ * @since 4.0.0
37
+ */
38
+ export class Config extends /*#__PURE__*/Context.Service()("@effect/ai-openai-compat/OpenAiEmbeddingModel/Config") {}
39
+ /**
40
+ * Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
41
+ *
42
+ * **When to use**
43
+ *
44
+ * Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
45
+ * service to an Effect program.
46
+ *
47
+ * @see {@link layer} for providing only the embedding model service
48
+ * @see {@link withConfigOverride} for scoped request configuration overrides
49
+ *
50
+ * @category constructors
51
+ * @since 4.0.0
52
+ */
53
+ export const model = (model, options) => AiModel.make("openai", model, Layer.merge(layer({
54
+ model,
55
+ config: options
56
+ }), Layer.succeed(EmbeddingModel.Dimensions, options.dimensions)));
57
+ /**
58
+ * Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
59
+ *
60
+ * **When to use**
61
+ *
62
+ * Use when you need to build or provide an `EmbeddingModel` service directly
63
+ * from an existing `OpenAiClient`.
64
+ *
65
+ * **Details**
66
+ *
67
+ * The service sends embedding requests through `OpenAiClient.createEmbedding`.
68
+ * Request config is merged as the selected model, constructor config, then
69
+ * scoped `Config`, so scoped overrides take precedence. Provider usage
70
+ * `prompt_tokens` is exposed as `usage.inputTokens`.
71
+ *
72
+ * **Gotchas**
73
+ *
74
+ * Provider responses must contain one numeric vector for every requested input
75
+ * with unique, in-range `index` values; otherwise embedding operations fail with
76
+ * `AiError.InvalidOutputError`.
77
+ *
78
+ * @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
79
+ * @see {@link layer} for providing the service as a `Layer`
80
+ * @see {@link withConfigOverride} for scoping embedding request overrides
81
+ *
82
+ * @category constructors
83
+ * @since 4.0.0
84
+ */
85
+ export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
86
+ model,
87
+ config: providerConfig
88
+ }) {
89
+ const client = yield* OpenAiClient;
90
+ const makeConfig = Effect.gen(function* () {
91
+ const services = yield* Effect.context();
92
+ return {
93
+ model,
94
+ ...providerConfig,
95
+ ...services.mapUnsafe.get(Config.key)
96
+ };
97
+ });
98
+ return yield* EmbeddingModel.make({
99
+ embedMany: Effect.fnUntraced(function* ({
100
+ inputs
101
+ }) {
102
+ const config = yield* makeConfig;
103
+ const response = yield* client.createEmbedding({
104
+ ...config,
105
+ input: inputs
106
+ });
107
+ return yield* mapProviderResponse(inputs.length, response);
108
+ })
109
+ });
110
+ });
111
+ /**
112
+ * Creates a layer for an OpenAI-compatible embedding model service.
113
+ *
114
+ * **When to use**
115
+ *
116
+ * Use when composing application layers and you want an OpenAI-compatible
117
+ * embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
118
+ * supplying `OpenAiClient` from another layer.
119
+ *
120
+ * @see {@link make} for constructing the embedding model service effectfully
121
+ * @see {@link model} for creating an `AiModel` with configured dimensions
122
+ *
123
+ * @category layers
124
+ * @since 4.0.0
125
+ */
126
+ export const layer = options => Layer.effect(EmbeddingModel.EmbeddingModel, make(options));
127
+ /**
128
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
129
+ *
130
+ * **When to use**
131
+ *
132
+ * Use to apply embedding request options to one effect without changing the
133
+ * model's default configuration.
134
+ *
135
+ * **Details**
136
+ *
137
+ * The overrides are merged with any existing `Config` service for the duration
138
+ * of the supplied effect. Fields in `overrides` take precedence over existing
139
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
140
+ * and `withConfigOverride(effect, overrides)`.
141
+ *
142
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
143
+ *
144
+ * @category configuration
145
+ * @since 4.0.0
146
+ */
147
+ export const withConfigOverride = /*#__PURE__*/dual(2, (self, overrides) => Effect.flatMap(Effect.serviceOption(Config), config => Effect.provideService(self, Config, {
148
+ ...(config._tag === "Some" ? config.value : {}),
149
+ ...overrides
150
+ })));
151
+ const mapProviderResponse = (inputLength, response) => {
152
+ if (response.data.length !== inputLength) {
153
+ return Effect.fail(invalidOutput(`Provider returned ${response.data.length} embeddings but expected ${inputLength}`));
154
+ }
155
+ const results = new Array(inputLength);
156
+ const seen = new Set();
157
+ for (const entry of response.data) {
158
+ if (!Number.isInteger(entry.index) || entry.index < 0 || entry.index >= inputLength) {
159
+ return Effect.fail(invalidOutput(`Provider returned invalid embedding index: ${entry.index}`));
160
+ }
161
+ if (seen.has(entry.index)) {
162
+ return Effect.fail(invalidOutput(`Provider returned duplicate embedding index: ${entry.index}`));
163
+ }
164
+ if (!Array.isArray(entry.embedding)) {
165
+ return Effect.fail(invalidOutput(`Provider returned non-vector embedding at index ${entry.index}`));
166
+ }
167
+ seen.add(entry.index);
168
+ results[entry.index] = [...entry.embedding];
169
+ }
170
+ if (seen.size !== inputLength) {
171
+ return Effect.fail(invalidOutput(`Provider returned embeddings for ${seen.size} inputs but expected ${inputLength}`));
172
+ }
173
+ return Effect.succeed({
174
+ results,
175
+ usage: {
176
+ inputTokens: response.usage?.prompt_tokens
177
+ }
178
+ });
179
+ };
180
+ const invalidOutput = description => AiError.make({
181
+ module: "OpenAiEmbeddingModel",
182
+ method: "embedMany",
183
+ reason: new AiError.InvalidOutputError({
184
+ description
185
+ })
186
+ });
187
+ //# sourceMappingURL=OpenAiEmbeddingModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAiEmbeddingModel.js","names":["Context","Effect","dual","Layer","AiError","EmbeddingModel","AiModel","OpenAiClient","Config","Service","model","options","make","merge","layer","config","succeed","Dimensions","dimensions","fnUntraced","providerConfig","client","makeConfig","gen","services","context","mapUnsafe","get","key","embedMany","inputs","response","createEmbedding","input","mapProviderResponse","length","effect","withConfigOverride","self","overrides","flatMap","serviceOption","provideService","_tag","value","inputLength","data","fail","invalidOutput","results","Array","seen","Set","entry","Number","isInteger","index","has","isArray","embedding","add","size","usage","inputTokens","prompt_tokens","description","module","method","reason","InvalidOutputError"],"sources":["../src/OpenAiEmbeddingModel.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;AASA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,OAAO,MAAM,4BAA4B;AACrD,OAAO,KAAKC,cAAc,MAAM,mCAAmC;AACnE,OAAO,KAAKC,OAAO,MAAM,0BAA0B;AAEnD,SAASC,YAAY,QAAQ,mBAAmB;AAahD;;;;;;;;;;;;;;;;;;;;AAoBA,OAAM,MAAOC,MAAO,sBAAQR,OAAO,CAACS,OAAO,EAGxC,CAAC,sDAAsD,CAAC;AAE3D;;;;;;;;;;;;;;AAcA,OAAO,MAAMC,KAAK,GAAGA,CACnBA,KAAa,EACbC,OAGC,KAEDL,OAAO,CAACM,IAAI,CACV,QAAQ,EACRF,KAAK,EACLP,KAAK,CAACU,KAAK,CACTC,KAAK,CAAC;EACJJ,KAAK;EACLK,MAAM,EAAEJ;CACT,CAAC,EACFR,KAAK,CAACa,OAAO,CAACX,cAAc,CAACY,UAAU,EAAEN,OAAO,CAACO,UAAU,CAAC,CAC7D,CACF;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,OAAO,MAAMN,IAAI,gBAAGX,MAAM,CAACkB,UAAU,CAAC,WAAU;EAAET,KAAK;EAAEK,MAAM,EAAEK;AAAc,CAG9E;EACC,MAAMC,MAAM,GAAG,OAAOd,YAAY;EAElC,MAAMe,UAAU,GAAGrB,MAAM,CAACsB,GAAG,CAAC,aAAS;IACrC,MAAMC,QAAQ,GAAG,OAAOvB,MAAM,CAACwB,OAAO,EAAS;IAC/C,OAAO;MAAEf,KAAK;MAAE,GAAGU,cAAc;MAAE,GAAGI,QAAQ,CAACE,SAAS,CAACC,GAAG,CAACnB,MAAM,C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GAEhC,CAAC;AACJ,CAAC;AAED,MAAMhB,aAAa,GAAIiB,WAAmB,IACxC7D,OAAO,CAACQ,IAAI,CAAC;EACXsD,MAAM,EAAE,sBAAsB;EAC9BC,MAAM,EAAE,WAAW;EACnBC,MAAM,EAAE,IAAIhE,OAAO,CAACiE,kBAAkB,CAAC;IAAEJ;EAAW,CAAE;CACvD,CAAC","ignoreList":[]}
@@ -1,11 +1,24 @@
1
1
  /**
2
- * @since 1.0.0
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
  * OpenAI-specific error metadata fields.
6
19
  *
7
- * @since 1.0.0
8
20
  * @category models
21
+ * @since 4.0.0
9
22
  */
10
23
  export type OpenAiErrorMetadata = {
11
24
  /**
@@ -24,11 +37,13 @@ export type OpenAiErrorMetadata = {
24
37
  /**
25
38
  * OpenAI-specific rate limit metadata fields.
26
39
  *
40
+ * **Details**
41
+ *
27
42
  * Extends base error metadata with rate limit specific information from
28
43
  * OpenAI's rate limit headers.
29
44
  *
30
- * @since 1.0.0
31
45
  * @category models
46
+ * @since 4.0.0
32
47
  */
33
48
  export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
34
49
  /**
@@ -49,45 +64,104 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
49
64
  readonly resetTokens: string | null;
50
65
  };
51
66
  declare module "effect/unstable/ai/AiError" {
52
- interface RateLimitError {
53
- readonly metadata: {
54
- readonly openai?: OpenAiRateLimitMetadata | null;
55
- };
67
+ /**
68
+ * Metadata attached to rate limit errors returned by OpenAI-compatible APIs.
69
+ *
70
+ * @category models
71
+ * @since 4.0.0
72
+ */
73
+ interface RateLimitErrorMetadata {
74
+ readonly openai?: OpenAiRateLimitMetadata | null;
56
75
  }
57
- interface QuotaExhaustedError {
58
- readonly metadata: {
59
- readonly openai?: OpenAiErrorMetadata | null;
60
- };
76
+ /**
77
+ * Metadata attached when an OpenAI-compatible provider reports that quota or
78
+ * billing limits have been exhausted.
79
+ *
80
+ * @category models
81
+ * @since 4.0.0
82
+ */
83
+ interface QuotaExhaustedErrorMetadata {
84
+ readonly openai?: OpenAiErrorMetadata | null;
61
85
  }
62
- interface AuthenticationError {
63
- readonly metadata: {
64
- readonly openai?: OpenAiErrorMetadata | null;
65
- };
86
+ /**
87
+ * Metadata attached to authentication failures from OpenAI-compatible APIs,
88
+ * such as invalid, missing, or unauthorized API credentials.
89
+ *
90
+ * @category models
91
+ * @since 4.0.0
92
+ */
93
+ interface AuthenticationErrorMetadata {
94
+ readonly openai?: OpenAiErrorMetadata | null;
66
95
  }
67
- interface ContentPolicyError {
68
- readonly metadata: {
69
- readonly openai?: OpenAiErrorMetadata | null;
70
- };
96
+ /**
97
+ * Metadata attached when an OpenAI-compatible provider rejects content because
98
+ * it violates a safety or usage policy.
99
+ *
100
+ * @category models
101
+ * @since 4.0.0
102
+ */
103
+ interface ContentPolicyErrorMetadata {
104
+ readonly openai?: OpenAiErrorMetadata | null;
71
105
  }
72
- interface InvalidRequestError {
73
- readonly metadata: {
74
- readonly openai?: OpenAiErrorMetadata | null;
75
- };
106
+ /**
107
+ * Metadata attached to malformed or unsupported requests rejected by an
108
+ * OpenAI-compatible API before model execution.
109
+ *
110
+ * @category models
111
+ * @since 4.0.0
112
+ */
113
+ interface InvalidRequestErrorMetadata {
114
+ readonly openai?: OpenAiErrorMetadata | null;
76
115
  }
77
- interface InternalProviderError {
78
- readonly metadata: {
79
- readonly openai?: OpenAiErrorMetadata | null;
80
- };
116
+ /**
117
+ * Metadata attached to unexpected server-side failures reported by an
118
+ * OpenAI-compatible provider.
119
+ *
120
+ * @category models
121
+ * @since 4.0.0
122
+ */
123
+ interface InternalProviderErrorMetadata {
124
+ readonly openai?: OpenAiErrorMetadata | null;
125
+ }
126
+ /**
127
+ * Metadata attached when an OpenAI-compatible response cannot be converted
128
+ * into the expected AI package output shape.
129
+ *
130
+ * @category models
131
+ * @since 4.0.0
132
+ */
133
+ interface InvalidOutputErrorMetadata {
134
+ readonly openai?: OpenAiErrorMetadata | null;
135
+ }
136
+ /**
137
+ * Metadata attached when an OpenAI-compatible structured output response does
138
+ * not satisfy the requested schema or parsing constraints.
139
+ *
140
+ * @category models
141
+ * @since 4.0.0
142
+ */
143
+ interface StructuredOutputErrorMetadata {
144
+ readonly openai?: OpenAiErrorMetadata | null;
81
145
  }
82
- interface InvalidOutputError {
83
- readonly metadata: {
84
- readonly openai?: OpenAiErrorMetadata | null;
85
- };
146
+ /**
147
+ * Metadata attached when an OpenAI-compatible provider cannot support the
148
+ * schema supplied for structured output or tool definitions.
149
+ *
150
+ * @category models
151
+ * @since 4.0.0
152
+ */
153
+ interface UnsupportedSchemaErrorMetadata {
154
+ readonly openai?: OpenAiErrorMetadata | null;
86
155
  }
87
- interface UnknownError {
88
- readonly metadata: {
89
- readonly openai?: OpenAiErrorMetadata | null;
90
- };
156
+ /**
157
+ * Metadata attached when an OpenAI-compatible error response cannot be mapped
158
+ * to a more specific shared AI error category.
159
+ *
160
+ * @category models
161
+ * @since 4.0.0
162
+ */
163
+ interface UnknownErrorMetadata {
164
+ readonly openai?: OpenAiErrorMetadata | null;
91
165
  }
92
166
  }
93
167
  //# sourceMappingURL=OpenAiError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAiError.d.ts","sourceRoot":"","sources":["../src/OpenAiError.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH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A4B,CAAC;IAC1C;;;;;OAKG;IACH,UAAiB,sBAAsB;QACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;KACjD;IAED;;;;;;OAMG;IACH,UAAiB,2BAA2B;QAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,2BAA2B;QAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,0BAA0B;QACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,2BAA2B;QAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,6BAA6B;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,0BAA0B;QACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,6BAA6B;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,8BAA8B;QAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED;;;;;;OAMG;IACH,UAAiB,oBAAoB;QACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;CACF"}
@@ -1,5 +1,18 @@
1
1
  /**
2
- * @since 1.0.0
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
  export {};
5
18
  //# sourceMappingURL=OpenAiError.js.map