@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,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The module's single authenticated exit to Enlitt.
|
|
3
|
+
*
|
|
4
|
+
* `specs/SDK-side routing.md` gives this file three jobs that must live in
|
|
5
|
+
* exactly one place: the definition of the internal client
|
|
6
|
+
* (`InternalEnlittClient`, built once per factory call by
|
|
7
|
+
* `createInternalClient()`), the one place a personal session is resolved
|
|
8
|
+
* (`InternalEnlittClient.resolveSession`), and the one function that ever
|
|
9
|
+
* issues an HTTP request to Enlitt (`requestEnlitt()`). Both the standard and
|
|
10
|
+
* premium model files call through this file rather than `fetch` directly, so
|
|
11
|
+
* every header, every safety check, and every retry the spec requires exists
|
|
12
|
+
* exactly once instead of once per model.
|
|
13
|
+
*
|
|
14
|
+
* It owns exactly two internal retries and no others: the bounded, jittered
|
|
15
|
+
* wait that absorbs `rate_limit_exceeded` (inside `requestEnlitt()` itself,
|
|
16
|
+
* because it applies uniformly to every request this module sends), and a
|
|
17
|
+
* bounded transient retry of a premium terminal report under one unchanged
|
|
18
|
+
* `report_id`/`Idempotency-Key` (`reportEnlittPremiumTerminal()`, layered on
|
|
19
|
+
* top of `requestEnlitt()` because it applies to exactly one call shape and
|
|
20
|
+
* must never leak onto a preflight, a standard call, or a refusal). Every
|
|
21
|
+
* other failure — every refusal, every conflict, every `4xx` other than `429
|
|
22
|
+
* rate_limit_exceeded` — is normalized and thrown once, never retried here.
|
|
23
|
+
*
|
|
24
|
+
* It never accepts a personal identity as a caller-supplied parameter: the
|
|
25
|
+
* only personal value that ever leaves this file is the opaque token
|
|
26
|
+
* `client.resolveSession()` returns, and no argument, option, or request body
|
|
27
|
+
* field can supply or override it. It never logs or returns that token,
|
|
28
|
+
* prompt content, or a raw provider error, and it never runs in a browser —
|
|
29
|
+
* it is reachable only through `@enlitt/sdk/server`, which the package export
|
|
30
|
+
* map keeps out of the `browser` condition.
|
|
31
|
+
*/
|
|
32
|
+
import { EnlittError } from "./errors.js";
|
|
33
|
+
import { type EnlittSession } from "./session.js";
|
|
34
|
+
/**
|
|
35
|
+
* The SDK's own version, sent as `X-Enlitt-SDK-Version` so Enlitt's own logs
|
|
36
|
+
* can tell which client behavior produced a given request without the header
|
|
37
|
+
* carrying anything about the business or the user.
|
|
38
|
+
*
|
|
39
|
+
* A literal rather than a `package.json` import: this package ships as both
|
|
40
|
+
* ESM and CJS, its `tsup` build does not embed the manifest, and a JSON
|
|
41
|
+
* import here would tie a request-time value to a file layout assumption
|
|
42
|
+
* this module has no other reason to make. It must be bumped by hand
|
|
43
|
+
* alongside `package.json`'s `version` field.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SDK_VERSION = "0.1.1";
|
|
46
|
+
/**
|
|
47
|
+
* Caller-supplied tuning for the rate-limit wait. Every field is optional
|
|
48
|
+
* because `createInternalClient()` folds it over the SDK's own defaults
|
|
49
|
+
* exactly once, at construction, which is what lets every later read of
|
|
50
|
+
* `client.rateLimit` assume every field but `onRateLimit` is present.
|
|
51
|
+
*/
|
|
52
|
+
export interface EnlittRateLimitRetryOptions {
|
|
53
|
+
/** Upper bound on attempts, including the first (minimum 1). Default {@link DEFAULT_RATE_LIMIT_MAX_ATTEMPTS}. */
|
|
54
|
+
readonly maxAttempts?: number;
|
|
55
|
+
/** Upper bound on total time spent waiting, measured from the first refusal. Default {@link DEFAULT_RATE_LIMIT_MAX_TOTAL_WAIT_MS}. */
|
|
56
|
+
readonly maxTotalWaitMs?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Invoked once per wait, with the attempt number (1-based) about to be
|
|
59
|
+
* slept and the jittered delay in milliseconds. The only way a business
|
|
60
|
+
* observes a rate-limit wait without this module disclosing a plan fact.
|
|
61
|
+
*/
|
|
62
|
+
readonly onRateLimit?: (attempt: number, delayMs: number) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Constructor options for `createInternalClient()`.
|
|
66
|
+
*
|
|
67
|
+
* `secretKey` and `baseUrl` are exactly what `resolveBusinessAuthorizationHeader()`
|
|
68
|
+
* and the HTTPS assertion need and nothing more; neither this type nor the
|
|
69
|
+
* client it builds ever carries a personal identity, because the only
|
|
70
|
+
* personal value the transport ever sends is the token `resolveSession()`
|
|
71
|
+
* (built from `session`, or from the ambient context) produces at request
|
|
72
|
+
* time.
|
|
73
|
+
*/
|
|
74
|
+
export interface EnlittOptions {
|
|
75
|
+
/** Forwarded to `resolveBusinessAuthorizationHeader()` unchanged. */
|
|
76
|
+
readonly secretKey?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Enlitt's base URL. Resolves from this option, then `ENLITT_BASE_URL`, then
|
|
79
|
+
* the deployed Enlitt origin compiled into the package. Must be `https:`, or
|
|
80
|
+
* `http:` on a local host. Parsed and validated once, at construction.
|
|
81
|
+
*/
|
|
82
|
+
readonly baseUrl?: string;
|
|
83
|
+
/**
|
|
84
|
+
* An explicit session, for a caller that cannot rely on the ambient
|
|
85
|
+
* `AsyncLocalStorage` context — a background job, or a framework
|
|
86
|
+
* `enlittSessionMiddleware()` cannot wrap. When absent, every call resolves
|
|
87
|
+
* the session from `getEnlittSession()` instead.
|
|
88
|
+
*/
|
|
89
|
+
readonly session?: EnlittSession;
|
|
90
|
+
readonly rateLimit?: EnlittRateLimitRetryOptions;
|
|
91
|
+
/**
|
|
92
|
+
* Observes a failure `reportEnlittPremiumTerminal()` could not recover
|
|
93
|
+
* from after exhausting its bounded retry. There is no caller left to
|
|
94
|
+
* return the error to by the time this fires — the provider call this
|
|
95
|
+
* report describes has already completed — so this hook is the only way a
|
|
96
|
+
* business ever learns a terminal report did not land.
|
|
97
|
+
*/
|
|
98
|
+
readonly onTerminalReportError?: (error: EnlittError) => void;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The internal client every request in this module is built from.
|
|
102
|
+
*
|
|
103
|
+
* Constructed once per factory call from the business's resolved secret and
|
|
104
|
+
* the deployed environment, and never held as nullable: holding a client at
|
|
105
|
+
* all is what makes a call managed, so there is no code path in this package
|
|
106
|
+
* that represents "no Enlitt configuration" as a null or optional client
|
|
107
|
+
* instead of failing at construction.
|
|
108
|
+
*/
|
|
109
|
+
export interface InternalEnlittClient {
|
|
110
|
+
readonly baseUrl: string;
|
|
111
|
+
/** The full `Authorization` header value, e.g. `Bearer sk_...`. Never logged or returned. */
|
|
112
|
+
readonly businessAuthorization: string;
|
|
113
|
+
readonly sdkVersion: string;
|
|
114
|
+
/**
|
|
115
|
+
* The module's single session resolution. Returns the explicit
|
|
116
|
+
* `EnlittOptions.session` when one was given; otherwise defers to
|
|
117
|
+
* `getEnlittSession()`, which itself distinguishes "no middleware
|
|
118
|
+
* installed" (`EnlittConfigurationError`) from "signed out" (`null`,
|
|
119
|
+
* raised here as `EnlittLoginRequiredError` with `providerInvoked: false`).
|
|
120
|
+
* Both model files call this indirectly through `requestEnlitt()` rather
|
|
121
|
+
* than resolving a session themselves, which is what keeps the three
|
|
122
|
+
* outcomes from drifting apart between the standard and premium paths.
|
|
123
|
+
*/
|
|
124
|
+
readonly resolveSession: () => EnlittSession;
|
|
125
|
+
readonly rateLimit: Required<Omit<EnlittRateLimitRetryOptions, "onRateLimit">> & Pick<EnlittRateLimitRetryOptions, "onRateLimit">;
|
|
126
|
+
readonly onTerminalReportError?: (error: EnlittError) => void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Builds the internal client from a factory call's resolved options.
|
|
130
|
+
*
|
|
131
|
+
* Resolves the business authorization header eagerly (through
|
|
132
|
+
* `resolveBusinessAuthorizationHeader()`, the only path to that secret) so a
|
|
133
|
+
* missing or unusable key fails at construction, before any network call and
|
|
134
|
+
* before a provider is ever at risk of running unaccounted. Folds
|
|
135
|
+
* `rateLimit` over the SDK's defaults exactly once here, so no per-request
|
|
136
|
+
* code has to treat any field but `onRateLimit` as possibly absent.
|
|
137
|
+
*/
|
|
138
|
+
export declare function createInternalClient(options: EnlittOptions): InternalEnlittClient;
|
|
139
|
+
/** One request this module knows how to issue. */
|
|
140
|
+
export interface EnlittRequestInit {
|
|
141
|
+
readonly path: string;
|
|
142
|
+
/** `POST` unless a read endpoint (`GET /v1/enlitt/usage`) says otherwise. */
|
|
143
|
+
readonly method?: "POST" | "GET";
|
|
144
|
+
/** Ignored for `GET`, which has no body. */
|
|
145
|
+
readonly body?: unknown;
|
|
146
|
+
/**
|
|
147
|
+
* Sent as `Idempotency-Key` (and, for a terminal report, equals the body's
|
|
148
|
+
* own `report_id`). Required for `POST`; a `GET` sends no `Idempotency-Key`,
|
|
149
|
+
* because `PROTOCOLS.md` forbids one on a route that does not deduplicate.
|
|
150
|
+
*/
|
|
151
|
+
readonly callId?: string;
|
|
152
|
+
readonly accept: "application/json" | "text/event-stream";
|
|
153
|
+
readonly signal?: AbortSignal;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Issues one `POST` to `client.baseUrl + init.path` carrying every header the
|
|
157
|
+
* protocol requires and no other identity-bearing header, and returns the
|
|
158
|
+
* successful `Response` unread so a caller that needs a stream can consume
|
|
159
|
+
* it incrementally.
|
|
160
|
+
*
|
|
161
|
+
* This is the only function in the package that calls `fetch()` against
|
|
162
|
+
* Enlitt. Every safety property the spec requires — HTTPS, no redirects,
|
|
163
|
+
* bounded response size, normalization of every failure, and the
|
|
164
|
+
* `rate_limit_exceeded` wait — lives here so no call site can accidentally
|
|
165
|
+
* skip one.
|
|
166
|
+
*/
|
|
167
|
+
export declare function requestEnlitt(client: InternalEnlittClient, init: EnlittRequestInit): Promise<Response>;
|
|
168
|
+
/**
|
|
169
|
+
* Retries a premium terminal report a bounded number of times on a
|
|
170
|
+
* transient failure, resending the identical `init` — the same body (and so
|
|
171
|
+
* the same `report_id`) and the same `Idempotency-Key` — on every attempt,
|
|
172
|
+
* which is what makes the retry safe: Enlitt's own idempotency on that key
|
|
173
|
+
* turns a duplicate send into a replay rather than a second report.
|
|
174
|
+
*
|
|
175
|
+
* Only a failure with no distinct business action of its own is treated as
|
|
176
|
+
* transient: a transport failure that never produced a response, or one of
|
|
177
|
+
* the three retryable server-side wire codes (`server_error`,
|
|
178
|
+
* `provider_error`, `no_capable_route`). A refusal, a conflict, or an
|
|
179
|
+
* exhausted `rate_limit_exceeded` wait (already retried once, inside
|
|
180
|
+
* `requestEnlitt()`) is never retried again here — retrying a refusal a
|
|
181
|
+
* second time under a different name is exactly what the spec forbids.
|
|
182
|
+
*
|
|
183
|
+
* Exhausting the bound reports the last error to `client.onTerminalReportError`
|
|
184
|
+
* and rethrows it, rather than swallowing it: the hook exists because the
|
|
185
|
+
* provider call this report describes has already finished and there is no
|
|
186
|
+
* result left to withhold from a caller, not because the failure stops
|
|
187
|
+
* mattering.
|
|
188
|
+
*/
|
|
189
|
+
export declare function reportEnlittPremiumTerminal(client: InternalEnlittClient, init: EnlittRequestInit): Promise<Response>;
|
|
190
|
+
/**
|
|
191
|
+
* True for an unfollowed redirect under `redirect: "manual"`: a `3xx` status
|
|
192
|
+
* (server runtimes such as Workers and Node) or an `opaqueredirect` response
|
|
193
|
+
* with status `0` (browsers, which hide the redirect's details).
|
|
194
|
+
*/
|
|
195
|
+
export declare function isRedirectResponse(response: Response): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* The `transport_failed` error for a refused redirect. The body is cancelled
|
|
198
|
+
* unread so the connection is released; nothing from it is used.
|
|
199
|
+
*/
|
|
200
|
+
export declare function redirectRefused(response: Response): EnlittError;
|
|
201
|
+
/**
|
|
202
|
+
* Reads a successful response's body as JSON, bounded by the same body-size
|
|
203
|
+
* limit every other read in this file uses. An oversized body or one that is
|
|
204
|
+
* not valid JSON is a `malformed_response` `EnlittError`, never a raw parser
|
|
205
|
+
* exception. Every JSON-bodied Enlitt response (begin, terminal report, usage,
|
|
206
|
+
* non-streaming standard response) is read through here, so no caller buffers
|
|
207
|
+
* an unbounded body or parses JSON on its own.
|
|
208
|
+
*/
|
|
209
|
+
export declare function readEnlittJson(response: Response): Promise<unknown>;
|
|
210
|
+
/**
|
|
211
|
+
* HTTPS is required outside local development. `http:` is accepted only for
|
|
212
|
+
* the three hosts a developer's own machine can present as, and there is no
|
|
213
|
+
* environment flag that relaxes this — a business misconfiguring its own
|
|
214
|
+
* deployed base URL must fail loudly rather than send its business and
|
|
215
|
+
* personal credentials in the clear.
|
|
216
|
+
*
|
|
217
|
+
* Exported (in addition to being used per-request by `requestEnlitt()`) so
|
|
218
|
+
* `language-model.ts` can run the identical check once, at `enlitt()`
|
|
219
|
+
* construction, against the resolved `baseUrl` before any request is made —
|
|
220
|
+
* the spec requires base URL validation to happen at construction, not per
|
|
221
|
+
* call, and duplicating this rule there would let the two copies drift.
|
|
222
|
+
*/
|
|
223
|
+
export declare function assertHttps(baseUrl: string): void;
|
|
224
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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GAAG,OAAO,CAAC,OAAO,CAAC,CAgBzE;AAiCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAYjD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The framework-neutral `usage()` helper over `GET /v1/enlitt/usage`.
|
|
3
|
+
*
|
|
4
|
+
* It builds the same internal client as `withPremiumCharge()`, resolves the
|
|
5
|
+
* same personal session (explicit, or ambient from the middleware), performs
|
|
6
|
+
* one authenticated read, and tolerant-parses the response. It returns the two
|
|
7
|
+
* integer percentages and the canonical NANOUSD caps unchanged: no conversion,
|
|
8
|
+
* caching, retry beyond transport policy, or admission inference.
|
|
9
|
+
*
|
|
10
|
+
* The result is advisory. A concurrent call can consume capacity before the
|
|
11
|
+
* caller acts, so it is guidance and never a reservation or quote. It exposes
|
|
12
|
+
* no credit unit, plan, balance, period, rate tuple, or user identity; the wire
|
|
13
|
+
* response carries none and this file adds none.
|
|
14
|
+
*/
|
|
15
|
+
import { type EnlittOptions } from "./transport.cjs";
|
|
16
|
+
/** One pool's availability, exactly as the wire reports it. */
|
|
17
|
+
export interface UsageAvailability {
|
|
18
|
+
/** An integer from 0 through 100: the floor of the share of this pool still available. */
|
|
19
|
+
readonly remainingPercent: number;
|
|
20
|
+
/** The most this application could reserve for one call right now, as a canonical NANOUSD string. */
|
|
21
|
+
readonly limitCapNanoUsd: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads the signed-in user's current availability for this application.
|
|
25
|
+
*
|
|
26
|
+
* A missing ambient context raises `EnlittConfigurationError`, a context with
|
|
27
|
+
* no session raises `EnlittLoginRequiredError`, and every refusal (including an
|
|
28
|
+
* unknown error code from a newer server) goes through the shared normalizer,
|
|
29
|
+
* exactly as for a model call. It never raises `spending_limit_exceeded`: the
|
|
30
|
+
* read starts no request-rate budget and reserves nothing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function usage(options?: EnlittOptions): Promise<{
|
|
33
|
+
readonly standard: UsageAvailability;
|
|
34
|
+
readonly premium: UsageAvailability;
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The framework-neutral `usage()` helper over `GET /v1/enlitt/usage`.
|
|
3
|
+
*
|
|
4
|
+
* It builds the same internal client as `withPremiumCharge()`, resolves the
|
|
5
|
+
* same personal session (explicit, or ambient from the middleware), performs
|
|
6
|
+
* one authenticated read, and tolerant-parses the response. It returns the two
|
|
7
|
+
* integer percentages and the canonical NANOUSD caps unchanged: no conversion,
|
|
8
|
+
* caching, retry beyond transport policy, or admission inference.
|
|
9
|
+
*
|
|
10
|
+
* The result is advisory. A concurrent call can consume capacity before the
|
|
11
|
+
* caller acts, so it is guidance and never a reservation or quote. It exposes
|
|
12
|
+
* no credit unit, plan, balance, period, rate tuple, or user identity; the wire
|
|
13
|
+
* response carries none and this file adds none.
|
|
14
|
+
*/
|
|
15
|
+
import { type EnlittOptions } from "./transport.js";
|
|
16
|
+
/** One pool's availability, exactly as the wire reports it. */
|
|
17
|
+
export interface UsageAvailability {
|
|
18
|
+
/** An integer from 0 through 100: the floor of the share of this pool still available. */
|
|
19
|
+
readonly remainingPercent: number;
|
|
20
|
+
/** The most this application could reserve for one call right now, as a canonical NANOUSD string. */
|
|
21
|
+
readonly limitCapNanoUsd: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads the signed-in user's current availability for this application.
|
|
25
|
+
*
|
|
26
|
+
* A missing ambient context raises `EnlittConfigurationError`, a context with
|
|
27
|
+
* no session raises `EnlittLoginRequiredError`, and every refusal (including an
|
|
28
|
+
* unknown error code from a newer server) goes through the shared normalizer,
|
|
29
|
+
* exactly as for a model call. It never raises `spending_limit_exceeded`: the
|
|
30
|
+
* read starts no request-rate budget and reserves nothing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function usage(options?: EnlittOptions): Promise<{
|
|
33
|
+
readonly standard: UsageAvailability;
|
|
34
|
+
readonly premium: UsageAvailability;
|
|
35
|
+
}>;
|
|
36
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/core/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAuD,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGzG,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,qGAAqG;IACrG,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAKD;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC;IAAE,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;CAAE,CAAC,CA6B/I"}
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkYPA4R65T_cjs = require('./chunk-YPA4R65T.cjs');
|
|
4
|
+
var chunkPPOUNWNA_cjs = require('./chunk-PPOUNWNA.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "usage", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkYPA4R65T_cjs.usage; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ENLITT_SESSION_COOKIE_NAME", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkPPOUNWNA_cjs.ENLITT_SESSION_COOKIE_NAME; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "ENLITT_SESSION_HEADER_NAME", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkPPOUNWNA_cjs.ENLITT_SESSION_HEADER_NAME; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "EnlittAuthenticationError", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittAuthenticationError; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "EnlittAuthorizationError", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittAuthorizationError; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "EnlittConfigurationError", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittConfigurationError; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "EnlittError", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittError; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "EnlittInsufficientCreditsError", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittInsufficientCreditsError; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "EnlittLimitExceededError", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittLimitExceededError; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "EnlittLoginRequiredError", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittLoginRequiredError; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "EnlittRateLimitError", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittRateLimitError; }
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "EnlittSubscriptionInactiveError", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () { return chunkPPOUNWNA_cjs.EnlittSubscriptionInactiveError; }
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "enlittSession", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return chunkPPOUNWNA_cjs.enlittSession; }
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "enlittSessionMiddleware", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return chunkPPOUNWNA_cjs.enlittSessionMiddleware; }
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "getEnlittSession", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return chunkPPOUNWNA_cjs.getEnlittSession; }
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "runWithEnlittSession", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () { return chunkPPOUNWNA_cjs.runWithEnlittSession; }
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "withPremiumCharge", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () { return chunkPPOUNWNA_cjs.withPremiumCharge; }
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=core.cjs.map
|
|
77
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"core.cjs"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { usage } from './chunk-NI6WH5FI.js';
|
|
2
|
+
export { ENLITT_SESSION_COOKIE_NAME, ENLITT_SESSION_HEADER_NAME, EnlittAuthenticationError, EnlittAuthorizationError, EnlittConfigurationError, EnlittError, EnlittInsufficientCreditsError, EnlittLimitExceededError, EnlittLoginRequiredError, EnlittRateLimitError, EnlittSubscriptionInactiveError, enlittSession, enlittSessionMiddleware, getEnlittSession, runWithEnlittSession, withPremiumCharge } from './chunk-O6ASIA3X.js';
|
|
3
|
+
//# sourceMappingURL=core.js.map
|
|
4
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"core.js"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk` — the isomorphic entry point.
|
|
3
|
+
*
|
|
4
|
+
* Only declarations that are safe in both a browser bundle and a server
|
|
5
|
+
* runtime belong here. Anything that reads a secret lives behind
|
|
6
|
+
* `@enlitt/sdk/server`; anything that touches `window` lives behind
|
|
7
|
+
* `@enlitt/sdk/browser`. `docs/ARCHITECTURE.md` keeps that split, and the
|
|
8
|
+
* `browser` export condition in `package.json` enforces it at bundle time.
|
|
9
|
+
*
|
|
10
|
+
* Account contributes nothing here on purpose. Its browser half is a pair of
|
|
11
|
+
* navigations that only make sense in a browser, and its server half handles
|
|
12
|
+
* the business secret; a session type exported from here would be the first
|
|
13
|
+
* step towards a browser-readable session, which is exactly what the HttpOnly
|
|
14
|
+
* cookie exists to prevent.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@enlitt/sdk` — the isomorphic entry point.
|
|
3
|
+
*
|
|
4
|
+
* Only declarations that are safe in both a browser bundle and a server
|
|
5
|
+
* runtime belong here. Anything that reads a secret lives behind
|
|
6
|
+
* `@enlitt/sdk/server`; anything that touches `window` lives behind
|
|
7
|
+
* `@enlitt/sdk/browser`. `docs/ARCHITECTURE.md` keeps that split, and the
|
|
8
|
+
* `browser` export condition in `package.json` enforces it at bundle time.
|
|
9
|
+
*
|
|
10
|
+
* Account contributes nothing here on purpose. Its browser half is a pair of
|
|
11
|
+
* navigations that only make sense in a browser, and its server half handles
|
|
12
|
+
* the business secret; a session type exported from here would be the first
|
|
13
|
+
* step towards a browser-readable session, which is exactly what the HttpOnly
|
|
14
|
+
* cookie exists to prevent.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Thin OpenAI Responses adapter over Enlitt's existing standard transport and premium lifecycle. */
|
|
2
|
+
import { ENLITT_STANDARD_MODEL } from "@enlitt/protocol";
|
|
3
|
+
import type OpenAI from "openai";
|
|
4
|
+
import type { Response as OpenAIResponseResult, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, ResponseStreamEvent, ResponseUsage } from "openai/resources/responses/responses";
|
|
5
|
+
import { type EnlittOptions, type InternalEnlittClient } from "../core/transport.cjs";
|
|
6
|
+
import { type EnlittOpenAIAudio, type EnlittOpenAIImages } from "./media.cjs";
|
|
7
|
+
export { ENLITT_STANDARD_MODEL };
|
|
8
|
+
export interface EnlittOpenAIRequestOptions {
|
|
9
|
+
readonly signal?: AbortSignal;
|
|
10
|
+
readonly timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface EnlittOpenAICallOptions {
|
|
13
|
+
readonly idempotencyKey?: string;
|
|
14
|
+
readonly maxCharge?: string;
|
|
15
|
+
readonly price?: EnlittOpenAIPrice;
|
|
16
|
+
readonly reportingDeadlineMs?: number;
|
|
17
|
+
readonly metadata?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export interface OpenAIPremiumPriceContext {
|
|
20
|
+
readonly status: "completed" | "canceled";
|
|
21
|
+
readonly response?: OpenAIResponseResult;
|
|
22
|
+
readonly events?: readonly ResponseStreamEvent[];
|
|
23
|
+
readonly usage?: ResponseUsage;
|
|
24
|
+
readonly startedAt: Date;
|
|
25
|
+
readonly endedAt: Date;
|
|
26
|
+
readonly durationMs: number;
|
|
27
|
+
readonly timeToFirstTokenMs?: number;
|
|
28
|
+
readonly effectiveMaxChargeNanoUsd: string;
|
|
29
|
+
}
|
|
30
|
+
export type EnlittOpenAIPrice = string | ((context: OpenAIPremiumPriceContext) => string | Promise<string>);
|
|
31
|
+
export type EnlittOpenAIResponseCreateParamsNonStreaming = ResponseCreateParamsNonStreaming & {
|
|
32
|
+
readonly enlitt?: EnlittOpenAICallOptions;
|
|
33
|
+
};
|
|
34
|
+
export type EnlittOpenAIResponseCreateParamsStreaming = ResponseCreateParamsStreaming & {
|
|
35
|
+
readonly enlitt?: EnlittOpenAICallOptions;
|
|
36
|
+
};
|
|
37
|
+
export type EnlittOpenAIStream = AsyncIterable<ResponseStreamEvent>;
|
|
38
|
+
export interface EnlittOpenAIClient {
|
|
39
|
+
/** Premium-only image generation; see `media.ts`. */
|
|
40
|
+
readonly images: EnlittOpenAIImages;
|
|
41
|
+
/** Premium-only speech and transcription; see `media.ts`. */
|
|
42
|
+
readonly audio: EnlittOpenAIAudio;
|
|
43
|
+
readonly responses: {
|
|
44
|
+
create(body: EnlittOpenAIResponseCreateParamsNonStreaming, options?: EnlittOpenAIRequestOptions): Promise<OpenAIResponseResult>;
|
|
45
|
+
create(body: EnlittOpenAIResponseCreateParamsStreaming, options?: EnlittOpenAIRequestOptions): Promise<EnlittOpenAIStream>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export declare function enlitt(options?: EnlittOptions): EnlittOpenAIClient;
|
|
49
|
+
export declare function enlitt(client: OpenAI, options?: EnlittOptions): EnlittOpenAIClient;
|
|
50
|
+
export declare function validateRequestOptions(options: EnlittOpenAIRequestOptions | undefined): void;
|
|
51
|
+
/** Validates `body.enlitt` under the shared call-option rules; also used by `media.ts`. */
|
|
52
|
+
export declare function readCallOptions(body: {
|
|
53
|
+
enlitt?: EnlittOpenAICallOptions;
|
|
54
|
+
}, mode: "standard" | "premium"): {
|
|
55
|
+
idempotencyKey: string;
|
|
56
|
+
metadata: Record<string, string> | undefined;
|
|
57
|
+
maxCharge?: never;
|
|
58
|
+
price?: never;
|
|
59
|
+
reportingDeadlineMs?: never;
|
|
60
|
+
} | {
|
|
61
|
+
idempotencyKey: string;
|
|
62
|
+
metadata: Record<string, string> | undefined;
|
|
63
|
+
maxCharge: string;
|
|
64
|
+
price: string | ((context: OpenAIPremiumPriceContext) => string | Promise<string>) | undefined;
|
|
65
|
+
reportingDeadlineMs: number | undefined;
|
|
66
|
+
};
|
|
67
|
+
/** The one price rule for this adapter, generic over the context so `media.ts` shares it. */
|
|
68
|
+
export declare function evaluatePrice<Context = OpenAIPremiumPriceContext>(client: InternalEnlittClient, price: string | ((context: Context) => string | Promise<string>) | undefined, context: Context): Promise<string>;
|
|
69
|
+
export declare function perToken(rates: {
|
|
70
|
+
readonly input: string;
|
|
71
|
+
readonly output: string;
|
|
72
|
+
}): (context: OpenAIPremiumPriceContext) => string;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Thin OpenAI Responses adapter over Enlitt's existing standard transport and premium lifecycle. */
|
|
2
|
+
import { ENLITT_STANDARD_MODEL } from "@enlitt/protocol";
|
|
3
|
+
import type OpenAI from "openai";
|
|
4
|
+
import type { Response as OpenAIResponseResult, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, ResponseStreamEvent, ResponseUsage } from "openai/resources/responses/responses";
|
|
5
|
+
import { type EnlittOptions, type InternalEnlittClient } from "../core/transport.js";
|
|
6
|
+
import { type EnlittOpenAIAudio, type EnlittOpenAIImages } from "./media.js";
|
|
7
|
+
export { ENLITT_STANDARD_MODEL };
|
|
8
|
+
export interface EnlittOpenAIRequestOptions {
|
|
9
|
+
readonly signal?: AbortSignal;
|
|
10
|
+
readonly timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface EnlittOpenAICallOptions {
|
|
13
|
+
readonly idempotencyKey?: string;
|
|
14
|
+
readonly maxCharge?: string;
|
|
15
|
+
readonly price?: EnlittOpenAIPrice;
|
|
16
|
+
readonly reportingDeadlineMs?: number;
|
|
17
|
+
readonly metadata?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export interface OpenAIPremiumPriceContext {
|
|
20
|
+
readonly status: "completed" | "canceled";
|
|
21
|
+
readonly response?: OpenAIResponseResult;
|
|
22
|
+
readonly events?: readonly ResponseStreamEvent[];
|
|
23
|
+
readonly usage?: ResponseUsage;
|
|
24
|
+
readonly startedAt: Date;
|
|
25
|
+
readonly endedAt: Date;
|
|
26
|
+
readonly durationMs: number;
|
|
27
|
+
readonly timeToFirstTokenMs?: number;
|
|
28
|
+
readonly effectiveMaxChargeNanoUsd: string;
|
|
29
|
+
}
|
|
30
|
+
export type EnlittOpenAIPrice = string | ((context: OpenAIPremiumPriceContext) => string | Promise<string>);
|
|
31
|
+
export type EnlittOpenAIResponseCreateParamsNonStreaming = ResponseCreateParamsNonStreaming & {
|
|
32
|
+
readonly enlitt?: EnlittOpenAICallOptions;
|
|
33
|
+
};
|
|
34
|
+
export type EnlittOpenAIResponseCreateParamsStreaming = ResponseCreateParamsStreaming & {
|
|
35
|
+
readonly enlitt?: EnlittOpenAICallOptions;
|
|
36
|
+
};
|
|
37
|
+
export type EnlittOpenAIStream = AsyncIterable<ResponseStreamEvent>;
|
|
38
|
+
export interface EnlittOpenAIClient {
|
|
39
|
+
/** Premium-only image generation; see `media.ts`. */
|
|
40
|
+
readonly images: EnlittOpenAIImages;
|
|
41
|
+
/** Premium-only speech and transcription; see `media.ts`. */
|
|
42
|
+
readonly audio: EnlittOpenAIAudio;
|
|
43
|
+
readonly responses: {
|
|
44
|
+
create(body: EnlittOpenAIResponseCreateParamsNonStreaming, options?: EnlittOpenAIRequestOptions): Promise<OpenAIResponseResult>;
|
|
45
|
+
create(body: EnlittOpenAIResponseCreateParamsStreaming, options?: EnlittOpenAIRequestOptions): Promise<EnlittOpenAIStream>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export declare function enlitt(options?: EnlittOptions): EnlittOpenAIClient;
|
|
49
|
+
export declare function enlitt(client: OpenAI, options?: EnlittOptions): EnlittOpenAIClient;
|
|
50
|
+
export declare function validateRequestOptions(options: EnlittOpenAIRequestOptions | undefined): void;
|
|
51
|
+
/** Validates `body.enlitt` under the shared call-option rules; also used by `media.ts`. */
|
|
52
|
+
export declare function readCallOptions(body: {
|
|
53
|
+
enlitt?: EnlittOpenAICallOptions;
|
|
54
|
+
}, mode: "standard" | "premium"): {
|
|
55
|
+
idempotencyKey: string;
|
|
56
|
+
metadata: Record<string, string> | undefined;
|
|
57
|
+
maxCharge?: never;
|
|
58
|
+
price?: never;
|
|
59
|
+
reportingDeadlineMs?: never;
|
|
60
|
+
} | {
|
|
61
|
+
idempotencyKey: string;
|
|
62
|
+
metadata: Record<string, string> | undefined;
|
|
63
|
+
maxCharge: string;
|
|
64
|
+
price: string | ((context: OpenAIPremiumPriceContext) => string | Promise<string>) | undefined;
|
|
65
|
+
reportingDeadlineMs: number | undefined;
|
|
66
|
+
};
|
|
67
|
+
/** The one price rule for this adapter, generic over the context so `media.ts` shares it. */
|
|
68
|
+
export declare function evaluatePrice<Context = OpenAIPremiumPriceContext>(client: InternalEnlittClient, price: string | ((context: Context) => string | Promise<string>) | undefined, context: Context): Promise<string>;
|
|
69
|
+
export declare function perToken(rates: {
|
|
70
|
+
readonly input: string;
|
|
71
|
+
readonly output: string;
|
|
72
|
+
}): (context: OpenAIPremiumPriceContext) => string;
|
|
73
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/openai/client.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,EACL,qBAAq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I,EAAE;IAAE,MAAM,CAAC,EAAE,uBAAuB,CAAA;CAAE,EAAE,IAAI,EAAE,UAAU,GAAG,SAAS;;;;;;;;;;+BA3FpD,yBAAyB,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;;EA0HzG;AAsZD,6FAA6F;AAC7F,wBAAsB,aAAa,CAAC,OAAO,GAAG,yBAAyB,EAAE,MAAM,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAQtN;AA6BD,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,CAAC,OAAO,EAAE,yBAAyB,KAAK,MAAM,CAInI"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { ENLITT_STANDARD_MODEL, enlitt, perToken, type EnlittOpenAICallOptions, type EnlittOpenAIClient, type EnlittOpenAIPrice, type EnlittOpenAIRequestOptions, type EnlittOpenAIResponseCreateParamsNonStreaming, type EnlittOpenAIResponseCreateParamsStreaming, type EnlittOpenAIStream, type OpenAIPremiumPriceContext } from "./client.cjs";
|
|
2
|
+
export { type EnlittOpenAIAudio, type EnlittOpenAIImages, type EnlittOpenAIImageGenerateParams, type EnlittOpenAIMediaCallOptions, type EnlittOpenAIMediaPrice, type EnlittOpenAISpeechCreateParams, type EnlittOpenAITranscriptionCreateParams, type OpenAIPremiumMediaPriceContext } from "./media.cjs";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ENLITT_STANDARD_MODEL, enlitt, perToken, type EnlittOpenAICallOptions, type EnlittOpenAIClient, type EnlittOpenAIPrice, type EnlittOpenAIRequestOptions, type EnlittOpenAIResponseCreateParamsNonStreaming, type EnlittOpenAIResponseCreateParamsStreaming, type EnlittOpenAIStream, type OpenAIPremiumPriceContext } from "./client.js";
|
|
2
|
+
export { type EnlittOpenAIAudio, type EnlittOpenAIImages, type EnlittOpenAIImageGenerateParams, type EnlittOpenAIMediaCallOptions, type EnlittOpenAIMediaPrice, type EnlittOpenAISpeechCreateParams, type EnlittOpenAITranscriptionCreateParams, type OpenAIPremiumMediaPriceContext } from "./media.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,MAAM,EACN,QAAQ,EACR,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,4CAA4C,EACjD,KAAK,yCAAyC,EAC9C,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC/B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,8BAA8B,EACnC,KAAK,qCAAqC,EAC1C,KAAK,8BAA8B,EACpC,MAAM,YAAY,CAAC"}
|