@effect/ai-openai-compat 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.
- package/dist/OpenAiClient.d.ts +250 -51
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +108 -9
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +83 -10
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +51 -7
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +214 -0
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
- package/dist/OpenAiEmbeddingModel.js +218 -0
- package/dist/OpenAiEmbeddingModel.js.map +1 -0
- package/dist/OpenAiError.d.ts +109 -35
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiError.js +14 -1
- package/dist/OpenAiLanguageModel.d.ts +326 -18
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +126 -25
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +72 -22
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +47 -8
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/index.d.ts +10 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -17
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +4 -4
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/OpenAiClient.ts +283 -49
- package/src/OpenAiConfig.ts +84 -11
- package/src/OpenAiEmbeddingModel.ts +360 -0
- package/src/OpenAiError.ts +111 -35
- package/src/OpenAiLanguageModel.ts +409 -40
- package/src/OpenAiTelemetry.ts +103 -27
- package/src/index.ts +11 -17
- package/src/internal/errors.ts +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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O,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CACnE,KAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,KAAK,EAAE,YAAY,CACN,CAAA;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,kBAAkB,EAAE;IAC/B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,CAAC,SAAS,EAAE,OAAO,MAAM,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,218 @@
|
|
|
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, and supports scoped request configuration overrides.
|
|
6
|
+
*
|
|
7
|
+
* **Mental model**
|
|
8
|
+
*
|
|
9
|
+
* - {@link make} builds the `EmbeddingModel` service when an
|
|
10
|
+
* {@link OpenAiClient} is already available.
|
|
11
|
+
* - {@link layer} provides that service as a `Layer`.
|
|
12
|
+
* - {@link model} creates an `AiModel` and also provides the configured vector
|
|
13
|
+
* dimensions service expected by embedding consumers.
|
|
14
|
+
* - {@link Config} and {@link withConfigOverride} merge default request options
|
|
15
|
+
* with scoped overrides for individual operations.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* - Use {@link model} when application code wants a named `AiModel` with known
|
|
20
|
+
* dimensions.
|
|
21
|
+
* - Use {@link layer} when composing services around an existing
|
|
22
|
+
* {@link OpenAiClient} layer.
|
|
23
|
+
* - Use {@link withConfigOverride} to set per-operation options such as `user`,
|
|
24
|
+
* `dimensions`, or provider-specific request fields.
|
|
25
|
+
*
|
|
26
|
+
* **Gotchas**
|
|
27
|
+
*
|
|
28
|
+
* - {@link Model} is `string` because OpenAI-compatible providers use their
|
|
29
|
+
* own embedding model identifiers.
|
|
30
|
+
* - {@link model} requires explicit dimensions because compatible providers do
|
|
31
|
+
* not expose a shared way to infer vector width.
|
|
32
|
+
* - Provider responses must contain one numeric vector per input with unique,
|
|
33
|
+
* in-range indexes; base64 embeddings or malformed indexes fail with
|
|
34
|
+
* `InvalidOutputError`.
|
|
35
|
+
*
|
|
36
|
+
* @since 4.0.0
|
|
37
|
+
*/
|
|
38
|
+
import * as Context from "effect/Context";
|
|
39
|
+
import * as Effect from "effect/Effect";
|
|
40
|
+
import { dual } from "effect/Function";
|
|
41
|
+
import * as Layer from "effect/Layer";
|
|
42
|
+
import * as AiError from "effect/unstable/ai/AiError";
|
|
43
|
+
import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
|
|
44
|
+
import * as AiModel from "effect/unstable/ai/Model";
|
|
45
|
+
import { OpenAiClient } from "./OpenAiClient.js";
|
|
46
|
+
/**
|
|
47
|
+
* Service definition for OpenAI embedding model configuration.
|
|
48
|
+
*
|
|
49
|
+
* **When to use**
|
|
50
|
+
*
|
|
51
|
+
* Use when you need to provide shared default request options for
|
|
52
|
+
* OpenAI-compatible embedding operations through the Effect context, such as
|
|
53
|
+
* `dimensions`, `encoding_format`, or `user`.
|
|
54
|
+
*
|
|
55
|
+
* **Details**
|
|
56
|
+
*
|
|
57
|
+
* The service stores the embedding request payload without `input`. Requests
|
|
58
|
+
* combine the selected model, layer or constructor config, and scoped context
|
|
59
|
+
* config, with scoped context config taking precedence.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
62
|
+
*
|
|
63
|
+
* @category context
|
|
64
|
+
* @since 4.0.0
|
|
65
|
+
*/
|
|
66
|
+
export class Config extends /*#__PURE__*/Context.Service()("@effect/ai-openai-compat/OpenAiEmbeddingModel/Config") {}
|
|
67
|
+
/**
|
|
68
|
+
* Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
|
|
69
|
+
*
|
|
70
|
+
* **When to use**
|
|
71
|
+
*
|
|
72
|
+
* Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
|
|
73
|
+
* service to an Effect program.
|
|
74
|
+
*
|
|
75
|
+
* @see {@link layer} for providing only the embedding model service
|
|
76
|
+
* @see {@link withConfigOverride} for scoped request configuration overrides
|
|
77
|
+
*
|
|
78
|
+
* @category constructors
|
|
79
|
+
* @since 4.0.0
|
|
80
|
+
*/
|
|
81
|
+
export const model = (model, options) => AiModel.make("openai", model, Layer.merge(layer({
|
|
82
|
+
model,
|
|
83
|
+
config: {
|
|
84
|
+
...options.config,
|
|
85
|
+
dimensions: options.dimensions
|
|
86
|
+
}
|
|
87
|
+
}), Layer.succeed(EmbeddingModel.Dimensions, options.dimensions)));
|
|
88
|
+
/**
|
|
89
|
+
* Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
|
|
90
|
+
*
|
|
91
|
+
* **When to use**
|
|
92
|
+
*
|
|
93
|
+
* Use when you need to build or provide an `EmbeddingModel` service directly
|
|
94
|
+
* from an existing `OpenAiClient`.
|
|
95
|
+
*
|
|
96
|
+
* **Details**
|
|
97
|
+
*
|
|
98
|
+
* The service sends embedding requests through `OpenAiClient.createEmbedding`.
|
|
99
|
+
* Request config is merged as the selected model, constructor config, then
|
|
100
|
+
* scoped `Config`, so scoped overrides take precedence. Provider usage
|
|
101
|
+
* `prompt_tokens` is exposed as `usage.inputTokens`.
|
|
102
|
+
*
|
|
103
|
+
* **Gotchas**
|
|
104
|
+
*
|
|
105
|
+
* Provider responses must contain one numeric vector for every requested input
|
|
106
|
+
* with unique, in-range `index` values; otherwise embedding operations fail with
|
|
107
|
+
* `AiError.InvalidOutputError`.
|
|
108
|
+
*
|
|
109
|
+
* @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
|
|
110
|
+
* @see {@link layer} for providing the service as a `Layer`
|
|
111
|
+
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
112
|
+
*
|
|
113
|
+
* @category constructors
|
|
114
|
+
* @since 4.0.0
|
|
115
|
+
*/
|
|
116
|
+
export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
117
|
+
model,
|
|
118
|
+
config: providerConfig
|
|
119
|
+
}) {
|
|
120
|
+
const client = yield* OpenAiClient;
|
|
121
|
+
const makeConfig = Effect.gen(function* () {
|
|
122
|
+
const services = yield* Effect.context();
|
|
123
|
+
return {
|
|
124
|
+
model,
|
|
125
|
+
...providerConfig,
|
|
126
|
+
...services.mapUnsafe.get(Config.key)
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
return yield* EmbeddingModel.make({
|
|
130
|
+
embedMany: Effect.fnUntraced(function* ({
|
|
131
|
+
inputs
|
|
132
|
+
}) {
|
|
133
|
+
const config = yield* makeConfig;
|
|
134
|
+
const response = yield* client.createEmbedding({
|
|
135
|
+
...config,
|
|
136
|
+
input: inputs
|
|
137
|
+
});
|
|
138
|
+
return yield* mapProviderResponse(inputs.length, response);
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* Creates a layer for an OpenAI-compatible embedding model service.
|
|
144
|
+
*
|
|
145
|
+
* **When to use**
|
|
146
|
+
*
|
|
147
|
+
* Use when composing application layers and you want an OpenAI-compatible
|
|
148
|
+
* embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
|
|
149
|
+
* supplying `OpenAiClient` from another layer.
|
|
150
|
+
*
|
|
151
|
+
* @see {@link make} for constructing the embedding model service effectfully
|
|
152
|
+
* @see {@link model} for creating an `AiModel` with configured dimensions
|
|
153
|
+
*
|
|
154
|
+
* @category layers
|
|
155
|
+
* @since 4.0.0
|
|
156
|
+
*/
|
|
157
|
+
export const layer = options => Layer.effect(EmbeddingModel.EmbeddingModel, make(options));
|
|
158
|
+
/**
|
|
159
|
+
* Provides scoped request config overrides for OpenAI-compatible embedding model operations.
|
|
160
|
+
*
|
|
161
|
+
* **When to use**
|
|
162
|
+
*
|
|
163
|
+
* Use to apply embedding request options to one effect without changing the
|
|
164
|
+
* model's default configuration.
|
|
165
|
+
*
|
|
166
|
+
* **Details**
|
|
167
|
+
*
|
|
168
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
169
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
170
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
171
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
172
|
+
*
|
|
173
|
+
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
174
|
+
*
|
|
175
|
+
* @category configuration
|
|
176
|
+
* @since 4.0.0
|
|
177
|
+
*/
|
|
178
|
+
export const withConfigOverride = /*#__PURE__*/dual(2, (self, overrides) => Effect.flatMap(Effect.serviceOption(Config), config => Effect.provideService(self, Config, {
|
|
179
|
+
...(config._tag === "Some" ? config.value : {}),
|
|
180
|
+
...overrides
|
|
181
|
+
})));
|
|
182
|
+
const mapProviderResponse = (inputLength, response) => {
|
|
183
|
+
if (response.data.length !== inputLength) {
|
|
184
|
+
return Effect.fail(invalidOutput(`Provider returned ${response.data.length} embeddings but expected ${inputLength}`));
|
|
185
|
+
}
|
|
186
|
+
const results = new Array(inputLength);
|
|
187
|
+
const seen = new Set();
|
|
188
|
+
for (const entry of response.data) {
|
|
189
|
+
if (!Number.isInteger(entry.index) || entry.index < 0 || entry.index >= inputLength) {
|
|
190
|
+
return Effect.fail(invalidOutput(`Provider returned invalid embedding index: ${entry.index}`));
|
|
191
|
+
}
|
|
192
|
+
if (seen.has(entry.index)) {
|
|
193
|
+
return Effect.fail(invalidOutput(`Provider returned duplicate embedding index: ${entry.index}`));
|
|
194
|
+
}
|
|
195
|
+
if (!Array.isArray(entry.embedding)) {
|
|
196
|
+
return Effect.fail(invalidOutput(`Provider returned non-vector embedding at index ${entry.index}`));
|
|
197
|
+
}
|
|
198
|
+
seen.add(entry.index);
|
|
199
|
+
results[entry.index] = [...entry.embedding];
|
|
200
|
+
}
|
|
201
|
+
if (seen.size !== inputLength) {
|
|
202
|
+
return Effect.fail(invalidOutput(`Provider returned embeddings for ${seen.size} inputs but expected ${inputLength}`));
|
|
203
|
+
}
|
|
204
|
+
return Effect.succeed({
|
|
205
|
+
results,
|
|
206
|
+
usage: {
|
|
207
|
+
inputTokens: response.usage?.prompt_tokens
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
const invalidOutput = description => AiError.make({
|
|
212
|
+
module: "OpenAiEmbeddingModel",
|
|
213
|
+
method: "embedMany",
|
|
214
|
+
reason: new AiError.InvalidOutputError({
|
|
215
|
+
description
|
|
216
|
+
})
|
|
217
|
+
});
|
|
218
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,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,sBAAQR,OAAO,CAACS,OAAO,EAaxC,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,EAAE;IACN,GAAGJ,OAAO,CAACI,MAAM;IACjBC,UAAU,EAAEL,OAAO,CAACK;;CAEvB,CAAC,EACFb,KAAK,CAACc,OAAO,CAACZ,cAAc,CAACa,UAAU,EAAEP,OAAO,CAACK,UAAU,CAAC,CAC7D,CACF;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,OAAO,MAAMJ,IAAI,gBAAGX,MAAM,CAACkB,UAAU,CAAC,WAAU;EAAET,KAAK;EAAEK,MAAM,EAAEK;AAAc,CAG9E;EACC,MAAMC,MAAM,GAAG,OAAOd,YAAY;EAElC,MAAMe,UAAU,GAAGrB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a,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":[]}
|
package/dist/OpenAiError.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"OpenAiError.d.ts","sourceRoot":"","sources":["../src/OpenAiError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;GAKG;AACH,MAAM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C,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"}
|
package/dist/OpenAiError.js
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|