@vite-hub/runtime 0.0.4 → 0.3.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.
- package/README.md +278 -41
- package/dist/durability.d.ts +107 -0
- package/dist/durability.js +168 -0
- package/dist/error-diagnostics-BKICpwZp.js +85 -0
- package/dist/error-diagnostics-BsJr9VdW.d.ts +15 -0
- package/dist/errors-BEomN3fX.js +190 -0
- package/dist/execution-budget-BPXbISEt.d.ts +56 -0
- package/dist/index-Bcl-Hr-a.d.ts +678 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -1159
- package/dist/internal/drain.d.ts +17 -0
- package/dist/internal/drain.js +75 -0
- package/dist/internal/execution-budget.d.ts +10 -0
- package/dist/internal/execution-budget.js +17 -0
- package/dist/internal/grant.d.ts +36 -0
- package/dist/internal/grant.js +44 -0
- package/dist/internal/h3.d.ts +42 -0
- package/dist/internal/h3.js +181 -0
- package/dist/internal/node.d.ts +33 -0
- package/dist/{node.js → internal/node.js} +12 -9
- package/dist/internal/public-url.d.ts +2 -0
- package/dist/internal/public-url.js +2 -0
- package/dist/internal/run-scope.d.ts +11 -0
- package/dist/internal/run-scope.js +30 -0
- package/dist/internal/runtime-type.d.ts +26 -0
- package/dist/internal/runtime-type.js +3 -0
- package/dist/internal/shutdown.d.ts +84 -0
- package/dist/internal/shutdown.js +202 -0
- package/dist/internal/test-mode-setup.d.ts +7 -0
- package/dist/internal/test-mode-setup.js +114 -0
- package/dist/internal/test-mode.d.ts +32 -0
- package/dist/internal/test-mode.js +9 -0
- package/dist/operations.d.ts +167 -0
- package/dist/operations.js +406 -0
- package/dist/public-url-1WeOw54Z.d.ts +34 -0
- package/dist/public-url-B6x0HMgY.js +140 -0
- package/dist/request-context-CP9NhgLL.js +2274 -0
- package/dist/runtime-type-BftydMAf.js +88 -0
- package/package.json +92 -17
- package/dist/drain.d.ts +0 -1
- package/dist/drain.js +0 -52
- package/dist/index-tBKyUP1T.d.ts +0 -314
- package/dist/node.d.ts +0 -35
- package/dist/runtime-type-ovvOd6m5.js +0 -37
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { defineDiagnostics } from "nostics";
|
|
2
|
+
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
3
|
+
//#region ../internal/dist/error-diagnostics-NFLF9k-4.js
|
|
4
|
+
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
5
|
+
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
6
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
7
|
+
codes: {
|
|
8
|
+
INTERNAL_R0012: {
|
|
9
|
+
...dynamicError,
|
|
10
|
+
fix: "Check the URL, the headers, and the credentials of the HTTP request. `error.status` holds the status that the server sent."
|
|
11
|
+
},
|
|
12
|
+
INTERNAL_R0013: {
|
|
13
|
+
...dynamicError,
|
|
14
|
+
fix: "Check that the provider token can manage the resource in the path that the message names. `error.kind` and `error.codes` hold the provider failure."
|
|
15
|
+
},
|
|
16
|
+
INTERNAL_R0014: {
|
|
17
|
+
why: ({ path }) => `Cannot read Provision State from "${path}".`,
|
|
18
|
+
fix: "Check file access and restore valid JSON while preserving existing resource IDs."
|
|
19
|
+
},
|
|
20
|
+
INTERNAL_R0020: {
|
|
21
|
+
fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
|
|
22
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
23
|
+
},
|
|
24
|
+
INTERNAL_R0021: {
|
|
25
|
+
fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
|
|
26
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
27
|
+
},
|
|
28
|
+
INTERNAL_R0022: {
|
|
29
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
30
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
31
|
+
},
|
|
32
|
+
INTERNAL_R0024: {
|
|
33
|
+
fix: "Start the dev server with `vite dev`, or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
|
|
34
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
35
|
+
},
|
|
36
|
+
INTERNAL_R0023: {
|
|
37
|
+
fix: "Ask for access to the section of this operation.",
|
|
38
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
39
|
+
},
|
|
40
|
+
INTERNAL_B0001: {
|
|
41
|
+
...dynamicError,
|
|
42
|
+
fix: "Give the resource that the message names another name or binding in the `vitehub()` options of its feature, so that two different Cloudflare resources do not share one name."
|
|
43
|
+
},
|
|
44
|
+
INTERNAL_B0015: {
|
|
45
|
+
...dynamicError,
|
|
46
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
47
|
+
},
|
|
48
|
+
INTERNAL_B0016: {
|
|
49
|
+
...dynamicError,
|
|
50
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
51
|
+
},
|
|
52
|
+
INTERNAL_B0017: {
|
|
53
|
+
...dynamicError,
|
|
54
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
55
|
+
},
|
|
56
|
+
INTERNAL_B0018: {
|
|
57
|
+
...dynamicError,
|
|
58
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
59
|
+
},
|
|
60
|
+
INTERNAL_B0019: {
|
|
61
|
+
...dynamicError,
|
|
62
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
63
|
+
},
|
|
64
|
+
INTERNAL_B0020: {
|
|
65
|
+
...dynamicError,
|
|
66
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
67
|
+
},
|
|
68
|
+
INTERNAL_B0021: {
|
|
69
|
+
...dynamicError,
|
|
70
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
71
|
+
},
|
|
72
|
+
INTERNAL_B0022: {
|
|
73
|
+
...dynamicError,
|
|
74
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
75
|
+
},
|
|
76
|
+
INTERNAL_B0025: {
|
|
77
|
+
...dynamicError,
|
|
78
|
+
fix: "Replace the `new URL(\"./...\", import.meta.url)` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` of that file."
|
|
79
|
+
},
|
|
80
|
+
INTERNAL_B0026: {
|
|
81
|
+
...dynamicError,
|
|
82
|
+
fix: "Replace the computed `import()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` or with `import(\"<literal path>\")`."
|
|
83
|
+
},
|
|
84
|
+
INTERNAL_B0027: {
|
|
85
|
+
...dynamicError,
|
|
86
|
+
fix: "Replace the computed `require()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import`."
|
|
87
|
+
},
|
|
88
|
+
INTERNAL_B0028: {
|
|
89
|
+
...dynamicError,
|
|
90
|
+
fix: "Wait for the other build of this app to finish, or stop the process that the message names, then build again."
|
|
91
|
+
},
|
|
92
|
+
INTERNAL_B0029: {
|
|
93
|
+
...dynamicError,
|
|
94
|
+
fix: "Stop the other builds that write the same Deno output folder, delete the `.vitehub-lock` folder next to that output folder, such as `.output.vitehub-lock`, then build again."
|
|
95
|
+
},
|
|
96
|
+
INTERNAL_B0031: {
|
|
97
|
+
...dynamicError,
|
|
98
|
+
fix: "Import `./schedule/deno-cron.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./schedule/deno-cron.mjs\", import.meta.url).href)` outside any condition."
|
|
99
|
+
},
|
|
100
|
+
INTERNAL_B0032: {
|
|
101
|
+
...dynamicError,
|
|
102
|
+
fix: "Import `./server/index.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./server/index.mjs\", import.meta.url).href)` outside any condition."
|
|
103
|
+
},
|
|
104
|
+
INTERNAL_B0035: {
|
|
105
|
+
...dynamicError,
|
|
106
|
+
fix: "Delete the provider output folder that holds the file that the message names, such as `dist/<app>` for Cloudflare, and build again."
|
|
107
|
+
},
|
|
108
|
+
INTERNAL_B0039: {
|
|
109
|
+
...dynamicError,
|
|
110
|
+
fix: "Fix the build error that ViteHub showed before this one. ViteHub stops writing the provider output when another part of the build fails."
|
|
111
|
+
},
|
|
112
|
+
INTERNAL_B0040: {
|
|
113
|
+
...dynamicError,
|
|
114
|
+
fix: "Remove the custom Nitro `output.serverDir`, so that the Nitro preset of the host writes the server entry that the message names."
|
|
115
|
+
},
|
|
116
|
+
INTERNAL_B0043: {
|
|
117
|
+
...dynamicError,
|
|
118
|
+
fix: "Delete the build output folder, such as `.output` or `.vercel/output`, and build again."
|
|
119
|
+
},
|
|
120
|
+
INTERNAL_B0046: {
|
|
121
|
+
...dynamicError,
|
|
122
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
123
|
+
},
|
|
124
|
+
INTERNAL_B0047: {
|
|
125
|
+
...dynamicError,
|
|
126
|
+
fix: "Correct the `package.json` file that the message names so that it holds one JSON object, or run `pnpm install` again to restore an installed package."
|
|
127
|
+
},
|
|
128
|
+
INTERNAL_B0048: {
|
|
129
|
+
fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
|
|
130
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
131
|
+
},
|
|
132
|
+
INTERNAL_B0049: {
|
|
133
|
+
fix: "Set `cli: { namespace, command }` on one of the two operations.",
|
|
134
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
135
|
+
},
|
|
136
|
+
INTERNAL_B0050: {
|
|
137
|
+
fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
|
|
138
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
139
|
+
},
|
|
140
|
+
INTERNAL_B0051: {
|
|
141
|
+
why: ({ field, generated, name, path, project, scope }) => `The Cloudflare ${path} entry "${name}"${scope} is written by ViteHub and by the project's Wrangler config with a different ${field}: ${generated} and ${project}.`,
|
|
142
|
+
fix: "Remove the entry from the project's Wrangler config, since ViteHub writes it, or give one of them another name."
|
|
143
|
+
},
|
|
144
|
+
INTERNAL_B0052: {
|
|
145
|
+
why: ({ column, section }) => `The column "${column}" of the Console section "${section}" needs both \`format: "switch"\` and a \`switch\` operation name such as "skills.set".`,
|
|
146
|
+
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
147
|
+
},
|
|
148
|
+
INTERNAL_R0025: {
|
|
149
|
+
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
150
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
151
|
+
},
|
|
152
|
+
INTERNAL_R0026: {
|
|
153
|
+
why: "The server parsed a destructive operation that the CLI did not confirm.",
|
|
154
|
+
fix: "Review the operation, then run it again with --yes to confirm the change."
|
|
155
|
+
},
|
|
156
|
+
INTERNAL_C0001: {
|
|
157
|
+
...dynamicError,
|
|
158
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
159
|
+
},
|
|
160
|
+
INTERNAL_C0002: {
|
|
161
|
+
...dynamicError,
|
|
162
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
163
|
+
},
|
|
164
|
+
INTERNAL_R0001: {
|
|
165
|
+
...dynamicError,
|
|
166
|
+
fix: "Set `host` in `vitehub()`, or in the `vitehub` options of `nuxt.config.ts`, to `cloudflare`, `deno`, `netlify`, `node`, or `vercel`. Or remove `host` so that ViteHub finds the host from the environment."
|
|
167
|
+
},
|
|
168
|
+
INTERNAL_R0002: {
|
|
169
|
+
...dynamicError,
|
|
170
|
+
fix: "Stop using the feature that the message names, or set `host` in `vitehub()` to a host that provides it. For Blob, you can also set `blob: { driver: \"s3\" }` with a remote store."
|
|
171
|
+
},
|
|
172
|
+
INTERNAL_R0004: {
|
|
173
|
+
...dynamicError,
|
|
174
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `fetch()` Source options, or ask the server for a smaller response."
|
|
175
|
+
},
|
|
176
|
+
INTERNAL_R0005: {
|
|
177
|
+
...dynamicError,
|
|
178
|
+
fix: "Set `method` of the HTTP request to `GET`, `HEAD`, or `POST`."
|
|
179
|
+
},
|
|
180
|
+
INTERNAL_R0006: {
|
|
181
|
+
...dynamicError,
|
|
182
|
+
fix: "Set `timeout` of the HTTP request to a number of milliseconds from 1 to 2147483647, or remove it to use the default."
|
|
183
|
+
},
|
|
184
|
+
INTERNAL_R0007: {
|
|
185
|
+
...dynamicError,
|
|
186
|
+
fix: "Set `maxResponseBytes` of the HTTP request to a positive integer no greater than the limit that the message names, or remove it to use the default."
|
|
187
|
+
},
|
|
188
|
+
INTERNAL_R0008: {
|
|
189
|
+
...dynamicError,
|
|
190
|
+
fix: "Make the value that the message names match its schema: the input, query, or body that you send, or the response schema that you declare for the request."
|
|
191
|
+
},
|
|
192
|
+
INTERNAL_R0009: {
|
|
193
|
+
...dynamicError,
|
|
194
|
+
fix: "Use a Standard Schema whose `validate()` returns `{ value }` or `{ issues }` for the value that the message names."
|
|
195
|
+
},
|
|
196
|
+
INTERNAL_R0010: {
|
|
197
|
+
...dynamicError,
|
|
198
|
+
fix: "Run the command again. If the error stays, check the Cloudflare API status, because Cloudflare sent a response that ViteHub cannot read."
|
|
199
|
+
},
|
|
200
|
+
INTERNAL_R0011: {
|
|
201
|
+
...dynamicError,
|
|
202
|
+
fix: "Pass an h3 app, an object with a `fetch(request)` method, or a fetch function as `app`."
|
|
203
|
+
},
|
|
204
|
+
INTERNAL_CONSOLE_KEY_NAME_INVALID: {
|
|
205
|
+
why: ({ name }) => `[vitehub] The Console key name ${JSON.stringify(name)} must be 1 to 64 of A-Z, 0-9, and _.`,
|
|
206
|
+
fix: "Name the Console key with 1 to 64 characters from A-Z, 0-9, and _, such as `CI`. The app reads its public key from `VITEHUB_CONSOLE_KEY_<NAME>`."
|
|
207
|
+
},
|
|
208
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_INVALID: {
|
|
209
|
+
why: "[vitehub] A Console private key is the 32-byte Ed25519 seed as base64url (43 characters). `vitehub secret console-key` makes one.",
|
|
210
|
+
fix: "Run `vitehub secret console-key` and use the 43-character private key that it prints, without spaces or quotes."
|
|
211
|
+
},
|
|
212
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLES_MULTIPLE: {
|
|
213
|
+
why: ({ prefix, variables }) => `[vitehub] Set one ${prefix}<NAME> variable. This environment has ${variables}.`,
|
|
214
|
+
fix: "Keep one `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` variable in the environment of the command, and unset the others that the message names."
|
|
215
|
+
},
|
|
216
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLE_INVALID: {
|
|
217
|
+
why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
|
|
218
|
+
fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
|
|
219
|
+
},
|
|
220
|
+
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
221
|
+
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
222
|
+
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
223
|
+
},
|
|
224
|
+
INTERNAL_MCP_ARGUMENTS_INVALID: {
|
|
225
|
+
why: ({ detail }) => detail,
|
|
226
|
+
fix: "Pass the prompt or resource the arguments that `prompts/list` or `resources/templates/list` describes for it."
|
|
227
|
+
},
|
|
228
|
+
INTERNAL_MCP_METHOD_FAILED: {
|
|
229
|
+
why: ({ name }) => `${name} failed on the server.`,
|
|
230
|
+
fix: "Read the server log for the error of the MCP prompt or resource that the message names, and fix its handler."
|
|
231
|
+
},
|
|
232
|
+
INTERNAL_MCP_RESOURCE_NOT_FOUND: {
|
|
233
|
+
why: ({ uri }) => `Resource not found: ${uri}. Call resources/list or resources/templates/list for the resources of this server.`,
|
|
234
|
+
fix: "Call `resources/list` or `resources/templates/list`, and read a URI that one of them returns."
|
|
235
|
+
},
|
|
236
|
+
INTERNAL_PRESET_OPTION_UNKNOWN: {
|
|
237
|
+
why: ({ key, label }) => `[vitehub] Unknown ${label} option "${key}".`,
|
|
238
|
+
fix: "Remove the option that the message names from the preset options, or correct its spelling to an option that the preset declares."
|
|
239
|
+
},
|
|
240
|
+
INTERNAL_PRESET_TUPLE_INVALID: {
|
|
241
|
+
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
242
|
+
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
243
|
+
},
|
|
244
|
+
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
245
|
+
why: "[vitehub] A derived secret requires a purpose.",
|
|
246
|
+
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
247
|
+
},
|
|
248
|
+
INTERNAL_SECRET_TOO_SHORT: {
|
|
249
|
+
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
250
|
+
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
251
|
+
},
|
|
252
|
+
INTERNAL_SQLITE_ARGUMENT_INVALID: {
|
|
253
|
+
why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
|
|
254
|
+
fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
|
|
255
|
+
},
|
|
256
|
+
INTERNAL_SQLITE_INTEGER_UNSAFE: {
|
|
257
|
+
why: "Received integer which cannot be safely represented as a JavaScript number",
|
|
258
|
+
fix: "Create the client with `intMode: \"bigint\"` or `intMode: \"string\"`, or read the column with `CAST(column AS TEXT)` in the query."
|
|
259
|
+
},
|
|
260
|
+
INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED: {
|
|
261
|
+
why: ({ target }) => `[vitehub] Valibot cannot convert a schema to the ${target} JSON Schema target.`,
|
|
262
|
+
fix: "Ask for the `draft-07`, `draft-2020-12`, or `openapi-3.0` JSON Schema target, or pass one of them as `withValibotJsonSchema(schema, { target })`."
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region ../internal/dist/object.js
|
|
268
|
+
/** A non-null object or a function that is not an array. */
|
|
269
|
+
function isRecordOrFunction(value) {
|
|
270
|
+
return Object(value) === value && !Array.isArray(value);
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region ../internal/dist/standard-schema.js
|
|
274
|
+
function readOwn(value, key) {
|
|
275
|
+
if (value === null || Object(value) !== value) return;
|
|
276
|
+
try {
|
|
277
|
+
return Reflect.get(Object(value), key);
|
|
278
|
+
} catch {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Read a Standard JSON Schema projection without throwing.
|
|
284
|
+
*
|
|
285
|
+
* Returns `undefined` when the schema has no `~standard.jsonSchema`, when the library cannot represent the type
|
|
286
|
+
* (Zod throws for `Date`), or when the projection is not an object. Callers decide how to fall back.
|
|
287
|
+
*/
|
|
288
|
+
function standardJsonSchema(schema, direction, target = "draft-2020-12", libraryOptions) {
|
|
289
|
+
const jsonSchema = readOwn(readOwn(schema, "~standard"), "jsonSchema");
|
|
290
|
+
const project = readOwn(jsonSchema, direction);
|
|
291
|
+
if (typeof project !== "function") return;
|
|
292
|
+
try {
|
|
293
|
+
const result = project.call(jsonSchema, libraryOptions ? {
|
|
294
|
+
target,
|
|
295
|
+
libraryOptions
|
|
296
|
+
} : { target });
|
|
297
|
+
return isRecordOrFunction(result) ? result : void 0;
|
|
298
|
+
} catch {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region ../internal/dist/valibot.js
|
|
304
|
+
const valibotTargets = /* @__PURE__ */ new Set([
|
|
305
|
+
"draft-07",
|
|
306
|
+
"draft-2020-12",
|
|
307
|
+
"openapi-3.0"
|
|
308
|
+
]);
|
|
309
|
+
function isValibotTarget(value) {
|
|
310
|
+
return valibotTargets.has(String(value));
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Add Standard JSON Schema conversion to a plain Valibot schema. Valibot schemas validate as Standard Schema but carry
|
|
314
|
+
* no JSON Schema, so forms, tools, and model providers would get no shape for them. Other schemas, Valibot schemas that
|
|
315
|
+
* already convert, and async Valibot schemas return unchanged. The copy keeps every Valibot property, so validation
|
|
316
|
+
* does not change.
|
|
317
|
+
*
|
|
318
|
+
* `target` fixes the JSON Schema dialect. Without it, each conversion uses the dialect that the caller asks for.
|
|
319
|
+
*/
|
|
320
|
+
function withValibotJsonSchema(schema, options = {}) {
|
|
321
|
+
const standard = schema["~standard"];
|
|
322
|
+
if (standard.vendor !== "valibot" || Reflect.get(schema, "async") === true) return schema;
|
|
323
|
+
if (Object.hasOwn(standard, "jsonSchema") && standard.jsonSchema) return schema;
|
|
324
|
+
const convert = (typeMode) => (request) => {
|
|
325
|
+
const target = options.target ?? request.target;
|
|
326
|
+
if (!isValibotTarget(target)) throw internalErrorDiagnostics.INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED({ target: String(target) });
|
|
327
|
+
return toJsonSchema(schema, {
|
|
328
|
+
target,
|
|
329
|
+
typeMode,
|
|
330
|
+
errorMode: "ignore"
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
return {
|
|
334
|
+
...schema,
|
|
335
|
+
"~standard": {
|
|
336
|
+
...standard,
|
|
337
|
+
jsonSchema: {
|
|
338
|
+
input: convert("input"),
|
|
339
|
+
output: convert("output")
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region ../internal/dist/operation-definition.js
|
|
346
|
+
const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
|
|
347
|
+
const kinds = /* @__PURE__ */ new Set([
|
|
348
|
+
"read",
|
|
349
|
+
"write",
|
|
350
|
+
"destructive"
|
|
351
|
+
]);
|
|
352
|
+
function invalidDefinition(name, reason) {
|
|
353
|
+
return internalErrorDiagnostics.INTERNAL_R0020({ message: `[vitehub] Operation ${JSON.stringify(name)} is invalid: ${reason}` });
|
|
354
|
+
}
|
|
355
|
+
function checkDefinition(definition) {
|
|
356
|
+
if (!isRecordOrFunction(definition)) throw invalidDefinition(void 0, "defineOperation() takes an object.");
|
|
357
|
+
const { name } = definition;
|
|
358
|
+
if (String(name) !== name || !nameFormat.test(name)) throw invalidDefinition(name, "the name must look like `section.verb`, in lower case.");
|
|
359
|
+
if (String(definition.description) !== definition.description || !definition.description) throw invalidDefinition(name, "add a one sentence description.");
|
|
360
|
+
const { section } = definition;
|
|
361
|
+
if (section !== false && !(section instanceof Function) && !isSectionId(section)) throw invalidDefinition(name, "section must be a Console section id, a function, or false; section ids cannot contain ':'.");
|
|
362
|
+
if (definition.scope !== void 0 && (!(definition.scope instanceof Function) || String(section) !== section)) throw invalidDefinition(name, "scope must be a function, and it needs a section id.");
|
|
363
|
+
if (!kinds.has(String(definition.kind))) throw invalidDefinition(name, "kind must be \"read\", \"write\", or \"destructive\".");
|
|
364
|
+
const input = definition.input;
|
|
365
|
+
if (!isRecordOrFunction(input) || !isRecordOrFunction(input["~standard"]) || !(input["~standard"].validate instanceof Function)) throw invalidDefinition(name, "input must be a Standard Schema, such as a valibot object.");
|
|
366
|
+
if (!(definition.run instanceof Function)) throw invalidDefinition(name, "run must be a function.");
|
|
367
|
+
const { maxRequestBytes } = definition;
|
|
368
|
+
if (maxRequestBytes !== void 0 && (!Number.isInteger(maxRequestBytes) || Number(maxRequestBytes) < 65536)) throw invalidDefinition(name, `maxRequestBytes can only raise the limit above ${defaultRequestBytes} bytes (64 KiB).`);
|
|
369
|
+
if (definition.readOnlyWhen !== void 0 && !(definition.readOnlyWhen instanceof Function)) throw invalidDefinition(name, "readOnlyWhen must be a function.");
|
|
370
|
+
const { mcp } = definition;
|
|
371
|
+
if (mcp !== void 0 && mcp !== false && (!isRecordOrFunction(mcp) || mcp.title !== void 0 && (String(mcp.title) !== mcp.title || !mcp.title) || mcp.format !== void 0 && !(mcp.format instanceof Function))) throw invalidDefinition(name, "mcp must be false, or an object with a title string and a format function.");
|
|
372
|
+
}
|
|
373
|
+
/** The default limit of a call, in bytes. */
|
|
374
|
+
const defaultRequestBytes = 65536;
|
|
375
|
+
/** Input keys that the generated CLI commands read themselves. */
|
|
376
|
+
const reservedOperationFlags = [
|
|
377
|
+
"input",
|
|
378
|
+
"json",
|
|
379
|
+
"timeout",
|
|
380
|
+
"url",
|
|
381
|
+
"yes"
|
|
382
|
+
];
|
|
383
|
+
/**
|
|
384
|
+
* Define one operation. The Console, the CLI, MCP, and agent tools call the same definition. Contribute it with
|
|
385
|
+
* `vitehub: { operations: [{ module, export }] }` on a Vite plugin.
|
|
386
|
+
*/
|
|
387
|
+
function defineOperation(definition) {
|
|
388
|
+
checkDefinition(definition);
|
|
389
|
+
const defined = {
|
|
390
|
+
...definition,
|
|
391
|
+
input: withValibotJsonSchema(definition.input)
|
|
392
|
+
};
|
|
393
|
+
const properties = operationInputJsonSchema(defined).properties;
|
|
394
|
+
const clashes = isRecordOrFunction(properties) ? Object.keys(properties).filter((key) => reservedOperationFlags.includes(key)) : [];
|
|
395
|
+
if (clashes.length) throw invalidDefinition(definition.name, `the input key ${clashes.map((key) => JSON.stringify(key)).join(", ")} is a CLI flag of every command (${reservedOperationFlags.join(", ")}). Rename it.`);
|
|
396
|
+
return defined;
|
|
397
|
+
}
|
|
398
|
+
function isSectionId(section) {
|
|
399
|
+
return typeof section === "string" && section !== "" && !section.includes(":");
|
|
400
|
+
}
|
|
401
|
+
/** JSON Schema of the input, for CLI flags and MCP tool schemas. Falls back to an open object. */
|
|
402
|
+
function operationInputJsonSchema(operation) {
|
|
403
|
+
return standardJsonSchema(operation.input, "input") ?? { type: "object" };
|
|
404
|
+
}
|
|
405
|
+
//#endregion
|
|
406
|
+
export { defineOperation };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/public-url.d.ts
|
|
2
|
+
/** Public origins resolved from `vitehub({ publicUrl })` at build time. */
|
|
3
|
+
interface PublicUrlConfig {
|
|
4
|
+
/** One origin for the whole deployment. */
|
|
5
|
+
url?: string;
|
|
6
|
+
/** One origin per discovered Agent, from the function form. */
|
|
7
|
+
agents?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
/** Replace aliases when a generated Agent registry is installed. */
|
|
10
|
+
declare function resetPublicUrlAgentNames(): void;
|
|
11
|
+
/** Associate an evaluated Agent name with the identity used by build-time URL configuration. */
|
|
12
|
+
declare function registerPublicUrlAgentName(name: string, discoveredName: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the public origin of this deployment.
|
|
15
|
+
*
|
|
16
|
+
* A configured origin always wins over the request: the single `vitehub({ publicUrl })` origin, then the origin of
|
|
17
|
+
* the Agent, then, for a request, the configured origin with the same host as the request or the only configured origin. When
|
|
18
|
+
* `publicUrl` configures several origins and none of them fits, the result is `undefined`: the request Host cannot
|
|
19
|
+
* name a new origin. Only when nothing is configured, such as in `vite dev`, the request origin is the result.
|
|
20
|
+
* Set `configuredOnly` when the request must not supply it in that case either.
|
|
21
|
+
*/
|
|
22
|
+
declare function resolvePublicUrl(options?: {
|
|
23
|
+
agentName?: string;
|
|
24
|
+
request?: Pick<Request, "url">;
|
|
25
|
+
configuredOnly?: boolean;
|
|
26
|
+
}): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Build the hosted Console URL that opens one Agent invocation, such as
|
|
29
|
+
* `https://console.vitehub.dev/open?project=https%3A%2F%2Fapp.example.com&path=%2Fagents%2Fbot%2Finvocations%2Fid`.
|
|
30
|
+
* `origin` must not include the application base path. The hosted Console checks the project URL when it opens the link.
|
|
31
|
+
*/
|
|
32
|
+
declare function consoleInvocationUrl(origin: string, agentName: string, invocationId: string): string;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { resolvePublicUrl as a, resetPublicUrlAgentNames as i, consoleInvocationUrl as n, registerPublicUrlAgentName as r, PublicUrlConfig as t };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BKICpwZp.js";
|
|
2
|
+
//#region src/route-segment.ts
|
|
3
|
+
const plainSegment = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4
|
+
function encodeRouteSegment(value) {
|
|
5
|
+
if (plainSegment.test(value)) return value;
|
|
6
|
+
let encoded = "~";
|
|
7
|
+
for (let index = 0; index < value.length; index++) encoded += value.charCodeAt(index).toString(16).padStart(4, "0");
|
|
8
|
+
return encoded;
|
|
9
|
+
}
|
|
10
|
+
function decodeRouteSegment(segment) {
|
|
11
|
+
if (plainSegment.test(segment)) return segment;
|
|
12
|
+
if (!/^~(?:[0-9a-f]{4})+$/.test(segment)) return;
|
|
13
|
+
let value = "";
|
|
14
|
+
for (let index = 1; index < segment.length; index += 4) value += String.fromCharCode(Number.parseInt(segment.slice(index, index + 4), 16));
|
|
15
|
+
return encodeRouteSegment(value) === segment ? value : void 0;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/hosted-console.ts
|
|
19
|
+
/** The origin of the hosted Console. */
|
|
20
|
+
const hostedConsoleOrigin = "https://console.vitehub.dev";
|
|
21
|
+
const loopbackHosts = /* @__PURE__ */ new Set([
|
|
22
|
+
"localhost",
|
|
23
|
+
"127.0.0.1",
|
|
24
|
+
"[::1]"
|
|
25
|
+
]);
|
|
26
|
+
const pathBase = "https://console.invalid";
|
|
27
|
+
/**
|
|
28
|
+
* The Console path of a link, such as `/agents/bot/invocations/abc?tab=trace`, or `undefined` when the value is not a
|
|
29
|
+
* Console path. A Console path starts with one `/`. Absolute URLs, protocol-relative URLs, and backslashes are not
|
|
30
|
+
* Console paths, so a link cannot send the browser to another site. A path that starts with `/_vitehub`, as on a
|
|
31
|
+
* Console that the app serves, loses that prefix.
|
|
32
|
+
*/
|
|
33
|
+
function normalizeConsolePath(path) {
|
|
34
|
+
if (!path.startsWith("/") || path.startsWith("//") || path.includes("\\")) return void 0;
|
|
35
|
+
let url;
|
|
36
|
+
try {
|
|
37
|
+
url = new URL(path, pathBase);
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (url.origin !== pathBase) return void 0;
|
|
42
|
+
const pathname = url.pathname.replace(/^\/_vitehub(?=\/|$)/, "") || "/";
|
|
43
|
+
if (pathname.startsWith("//")) return void 0;
|
|
44
|
+
return `${pathname}${url.search}${url.hash}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The project URL of a link: the app origin and its application mount, such as `https://app.example.com/portal`, or
|
|
48
|
+
* `undefined` when the URL cannot be a project. A project URL is `https:`, or `http:` on a loopback host, and has no
|
|
49
|
+
* user name or password.
|
|
50
|
+
*/
|
|
51
|
+
function normalizeConsoleProjectUrl(projectUrl) {
|
|
52
|
+
let url;
|
|
53
|
+
try {
|
|
54
|
+
url = new URL(projectUrl);
|
|
55
|
+
} catch {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (url.username || url.password) return void 0;
|
|
59
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopbackHosts.has(url.hostname))) return void 0;
|
|
60
|
+
const mount = url.pathname.search(/\/_vitehub(?=\/|$)/);
|
|
61
|
+
const base = (mount === -1 ? url.pathname : url.pathname.slice(0, mount)).replace(/\/+$/, "");
|
|
62
|
+
return `${url.origin}${base}`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The hosted Console URL that opens one page of a project, such as
|
|
66
|
+
* `https://console.vitehub.dev/open?project=https%3A%2F%2Fapp.example.com&path=%2Fkv`.
|
|
67
|
+
*
|
|
68
|
+
* `projectUrl` is the app origin with its application mount, such as `https://app.example.com/portal`. `path` is the
|
|
69
|
+
* Console path, such as `/agents/bot/invocations/abc`. The hosted Console switches to the project when this browser
|
|
70
|
+
* linked it, or asks the person to link it first. The URL holds no secret.
|
|
71
|
+
*
|
|
72
|
+
* Throws `RUNTIME_CONSOLE_PROJECT_URL_INVALID` when `projectUrl` is not `https:` (or `http:` on a loopback host), and
|
|
73
|
+
* `RUNTIME_CONSOLE_PATH_INVALID` when `path` is not a Console path.
|
|
74
|
+
*/
|
|
75
|
+
function hostedConsoleUrl(projectUrl, path, consoleOrigin = hostedConsoleOrigin) {
|
|
76
|
+
const project = normalizeConsoleProjectUrl(projectUrl);
|
|
77
|
+
if (!project) throw runtimeErrorDiagnostics.RUNTIME_CONSOLE_PROJECT_URL_INVALID({ value: projectUrl });
|
|
78
|
+
const consolePath = normalizeConsolePath(path);
|
|
79
|
+
if (!consolePath) throw runtimeErrorDiagnostics.RUNTIME_CONSOLE_PATH_INVALID({ value: path });
|
|
80
|
+
const url = new URL("/open", consoleOrigin);
|
|
81
|
+
url.search = new URLSearchParams({
|
|
82
|
+
project,
|
|
83
|
+
path: consolePath
|
|
84
|
+
}).toString();
|
|
85
|
+
return url.href;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/public-url.ts
|
|
89
|
+
const publicUrlAgentNames = /* @__PURE__ */ new Map();
|
|
90
|
+
/** Replace aliases when a generated Agent registry is installed. */
|
|
91
|
+
function resetPublicUrlAgentNames() {
|
|
92
|
+
publicUrlAgentNames.clear();
|
|
93
|
+
}
|
|
94
|
+
/** Associate an evaluated Agent name with the identity used by build-time URL configuration. */
|
|
95
|
+
function registerPublicUrlAgentName(name, discoveredName) {
|
|
96
|
+
const previous = publicUrlAgentNames.get(name);
|
|
97
|
+
publicUrlAgentNames.set(name, previous === void 0 || previous === discoveredName ? discoveredName : null);
|
|
98
|
+
}
|
|
99
|
+
function publicUrlConfig() {
|
|
100
|
+
return typeof __VITEHUB_PUBLIC_URL__ === "undefined" ? {} : __VITEHUB_PUBLIC_URL__;
|
|
101
|
+
}
|
|
102
|
+
function applicationBasePath() {
|
|
103
|
+
const segments = (typeof __VITEHUB_APP_BASE_URL__ === "undefined" ? "/" : __VITEHUB_APP_BASE_URL__).split("/").filter(Boolean);
|
|
104
|
+
return segments.length ? `/${segments.join("/")}` : "";
|
|
105
|
+
}
|
|
106
|
+
function configuredAgentUrl(config, name) {
|
|
107
|
+
return config.agents && Object.hasOwn(config.agents, name) ? config.agents[name] : void 0;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Resolve the public origin of this deployment.
|
|
111
|
+
*
|
|
112
|
+
* A configured origin always wins over the request: the single `vitehub({ publicUrl })` origin, then the origin of
|
|
113
|
+
* the Agent, then, for a request, the configured origin with the same host as the request or the only configured origin. When
|
|
114
|
+
* `publicUrl` configures several origins and none of them fits, the result is `undefined`: the request Host cannot
|
|
115
|
+
* name a new origin. Only when nothing is configured, such as in `vite dev`, the request origin is the result.
|
|
116
|
+
* Set `configuredOnly` when the request must not supply it in that case either.
|
|
117
|
+
*/
|
|
118
|
+
function resolvePublicUrl(options = {}) {
|
|
119
|
+
const config = publicUrlConfig();
|
|
120
|
+
if (config.url) return config.url;
|
|
121
|
+
const discoveredName = options.agentName ? publicUrlAgentNames.get(options.agentName) : void 0;
|
|
122
|
+
const agentUrl = options.agentName ? configuredAgentUrl(config, options.agentName) ?? (discoveredName ? configuredAgentUrl(config, discoveredName) : void 0) : void 0;
|
|
123
|
+
if (agentUrl || !options.request) return agentUrl;
|
|
124
|
+
const request = new URL(options.request.url);
|
|
125
|
+
const configured = [...new Set(Object.values(config.agents ?? {}))];
|
|
126
|
+
if (configured.length) return configured.find((url) => new URL(url).host === request.host) ?? (configured.length === 1 ? configured[0] : void 0);
|
|
127
|
+
return options.configuredOnly ? void 0 : request.origin;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build the hosted Console URL that opens one Agent invocation, such as
|
|
131
|
+
* `https://console.vitehub.dev/open?project=https%3A%2F%2Fapp.example.com&path=%2Fagents%2Fbot%2Finvocations%2Fid`.
|
|
132
|
+
* `origin` must not include the application base path. The hosted Console checks the project URL when it opens the link.
|
|
133
|
+
*/
|
|
134
|
+
function consoleInvocationUrl(origin, agentName, invocationId) {
|
|
135
|
+
const project = `${new URL(origin).origin}${applicationBasePath()}`;
|
|
136
|
+
const path = `/agents/${encodeRouteSegment(agentName)}/invocations/${encodeURIComponent(invocationId)}`;
|
|
137
|
+
return `${hostedConsoleOrigin}/open?project=${encodeURIComponent(project)}&path=${encodeURIComponent(path)}`;
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { hostedConsoleOrigin as a, normalizeConsoleProjectUrl as c, resolvePublicUrl as i, decodeRouteSegment as l, registerPublicUrlAgentName as n, hostedConsoleUrl as o, resetPublicUrlAgentNames as r, normalizeConsolePath as s, consoleInvocationUrl as t, encodeRouteSegment as u };
|