@effect/ai-openai-compat 4.0.0-beta.8 → 4.0.0-beta.81

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 (38) 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 +186 -0
  10. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  11. package/dist/OpenAiEmbeddingModel.js +190 -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 +304 -20
  17. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  18. package/dist/OpenAiLanguageModel.js +157 -27
  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/package.json +3 -3
  31. package/src/OpenAiClient.ts +273 -50
  32. package/src/OpenAiConfig.ts +69 -11
  33. package/src/OpenAiEmbeddingModel.ts +332 -0
  34. package/src/OpenAiError.ts +111 -35
  35. package/src/OpenAiLanguageModel.ts +425 -42
  36. package/src/OpenAiTelemetry.ts +81 -32
  37. package/src/index.ts +11 -17
  38. package/src/internal/errors.ts +4 -4
@@ -0,0 +1,186 @@
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 * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
14
+ import * as AiModel from "effect/unstable/ai/Model";
15
+ import { OpenAiClient } from "./OpenAiClient.ts";
16
+ /**
17
+ * A model identifier accepted by an OpenAI-compatible embeddings endpoint.
18
+ *
19
+ * @category models
20
+ * @since 4.0.0
21
+ */
22
+ export type Model = string;
23
+ declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai-compat/OpenAiEmbeddingModel/Config", {
24
+ readonly [x: string]: unknown;
25
+ readonly model?: string;
26
+ readonly user?: string | undefined | undefined;
27
+ readonly encoding_format?: "float" | "base64" | undefined | undefined;
28
+ readonly dimensions?: number | undefined | undefined;
29
+ }>;
30
+ /**
31
+ * Context service for OpenAI embedding model configuration.
32
+ *
33
+ * **When to use**
34
+ *
35
+ * Use when you need to provide shared default request options for
36
+ * OpenAI-compatible embedding operations through the Effect context, such as
37
+ * `dimensions`, `encoding_format`, or `user`.
38
+ *
39
+ * **Details**
40
+ *
41
+ * The service stores the embedding request payload without `input`. Requests
42
+ * combine the selected model, layer or constructor config, and scoped context
43
+ * config, with scoped context config taking precedence.
44
+ *
45
+ * @see {@link withConfigOverride} for scoping embedding request overrides
46
+ *
47
+ * @category context
48
+ * @since 4.0.0
49
+ */
50
+ export declare class Config extends Config_base {
51
+ }
52
+ /**
53
+ * Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
54
+ *
55
+ * **When to use**
56
+ *
57
+ * Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
58
+ * service to an Effect program.
59
+ *
60
+ * @see {@link layer} for providing only the embedding model service
61
+ * @see {@link withConfigOverride} for scoped request configuration overrides
62
+ *
63
+ * @category constructors
64
+ * @since 4.0.0
65
+ */
66
+ export declare const model: (model: string, options: {
67
+ readonly dimensions: number;
68
+ readonly config?: Omit<typeof Config.Service, "model" | "dimensions">;
69
+ }) => AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient>;
70
+ /**
71
+ * Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
72
+ *
73
+ * **When to use**
74
+ *
75
+ * Use when you need to build or provide an `EmbeddingModel` service directly
76
+ * from an existing `OpenAiClient`.
77
+ *
78
+ * **Details**
79
+ *
80
+ * The service sends embedding requests through `OpenAiClient.createEmbedding`.
81
+ * Request config is merged as the selected model, constructor config, then
82
+ * scoped `Config`, so scoped overrides take precedence. Provider usage
83
+ * `prompt_tokens` is exposed as `usage.inputTokens`.
84
+ *
85
+ * **Gotchas**
86
+ *
87
+ * Provider responses must contain one numeric vector for every requested input
88
+ * with unique, in-range `index` values; otherwise embedding operations fail with
89
+ * `AiError.InvalidOutputError`.
90
+ *
91
+ * @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
92
+ * @see {@link layer} for providing the service as a `Layer`
93
+ * @see {@link withConfigOverride} for scoping embedding request overrides
94
+ *
95
+ * @category constructors
96
+ * @since 4.0.0
97
+ */
98
+ export declare const make: (args_0: {
99
+ readonly model: string;
100
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined;
101
+ }) => Effect.Effect<EmbeddingModel.Service, never, OpenAiClient>;
102
+ /**
103
+ * Creates a layer for an OpenAI-compatible embedding model service.
104
+ *
105
+ * **When to use**
106
+ *
107
+ * Use when composing application layers and you want an OpenAI-compatible
108
+ * embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
109
+ * supplying `OpenAiClient` from another layer.
110
+ *
111
+ * @see {@link make} for constructing the embedding model service effectfully
112
+ * @see {@link model} for creating an `AiModel` with configured dimensions
113
+ *
114
+ * @category layers
115
+ * @since 4.0.0
116
+ */
117
+ export declare const layer: (options: {
118
+ readonly model: string;
119
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined;
120
+ }) => Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient>;
121
+ /**
122
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
123
+ *
124
+ * **When to use**
125
+ *
126
+ * Use to apply embedding request options to one effect without changing the
127
+ * model's default configuration.
128
+ *
129
+ * **Details**
130
+ *
131
+ * The overrides are merged with any existing `Config` service for the duration
132
+ * of the supplied effect. Fields in `overrides` take precedence over existing
133
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
134
+ * and `withConfigOverride(effect, overrides)`.
135
+ *
136
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
137
+ *
138
+ * @category configuration
139
+ * @since 4.0.0
140
+ */
141
+ export declare const withConfigOverride: {
142
+ /**
143
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
144
+ *
145
+ * **When to use**
146
+ *
147
+ * Use to apply embedding request options to one effect without changing the
148
+ * model's default configuration.
149
+ *
150
+ * **Details**
151
+ *
152
+ * The overrides are merged with any existing `Config` service for the duration
153
+ * of the supplied effect. Fields in `overrides` take precedence over existing
154
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
155
+ * and `withConfigOverride(effect, overrides)`.
156
+ *
157
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
158
+ *
159
+ * @category configuration
160
+ * @since 4.0.0
161
+ */
162
+ (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
163
+ /**
164
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
165
+ *
166
+ * **When to use**
167
+ *
168
+ * Use to apply embedding request options to one effect without changing the
169
+ * model's default configuration.
170
+ *
171
+ * **Details**
172
+ *
173
+ * The overrides are merged with any existing `Config` service for the duration
174
+ * of the supplied effect. Fields in `overrides` take precedence over existing
175
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
176
+ * and `withConfigOverride(effect, overrides)`.
177
+ *
178
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
179
+ *
180
+ * @category configuration
181
+ * @since 4.0.0
182
+ */
183
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>;
184
+ };
185
+ export {};
186
+ //# 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;AAGrC,OAAO,KAAK,cAAc,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;;;;;;;;AAE1B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,MAAO,SAAQ,WAa+B;CAAG;AAE9D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAChB,OAAO,MAAM,EACb,SAAS;IACP,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,CAAC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CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;CAoDhH,CAAA"}
@@ -0,0 +1,190 @@
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: {
56
+ ...options.config,
57
+ dimensions: options.dimensions
58
+ }
59
+ }), Layer.succeed(EmbeddingModel.Dimensions, options.dimensions)));
60
+ /**
61
+ * Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
62
+ *
63
+ * **When to use**
64
+ *
65
+ * Use when you need to build or provide an `EmbeddingModel` service directly
66
+ * from an existing `OpenAiClient`.
67
+ *
68
+ * **Details**
69
+ *
70
+ * The service sends embedding requests through `OpenAiClient.createEmbedding`.
71
+ * Request config is merged as the selected model, constructor config, then
72
+ * scoped `Config`, so scoped overrides take precedence. Provider usage
73
+ * `prompt_tokens` is exposed as `usage.inputTokens`.
74
+ *
75
+ * **Gotchas**
76
+ *
77
+ * Provider responses must contain one numeric vector for every requested input
78
+ * with unique, in-range `index` values; otherwise embedding operations fail with
79
+ * `AiError.InvalidOutputError`.
80
+ *
81
+ * @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
82
+ * @see {@link layer} for providing the service as a `Layer`
83
+ * @see {@link withConfigOverride} for scoping embedding request overrides
84
+ *
85
+ * @category constructors
86
+ * @since 4.0.0
87
+ */
88
+ export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
89
+ model,
90
+ config: providerConfig
91
+ }) {
92
+ const client = yield* OpenAiClient;
93
+ const makeConfig = Effect.gen(function* () {
94
+ const services = yield* Effect.context();
95
+ return {
96
+ model,
97
+ ...providerConfig,
98
+ ...services.mapUnsafe.get(Config.key)
99
+ };
100
+ });
101
+ return yield* EmbeddingModel.make({
102
+ embedMany: Effect.fnUntraced(function* ({
103
+ inputs
104
+ }) {
105
+ const config = yield* makeConfig;
106
+ const response = yield* client.createEmbedding({
107
+ ...config,
108
+ input: inputs
109
+ });
110
+ return yield* mapProviderResponse(inputs.length, response);
111
+ })
112
+ });
113
+ });
114
+ /**
115
+ * Creates a layer for an OpenAI-compatible embedding model service.
116
+ *
117
+ * **When to use**
118
+ *
119
+ * Use when composing application layers and you want an OpenAI-compatible
120
+ * embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
121
+ * supplying `OpenAiClient` from another layer.
122
+ *
123
+ * @see {@link make} for constructing the embedding model service effectfully
124
+ * @see {@link model} for creating an `AiModel` with configured dimensions
125
+ *
126
+ * @category layers
127
+ * @since 4.0.0
128
+ */
129
+ export const layer = options => Layer.effect(EmbeddingModel.EmbeddingModel, make(options));
130
+ /**
131
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
132
+ *
133
+ * **When to use**
134
+ *
135
+ * Use to apply embedding request options to one effect without changing the
136
+ * model's default configuration.
137
+ *
138
+ * **Details**
139
+ *
140
+ * The overrides are merged with any existing `Config` service for the duration
141
+ * of the supplied effect. Fields in `overrides` take precedence over existing
142
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
143
+ * and `withConfigOverride(effect, overrides)`.
144
+ *
145
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
146
+ *
147
+ * @category configuration
148
+ * @since 4.0.0
149
+ */
150
+ export const withConfigOverride = /*#__PURE__*/dual(2, (self, overrides) => Effect.flatMap(Effect.serviceOption(Config), config => Effect.provideService(self, Config, {
151
+ ...(config._tag === "Some" ? config.value : {}),
152
+ ...overrides
153
+ })));
154
+ const mapProviderResponse = (inputLength, response) => {
155
+ if (response.data.length !== inputLength) {
156
+ return Effect.fail(invalidOutput(`Provider returned ${response.data.length} embeddings but expected ${inputLength}`));
157
+ }
158
+ const results = new Array(inputLength);
159
+ const seen = new Set();
160
+ for (const entry of response.data) {
161
+ if (!Number.isInteger(entry.index) || entry.index < 0 || entry.index >= inputLength) {
162
+ return Effect.fail(invalidOutput(`Provider returned invalid embedding index: ${entry.index}`));
163
+ }
164
+ if (seen.has(entry.index)) {
165
+ return Effect.fail(invalidOutput(`Provider returned duplicate embedding index: ${entry.index}`));
166
+ }
167
+ if (!Array.isArray(entry.embedding)) {
168
+ return Effect.fail(invalidOutput(`Provider returned non-vector embedding at index ${entry.index}`));
169
+ }
170
+ seen.add(entry.index);
171
+ results[entry.index] = [...entry.embedding];
172
+ }
173
+ if (seen.size !== inputLength) {
174
+ return Effect.fail(invalidOutput(`Provider returned embeddings for ${seen.size} inputs but expected ${inputLength}`));
175
+ }
176
+ return Effect.succeed({
177
+ results,
178
+ usage: {
179
+ inputTokens: response.usage?.prompt_tokens
180
+ }
181
+ });
182
+ };
183
+ const invalidOutput = description => AiError.make({
184
+ module: "OpenAiEmbeddingModel",
185
+ method: "embedMany",
186
+ reason: new AiError.InvalidOutputError({
187
+ description
188
+ })
189
+ });
190
+ //# 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","dimensions","succeed","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;AAUhD;;;;;;;;;;;;;;;;;;;;AAoBA,OAAM,MAAOC,MAAO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A8CK,KAAK,CAACG,KAAK,EAAE,CAAC,CAAC;IAChG;IACA,IAAIL,IAAI,CAACM,GAAG,CAACJ,KAAK,CAACG,KAAK,CAAC,EAAE;MACzB,OAAOvD,MAAM,CAAC8C,IAAI,CAACC,aAAa,CAAC,gDAAgDK,KAAK,CAACG,KAAK,EAAE,CAAC,CAAC;IAClG;IACA,IAAI,CAACN,KAAK,CAACQ,OAAO,CAACL,KAAK,CAACM,SAAS,CAAC,EAAE;MACnC,OAAO1D,MAAM,CAAC8C,IAAI,CAACC,aAAa,CAAC,mDAAmDK,KAAK,CAACG,KAAK,EAAE,CAAC,CAAC;IACrG;IAEAL,IAAI,CAACS,GAAG,CAACP,KAAK,CAACG,KAAK,CAAC;IACrBP,OAAO,CAACI,KAAK,CAACG,KAAK,CAAC,GAAG,CAAC,GAAGH,KAAK,CAACM,SAAS,CAAC;EAC7C;EAEA,IAAIR,IAAI,CAACU,IAAI,KAAKhB,WAAW,EAAE;IAC7B,OAAO5C,MAAM,CAAC8C,IAAI,CAChBC,aAAa,CAAC,oCAAoCG,IAAI,CAACU,IAAI,wBAAwBhB,WAAW,EAAE,CAAC,CAClG;EACH;EAEA,OAAO5C,MAAM,CAACgB,OAAO,CAAC;IACpBgC,OAAO;IACPa,KAAK,EAAE;MACLC,WAAW,EAAEhC,QAAQ,CAAC+B,KAAK,EAAEE;;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;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG;IAC1D;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAA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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