@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,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 chunk2BGWYTJM_cjs = require('./chunk-2BGWYTJM.cjs');
4
+ require('./chunk-6OWXYBBT.cjs');
5
+ require('./chunk-PPOUNWNA.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "ENLITT_STANDARD_MODEL", {
10
+ enumerable: true,
11
+ get: function () { return chunk2BGWYTJM_cjs.ENLITT_STANDARD_MODEL; }
12
+ });
13
+ Object.defineProperty(exports, "enlitt", {
14
+ enumerable: true,
15
+ get: function () { return chunk2BGWYTJM_cjs.enlitt; }
16
+ });
17
+ Object.defineProperty(exports, "perToken", {
18
+ enumerable: true,
19
+ get: function () { return chunk2BGWYTJM_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-UVZMKGIL.js';
2
+ import './chunk-V5TCSQ7C.js';
3
+ import './chunk-O6ASIA3X.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,142 @@
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.1",
4
+ "description": "Official TypeScript SDK for Enlitt",
5
+ "homepage": "https://enlitt.com/docs",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/enlitt/sdk.git",
9
+ "directory": "packages/sdk"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/enlitt/sdk/issues"
13
+ },
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "CHANGELOG.md"
21
+ ],
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "require": {
32
+ "types": "./dist/index.d.cts",
33
+ "default": "./dist/index.cjs"
34
+ }
35
+ },
36
+ "./browser": {
37
+ "import": {
38
+ "types": "./dist/browser.d.ts",
39
+ "default": "./dist/browser.js"
40
+ },
41
+ "require": {
42
+ "types": "./dist/browser.d.cts",
43
+ "default": "./dist/browser.cjs"
44
+ }
45
+ },
46
+ "./core": {
47
+ "browser": "./dist/server-unavailable.js",
48
+ "import": {
49
+ "types": "./dist/core/index.d.ts",
50
+ "default": "./dist/core.js"
51
+ },
52
+ "require": {
53
+ "types": "./dist/core/index.d.cts",
54
+ "default": "./dist/core.cjs"
55
+ }
56
+ },
57
+ "./vercel": {
58
+ "browser": "./dist/server-unavailable.js",
59
+ "import": {
60
+ "types": "./dist/vercel/index.d.ts",
61
+ "default": "./dist/vercel.js"
62
+ },
63
+ "require": {
64
+ "types": "./dist/vercel/index.d.cts",
65
+ "default": "./dist/vercel.cjs"
66
+ }
67
+ },
68
+ "./openai": {
69
+ "browser": "./dist/server-unavailable.js",
70
+ "import": {
71
+ "types": "./dist/openai/index.d.ts",
72
+ "default": "./dist/openai.js"
73
+ },
74
+ "require": {
75
+ "types": "./dist/openai/index.d.cts",
76
+ "default": "./dist/openai.cjs"
77
+ }
78
+ },
79
+ "./server": {
80
+ "browser": "./dist/server-unavailable.js",
81
+ "import": {
82
+ "types": "./dist/server/index.d.ts",
83
+ "default": "./dist/server.js"
84
+ },
85
+ "require": {
86
+ "types": "./dist/server/index.d.cts",
87
+ "default": "./dist/server.cjs"
88
+ }
89
+ },
90
+ "./package.json": "./package.json"
91
+ },
92
+ "engines": {
93
+ "node": ">=22"
94
+ },
95
+ "publishConfig": {
96
+ "access": "public"
97
+ },
98
+ "devDependencies": {
99
+ "@ai-sdk/provider": "4.0.10",
100
+ "@arethetypeswrong/cli": "^0.18.5",
101
+ "@types/node": "^24.13.3",
102
+ "ai": "6.0.209",
103
+ "openai": "7.27.0",
104
+ "publint": "^0.3.25",
105
+ "tsup": "^8.5.1",
106
+ "typescript": "^7.0.2",
107
+ "vitest": "^4.1.11"
108
+ },
109
+ "dependencies": {
110
+ "@enlitt/protocol": "0.1.1"
111
+ },
112
+ "peerDependencies": {
113
+ "openai": "^7.27.0"
114
+ },
115
+ "typesVersions": {
116
+ "*": {
117
+ "browser": [
118
+ "dist/browser.d.ts"
119
+ ],
120
+ "core": [
121
+ "dist/core/index.d.ts"
122
+ ],
123
+ "vercel": [
124
+ "dist/vercel/index.d.ts"
125
+ ],
126
+ "openai": [
127
+ "dist/openai/index.d.ts"
128
+ ],
129
+ "server": [
130
+ "dist/server/index.d.ts"
131
+ ]
132
+ }
133
+ },
134
+ "scripts": {
135
+ "dev": "tsup --watch",
136
+ "build": "tsup && tsc -p tsconfig.build.json && node scripts/emit-cts-declarations.mjs",
137
+ "typecheck": "tsc --noEmit",
138
+ "lint": "eslint .",
139
+ "test": "vitest run",
140
+ "test:package": "rm -rf .pack && pnpm --config.ignore-scripts=true pack --pack-destination .pack > /dev/null && publint .pack/*.tgz && attw .pack/*.tgz --profile node16"
141
+ }
6
142
  }