@vite-hub/kv 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +19 -13
  2. package/dist/{cli-DpPhz_Ek.d.ts → cli-CLomw9ml.d.ts} +1 -0
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +24 -12
  5. package/dist/{cloudflare-env-lOtHHsgP.js → cloudflare-env-Dl349h_9.js} +2 -1
  6. package/dist/{cloudflare-kv-BIEUFzRT.js → cloudflare-kv-DQJhmGof.js} +22 -10
  7. package/dist/{cloudflare-kv-local-BBw3ZT1K.js → cloudflare-kv-local-COjgHweC.js} +3 -7
  8. package/dist/{config-BXEVoZE3.js → config-pfyPiPrI.js} +65 -28
  9. package/dist/{create-storage-BGsrQKw3.js → create-storage-DQ1BbFqH.js} +5 -5
  10. package/dist/{cursor-history-BqIQePNP.js → cursor-history-CAT4mpP1.js} +7 -3
  11. package/dist/{deno-kv-BM9mYdUp.js → deno-kv-Cf0ZveeN.js} +43 -7
  12. package/dist/driver-Du6Eh9p2.d.ts +47 -0
  13. package/dist/{error-diagnostics-BxqvtEIb.js → error-diagnostics-C4VTHInS.js} +16 -4
  14. package/dist/errors-BpiM-Vmh.js +125 -0
  15. package/dist/errors.d.ts +13 -1
  16. package/dist/errors.js +2 -2
  17. package/dist/{fs-lite-BLZId9_P.js → fs-lite-BTcBUP6B.js} +1 -1
  18. package/dist/fs-lite-C8yXCVDM.js +2 -0
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +39 -52
  21. package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-CI2PJGqu.d.ts} +13 -2
  22. package/dist/{operations-Ch-gKaey.js → operations-CqKs7Ykc.js} +24 -45
  23. package/dist/{operations-B-WZ7P1h.js → operations-nAaONxzh.js} +273 -231
  24. package/dist/operations.d.ts +2 -2
  25. package/dist/operations.js +4 -3
  26. package/dist/out-BbXG-yVX.js +21755 -0
  27. package/dist/{redis-shared-E5mahECF.js → redis-shared-1M0IaguQ.js} +1 -1
  28. package/dist/request-log-Dj9Vw7qG.js +105 -0
  29. package/dist/{results-p7nPCnaJ.js → results-D6jfPtCk.js} +0 -1
  30. package/dist/runtime/cloudflare-kv.d.ts +1 -1
  31. package/dist/runtime/cloudflare-kv.js +1 -1
  32. package/dist/runtime/cloudflare-request-env.js +1 -1
  33. package/dist/runtime/database.d.ts +2 -0
  34. package/dist/{database-72Jk3VVk.js → runtime/database.js} +68 -37
  35. package/dist/runtime/nitro-plugin.js +12 -5
  36. package/dist/runtime/redis-driver.d.ts +2 -2
  37. package/dist/runtime/redis-driver.js +2 -5
  38. package/dist/runtime/unstorage-driver.js +6 -2
  39. package/dist/runtime/upstash-driver.d.ts +2 -2
  40. package/dist/runtime/upstash-driver.js +2 -6
  41. package/dist/{types-DEiKew_3.d.ts → types-Cp6IBhSN.d.ts} +36 -37
  42. package/dist/{upstash-DDlqTttY.js → upstash-5sTbIR35.js} +2 -2
  43. package/dist/virtual-module.d.ts +1 -0
  44. package/dist/vite.d.ts +21 -6
  45. package/dist/vite.js +2738 -415
  46. package/package.json +10 -5
  47. package/dist/driver-BwxgaQ-f.d.ts +0 -15
  48. package/dist/errors-DbwufFZp.js +0 -60
  49. package/dist/fs-lite-RAoxu8L0.js +0 -2
  50. package/dist/main-F3Y22_uV.js +0 -2353
@@ -4,234 +4,11 @@ import { readdir } from "node:fs/promises";
4
4
  import { basename, dirname, join, parse, relative, resolve } from "node:path";
5
5
  import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
6
6
  import { createInterface } from "node:readline/promises";
7
+ import { defineDiagnostics } from "nostics";
7
8
  import { tmpdir } from "node:os";
8
9
  import "node:url";
9
- import { defineDiagnostics } from "nostics";
10
10
  import { createBirpc } from "birpc";
11
11
  import { toJsonSchema } from "@valibot/to-json-schema";
12
- //#region ../internal/src/cli.ts
13
- /**
14
- * The seed files in `dir` and its subfolders, as sorted paths relative to `dir` with `/`. Files and folders whose name
15
- * starts with `.`, such as `.gitkeep`, are not seed files. Returns `undefined` when `dir` does not exist.
16
- */
17
- async function listSeedFiles(dir) {
18
- const entries = await readdir(dir, {
19
- recursive: true,
20
- withFileTypes: true
21
- }).catch((error) => {
22
- if (error.code === "ENOENT") return void 0;
23
- throw error;
24
- });
25
- if (!entries) return;
26
- return entries.filter((entry) => entry.isFile()).map((entry) => relative(dir, join(entry.parentPath, entry.name)).replaceAll("\\", "/")).filter((file) => !file.split("/").some((segment) => segment.startsWith("."))).sort();
27
- }
28
- function parseViteHubDevTimeout(value, error) {
29
- if (!/^\d+$/.test(value)) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
30
- const timeout = Number(value);
31
- if (timeout > 2147483647) throw error("--timeout must be at most 2147483647 milliseconds.");
32
- if (!Number.isInteger(timeout) || timeout < 1) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
33
- return timeout;
34
- }
35
- /**
36
- * Reads one dev target option at `args[index]`: `--url <url>`, `--server <url>`,
37
- * `--url=<url>`, `--timeout <ms>` or `--timeout=<ms>`.
38
- *
39
- * Returns the number of extra arguments that the option used (`0` or `1`), or
40
- * `undefined` when `args[index]` is not a dev target option.
41
- */
42
- function readViteHubDevTargetOption(args, index, target, errors) {
43
- const arg = args[index];
44
- if (arg === void 0) return;
45
- const readValue = () => {
46
- const value = args[index + 1];
47
- if (!value || value.startsWith("-")) throw errors.missingValue(`Missing value for ${arg}.`);
48
- return value;
49
- };
50
- if (arg === "--url" || arg === "--server") {
51
- target.url = readValue();
52
- return 1;
53
- }
54
- if (arg.startsWith("--url=")) {
55
- const value = arg.slice(6);
56
- if (!value) throw errors.missingValue(`Missing value for ${arg}.`);
57
- target.url = value;
58
- return 0;
59
- }
60
- if (arg === "--timeout") {
61
- target.timeout = parseViteHubDevTimeout(readValue(), errors.invalidTimeout);
62
- return 1;
63
- }
64
- if (arg.startsWith("--timeout=")) {
65
- target.timeout = parseViteHubDevTimeout(arg.slice(10), errors.invalidInlineTimeout);
66
- return 0;
67
- }
68
- }
69
- /**
70
- * Reads `--<name> <value>` or `--<name>=<value>` at `args[index]`. Returns the value and the number of extra arguments
71
- * that the option used (`0` or `1`), or `undefined` when `args[index]` is another argument. Throws `error` when the value
72
- * is missing.
73
- */
74
- function readCliOptionValue(args, index, name, error) {
75
- const arg = args[index];
76
- if (arg === `--${name}`) {
77
- const value = args[index + 1];
78
- if (value === void 0 || value.startsWith("--")) throw error(`--${name} needs a value.`);
79
- return {
80
- consumed: 1,
81
- value
82
- };
83
- }
84
- if (arg.startsWith(`--${name}=`)) return {
85
- consumed: 0,
86
- value: arg.slice(name.length + 3)
87
- };
88
- }
89
- /** Reads the value of `--<name>` as an integer from 1. Throws `error` for any other value. */
90
- function parseCliPositiveInteger(name, value, error) {
91
- const number = Number(value);
92
- if (!value || !Number.isInteger(number) || number < 1) throw error(`--${name} must be a positive integer.`);
93
- return number;
94
- }
95
- /** Writes a command failure: as `{ error }` JSON on stdout with `--json`, else the message and fix on stderr. Returns exit code 1. */
96
- function writeCliFailure(json, streams, failure) {
97
- if (json) streams.stdout.write(`${JSON.stringify({ error: failure }, null, 2)}\n`);
98
- else streams.stderr.write(`${failure.message}${failure.fix ? `\n${failure.fix}` : ""}\n`);
99
- return 1;
100
- }
101
- /** Asks a question on the terminal through stderr. Only `y` or `yes`, in any case, is a yes. */
102
- async function askOnTerminal(question) {
103
- const terminal = createInterface({
104
- input: process.stdin,
105
- output: process.stderr
106
- });
107
- try {
108
- return /^y(es)?$/i.test((await terminal.question(question)).trim());
109
- } finally {
110
- terminal.close();
111
- }
112
- }
113
- /** File in the project root where the running dev server tells commands where it listens. */
114
- const viteHubDevServerFile = ".vitehub/dev-server.json";
115
- function writeViteHubDevServerFile(root, info) {
116
- const file = join(root, viteHubDevServerFile);
117
- mkdirSync(dirname(file), { recursive: true });
118
- writeFileSync(file, `${JSON.stringify(info)}\n`);
119
- }
120
- function removeViteHubDevServerFile(root) {
121
- rmSync(join(root, viteHubDevServerFile), { force: true });
122
- }
123
- /** The dev server that runs in `root`, or undefined when there is no file or it is not valid. */
124
- function readViteHubDevServerFile(root) {
125
- try {
126
- const value = JSON.parse(readFileSync(join(root, viteHubDevServerFile), "utf8"));
127
- const url = isRecord(value) ? value.url : void 0;
128
- const served = isRecord(value) ? value.root : void 0;
129
- return typeof url === "string" && url && typeof served === "string" && served ? {
130
- root: served,
131
- url
132
- } : void 0;
133
- } catch {
134
- return;
135
- }
136
- }
137
- /**
138
- * Where a command finds the dev server of its project: the file that the server wrote in a project root, else
139
- * `VITEHUB_DEV_SERVER_URL`. It never guesses a port, since another project may use it.
140
- */
141
- function findViteHubDevServerUrl(roots, env) {
142
- for (const root of roots) {
143
- const file = readViteHubDevServerFile(root);
144
- if (file && roots.some((candidate) => candidate.replace(/\/+$/, "") === file.root.replace(/\/+$/, ""))) return file.url;
145
- }
146
- return env["VITEHUB_DEV_SERVER_URL"] || void 0;
147
- }
148
- //#endregion
149
- //#region ../internal/src/build/vite.ts
150
- const projectRootDirectoryMarkers = [
151
- ["server", "agents"],
152
- ["server", "channels"],
153
- ["server", "connections"],
154
- ["server", "browsers"],
155
- ["server", "emails"],
156
- ["server", "schedules"],
157
- ["server", "workspaces"]
158
- ];
159
- const projectRootFileMarkers = [
160
- ["package.json"],
161
- ["nuxt.config.ts"],
162
- ["nuxt.config.mts"],
163
- ["nuxt.config.js"],
164
- ["nuxt.config.mjs"]
165
- ];
166
- function createNoExternalAddition(...packageNames) {
167
- return (current) => {
168
- if (current === true) return;
169
- const values = Array.isArray(current) ? current : [current];
170
- const missing = packageNames.filter((packageName) => !values.includes(packageName));
171
- return missing.length ? missing : void 0;
172
- };
173
- }
174
- function isServerEnvironment(name, config) {
175
- return name === "ssr" || config.consumer === "server";
176
- }
177
- function includesNitroVitePlugin(value) {
178
- if (Array.isArray(value)) return value.some(includesNitroVitePlugin);
179
- if (!value || typeof value !== "object") return false;
180
- return "name" in value && value.name === "nitro:main";
181
- }
182
- function hasNitroConfigContext(config) {
183
- return config["__vitehubNitroConfigContext"] === true || includesNitroVitePlugin(config.plugins);
184
- }
185
- function shouldSkipViteProviderBuild(command) {
186
- return command === "serve";
187
- }
188
- function resolveViteHubProjectRoot(root, options = {}) {
189
- const resolvedRoot = resolve(root);
190
- const temporaryRoot = resolve(tmpdir());
191
- const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
192
- if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
193
- if (basename(resolvedRoot) === "app") {
194
- const parent = dirname(resolvedRoot);
195
- if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
196
- "nuxt.config.ts",
197
- "nuxt.config.mts",
198
- "nuxt.config.js",
199
- "nuxt.config.mjs"
200
- ]))) return parent;
201
- }
202
- let current = resolvedRoot;
203
- while (true) {
204
- if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
205
- if (hasProjectRootMarker(current)) return current;
206
- const parent = dirname(current);
207
- if (parent === current) return resolvedRoot;
208
- current = parent;
209
- }
210
- }
211
- function hasProjectRootDirectoryMarker(root) {
212
- for (const marker of projectRootDirectoryMarkers) try {
213
- if (statSync(resolve(root, ...marker)).isDirectory()) return true;
214
- } catch (error) {
215
- if (error.code !== "ENOENT") throw error;
216
- }
217
- return false;
218
- }
219
- function hasProjectRootMarker(root) {
220
- if (hasProjectRootDirectoryMarker(root)) return true;
221
- return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
222
- }
223
- function hasProjectRootFileMarker(root, markers) {
224
- for (const marker of markers) {
225
- const path = Array.isArray(marker) ? marker : [marker];
226
- try {
227
- if (statSync(resolve(root, ...path)).isFile()) return true;
228
- } catch (error) {
229
- if (error.code !== "ENOENT") throw error;
230
- }
231
- }
232
- return false;
233
- }
234
- //#endregion
235
12
  //#region ../internal/src/error-diagnostics.ts
236
13
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
237
14
  const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
@@ -258,7 +35,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
258
35
  why: ({ message }) => message === void 0 ? "" : String(message)
259
36
  },
260
37
  INTERNAL_R0022: {
261
- fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
38
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
262
39
  why: ({ message }) => message === void 0 ? "" : String(message)
263
40
  },
264
41
  INTERNAL_R0024: {
@@ -403,7 +180,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
403
180
  },
404
181
  INTERNAL_R0004: {
405
182
  ...dynamicError,
406
- fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `fetch()` Source options, or ask the server for a smaller response."
183
+ fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
407
184
  },
408
185
  INTERNAL_R0005: {
409
186
  ...dynamicError,
@@ -449,6 +226,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
449
226
  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 _.`,
450
227
  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>`."
451
228
  },
229
+ INTERNAL_DEV_SERVER_NOT_FOUND: {
230
+ why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
231
+ fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
232
+ },
452
233
  INTERNAL_FORGE_NOT_INSTALLED: {
453
234
  why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
454
235
  fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
@@ -473,6 +254,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
473
254
  why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
474
255
  fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
475
256
  },
257
+ INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
258
+ why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
259
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
260
+ },
476
261
  INTERNAL_SECRET_PURPOSE_MISSING: {
477
262
  why: "[vitehub] A derived secret requires a purpose.",
478
263
  fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
@@ -496,6 +281,245 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
496
281
  }
497
282
  });
498
283
  //#endregion
284
+ //#region ../internal/src/cli.ts
285
+ /**
286
+ * The seed files in `dir` and its subfolders, as sorted paths relative to `dir` with `/`. Files and folders whose name
287
+ * starts with `.`, such as `.gitkeep`, are not seed files. Returns `undefined` when `dir` does not exist.
288
+ */
289
+ async function listSeedFiles(dir) {
290
+ const entries = await readdir(dir, {
291
+ recursive: true,
292
+ withFileTypes: true
293
+ }).catch((error) => {
294
+ if (error.code === "ENOENT") return void 0;
295
+ throw error;
296
+ });
297
+ if (!entries) return;
298
+ return entries.filter((entry) => entry.isFile()).map((entry) => relative(dir, join(entry.parentPath, entry.name)).replaceAll("\\", "/")).filter((file) => !file.split("/").some((segment) => segment.startsWith("."))).sort();
299
+ }
300
+ function parseViteHubDevTimeout(value, error) {
301
+ if (!/^\d+$/.test(value)) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
302
+ const timeout = Number(value);
303
+ if (timeout > 2147483647) throw error("--timeout must be at most 2147483647 milliseconds.");
304
+ if (!Number.isInteger(timeout) || timeout < 1) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
305
+ return timeout;
306
+ }
307
+ /**
308
+ * Reads one dev target option at `args[index]`: `--url <url>`, `--url=<url>`,
309
+ * `--timeout <ms>` or `--timeout=<ms>`. `--url` is always the app, and `--server` fails with the fix.
310
+ *
311
+ * Returns the number of extra arguments that the option used (`0` or `1`), or
312
+ * `undefined` when `args[index]` is not a dev target option.
313
+ */
314
+ function readViteHubDevTargetOption(args, index, target, errors) {
315
+ const arg = args[index];
316
+ if (arg === void 0) return;
317
+ const readValue = () => {
318
+ const value = args[index + 1];
319
+ if (!value || value.startsWith("-")) throw errors.missingValue(`Missing value for ${arg}.`);
320
+ return value;
321
+ };
322
+ if (arg === "--server" || arg.startsWith("--server=")) throw errors.unknownOption("--server is now --url. Pass --url with the app URL, such as --url http://localhost:3000.");
323
+ if (arg === "--url") {
324
+ target.url = readValue();
325
+ return 1;
326
+ }
327
+ if (arg.startsWith("--url=")) {
328
+ const value = arg.slice(6);
329
+ if (!value) throw errors.missingValue(`Missing value for ${arg}.`);
330
+ target.url = value;
331
+ return 0;
332
+ }
333
+ if (arg === "--timeout") {
334
+ target.timeout = parseViteHubDevTimeout(readValue(), errors.invalidTimeout);
335
+ return 1;
336
+ }
337
+ if (arg.startsWith("--timeout=")) {
338
+ target.timeout = parseViteHubDevTimeout(arg.slice(10), errors.invalidInlineTimeout);
339
+ return 0;
340
+ }
341
+ }
342
+ /**
343
+ * Reads `--<name> <value>` or `--<name>=<value>` at `args[index]`. Returns the value and the number of extra arguments
344
+ * that the option used (`0` or `1`), or `undefined` when `args[index]` is another argument. Throws `error` when the value
345
+ * is missing.
346
+ */
347
+ function readCliOptionValue(args, index, name, error) {
348
+ const arg = args[index];
349
+ if (arg === `--${name}`) {
350
+ const value = args[index + 1];
351
+ if (value === void 0 || value.startsWith("--")) throw error(`--${name} needs a value.`);
352
+ return {
353
+ consumed: 1,
354
+ value
355
+ };
356
+ }
357
+ if (arg.startsWith(`--${name}=`)) return {
358
+ consumed: 0,
359
+ value: arg.slice(name.length + 3)
360
+ };
361
+ }
362
+ /** Reads the value of `--<name>` as an integer from 1. Throws `error` for any other value. */
363
+ function parseCliPositiveInteger(name, value, error) {
364
+ const number = Number(value);
365
+ if (!value || !Number.isInteger(number) || number < 1) throw error(`--${name} must be a positive integer.`);
366
+ return number;
367
+ }
368
+ /** Writes a command failure: as `{ error }` JSON on stdout with `--json`, else the message and fix on stderr. Returns exit code 1. */
369
+ function writeCliFailure(json, streams, failure) {
370
+ if (json) streams.stdout.write(`${JSON.stringify({ error: failure }, null, 2)}\n`);
371
+ else streams.stderr.write(`${failure.message}${failure.fix ? `\n${failure.fix}` : ""}\n`);
372
+ return 1;
373
+ }
374
+ /** Asks a question on the terminal through stderr. Only `y` or `yes`, in any case, is a yes. */
375
+ async function askOnTerminal(question) {
376
+ const terminal = createInterface({
377
+ input: process.stdin,
378
+ output: process.stderr
379
+ });
380
+ try {
381
+ return /^y(es)?$/i.test((await terminal.question(question)).trim());
382
+ } finally {
383
+ terminal.close();
384
+ }
385
+ }
386
+ /** File in the project root where the running dev server tells commands where it listens. */
387
+ const viteHubDevServerFile = ".vitehub/dev-server.json";
388
+ function writeViteHubDevServerFile(root, info) {
389
+ const file = join(root, viteHubDevServerFile);
390
+ mkdirSync(dirname(file), { recursive: true });
391
+ writeFileSync(file, `${JSON.stringify(info)}\n`);
392
+ }
393
+ function removeViteHubDevServerFile(root) {
394
+ rmSync(join(root, viteHubDevServerFile), { force: true });
395
+ }
396
+ /** The dev server that runs in `root`, or undefined when there is no file or it is not valid. */
397
+ function readViteHubDevServerFile(root) {
398
+ try {
399
+ const value = JSON.parse(readFileSync(join(root, viteHubDevServerFile), "utf8"));
400
+ const url = isRecord(value) ? value.url : void 0;
401
+ const served = isRecord(value) ? value.root : void 0;
402
+ return typeof url === "string" && url && typeof served === "string" && served ? {
403
+ root: served,
404
+ url
405
+ } : void 0;
406
+ } catch {
407
+ return;
408
+ }
409
+ }
410
+ /**
411
+ * Where a command finds the dev server of its project: the file that the server wrote in a project root, else
412
+ * `VITEHUB_DEV_SERVER_URL`. It never guesses a port, since another project may use it.
413
+ */
414
+ function findViteHubDevServerUrl(roots, env) {
415
+ for (const root of roots) {
416
+ const file = readViteHubDevServerFile(root);
417
+ if (file && roots.some((candidate) => candidate.replace(/\/+$/, "") === file.root.replace(/\/+$/, ""))) return file.url;
418
+ }
419
+ return env["VITEHUB_DEV_SERVER_URL"] || void 0;
420
+ }
421
+ //#endregion
422
+ //#region ../internal/src/build/vite.ts
423
+ const projectRootDirectoryMarkers = [
424
+ ["server", "agents"],
425
+ ["server", "channels"],
426
+ ["server", "connections"],
427
+ ["server", "browsers"],
428
+ ["server", "emails"],
429
+ ["server", "schedules"],
430
+ ["server", "workspaces"]
431
+ ];
432
+ const projectRootFileMarkers = [
433
+ ["package.json"],
434
+ ["nuxt.config.ts"],
435
+ ["nuxt.config.mts"],
436
+ ["nuxt.config.js"],
437
+ ["nuxt.config.mjs"]
438
+ ];
439
+ /** Record a selected plugin in its pre config hook, before other plugins consume the selection. */
440
+ function markViteConfigPlugin(env, name) {
441
+ Reflect.set(env, Symbol.for(`vitehub.config-plugin:${name}`), true);
442
+ }
443
+ function createNoExternalAddition(...packageNames) {
444
+ return (current) => {
445
+ if (current === true) return;
446
+ const values = Array.isArray(current) ? current : [current];
447
+ const missing = packageNames.filter((packageName) => !values.includes(packageName));
448
+ return missing.length ? missing : void 0;
449
+ };
450
+ }
451
+ function isServerEnvironment(name, config) {
452
+ return name === "ssr" || config.consumer === "server";
453
+ }
454
+ const VITEHUB_NITRO_CONFIG_CONTEXT = "__vitehubNitroConfigContext";
455
+ const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
456
+ /**
457
+ * Set by `vite-hub/nuxt` when it replays Vite config hooks for `nuxt prepare`. Prepare uses `command: "build"` to write
458
+ * the same types as the build, but it builds nothing.
459
+ */
460
+ const VITEHUB_PREPARE = "__vitehubPrepare";
461
+ function includesNitroVitePlugin(value) {
462
+ if (Array.isArray(value)) return value.some(includesNitroVitePlugin);
463
+ if (!value || typeof value !== "object") return false;
464
+ return "name" in value && value.name === "nitro:main";
465
+ }
466
+ function hasNitroConfigContext(config) {
467
+ return config["__vitehubNitroConfigContext"] === true || includesNitroVitePlugin(config.plugins);
468
+ }
469
+ function shouldSkipViteProviderBuild(command) {
470
+ return command === "serve";
471
+ }
472
+ function resolveViteHubProjectRoot(root, options = {}) {
473
+ const resolvedRoot = resolve(root);
474
+ const temporaryRoot = resolve(tmpdir());
475
+ const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
476
+ if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
477
+ if (basename(resolvedRoot) === "app") {
478
+ const parent = dirname(resolvedRoot);
479
+ if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
480
+ "nuxt.config.ts",
481
+ "nuxt.config.mts",
482
+ "nuxt.config.js",
483
+ "nuxt.config.mjs"
484
+ ]))) return parent;
485
+ }
486
+ let current = resolvedRoot;
487
+ while (true) {
488
+ if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
489
+ if (hasProjectRootMarker(current)) return current;
490
+ const parent = dirname(current);
491
+ if (parent === current) return resolvedRoot;
492
+ current = parent;
493
+ }
494
+ }
495
+ function hasProjectRootDirectoryMarker(root) {
496
+ for (const marker of projectRootDirectoryMarkers) try {
497
+ if (statSync(resolve(root, ...marker)).isDirectory()) return true;
498
+ } catch (error) {
499
+ if (!isMissingProjectMarker(error)) throw error;
500
+ }
501
+ return false;
502
+ }
503
+ function hasProjectRootMarker(root) {
504
+ if (hasProjectRootDirectoryMarker(root)) return true;
505
+ return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
506
+ }
507
+ function hasProjectRootFileMarker(root, markers) {
508
+ for (const marker of markers) {
509
+ const path = Array.isArray(marker) ? marker : [marker];
510
+ try {
511
+ if (statSync(resolve(root, ...path)).isFile()) return true;
512
+ } catch (error) {
513
+ if (!isMissingProjectMarker(error)) throw error;
514
+ }
515
+ }
516
+ return false;
517
+ }
518
+ function isMissingProjectMarker(error) {
519
+ const code = error.code;
520
+ return code === "ENOENT" || code === "ENOTDIR";
521
+ }
522
+ //#endregion
499
523
  //#region ../internal/src/operation-rpc.ts
500
524
  /** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
501
525
  const operationRpcPath = "/_vitehub/rpc";
@@ -900,6 +924,7 @@ const reservedOperationNamespaces = [
900
924
  "drain",
901
925
  "login",
902
926
  "logout",
927
+ "update",
903
928
  "whoami"
904
929
  ]
905
930
  ];
@@ -1009,11 +1034,16 @@ function operationsOf(value) {
1009
1034
  /** The CLI namespace and command of an operation. Defaults: the section (or the name prefix) and the verb. */
1010
1035
  function operationCliPath(operation) {
1011
1036
  const dot = operation.name.indexOf(".");
1037
+ const cli = operationCliOptions(operation);
1012
1038
  return {
1013
- command: operation.cli?.command ?? operation.name.slice(dot + 1),
1014
- namespace: operation.cli?.namespace ?? (typeof operation.section === "string" ? operation.section : operation.name.slice(0, dot))
1039
+ command: cli?.command ?? operation.name.slice(dot + 1),
1040
+ namespace: cli?.namespace ?? (typeof operation.section === "string" ? operation.section : operation.name.slice(0, dot))
1015
1041
  };
1016
1042
  }
1043
+ /** The CLI options of an operation, or undefined for an operation without options or with `cli: false`. */
1044
+ function operationCliOptions(operation) {
1045
+ return operation.cli || void 0;
1046
+ }
1017
1047
  /**
1018
1048
  * The MCP tool name of an operation: every character outside `[a-zA-Z0-9_-]` becomes `_`, since clients such as
1019
1049
  * Claude reject a dot in a tool name. `content.publish` is `content_publish`.
@@ -1038,6 +1068,7 @@ function createOperationRegistry(sources) {
1038
1068
  const operations = [...byName.values()].map((entry) => entry.operation).sort((left, right) => left.name.localeCompare(right.name));
1039
1069
  const commands = /* @__PURE__ */ new Map();
1040
1070
  for (const operation of operations) {
1071
+ if (operation.cli === false) continue;
1041
1072
  const { command, namespace } = operationCliPath(operation);
1042
1073
  if (reservedOperationNamespaces.includes(namespace)) throw invalidDefinition(operation.name, `the CLI namespace ${JSON.stringify(namespace)} is reserved for built-in commands. Set cli.namespace to another name.`);
1043
1074
  const key = `${namespace} ${command}`;
@@ -1065,12 +1096,23 @@ function describeInputIssues(issues) {
1065
1096
  return path ? `${path}: ${issue.message}` : issue.message;
1066
1097
  }).join(" ");
1067
1098
  }
1099
+ function describeInputFields(schema) {
1100
+ const shapes = (Array.isArray(schema.anyOf) ? schema.anyOf : [schema]).map((shape) => {
1101
+ if (!isRecordOrFunction(shape) || !isRecordOrFunction(shape.properties)) return void 0;
1102
+ const required = Array.isArray(shape.required) ? shape.required : [];
1103
+ const fields = Object.keys(shape.properties).map((field) => required.includes(field) ? field : `${field}?`);
1104
+ return fields.length ? `{ ${fields.join(", ")} }` : "{}";
1105
+ });
1106
+ return shapes.every((shape) => shape !== void 0) ? shapes.join(" or ") : void 0;
1107
+ }
1068
1108
  /** Validate `input` with the schema of the operation. Throws `INTERNAL_R0022` with `status: 400`. */
1069
1109
  async function parseOperationInput(operation, input) {
1070
1110
  const result = await operation.input["~standard"].validate(input ?? {});
1071
1111
  if (!result.issues) return result.value;
1072
- const error = internalErrorDiagnostics.INTERNAL_R0022({ message: `Invalid input for ${operation.name}. ${describeInputIssues(result.issues)}` });
1073
- throw Object.assign(error, { status: 400 });
1112
+ const fields = describeInputFields(operationInputJsonSchema(operation));
1113
+ const issues = describeInputIssues(result.issues);
1114
+ const message = `Invalid input for ${operation.name}. ${issues}${fields ? `${/[.!?]$/.test(issues) ? "" : "."} ${operation.name} takes ${fields}.` : ""}`;
1115
+ throw Object.assign(internalErrorDiagnostics.INTERNAL_R0022({ message }), { status: 400 });
1074
1116
  }
1075
1117
  /**
1076
1118
  * The section that grants a call, or `false` for any Console user. `undefined` means the input names no valid section.
@@ -1348,4 +1390,4 @@ async function callOperationFromCli(call, name, input) {
1348
1390
  }, name, input);
1349
1391
  }
1350
1392
  //#endregion
1351
- export { writeViteHubDevServerFile as A, listSeedFiles as C, readViteHubDevTargetOption as D, readViteHubDevServerFile as E, removeViteHubDevServerFile as O, askOnTerminal as S, readCliOptionValue as T, createNoExternalAddition as _, operationRootHeader as a, resolveViteHubProjectRoot as b, projectRootHash as c, defineOperation as d, answerOperationRpc as f, internalErrorDiagnostics as g, readOperationRpcCall as h, createOperationRegistry as i, writeCliFailure as k, runOperation as l, operationRpcRefusal as m, callOperationFromCli as n, operationRpcHeader as o, operationRpcPath as p, collectOperationContributions as r, operationsOf as s, assertOperationProject as t, toOperationFailure as u, hasNitroConfigContext as v, parseCliPositiveInteger as w, shouldSkipViteProviderBuild as x, isServerEnvironment as y };
1393
+ export { readViteHubDevTargetOption as A, resolveViteHubProjectRoot as C, parseCliPositiveInteger as D, listSeedFiles as E, writeCliFailure as M, writeViteHubDevServerFile as N, readCliOptionValue as O, internalErrorDiagnostics as P, markViteConfigPlugin as S, askOnTerminal as T, VITEHUB_PREPARE as _, operationRootHeader as a, hasNitroConfigContext as b, projectRootHash as c, defineOperation as d, answerOperationRpc as f, VITEHUB_NITRO_CONFIG_CONTEXT as g, readOperationRpcCall as h, createOperationRegistry as i, removeViteHubDevServerFile as j, readViteHubDevServerFile as k, runOperation as l, operationRpcRefusal as m, callOperationFromCli as n, operationRpcHeader as o, operationRpcPath as p, collectOperationContributions as r, operationsOf as s, assertOperationProject as t, toOperationFailure as u, VITEHUB_PROJECT_ROOT as v, shouldSkipViteProviderBuild as w, isServerEnvironment as x, createNoExternalAddition as y };
@@ -1,5 +1,5 @@
1
- import { s as KVDriver } from "./types-DEiKew_3.js";
2
- import { t as AnyOperation } from "./operation-definition-8gOe-ubD.js";
1
+ import { c as KVDriver } from "./types-Cp6IBhSN.js";
2
+ import { t as AnyOperation } from "./operation-definition-CI2PJGqu.js";
3
3
  //#region src/runtime/operations.d.ts
4
4
  interface KVDevListResult {
5
5
  /** Present when more keys exist. Pass it as `--cursor` to read the next page. */
@@ -1,5 +1,5 @@
1
- import { a as operationRootHeader, c as projectRootHash, d as defineOperation, f as answerOperationRpc, g as internalErrorDiagnostics, h as readOperationRpcCall, i as createOperationRegistry, l as runOperation, m as operationRpcRefusal, o as operationRpcHeader, s as operationsOf, t as assertOperationProject, u as toOperationFailure } from "./operations-B-WZ7P1h.js";
2
- import { t as kvDevMaximumListLimit } from "./results-p7nPCnaJ.js";
1
+ import { P as internalErrorDiagnostics, a as operationRootHeader, c as projectRootHash, d as defineOperation, f as answerOperationRpc, h as readOperationRpcCall, i as createOperationRegistry, l as runOperation, m as operationRpcRefusal, o as operationRpcHeader, s as operationsOf, t as assertOperationProject, u as toOperationFailure } from "./operations-nAaONxzh.js";
2
+ import { t as kvDevMaximumListLimit } from "./results-D6jfPtCk.js";
3
3
  import { n as isViteHubLoopbackPeer } from "./dev-peer-CHafxbtj.js";
4
4
  import * as v from "valibot";
5
5
  //#region ../internal/src/secret.ts
@@ -204,6 +204,7 @@ function createStandaloneOperationHandler(sources, root) {
204
204
  sections: "all"
205
205
  },
206
206
  development: true,
207
+ projectRoot: root,
207
208
  surface: "cli",
208
209
  user: null,
209
210
  request,
@@ -237,7 +238,7 @@ function createStandaloneOperationHandler(sources, root) {
237
238
  }
238
239
  //#endregion
239
240
  //#region src/operations.ts
240
- const runtime = () => import("./operations-Ch-gKaey.js");
241
+ const runtime = () => import("./operations-CqKs7Ykc.js");
241
242
  const store = v.optional(v.pipe(v.string(), v.check((name) => name.trim() !== "", "Name a store.")));
242
243
  const key = v.string();
243
244
  function defineKVOperation(definition) {