@vite-hub/workspace 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 (129) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +236 -58
  3. package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  4. package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
  5. package/dist/ai.d.ts +2 -2
  6. package/dist/ai.js +1 -1
  7. package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
  8. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  9. package/dist/blob-database.d.ts +521 -0
  10. package/dist/blob-database.js +601 -0
  11. package/dist/cloudflare.d.ts +5 -6
  12. package/dist/cloudflare.js +1 -1
  13. package/dist/config-B7dmzDX3.js +1112 -0
  14. package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
  15. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  16. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  17. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  18. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  19. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  20. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  21. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  22. package/dist/file-C0_aPWSS.js +26 -0
  23. package/dist/file-metadata-CxDy-E2H.js +58 -0
  24. package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
  25. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  26. package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
  27. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  28. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  29. package/dist/glob--XcLlcml.js +22 -0
  30. package/dist/glob--kNYDbfU.js +30 -0
  31. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  32. package/dist/host-CFnrTXTK.js +1086 -0
  33. package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
  34. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  35. package/dist/hosted-vercel-blob.d.ts +5 -6
  36. package/dist/hosted-vercel-blob.js +1 -1
  37. package/dist/hosted.d.ts +6 -7
  38. package/dist/hosted.js +1 -1
  39. package/dist/index.d.ts +76 -64
  40. package/dist/index.js +162 -457
  41. package/dist/inspect-BoObD2cJ.js +167 -0
  42. package/dist/internal/path.d.ts +2 -0
  43. package/dist/internal/path.js +2 -0
  44. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  45. package/dist/loader.d.ts +5 -6
  46. package/dist/loader.js +3 -2
  47. package/dist/mcp-resources-BREFCmtn.js +39 -0
  48. package/dist/memory-BbwOqDXl.js +248 -0
  49. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  50. package/dist/mountx.d.ts +4 -6
  51. package/dist/mountx.js +10 -8
  52. package/dist/nitro.d.ts +1 -1
  53. package/dist/nitro.js +1 -1
  54. package/dist/nuxt.d.ts +13 -12
  55. package/dist/nuxt.js +10 -8
  56. package/dist/operations-BcpWr41m.js +159 -0
  57. package/dist/operations-CGqY1XeG.js +965 -0
  58. package/dist/operations-DnOwKsJT.d.ts +136 -0
  59. package/dist/operations.d.ts +53 -0
  60. package/dist/operations.js +2 -0
  61. package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
  62. package/dist/path-DrSIenjj.js +59 -0
  63. package/dist/path-zHxQUbqa.d.ts +9 -0
  64. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  65. package/dist/provider-kXjfli9u.js +1457 -0
  66. package/dist/providers/github/store.d.ts +3 -5
  67. package/dist/providers/github/store.js +1 -1
  68. package/dist/registry-Bp-8UUfG.js +129 -0
  69. package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
  70. package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
  71. package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
  72. package/dist/runtime/assets.d.ts +3 -5
  73. package/dist/runtime/assets.js +9 -6
  74. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  75. package/dist/runtime/empty-registry.d.ts +1 -2
  76. package/dist/runtime/state.d.ts +4 -4
  77. package/dist/runtime/state.js +10 -7
  78. package/dist/runtime/workspace.d.ts +1 -1
  79. package/dist/runtime/workspace.js +1 -1
  80. package/dist/runtime.d.ts +84 -15
  81. package/dist/runtime.js +561 -108
  82. package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
  83. package/dist/server-BNQ-Nbjj.js +290 -0
  84. package/dist/server.d.ts +22 -34
  85. package/dist/server.js +2 -355
  86. package/dist/shared-DalXdP0i.js +2158 -0
  87. package/dist/source-metadata.d.ts +7 -1
  88. package/dist/source-metadata.js +34 -2
  89. package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
  90. package/dist/store-CXgmu-uw.js +1729 -0
  91. package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
  92. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  93. package/dist/test.d.ts +1 -1
  94. package/dist/test.js +1 -1
  95. package/dist/token-CO62GglH.js +61 -0
  96. package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
  97. package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
  98. package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
  99. package/dist/utils-Blrh4N2n.js +545 -0
  100. package/dist/vite-BEvgU2GY.js +20909 -0
  101. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  102. package/dist/vite.d.ts +2 -50
  103. package/dist/vite.js +2 -2
  104. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  105. package/dist/workspace-6pxkOuxr.js +1286 -0
  106. package/dist/workspace-BWJQBK1u.d.ts +7 -0
  107. package/package.json +90 -59
  108. package/dist/chunk-8H4AJuhK.js +0 -14
  109. package/dist/collections/client.d.ts +0 -39
  110. package/dist/collections/client.js +0 -137
  111. package/dist/collections.d.ts +0 -59
  112. package/dist/collections.js +0 -159
  113. package/dist/config-CDoyls2X.js +0 -30
  114. package/dist/config-CZLO0m9h.js +0 -7811
  115. package/dist/file-CHfsZpso.js +0 -23
  116. package/dist/glob-D0vD_wRY.js +0 -17
  117. package/dist/host-CAnbugpI.js +0 -370
  118. package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
  119. package/dist/lifecycle-BYoa9hVb.js +0 -176
  120. package/dist/provider-C3_elpEh.js +0 -599
  121. package/dist/publish.d.ts +0 -35
  122. package/dist/publish.js +0 -112
  123. package/dist/registry-CqyDTW9Y.js +0 -74
  124. package/dist/runtime-options-BsPSv5O7.js +0 -13
  125. package/dist/shared-jfogBrd5.js +0 -273
  126. package/dist/store-Bs1SLh55.js +0 -414
  127. package/dist/vite-tbfDxtlu.js +0 -2191
  128. package/dist/workspace-66SKyiec.d.ts +0 -6
  129. package/dist/workspace-C4k92Ow8.js +0 -1460
@@ -0,0 +1,136 @@
1
+ import { StandardSchemaV1 } from "@standard-schema/spec";
2
+ //#region ../internal/src/operations.d.ts
3
+ /** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
4
+ type OperationKind = "read" | "write" | "destructive";
5
+ /** The signed-in user of a call. */
6
+ interface OperationUser {
7
+ id: string;
8
+ name?: string;
9
+ email?: string;
10
+ image?: string;
11
+ [key: string]: unknown;
12
+ }
13
+ /** The Agent Actor when an agent calls through a capability or MCP on behalf of a user. */
14
+ interface OperationActor {
15
+ id: string;
16
+ kind?: string;
17
+ label?: string;
18
+ meta?: object;
19
+ }
20
+ /** The checked Console access of a call. `vite-hub` issues it. `ConsoleAccess` has this shape. */
21
+ interface OperationAccess {
22
+ readonly mode: string;
23
+ /**
24
+ * The sections that the call may use. `"all"` when no section filter applies. An entry is a section id (`"kv"`, every
25
+ * operation of the section) or `"<section>:read"` (only the operations that read).
26
+ */
27
+ readonly sections: "all" | readonly string[];
28
+ readonly user?: OperationUser;
29
+ }
30
+ interface OperationContext {
31
+ /** The checked Console access of the call. */
32
+ access: OperationAccess;
33
+ /** The signed-in user, or null. */
34
+ user: OperationUser | null;
35
+ /** The Agent Actor when an agent calls on behalf of `user`. */
36
+ actor?: OperationActor;
37
+ surface: "console" | "cli" | "mcp" | "agent";
38
+ /** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
39
+ development?: boolean;
40
+ env?: Record<string, unknown>;
41
+ waitUntil?: (task: Promise<unknown>) => void;
42
+ request?: Request;
43
+ /** Operations set a success status here, such as 202 for an accepted call. */
44
+ response?: {
45
+ status?: number;
46
+ };
47
+ /**
48
+ * An agent or an MCP client may pass `lease: "override"` to `content.save`, `content.remove`, and `content.restore`
49
+ * only when the developer allowed it. Defaults to false, so a model cannot take over a document that a person is editing.
50
+ */
51
+ overrideLeases?: boolean;
52
+ /**
53
+ * What an Agent may read of the Channel conversations, set by `operations({ conversations })`. `participant`: only the
54
+ * threads that the Actor takes part in. `all`: every thread. Unset: none.
55
+ */
56
+ conversations?: "all" | "participant";
57
+ }
58
+ interface OperationDefinition<Input, Output> {
59
+ /** `<section>.<verb>`, such as `content.publish`. Unique per app. */
60
+ name: string;
61
+ /** One sentence. Becomes the CLI help line and the MCP tool description. */
62
+ description: string;
63
+ /**
64
+ * Console section that grants access, such as `content`. `false`: any Console user. A function reads the section
65
+ * from the input, for operations that serve several sections.
66
+ */
67
+ section: string | false | ((input: Input) => string | undefined);
68
+ /** `read` never changes state. `write` changes state. `destructive` deletes or publishes; the CLI asks for `--yes`, MCP marks `destructiveHint`, agents require approval by default. */
69
+ kind: OperationKind;
70
+ /** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
71
+ input: StandardSchemaV1<unknown, Input>;
72
+ output?: StandardSchemaV1<unknown, Output>;
73
+ cli?: {
74
+ /** Defaults: namespace = section, command = verb. */
75
+ namespace?: string;
76
+ command?: string;
77
+ /** Input keys read from positional arguments, in order. */
78
+ positional?: string[];
79
+ /** Human output, written verbatim. Without it the CLI prints JSON. `--json` always prints JSON. */
80
+ format?: (output: Output) => string;
81
+ /** `vitehub <namespace>` runs this command when no command is named, such as `vitehub usage`. */
82
+ default?: boolean;
83
+ /**
84
+ * Route of the app that takes a signed dispatch of this operation, such as `/_vitehub/schedules/run`. With `--url`
85
+ * and a dispatch key in the environment (`VITEHUB_DISPATCH_KEY`), the command signs the input and posts it there, so
86
+ * a CI job needs no Console credentials. Without a key it calls the RPC.
87
+ */
88
+ dispatch?: string;
89
+ };
90
+ /** Largest request body in bytes. It can raise the 64 KiB default but not lower it. */
91
+ maxRequestBytes?: number;
92
+ /**
93
+ * Returns true when this call only reads, such as a dry run of a `destructive` operation. The CLI then skips the
94
+ * confirmation, and agents run it without approval. Without it, every call of a `destructive` operation asks.
95
+ */
96
+ readOnlyWhen?: (input: Input) => boolean;
97
+ /** `false`: MCP does not offer the operation as a tool, such as an editor transport that only the Console uses. */
98
+ mcp?: false;
99
+ /** `false`: the operation never reads `context.user`, so the Console skips the session lookup for it. */
100
+ user?: false;
101
+ /**
102
+ * The operation runs code of the app, such as a workflow, a job, a task, or a schedule. The Console registers it only
103
+ * when `console.invoke` is on, which is the default in development and off in a production build.
104
+ */
105
+ invoke?: true;
106
+ run: (input: Input, context: OperationContext) => Output | Promise<Output>;
107
+ }
108
+ /** An operation of any input and output, as a registry holds it. */
109
+ interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "output" | "readOnlyWhen" | "run" | "section"> {
110
+ readOnlyWhen?: (input: never) => boolean;
111
+ cli?: {
112
+ namespace?: string;
113
+ command?: string;
114
+ default?: boolean;
115
+ dispatch?: string;
116
+ positional?: string[];
117
+ format?: (output: never) => string;
118
+ };
119
+ input: StandardSchemaV1;
120
+ output?: StandardSchemaV1;
121
+ run: (input: never, context: OperationContext) => unknown;
122
+ section: string | false | ((input: never) => string | undefined);
123
+ }
124
+ /** The contribution of one plugin: operations, or a module that exports them. */
125
+ interface OperationContributionEntry {
126
+ /** Module the app imports, such as `@vite-hub/content/operations`. */
127
+ module: string;
128
+ /** Named export that holds an operation or an array of operations. Defaults to `default`. */
129
+ export?: string;
130
+ /** Loads the export in the tool process, for a module that the tool cannot resolve by name. */
131
+ load?: () => Promise<unknown>;
132
+ /** `false`: the app already has these operations at runtime. Only tools such as the CLI and `vitehub inspect` read the entry. */
133
+ runtime?: false;
134
+ }
135
+ //#endregion
136
+ export { OperationContributionEntry as n, AnyOperation as t };
@@ -0,0 +1,53 @@
1
+ import { At as WorkspaceRevision } from "./types-DeK9GIxy.js";
2
+ import { t as AnyOperation } from "./operations-DnOwKsJT.js";
3
+ //#region src/results.d.ts
4
+ /** A retained revision as `workspace.history`, `workspace.refs`, and `workspace.show` report it. */
5
+ interface WorkspaceHistoryRevision extends WorkspaceRevision {
6
+ /** The `author` string from the revision metadata, when it has one. */
7
+ author?: string;
8
+ }
9
+ interface WorkspaceHistoryList {
10
+ workspace: string;
11
+ /** Set when the list reads one ref. Without it, the list merges every ref, newest first. */
12
+ ref?: string;
13
+ revisions: WorkspaceHistoryRevision[];
14
+ /** Pass to the next request with the same ref. */
15
+ cursor?: string;
16
+ /** True when older revisions exist than the ones in this list. */
17
+ more: boolean;
18
+ }
19
+ interface WorkspaceHistoryRefs {
20
+ workspace: string;
21
+ refs: Array<{
22
+ name: string;
23
+ head: WorkspaceHistoryRevision;
24
+ }>;
25
+ }
26
+ interface WorkspaceHistoryFile {
27
+ path: string;
28
+ size?: number;
29
+ mediaType?: string;
30
+ /** SHA-256 of the retained bytes, when the Store reports it. */
31
+ digest?: string;
32
+ }
33
+ interface WorkspaceHistoryContent extends WorkspaceHistoryFile {
34
+ /** `utf8` for valid UTF-8 text. Other bytes use `base64`. */
35
+ encoding: "base64" | "utf8";
36
+ content: string;
37
+ }
38
+ interface WorkspaceHistoryDetails {
39
+ workspace: string;
40
+ revision: WorkspaceHistoryRevision;
41
+ /** The path inside the revision, when the request names one. */
42
+ path?: string;
43
+ /** Files of the revision, or of the directory at `path`. */
44
+ files?: WorkspaceHistoryFile[];
45
+ /** The file at `path`. */
46
+ file?: WorkspaceHistoryContent;
47
+ }
48
+ //#endregion
49
+ //#region src/operations.d.ts
50
+ /** The `workspace.*` operations: history, refs, and show. The Console, `vitehub workspace`, and agents run them. */
51
+ export declare const workspaceOperations: readonly AnyOperation[];
52
+ //#endregion
53
+ export type { WorkspaceHistoryContent, WorkspaceHistoryDetails, WorkspaceHistoryFile, WorkspaceHistoryList, WorkspaceHistoryRefs, WorkspaceHistoryRevision };
@@ -0,0 +1,2 @@
1
+ import { t as workspaceOperations } from "./operations-CGqY1XeG.js";
2
+ export { workspaceOperations };
@@ -1,30 +1,17 @@
1
- import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
- import { relative, resolve, sep } from "node:path";
1
+ import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.js";
2
+ import { l as workspacePathError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
3
+ import { isAbsolute, relative, resolve, sep } from "node:path";
3
4
  import { createHash } from "node:crypto";
4
5
  import { minimatch } from "minimatch";
5
- import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
6
- //#region src/core/errors.ts
7
- function workspaceError(message, options) {
8
- return new ViteHubError("WORKSPACE_FAILED", message, options);
9
- }
10
- function workspaceNotFoundError(name) {
11
- return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
12
- }
13
- function workspacePathError(path) {
14
- const publicPath = path.slice(0, 4096);
15
- return new ViteHubError("WORKSPACE_PATH_INVALID", `[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
16
- }
17
- function isWorkspaceError(value) {
18
- const code = getViteHubErrorShape(value)?.code;
19
- return code === "WORKSPACE_COLLECTION_CURSOR_INVALID" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
20
- }
21
- //#endregion
6
+ import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
22
7
  //#region src/core/path.ts
23
8
  var path_exports = /* @__PURE__ */ __exportAll({
24
9
  contentStreamChunks: () => contentStreamChunks,
25
10
  contentStreamToBytes: () => contentStreamToBytes,
26
11
  contentToBytes: () => contentToBytes,
27
12
  decodeFile: () => decodeFile,
13
+ isExcludedWorkspacePath: () => isExcludedWorkspacePath,
14
+ isWorkspaceBytes: () => isWorkspaceBytes,
28
15
  matchesAny: () => matchesAny,
29
16
  normalizeSafeWorkspacePath: () => normalizeSafeWorkspacePath,
30
17
  normalizeSafeWorkspacePattern: () => normalizeSafeWorkspacePattern,
@@ -35,14 +22,12 @@ var path_exports = /* @__PURE__ */ __exportAll({
35
22
  function normalizeWorkspacePath(path = "") {
36
23
  return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
37
24
  }
38
- function normalizeSafeWorkspacePath(path = "", options = {}) {
39
- const raw = path.replace(/\\/g, "/");
25
+ function isExcludedWorkspacePath(path, excluded = []) {
40
26
  const normalized = normalizeWorkspacePath(path);
41
- const parts = normalized.split("/").filter(Boolean);
42
- if (!options.allowEmpty && !normalized) throw workspacePathError(path);
43
- if (raw.startsWith("/") || parts.some((part) => part === "." || part === "..")) throw workspacePathError(path);
44
- if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw workspacePathError(path);
45
- return normalized;
27
+ return excluded.some((item) => {
28
+ const excludedPath = normalizeWorkspacePath(item);
29
+ return excludedPath === "" || normalized === excludedPath || normalized.startsWith(`${excludedPath}/`);
30
+ });
46
31
  }
47
32
  function normalizeSafeWorkspacePattern(pattern) {
48
33
  return normalizeSafeWorkspacePath(pattern, {
@@ -52,12 +37,13 @@ function normalizeSafeWorkspacePattern(pattern) {
52
37
  }
53
38
  function resolveInside(root, path = "") {
54
39
  const resolvedRoot = resolve(root);
55
- const resolved = resolve(resolvedRoot, normalizeWorkspacePath(path));
40
+ const normalized = normalizeSafeWorkspacePath(path, {
41
+ allowEmpty: true,
42
+ allowReserved: true
43
+ });
44
+ const resolved = resolve(resolvedRoot, normalized);
56
45
  const rel = relative(resolvedRoot, resolved);
57
- if (rel.startsWith("..") || rel === ".." || rel.includes(`..${sep}`) || rel === "") {
58
- if (rel === "") return resolved;
59
- throw workspacePathError(path);
60
- }
46
+ if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw workspacePathError(path);
61
47
  return resolved;
62
48
  }
63
49
  function matchesAny(path, patterns) {
@@ -66,6 +52,11 @@ function matchesAny(path, patterns) {
66
52
  const normalizedPath = normalizeWorkspacePath(path);
67
53
  return list.some((pattern) => minimatch(normalizedPath, normalizeWorkspacePath(pattern), { dot: true }));
68
54
  }
55
+ const typedArrayTag = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag)?.get;
56
+ /** Recognize byte arrays from VM and sandbox realms. */
57
+ function isWorkspaceBytes(value) {
58
+ return ArrayBuffer.isView(value) && typedArrayTag?.call(value) === "Uint8Array";
59
+ }
69
60
  function contentToBytes(content) {
70
61
  return typeof content === "string" ? new TextEncoder().encode(content) : content;
71
62
  }
@@ -75,14 +66,22 @@ function isReadableStream(value) {
75
66
  async function* contentStreamChunks(stream) {
76
67
  if (isReadableStream(stream)) {
77
68
  const reader = stream.getReader();
69
+ let completed = false;
78
70
  try {
79
71
  while (true) {
80
72
  const chunk = await reader.read();
81
- if (chunk.done) return;
73
+ if (chunk.done) {
74
+ completed = true;
75
+ return;
76
+ }
82
77
  yield chunk.value;
83
78
  }
84
79
  } finally {
85
- reader.releaseLock();
80
+ try {
81
+ if (!completed) await reader.cancel();
82
+ } finally {
83
+ reader.releaseLock();
84
+ }
86
85
  }
87
86
  return;
88
87
  }
@@ -108,8 +107,8 @@ function decodeFile(content, options) {
108
107
  return typeof content === "string" ? content : new TextDecoder().decode(content);
109
108
  }
110
109
  async function sha256(input) {
111
- const bytes = contentToBytes(typeof input === "string" || input instanceof Uint8Array ? input : JSON.stringify(input));
110
+ const bytes = contentToBytes(hasRuntimeType(input, "string") || isWorkspaceBytes(input) ? input : JSON.stringify(input));
112
111
  return createHash("sha256").update(bytes).digest("hex");
113
112
  }
114
113
  //#endregion
115
- export { matchesAny as a, normalizeWorkspacePath as c, sha256 as d, isWorkspaceError as f, decodeFile as i, path_exports as l, workspaceNotFoundError as m, contentStreamToBytes as n, normalizeSafeWorkspacePath as o, workspaceError as p, contentToBytes as r, normalizeSafeWorkspacePattern as s, contentStreamChunks as t, resolveInside as u };
114
+ export { isExcludedWorkspacePath as a, normalizeSafeWorkspacePattern as c, resolveInside as d, sha256 as f, decodeFile as i, normalizeWorkspacePath as l, contentStreamToBytes as n, isWorkspaceBytes as o, contentToBytes as r, matchesAny as s, contentStreamChunks as t, path_exports as u };
@@ -0,0 +1,59 @@
1
+ import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
2
+ //#region src/core/errors.ts
3
+ function workspaceError(message, options) {
4
+ const code = message.startsWith("[vitehub] Workspace file does not exist:") || message.startsWith("[vitehub] Workspace path does not exist:") || message.startsWith("[vitehub] Custom Workspace Source file does not exist:") ? "WORKSPACE_NOT_FOUND" : "WORKSPACE_FAILED";
5
+ return new ViteHubError(code, message, options);
6
+ }
7
+ function workspaceConflict(message, options) {
8
+ return new ViteHubError("WORKSPACE_CONFLICT", message, options);
9
+ }
10
+ function workspaceConflictError(path, expected, actual) {
11
+ return workspaceConflict(`[vitehub] Workspace path changed before the conditional write: ${path}.`, { details: {
12
+ actual,
13
+ expected,
14
+ path
15
+ } });
16
+ }
17
+ function assertWorkspaceDigest(path, expected, actual) {
18
+ if (expected === null ? actual !== void 0 : actual !== expected) throw workspaceConflictError(path, expected, actual);
19
+ }
20
+ function workspaceNotFoundError(name) {
21
+ return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
22
+ }
23
+ function workspacePathError(path) {
24
+ const publicPath = path.slice(0, 4096);
25
+ return new ViteHubError("WORKSPACE_PATH_INVALID", `[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
26
+ }
27
+ function isWorkspaceError(value) {
28
+ const code = getViteHubErrorShape(value)?.code;
29
+ return code === "WORKSPACE_CONFLICT" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
30
+ }
31
+ function isWorkspaceConflict(value) {
32
+ return getViteHubErrorShape(value)?.code === "WORKSPACE_CONFLICT";
33
+ }
34
+ //#endregion
35
+ //#region src/internal/path.ts
36
+ function classifyWindowsComponent(part) {
37
+ const withoutStream = part.toLowerCase().split(":", 1)[0];
38
+ return {
39
+ normalized: withoutStream.replace(/[ .]+$/, ""),
40
+ isTraversal: /^(?:\.(?: +[. ]*)?|\.\.(?: +[. ]*)?)$/.test(withoutStream)
41
+ };
42
+ }
43
+ function normalizeSafeWorkspacePath(path = "", options = {}) {
44
+ const raw = path.replace(/\\/g, "/");
45
+ const normalized = raw.replace(/^\/+/, "").replace(/\/+$/, "");
46
+ const parts = normalized.split("/").filter(Boolean);
47
+ if (!options.allowEmpty && !normalized) throw workspacePathError(path);
48
+ if (raw.startsWith("/") || /^[a-z]:/i.test(raw) || raw.includes("\0")) throw workspacePathError(path);
49
+ if (parts.some((part, index) => {
50
+ const name = part.toLowerCase();
51
+ const classification = classifyWindowsComponent(part);
52
+ const reserved = classification.normalized === ".git" || /^git~\d+$/.test(classification.normalized) || index === 0 && classification.normalized === ".vitehub" || index === 0 && /^vitehu~\d+$/.test(classification.normalized);
53
+ const canonical = (classification.normalized === ".git" || index === 0 && classification.normalized === ".vitehub") && name === classification.normalized;
54
+ return classification.isTraversal || reserved && (!options.allowReserved || !canonical);
55
+ })) throw workspacePathError(path);
56
+ return normalized;
57
+ }
58
+ //#endregion
59
+ export { workspaceConflict as a, workspaceNotFoundError as c, isWorkspaceError as i, workspacePathError as l, assertWorkspaceDigest as n, workspaceConflictError as o, isWorkspaceConflict as r, workspaceError as s, normalizeSafeWorkspacePath as t };
@@ -0,0 +1,9 @@
1
+ //#region src/internal/path.d.ts
2
+ interface SafeWorkspacePathOptions {
3
+ allowEmpty?: boolean;
4
+ allowReserved?: boolean;
5
+ pattern?: boolean;
6
+ }
7
+ declare function normalizeSafeWorkspacePath(path?: string, options?: SafeWorkspacePathOptions): string;
8
+ //#endregion
9
+ export { normalizeSafeWorkspacePath as n, SafeWorkspacePathOptions as t };
@@ -0,0 +1,10 @@
1
+ import { Tt as WorkspacePlugin } from "./types-DeK9GIxy.js";
2
+ //#region src/core/plugins.d.ts
3
+ /**
4
+ * Add a plugin's rules and hooks to a Workspace by name, including discovered Workspaces the caller does not define.
5
+ * Registering the same plugin id again replaces the earlier registration. A plugin declared by the Workspace Definition
6
+ * with the same id wins. The returned function removes this registration.
7
+ */
8
+ declare function registerWorkspacePlugin(workspace: string, plugin: WorkspacePlugin): () => void;
9
+ //#endregion
10
+ export { registerWorkspacePlugin as t };