@enlitt/sdk 0.0.0-stage → 0.1.1
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/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +63 -2
- package/dist/browser/auth.d.cts +44 -0
- package/dist/browser/auth.d.ts +45 -0
- package/dist/browser/auth.d.ts.map +1 -0
- package/dist/browser.cjs +35 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +12 -0
- package/dist/browser.d.ts +13 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +32 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunk-2BGWYTJM.cjs +1097 -0
- package/dist/chunk-2BGWYTJM.cjs.map +1 -0
- package/dist/chunk-6OWXYBBT.cjs +146 -0
- package/dist/chunk-6OWXYBBT.cjs.map +1 -0
- package/dist/chunk-NI6WH5FI.js +33 -0
- package/dist/chunk-NI6WH5FI.js.map +1 -0
- package/dist/chunk-O6ASIA3X.js +866 -0
- package/dist/chunk-O6ASIA3X.js.map +1 -0
- package/dist/chunk-PPOUNWNA.cjs +895 -0
- package/dist/chunk-PPOUNWNA.cjs.map +1 -0
- package/dist/chunk-UVZMKGIL.js +1091 -0
- package/dist/chunk-UVZMKGIL.js.map +1 -0
- package/dist/chunk-V5TCSQ7C.js +143 -0
- package/dist/chunk-V5TCSQ7C.js.map +1 -0
- package/dist/chunk-YPA4R65T.cjs +35 -0
- package/dist/chunk-YPA4R65T.cjs.map +1 -0
- package/dist/core/errors.d.cts +262 -0
- package/dist/core/errors.d.ts +263 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/index.d.cts +24 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/premium.d.cts +230 -0
- package/dist/core/premium.d.ts +231 -0
- package/dist/core/premium.d.ts.map +1 -0
- package/dist/core/session.d.cts +122 -0
- package/dist/core/session.d.ts +123 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/sse.d.cts +79 -0
- package/dist/core/sse.d.ts +80 -0
- package/dist/core/sse.d.ts.map +1 -0
- package/dist/core/transport.d.cts +223 -0
- package/dist/core/transport.d.ts +224 -0
- package/dist/core/transport.d.ts.map +1 -0
- package/dist/core/usage.d.cts +35 -0
- package/dist/core/usage.d.ts +36 -0
- package/dist/core/usage.d.ts.map +1 -0
- package/dist/core.cjs +77 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.js +4 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/openai/client.d.cts +72 -0
- package/dist/openai/client.d.ts +73 -0
- package/dist/openai/client.d.ts.map +1 -0
- package/dist/openai/index.d.cts +2 -0
- package/dist/openai/index.d.ts +3 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/media.d.cts +108 -0
- package/dist/openai/media.d.ts +109 -0
- package/dist/openai/media.d.ts.map +1 -0
- package/dist/openai.cjs +623 -0
- package/dist/openai.cjs.map +1 -0
- package/dist/openai.js +617 -0
- package/dist/openai.js.map +1 -0
- package/dist/server/callback.d.cts +107 -0
- package/dist/server/callback.d.ts +108 -0
- package/dist/server/callback.d.ts.map +1 -0
- package/dist/server/client-sign-in.d.cts +77 -0
- package/dist/server/client-sign-in.d.ts +78 -0
- package/dist/server/client-sign-in.d.ts.map +1 -0
- package/dist/server/index.d.cts +20 -0
- package/dist/server/index.d.ts +21 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/secrets.d.cts +46 -0
- package/dist/server/secrets.d.ts +47 -0
- package/dist/server/secrets.d.ts.map +1 -0
- package/dist/server-unavailable.cjs +8 -0
- package/dist/server-unavailable.cjs.map +1 -0
- package/dist/server-unavailable.d.cts +10 -0
- package/dist/server-unavailable.d.ts +11 -0
- package/dist/server-unavailable.d.ts.map +1 -0
- package/dist/server-unavailable.js +6 -0
- package/dist/server-unavailable.js.map +1 -0
- package/dist/server.cjs +880 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.js +795 -0
- package/dist/server.js.map +1 -0
- package/dist/vercel/index.d.cts +17 -0
- package/dist/vercel/index.d.ts +18 -0
- package/dist/vercel/index.d.ts.map +1 -0
- package/dist/vercel/language-model.d.cts +146 -0
- package/dist/vercel/language-model.d.ts +147 -0
- package/dist/vercel/language-model.d.ts.map +1 -0
- package/dist/vercel/premium-language-model.d.cts +127 -0
- package/dist/vercel/premium-language-model.d.ts +128 -0
- package/dist/vercel/premium-language-model.d.ts.map +1 -0
- package/dist/vercel/premium-media-model.d.cts +101 -0
- package/dist/vercel/premium-media-model.d.ts +102 -0
- package/dist/vercel/premium-media-model.d.ts.map +1 -0
- package/dist/vercel/standard-language-model.d.cts +104 -0
- package/dist/vercel/standard-language-model.d.ts +105 -0
- package/dist/vercel/standard-language-model.d.ts.map +1 -0
- package/dist/vercel.cjs +22 -0
- package/dist/vercel.cjs.map +1 -0
- package/dist/vercel.js +5 -0
- package/dist/vercel.js.map +1 -0
- package/package.json +139 -3
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's typed error hierarchy and the single mapping from an Enlitt
|
|
3
|
+
* failure to one of its classes.
|
|
4
|
+
*
|
|
5
|
+
* This file declares no wire code list of its own. The stable codes, their
|
|
6
|
+
* OpenAI-shaped `type`, their HTTP status, their retryability, and whether
|
|
7
|
+
* they may carry `authorize_url` all come from the frozen record
|
|
8
|
+
* `@enlitt/protocol` exports — the same record the backend raises from. That
|
|
9
|
+
* is what keeps a code, and every fact about it, declared exactly once across
|
|
10
|
+
* the wire rather than asserted independently in two workspaces.
|
|
11
|
+
*
|
|
12
|
+
* It declares one small closed set of SDK-local codes, for the four failures
|
|
13
|
+
* that never reach the wire and so can have no entry in the protocol record.
|
|
14
|
+
* That set is provably disjoint from the record's codes (see
|
|
15
|
+
* `_LocalCodesDisjointFromWireCodes` below), so no reader ever has to ask
|
|
16
|
+
* which side of the wire a given code came from.
|
|
17
|
+
*
|
|
18
|
+
* No class here carries a balance, plan, service tier, period, or personal
|
|
19
|
+
* identity, and none wraps a provider's own error — a provider failure that
|
|
20
|
+
* passes through the premium path is rethrown unchanged by
|
|
21
|
+
* `normalizeEnlittModelError` and is never an instance of `EnlittError`.
|
|
22
|
+
*/
|
|
23
|
+
import { ENLITT_ERROR_CODE, type EnlittErrorCode as EnlittWireCode } from "@enlitt/protocol";
|
|
24
|
+
/**
|
|
25
|
+
* The only codes this module originates. They exist because these four
|
|
26
|
+
* failures never reach the wire: bad or missing configuration, a request
|
|
27
|
+
* that never produced an HTTP response, a response that could not be parsed,
|
|
28
|
+
* and a caller-initiated abort. All four are always non-retryable and always
|
|
29
|
+
* report `providerInvoked: false`, the same as every wire-originated code,
|
|
30
|
+
* because none of them means a provider was ever reached either.
|
|
31
|
+
*/
|
|
32
|
+
export type EnlittLocalCode = "configuration_invalid" | "transport_failed" | "malformed_response" | "request_canceled";
|
|
33
|
+
/**
|
|
34
|
+
* The bounded facts a caller may attach when constructing an error: the
|
|
35
|
+
* parsed `Retry-After`, the upstream `x-request-id`, and a navigation target.
|
|
36
|
+
* Every field is optional because most codes carry none of them — a local
|
|
37
|
+
* code carries none at all, and `authorizeUrl` is stored only where the
|
|
38
|
+
* record permits the resulting code to carry one (see `EnlittError` below).
|
|
39
|
+
*/
|
|
40
|
+
export interface EnlittErrorFacts {
|
|
41
|
+
/** Milliseconds, converted once from the wire's `Retry-After` seconds. */
|
|
42
|
+
readonly retryAfterMs?: number;
|
|
43
|
+
readonly requestId?: string;
|
|
44
|
+
readonly authorizeUrl?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Only meaningful for a code the record does not contain: the protocol
|
|
47
|
+
* classifier's status-derived answer for a code from a newer server. A code
|
|
48
|
+
* in the record always takes its `retryable` from the record instead.
|
|
49
|
+
*/
|
|
50
|
+
readonly retryable?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Any other string: a code this SDK version does not know. `string & {}`
|
|
54
|
+
* keeps editor completion for the known codes while forcing every business
|
|
55
|
+
* `switch` over `EnlittError["code"]` to carry a `default` branch. Exported as
|
|
56
|
+
* a type only; it adds no runtime value.
|
|
57
|
+
*/
|
|
58
|
+
export type EnlittUnrecognizedCode = string & {};
|
|
59
|
+
/**
|
|
60
|
+
* The base class for every Enlitt-originated failure, and the only carrier
|
|
61
|
+
* of Enlitt's stable wire codes into a caller's code.
|
|
62
|
+
*
|
|
63
|
+
* Enlitt failures with no distinct business action of their own — invalid
|
|
64
|
+
* request, unsupported capability, conflict, routing, and server failures,
|
|
65
|
+
* plus a wire code newer than this SDK knows — surface as this class
|
|
66
|
+
* directly, carrying their stable code. Every other wire code that does
|
|
67
|
+
* imply a distinct action gets its own subclass below.
|
|
68
|
+
*/
|
|
69
|
+
export declare class EnlittError extends Error {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly code: EnlittWireCode | EnlittLocalCode | EnlittUnrecognizedCode;
|
|
72
|
+
/**
|
|
73
|
+
* Always `false`. Enlitt refuses before a provider is ever reached, so no
|
|
74
|
+
* instance of this hierarchy can report otherwise — that is the one
|
|
75
|
+
* question a business needs answered before it retries or bills anything.
|
|
76
|
+
* A provider's own error is never wrapped in this class in the first
|
|
77
|
+
* place; see `normalizeEnlittModelError`.
|
|
78
|
+
*/
|
|
79
|
+
readonly providerInvoked: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Read from the frozen record for a wire code, and always `false` for a
|
|
82
|
+
* local code, which has no record entry. Never decided per instance: a
|
|
83
|
+
* refusal carries the non-retryable marker the pinned Vercel AI SDK reads,
|
|
84
|
+
* so a configured `maxRetries` cannot turn one refusal into several.
|
|
85
|
+
*/
|
|
86
|
+
readonly retryable: boolean;
|
|
87
|
+
readonly retryAfterMs?: number;
|
|
88
|
+
readonly requestId?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Present only when the record's `authorizeUrl` field for this instance's
|
|
91
|
+
* code is `"allowed"` and a caller supplied one. It is a navigation
|
|
92
|
+
* target, never a disclosure: the actual figures live only on Enlitt's own
|
|
93
|
+
* dashboard behind it.
|
|
94
|
+
*
|
|
95
|
+
* The record allows this on the four `insufficient_credits_error` codes and
|
|
96
|
+
* no others, which is what this module's spec text says. `authorizeUrl` is
|
|
97
|
+
* still read from the record rather than decided here, per this module's own
|
|
98
|
+
* rule; the record simply now agrees with the spec.
|
|
99
|
+
*/
|
|
100
|
+
readonly authorizeUrl?: string;
|
|
101
|
+
constructor(code: EnlittWireCode | EnlittLocalCode | EnlittUnrecognizedCode, message: string, facts?: EnlittErrorFacts);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Code `configuration_invalid`. Missing or invalid SDK configuration: absent
|
|
105
|
+
* business secret, browser use, invalid base URL, invalid call options, an
|
|
106
|
+
* invalid quote, or a missing session context. Thrown locally before any
|
|
107
|
+
* network call, so a misconfigured deployment fails without touching Enlitt
|
|
108
|
+
* or a provider. Audience is the business's own logs; it must never reach an
|
|
109
|
+
* end user's screen.
|
|
110
|
+
*/
|
|
111
|
+
export declare class EnlittConfigurationError extends EnlittError {
|
|
112
|
+
readonly name = "EnlittConfigurationError";
|
|
113
|
+
constructor(message: string);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Code `personal_login_required`. No usable personal session resolves for
|
|
117
|
+
* this application. It belongs to both the standard and premium paths
|
|
118
|
+
* identically, with the provider left uninvoked either way: the alternative
|
|
119
|
+
* — letting premium proceed at the business's own cost — would mean every
|
|
120
|
+
* user whose session expired silently moved their spending onto the
|
|
121
|
+
* business. Audience is the end user: the business sends them through
|
|
122
|
+
* Enlitt login or reauthorization.
|
|
123
|
+
*/
|
|
124
|
+
export declare class EnlittLoginRequiredError extends EnlittError {
|
|
125
|
+
readonly name = "EnlittLoginRequiredError";
|
|
126
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Code `spending_limit_exceeded`. One of the user's application limits
|
|
130
|
+
* refused the call. `limitRule` copies `error.enlitt.limit_rule`
|
|
131
|
+
* (`standard_per_call`, `premium_per_call`, `rate.standard`, `rate.premium`,
|
|
132
|
+
* or a rule a newer server added) so the business can explain which limit refused without
|
|
133
|
+
* learning its value. It carries no amount, because a user's ceiling is their
|
|
134
|
+
* own financial position. An unknown future rule stays a string and is
|
|
135
|
+
* rendered generically; this field is never a closed authorization decision.
|
|
136
|
+
* Audience is the end user, who raises the limit at `authorizeUrl`.
|
|
137
|
+
*/
|
|
138
|
+
export declare class EnlittLimitExceededError extends EnlittError {
|
|
139
|
+
readonly name = "EnlittLimitExceededError";
|
|
140
|
+
readonly limitRule: string;
|
|
141
|
+
constructor(message: string, limitRule: string, facts?: EnlittErrorFacts);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Codes `premium_balance_exhausted` and `standard_balance_exhausted` (and any
|
|
145
|
+
* credit-refusal code from a newer server, carried raw). The first means the
|
|
146
|
+
* matching allowance plus eligible bundles cannot cover the call; the second
|
|
147
|
+
* is the standard equivalent. `admissibleMaxChargeNanoUsd` is present only on
|
|
148
|
+
* a premium `premium_balance_exhausted`: the largest `maxCharge` the user's
|
|
149
|
+
* remaining credits would admit now, copied byte for byte. It is the protocol's
|
|
150
|
+
* single disclosed figure; the SDK never retries with it on its own. No other
|
|
151
|
+
* balance, plan, tier, or period fact is ever carried. The audience is the
|
|
152
|
+
* end user, who tops up or upgrades at `authorizeUrl`.
|
|
153
|
+
*/
|
|
154
|
+
export declare class EnlittInsufficientCreditsError extends EnlittError {
|
|
155
|
+
readonly name = "EnlittInsufficientCreditsError";
|
|
156
|
+
readonly admissibleMaxChargeNanoUsd?: string;
|
|
157
|
+
constructor(code: typeof ENLITT_ERROR_CODE.premium_balance_exhausted | typeof ENLITT_ERROR_CODE.standard_balance_exhausted | EnlittUnrecognizedCode, message: string, facts?: EnlittErrorFacts & {
|
|
158
|
+
readonly admissibleMaxChargeNanoUsd?: string;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Code `subscription_inactive`. No subscription period covers the current
|
|
163
|
+
* instant. Because every registered user holds at least the free plan, this
|
|
164
|
+
* is exceptional rather than the ordinary state of a user who has not paid:
|
|
165
|
+
* a user who never subscribed, lapsed, or canceled receives
|
|
166
|
+
* `EnlittInsufficientCreditsError` at free-plan ceilings instead. Audience is
|
|
167
|
+
* the end user, but a business seeing this at any volume should treat it as
|
|
168
|
+
* a defect signal rather than a funnel step.
|
|
169
|
+
*/
|
|
170
|
+
export declare class EnlittSubscriptionInactiveError extends EnlittError {
|
|
171
|
+
readonly name = "EnlittSubscriptionInactiveError";
|
|
172
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Code `rate_limit_exceeded`. This user has started as many standard calls as
|
|
176
|
+
* their plan allows for the current minute. Only the standard path raises it:
|
|
177
|
+
* a premium operation consumes no request budget. It is the only refusal-shaped
|
|
178
|
+
* condition that is retryable, and the only class that carries
|
|
179
|
+
* `retryAfterMs` in practice. It is emphatically not an
|
|
180
|
+
* `EnlittInsufficientCreditsError`: conflating a transient wait with an
|
|
181
|
+
* exhausted balance would tell users to buy credits they do not need. It
|
|
182
|
+
* carries no rate, remaining request count, or plan fact, because those are
|
|
183
|
+
* the user's plan details.
|
|
184
|
+
*/
|
|
185
|
+
export declare class EnlittRateLimitError extends EnlittError {
|
|
186
|
+
readonly name = "EnlittRateLimitError";
|
|
187
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Code `invalid_api_key`. The presented business key is missing, invalid, or
|
|
191
|
+
* revoked. Audience is the business's own logs; never rendered to an end
|
|
192
|
+
* user, and never softened into a direct provider call.
|
|
193
|
+
*/
|
|
194
|
+
export declare class EnlittAuthenticationError extends EnlittError {
|
|
195
|
+
readonly name = "EnlittAuthenticationError";
|
|
196
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
197
|
+
}
|
|
198
|
+
/** The two wire codes `EnlittAuthorizationError` carries. */
|
|
199
|
+
export type EnlittAuthorizationCode = typeof ENLITT_ERROR_CODE.insufficient_permissions | typeof ENLITT_ERROR_CODE.premium_not_enabled;
|
|
200
|
+
/**
|
|
201
|
+
* A business credential or configuration problem. Audience is the business's
|
|
202
|
+
* own logs; never rendered to an end user, and never softened into a direct
|
|
203
|
+
* provider call. Two codes:
|
|
204
|
+
*
|
|
205
|
+
* - `insufficient_permissions` (the default): the presented business key is
|
|
206
|
+
* valid but used outside its authenticated application or scope.
|
|
207
|
+
* - `premium_not_enabled` (owner decision 2026-10-25): the application's
|
|
208
|
+
* premium switch is off, or changed during the call. On a refused premium
|
|
209
|
+
* start no provider was invoked; on a refused terminal report the provider
|
|
210
|
+
* already ran and the call was not charged.
|
|
211
|
+
*/
|
|
212
|
+
export declare class EnlittAuthorizationError extends EnlittError {
|
|
213
|
+
readonly name = "EnlittAuthorizationError";
|
|
214
|
+
constructor(message: string, facts?: EnlittErrorFacts, code?: EnlittAuthorizationCode);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* An Enlitt HTTP error response, shaped for normalization: the HTTP status,
|
|
218
|
+
* the parsed JSON body (untrusted, hence `unknown`), and the two response
|
|
219
|
+
* headers normalization reads. `core/transport.ts` is the only intended
|
|
220
|
+
* producer of this shape.
|
|
221
|
+
*/
|
|
222
|
+
export interface EnlittHttpErrorResponse {
|
|
223
|
+
readonly kind: "http_error";
|
|
224
|
+
readonly status: number;
|
|
225
|
+
readonly body: unknown;
|
|
226
|
+
readonly headers: Readonly<Record<string, string | undefined>>;
|
|
227
|
+
}
|
|
228
|
+
/** A request that never produced an HTTP response at all. */
|
|
229
|
+
export interface EnlittTransportFailure {
|
|
230
|
+
readonly kind: "transport_failed";
|
|
231
|
+
readonly message?: string;
|
|
232
|
+
}
|
|
233
|
+
/** A response that was received but could not be parsed as Enlitt's contract. */
|
|
234
|
+
export interface EnlittMalformedResponse {
|
|
235
|
+
readonly kind: "malformed_response";
|
|
236
|
+
readonly message?: string;
|
|
237
|
+
}
|
|
238
|
+
/** A caller-initiated abort of a request still in flight. */
|
|
239
|
+
export interface EnlittRequestCanceled {
|
|
240
|
+
readonly kind: "request_canceled";
|
|
241
|
+
readonly message?: string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Every shape `normalizeEnlittModelError` recognizes. `error` is typed
|
|
245
|
+
* `unknown` at the function boundary because it is handed whatever the
|
|
246
|
+
* transport or the runtime threw; this union is what it is checked against.
|
|
247
|
+
*/
|
|
248
|
+
export type EnlittNormalizationInput = EnlittHttpErrorResponse | EnlittTransportFailure | EnlittMalformedResponse | EnlittRequestCanceled;
|
|
249
|
+
/**
|
|
250
|
+
* Maps one Enlitt failure to exactly one class.
|
|
251
|
+
*
|
|
252
|
+
* `providerInvoked` is accepted for signature symmetry with callers that
|
|
253
|
+
* track it across the premium path, but every value returned is an
|
|
254
|
+
* `EnlittError`, whose `providerInvoked` is always `false`: Enlitt refuses
|
|
255
|
+
* before a provider is reached. A provider's own error is never routed
|
|
256
|
+
* through this function; the premium path rethrows it unchanged.
|
|
257
|
+
*
|
|
258
|
+
* The mapping is keyed on the stable code alone, never on HTTP status: a
|
|
259
|
+
* `429` carrying any code other than `rate_limit_exceeded` does not become
|
|
260
|
+
* `EnlittRateLimitError`.
|
|
261
|
+
*/
|
|
262
|
+
export declare function normalizeEnlittModelError(error: unknown, providerInvoked: boolean): EnlittError;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's typed error hierarchy and the single mapping from an Enlitt
|
|
3
|
+
* failure to one of its classes.
|
|
4
|
+
*
|
|
5
|
+
* This file declares no wire code list of its own. The stable codes, their
|
|
6
|
+
* OpenAI-shaped `type`, their HTTP status, their retryability, and whether
|
|
7
|
+
* they may carry `authorize_url` all come from the frozen record
|
|
8
|
+
* `@enlitt/protocol` exports — the same record the backend raises from. That
|
|
9
|
+
* is what keeps a code, and every fact about it, declared exactly once across
|
|
10
|
+
* the wire rather than asserted independently in two workspaces.
|
|
11
|
+
*
|
|
12
|
+
* It declares one small closed set of SDK-local codes, for the four failures
|
|
13
|
+
* that never reach the wire and so can have no entry in the protocol record.
|
|
14
|
+
* That set is provably disjoint from the record's codes (see
|
|
15
|
+
* `_LocalCodesDisjointFromWireCodes` below), so no reader ever has to ask
|
|
16
|
+
* which side of the wire a given code came from.
|
|
17
|
+
*
|
|
18
|
+
* No class here carries a balance, plan, service tier, period, or personal
|
|
19
|
+
* identity, and none wraps a provider's own error — a provider failure that
|
|
20
|
+
* passes through the premium path is rethrown unchanged by
|
|
21
|
+
* `normalizeEnlittModelError` and is never an instance of `EnlittError`.
|
|
22
|
+
*/
|
|
23
|
+
import { ENLITT_ERROR_CODE, type EnlittErrorCode as EnlittWireCode } from "@enlitt/protocol";
|
|
24
|
+
/**
|
|
25
|
+
* The only codes this module originates. They exist because these four
|
|
26
|
+
* failures never reach the wire: bad or missing configuration, a request
|
|
27
|
+
* that never produced an HTTP response, a response that could not be parsed,
|
|
28
|
+
* and a caller-initiated abort. All four are always non-retryable and always
|
|
29
|
+
* report `providerInvoked: false`, the same as every wire-originated code,
|
|
30
|
+
* because none of them means a provider was ever reached either.
|
|
31
|
+
*/
|
|
32
|
+
export type EnlittLocalCode = "configuration_invalid" | "transport_failed" | "malformed_response" | "request_canceled";
|
|
33
|
+
/**
|
|
34
|
+
* The bounded facts a caller may attach when constructing an error: the
|
|
35
|
+
* parsed `Retry-After`, the upstream `x-request-id`, and a navigation target.
|
|
36
|
+
* Every field is optional because most codes carry none of them — a local
|
|
37
|
+
* code carries none at all, and `authorizeUrl` is stored only where the
|
|
38
|
+
* record permits the resulting code to carry one (see `EnlittError` below).
|
|
39
|
+
*/
|
|
40
|
+
export interface EnlittErrorFacts {
|
|
41
|
+
/** Milliseconds, converted once from the wire's `Retry-After` seconds. */
|
|
42
|
+
readonly retryAfterMs?: number;
|
|
43
|
+
readonly requestId?: string;
|
|
44
|
+
readonly authorizeUrl?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Only meaningful for a code the record does not contain: the protocol
|
|
47
|
+
* classifier's status-derived answer for a code from a newer server. A code
|
|
48
|
+
* in the record always takes its `retryable` from the record instead.
|
|
49
|
+
*/
|
|
50
|
+
readonly retryable?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Any other string: a code this SDK version does not know. `string & {}`
|
|
54
|
+
* keeps editor completion for the known codes while forcing every business
|
|
55
|
+
* `switch` over `EnlittError["code"]` to carry a `default` branch. Exported as
|
|
56
|
+
* a type only; it adds no runtime value.
|
|
57
|
+
*/
|
|
58
|
+
export type EnlittUnrecognizedCode = string & {};
|
|
59
|
+
/**
|
|
60
|
+
* The base class for every Enlitt-originated failure, and the only carrier
|
|
61
|
+
* of Enlitt's stable wire codes into a caller's code.
|
|
62
|
+
*
|
|
63
|
+
* Enlitt failures with no distinct business action of their own — invalid
|
|
64
|
+
* request, unsupported capability, conflict, routing, and server failures,
|
|
65
|
+
* plus a wire code newer than this SDK knows — surface as this class
|
|
66
|
+
* directly, carrying their stable code. Every other wire code that does
|
|
67
|
+
* imply a distinct action gets its own subclass below.
|
|
68
|
+
*/
|
|
69
|
+
export declare class EnlittError extends Error {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly code: EnlittWireCode | EnlittLocalCode | EnlittUnrecognizedCode;
|
|
72
|
+
/**
|
|
73
|
+
* Always `false`. Enlitt refuses before a provider is ever reached, so no
|
|
74
|
+
* instance of this hierarchy can report otherwise — that is the one
|
|
75
|
+
* question a business needs answered before it retries or bills anything.
|
|
76
|
+
* A provider's own error is never wrapped in this class in the first
|
|
77
|
+
* place; see `normalizeEnlittModelError`.
|
|
78
|
+
*/
|
|
79
|
+
readonly providerInvoked: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Read from the frozen record for a wire code, and always `false` for a
|
|
82
|
+
* local code, which has no record entry. Never decided per instance: a
|
|
83
|
+
* refusal carries the non-retryable marker the pinned Vercel AI SDK reads,
|
|
84
|
+
* so a configured `maxRetries` cannot turn one refusal into several.
|
|
85
|
+
*/
|
|
86
|
+
readonly retryable: boolean;
|
|
87
|
+
readonly retryAfterMs?: number;
|
|
88
|
+
readonly requestId?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Present only when the record's `authorizeUrl` field for this instance's
|
|
91
|
+
* code is `"allowed"` and a caller supplied one. It is a navigation
|
|
92
|
+
* target, never a disclosure: the actual figures live only on Enlitt's own
|
|
93
|
+
* dashboard behind it.
|
|
94
|
+
*
|
|
95
|
+
* The record allows this on the four `insufficient_credits_error` codes and
|
|
96
|
+
* no others, which is what this module's spec text says. `authorizeUrl` is
|
|
97
|
+
* still read from the record rather than decided here, per this module's own
|
|
98
|
+
* rule; the record simply now agrees with the spec.
|
|
99
|
+
*/
|
|
100
|
+
readonly authorizeUrl?: string;
|
|
101
|
+
constructor(code: EnlittWireCode | EnlittLocalCode | EnlittUnrecognizedCode, message: string, facts?: EnlittErrorFacts);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Code `configuration_invalid`. Missing or invalid SDK configuration: absent
|
|
105
|
+
* business secret, browser use, invalid base URL, invalid call options, an
|
|
106
|
+
* invalid quote, or a missing session context. Thrown locally before any
|
|
107
|
+
* network call, so a misconfigured deployment fails without touching Enlitt
|
|
108
|
+
* or a provider. Audience is the business's own logs; it must never reach an
|
|
109
|
+
* end user's screen.
|
|
110
|
+
*/
|
|
111
|
+
export declare class EnlittConfigurationError extends EnlittError {
|
|
112
|
+
readonly name = "EnlittConfigurationError";
|
|
113
|
+
constructor(message: string);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Code `personal_login_required`. No usable personal session resolves for
|
|
117
|
+
* this application. It belongs to both the standard and premium paths
|
|
118
|
+
* identically, with the provider left uninvoked either way: the alternative
|
|
119
|
+
* — letting premium proceed at the business's own cost — would mean every
|
|
120
|
+
* user whose session expired silently moved their spending onto the
|
|
121
|
+
* business. Audience is the end user: the business sends them through
|
|
122
|
+
* Enlitt login or reauthorization.
|
|
123
|
+
*/
|
|
124
|
+
export declare class EnlittLoginRequiredError extends EnlittError {
|
|
125
|
+
readonly name = "EnlittLoginRequiredError";
|
|
126
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Code `spending_limit_exceeded`. One of the user's application limits
|
|
130
|
+
* refused the call. `limitRule` copies `error.enlitt.limit_rule`
|
|
131
|
+
* (`standard_per_call`, `premium_per_call`, `rate.standard`, `rate.premium`,
|
|
132
|
+
* or a rule a newer server added) so the business can explain which limit refused without
|
|
133
|
+
* learning its value. It carries no amount, because a user's ceiling is their
|
|
134
|
+
* own financial position. An unknown future rule stays a string and is
|
|
135
|
+
* rendered generically; this field is never a closed authorization decision.
|
|
136
|
+
* Audience is the end user, who raises the limit at `authorizeUrl`.
|
|
137
|
+
*/
|
|
138
|
+
export declare class EnlittLimitExceededError extends EnlittError {
|
|
139
|
+
readonly name = "EnlittLimitExceededError";
|
|
140
|
+
readonly limitRule: string;
|
|
141
|
+
constructor(message: string, limitRule: string, facts?: EnlittErrorFacts);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Codes `premium_balance_exhausted` and `standard_balance_exhausted` (and any
|
|
145
|
+
* credit-refusal code from a newer server, carried raw). The first means the
|
|
146
|
+
* matching allowance plus eligible bundles cannot cover the call; the second
|
|
147
|
+
* is the standard equivalent. `admissibleMaxChargeNanoUsd` is present only on
|
|
148
|
+
* a premium `premium_balance_exhausted`: the largest `maxCharge` the user's
|
|
149
|
+
* remaining credits would admit now, copied byte for byte. It is the protocol's
|
|
150
|
+
* single disclosed figure; the SDK never retries with it on its own. No other
|
|
151
|
+
* balance, plan, tier, or period fact is ever carried. The audience is the
|
|
152
|
+
* end user, who tops up or upgrades at `authorizeUrl`.
|
|
153
|
+
*/
|
|
154
|
+
export declare class EnlittInsufficientCreditsError extends EnlittError {
|
|
155
|
+
readonly name = "EnlittInsufficientCreditsError";
|
|
156
|
+
readonly admissibleMaxChargeNanoUsd?: string;
|
|
157
|
+
constructor(code: typeof ENLITT_ERROR_CODE.premium_balance_exhausted | typeof ENLITT_ERROR_CODE.standard_balance_exhausted | EnlittUnrecognizedCode, message: string, facts?: EnlittErrorFacts & {
|
|
158
|
+
readonly admissibleMaxChargeNanoUsd?: string;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Code `subscription_inactive`. No subscription period covers the current
|
|
163
|
+
* instant. Because every registered user holds at least the free plan, this
|
|
164
|
+
* is exceptional rather than the ordinary state of a user who has not paid:
|
|
165
|
+
* a user who never subscribed, lapsed, or canceled receives
|
|
166
|
+
* `EnlittInsufficientCreditsError` at free-plan ceilings instead. Audience is
|
|
167
|
+
* the end user, but a business seeing this at any volume should treat it as
|
|
168
|
+
* a defect signal rather than a funnel step.
|
|
169
|
+
*/
|
|
170
|
+
export declare class EnlittSubscriptionInactiveError extends EnlittError {
|
|
171
|
+
readonly name = "EnlittSubscriptionInactiveError";
|
|
172
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Code `rate_limit_exceeded`. This user has started as many standard calls as
|
|
176
|
+
* their plan allows for the current minute. Only the standard path raises it:
|
|
177
|
+
* a premium operation consumes no request budget. It is the only refusal-shaped
|
|
178
|
+
* condition that is retryable, and the only class that carries
|
|
179
|
+
* `retryAfterMs` in practice. It is emphatically not an
|
|
180
|
+
* `EnlittInsufficientCreditsError`: conflating a transient wait with an
|
|
181
|
+
* exhausted balance would tell users to buy credits they do not need. It
|
|
182
|
+
* carries no rate, remaining request count, or plan fact, because those are
|
|
183
|
+
* the user's plan details.
|
|
184
|
+
*/
|
|
185
|
+
export declare class EnlittRateLimitError extends EnlittError {
|
|
186
|
+
readonly name = "EnlittRateLimitError";
|
|
187
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Code `invalid_api_key`. The presented business key is missing, invalid, or
|
|
191
|
+
* revoked. Audience is the business's own logs; never rendered to an end
|
|
192
|
+
* user, and never softened into a direct provider call.
|
|
193
|
+
*/
|
|
194
|
+
export declare class EnlittAuthenticationError extends EnlittError {
|
|
195
|
+
readonly name = "EnlittAuthenticationError";
|
|
196
|
+
constructor(message: string, facts?: EnlittErrorFacts);
|
|
197
|
+
}
|
|
198
|
+
/** The two wire codes `EnlittAuthorizationError` carries. */
|
|
199
|
+
export type EnlittAuthorizationCode = typeof ENLITT_ERROR_CODE.insufficient_permissions | typeof ENLITT_ERROR_CODE.premium_not_enabled;
|
|
200
|
+
/**
|
|
201
|
+
* A business credential or configuration problem. Audience is the business's
|
|
202
|
+
* own logs; never rendered to an end user, and never softened into a direct
|
|
203
|
+
* provider call. Two codes:
|
|
204
|
+
*
|
|
205
|
+
* - `insufficient_permissions` (the default): the presented business key is
|
|
206
|
+
* valid but used outside its authenticated application or scope.
|
|
207
|
+
* - `premium_not_enabled` (owner decision 2026-10-25): the application's
|
|
208
|
+
* premium switch is off, or changed during the call. On a refused premium
|
|
209
|
+
* start no provider was invoked; on a refused terminal report the provider
|
|
210
|
+
* already ran and the call was not charged.
|
|
211
|
+
*/
|
|
212
|
+
export declare class EnlittAuthorizationError extends EnlittError {
|
|
213
|
+
readonly name = "EnlittAuthorizationError";
|
|
214
|
+
constructor(message: string, facts?: EnlittErrorFacts, code?: EnlittAuthorizationCode);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* An Enlitt HTTP error response, shaped for normalization: the HTTP status,
|
|
218
|
+
* the parsed JSON body (untrusted, hence `unknown`), and the two response
|
|
219
|
+
* headers normalization reads. `core/transport.ts` is the only intended
|
|
220
|
+
* producer of this shape.
|
|
221
|
+
*/
|
|
222
|
+
export interface EnlittHttpErrorResponse {
|
|
223
|
+
readonly kind: "http_error";
|
|
224
|
+
readonly status: number;
|
|
225
|
+
readonly body: unknown;
|
|
226
|
+
readonly headers: Readonly<Record<string, string | undefined>>;
|
|
227
|
+
}
|
|
228
|
+
/** A request that never produced an HTTP response at all. */
|
|
229
|
+
export interface EnlittTransportFailure {
|
|
230
|
+
readonly kind: "transport_failed";
|
|
231
|
+
readonly message?: string;
|
|
232
|
+
}
|
|
233
|
+
/** A response that was received but could not be parsed as Enlitt's contract. */
|
|
234
|
+
export interface EnlittMalformedResponse {
|
|
235
|
+
readonly kind: "malformed_response";
|
|
236
|
+
readonly message?: string;
|
|
237
|
+
}
|
|
238
|
+
/** A caller-initiated abort of a request still in flight. */
|
|
239
|
+
export interface EnlittRequestCanceled {
|
|
240
|
+
readonly kind: "request_canceled";
|
|
241
|
+
readonly message?: string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Every shape `normalizeEnlittModelError` recognizes. `error` is typed
|
|
245
|
+
* `unknown` at the function boundary because it is handed whatever the
|
|
246
|
+
* transport or the runtime threw; this union is what it is checked against.
|
|
247
|
+
*/
|
|
248
|
+
export type EnlittNormalizationInput = EnlittHttpErrorResponse | EnlittTransportFailure | EnlittMalformedResponse | EnlittRequestCanceled;
|
|
249
|
+
/**
|
|
250
|
+
* Maps one Enlitt failure to exactly one class.
|
|
251
|
+
*
|
|
252
|
+
* `providerInvoked` is accepted for signature symmetry with callers that
|
|
253
|
+
* track it across the premium path, but every value returned is an
|
|
254
|
+
* `EnlittError`, whose `providerInvoked` is always `false`: Enlitt refuses
|
|
255
|
+
* before a provider is reached. A provider's own error is never routed
|
|
256
|
+
* through this function; the premium path rethrows it unchanged.
|
|
257
|
+
*
|
|
258
|
+
* The mapping is keyed on the stable code alone, never on HTTP status: a
|
|
259
|
+
* `429` carrying any code other than `rate_limit_exceeded` does not become
|
|
260
|
+
* `EnlittRateLimitError`.
|
|
261
|
+
*/
|
|
262
|
+
export declare function normalizeEnlittModelError(error: unknown, providerInvoked: boolean): EnlittError;
|
|
263
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk/core` — the framework-neutral public entry.
|
|
3
|
+
*
|
|
4
|
+
* Everything a business needs that does not depend on a particular AI
|
|
5
|
+
* framework lives behind this entry: the session helpers, the typed error
|
|
6
|
+
* hierarchy, `withPremiumCharge()` for premium calls made outside the Vercel AI
|
|
7
|
+
* SDK, and `usage()`. A framework adapter (today `@enlitt/sdk/vercel`) maps its
|
|
8
|
+
* own types onto these functions rather than copying authentication, retries,
|
|
9
|
+
* errors, session resolution, or the premium state machine.
|
|
10
|
+
*
|
|
11
|
+
* It deliberately exports no raw transport, SSE parser, request builder,
|
|
12
|
+
* credential formatter, or Vercel type. The core source graph imports only
|
|
13
|
+
* standard Web and Node APIs, `@enlitt/protocol`, and Account's internal
|
|
14
|
+
* credential formatter, and never `@ai-sdk/provider`.
|
|
15
|
+
*
|
|
16
|
+
* Everything reachable from here may read the business secret key, so the
|
|
17
|
+
* package export map resolves this subpath's `browser` condition to
|
|
18
|
+
* `server-unavailable.ts`.
|
|
19
|
+
*/
|
|
20
|
+
export { withPremiumCharge, type PremiumChargeFunction, type PremiumChargeHandle, type PremiumTerminalFacts, type WithPremiumChargeOptions } from "./premium.cjs";
|
|
21
|
+
export { usage, type UsageAvailability } from "./usage.cjs";
|
|
22
|
+
export type { EnlittOptions, EnlittRateLimitRetryOptions } from "./transport.cjs";
|
|
23
|
+
export { ENLITT_SESSION_COOKIE_NAME, ENLITT_SESSION_HEADER_NAME, enlittSession, enlittSessionMiddleware, getEnlittSession, runWithEnlittSession, type EnlittMiddleware, type EnlittSession, type SessionMiddlewareOptions } from "./session.cjs";
|
|
24
|
+
export { EnlittAuthenticationError, EnlittAuthorizationError, EnlittConfigurationError, EnlittError, EnlittInsufficientCreditsError, EnlittLimitExceededError, EnlittLoginRequiredError, EnlittRateLimitError, EnlittSubscriptionInactiveError, type EnlittLocalCode, type EnlittUnrecognizedCode } from "./errors.cjs";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk/core` — the framework-neutral public entry.
|
|
3
|
+
*
|
|
4
|
+
* Everything a business needs that does not depend on a particular AI
|
|
5
|
+
* framework lives behind this entry: the session helpers, the typed error
|
|
6
|
+
* hierarchy, `withPremiumCharge()` for premium calls made outside the Vercel AI
|
|
7
|
+
* SDK, and `usage()`. A framework adapter (today `@enlitt/sdk/vercel`) maps its
|
|
8
|
+
* own types onto these functions rather than copying authentication, retries,
|
|
9
|
+
* errors, session resolution, or the premium state machine.
|
|
10
|
+
*
|
|
11
|
+
* It deliberately exports no raw transport, SSE parser, request builder,
|
|
12
|
+
* credential formatter, or Vercel type. The core source graph imports only
|
|
13
|
+
* standard Web and Node APIs, `@enlitt/protocol`, and Account's internal
|
|
14
|
+
* credential formatter, and never `@ai-sdk/provider`.
|
|
15
|
+
*
|
|
16
|
+
* Everything reachable from here may read the business secret key, so the
|
|
17
|
+
* package export map resolves this subpath's `browser` condition to
|
|
18
|
+
* `server-unavailable.ts`.
|
|
19
|
+
*/
|
|
20
|
+
export { withPremiumCharge, type PremiumChargeFunction, type PremiumChargeHandle, type PremiumTerminalFacts, type WithPremiumChargeOptions } from "./premium.js";
|
|
21
|
+
export { usage, type UsageAvailability } from "./usage.js";
|
|
22
|
+
export type { EnlittOptions, EnlittRateLimitRetryOptions } from "./transport.js";
|
|
23
|
+
export { ENLITT_SESSION_COOKIE_NAME, ENLITT_SESSION_HEADER_NAME, enlittSession, enlittSessionMiddleware, getEnlittSession, runWithEnlittSession, type EnlittMiddleware, type EnlittSession, type SessionMiddlewareOptions } from "./session.js";
|
|
24
|
+
export { EnlittAuthenticationError, EnlittAuthorizationError, EnlittConfigurationError, EnlittError, EnlittInsufficientCreditsError, EnlittLimitExceededError, EnlittLoginRequiredError, EnlittRateLimitError, EnlittSubscriptionInactiveError, type EnlittLocalCode, type EnlittUnrecognizedCode } from "./errors.js";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,iBAAiB,EACjB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE3D,YAAY,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,aAAa,EACb,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,EACxB,WAAW,EACX,8BAA8B,EAC9B,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAC/B,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC5B,MAAM,aAAa,CAAC"}
|