@vite-hub/sandbox 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +388 -22
  3. package/dist/cloudflare-DO0h3Ncf.js +281 -0
  4. package/dist/cloudflare-env-BBJaBbuQ.js +39 -0
  5. package/dist/crabbox-BFCdf41h.js +1106 -0
  6. package/dist/error-diagnostics-BSysPv-D.js +166 -0
  7. package/dist/error-diagnostics-dGQqfgLt.js +99 -0
  8. package/dist/file-listing-DECFTdSl.js +26 -0
  9. package/dist/file-lock-CxyVl4Cv.js +73 -0
  10. package/dist/index-CXej1Bt0.d.ts +519 -0
  11. package/dist/index.d.ts +2 -65
  12. package/dist/index.js +277 -1172
  13. package/dist/internal/cloudflare.d.ts +4 -0
  14. package/dist/internal/cloudflare.js +16 -0
  15. package/dist/internal/host-toolchain.d.ts +22 -0
  16. package/dist/internal/host-toolchain.js +97 -0
  17. package/dist/internal/vercel.d.ts +4 -0
  18. package/dist/internal/vercel.js +16 -0
  19. package/dist/module-types-BfyRBaiP.js +7 -0
  20. package/dist/module-types-Cis4hrF1.d.ts +95 -0
  21. package/dist/remote-1Jz2oUMK.js +247 -0
  22. package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
  23. package/dist/runtime-DHp6ImeP.js +32 -0
  24. package/dist/runtime-type-DrmrW5m5.js +42 -0
  25. package/dist/session-DD0S1PDC.js +337 -0
  26. package/dist/shell-quote-Q3u3plif.js +6 -0
  27. package/dist/ssh.d.ts +55 -0
  28. package/dist/ssh.js +219 -0
  29. package/dist/task/index.d.ts +67 -0
  30. package/dist/task/index.js +1523 -0
  31. package/dist/task/runtime/empty-registry.d.ts +6 -0
  32. package/dist/{runtime → task/runtime}/empty-registry.js +2 -2
  33. package/dist/task/runtime/provider-loader.d.ts +20 -0
  34. package/dist/task/runtime/provider-loader.js +19 -0
  35. package/dist/task/runtime/providers/cloudflare.d.ts +28 -0
  36. package/dist/task/runtime/providers/cloudflare.js +26 -0
  37. package/dist/task/runtime/providers/vercel.d.ts +12 -0
  38. package/dist/{runtime → task/runtime}/providers/vercel.js +17 -14
  39. package/dist/task/runtime/state.d.ts +24 -0
  40. package/dist/task/runtime/state.js +73 -0
  41. package/dist/task/vite.d.ts +360 -0
  42. package/dist/task/vite.js +3643 -0
  43. package/dist/toolchain-BUVXtQ2m.js +527 -0
  44. package/dist/trusted-host-DNMJ-Oig.js +872 -0
  45. package/dist/vercel-Jtxa9TJx.js +279 -0
  46. package/package.json +103 -39
  47. package/dist/cloudflare-env-2NctU8i7.js +0 -12
  48. package/dist/module-types-DfXe133f.d.ts +0 -91
  49. package/dist/module-types-Dj1MFmHT.js +0 -7
  50. package/dist/provider-loader-hL7uHVWp.d.ts +0 -21
  51. package/dist/runtime/empty-registry.d.ts +0 -6
  52. package/dist/runtime/provider-loader.d.ts +0 -2
  53. package/dist/runtime/provider-loader.js +0 -15
  54. package/dist/runtime/providers/cloudflare.d.ts +0 -29
  55. package/dist/runtime/providers/cloudflare.js +0 -25
  56. package/dist/runtime/providers/vercel.d.ts +0 -112
  57. package/dist/runtime/state.d.ts +0 -17
  58. package/dist/runtime/state.js +0 -21
  59. package/dist/vite.d.ts +0 -24
  60. package/dist/vite.js +0 -2367
@@ -0,0 +1,6 @@
1
+ //#region src/task/runtime/empty-registry.d.ts
2
+ type SandboxTaskRegistry = Record<string, unknown>;
3
+ export interface SandboxTaskDefinitionModules {}
4
+ declare const registry: SandboxTaskRegistry;
5
+ //#endregion
6
+ export { registry as default };
@@ -1,6 +1,6 @@
1
- //#region src/runtime/empty-registry.ts
1
+ //#region src/task/runtime/empty-registry.ts
2
2
  function getRuntimeRegistry() {
3
- return globalThis.__vitehubSandboxRegistry || {};
3
+ return globalThis.__vitehubSandboxTaskRegistry || {};
4
4
  }
5
5
  const registry = new Proxy({}, {
6
6
  get(_target, key, receiver) {
@@ -0,0 +1,20 @@
1
+ import { l as Sandbox } from "../../index-CXej1Bt0.js";
2
+ import { l as SandboxTaskDefinitionOptions, p as SandboxTaskProvider, u as SandboxTaskDefinitionProviderOptions } from "../../module-types-Cis4hrF1.js";
3
+ //#region src/task/runtime/provider-loader.d.ts
4
+ export interface ResolvedTaskSandbox {
5
+ closeAfterRun?: boolean;
6
+ provider: SandboxTaskProvider;
7
+ resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
8
+ sandboxId?: string;
9
+ }
10
+ export interface SandboxTaskRuntimeProvider {
11
+ resolveTaskSandbox: (options: {
12
+ local: SandboxTaskDefinitionOptions;
13
+ provider: SandboxTaskDefinitionProviderOptions & {
14
+ provider: SandboxTaskProvider;
15
+ };
16
+ } | any, context?: any) => Promise<ResolvedTaskSandbox>;
17
+ }
18
+ export declare function unsupportedHostedSandboxTaskProviderError(provider: unknown): Error;
19
+ export declare function loadSandboxTaskRuntimeProvider(provider: SandboxTaskProvider): Promise<SandboxTaskRuntimeProvider>;
20
+ //#endregion
@@ -0,0 +1,19 @@
1
+ import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-dGQqfgLt.js";
2
+ //#region src/task/runtime/provider-loader.ts
3
+ const dynamicImport = new Function("specifier", "return import(specifier)");
4
+ function unsupportedHostedSandboxTaskProviderError(provider) {
5
+ return sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0076({ message: `[vitehub] Unsupported sandbox provider for this hosted build: ${String(provider)}` });
6
+ }
7
+ async function loadSandboxTaskRuntimeProvider(provider) {
8
+ if (provider === "cloudflare") {
9
+ const { resolveCloudflareTaskSandbox } = await dynamicImport("./providers/cloudflare.js");
10
+ return { resolveTaskSandbox: resolveCloudflareTaskSandbox };
11
+ }
12
+ if (provider === "vercel") {
13
+ const { resolveVercelTaskSandbox } = await dynamicImport("./providers/vercel.js");
14
+ return { resolveTaskSandbox: resolveVercelTaskSandbox };
15
+ }
16
+ throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0068({ message: `[vitehub] Unsupported sandbox provider: ${provider}` });
17
+ }
18
+ //#endregion
19
+ export { loadSandboxTaskRuntimeProvider, unsupportedHostedSandboxTaskProviderError };
@@ -0,0 +1,28 @@
1
+ import { l as Sandbox } from "../../../index-CXej1Bt0.js";
2
+ import { l as SandboxTaskDefinitionOptions, n as CloudflareSandboxTaskDefinitionProviderOptions } from "../../../module-types-Cis4hrF1.js";
3
+ //#region src/task/runtime/providers/cloudflare.d.ts
4
+ type SandboxTaskOptions = {
5
+ local: SandboxTaskDefinitionOptions;
6
+ provider: CloudflareSandboxTaskDefinitionProviderOptions;
7
+ };
8
+ type SandboxTaskEvent = {
9
+ context?: {
10
+ cloudflare?: {
11
+ env?: Record<string, unknown>;
12
+ };
13
+ _platform?: {
14
+ cloudflare?: {
15
+ env?: Record<string, unknown>;
16
+ };
17
+ };
18
+ };
19
+ };
20
+ export declare function resolveCloudflareTaskSandbox(options: SandboxTaskOptions, context?: {
21
+ event?: SandboxTaskEvent;
22
+ }): Promise<{
23
+ closeAfterRun: boolean;
24
+ provider: "cloudflare";
25
+ sandboxId: string | undefined;
26
+ resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
27
+ }>;
28
+ //#endregion
@@ -0,0 +1,26 @@
1
+ import { resolveCloudflareSandbox } from "../../../internal/cloudflare.js";
2
+ import { t as sandboxTaskErrorDiagnostics } from "../../../error-diagnostics-dGQqfgLt.js";
3
+ import { t as getCloudflareEnv } from "../../../cloudflare-env-BBJaBbuQ.js";
4
+ //#region src/task/runtime/providers/cloudflare.ts
5
+ async function resolveCloudflareTaskSandbox(options, context = {}) {
6
+ const env = getCloudflareEnv(context.event);
7
+ const bindingName = options.provider.binding || "SANDBOX";
8
+ const namespace = env && Object.hasOwn(env, bindingName) ? env[bindingName] : void 0;
9
+ if (!namespace) throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0071({ message: `Cloudflare sandbox requires the "${bindingName}" binding. Set sandbox.binding or run inside Cloudflare. The cloudflare preset writes the binding and its Container to .output/server/wrangler.json, and the Vite or Nuxt dev server cannot host them: build, then run \`npx wrangler --cwd .output/server dev\` (needs Docker).` });
10
+ return {
11
+ closeAfterRun: options.provider.keepAlive === true,
12
+ provider: "cloudflare",
13
+ sandboxId: options.provider.sandboxId,
14
+ resolveSandbox: async (requirements) => await resolveCloudflareSandbox({
15
+ namespace,
16
+ sandboxId: options.provider.sandboxId,
17
+ cloudflare: {
18
+ sleepAfter: options.provider.sleepAfter ?? "5m",
19
+ keepAlive: options.provider.keepAlive,
20
+ normalizeId: options.provider.normalizeId
21
+ }
22
+ }, requirements)
23
+ };
24
+ }
25
+ //#endregion
26
+ export { resolveCloudflareTaskSandbox };
@@ -0,0 +1,12 @@
1
+ import { l as Sandbox } from "../../../index-CXej1Bt0.js";
2
+ import { h as VercelSandboxTaskProviderOptions, l as SandboxTaskDefinitionOptions } from "../../../module-types-Cis4hrF1.js";
3
+ //#region src/task/runtime/providers/vercel.d.ts
4
+ type SandboxTaskOptions = {
5
+ local: SandboxTaskDefinitionOptions;
6
+ provider: VercelSandboxTaskProviderOptions;
7
+ };
8
+ export declare function resolveVercelTaskSandbox(options: SandboxTaskOptions): Promise<{
9
+ provider: "vercel";
10
+ resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
11
+ }>;
12
+ //#endregion
@@ -1,22 +1,25 @@
1
- import { resolveVercelBox } from "@vite-hub/box/_internal/vercel";
2
- //#region src/internal/shared/env.ts
3
- function readNonEmptyEnv(env, ...keys) {
4
- for (const key of keys) {
5
- const trimmed = env[key]?.trim();
6
- if (trimmed) return trimmed;
1
+ import { resolveVercelSandbox } from "../../../internal/vercel.js";
2
+ //#region ../internal/src/env.ts
3
+ function trimmed(value) {
4
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
5
+ }
6
+ function readEnv(env, ...names) {
7
+ for (const name of names) {
8
+ const value = trimmed(env[name]);
9
+ if (value) return value;
7
10
  }
8
11
  }
9
12
  //#endregion
10
- //#region src/runtime/providers/vercel.ts
13
+ //#region src/task/runtime/providers/vercel.ts
11
14
  function readConfigCredential(value) {
12
15
  return value?.trim() || void 0;
13
16
  }
14
17
  function resolveEnvCredentials() {
15
18
  const env = typeof process !== "undefined" ? process.env : {};
16
19
  return {
17
- token: readNonEmptyEnv(env, "VITE_SANDBOX_TOKEN", "VERCEL_TOKEN"),
18
- teamId: readNonEmptyEnv(env, "VITE_SANDBOX_TEAM_ID", "VERCEL_TEAM_ID"),
19
- projectId: readNonEmptyEnv(env, "VITE_SANDBOX_PROJECT_ID", "VERCEL_PROJECT_ID")
20
+ token: readEnv(env, "VITE_SANDBOX_TOKEN", "VERCEL_TOKEN"),
21
+ teamId: readEnv(env, "VITE_SANDBOX_TEAM_ID", "VERCEL_TEAM_ID"),
22
+ projectId: readEnv(env, "VITE_SANDBOX_PROJECT_ID", "VERCEL_PROJECT_ID")
20
23
  };
21
24
  }
22
25
  function resolveCredentials(provider) {
@@ -31,9 +34,9 @@ function resolveCredentials(provider) {
31
34
  projectId
32
35
  };
33
36
  }
34
- async function resolveVercelSandboxBox(options) {
37
+ async function resolveVercelTaskSandbox(options) {
35
38
  const credentials = resolveCredentials(options.provider);
36
- const boxOptions = {
39
+ const sandboxOptions = {
37
40
  runtime: options.provider.runtime || "node24",
38
41
  timeout: typeof options.local.timeout === "number" ? options.local.timeout : options.provider.timeout,
39
42
  cpu: options.provider.cpu,
@@ -44,8 +47,8 @@ async function resolveVercelSandboxBox(options) {
44
47
  };
45
48
  return {
46
49
  provider: "vercel",
47
- resolveBox: async (requirements) => await resolveVercelBox(boxOptions, requirements)
50
+ resolveSandbox: async (requirements) => await resolveVercelSandbox(sandboxOptions, requirements)
48
51
  };
49
52
  }
50
53
  //#endregion
51
- export { resolveVercelSandboxBox };
54
+ export { resolveVercelTaskSandbox };
@@ -0,0 +1,24 @@
1
+ import { a as SandboxTaskDefinitionBundle, l as SandboxTaskDefinitionOptions, t as AgentSandboxTaskConfig } from "../../module-types-Cis4hrF1.js";
2
+ //#region src/task/runtime/state.d.ts
3
+ export type SandboxTaskRegistryEntry = {
4
+ bundle: SandboxTaskDefinitionBundle;
5
+ options?: SandboxTaskDefinitionOptions;
6
+ };
7
+ export type SandboxTaskRuntimeRegistry = Record<string, SandboxTaskRegistryEntry | (() => Promise<{
8
+ default?: SandboxTaskRegistryEntry;
9
+ }>)>;
10
+ type GeneratedSandboxTaskRuntimeRegistryEntry = {
11
+ load: () => Promise<{
12
+ default?: SandboxTaskRegistryEntry;
13
+ }>;
14
+ stablePath: string;
15
+ };
16
+ type GeneratedSandboxTaskRuntimeRegistry = Record<string, GeneratedSandboxTaskRuntimeRegistryEntry>;
17
+ export declare function createGeneratedSandboxTaskModuleSpecifier(path: string, recover?: boolean): string;
18
+ export declare function createGeneratedSandboxTaskRuntimeRegistry(scope: string, registry: GeneratedSandboxTaskRuntimeRegistry): SandboxTaskRuntimeRegistry;
19
+ export declare function getSandboxTaskRuntimeConfig(): false | AgentSandboxTaskConfig | undefined;
20
+ export declare function getSandboxTaskRuntimeRegistry(): SandboxTaskRuntimeRegistry | undefined;
21
+ export declare function setSandboxTaskRuntimeConfig(config: false | AgentSandboxTaskConfig | undefined): void;
22
+ export declare function setSandboxTaskRuntimeRegistry(registry: SandboxTaskRuntimeRegistry | undefined): void;
23
+ export declare function resetSandboxTaskRuntimeState(): void;
24
+ //#endregion
@@ -0,0 +1,73 @@
1
+ import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-dGQqfgLt.js";
2
+ import { pathToFileURL } from "node:url";
3
+ //#region src/task/runtime/state.ts
4
+ let sandboxTaskConfig;
5
+ let sandboxTaskRegistry;
6
+ const generatedRegistries = /* @__PURE__ */ new Map();
7
+ const generatedRegistryOwnership = /* @__PURE__ */ new WeakMap();
8
+ let generatedRegistryRecoveryId = 0;
9
+ function isMissingGeneratedSandboxTaskModule(error) {
10
+ const code = Reflect.get(Object(error), "code");
11
+ return code === "ENOENT" || code === "ERR_MODULE_NOT_FOUND";
12
+ }
13
+ function createGeneratedSandboxTaskModuleSpecifier(path, recover = false) {
14
+ const normalizedPath = path.replaceAll("\\", "/");
15
+ const url = normalizedPath.startsWith("file:") ? new URL(normalizedPath) : pathToFileURL(normalizedPath);
16
+ if (recover) url.searchParams.set("vitehub-recovery", String(++generatedRegistryRecoveryId));
17
+ return url.href;
18
+ }
19
+ async function loadActiveGeneratedSandboxTaskDefinition(scope, name) {
20
+ const activeEntry = (await import(
21
+ /* @vite-ignore */
22
+ createGeneratedSandboxTaskModuleSpecifier(scope, true)
23
+ )).default?.[name];
24
+ if (!activeEntry) throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0074({ message: `[vitehub] Sandbox Task Definition "${name}" is no longer generated.` });
25
+ return typeof activeEntry === "function" ? await activeEntry() : { default: activeEntry };
26
+ }
27
+ function createGeneratedSandboxTaskRuntimeRegistry(scope, registry) {
28
+ const runtimeRegistry = Object.fromEntries(Object.keys(registry).map((name) => [name, async () => {
29
+ const activeRegistry = generatedRegistries.get(scope);
30
+ const entry = activeRegistry === void 0 ? registry[name] : activeRegistry[name];
31
+ if (!entry) throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0075({ message: `[vitehub] Sandbox Task Definition "${name}" is no longer generated.` });
32
+ try {
33
+ return await entry.load();
34
+ } catch (error) {
35
+ if (!isMissingGeneratedSandboxTaskModule(error)) throw error;
36
+ try {
37
+ return await import(
38
+ /* @vite-ignore */
39
+ createGeneratedSandboxTaskModuleSpecifier(entry.stablePath, true)
40
+ );
41
+ } catch (stableError) {
42
+ if (!isMissingGeneratedSandboxTaskModule(stableError)) throw stableError;
43
+ return await loadActiveGeneratedSandboxTaskDefinition(scope, name);
44
+ }
45
+ }
46
+ }]));
47
+ generatedRegistryOwnership.set(runtimeRegistry, {
48
+ registry,
49
+ scope
50
+ });
51
+ return runtimeRegistry;
52
+ }
53
+ function getSandboxTaskRuntimeConfig() {
54
+ return sandboxTaskConfig;
55
+ }
56
+ function getSandboxTaskRuntimeRegistry() {
57
+ return sandboxTaskRegistry;
58
+ }
59
+ function setSandboxTaskRuntimeConfig(config) {
60
+ sandboxTaskConfig = config;
61
+ }
62
+ function setSandboxTaskRuntimeRegistry(registry) {
63
+ sandboxTaskRegistry = registry;
64
+ const generated = registry && generatedRegistryOwnership.get(registry);
65
+ if (generated) generatedRegistries.set(generated.scope, generated.registry);
66
+ }
67
+ function resetSandboxTaskRuntimeState() {
68
+ sandboxTaskConfig = void 0;
69
+ sandboxTaskRegistry = void 0;
70
+ generatedRegistries.clear();
71
+ }
72
+ //#endregion
73
+ export { createGeneratedSandboxTaskModuleSpecifier, createGeneratedSandboxTaskRuntimeRegistry, getSandboxTaskRuntimeConfig, getSandboxTaskRuntimeRegistry, resetSandboxTaskRuntimeState, setSandboxTaskRuntimeConfig, setSandboxTaskRuntimeRegistry };
@@ -0,0 +1,360 @@
1
+ import { t as AgentSandboxTaskConfig } from "../module-types-Cis4hrF1.js";
2
+ import { Plugin } from "vite";
3
+ //#region ../internal/src/inspect.d.ts
4
+ interface ViteHubDefinitionField {
5
+ label: string;
6
+ value: string;
7
+ }
8
+ /** Serializable summary of one discovered Definition. Files are relative to the project root. */
9
+ interface ViteHubDefinitionSummary {
10
+ fields: readonly ViteHubDefinitionField[];
11
+ file: string;
12
+ name: string;
13
+ source: string;
14
+ }
15
+ /** Lists the Definitions that one owner package discovered for the resolved Vite config. */
16
+ interface ViteHubDefinitionInspector {
17
+ /** Stable singular kind, for example `queue` or `rate-limit`. */
18
+ kind: string;
19
+ label: string;
20
+ list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
21
+ }
22
+ /** One generated Provider Output file or directory that an owner package can write. */
23
+ interface ViteHubProviderOutputEntry {
24
+ description: string;
25
+ owner: string;
26
+ /** Absolute path. */
27
+ path: string;
28
+ }
29
+ interface ViteHubInspectionContributor {
30
+ definitions?: readonly ViteHubDefinitionInspector[];
31
+ providerOutput?: readonly ViteHubProviderOutputEntry[];
32
+ }
33
+ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
34
+ interface ViteHubInspectionPluginMetadata {
35
+ inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
36
+ }
37
+ //#endregion
38
+ //#region src/task/internal/shared/feature-definitions.d.ts
39
+ interface ScannedDefinition {
40
+ name: string;
41
+ handler: string;
42
+ _meta: {
43
+ filename: string;
44
+ sourcePath: string;
45
+ };
46
+ }
47
+ //#endregion
48
+ //#region src/task/discovery.d.ts
49
+ interface DiscoveredSandboxTaskDefinition extends ScannedDefinition {
50
+ kind: 'definition' | 'package-entry';
51
+ source: 'server-sandbox-tasks' | 'vite-suffix';
52
+ }
53
+ export declare function discoverSandboxTaskDefinitions(options: {
54
+ mode?: 'vite-suffix';
55
+ rootDir: string;
56
+ scanDirs?: string[];
57
+ } | {
58
+ mode: 'server-sandbox-tasks';
59
+ scanDirs: string[];
60
+ }): DiscoveredSandboxTaskDefinition[];
61
+ //#endregion
62
+ //#region ../internal/src/console.d.ts
63
+ type MaybePromise<T> = T | Promise<T>;
64
+ /** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
65
+ interface ViteHubConsoleDefinitionCatalogView {
66
+ kind: "definition-catalog";
67
+ /** States which runtime data this catalog does not include. */
68
+ notice: string;
69
+ }
70
+ interface ViteHubConsoleRecordColumn {
71
+ /** Key in `ViteHubConsoleRecord.cells`. */
72
+ key: string;
73
+ label: string;
74
+ }
75
+ /** Shows records in a table and the selected record's fields in a detail panel. */
76
+ interface ViteHubConsoleRecordTableView {
77
+ columns: readonly ViteHubConsoleRecordColumn[];
78
+ kind: "record-table";
79
+ /** States the source and limits of the records. */
80
+ notice: string;
81
+ }
82
+ /**
83
+ * Lists the collections and documents of an owner runtime and edits them with owner actions: a form generated from each
84
+ * collection's JSON Schema, a Markdown body, save, publish, and revision history.
85
+ */
86
+ interface ViteHubConsoleDocumentEditorView {
87
+ kind: "document-editor";
88
+ /** States where documents are stored and what the editor does not do. */
89
+ notice: string;
90
+ }
91
+ interface ViteHubConsoleOperationColumn {
92
+ /** Dot path into each item of the result, such as `author.name` or `messages.0.body`. */
93
+ key: string;
94
+ label: string;
95
+ /** `datetime` shows a time in milliseconds since the epoch as a date. `excerpt` cuts a long text. */
96
+ format?: "datetime" | "excerpt";
97
+ }
98
+ /** A chip above the list. Choosing it merges `input` into the operation input. The first chip is the default. */
99
+ interface ViteHubConsoleOperationFilter {
100
+ id: string;
101
+ label: string;
102
+ input: Readonly<Record<string, unknown>>;
103
+ }
104
+ /**
105
+ * Lists the items that an operation returns, called over the Console RPC with the signed-in Console user. The operation
106
+ * checks the access of that user for each item, so the view shows only what the user may read. `operation` must return an
107
+ * array of objects with an `id`. A failure of the operation, with its `fix`, shows where the list would be.
108
+ */
109
+ interface ViteHubConsoleOperationView {
110
+ columns: readonly ViteHubConsoleOperationColumn[];
111
+ filters?: readonly ViteHubConsoleOperationFilter[];
112
+ kind: "operation-view";
113
+ /**
114
+ * Makes each row a link: `{path}` placeholders take values from the item and are URL-encoded, and `{path:path}` takes an
115
+ * app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link). Rows where
116
+ * `when.path` is not `when.equals` get none.
117
+ */
118
+ link?: {
119
+ label?: string;
120
+ template: string;
121
+ when?: {
122
+ equals: string;
123
+ path: string;
124
+ };
125
+ };
126
+ notice: string;
127
+ /** Operation name, such as `comments.list`. */
128
+ operation: string;
129
+ /** Fetch every page with `limit` and a `before` object whose keys read these dot paths from the last item. */
130
+ pagination?: {
131
+ limit: number;
132
+ cursor: Readonly<Record<string, string>>;
133
+ };
134
+ }
135
+ interface ViteHubConsoleAuthView {
136
+ kind: "auth-management";
137
+ notice: string;
138
+ }
139
+ interface ViteHubConsoleAuthSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleAuthView> {}
140
+ type ViteHubConsoleSectionView = ViteHubConsoleOperationView | ViteHubConsoleAuthView | ViteHubConsoleDefinitionCatalogView | ViteHubConsoleRecordTableView | ViteHubConsoleDocumentEditorView;
141
+ /**
142
+ * The overview of a document editor section: document counts by state, the changes that wait for a publish, recent
143
+ * activity, and a New button per collection. It reads the owner `overview` action.
144
+ */
145
+ interface ViteHubConsoleDocumentDashboardView {
146
+ kind: "document-dashboard";
147
+ }
148
+ /**
149
+ * The media library of a document editor section: folders, uploads, alt text, focal points, and crops of the Blob Store
150
+ * that `blob.serve` serves. The owner decides who may use it with `mediaAccess`, and finds the documents that use a file
151
+ * with `references`. The page needs the Blob section, so declare it with `requires: ["blob"]`.
152
+ */
153
+ interface ViteHubConsoleMediaLibraryView {
154
+ kind: "media-library";
155
+ }
156
+ /**
157
+ * The singletons of a document editor section, such as site settings: one row per singleton that opens it in the
158
+ * editor. Singletons appear here instead of among the collections, and the Console hides the page when the section has
159
+ * none.
160
+ */
161
+ interface ViteHubConsoleDocumentSettingsView {
162
+ kind: "document-settings";
163
+ }
164
+ /** A view that the Console UI in `vite-hub` renders for a section page. */
165
+ type ViteHubConsoleSectionPageView = ViteHubConsoleDocumentDashboardView | ViteHubConsoleDocumentSettingsView | ViteHubConsoleMediaLibraryView;
166
+ /**
167
+ * A page of a section next to its main view, such as the Content dashboard or media library. The section sidebar lists
168
+ * the pages, and each page has its own URL:
169
+ *
170
+ * - `/_vitehub/<section>` serves the `index` page, or the main view when the section has none.
171
+ * - `/_vitehub/<section>/-/<page>` serves every other page. The `-` segment keeps page URLs apart from the main view's
172
+ * own segments, such as a collection name.
173
+ *
174
+ * Pages share the access of their section: `console.authorize` that allows the section allows every page of it.
175
+ */
176
+ interface ViteHubConsoleSectionPage {
177
+ /** Lowercase route segment, for example `media`. */
178
+ id: string;
179
+ /** Display name, for example `Media`. */
180
+ label: string;
181
+ /** Iconify class name, for example `i-lucide-image`. */
182
+ icon: string;
183
+ view: ViteHubConsoleSectionPageView;
184
+ /**
185
+ * Serve this page at the section root. At most one page sets it, and `/_vitehub/<section>/-/<id>` then redirects to
186
+ * the root.
187
+ */
188
+ index?: boolean;
189
+ /**
190
+ * Sidebar heading, for example `Assets`. Pages without a group lead the sidebar, above the main view's navigation.
191
+ * Grouped pages follow it, in the order their group first appears.
192
+ */
193
+ group?: string;
194
+ /** Section ids that the project must enable, such as `["blob"]`. The Console leaves the page out otherwise. */
195
+ requires?: readonly string[];
196
+ }
197
+ /** One entry of a record's activity, such as a comment in a thread. `at` is an ISO 8601 timestamp. */
198
+ interface ViteHubConsoleRecordActivity {
199
+ author: string;
200
+ at: string;
201
+ text: string;
202
+ }
203
+ /** One serializable record row. Values are display strings. Do not put credentials in records. */
204
+ interface ViteHubConsoleRecord {
205
+ cells: Readonly<Record<string, string>>;
206
+ fields: readonly ViteHubDefinitionField[];
207
+ id: string;
208
+ /** The Console can run this record when it represents a runnable Schedule Definition. */
209
+ runnable?: boolean;
210
+ /**
211
+ * Where the record lives in the app, such as the page of a comment thread. `href` is an app path that starts with one
212
+ * `/`, or an `https:` URL. The Console opens it in a new tab.
213
+ */
214
+ link?: {
215
+ href: string;
216
+ label: string;
217
+ };
218
+ /** Entries in time order, such as the comments of a thread. The Console shows them as a conversation. */
219
+ activity?: readonly ViteHubConsoleRecordActivity[];
220
+ }
221
+ /** Serializable description of a Console section. The Console UI in `vite-hub` renders the view. */
222
+ interface ViteHubConsoleSectionDescriptor<TView extends ViteHubConsoleSectionView = ViteHubConsoleSectionView> {
223
+ description: string;
224
+ /**
225
+ * Iconify class name, for example `i-lucide-inbox`. The Console draws with Lucide; `ph` also resolves. The
226
+ * Console build bundles the icon of every section in the `vite-hub` Console registry and fails if it cannot resolve one.
227
+ */
228
+ icon: string;
229
+ /** Lowercase route segment, for example `queues`. The Console serves the section at `/_vitehub/<id>`. */
230
+ id: string;
231
+ /** Plural display name, for example `Queues`. */
232
+ label: string;
233
+ view: TView;
234
+ /** Pages next to the main view, in sidebar order. Only document editor sections render pages today. */
235
+ pages?: readonly ViteHubConsoleSectionPage[];
236
+ }
237
+ interface ViteHubConsoleDefinitionCatalogSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleDefinitionCatalogView> {
238
+ /** Reads the section data on the server. The Console never runs it in the browser. */
239
+ read: (options: TOptions) => MaybePromise<readonly ViteHubDefinitionSummary[]>;
240
+ }
241
+ interface ViteHubConsoleRecordTableSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleRecordTableView> {
242
+ /** Reads the section data on the server. The Console never runs it in the browser. */
243
+ read: (options: TOptions) => MaybePromise<readonly ViteHubConsoleRecord[]>;
244
+ }
245
+ /** A named export of an owner package server module that the host imports in its generated server code. */
246
+ interface ViteHubConsoleServerExport {
247
+ /** Named export of `module`. */
248
+ export: string;
249
+ /**
250
+ * Owner package module specifier, for example `@vite-hub/email/runtime/console`. The host maps it to the module
251
+ * path that the application can import.
252
+ */
253
+ module: string;
254
+ }
255
+ /**
256
+ * Server module export that returns records on each Console request. The export must be a
257
+ * {@link ViteHubConsoleRuntimeRecordReader}.
258
+ */
259
+ interface ViteHubConsoleRuntimeReader extends ViteHubConsoleServerExport {}
260
+ /**
261
+ * A record table that also reads records at request time. The Console shows the build-time records of `read` first,
262
+ * then the records of the `runtime` reader. A runtime record replaces a build-time record with the same id.
263
+ */
264
+ interface ViteHubConsoleRuntimeRecordTableSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleRecordTableView> {
265
+ /** Reads build-time records on the server. When omitted, the section has only runtime records. */
266
+ read?: (options: TOptions) => MaybePromise<readonly ViteHubConsoleRecord[]>;
267
+ runtime: ViteHubConsoleRuntimeReader;
268
+ /**
269
+ * Returns the absolute path of the application module that turns the section on, such as `server/comments.ts`, or
270
+ * `undefined` when the project has none. With it, the host shows the section only when the module exists; without
271
+ * it, a Vite option enables the section.
272
+ */
273
+ entry?: (options: TOptions) => MaybePromise<string | undefined>;
274
+ }
275
+ /** A section whose list comes from an operation, called with the Console user on each visit. It has no build-time data. */
276
+ interface ViteHubConsoleOperationSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleOperationView> {}
277
+ /**
278
+ * A document editor section. The owner finds the application module that holds its runtime, such as `server/content.ts`,
279
+ * and names the server export that turns that module into {@link ViteHubConsoleDocumentActions}. The host shows the
280
+ * section only when `entry` finds a module, imports the module on the first Console request, and checks the Console
281
+ * section before it calls an action. The owner actions check their own access policy for the signed-in user.
282
+ */
283
+ interface ViteHubConsoleDocumentEditorSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleDocumentEditorView> {
284
+ /** Returns the absolute path of the application module, or `undefined` when the project has none. */
285
+ entry: (options: TOptions) => MaybePromise<string | undefined>;
286
+ /**
287
+ * Reads, at build time and without running the application, what the project lacks for some editor features, such as
288
+ * a runner for scheduled publishes. The Console merges it with the owner `setup` action on each request.
289
+ */
290
+ inspect?: (options: TOptions, entry: string) => MaybePromise<ViteHubConsoleDocumentSetup>;
291
+ /** Owner export that must be a {@link ViteHubConsoleDocumentActionsFactory}. */
292
+ actions: ViteHubConsoleServerExport;
293
+ }
294
+ /**
295
+ * A Console section that an owner package contributes. The owner defines the label, icon, view, and data reader.
296
+ * `TOptions` is the discovery context that the host passes to `read`.
297
+ */
298
+ type ViteHubConsoleSectionContribution<TOptions = void> = ViteHubConsoleAuthSection | ViteHubConsoleDefinitionCatalogSection<TOptions> | ViteHubConsoleRecordTableSection<TOptions> | ViteHubConsoleRuntimeRecordTableSection<TOptions> | ViteHubConsoleDocumentEditorSection<TOptions> | ViteHubConsoleOperationSection;
299
+ /** A fix that the owner names for a feature the project lacks, such as `Add authorize to defineContent().` */
300
+ interface ViteHubConsoleDocumentHint {
301
+ /** One sentence that names the fix. Text in backticks shows as code. */
302
+ message: string;
303
+ /** Absolute URL of the documentation for the fix. */
304
+ docs?: string;
305
+ }
306
+ /**
307
+ * What the project lacks for some editor features. The editor names each fix where the feature would be, instead of
308
+ * failing without a reason.
309
+ */
310
+ interface ViteHubConsoleDocumentSetup {
311
+ /** Present when no user can read anything because the owner has no access policy. */
312
+ access?: ViteHubConsoleDocumentHint;
313
+ /**
314
+ * Live co-editing. `definition` names the Realtime Definition whose rooms are `<collection>/<id>`; the editor joins
315
+ * the room of a Markdown document instead of taking the edit lease. `unavailable` names why the owner wanted live
316
+ * editing and the host cannot run it, such as a host without a Realtime authority. Absent when live editing is off.
317
+ */
318
+ live?: {
319
+ definition: string;
320
+ } | {
321
+ unavailable: string;
322
+ };
323
+ /**
324
+ * Present when nothing runs scheduled publishes. The editor disables Schedule, and overdue schedules name the fix.
325
+ */
326
+ schedule?: ViteHubConsoleDocumentHint;
327
+ }
328
+ //#endregion
329
+ //#region src/task/inspect.d.ts
330
+ interface SandboxTaskInspectionOptions {
331
+ projectRoot: string;
332
+ rootDir: string;
333
+ }
334
+ /** Lists Sandbox Task Definitions and package entries as serializable inspection summaries. */
335
+ export declare function inspectSandboxTaskDefinitions(options: SandboxTaskInspectionOptions): ViteHubDefinitionSummary[];
336
+ /** Console section that lists discovered Sandbox Task Definitions. `vitehub inspect definitions` reads the same data. */
337
+ export declare const sandboxTaskConsoleSection: ViteHubConsoleSectionContribution<SandboxTaskInspectionOptions>;
338
+ //#endregion
339
+ //#region src/task/vite.d.ts
340
+ export type SandboxTaskPublicOptions = AgentSandboxTaskConfig | false;
341
+ export type SandboxTaskVitePlugin = Plugin & {
342
+ vitehub: ViteHubInspectionPluginMetadata;
343
+ nitro: {
344
+ name: string;
345
+ setup: (nitro: {
346
+ hooks: {
347
+ hook: (name: 'build:before', callback: () => void) => void;
348
+ };
349
+ options: Record<string, unknown>;
350
+ }) => void;
351
+ };
352
+ };
353
+ export declare function hubSandboxTask(options?: SandboxTaskPublicOptions): SandboxTaskVitePlugin;
354
+ declare module 'vite' {
355
+ interface UserConfig {
356
+ sandboxTask?: SandboxTaskPublicOptions;
357
+ }
358
+ }
359
+ //#endregion
360
+ export type { DiscoveredSandboxTaskDefinition, SandboxTaskInspectionOptions };