@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.
Files changed (117) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +21 -0
  3. package/README.md +63 -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-2BGWYTJM.cjs +1097 -0
  15. package/dist/chunk-2BGWYTJM.cjs.map +1 -0
  16. package/dist/chunk-6OWXYBBT.cjs +146 -0
  17. package/dist/chunk-6OWXYBBT.cjs.map +1 -0
  18. package/dist/chunk-NI6WH5FI.js +33 -0
  19. package/dist/chunk-NI6WH5FI.js.map +1 -0
  20. package/dist/chunk-O6ASIA3X.js +866 -0
  21. package/dist/chunk-O6ASIA3X.js.map +1 -0
  22. package/dist/chunk-PPOUNWNA.cjs +895 -0
  23. package/dist/chunk-PPOUNWNA.cjs.map +1 -0
  24. package/dist/chunk-UVZMKGIL.js +1091 -0
  25. package/dist/chunk-UVZMKGIL.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-YPA4R65T.cjs +35 -0
  29. package/dist/chunk-YPA4R65T.cjs.map +1 -0
  30. package/dist/core/errors.d.cts +262 -0
  31. package/dist/core/errors.d.ts +263 -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 +122 -0
  40. package/dist/core/session.d.ts +123 -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 +77 -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 +72 -0
  63. package/dist/openai/client.d.ts +73 -0
  64. package/dist/openai/client.d.ts.map +1 -0
  65. package/dist/openai/index.d.cts +2 -0
  66. package/dist/openai/index.d.ts +3 -0
  67. package/dist/openai/index.d.ts.map +1 -0
  68. package/dist/openai/media.d.cts +108 -0
  69. package/dist/openai/media.d.ts +109 -0
  70. package/dist/openai/media.d.ts.map +1 -0
  71. package/dist/openai.cjs +623 -0
  72. package/dist/openai.cjs.map +1 -0
  73. package/dist/openai.js +617 -0
  74. package/dist/openai.js.map +1 -0
  75. package/dist/server/callback.d.cts +107 -0
  76. package/dist/server/callback.d.ts +108 -0
  77. package/dist/server/callback.d.ts.map +1 -0
  78. package/dist/server/client-sign-in.d.cts +77 -0
  79. package/dist/server/client-sign-in.d.ts +78 -0
  80. package/dist/server/client-sign-in.d.ts.map +1 -0
  81. package/dist/server/index.d.cts +20 -0
  82. package/dist/server/index.d.ts +21 -0
  83. package/dist/server/index.d.ts.map +1 -0
  84. package/dist/server/secrets.d.cts +46 -0
  85. package/dist/server/secrets.d.ts +47 -0
  86. package/dist/server/secrets.d.ts.map +1 -0
  87. package/dist/server-unavailable.cjs +8 -0
  88. package/dist/server-unavailable.cjs.map +1 -0
  89. package/dist/server-unavailable.d.cts +10 -0
  90. package/dist/server-unavailable.d.ts +11 -0
  91. package/dist/server-unavailable.d.ts.map +1 -0
  92. package/dist/server-unavailable.js +6 -0
  93. package/dist/server-unavailable.js.map +1 -0
  94. package/dist/server.cjs +880 -0
  95. package/dist/server.cjs.map +1 -0
  96. package/dist/server.js +795 -0
  97. package/dist/server.js.map +1 -0
  98. package/dist/vercel/index.d.cts +17 -0
  99. package/dist/vercel/index.d.ts +18 -0
  100. package/dist/vercel/index.d.ts.map +1 -0
  101. package/dist/vercel/language-model.d.cts +146 -0
  102. package/dist/vercel/language-model.d.ts +147 -0
  103. package/dist/vercel/language-model.d.ts.map +1 -0
  104. package/dist/vercel/premium-language-model.d.cts +127 -0
  105. package/dist/vercel/premium-language-model.d.ts +128 -0
  106. package/dist/vercel/premium-language-model.d.ts.map +1 -0
  107. package/dist/vercel/premium-media-model.d.cts +101 -0
  108. package/dist/vercel/premium-media-model.d.ts +102 -0
  109. package/dist/vercel/premium-media-model.d.ts.map +1 -0
  110. package/dist/vercel/standard-language-model.d.cts +104 -0
  111. package/dist/vercel/standard-language-model.d.ts +105 -0
  112. package/dist/vercel/standard-language-model.d.ts.map +1 -0
  113. package/dist/vercel.cjs +22 -0
  114. package/dist/vercel.cjs.map +1 -0
  115. package/dist/vercel.js +5 -0
  116. package/dist/vercel.js.map +1 -0
  117. package/package.json +139 -3
@@ -0,0 +1,127 @@
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, LanguageModelV4 } 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
+ * A `v4` model (`ai@7`, Bug #28) is wrapped as a `v4` model. Its extra call
67
+ * options, result fields, part types, and finish reasons pass through by
68
+ * identity; the lifecycle below reads only members `v3` and `v4` share, which
69
+ * is why the body is written once against the `v3` types.
70
+ */
71
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV3): LanguageModelV3;
72
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV4): LanguageModelV4;
73
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV3 | LanguageModelV4): LanguageModelV3 | LanguageModelV4;
74
+ /**
75
+ * Resolves what the call charges, for a status of `completed` or `canceled`.
76
+ *
77
+ * - No `price`: `"0"` (a call with only `maxCharge` is free).
78
+ * - A constant: that constant, on both statuses.
79
+ * - A function: awaited exactly once, with no timeout of its own (a price that
80
+ * misses the terminal deadline only costs the business, because the call then
81
+ * expires and charges nothing). A throw, a rejection, or a result that is not
82
+ * a canonical nonnegative NANOUSD string charges `"0"` and is passed to
83
+ * `onTerminalReportError` as an `EnlittConfigurationError`; the call's own
84
+ * result or stream is unaffected.
85
+ *
86
+ * It never lowers the result to the effective maximum: that is the core's rule,
87
+ * applied when it reports. Generic over the context so the media wrappers
88
+ * (`premium-media-model.ts`) share this one rule rather than copying it.
89
+ */
90
+ export declare function evaluatePrice<Context = PremiumPriceContext>(client: InternalEnlittClient, price: string | ((context: Context) => string | Promise<string>) | undefined, context: Context): Promise<string>;
91
+ /**
92
+ * The Vercel adapter over `runPremiumCharge()` for a non-streaming call.
93
+ *
94
+ * A result is `completed`, a `length` finish included. A rejection while the
95
+ * call is canceled evaluates `price` with `status: "canceled"`, no usage, and
96
+ * empty content before rethrowing. Any other provider error is `failed`, is
97
+ * rethrown unchanged, and never calls `price`.
98
+ */
99
+ export declare function wrapPremiumGenerate(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<GenerateResult>): Promise<GenerateResult>;
100
+ /**
101
+ * The Vercel adapter over `runPremiumCharge()` for a streaming call.
102
+ *
103
+ * The returned promise resolves with the wrapped `StreamResult` as soon as the
104
+ * provider's `doStream` resolves, while the core's `run` stays pending until
105
+ * the stream terminates, so `doStream` returns as early as the unwrapped model
106
+ * would. A begin refusal rejects `doStream` before the provider is invoked, and
107
+ * a provider that rejects outright is reported `failed` and rethrown unchanged.
108
+ *
109
+ * The returned stream passes every part through unchanged, unbuffered, and with
110
+ * backpressure preserved (it reads one source chunk per consumer pull),
111
+ * collecting parts only when `price` is a function. A finish part (a `length`
112
+ * finish included) settles the operation `completed`; an error part, a source
113
+ * error, or a source that ends with no finish settles it `failed`; consumer
114
+ * cancellation or an aborted `request.signal` settles it `canceled`. Creating a
115
+ * stream reports nothing; the report is sent when the stream terminates, and
116
+ * the stream is not closed until it has been sent, so a serverless process
117
+ * cannot end between the last part and its report. A rejection the core raises
118
+ * after the stream was returned is observed here and never becomes an
119
+ * unhandled rejection.
120
+ */
121
+ export declare function wrapPremiumStream(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<StreamResult>): Promise<StreamResult>;
122
+ /** The content-free timing bracket as the wire reports it. */
123
+ export declare function timingFacts(startedAt: Date, endedAt: Date): {
124
+ startedAt: string;
125
+ endedAt: string;
126
+ };
127
+ export {};
@@ -0,0 +1,128 @@
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, LanguageModelV4 } 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
+ * A `v4` model (`ai@7`, Bug #28) is wrapped as a `v4` model. Its extra call
67
+ * options, result fields, part types, and finish reasons pass through by
68
+ * identity; the lifecycle below reads only members `v3` and `v4` share, which
69
+ * is why the body is written once against the `v3` types.
70
+ */
71
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV3): LanguageModelV3;
72
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV4): LanguageModelV4;
73
+ export declare function createPremiumLanguageModel(client: InternalEnlittClient, model: LanguageModelV3 | LanguageModelV4): LanguageModelV3 | LanguageModelV4;
74
+ /**
75
+ * Resolves what the call charges, for a status of `completed` or `canceled`.
76
+ *
77
+ * - No `price`: `"0"` (a call with only `maxCharge` is free).
78
+ * - A constant: that constant, on both statuses.
79
+ * - A function: awaited exactly once, with no timeout of its own (a price that
80
+ * misses the terminal deadline only costs the business, because the call then
81
+ * expires and charges nothing). A throw, a rejection, or a result that is not
82
+ * a canonical nonnegative NANOUSD string charges `"0"` and is passed to
83
+ * `onTerminalReportError` as an `EnlittConfigurationError`; the call's own
84
+ * result or stream is unaffected.
85
+ *
86
+ * It never lowers the result to the effective maximum: that is the core's rule,
87
+ * applied when it reports. Generic over the context so the media wrappers
88
+ * (`premium-media-model.ts`) share this one rule rather than copying it.
89
+ */
90
+ export declare function evaluatePrice<Context = PremiumPriceContext>(client: InternalEnlittClient, price: string | ((context: Context) => string | Promise<string>) | undefined, context: Context): Promise<string>;
91
+ /**
92
+ * The Vercel adapter over `runPremiumCharge()` for a non-streaming call.
93
+ *
94
+ * A result is `completed`, a `length` finish included. A rejection while the
95
+ * call is canceled evaluates `price` with `status: "canceled"`, no usage, and
96
+ * empty content before rethrowing. Any other provider error is `failed`, is
97
+ * rethrown unchanged, and never calls `price`.
98
+ */
99
+ export declare function wrapPremiumGenerate(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<GenerateResult>): Promise<GenerateResult>;
100
+ /**
101
+ * The Vercel adapter over `runPremiumCharge()` for a streaming call.
102
+ *
103
+ * The returned promise resolves with the wrapped `StreamResult` as soon as the
104
+ * provider's `doStream` resolves, while the core's `run` stays pending until
105
+ * the stream terminates, so `doStream` returns as early as the unwrapped model
106
+ * would. A begin refusal rejects `doStream` before the provider is invoked, and
107
+ * a provider that rejects outright is reported `failed` and rethrown unchanged.
108
+ *
109
+ * The returned stream passes every part through unchanged, unbuffered, and with
110
+ * backpressure preserved (it reads one source chunk per consumer pull),
111
+ * collecting parts only when `price` is a function. A finish part (a `length`
112
+ * finish included) settles the operation `completed`; an error part, a source
113
+ * error, or a source that ends with no finish settles it `failed`; consumer
114
+ * cancellation or an aborted `request.signal` settles it `canceled`. Creating a
115
+ * stream reports nothing; the report is sent when the stream terminates, and
116
+ * the stream is not closed until it has been sent, so a serverless process
117
+ * cannot end between the last part and its report. A rejection the core raises
118
+ * after the stream was returned is observed here and never becomes an
119
+ * unhandled rejection.
120
+ */
121
+ export declare function wrapPremiumStream(client: InternalEnlittClient, request: PremiumChargeRequest, price: EnlittPrice | undefined, run: () => Promise<StreamResult>): Promise<StreamResult>;
122
+ /** The content-free timing bracket as the wire reports it. */
123
+ export declare function timingFacts(startedAt: Date, endedAt: Date): {
124
+ startedAt: string;
125
+ endedAt: string;
126
+ };
127
+ export {};
128
+ //# 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,EACf,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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,oBAAoB,EAAE,KAAK,EAAE,eAAe,GAAG,eAAe,CAAC;AAClH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,oBAAoB,EAAE,KAAK,EAAE,eAAe,GAAG,eAAe,CAAC;AAClH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,eAAe,GAAG,eAAe,GACvC,eAAe,GAAG,eAAe,CAAC;AAuDrC;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,aAAa,CAAC,OAAO,GAAG,mBAAmB,EAC/D,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,EAC5E,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAID;;;;;;;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;AAmID,8DAA8D;AAC9D,wBAAgB,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAElG"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Premium for non-language Vercel models: image generation, text-to-speech, and
3
+ * speech-to-text (owner decision 2026-11-15).
4
+ *
5
+ * An image, speech, or transcription call is one provider `doGenerate()`, so it
6
+ * is the language wrapper's non-streaming path with a different result shape.
7
+ * This file reuses `readEnlittCallOptions()`, `runPremiumCharge()`, the shared
8
+ * price evaluation, and the core's clamp exactly. What it adds is only:
9
+ *
10
+ * - the call identity (the supplied `idempotencyKey` itself, or a fresh random
11
+ * ID; a media call has no growing prompt to count),
12
+ * - the per-kind price context, and
13
+ * - the result mapping (images untouched; speech and transcription gain
14
+ * `providerMetadata.enlitt`).
15
+ *
16
+ * The begin and terminal requests are byte for byte the language wrapper's:
17
+ * there is no modality field on the wire. Nothing about the call's content
18
+ * (prompt, text, audio, images) is ever sent to Enlitt; the price context
19
+ * lives and dies in the business's own process.
20
+ */
21
+ import type { ImageModelV3, ImageModelV4, SpeechModelV3, SpeechModelV4, TranscriptionModelV3, TranscriptionModelV4 } from "@ai-sdk/provider";
22
+ import type { InternalEnlittClient } from "../core/transport.cjs";
23
+ /** What an image model's `doGenerate()` resolves with, derived rather than invented. */
24
+ export type ImageGenerateResult = Awaited<ReturnType<ImageModelV3["doGenerate"]>>;
25
+ /** What a speech model's `doGenerate()` resolves with. */
26
+ export type SpeechGenerateResult = Awaited<ReturnType<SpeechModelV3["doGenerate"]>>;
27
+ /** What a transcription model's `doGenerate()` resolves with. */
28
+ export type TranscriptionGenerateResult = Awaited<ReturnType<TranscriptionModelV3["doGenerate"]>>;
29
+ /** The fields every media price context shares. */
30
+ export interface PremiumMediaPriceBase {
31
+ readonly status: "completed" | "canceled";
32
+ /** When the provider was invoked. */
33
+ readonly startedAt: Date;
34
+ /** When the provider resolved, or when the call was canceled. */
35
+ readonly endedAt: Date;
36
+ readonly durationMs: number;
37
+ /** The most this call can charge; any price above it is lowered to it. */
38
+ readonly effectiveMaxChargeNanoUsd: string;
39
+ }
40
+ /**
41
+ * Everything the SDK knows when a media call ends, discriminated by `kind`.
42
+ * `result` is the provider's own result on `completed` and absent on
43
+ * `canceled`. `request` holds only a few facts read from the call options.
44
+ */
45
+ export type PremiumMediaPriceContext = (PremiumMediaPriceBase & {
46
+ readonly kind: "image";
47
+ readonly request: {
48
+ readonly n: number;
49
+ readonly size?: string;
50
+ readonly aspectRatio?: string;
51
+ };
52
+ readonly result?: ImageGenerateResult;
53
+ }) | (PremiumMediaPriceBase & {
54
+ readonly kind: "speech";
55
+ /** `characters` is the number of Unicode code points in the text to speak. */
56
+ readonly request: {
57
+ readonly characters: number;
58
+ readonly voice?: string;
59
+ readonly outputFormat?: string;
60
+ };
61
+ readonly result?: SpeechGenerateResult;
62
+ }) | (PremiumMediaPriceBase & {
63
+ readonly kind: "transcription";
64
+ readonly request: {
65
+ readonly mediaType: string;
66
+ };
67
+ readonly result?: TranscriptionGenerateResult;
68
+ });
69
+ /**
70
+ * What a premium media call states it costs. Same rules as `EnlittPrice`: a
71
+ * constant is charged on `completed` and `canceled`; a function runs once on
72
+ * either, may be async, and is never called on `failed`.
73
+ */
74
+ export type EnlittMediaPrice = string | ((context: PremiumMediaPriceContext) => string | Promise<string>);
75
+ /** Any of the three media model interfaces the wrapper accepts. */
76
+ export type PremiumMediaModel = ImageModelV3 | ImageModelV4 | SpeechModelV3 | SpeechModelV4 | TranscriptionModelV3 | TranscriptionModelV4;
77
+ /**
78
+ * Wraps an image model (`kind: "image"`), or a speech or transcription model
79
+ * (`kind: "audio"`), with the premium billing lifecycle.
80
+ *
81
+ * Returns a new object carrying the wrapped model's `specificationVersion`,
82
+ * `provider`, and `modelId`, plus an image model's `maxImagesPerCall` forwarded
83
+ * by reference (a function stays a function, called with the wrapped model as
84
+ * `this`). Only `doGenerate` is replaced. The provider is never invoked before
85
+ * Enlitt admits the call: every session and refusal path is
86
+ * `runPremiumCharge()`'s.
87
+ *
88
+ * Speech and transcription models have the same structural shape, so for
89
+ * `kind: "audio"` each call decides which it is from its own options.
90
+ *
91
+ * A `v4` model (`ai@7`, Bug #28) is wrapped as a `v4` model. The call options
92
+ * and results this file reads exist in both versions, so the body is written
93
+ * once against the `v3` types. A v4 image model's `supportsFileInputs` and
94
+ * `supportsMaskInputs` are forwarded; a v4 transcription model's
95
+ * `doGenerateFromUrl` and `doStream`, and a streaming speech model's
96
+ * `doStream`, are deliberately not exposed, because they would call the
97
+ * provider without an Enlitt operation. `ai` then downloads a URL itself and
98
+ * calls `doGenerate`, and reports streaming as unsupported by the model.
99
+ */
100
+ export declare function createPremiumMediaModel(client: InternalEnlittClient, model: ImageModelV3 | ImageModelV4, kind: "image"): ImageModelV3 | ImageModelV4;
101
+ export declare function createPremiumMediaModel(client: InternalEnlittClient, model: SpeechModelV3 | SpeechModelV4 | TranscriptionModelV3 | TranscriptionModelV4, kind: "audio"): SpeechModelV3 | SpeechModelV4 | TranscriptionModelV3 | TranscriptionModelV4;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Premium for non-language Vercel models: image generation, text-to-speech, and
3
+ * speech-to-text (owner decision 2026-11-15).
4
+ *
5
+ * An image, speech, or transcription call is one provider `doGenerate()`, so it
6
+ * is the language wrapper's non-streaming path with a different result shape.
7
+ * This file reuses `readEnlittCallOptions()`, `runPremiumCharge()`, the shared
8
+ * price evaluation, and the core's clamp exactly. What it adds is only:
9
+ *
10
+ * - the call identity (the supplied `idempotencyKey` itself, or a fresh random
11
+ * ID; a media call has no growing prompt to count),
12
+ * - the per-kind price context, and
13
+ * - the result mapping (images untouched; speech and transcription gain
14
+ * `providerMetadata.enlitt`).
15
+ *
16
+ * The begin and terminal requests are byte for byte the language wrapper's:
17
+ * there is no modality field on the wire. Nothing about the call's content
18
+ * (prompt, text, audio, images) is ever sent to Enlitt; the price context
19
+ * lives and dies in the business's own process.
20
+ */
21
+ import type { ImageModelV3, ImageModelV4, SpeechModelV3, SpeechModelV4, TranscriptionModelV3, TranscriptionModelV4 } from "@ai-sdk/provider";
22
+ import type { InternalEnlittClient } from "../core/transport.js";
23
+ /** What an image model's `doGenerate()` resolves with, derived rather than invented. */
24
+ export type ImageGenerateResult = Awaited<ReturnType<ImageModelV3["doGenerate"]>>;
25
+ /** What a speech model's `doGenerate()` resolves with. */
26
+ export type SpeechGenerateResult = Awaited<ReturnType<SpeechModelV3["doGenerate"]>>;
27
+ /** What a transcription model's `doGenerate()` resolves with. */
28
+ export type TranscriptionGenerateResult = Awaited<ReturnType<TranscriptionModelV3["doGenerate"]>>;
29
+ /** The fields every media price context shares. */
30
+ export interface PremiumMediaPriceBase {
31
+ readonly status: "completed" | "canceled";
32
+ /** When the provider was invoked. */
33
+ readonly startedAt: Date;
34
+ /** When the provider resolved, or when the call was canceled. */
35
+ readonly endedAt: Date;
36
+ readonly durationMs: number;
37
+ /** The most this call can charge; any price above it is lowered to it. */
38
+ readonly effectiveMaxChargeNanoUsd: string;
39
+ }
40
+ /**
41
+ * Everything the SDK knows when a media call ends, discriminated by `kind`.
42
+ * `result` is the provider's own result on `completed` and absent on
43
+ * `canceled`. `request` holds only a few facts read from the call options.
44
+ */
45
+ export type PremiumMediaPriceContext = (PremiumMediaPriceBase & {
46
+ readonly kind: "image";
47
+ readonly request: {
48
+ readonly n: number;
49
+ readonly size?: string;
50
+ readonly aspectRatio?: string;
51
+ };
52
+ readonly result?: ImageGenerateResult;
53
+ }) | (PremiumMediaPriceBase & {
54
+ readonly kind: "speech";
55
+ /** `characters` is the number of Unicode code points in the text to speak. */
56
+ readonly request: {
57
+ readonly characters: number;
58
+ readonly voice?: string;
59
+ readonly outputFormat?: string;
60
+ };
61
+ readonly result?: SpeechGenerateResult;
62
+ }) | (PremiumMediaPriceBase & {
63
+ readonly kind: "transcription";
64
+ readonly request: {
65
+ readonly mediaType: string;
66
+ };
67
+ readonly result?: TranscriptionGenerateResult;
68
+ });
69
+ /**
70
+ * What a premium media call states it costs. Same rules as `EnlittPrice`: a
71
+ * constant is charged on `completed` and `canceled`; a function runs once on
72
+ * either, may be async, and is never called on `failed`.
73
+ */
74
+ export type EnlittMediaPrice = string | ((context: PremiumMediaPriceContext) => string | Promise<string>);
75
+ /** Any of the three media model interfaces the wrapper accepts. */
76
+ export type PremiumMediaModel = ImageModelV3 | ImageModelV4 | SpeechModelV3 | SpeechModelV4 | TranscriptionModelV3 | TranscriptionModelV4;
77
+ /**
78
+ * Wraps an image model (`kind: "image"`), or a speech or transcription model
79
+ * (`kind: "audio"`), with the premium billing lifecycle.
80
+ *
81
+ * Returns a new object carrying the wrapped model's `specificationVersion`,
82
+ * `provider`, and `modelId`, plus an image model's `maxImagesPerCall` forwarded
83
+ * by reference (a function stays a function, called with the wrapped model as
84
+ * `this`). Only `doGenerate` is replaced. The provider is never invoked before
85
+ * Enlitt admits the call: every session and refusal path is
86
+ * `runPremiumCharge()`'s.
87
+ *
88
+ * Speech and transcription models have the same structural shape, so for
89
+ * `kind: "audio"` each call decides which it is from its own options.
90
+ *
91
+ * A `v4` model (`ai@7`, Bug #28) is wrapped as a `v4` model. The call options
92
+ * and results this file reads exist in both versions, so the body is written
93
+ * once against the `v3` types. A v4 image model's `supportsFileInputs` and
94
+ * `supportsMaskInputs` are forwarded; a v4 transcription model's
95
+ * `doGenerateFromUrl` and `doStream`, and a streaming speech model's
96
+ * `doStream`, are deliberately not exposed, because they would call the
97
+ * provider without an Enlitt operation. `ai` then downloads a URL itself and
98
+ * calls `doGenerate`, and reports streaming as unsupported by the model.
99
+ */
100
+ export declare function createPremiumMediaModel(client: InternalEnlittClient, model: ImageModelV3 | ImageModelV4, kind: "image"): ImageModelV3 | ImageModelV4;
101
+ export declare function createPremiumMediaModel(client: InternalEnlittClient, model: SpeechModelV3 | SpeechModelV4 | TranscriptionModelV3 | TranscriptionModelV4, kind: "audio"): SpeechModelV3 | SpeechModelV4 | TranscriptionModelV3 | TranscriptionModelV4;
102
+ //# sourceMappingURL=premium-media-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"premium-media-model.d.ts","sourceRoot":"","sources":["../../src/vercel/premium-media-model.ts"],"names":[],"mappings":"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"}
@@ -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 {};