@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,98 @@
1
+ /**
2
+ * The Vercel AI SDK adapter over the framework-neutral premium lifecycle.
3
+ *
4
+ * `specs/SDK-side routing.md` gives this file only the provider mapping around
5
+ * `core/premium.ts`: it wraps the provider model a business selected and pays
6
+ * for, maps each provider-interface outcome onto the core's status and charge,
7
+ * collects the price context, and offers `perToken()`. It contains no begin, no
8
+ * status rule, no clamp, and no report of its own; all of those are
9
+ * `runPremiumCharge()`'s, so a business moving a call between this wrapper and
10
+ * `withPremiumCharge()` changes how the charge is computed and nothing about how
11
+ * it is settled.
12
+ *
13
+ * The internal client is never null: an SDK holding no Enlitt configuration
14
+ * fails at construction (`createInternalClient()`), before any model exists, so
15
+ * there is no premium model that can reach a provider without Enlitt having
16
+ * admitted the call first. A session that is absent, expired, or revoked fails
17
+ * the call with the provider uninvoked, because letting a rejected session fall
18
+ * through would silently move that user's spend onto the business.
19
+ *
20
+ * Nothing about a call's content is ever sent to Enlitt: the price context lives
21
+ * and dies in the business's own process.
22
+ */
23
+ import type { LanguageModelV3 } from "@ai-sdk/provider";
24
+ import { type PremiumChargeRequest } from "../core/premium.cjs";
25
+ import type { InternalEnlittClient } from "../core/transport.cjs";
26
+ import { type EnlittPrice, type PremiumPriceContext } from "./language-model.cjs";
27
+ /**
28
+ * Derived rather than invented, per the shared type conventions: the pinned
29
+ * package exports no name for what `doGenerate()` returns, so this alias is the
30
+ * only place that fact is stated and it can never drift from the interface it
31
+ * claims to implement.
32
+ */
33
+ type GenerateResult = Awaited<ReturnType<LanguageModelV3["doGenerate"]>>;
34
+ /** Same reasoning as {@link GenerateResult}, for `doStream()`. */
35
+ type StreamResult = Awaited<ReturnType<LanguageModelV3["doStream"]>>;
36
+ /**
37
+ * Returns a price function: `input x usage.inputTokens.total + output x
38
+ * usage.outputTokens.total`, both rates in NANOUSD per token as canonical
39
+ * strings, computed exactly in `bigint`. A missing total counts as zero, so a
40
+ * canceled call with no usage charges nothing for that side. Cached and
41
+ * reasoning tokens are priced as ordinary input and output tokens, as they are
42
+ * already inside the totals; a business that prices them differently writes its
43
+ * own function. Non-canonical rates are rejected as `EnlittConfigurationError`
44
+ * when the function is created, not when it runs.
45
+ */
46
+ export declare function perToken(rates: {
47
+ input: string;
48
+ output: string;
49
+ }): (context: PremiumPriceContext) => string;
50
+ /**
51
+ * Transparently wraps the business's own provider model with the premium
52
+ * billing lifecycle.
53
+ *
54
+ * Preserves every request, provider option, result, warning, error, response ID,
55
+ * and stream part `model` itself produces, adding only `providerMetadata.enlitt`
56
+ * (`{ operationId, effectiveMaxChargeNanoUsd }` and nothing else) to the
57
+ * non-streaming result and to a stream's `finish` part. `provider` and
58
+ * `modelId` pass straight through, because this middleware changes nothing
59
+ * about which provider or model identity a caller sees.
60
+ *
61
+ * One model invocation is one operation. A Vercel agent loop invokes the model
62
+ * once per step, so each step has its own maximum, price, and report; an
63
+ * automatic retry of the same step re-presents the same prompt, resolves the
64
+ * same call ID, and replays the same operation instead of beginning a second.
65
+ */
66
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV3): LanguageModelV3;
67
+ /**
68
+ * The Vercel adapter over `runPremiumCharge()` for a non-streaming call.
69
+ *
70
+ * A result is `completed`, a `length` finish included. A rejection while the
71
+ * call is canceled evaluates `price` with `status: "canceled"`, no usage, and
72
+ * empty content before rethrowing. Any other provider error is `failed`, is
73
+ * rethrown unchanged, and never calls `price`.
74
+ */
75
+ export declare function wrapPremiumGenerate(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<GenerateResult>): Promise<GenerateResult>;
76
+ /**
77
+ * The Vercel adapter over `runPremiumCharge()` for a streaming call.
78
+ *
79
+ * The returned promise resolves with the wrapped `StreamResult` as soon as the
80
+ * provider's `doStream` resolves, while the core's `run` stays pending until
81
+ * the stream terminates, so `doStream` returns as early as the unwrapped model
82
+ * would. A begin refusal rejects `doStream` before the provider is invoked, and
83
+ * a provider that rejects outright is reported `failed` and rethrown unchanged.
84
+ *
85
+ * The returned stream passes every part through unchanged, unbuffered, and with
86
+ * backpressure preserved (it reads one source chunk per consumer pull),
87
+ * collecting parts only when `price` is a function. A finish part (a `length`
88
+ * finish included) settles the operation `completed`; an error part, a source
89
+ * error, or a source that ends with no finish settles it `failed`; consumer
90
+ * cancellation or an aborted `request.signal` settles it `canceled`. Creating a
91
+ * stream reports nothing; the report is sent when the stream terminates, and
92
+ * the stream is not closed until it has been sent, so a serverless process
93
+ * cannot end between the last part and its report. A rejection the core raises
94
+ * after the stream was returned is observed here and never becomes an
95
+ * unhandled rejection.
96
+ */
97
+ export declare function wrapPremiumStream(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<StreamResult>): Promise<StreamResult>;
98
+ export {};
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The Vercel AI SDK adapter over the framework-neutral premium lifecycle.
3
+ *
4
+ * `specs/SDK-side routing.md` gives this file only the provider mapping around
5
+ * `core/premium.ts`: it wraps the provider model a business selected and pays
6
+ * for, maps each provider-interface outcome onto the core's status and charge,
7
+ * collects the price context, and offers `perToken()`. It contains no begin, no
8
+ * status rule, no clamp, and no report of its own; all of those are
9
+ * `runPremiumCharge()`'s, so a business moving a call between this wrapper and
10
+ * `withPremiumCharge()` changes how the charge is computed and nothing about how
11
+ * it is settled.
12
+ *
13
+ * The internal client is never null: an SDK holding no Enlitt configuration
14
+ * fails at construction (`createInternalClient()`), before any model exists, so
15
+ * there is no premium model that can reach a provider without Enlitt having
16
+ * admitted the call first. A session that is absent, expired, or revoked fails
17
+ * the call with the provider uninvoked, because letting a rejected session fall
18
+ * through would silently move that user's spend onto the business.
19
+ *
20
+ * Nothing about a call's content is ever sent to Enlitt: the price context lives
21
+ * and dies in the business's own process.
22
+ */
23
+ import type { LanguageModelV3 } from "@ai-sdk/provider";
24
+ import { type PremiumChargeRequest } from "../core/premium.js";
25
+ import type { InternalEnlittClient } from "../core/transport.js";
26
+ import { type EnlittPrice, type PremiumPriceContext } from "./language-model.js";
27
+ /**
28
+ * Derived rather than invented, per the shared type conventions: the pinned
29
+ * package exports no name for what `doGenerate()` returns, so this alias is the
30
+ * only place that fact is stated and it can never drift from the interface it
31
+ * claims to implement.
32
+ */
33
+ type GenerateResult = Awaited<ReturnType<LanguageModelV3["doGenerate"]>>;
34
+ /** Same reasoning as {@link GenerateResult}, for `doStream()`. */
35
+ type StreamResult = Awaited<ReturnType<LanguageModelV3["doStream"]>>;
36
+ /**
37
+ * Returns a price function: `input x usage.inputTokens.total + output x
38
+ * usage.outputTokens.total`, both rates in NANOUSD per token as canonical
39
+ * strings, computed exactly in `bigint`. A missing total counts as zero, so a
40
+ * canceled call with no usage charges nothing for that side. Cached and
41
+ * reasoning tokens are priced as ordinary input and output tokens, as they are
42
+ * already inside the totals; a business that prices them differently writes its
43
+ * own function. Non-canonical rates are rejected as `EnlittConfigurationError`
44
+ * when the function is created, not when it runs.
45
+ */
46
+ export declare function perToken(rates: {
47
+ input: string;
48
+ output: string;
49
+ }): (context: PremiumPriceContext) => string;
50
+ /**
51
+ * Transparently wraps the business's own provider model with the premium
52
+ * billing lifecycle.
53
+ *
54
+ * Preserves every request, provider option, result, warning, error, response ID,
55
+ * and stream part `model` itself produces, adding only `providerMetadata.enlitt`
56
+ * (`{ operationId, effectiveMaxChargeNanoUsd }` and nothing else) to the
57
+ * non-streaming result and to a stream's `finish` part. `provider` and
58
+ * `modelId` pass straight through, because this middleware changes nothing
59
+ * about which provider or model identity a caller sees.
60
+ *
61
+ * One model invocation is one operation. A Vercel agent loop invokes the model
62
+ * once per step, so each step has its own maximum, price, and report; an
63
+ * automatic retry of the same step re-presents the same prompt, resolves the
64
+ * same call ID, and replays the same operation instead of beginning a second.
65
+ */
66
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV3): LanguageModelV3;
67
+ /**
68
+ * The Vercel adapter over `runPremiumCharge()` for a non-streaming call.
69
+ *
70
+ * A result is `completed`, a `length` finish included. A rejection while the
71
+ * call is canceled evaluates `price` with `status: "canceled"`, no usage, and
72
+ * empty content before rethrowing. Any other provider error is `failed`, is
73
+ * rethrown unchanged, and never calls `price`.
74
+ */
75
+ export declare function wrapPremiumGenerate(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<GenerateResult>): Promise<GenerateResult>;
76
+ /**
77
+ * The Vercel adapter over `runPremiumCharge()` for a streaming call.
78
+ *
79
+ * The returned promise resolves with the wrapped `StreamResult` as soon as the
80
+ * provider's `doStream` resolves, while the core's `run` stays pending until
81
+ * the stream terminates, so `doStream` returns as early as the unwrapped model
82
+ * would. A begin refusal rejects `doStream` before the provider is invoked, and
83
+ * a provider that rejects outright is reported `failed` and rethrown unchanged.
84
+ *
85
+ * The returned stream passes every part through unchanged, unbuffered, and with
86
+ * backpressure preserved (it reads one source chunk per consumer pull),
87
+ * collecting parts only when `price` is a function. A finish part (a `length`
88
+ * finish included) settles the operation `completed`; an error part, a source
89
+ * error, or a source that ends with no finish settles it `failed`; consumer
90
+ * cancellation or an aborted `request.signal` settles it `canceled`. Creating a
91
+ * stream reports nothing; the report is sent when the stream terminates, and
92
+ * the stream is not closed until it has been sent, so a serverless process
93
+ * cannot end between the last part and its report. A rejection the core raises
94
+ * after the stream was returned is observed here and never becomes an
95
+ * unhandled rejection.
96
+ */
97
+ export declare function wrapPremiumStream(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<StreamResult>): Promise<StreamResult>;
98
+ export {};
99
+ //# sourceMappingURL=premium-language-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"premium-language-model.d.ts","sourceRoot":"","sources":["../../src/vercel/premium-language-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAIL,KAAK,oBAAoB,EAI1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACzB,MAAM,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,KAAK,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEzE,kEAAkE;AAClE,KAAK,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAIrE;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,CAAC,OAAO,EAAE,mBAAmB,KAAK,MAAM,CAS3G;AAID;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,oBAAoB,EAAE,KAAK,EAAE,eAAe,GAAG,eAAe,CA4ChH;AA6CD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,WAAW,GAAG,SAAS,EAC9B,GAAG,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,GACjC,OAAO,CAAC,cAAc,CAAC,CA4DzB;AAuBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,WAAW,GAAG,SAAS,EAC9B,GAAG,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC,CAgCvB"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Implements the whole-request path, where Enlitt is the model provider.
3
+ *
4
+ * `specs/SDK-side routing.md` gives this file the job of mapping a pinned
5
+ * Vercel AI SDK call into Enlitt's standard request (`EnlittStandardRequest`),
6
+ * sending the complete request to Enlitt over `core/transport.ts`, and mapping
7
+ * the response or event stream back into provider-interface parts. It is kept
8
+ * separate from `premium-language-model.ts` because the two paths send Enlitt
9
+ * fundamentally different things (a whole request here, a content-free billing
10
+ * lifecycle there), and conflating them would make it possible for a change to
11
+ * one to leak a field into the other.
12
+ *
13
+ * The business supplies no provider model: `model: "enlitt-standard"` is the
14
+ * only value this file ever sends, and no parameter anywhere here can override
15
+ * it. `buildStandardRequest()` is also the standard framework-normalization
16
+ * boundary: anything the standard capability floor does not carry is rejected
17
+ * there with `EnlittConfigurationError`, before any request, and never silently
18
+ * dropped or deferred to route selection.
19
+ *
20
+ * Responses and stream events are read in tolerant mode, so a newer server's
21
+ * additions (an unknown enum member, output item, content part, or stream event)
22
+ * degrade into `"other"`, a skipped item, or a skipped event instead of an
23
+ * error. Nothing here ever receives or displays a credit, balance, or tier
24
+ * fact: the wire schemas carry none.
25
+ */
26
+ import { type EnlittStandardRequest, type OpenAIResponse } from "@enlitt/protocol";
27
+ import type { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3StreamPart } from "@ai-sdk/provider";
28
+ import { type InternalEnlittClient } from "../core/transport.cjs";
29
+ import { type SseEvent } from "../core/sse.cjs";
30
+ import { type EnlittProviderOptions } from "./language-model.cjs";
31
+ /**
32
+ * Derived rather than invented, per the shared type conventions: the pinned
33
+ * package exports no name for what `doGenerate()` returns, so this alias is the
34
+ * only place that fact is stated, and it can never drift from the interface it
35
+ * claims to implement.
36
+ */
37
+ type GenerateResult = Awaited<ReturnType<LanguageModelV3["doGenerate"]>>;
38
+ /**
39
+ * Implements `doGenerate()` and `doStream()` for the pinned Vercel AI SDK
40
+ * provider interface, with `modelId` `"enlitt-standard"`.
41
+ *
42
+ * Every invocation follows the sequence the spec names:
43
+ * `readEnlittCallOptions()`, `resolveCallId()`, `buildStandardRequest()`,
44
+ * `requestEnlitt()`. The call ID used for `Idempotency-Key` is therefore derived
45
+ * before the body it protects is built, and a caller's options are read exactly
46
+ * once. This function contains no session logic and no error classification of
47
+ * its own: both live in `transport.ts` and `errors.ts`.
48
+ */
49
+ export declare function createStandardLanguageModel(client: InternalEnlittClient): LanguageModelV3;
50
+ /**
51
+ * Maps supported Vercel input into an `EnlittStandardRequest` and validates it
52
+ * with the protocol's strict validator, so a body built here can never diverge
53
+ * from what the wire accepts.
54
+ *
55
+ * Uses `model: "enlitt-standard"` unconditionally. It never sends a provider or
56
+ * model override, `conversation`, `previous_response_id`, `store`, `background`,
57
+ * `include`, `service_tier`, or any other field the protocol rejects, and it
58
+ * raises `EnlittConfigurationError` for each unsupported capability instead of
59
+ * dropping it: structured response formats, sampling controls (temperature,
60
+ * topP, topK, penalties, seed, stop sequences), required or named tool choice,
61
+ * provider-defined tools, file/audio/video parts, reasoning, and
62
+ * provider-specific options.
63
+ *
64
+ * `stream` is the fourth, optional argument because the call site, not the
65
+ * prompt, decides it; it defaults to `false` and is omitted from the body then.
66
+ */
67
+ export declare function buildStandardRequest(params: LanguageModelV3CallOptions, options: EnlittProviderOptions, callId: string, stream?: boolean): EnlittStandardRequest;
68
+ /**
69
+ * Maps `OpenAIResponse` back into `GenerateResult`, preserving text, function
70
+ * calls, finish reason, and exact usage.
71
+ *
72
+ * An output item or content part that is an `UnknownVariant` is skipped and
73
+ * contributes no content. Each distinct unknown `type` adds exactly one `other`
74
+ * warning telling the business to upgrade the SDK, so a newer server never
75
+ * produces a silent gap.
76
+ */
77
+ export declare function mapStandardGenerateResponse(response: OpenAIResponse): GenerateResult;
78
+ /**
79
+ * Consumes the events `createSseEventStream()` produces, parses each `data`
80
+ * payload in tolerant mode, enforces the ordering rule incrementally, and emits
81
+ * provider-interface stream parts one event at a time.
82
+ *
83
+ * Ordering: the first event must be `response.created`; each next event's
84
+ * `sequence_number` must be exactly one more than the previous (a gap or a
85
+ * lower number is rejected), except an identical repeat of the last event,
86
+ * which is absorbed; nothing may follow the terminal event; and a stream that
87
+ * ends without a known terminal event is rejected. An unknown event takes part
88
+ * in the sequence check but emits nothing and is never terminal.
89
+ *
90
+ * Every protocol violation (bad JSON, a bad shape, a gap, an out-of-order or
91
+ * conflicting event, a missing or trailing terminal) ends the stream with one
92
+ * `error` part carrying a `malformed_response` `EnlittError`, then closes it.
93
+ * A failed response terminates with a single `finish` part whose reason is
94
+ * `"error"`. Abort and source read failures error the stream with the
95
+ * underlying reason.
96
+ *
97
+ * Backpressure and cancellation are preserved: `pull` reads and enqueues at
98
+ * most one batch of parts per consumer pull, so the consumer's read rate
99
+ * governs how far the HTTP read runs ahead, and `cancel` and `signal` abort the
100
+ * same in-flight request. No event content is buffered whole, copied, hashed,
101
+ * or logged.
102
+ */
103
+ export declare function mapStandardStream(events: ReadableStream<SseEvent>, signal?: AbortSignal): ReadableStream<LanguageModelV3StreamPart>;
104
+ export {};
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Implements the whole-request path, where Enlitt is the model provider.
3
+ *
4
+ * `specs/SDK-side routing.md` gives this file the job of mapping a pinned
5
+ * Vercel AI SDK call into Enlitt's standard request (`EnlittStandardRequest`),
6
+ * sending the complete request to Enlitt over `core/transport.ts`, and mapping
7
+ * the response or event stream back into provider-interface parts. It is kept
8
+ * separate from `premium-language-model.ts` because the two paths send Enlitt
9
+ * fundamentally different things (a whole request here, a content-free billing
10
+ * lifecycle there), and conflating them would make it possible for a change to
11
+ * one to leak a field into the other.
12
+ *
13
+ * The business supplies no provider model: `model: "enlitt-standard"` is the
14
+ * only value this file ever sends, and no parameter anywhere here can override
15
+ * it. `buildStandardRequest()` is also the standard framework-normalization
16
+ * boundary: anything the standard capability floor does not carry is rejected
17
+ * there with `EnlittConfigurationError`, before any request, and never silently
18
+ * dropped or deferred to route selection.
19
+ *
20
+ * Responses and stream events are read in tolerant mode, so a newer server's
21
+ * additions (an unknown enum member, output item, content part, or stream event)
22
+ * degrade into `"other"`, a skipped item, or a skipped event instead of an
23
+ * error. Nothing here ever receives or displays a credit, balance, or tier
24
+ * fact: the wire schemas carry none.
25
+ */
26
+ import { type EnlittStandardRequest, type OpenAIResponse } from "@enlitt/protocol";
27
+ import type { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3StreamPart } from "@ai-sdk/provider";
28
+ import { type InternalEnlittClient } from "../core/transport.js";
29
+ import { type SseEvent } from "../core/sse.js";
30
+ import { type EnlittProviderOptions } from "./language-model.js";
31
+ /**
32
+ * Derived rather than invented, per the shared type conventions: the pinned
33
+ * package exports no name for what `doGenerate()` returns, so this alias is the
34
+ * only place that fact is stated, and it can never drift from the interface it
35
+ * claims to implement.
36
+ */
37
+ type GenerateResult = Awaited<ReturnType<LanguageModelV3["doGenerate"]>>;
38
+ /**
39
+ * Implements `doGenerate()` and `doStream()` for the pinned Vercel AI SDK
40
+ * provider interface, with `modelId` `"enlitt-standard"`.
41
+ *
42
+ * Every invocation follows the sequence the spec names:
43
+ * `readEnlittCallOptions()`, `resolveCallId()`, `buildStandardRequest()`,
44
+ * `requestEnlitt()`. The call ID used for `Idempotency-Key` is therefore derived
45
+ * before the body it protects is built, and a caller's options are read exactly
46
+ * once. This function contains no session logic and no error classification of
47
+ * its own: both live in `transport.ts` and `errors.ts`.
48
+ */
49
+ export declare function createStandardLanguageModel(client: InternalEnlittClient): LanguageModelV3;
50
+ /**
51
+ * Maps supported Vercel input into an `EnlittStandardRequest` and validates it
52
+ * with the protocol's strict validator, so a body built here can never diverge
53
+ * from what the wire accepts.
54
+ *
55
+ * Uses `model: "enlitt-standard"` unconditionally. It never sends a provider or
56
+ * model override, `conversation`, `previous_response_id`, `store`, `background`,
57
+ * `include`, `service_tier`, or any other field the protocol rejects, and it
58
+ * raises `EnlittConfigurationError` for each unsupported capability instead of
59
+ * dropping it: structured response formats, sampling controls (temperature,
60
+ * topP, topK, penalties, seed, stop sequences), required or named tool choice,
61
+ * provider-defined tools, file/audio/video parts, reasoning, and
62
+ * provider-specific options.
63
+ *
64
+ * `stream` is the fourth, optional argument because the call site, not the
65
+ * prompt, decides it; it defaults to `false` and is omitted from the body then.
66
+ */
67
+ export declare function buildStandardRequest(params: LanguageModelV3CallOptions, options: EnlittProviderOptions, callId: string, stream?: boolean): EnlittStandardRequest;
68
+ /**
69
+ * Maps `OpenAIResponse` back into `GenerateResult`, preserving text, function
70
+ * calls, finish reason, and exact usage.
71
+ *
72
+ * An output item or content part that is an `UnknownVariant` is skipped and
73
+ * contributes no content. Each distinct unknown `type` adds exactly one `other`
74
+ * warning telling the business to upgrade the SDK, so a newer server never
75
+ * produces a silent gap.
76
+ */
77
+ export declare function mapStandardGenerateResponse(response: OpenAIResponse): GenerateResult;
78
+ /**
79
+ * Consumes the events `createSseEventStream()` produces, parses each `data`
80
+ * payload in tolerant mode, enforces the ordering rule incrementally, and emits
81
+ * provider-interface stream parts one event at a time.
82
+ *
83
+ * Ordering: the first event must be `response.created`; each next event's
84
+ * `sequence_number` must be exactly one more than the previous (a gap or a
85
+ * lower number is rejected), except an identical repeat of the last event,
86
+ * which is absorbed; nothing may follow the terminal event; and a stream that
87
+ * ends without a known terminal event is rejected. An unknown event takes part
88
+ * in the sequence check but emits nothing and is never terminal.
89
+ *
90
+ * Every protocol violation (bad JSON, a bad shape, a gap, an out-of-order or
91
+ * conflicting event, a missing or trailing terminal) ends the stream with one
92
+ * `error` part carrying a `malformed_response` `EnlittError`, then closes it.
93
+ * A failed response terminates with a single `finish` part whose reason is
94
+ * `"error"`. Abort and source read failures error the stream with the
95
+ * underlying reason.
96
+ *
97
+ * Backpressure and cancellation are preserved: `pull` reads and enqueues at
98
+ * most one batch of parts per consumer pull, so the consumer's read rate
99
+ * governs how far the HTTP read runs ahead, and `cancel` and `signal` abort the
100
+ * same in-flight request. No event content is buffered whole, copied, hashed,
101
+ * or logged.
102
+ */
103
+ export declare function mapStandardStream(events: ReadableStream<SseEvent>, signal?: AbortSignal): ReadableStream<LanguageModelV3StreamPart>;
104
+ export {};
105
+ //# sourceMappingURL=standard-language-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-language-model.d.ts","sourceRoot":"","sources":["../../src/vercel/standard-language-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EASL,KAAK,qBAAqB,EAG1B,KAAK,cAAc,EAKpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAG1B,yBAAyB,EAG1B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAiC,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAyC,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAwC,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEvG;;;;;GAKG;AACH,KAAK,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAkCzE;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,oBAAoB,GAAG,eAAe,CAoDzF;AAsBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,0BAA0B,EAClC,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,MAAM,EACd,MAAM,UAAQ,GACb,qBAAqB,CAuCvB;AAkLD;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc,CAkCpF;AAuGD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,EAChC,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,yBAAyB,CAAC,CA4H3C"}
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var chunkC76K6HLL_cjs = require('./chunk-C76K6HLL.cjs');
4
+ require('./chunk-6OWXYBBT.cjs');
5
+ require('./chunk-26SW63P5.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "ENLITT_STANDARD_MODEL", {
10
+ enumerable: true,
11
+ get: function () { return chunkC76K6HLL_cjs.ENLITT_STANDARD_MODEL; }
12
+ });
13
+ Object.defineProperty(exports, "enlitt", {
14
+ enumerable: true,
15
+ get: function () { return chunkC76K6HLL_cjs.enlitt; }
16
+ });
17
+ Object.defineProperty(exports, "perToken", {
18
+ enumerable: true,
19
+ get: function () { return chunkC76K6HLL_cjs.perToken; }
20
+ });
21
+ //# sourceMappingURL=vercel.cjs.map
22
+ //# sourceMappingURL=vercel.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"vercel.cjs"}
package/dist/vercel.js ADDED
@@ -0,0 +1,5 @@
1
+ export { ENLITT_STANDARD_MODEL, enlitt, perToken } from './chunk-SFI4RLNN.js';
2
+ import './chunk-V5TCSQ7C.js';
3
+ import './chunk-6DPBYLA5.js';
4
+ //# sourceMappingURL=vercel.js.map
5
+ //# sourceMappingURL=vercel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"vercel.js"}
package/package.json CHANGED
@@ -1,6 +1,132 @@
1
1
  {
2
2
  "name": "@enlitt/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Official TypeScript SDK for Enlitt",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "CHANGELOG.md"
12
+ ],
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.cts",
24
+ "default": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "./browser": {
28
+ "import": {
29
+ "types": "./dist/browser.d.ts",
30
+ "default": "./dist/browser.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/browser.d.cts",
34
+ "default": "./dist/browser.cjs"
35
+ }
36
+ },
37
+ "./core": {
38
+ "browser": "./dist/server-unavailable.js",
39
+ "import": {
40
+ "types": "./dist/core/index.d.ts",
41
+ "default": "./dist/core.js"
42
+ },
43
+ "require": {
44
+ "types": "./dist/core/index.d.cts",
45
+ "default": "./dist/core.cjs"
46
+ }
47
+ },
48
+ "./vercel": {
49
+ "browser": "./dist/server-unavailable.js",
50
+ "import": {
51
+ "types": "./dist/vercel/index.d.ts",
52
+ "default": "./dist/vercel.js"
53
+ },
54
+ "require": {
55
+ "types": "./dist/vercel/index.d.cts",
56
+ "default": "./dist/vercel.cjs"
57
+ }
58
+ },
59
+ "./openai": {
60
+ "browser": "./dist/server-unavailable.js",
61
+ "import": {
62
+ "types": "./dist/openai/index.d.ts",
63
+ "default": "./dist/openai.js"
64
+ },
65
+ "require": {
66
+ "types": "./dist/openai/index.d.cts",
67
+ "default": "./dist/openai.cjs"
68
+ }
69
+ },
70
+ "./server": {
71
+ "browser": "./dist/server-unavailable.js",
72
+ "import": {
73
+ "types": "./dist/server/index.d.ts",
74
+ "default": "./dist/server.js"
75
+ },
76
+ "require": {
77
+ "types": "./dist/server/index.d.cts",
78
+ "default": "./dist/server.cjs"
79
+ }
80
+ },
81
+ "./package.json": "./package.json"
82
+ },
83
+ "engines": {
84
+ "node": ">=22"
85
+ },
86
+ "publishConfig": {
87
+ "access": "public"
88
+ },
89
+ "devDependencies": {
90
+ "@ai-sdk/provider": "4.0.10",
91
+ "@arethetypeswrong/cli": "^0.18.5",
92
+ "@types/node": "^24.13.3",
93
+ "openai": "7.27.0",
94
+ "publint": "^0.3.25",
95
+ "tsup": "^8.5.1",
96
+ "typescript": "^7.0.2",
97
+ "vitest": "^4.1.11"
98
+ },
99
+ "dependencies": {
100
+ "@enlitt/protocol": "0.1.0"
101
+ },
102
+ "peerDependencies": {
103
+ "openai": "^7.27.0"
104
+ },
105
+ "typesVersions": {
106
+ "*": {
107
+ "browser": [
108
+ "dist/browser.d.ts"
109
+ ],
110
+ "core": [
111
+ "dist/core/index.d.ts"
112
+ ],
113
+ "vercel": [
114
+ "dist/vercel/index.d.ts"
115
+ ],
116
+ "openai": [
117
+ "dist/openai/index.d.ts"
118
+ ],
119
+ "server": [
120
+ "dist/server/index.d.ts"
121
+ ]
122
+ }
123
+ },
124
+ "scripts": {
125
+ "dev": "tsup --watch",
126
+ "build": "tsup && tsc -p tsconfig.build.json && node scripts/emit-cts-declarations.mjs",
127
+ "typecheck": "tsc --noEmit",
128
+ "lint": "eslint .",
129
+ "test": "vitest run",
130
+ "test:package": "rm -rf .pack && pnpm --config.ignore-scripts=true pack --pack-destination .pack > /dev/null && publint .pack/*.tgz && attw .pack/*.tgz --profile node16"
131
+ }
6
132
  }