@enlitt/sdk 0.0.0-stage → 0.1.0

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 (108) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -2
  4. package/dist/browser/auth.d.cts +44 -0
  5. package/dist/browser/auth.d.ts +45 -0
  6. package/dist/browser/auth.d.ts.map +1 -0
  7. package/dist/browser.cjs +35 -0
  8. package/dist/browser.cjs.map +1 -0
  9. package/dist/browser.d.cts +12 -0
  10. package/dist/browser.d.ts +13 -0
  11. package/dist/browser.d.ts.map +1 -0
  12. package/dist/browser.js +32 -0
  13. package/dist/browser.js.map +1 -0
  14. package/dist/chunk-26SW63P5.cjs +883 -0
  15. package/dist/chunk-26SW63P5.cjs.map +1 -0
  16. package/dist/chunk-6DPBYLA5.js +855 -0
  17. package/dist/chunk-6DPBYLA5.js.map +1 -0
  18. package/dist/chunk-6OWXYBBT.cjs +146 -0
  19. package/dist/chunk-6OWXYBBT.cjs.map +1 -0
  20. package/dist/chunk-C76K6HLL.cjs +906 -0
  21. package/dist/chunk-C76K6HLL.cjs.map +1 -0
  22. package/dist/chunk-G4DTTV5E.cjs +35 -0
  23. package/dist/chunk-G4DTTV5E.cjs.map +1 -0
  24. package/dist/chunk-SFI4RLNN.js +900 -0
  25. package/dist/chunk-SFI4RLNN.js.map +1 -0
  26. package/dist/chunk-V5TCSQ7C.js +143 -0
  27. package/dist/chunk-V5TCSQ7C.js.map +1 -0
  28. package/dist/chunk-VNVMEU34.js +33 -0
  29. package/dist/chunk-VNVMEU34.js.map +1 -0
  30. package/dist/core/errors.d.cts +254 -0
  31. package/dist/core/errors.d.ts +255 -0
  32. package/dist/core/errors.d.ts.map +1 -0
  33. package/dist/core/index.d.cts +24 -0
  34. package/dist/core/index.d.ts +25 -0
  35. package/dist/core/index.d.ts.map +1 -0
  36. package/dist/core/premium.d.cts +230 -0
  37. package/dist/core/premium.d.ts +231 -0
  38. package/dist/core/premium.d.ts.map +1 -0
  39. package/dist/core/session.d.cts +107 -0
  40. package/dist/core/session.d.ts +108 -0
  41. package/dist/core/session.d.ts.map +1 -0
  42. package/dist/core/sse.d.cts +79 -0
  43. package/dist/core/sse.d.ts +80 -0
  44. package/dist/core/sse.d.ts.map +1 -0
  45. package/dist/core/transport.d.cts +223 -0
  46. package/dist/core/transport.d.ts +224 -0
  47. package/dist/core/transport.d.ts.map +1 -0
  48. package/dist/core/usage.d.cts +35 -0
  49. package/dist/core/usage.d.ts +36 -0
  50. package/dist/core/usage.d.ts.map +1 -0
  51. package/dist/core.cjs +73 -0
  52. package/dist/core.cjs.map +1 -0
  53. package/dist/core.js +4 -0
  54. package/dist/core.js.map +1 -0
  55. package/dist/index.cjs +4 -0
  56. package/dist/index.cjs.map +1 -0
  57. package/dist/index.d.cts +16 -0
  58. package/dist/index.d.ts +17 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +3 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/openai/client.d.cts +48 -0
  63. package/dist/openai/client.d.ts +49 -0
  64. package/dist/openai/client.d.ts.map +1 -0
  65. package/dist/openai/index.d.cts +1 -0
  66. package/dist/openai/index.d.ts +2 -0
  67. package/dist/openai/index.d.ts.map +1 -0
  68. package/dist/openai.cjs +479 -0
  69. package/dist/openai.cjs.map +1 -0
  70. package/dist/openai.js +473 -0
  71. package/dist/openai.js.map +1 -0
  72. package/dist/server/callback.d.cts +106 -0
  73. package/dist/server/callback.d.ts +107 -0
  74. package/dist/server/callback.d.ts.map +1 -0
  75. package/dist/server/index.d.cts +19 -0
  76. package/dist/server/index.d.ts +20 -0
  77. package/dist/server/index.d.ts.map +1 -0
  78. package/dist/server/secrets.d.cts +46 -0
  79. package/dist/server/secrets.d.ts +47 -0
  80. package/dist/server/secrets.d.ts.map +1 -0
  81. package/dist/server-unavailable.cjs +8 -0
  82. package/dist/server-unavailable.cjs.map +1 -0
  83. package/dist/server-unavailable.d.cts +10 -0
  84. package/dist/server-unavailable.d.ts +11 -0
  85. package/dist/server-unavailable.d.ts.map +1 -0
  86. package/dist/server-unavailable.js +6 -0
  87. package/dist/server-unavailable.js.map +1 -0
  88. package/dist/server.cjs +354 -0
  89. package/dist/server.cjs.map +1 -0
  90. package/dist/server.js +275 -0
  91. package/dist/server.js.map +1 -0
  92. package/dist/vercel/index.d.cts +15 -0
  93. package/dist/vercel/index.d.ts +16 -0
  94. package/dist/vercel/index.d.ts.map +1 -0
  95. package/dist/vercel/language-model.d.cts +131 -0
  96. package/dist/vercel/language-model.d.ts +132 -0
  97. package/dist/vercel/language-model.d.ts.map +1 -0
  98. package/dist/vercel/premium-language-model.d.cts +98 -0
  99. package/dist/vercel/premium-language-model.d.ts +99 -0
  100. package/dist/vercel/premium-language-model.d.ts.map +1 -0
  101. package/dist/vercel/standard-language-model.d.cts +104 -0
  102. package/dist/vercel/standard-language-model.d.ts +105 -0
  103. package/dist/vercel/standard-language-model.d.ts.map +1 -0
  104. package/dist/vercel.cjs +22 -0
  105. package/dist/vercel.cjs.map +1 -0
  106. package/dist/vercel.js +5 -0
  107. package/dist/vercel.js.map +1 -0
  108. package/package.json +129 -3
@@ -0,0 +1,254 @@
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
+ /**
199
+ * Code `insufficient_permissions`. The presented business key is valid but
200
+ * used outside its authenticated application or scope. Audience is the
201
+ * business's own logs; never rendered to an end user, and never softened
202
+ * into a direct provider call.
203
+ */
204
+ export declare class EnlittAuthorizationError extends EnlittError {
205
+ readonly name = "EnlittAuthorizationError";
206
+ constructor(message: string, facts?: EnlittErrorFacts);
207
+ }
208
+ /**
209
+ * An Enlitt HTTP error response, shaped for normalization: the HTTP status,
210
+ * the parsed JSON body (untrusted, hence `unknown`), and the two response
211
+ * headers normalization reads. `core/transport.ts` is the only intended
212
+ * producer of this shape.
213
+ */
214
+ export interface EnlittHttpErrorResponse {
215
+ readonly kind: "http_error";
216
+ readonly status: number;
217
+ readonly body: unknown;
218
+ readonly headers: Readonly<Record<string, string | undefined>>;
219
+ }
220
+ /** A request that never produced an HTTP response at all. */
221
+ export interface EnlittTransportFailure {
222
+ readonly kind: "transport_failed";
223
+ readonly message?: string;
224
+ }
225
+ /** A response that was received but could not be parsed as Enlitt's contract. */
226
+ export interface EnlittMalformedResponse {
227
+ readonly kind: "malformed_response";
228
+ readonly message?: string;
229
+ }
230
+ /** A caller-initiated abort of a request still in flight. */
231
+ export interface EnlittRequestCanceled {
232
+ readonly kind: "request_canceled";
233
+ readonly message?: string;
234
+ }
235
+ /**
236
+ * Every shape `normalizeEnlittModelError` recognizes. `error` is typed
237
+ * `unknown` at the function boundary because it is handed whatever the
238
+ * transport or the runtime threw; this union is what it is checked against.
239
+ */
240
+ export type EnlittNormalizationInput = EnlittHttpErrorResponse | EnlittTransportFailure | EnlittMalformedResponse | EnlittRequestCanceled;
241
+ /**
242
+ * Maps one Enlitt failure to exactly one class.
243
+ *
244
+ * `providerInvoked` is accepted for signature symmetry with callers that
245
+ * track it across the premium path, but every value returned is an
246
+ * `EnlittError`, whose `providerInvoked` is always `false`: Enlitt refuses
247
+ * before a provider is reached. A provider's own error is never routed
248
+ * through this function; the premium path rethrows it unchanged.
249
+ *
250
+ * The mapping is keyed on the stable code alone, never on HTTP status: a
251
+ * `429` carrying any code other than `rate_limit_exceeded` does not become
252
+ * `EnlittRateLimitError`.
253
+ */
254
+ export declare function normalizeEnlittModelError(error: unknown, providerInvoked: boolean): EnlittError;
@@ -0,0 +1,255 @@
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
+ /**
199
+ * Code `insufficient_permissions`. The presented business key is valid but
200
+ * used outside its authenticated application or scope. Audience is the
201
+ * business's own logs; never rendered to an end user, and never softened
202
+ * into a direct provider call.
203
+ */
204
+ export declare class EnlittAuthorizationError extends EnlittError {
205
+ readonly name = "EnlittAuthorizationError";
206
+ constructor(message: string, facts?: EnlittErrorFacts);
207
+ }
208
+ /**
209
+ * An Enlitt HTTP error response, shaped for normalization: the HTTP status,
210
+ * the parsed JSON body (untrusted, hence `unknown`), and the two response
211
+ * headers normalization reads. `core/transport.ts` is the only intended
212
+ * producer of this shape.
213
+ */
214
+ export interface EnlittHttpErrorResponse {
215
+ readonly kind: "http_error";
216
+ readonly status: number;
217
+ readonly body: unknown;
218
+ readonly headers: Readonly<Record<string, string | undefined>>;
219
+ }
220
+ /** A request that never produced an HTTP response at all. */
221
+ export interface EnlittTransportFailure {
222
+ readonly kind: "transport_failed";
223
+ readonly message?: string;
224
+ }
225
+ /** A response that was received but could not be parsed as Enlitt's contract. */
226
+ export interface EnlittMalformedResponse {
227
+ readonly kind: "malformed_response";
228
+ readonly message?: string;
229
+ }
230
+ /** A caller-initiated abort of a request still in flight. */
231
+ export interface EnlittRequestCanceled {
232
+ readonly kind: "request_canceled";
233
+ readonly message?: string;
234
+ }
235
+ /**
236
+ * Every shape `normalizeEnlittModelError` recognizes. `error` is typed
237
+ * `unknown` at the function boundary because it is handed whatever the
238
+ * transport or the runtime threw; this union is what it is checked against.
239
+ */
240
+ export type EnlittNormalizationInput = EnlittHttpErrorResponse | EnlittTransportFailure | EnlittMalformedResponse | EnlittRequestCanceled;
241
+ /**
242
+ * Maps one Enlitt failure to exactly one class.
243
+ *
244
+ * `providerInvoked` is accepted for signature symmetry with callers that
245
+ * track it across the premium path, but every value returned is an
246
+ * `EnlittError`, whose `providerInvoked` is always `false`: Enlitt refuses
247
+ * before a provider is reached. A provider's own error is never routed
248
+ * through this function; the premium path rethrows it unchanged.
249
+ *
250
+ * The mapping is keyed on the stable code alone, never on HTTP status: a
251
+ * `429` carrying any code other than `rate_limit_exceeded` does not become
252
+ * `EnlittRateLimitError`.
253
+ */
254
+ export declare function normalizeEnlittModelError(error: unknown, providerInvoked: boolean): EnlittError;
255
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAEL,iBAAiB,EAMjB,KAAK,eAAe,IAAI,cAAc,EACvC,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GACvB,uBAAuB,GACvB,kBAAkB,GAClB,oBAAoB,GACpB,kBAAkB,CAAC;AAYvB;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG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;CAC3B;AAED,iFAAiF;AACjF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,6DAA6D;AAC7D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAChC,uBAAuB,GACvB,sBAAsB,GACtB,uBAAuB,GACvB,qBAAqB,CAAC;AAgF1B;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,GAAG,WAAW,CA0B/F"}
@@ -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, 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, 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,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"}