@vite-hub/workspace 0.0.1 → 0.0.2

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 (94) hide show
  1. package/README.md +190 -17
  2. package/dist/{ai-Bk3LLnit.js → ai-Cztw4eLk.js} +149 -29
  3. package/dist/ai-hFdsvDHC.d.ts +162 -0
  4. package/dist/ai.d.ts +2 -85
  5. package/dist/ai.js +1 -1
  6. package/dist/artifacts-store-BAV9jZpd.js +555 -0
  7. package/dist/asset-registry-CaG9b7tf.js +19 -0
  8. package/dist/cli.d.ts +31 -0
  9. package/dist/cli.js +303 -0
  10. package/dist/cloudflare-env-CKxUs2fa.js +20 -0
  11. package/dist/cloudflare.d.ts +16 -0
  12. package/dist/cloudflare.js +3 -0
  13. package/dist/collections/client.d.ts +39 -0
  14. package/dist/collections/client.js +137 -0
  15. package/dist/collections.d.ts +59 -0
  16. package/dist/collections.js +159 -0
  17. package/dist/config--r5unwPc.js +7811 -0
  18. package/dist/config-Ca5DM8fF.d.ts +28 -0
  19. package/dist/config-DCQ6y30R.js +30 -0
  20. package/dist/file-B2q9NE18.js +24 -0
  21. package/dist/{files-DbsIjBya.js → files-xy0le-_U.js} +6 -5
  22. package/dist/github-lIO6-2sH.js +194 -0
  23. package/dist/glob-DeH0dzZX.js +23 -0
  24. package/dist/host-I-_vDs05.js +370 -0
  25. package/dist/hosted-vercel-blob.d.ts +15 -0
  26. package/dist/hosted-vercel-blob.js +26 -0
  27. package/dist/hosted.d.ts +18 -0
  28. package/dist/hosted.js +30 -0
  29. package/dist/index.d.ts +137 -102
  30. package/dist/index.js +479 -594
  31. package/dist/lifecycle-Lhk3dAMt.js +176 -0
  32. package/dist/loader.d.ts +1 -1
  33. package/dist/loader.js +1 -1
  34. package/dist/nitro.d.ts +2 -31
  35. package/dist/nitro.js +2 -2
  36. package/dist/nuxt.d.ts +26 -0
  37. package/dist/nuxt.js +36 -0
  38. package/dist/path-CNI6wKIU.js +115 -0
  39. package/dist/{provider-BZuKAV4e.js → provider-CeQciesl.js} +142 -37
  40. package/dist/providers/cloudflare/artifacts-store.d.ts +1 -1
  41. package/dist/providers/cloudflare/artifacts-store.js +1 -383
  42. package/dist/providers/github/store.d.ts +6 -0
  43. package/dist/providers/github/store.js +362 -0
  44. package/dist/providers/vercel/blob-store.d.ts +1 -1
  45. package/dist/providers/vercel/blob-store.js +77 -18
  46. package/dist/publish.d.ts +3 -2
  47. package/dist/publish.js +48 -142
  48. package/dist/registry-C7DMdBXN.js +74 -0
  49. package/dist/{registry-D4Qzq26I.d.ts → registry-CoC9JxVt.d.ts} +3 -2
  50. package/dist/request-execution-C8qRcReq.js +80 -0
  51. package/dist/runtime/assets.d.ts +2 -1
  52. package/dist/runtime/assets.js +5 -5
  53. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  54. package/dist/runtime/empty-registry.d.ts +1 -1
  55. package/dist/runtime/state.d.ts +4 -21
  56. package/dist/runtime/state.js +7 -4
  57. package/dist/runtime/workspace.d.ts +2 -0
  58. package/dist/runtime/workspace.js +2 -0
  59. package/dist/runtime.d.ts +38 -0
  60. package/dist/runtime.js +643 -0
  61. package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
  62. package/dist/server.d.ts +65 -0
  63. package/dist/server.js +355 -0
  64. package/dist/shared-BRycRSbo.js +255 -0
  65. package/dist/source-metadata.d.ts +2 -0
  66. package/dist/source-metadata.js +2 -0
  67. package/dist/state-DSAHEsq6.d.ts +25 -0
  68. package/dist/sync-DO42ypji.js +269 -0
  69. package/dist/target-D4Bqb1eH.js +11 -0
  70. package/dist/test.d.ts +1 -1
  71. package/dist/test.js +1 -1
  72. package/dist/types-DHkae7Cb.d.ts +628 -0
  73. package/dist/use-D16tf8Ph.d.ts +86 -0
  74. package/dist/use-d_PlAdOu.js +353 -0
  75. package/dist/{utils-BtAm_K5P.js → utils-BPdaCyI6.js} +7 -3
  76. package/dist/vite-NWC9mFjI.js +1882 -0
  77. package/dist/vite.d.ts +33 -5
  78. package/dist/vite.js +2 -131
  79. package/dist/workspace-f2DBLmPZ.d.ts +6 -0
  80. package/dist/workspace-n4wBmdaM.js +1476 -0
  81. package/package.json +158 -62
  82. package/dist/asset-registry-CMuQbyvl.js +0 -14
  83. package/dist/cloudflare-env-DL94Uvpz.js +0 -12
  84. package/dist/config-CvS-7sre.js +0 -49
  85. package/dist/errors-BUL8SoFS.js +0 -21
  86. package/dist/lifecycle-uD82JeGh.js +0 -92
  87. package/dist/module-8LZUMEXC.js +0 -922
  88. package/dist/path-BVv9OXhg.js +0 -63
  89. package/dist/registry-Cnr0NoKv.js +0 -932
  90. package/dist/runtime/nitro-plugin.d.ts +0 -6
  91. package/dist/runtime/nitro-plugin.js +0 -14
  92. package/dist/sandbox-DtGXCWRq.js +0 -198
  93. package/dist/types-CwNcWTdt.d.ts +0 -378
  94. /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
@@ -0,0 +1,370 @@
1
+ import { c as normalizeWorkspacePath, d as sha256, i as decodeFile, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes } from "./path-CNI6wKIU.js";
2
+ import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-BPdaCyI6.js";
3
+ import { _ as scopedSearchQuery, f as assertDiffInsideSessionPaths, g as isMissingWorkspacePathError, h as filterSessionEntries, m as filterSessionDiff, p as assertPathInSessionScope } from "./workspace-n4wBmdaM.js";
4
+ import { posix } from "node:path";
5
+ import { normalizeExecutionAuthority } from "@vite-hub/runtime";
6
+ //#region src/session/host.ts
7
+ function normalizeTarget(target = "/workspace") {
8
+ const normalized = posix.resolve("/", target.replace(/\\/g, "/"));
9
+ if (normalized === "/") throw workspaceError("[vitehub] Workspace session target cannot be the host root.");
10
+ return normalized;
11
+ }
12
+ function normalizeSearchRoot(path) {
13
+ const normalized = posix.normalize(path.replace(/\\/g, "/"));
14
+ return normalized === "." ? "" : normalizeSafeWorkspacePath(normalized, { allowEmpty: true });
15
+ }
16
+ function toHostPath(root, path = "") {
17
+ const normalized = normalizeSafeWorkspacePath(path, { allowEmpty: true });
18
+ return normalized ? posix.join(root, normalized) : root;
19
+ }
20
+ function toHostCwd(root, cwd) {
21
+ if (cwd === void 0) return root;
22
+ if (!posix.isAbsolute(cwd)) return toHostPath(root, cwd);
23
+ const normalized = posix.normalize(cwd);
24
+ if (normalized === root || normalized.startsWith(`${root}/`)) return normalized;
25
+ if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized.slice(10));
26
+ throw workspaceError(`[vitehub] Workspace exec cwd must stay inside ${root}: ${cwd}.`);
27
+ }
28
+ function fromHostPath(root, path) {
29
+ const normalizedRoot = root.replace(/\/+$/, "");
30
+ const normalizedPath = posix.resolve(root, path).replace(/\/+$/, "");
31
+ if (normalizedPath === normalizedRoot) return "";
32
+ if (!normalizedPath.startsWith(`${normalizedRoot}/`)) throw workspaceError(`[vitehub] Workspace host returned a path outside ${root}: ${path}.`);
33
+ return normalizeWorkspacePath(normalizedPath.slice(normalizedRoot.length + 1));
34
+ }
35
+ function isGitSymlinkEntry(entry) {
36
+ return entry.metadata?.gitMode === "120000";
37
+ }
38
+ function hasSymlinkParent(path, symlinks) {
39
+ let parent = posix.dirname(path);
40
+ while (parent && parent !== "." && parent !== "/") {
41
+ if (symlinks.has(parent)) return true;
42
+ parent = posix.dirname(parent);
43
+ }
44
+ return false;
45
+ }
46
+ function isSafeHostSymlink(root, path, target) {
47
+ if (posix.isAbsolute(target)) return false;
48
+ const resolved = posix.resolve(posix.dirname(toHostPath(root, path)), target);
49
+ return resolved === root || resolved.startsWith(`${root}/`);
50
+ }
51
+ async function assertNoHostSymlinkParent(host, root, target) {
52
+ const path = fromHostPath(root, target);
53
+ if (hasSymlinkParent(path, new Set((await listHostEntries(host, root, "", true)).filter(isGitSymlinkEntry).map((entry) => entry.path)))) throw workspaceError(`[vitehub] Workspace host path crosses a symlink parent: ${path}.`);
54
+ }
55
+ function toWorkspaceEntry(root, entry) {
56
+ return {
57
+ metadata: entry.type === "symlink" ? { gitMode: "120000" } : void 0,
58
+ path: fromHostPath(root, entry.path),
59
+ size: entry.size,
60
+ type: entry.type === "directory" ? "directory" : "file"
61
+ };
62
+ }
63
+ async function ensureHostParent(host, path) {
64
+ const parent = posix.dirname(path);
65
+ if (parent && parent !== "." && parent !== "/") await host.files.mkdir(parent, { recursive: true });
66
+ }
67
+ async function readHostSymlinkTarget(host, root, path) {
68
+ const result = await host.exec("readlink", [fromHostPath(root, path)], { cwd: root });
69
+ if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: new Error(result.stderr || "readlink failed") });
70
+ return result.stdout.replace(/\n$/, "");
71
+ }
72
+ async function writeHostSymlink(host, root, path, target) {
73
+ await host.files.remove(path).catch(() => void 0);
74
+ const result = await host.exec("ln", [
75
+ "-s",
76
+ target,
77
+ fromHostPath(root, path)
78
+ ], { cwd: root });
79
+ if (result.code !== 0) throw workspaceError(`[vitehub] Failed to create workspace symlink: ${path}. ${result.stderr || "ln failed"}`);
80
+ }
81
+ async function readHostFile(host, root, path) {
82
+ if (!await host.files.exists(path)) return void 0;
83
+ const content = await host.files.read(path);
84
+ return content ? {
85
+ content,
86
+ path: fromHostPath(root, path)
87
+ } : void 0;
88
+ }
89
+ async function listHostEntries(host, root, path = "", recursive = false) {
90
+ const entries = await host.files.list(toHostPath(root, path), { recursive });
91
+ return (await Promise.all(entries.map(async (entry) => {
92
+ const workspaceEntry = toWorkspaceEntry(root, entry);
93
+ if (workspaceEntry.type !== "file" || isGitSymlinkEntry(workspaceEntry)) return workspaceEntry;
94
+ return (await host.exec("test", ["-x", fromHostPath(root, entry.path)], { cwd: root })).code === 0 ? {
95
+ ...workspaceEntry,
96
+ metadata: {
97
+ ...workspaceEntry.metadata,
98
+ gitMode: "100755"
99
+ }
100
+ } : workspaceEntry;
101
+ }))).filter((entry) => entry.path && entry.path !== ".git" && !entry.path.startsWith(".git/")).sort((left, right) => left.path.localeCompare(right.path));
102
+ }
103
+ async function makeHostFileExecutable(host, root, path) {
104
+ const result = await host.exec("chmod", ["+x", fromHostPath(root, path)], { cwd: root });
105
+ if (result.code !== 0) throw workspaceError(`[vitehub] Failed to preserve executable Workspace file: ${path}. ${result.stderr || "chmod failed"}`);
106
+ }
107
+ async function snapshotHost(host, root, name) {
108
+ return (await captureHostState(host, root, name)).snapshot;
109
+ }
110
+ async function captureHostState(host, root, name) {
111
+ const entries = await listHostEntries(host, root, "", true);
112
+ const contents = /* @__PURE__ */ new Map();
113
+ return {
114
+ contents,
115
+ snapshot: await createSnapshotFromEntries(await Promise.all(entries.map(async (entry) => {
116
+ if (entry.type !== "file") return entry;
117
+ const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path)) : await host.files.read(toHostPath(root, entry.path));
118
+ if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
119
+ contents.set(entry.path, content);
120
+ return {
121
+ ...entry,
122
+ digest: await sha256(content),
123
+ size: contentToBytes(content).byteLength
124
+ };
125
+ })), name)
126
+ };
127
+ }
128
+ async function restoreAttachedHost(host, root, diff, state) {
129
+ const changed = [...new Set(diff.entries.map((entry) => entry.path))];
130
+ for (const path of changed.sort((left, right) => right.length - left.length)) await host.files.remove(toHostPath(root, path), { recursive: true }).catch(() => void 0);
131
+ const baselineEntries = changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length);
132
+ for (const [path, entry] of baselineEntries) {
133
+ const target = toHostPath(root, path);
134
+ if (entry.type === "directory") {
135
+ await host.files.mkdir(target, { recursive: true });
136
+ continue;
137
+ }
138
+ const content = state.contents.get(path);
139
+ if (content === void 0) continue;
140
+ await ensureHostParent(host, target);
141
+ if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content));
142
+ else {
143
+ await host.files.write(target, contentToBytes(content));
144
+ if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
145
+ }
146
+ }
147
+ }
148
+ async function resetHostWorkspaceRoot(host, root) {
149
+ await host.files.remove(root, { recursive: true }).catch(() => void 0);
150
+ await host.files.mkdir(root, { recursive: true });
151
+ }
152
+ function normalizeSessionPaths(options) {
153
+ const paths = [...new Set((options?.paths || []).map((path) => normalizeSafeWorkspacePath(path, {
154
+ allowEmpty: true,
155
+ allowReserved: true
156
+ })))];
157
+ if (!paths.length || paths.includes("")) return void 0;
158
+ return paths.sort((left, right) => left.length - right.length || left.localeCompare(right));
159
+ }
160
+ async function sessionEntries(workspace, options) {
161
+ const paths = normalizeSessionPaths(options);
162
+ if (!paths) return await workspace.list("", { recursive: true });
163
+ const entries = /* @__PURE__ */ new Map();
164
+ for (const path of paths) {
165
+ const stat = await workspace.stat(path).catch((error) => {
166
+ if (isMissingWorkspacePathError(error)) return void 0;
167
+ throw error;
168
+ });
169
+ if (!stat) continue;
170
+ entries.set(stat.path, stat);
171
+ if (stat.type === "directory") for (const entry of await workspace.list(path, { recursive: true })) entries.set(entry.path, entry);
172
+ }
173
+ return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
174
+ }
175
+ async function materializeWorkspace(workspace, host, root, options) {
176
+ await resetHostWorkspaceRoot(host, root);
177
+ const entries = await sessionEntries(workspace, options);
178
+ const symlinks = new Set(entries.filter(isGitSymlinkEntry).map((entry) => entry.path));
179
+ const nested = entries.find((entry) => hasSymlinkParent(entry.path, symlinks));
180
+ if (nested) throw workspaceError(`[vitehub] Workspace path crosses a symlink parent: ${nested.path}.`);
181
+ for (const entry of entries.filter((entry) => entry.type === "directory")) await host.files.mkdir(toHostPath(root, entry.path), { recursive: true });
182
+ for (const entry of entries) {
183
+ if (entry.type !== "file") continue;
184
+ const target = toHostPath(root, entry.path);
185
+ await ensureHostParent(host, target);
186
+ if (isGitSymlinkEntry(entry)) {
187
+ const symlinkTarget = typeof entry.metadata?.symlinkTarget === "string" ? entry.metadata.symlinkTarget : new TextDecoder().decode(contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
188
+ if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
189
+ else await host.files.write(target, contentToBytes(symlinkTarget));
190
+ } else {
191
+ await host.files.write(target, contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
192
+ if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
193
+ }
194
+ }
195
+ return await snapshotHost(host, root, "host-open");
196
+ }
197
+ async function commitHostChanges(host, root, workspace, diff, mediaTypes, message) {
198
+ for (const entry of diff.entries) {
199
+ if (entry.after?.type === "directory") {
200
+ if (entry.before?.type === "file") await workspace.rm(entry.path, { force: true });
201
+ await workspace.mkdir(entry.path, { recursive: true });
202
+ continue;
203
+ }
204
+ if (entry.type === "removed") {
205
+ await workspace.rm(entry.path, {
206
+ force: true,
207
+ recursive: true
208
+ });
209
+ continue;
210
+ }
211
+ if (entry.after?.type !== "file") continue;
212
+ if (entry.before?.type === "directory") await workspace.rm(entry.path, {
213
+ force: true,
214
+ recursive: true
215
+ });
216
+ const before = entry.before?.type === "file" ? await workspace.stat(entry.path).catch(() => void 0) : void 0;
217
+ const target = toHostPath(root, entry.path);
218
+ const symlinkTarget = entry.after.metadata?.gitMode === "120000" ? await readHostSymlinkTarget(host, root, target) : void 0;
219
+ const file = symlinkTarget === void 0 ? await readHostFile(host, root, target) : isSafeHostSymlink(root, entry.path, symlinkTarget) ? {
220
+ content: symlinkTarget,
221
+ metadata: entry.after.metadata,
222
+ path: entry.path
223
+ } : {
224
+ content: symlinkTarget,
225
+ path: entry.path
226
+ };
227
+ if (file) await workspace.writeFile(entry.path, file.content, {
228
+ mediaType: file.mediaType || mediaTypes.get(entry.path) || before?.mediaType,
229
+ metadata: symlinkTarget === void 0 ? entry.after.metadata : file.metadata
230
+ });
231
+ }
232
+ await workspace.snapshot({ name: message || "host-commit" });
233
+ }
234
+ async function createHostedWorkspaceSession(workspace, options) {
235
+ const host = options.host;
236
+ let executionAuthority;
237
+ try {
238
+ executionAuthority = normalizeExecutionAuthority(host.executionAuthority);
239
+ } catch {
240
+ throw new TypeError("[vitehub] Workspace session host must declare executionAuthority.");
241
+ }
242
+ const root = normalizeTarget(options.target);
243
+ const sessionPaths = normalizeSessionPaths(options);
244
+ let closed = false;
245
+ let attachedState = options.attach ? await captureHostState(host, root, "host-attach") : void 0;
246
+ let baseline = attachedState?.snapshot || await materializeWorkspace(workspace, host, root, options);
247
+ const mediaTypes = /* @__PURE__ */ new Map();
248
+ function assertOpen() {
249
+ if (closed) throw workspaceError("[vitehub] Workspace host session is already closed.");
250
+ }
251
+ async function currentDiff() {
252
+ assertOpen();
253
+ return diffSnapshots(baseline, await snapshotHost(host, root));
254
+ }
255
+ return {
256
+ executionAuthority,
257
+ async readFile(path, readOptions) {
258
+ assertOpen();
259
+ const file = await readHostFile(host, root, toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths, { masked: true })));
260
+ if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
261
+ return decodeFile(file.content, readOptions);
262
+ },
263
+ async writeFile(path, content, writeOptions) {
264
+ assertOpen();
265
+ const target = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths));
266
+ await assertNoHostSymlinkParent(host, root, target);
267
+ await ensureHostParent(host, target);
268
+ await host.files.remove(target, { recursive: true }).catch(() => void 0);
269
+ const symlinkTarget = writeOptions?.metadata?.gitMode === "120000" ? new TextDecoder().decode(contentToBytes(content)) : void 0;
270
+ if (symlinkTarget !== void 0 && isSafeHostSymlink(root, fromHostPath(root, target), symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
271
+ else {
272
+ await host.files.write(target, contentToBytes(content));
273
+ const workspacePath = fromHostPath(root, target);
274
+ if (writeOptions?.metadata?.gitMode === "100755" || baseline.entries[workspacePath]?.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
275
+ }
276
+ const workspacePath = fromHostPath(root, target);
277
+ if (writeOptions?.mediaType) mediaTypes.set(workspacePath, writeOptions.mediaType);
278
+ else mediaTypes.delete(workspacePath);
279
+ },
280
+ async mkdir(path, mkdirOptions = {}) {
281
+ assertOpen();
282
+ const hostTarget = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true }));
283
+ await assertNoHostSymlinkParent(host, root, hostTarget);
284
+ await host.files.mkdir(hostTarget, { recursive: mkdirOptions.recursive });
285
+ },
286
+ async rm(path, rmOptions) {
287
+ assertOpen();
288
+ const workspacePath = assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths);
289
+ const target = toHostPath(root, workspacePath);
290
+ await assertNoHostSymlinkParent(host, root, target);
291
+ await host.files.remove(target, { recursive: rmOptions?.recursive });
292
+ mediaTypes.delete(normalizeWorkspacePath(workspacePath));
293
+ },
294
+ async list(path = "", listOptions = {}) {
295
+ assertOpen();
296
+ return filterSessionEntries(await listHostEntries(host, root, path, listOptions.recursive), sessionPaths);
297
+ },
298
+ async glob(pattern, globOptions) {
299
+ assertOpen();
300
+ const patterns = Array.isArray(pattern) ? pattern : [pattern];
301
+ const cwd = normalizeSearchRoot(globOptions?.cwd || "");
302
+ const { matchesAny } = await import("./path-CNI6wKIU.js").then((n) => n.l);
303
+ return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
304
+ if (entry.type !== "file") return false;
305
+ if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
306
+ if (!entry.path.startsWith(`${cwd}/`)) return false;
307
+ const relative = entry.path.slice(cwd.length + 1);
308
+ return patterns.some((item) => matchesAny(relative, item));
309
+ });
310
+ },
311
+ async search(query) {
312
+ assertOpen();
313
+ const { searchText } = await import("./search-C4REyHj9.js").then((n) => n.n);
314
+ const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
315
+ if (!scoped) return [];
316
+ const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
317
+ const limit = scoped.limit ?? 100;
318
+ const hits = [];
319
+ for (const entry of filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((item) => item.type === "file")) {
320
+ if (scopedSearchRoots.length && !scopedSearchRoots.some((path) => entry.path === path || entry.path.startsWith(`${path}/`))) continue;
321
+ const content = await host.files.read(toHostPath(root, entry.path));
322
+ if (content === null) continue;
323
+ const text = new TextDecoder().decode(content);
324
+ hits.push(...searchText(entry.path, text, {
325
+ ...scoped,
326
+ limit: limit - hits.length
327
+ }));
328
+ if (hits.length >= limit) break;
329
+ }
330
+ return hits;
331
+ },
332
+ async diff() {
333
+ return filterSessionDiff(await currentDiff(), sessionPaths);
334
+ },
335
+ async commit(commitOptions) {
336
+ const diff = await currentDiff();
337
+ if (!diff.entries.length) return;
338
+ assertDiffInsideSessionPaths(diff, sessionPaths);
339
+ await commitHostChanges(host, root, workspace, diff, mediaTypes, commitOptions?.message);
340
+ if (options.attach) {
341
+ attachedState = await captureHostState(host, root, commitOptions?.message || "host-commit");
342
+ baseline = attachedState.snapshot;
343
+ } else baseline = await snapshotHost(host, root, commitOptions?.message || "host-commit");
344
+ },
345
+ async exec(command, args = [], execOptions = {}) {
346
+ assertOpen();
347
+ const result = await host.exec(command, args, {
348
+ cwd: toHostCwd(root, execOptions.cwd),
349
+ env: execOptions.env,
350
+ signal: execOptions.abortSignal,
351
+ timeout: execOptions.timeout
352
+ });
353
+ return {
354
+ args,
355
+ command,
356
+ exitCode: result.code,
357
+ stderr: result.stderr,
358
+ stdout: result.stdout
359
+ };
360
+ },
361
+ async close() {
362
+ if (closed) return;
363
+ if (options.attach && attachedState) await restoreAttachedHost(host, root, filterSessionDiff(diffSnapshots(baseline, await snapshotHost(host, root)), sessionPaths), attachedState);
364
+ closed = true;
365
+ if (!options.attach) await materializeWorkspace(workspace, host, root, options);
366
+ }
367
+ };
368
+ }
369
+ //#endregion
370
+ export { createHostedWorkspaceSession };
@@ -0,0 +1,15 @@
1
+ import { v as ResolvedWorkspaceModuleOptions, w as VercelBlobWorkspaceStoreOptions } from "./types-DHkae7Cb.js";
2
+
3
+ //#region src/hosted-vercel-blob.d.ts
4
+ interface HostedVercelBlobWorkspaceRuntimeOptions {
5
+ assets?: boolean | string[];
6
+ env?: Record<string, string | undefined>;
7
+ root?: string;
8
+ store?: Partial<VercelBlobWorkspaceStoreOptions> & {
9
+ provider: "vercel-blob";
10
+ };
11
+ }
12
+ declare function installHostedVercelBlobWorkspaceRuntime(): void;
13
+ declare function configureHostedVercelBlobWorkspaceRuntime(options?: HostedVercelBlobWorkspaceRuntimeOptions): ResolvedWorkspaceModuleOptions;
14
+ //#endregion
15
+ export { HostedVercelBlobWorkspaceRuntimeOptions, type VercelBlobWorkspaceStoreOptions, configureHostedVercelBlobWorkspaceRuntime, installHostedVercelBlobWorkspaceRuntime };
@@ -0,0 +1,26 @@
1
+ import { p as workspaceError } from "./path-CNI6wKIU.js";
2
+ import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, o as resolveVercelBlobWorkspaceStore } from "./provider-CeQciesl.js";
3
+ import { createVercelBlobWorkspaceStore } from "./providers/vercel/blob-store.js";
4
+ import { resolve } from "node:path";
5
+ //#region src/hosted-vercel-blob.ts
6
+ function installHostedVercelBlobWorkspaceRuntime() {
7
+ const existingWorkspaceHostedStoreLoader = getWorkspaceHostedStoreLoader();
8
+ setWorkspaceHostedStoreLoader((storeOptions, workspaceName) => {
9
+ if (storeOptions.provider === "vercel-blob") return createVercelBlobWorkspaceStore(storeOptions, workspaceName);
10
+ if (existingWorkspaceHostedStoreLoader) return existingWorkspaceHostedStoreLoader(storeOptions, workspaceName);
11
+ throw workspaceError("[vitehub] Vercel Blob hosted workspace runtime cannot load unsupported hosted store.");
12
+ });
13
+ }
14
+ function configureHostedVercelBlobWorkspaceRuntime(options = {}) {
15
+ const root = resolve(process.cwd(), options.root || ".vitehub/workspaces");
16
+ const config = {
17
+ assets: options.assets,
18
+ root,
19
+ store: resolveVercelBlobWorkspaceStore(options.store, options.env)
20
+ };
21
+ installHostedVercelBlobWorkspaceRuntime();
22
+ setWorkspaceRuntimeConfig(config);
23
+ return config;
24
+ }
25
+ //#endregion
26
+ export { configureHostedVercelBlobWorkspaceRuntime, installHostedVercelBlobWorkspaceRuntime };
@@ -0,0 +1,18 @@
1
+ import { o as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions, w as VercelBlobWorkspaceStoreOptions } from "./types-DHkae7Cb.js";
2
+
3
+ //#region src/hosted.d.ts
4
+ type HostedWorkspaceRuntimeStoreOptions = Partial<CloudflareArtifactsWorkspaceStoreOptions> | (Partial<GitHubWorkspaceStoreOptions> & {
5
+ provider: "github";
6
+ }) | (Partial<VercelBlobWorkspaceStoreOptions> & {
7
+ provider: "vercel-blob";
8
+ });
9
+ interface HostedWorkspaceRuntimeOptions {
10
+ assets?: boolean | string[];
11
+ env?: Record<string, string | undefined>;
12
+ root?: string;
13
+ store?: HostedWorkspaceRuntimeStoreOptions;
14
+ }
15
+ declare function installHostedWorkspaceRuntime(): void;
16
+ declare function configureHostedWorkspaceRuntime(options?: HostedWorkspaceRuntimeOptions): ResolvedWorkspaceModuleOptions;
17
+ //#endregion
18
+ export { type CloudflareArtifactsWorkspaceStoreOptions, type GitHubWorkspaceStoreOptions, HostedWorkspaceRuntimeOptions, HostedWorkspaceRuntimeStoreOptions, type VercelBlobWorkspaceStoreOptions, configureHostedWorkspaceRuntime, installHostedWorkspaceRuntime };
package/dist/hosted.js ADDED
@@ -0,0 +1,30 @@
1
+ import { p as workspaceError } from "./path-CNI6wKIU.js";
2
+ import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, i as resolveGitHubWorkspaceStore, l as setWorkspaceHostedStoreLoader, r as resolveCloudflareArtifactsStore } from "./provider-CeQciesl.js";
3
+ import { createGitHubWorkspaceStore } from "./providers/github/store.js";
4
+ import { t as createCloudflareArtifactsWorkspaceStore } from "./artifacts-store-BAV9jZpd.js";
5
+ import { resolve } from "node:path";
6
+ //#region src/hosted.ts
7
+ function installHostedWorkspaceRuntime() {
8
+ const existingWorkspaceHostedStoreLoader = getWorkspaceHostedStoreLoader();
9
+ setWorkspaceHostedStoreLoader((storeOptions, workspaceName) => {
10
+ if (storeOptions.provider === "cloudflare-artifacts") return createCloudflareArtifactsWorkspaceStore(storeOptions, workspaceName);
11
+ if (storeOptions.provider === "github") return createGitHubWorkspaceStore(storeOptions, workspaceName);
12
+ if (existingWorkspaceHostedStoreLoader) return existingWorkspaceHostedStoreLoader(storeOptions, workspaceName);
13
+ throw workspaceError("[vitehub] Hosted workspace runtime cannot load unsupported hosted store.");
14
+ });
15
+ }
16
+ function configureHostedWorkspaceRuntime(options = {}) {
17
+ const root = resolve(process.cwd(), options.root || ".vitehub/workspaces");
18
+ const store = options.store?.provider === "github" ? resolveGitHubWorkspaceStore(options.store, options.env, { runtime: true }) : options.store?.provider === "vercel-blob" ? void 0 : resolveCloudflareArtifactsStore(options.store, options.env);
19
+ if (!store) throw workspaceError("[vitehub] Vercel Blob hosted workspace runtime must use @vite-hub/workspace/internal/runtime/hosted-vercel-blob.");
20
+ const config = {
21
+ assets: options.assets,
22
+ root,
23
+ store
24
+ };
25
+ installHostedWorkspaceRuntime();
26
+ setWorkspaceRuntimeConfig(config);
27
+ return config;
28
+ }
29
+ //#endregion
30
+ export { configureHostedWorkspaceRuntime, installHostedWorkspaceRuntime };