@vite-hub/workspace 0.0.0 → 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 (84) hide show
  1. package/README.md +262 -1
  2. package/dist/ai-Cztw4eLk.js +472 -0
  3. package/dist/ai-hFdsvDHC.d.ts +162 -0
  4. package/dist/ai.d.ts +3 -0
  5. package/dist/ai.js +2 -0
  6. package/dist/artifacts-store-BAV9jZpd.js +555 -0
  7. package/dist/asset-registry-CaG9b7tf.js +19 -0
  8. package/dist/chunk-8H4AJuhK.js +14 -0
  9. package/dist/cli.d.ts +31 -0
  10. package/dist/cli.js +303 -0
  11. package/dist/cloudflare-env-CKxUs2fa.js +20 -0
  12. package/dist/cloudflare.d.ts +16 -0
  13. package/dist/cloudflare.js +3 -0
  14. package/dist/collections/client.d.ts +39 -0
  15. package/dist/collections/client.js +137 -0
  16. package/dist/collections.d.ts +59 -0
  17. package/dist/collections.js +159 -0
  18. package/dist/config--r5unwPc.js +7811 -0
  19. package/dist/config-Ca5DM8fF.d.ts +28 -0
  20. package/dist/config-DCQ6y30R.js +30 -0
  21. package/dist/file-B2q9NE18.js +24 -0
  22. package/dist/files-xy0le-_U.js +51 -0
  23. package/dist/github-lIO6-2sH.js +194 -0
  24. package/dist/glob-DeH0dzZX.js +23 -0
  25. package/dist/host-I-_vDs05.js +370 -0
  26. package/dist/hosted-vercel-blob.d.ts +15 -0
  27. package/dist/hosted-vercel-blob.js +26 -0
  28. package/dist/hosted.d.ts +18 -0
  29. package/dist/hosted.js +30 -0
  30. package/dist/index.d.ts +185 -0
  31. package/dist/index.js +541 -0
  32. package/dist/lifecycle-Lhk3dAMt.js +176 -0
  33. package/dist/loader.d.ts +17 -0
  34. package/dist/loader.js +22 -0
  35. package/dist/nitro.d.ts +2 -0
  36. package/dist/nitro.js +2 -0
  37. package/dist/nuxt.d.ts +26 -0
  38. package/dist/nuxt.js +36 -0
  39. package/dist/path-CNI6wKIU.js +115 -0
  40. package/dist/provider-CeQciesl.js +599 -0
  41. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  42. package/dist/providers/cloudflare/artifacts-store.js +2 -0
  43. package/dist/providers/github/store.d.ts +6 -0
  44. package/dist/providers/github/store.js +362 -0
  45. package/dist/providers/vercel/blob-store.d.ts +6 -0
  46. package/dist/providers/vercel/blob-store.js +235 -0
  47. package/dist/publish.d.ts +35 -0
  48. package/dist/publish.js +112 -0
  49. package/dist/registry-C7DMdBXN.js +74 -0
  50. package/dist/registry-CoC9JxVt.d.ts +11 -0
  51. package/dist/request-execution-C8qRcReq.js +80 -0
  52. package/dist/runtime/assets.d.ts +12 -0
  53. package/dist/runtime/assets.js +138 -0
  54. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  55. package/dist/runtime/empty-assets-registry.js +4 -0
  56. package/dist/runtime/empty-registry.d.ts +6 -0
  57. package/dist/runtime/empty-registry.js +4 -0
  58. package/dist/runtime/state.d.ts +4 -0
  59. package/dist/runtime/state.js +15 -0
  60. package/dist/runtime/workspace.d.ts +2 -0
  61. package/dist/runtime/workspace.js +2 -0
  62. package/dist/runtime.d.ts +38 -0
  63. package/dist/runtime.js +643 -0
  64. package/dist/search-C4REyHj9.js +39 -0
  65. package/dist/server.d.ts +65 -0
  66. package/dist/server.js +355 -0
  67. package/dist/shared-BRycRSbo.js +255 -0
  68. package/dist/source-metadata.d.ts +2 -0
  69. package/dist/source-metadata.js +2 -0
  70. package/dist/state-DSAHEsq6.d.ts +25 -0
  71. package/dist/sync-DO42ypji.js +269 -0
  72. package/dist/target-D4Bqb1eH.js +11 -0
  73. package/dist/test.d.ts +2 -0
  74. package/dist/test.js +2 -0
  75. package/dist/types-DHkae7Cb.d.ts +628 -0
  76. package/dist/use-D16tf8Ph.d.ts +86 -0
  77. package/dist/use-d_PlAdOu.js +353 -0
  78. package/dist/utils-BPdaCyI6.js +55 -0
  79. package/dist/vite-NWC9mFjI.js +1882 -0
  80. package/dist/vite.d.ts +50 -0
  81. package/dist/vite.js +2 -0
  82. package/dist/workspace-f2DBLmPZ.d.ts +6 -0
  83. package/dist/workspace-n4wBmdaM.js +1476 -0
  84. package/package.json +197 -5
@@ -0,0 +1,86 @@
1
+ import { Ct as WorkspaceSnapshot, D as WorkspaceAssets, E as WorkspaceAssetPath, I as WorkspaceDiff, Jt as WorkspaceSourceSyncResult, P as WorkspaceDefinition, Q as WorkspaceMaterializeSourcesOptions, R as WorkspaceEntry, St as WorkspaceSessionOptions, Xt as WorkspaceStat, _ as ReadFileResult, b as RmOptions, c as ListOptions, dn as WriteFileOptions, en as WorkspaceSyncOptions, et as WorkspaceMaterializeSourcesResult, g as ReadFileOptions, gt as WorkspaceSearchQuery, ht as WorkspaceSearchHit, j as WorkspaceContent, m as MkdirOptions, n as DiffOptions, ot as WorkspaceName, s as GlobOptions, ut as WorkspacePublishOptions, vt as WorkspaceSession, x as SnapshotOptions } from "./types-DHkae7Cb.js";
2
+ import { a as WorkspaceReadOperations, d as WorkspaceWriteToolMap, n as ShellEnabled, o as WorkspaceShellResult, u as WorkspaceWriteOperations } from "./ai-hFdsvDHC.js";
3
+ import { Tool, ToolSet } from "ai";
4
+
5
+ //#region src/core/use.d.ts
6
+ type WorkspaceWritablePath<Name extends WorkspaceName> = WorkspaceAssetPath<Name> | (string & {});
7
+ interface UseWorkspaceOptions {
8
+ definition?: WorkspaceDefinition;
9
+ mode?: "read" | "write";
10
+ }
11
+ interface WorkspaceFacadeToolOptions extends WorkspaceReadOperations {
12
+ broadSearchPaths?: string[];
13
+ cwd?: string;
14
+ maxShellCalls?: number;
15
+ maxOutputLength?: number;
16
+ timeout?: number;
17
+ }
18
+ interface WritableWorkspaceFacadeToolOptions extends WorkspaceFacadeToolOptions, WorkspaceWriteOperations {}
19
+ type EnabledWriteCapability<Options, Key extends keyof WorkspaceWriteOperations> = Options extends Record<Key, infer Value> ? Value extends false ? false : true : true;
20
+ type WorkspaceReadTools<Options = undefined> = ((ShellEnabled<Options> extends true ? {
21
+ shell: Tool<{
22
+ command: string;
23
+ }, WorkspaceShellResult>;
24
+ } : {}) & (Options extends {
25
+ materialize: true;
26
+ } ? {
27
+ materialize_sources: Tool<{
28
+ path?: string;
29
+ sources?: string[];
30
+ }, WorkspaceMaterializeSourcesResult>;
31
+ } : {}) & ToolSet);
32
+ type WorkspaceWriteTools<Options = undefined> = WorkspaceReadTools<Options> & { [Key in keyof WorkspaceWriteToolMap as EnabledWriteCapability<Options, Key> extends true ? Key : never]: WorkspaceWriteToolMap[Key] } & ToolSet;
33
+ type WorkspaceReadToolSet = WorkspaceReadTools & {
34
+ inspect: <Options extends WorkspaceFacadeToolOptions | undefined = undefined>(options?: Options) => WorkspaceReadTools<Options>;
35
+ none: () => ToolSet;
36
+ };
37
+ type WorkspaceWriteToolSet = WorkspaceWriteTools & {
38
+ inspect: <Options extends WorkspaceFacadeToolOptions | undefined = undefined>(options?: Options) => WorkspaceReadTools<Options>;
39
+ none: () => ToolSet;
40
+ write: <Options extends WritableWorkspaceFacadeToolOptions | undefined = undefined>(options?: Options) => WorkspaceWriteTools<Options>;
41
+ };
42
+ type ReadonlyWorkspaceFs<Name extends WorkspaceName = WorkspaceName> = WorkspaceAssets<WorkspaceAssetPath<Name>>;
43
+ interface WritableWorkspaceFs<Name extends WorkspaceName = WorkspaceName> {
44
+ readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: WorkspaceWritablePath<Name>, options?: TOptions): Promise<ReadFileResult<TOptions>>;
45
+ writeFile(path: WorkspaceWritablePath<Name>, content: WorkspaceContent, options?: WriteFileOptions): Promise<void>;
46
+ appendFile(path: WorkspaceWritablePath<Name>, content: string): Promise<void>;
47
+ stat(path: WorkspaceWritablePath<Name>): Promise<WorkspaceStat>;
48
+ exists(path: WorkspaceWritablePath<Name>): Promise<boolean>;
49
+ list(path?: WorkspaceWritablePath<Name> | "", options?: ListOptions): Promise<WorkspaceEntry[]>;
50
+ glob(pattern: WorkspaceWritablePath<Name> | Array<WorkspaceWritablePath<Name>>, options?: GlobOptions): Promise<WorkspaceEntry[]>;
51
+ search(query: WorkspaceSearchQuery): Promise<WorkspaceSearchHit[]>;
52
+ mkdir(path: WorkspaceWritablePath<Name>, options?: MkdirOptions): Promise<void>;
53
+ rm(path: WorkspaceWritablePath<Name>, options?: RmOptions): Promise<void>;
54
+ movePath(from: WorkspaceWritablePath<Name>, to: WorkspaceWritablePath<Name>, options?: {
55
+ overwrite?: boolean;
56
+ }): Promise<void>;
57
+ copyPath(from: WorkspaceWritablePath<Name>, to: WorkspaceWritablePath<Name>, options?: {
58
+ overwrite?: boolean;
59
+ }): Promise<void>;
60
+ }
61
+ interface ReadonlyWorkspaceFacade<Name extends WorkspaceName = WorkspaceName> {
62
+ fs: ReadonlyWorkspaceFs<Name>;
63
+ tools: WorkspaceReadToolSet;
64
+ }
65
+ interface WritableWorkspaceFacade<Name extends WorkspaceName = WorkspaceName> {
66
+ diff(options?: DiffOptions): Promise<WorkspaceDiff>;
67
+ fs: WritableWorkspaceFs<Name>;
68
+ getMeta?(key: string): Promise<unknown>;
69
+ materializeSources(options?: WorkspaceMaterializeSourcesOptions): Promise<WorkspaceMaterializeSourcesResult>;
70
+ publish(options?: WorkspacePublishOptions): Promise<void>;
71
+ setMeta?(key: string, value: unknown): Promise<void>;
72
+ snapshot(options?: SnapshotOptions): Promise<WorkspaceSnapshot>;
73
+ startSession(options?: WorkspaceSessionOptions): Promise<WorkspaceSession>;
74
+ sync(options: WorkspaceSyncOptions): Promise<WorkspaceSourceSyncResult>;
75
+ tools: WorkspaceWriteToolSet;
76
+ }
77
+ type WorkspaceFacade<Name extends WorkspaceName = WorkspaceName, Mode extends UseWorkspaceOptions["mode"] = "read"> = Mode extends "write" ? WritableWorkspaceFacade<Name> : ReadonlyWorkspaceFacade<Name>;
78
+ declare function useWorkspace<Name extends WorkspaceName>(name: Name): ReadonlyWorkspaceFacade<Name>;
79
+ declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: {
80
+ mode: "read";
81
+ }): ReadonlyWorkspaceFacade<Name>;
82
+ declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: {
83
+ mode: "write";
84
+ }): WritableWorkspaceFacade<Name>;
85
+ //#endregion
86
+ export { WorkspaceFacadeToolOptions as a, WorkspaceWriteToolSet as c, WritableWorkspaceFacadeToolOptions as d, WritableWorkspaceFs as f, WorkspaceFacade as i, WorkspaceWriteTools as l, ReadonlyWorkspaceFs as n, WorkspaceReadToolSet as o, useWorkspace as p, UseWorkspaceOptions as r, WorkspaceReadTools as s, ReadonlyWorkspaceFacade as t, WritableWorkspaceFacade as u };
@@ -0,0 +1,353 @@
1
+ import { o as normalizeSafeWorkspacePath, p as workspaceError, s as normalizeSafeWorkspacePattern } from "./path-CNI6wKIU.js";
2
+ import { a as copyWorkspacePath, i as appendWorkspaceFile, t as createWorkspaceTools } from "./ai-Cztw4eLk.js";
3
+ import { r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-C8qRcReq.js";
4
+ import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
5
+ import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
6
+ import { t as createWorkspace } from "./workspace-n4wBmdaM.js";
7
+ import { a as useRegisteredWorkspace } from "./registry-C7DMdBXN.js";
8
+ import { getViteHubErrorShape } from "@vite-hub/runtime";
9
+ //#region src/core/use.ts
10
+ function normalizePath(path, allowEmpty = false) {
11
+ const reserved = normalizeSafeWorkspacePath(path, {
12
+ allowEmpty,
13
+ allowReserved: true
14
+ });
15
+ if (isGeneratedSourceDescriptorPath(reserved)) return reserved;
16
+ return normalizeSafeWorkspacePath(path, { allowEmpty });
17
+ }
18
+ function normalizeListPath(path = "") {
19
+ return normalizePath(path, true);
20
+ }
21
+ function normalizePattern(pattern) {
22
+ return Array.isArray(pattern) ? pattern.map(normalizeWorkspacePattern) : normalizeWorkspacePattern(pattern);
23
+ }
24
+ function normalizeWorkspacePattern(pattern) {
25
+ const reserved = normalizeSafeWorkspacePath(pattern, {
26
+ allowEmpty: true,
27
+ allowReserved: true,
28
+ pattern: true
29
+ });
30
+ if (isGeneratedSourceDescriptorPath(reserved)) return reserved;
31
+ return normalizeSafeWorkspacePattern(pattern);
32
+ }
33
+ function isGeneratedSourceDescriptorPath(path) {
34
+ return path === ".vitehub/sources" || path.startsWith(".vitehub/sources/");
35
+ }
36
+ async function materializeWorkspaceSources(workspace, options) {
37
+ if (!workspace.materializeSources) throw workspaceError("[vitehub] Workspace source materialization is unavailable.");
38
+ return await workspace.materializeSources(options);
39
+ }
40
+ function createLazyWorkspace(name, definition) {
41
+ let workspacePromise;
42
+ let syncPromise;
43
+ async function resolveWorkspace() {
44
+ workspacePromise ||= definition ? Promise.resolve(createWorkspace(definition)) : useRegisteredWorkspace(name);
45
+ return await workspacePromise;
46
+ }
47
+ async function resolveSyncedWorkspace() {
48
+ const workspace = await resolveWorkspace();
49
+ if (!syncPromise) {
50
+ const next = workspace.__syncWorkspaceDefinition?.() ?? Promise.resolve();
51
+ syncPromise = next;
52
+ next.catch(() => {
53
+ syncPromise = void 0;
54
+ });
55
+ }
56
+ await syncPromise;
57
+ return workspace;
58
+ }
59
+ const workspace = {
60
+ name,
61
+ async [workspaceStoreTarget]() {
62
+ return await (await resolveWorkspace())[workspaceStoreTarget]?.();
63
+ },
64
+ async sync(options) {
65
+ const next = (await resolveWorkspace()).sync(options);
66
+ syncPromise = next.then(() => void 0);
67
+ next.catch(() => {
68
+ syncPromise = void 0;
69
+ });
70
+ return await next;
71
+ },
72
+ async readFile(path, options) {
73
+ return await (await resolveSyncedWorkspace()).readFile(normalizePath(path), options);
74
+ },
75
+ async writeFile(path, content, options) {
76
+ await (await resolveSyncedWorkspace()).writeFile(normalizePath(path), content, options);
77
+ },
78
+ async list(path, options) {
79
+ return await (await resolveSyncedWorkspace()).list(path ? normalizeListPath(path) : "", options);
80
+ },
81
+ async glob(pattern, options) {
82
+ return await (await resolveSyncedWorkspace()).glob(normalizePattern(pattern), options);
83
+ },
84
+ async search(query) {
85
+ return await (await resolveSyncedWorkspace()).search({
86
+ ...query,
87
+ cwd: query.cwd ? normalizeListPath(query.cwd) : query.cwd,
88
+ paths: query.paths?.map((path) => normalizeListPath(path))
89
+ });
90
+ },
91
+ async stat(path) {
92
+ return await (await resolveSyncedWorkspace()).stat(normalizePath(path));
93
+ },
94
+ async exists(path) {
95
+ return await (await resolveSyncedWorkspace()).exists(normalizePath(path));
96
+ },
97
+ async mkdir(path, options) {
98
+ await (await resolveSyncedWorkspace()).mkdir(normalizePath(path), options);
99
+ },
100
+ async rm(path, options) {
101
+ await (await resolveSyncedWorkspace()).rm(normalizePath(path), options);
102
+ },
103
+ async materializeSources(options) {
104
+ return await materializeWorkspaceSources(await resolveSyncedWorkspace(), options);
105
+ },
106
+ async publish(options) {
107
+ if (syncPromise) await syncPromise;
108
+ await (await resolveWorkspace()).publish(options);
109
+ },
110
+ async snapshot(options) {
111
+ return await (await resolveSyncedWorkspace()).snapshot(options);
112
+ },
113
+ async diff(options) {
114
+ return await (await resolveSyncedWorkspace()).diff(options);
115
+ },
116
+ async getMeta(key) {
117
+ return await (await resolveWorkspace()).getMeta?.(key);
118
+ },
119
+ async setMeta(key, value) {
120
+ await (await resolveWorkspace()).setMeta?.(key, value);
121
+ },
122
+ async startSession(options) {
123
+ return await (await resolveSyncedWorkspace()).startSession(options);
124
+ },
125
+ mount(options) {
126
+ return {
127
+ workspace,
128
+ mode: options?.mode || "read-only",
129
+ target: options?.target || "/workspace",
130
+ async diff() {
131
+ return await (await resolveSyncedWorkspace()).mount(options).diff();
132
+ },
133
+ async commit(commitOptions) {
134
+ await (await resolveSyncedWorkspace()).mount(options).commit(commitOptions);
135
+ },
136
+ async export() {
137
+ return await (await resolveSyncedWorkspace()).mount(options).export();
138
+ }
139
+ };
140
+ }
141
+ };
142
+ return attachWorkspaceSourceRequestExecution(workspace, { async executeSourceRequest(input) {
143
+ const executor = getWorkspaceSourceRequestExecution(await resolveSyncedWorkspace());
144
+ if (!executor) throw new Error("[vitehub] No API-backed Source request executor is available for this workspace.");
145
+ return await executor.executeSourceRequest(input);
146
+ } });
147
+ }
148
+ function createWritableFs(workspace) {
149
+ return attachWorkspaceSourceRequestExecution({
150
+ readFile: async (path, options) => await workspace.readFile(normalizePath(path), options),
151
+ writeFile: async (path, content, options) => await workspace.writeFile(normalizePath(path), content, options),
152
+ appendFile: async (path, content) => await appendWorkspaceFile(workspace, normalizePath(path), content),
153
+ stat: async (path) => await workspace.stat(normalizePath(path)),
154
+ exists: async (path) => await workspace.exists(normalizePath(path)),
155
+ list: async (path, options) => await workspace.list(path ? normalizeListPath(path) : "", options),
156
+ glob: async (pattern, options) => await workspace.glob(normalizePattern(pattern), options),
157
+ search: async (query) => await workspace.search({
158
+ ...query,
159
+ cwd: query.cwd ? normalizeListPath(query.cwd) : query.cwd,
160
+ paths: query.paths?.map((path) => normalizeListPath(path))
161
+ }),
162
+ mkdir: async (path, options) => await workspace.mkdir(normalizePath(path), options),
163
+ rm: async (path, options) => await workspace.rm(normalizePath(path), options),
164
+ movePath: async (from, to, options) => {
165
+ const source = normalizePath(from);
166
+ await copyWorkspacePath(workspace, source, normalizePath(to), options?.overwrite);
167
+ await workspace.rm(source, {
168
+ recursive: true,
169
+ force: true
170
+ });
171
+ },
172
+ copyPath: async (from, to, options) => await copyWorkspacePath(workspace, normalizePath(from), normalizePath(to), options?.overwrite)
173
+ }, getWorkspaceSourceRequestExecution(workspace));
174
+ }
175
+ function useOptionalWorkspaceAssets(name) {
176
+ try {
177
+ return useWorkspaceAssets(name);
178
+ } catch (error) {
179
+ if (getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND") return void 0;
180
+ throw error;
181
+ }
182
+ }
183
+ async function ignoreMissingWorkspace(operation) {
184
+ try {
185
+ return await operation();
186
+ } catch (error) {
187
+ if (isMissingWorkspaceRead(error)) return void 0;
188
+ throw error;
189
+ }
190
+ }
191
+ function isMissingWorkspaceRead(error) {
192
+ return getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND" || error instanceof Error && error.message.includes("Workspace file does not exist:") || error instanceof Error && error.message.includes("Workspace path does not exist:");
193
+ }
194
+ function mergeEntries(primary = [], fallback = []) {
195
+ const entries = /* @__PURE__ */ new Map();
196
+ for (const entry of fallback) entries.set(entry.path, entry);
197
+ for (const entry of primary) entries.set(entry.path, entry);
198
+ return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
199
+ }
200
+ function mergeSearchHits(primary = [], fallback = []) {
201
+ const seen = /* @__PURE__ */ new Set();
202
+ return [...primary, ...fallback].filter((hit) => {
203
+ const key = `${hit.path}:${hit.line}:${hit.column}:${hit.text}`;
204
+ if (seen.has(key)) return false;
205
+ seen.add(key);
206
+ return true;
207
+ });
208
+ }
209
+ function createReadonlyFs(name, workspace) {
210
+ const assets = useOptionalWorkspaceAssets(name);
211
+ return attachWorkspaceSourceRequestExecution({
212
+ readFile: async (path, options) => {
213
+ const normalized = normalizePath(path);
214
+ try {
215
+ return await workspace.readFile(normalized, options);
216
+ } catch (error) {
217
+ if (assets && isMissingWorkspaceRead(error)) return await assets.readFile(normalized, options);
218
+ throw error;
219
+ }
220
+ },
221
+ stat: async (path) => {
222
+ const normalized = normalizePath(path);
223
+ try {
224
+ return await workspace.stat(normalized);
225
+ } catch (error) {
226
+ if (assets && isMissingWorkspaceRead(error)) return await assets.stat(normalized);
227
+ throw error;
228
+ }
229
+ },
230
+ exists: async (path) => {
231
+ const normalized = normalizePath(path);
232
+ return await ignoreMissingWorkspace(() => workspace.exists(normalized)) ?? (assets ? await assets.exists(normalized) : false);
233
+ },
234
+ list: async (path, options) => {
235
+ const normalized = path ? normalizeListPath(path) : "";
236
+ const workspaceEntries = await ignoreMissingWorkspace(() => workspace.list(normalized, options)) ?? [];
237
+ if (normalized && workspaceEntries.length) return workspaceEntries;
238
+ let assetEntries = assets ? await assets.list(normalized, options) : [];
239
+ if (!normalized && options?.recursive && workspaceEntries.length) {
240
+ const workspaceRoots = new Set(workspaceEntries.filter((entry) => entry.type === "directory").map((entry) => entry.path.split("/")[0]));
241
+ assetEntries = assetEntries.filter((entry) => !workspaceRoots.has(entry.path.split("/")[0]));
242
+ }
243
+ return mergeEntries(assetEntries, workspaceEntries);
244
+ },
245
+ glob: async (pattern, options) => {
246
+ const normalized = normalizePattern(pattern);
247
+ return mergeEntries(assets ? await assets.glob(normalized, options) : [], await ignoreMissingWorkspace(() => workspace.glob(normalized, options)) ?? []);
248
+ },
249
+ search: async (query) => {
250
+ const normalized = {
251
+ ...query,
252
+ cwd: query.cwd ? normalizeListPath(query.cwd) : query.cwd,
253
+ paths: query.paths?.map((path) => normalizeListPath(path))
254
+ };
255
+ const limit = normalized.limit ?? 100;
256
+ return mergeSearchHits(assets ? await assets.search(normalized) : [], await ignoreMissingWorkspace(() => workspace.search(normalized)) ?? []).slice(0, limit);
257
+ },
258
+ materializeSources: async (options) => await workspace.materializeSources?.(options) ?? {
259
+ bytes: 0,
260
+ directories: 0,
261
+ durationMs: 0,
262
+ files: 0,
263
+ path: options?.path || "",
264
+ sources: []
265
+ },
266
+ startSession: async (options) => await workspace.startSession(options)
267
+ }, getWorkspaceSourceRequestExecution(workspace));
268
+ }
269
+ function toReadOperations(options) {
270
+ return {
271
+ list: options?.list,
272
+ materialize: options?.materialize ?? true,
273
+ read: options?.read,
274
+ search: options?.search
275
+ };
276
+ }
277
+ function toWriteOperations(options) {
278
+ return {
279
+ ...toReadOperations(options),
280
+ write: {
281
+ appendFile: options?.appendFile !== false,
282
+ copyPath: options?.copyPath !== false,
283
+ deletePath: options?.deletePath !== false,
284
+ makeDir: options?.makeDir !== false,
285
+ movePath: options?.movePath !== false,
286
+ writeFile: options?.writeFile !== false
287
+ }
288
+ };
289
+ }
290
+ function createDefaultToolSet(createTools) {
291
+ return createTools();
292
+ }
293
+ function emptyTools() {
294
+ return {};
295
+ }
296
+ function useWorkspace(name, options) {
297
+ if (options?.mode === "write") {
298
+ const workspace = createLazyWorkspace(name, options.definition);
299
+ const createTools = (opts) => createWorkspaceTools(workspace, {
300
+ broadSearchPaths: opts?.broadSearchPaths,
301
+ cwd: opts?.cwd,
302
+ maxShellCalls: opts?.maxShellCalls,
303
+ maxOutputLength: opts?.maxOutputLength,
304
+ operations: toWriteOperations(opts),
305
+ timeout: opts?.timeout
306
+ });
307
+ const createReadTools = (opts) => createWorkspaceTools(createReadonlyFs(name, workspace), {
308
+ broadSearchPaths: opts?.broadSearchPaths,
309
+ cwd: opts?.cwd,
310
+ maxShellCalls: opts?.maxShellCalls,
311
+ maxOutputLength: opts?.maxOutputLength,
312
+ operations: toReadOperations(opts),
313
+ timeout: opts?.timeout
314
+ });
315
+ const tools = createDefaultToolSet(createTools);
316
+ tools.inspect = createReadTools;
317
+ tools.write = createTools;
318
+ tools.none = emptyTools;
319
+ return {
320
+ [workspaceStoreTarget]: async () => {
321
+ return await workspace[workspaceStoreTarget]?.();
322
+ },
323
+ diff: async (options) => await workspace.diff(options),
324
+ fs: createWritableFs(workspace),
325
+ getMeta: async (key) => await workspace.getMeta?.(key),
326
+ materializeSources: async (options) => await materializeWorkspaceSources(workspace, options),
327
+ publish: async (options) => await workspace.publish(options),
328
+ setMeta: async (key, value) => await workspace.setMeta?.(key, value),
329
+ snapshot: async (options) => await workspace.snapshot(options),
330
+ startSession: async (options) => await workspace.startSession(options),
331
+ sync: async (options) => await workspace.sync(options),
332
+ tools
333
+ };
334
+ }
335
+ const fs = createReadonlyFs(name, createLazyWorkspace(name, options?.definition));
336
+ const createTools = (opts) => createWorkspaceTools(fs, {
337
+ broadSearchPaths: opts?.broadSearchPaths,
338
+ cwd: opts?.cwd,
339
+ maxShellCalls: opts?.maxShellCalls,
340
+ maxOutputLength: opts?.maxOutputLength,
341
+ operations: toReadOperations(opts),
342
+ timeout: opts?.timeout
343
+ });
344
+ const tools = createDefaultToolSet(createTools);
345
+ tools.inspect = createTools;
346
+ tools.none = emptyTools;
347
+ return {
348
+ fs,
349
+ tools
350
+ };
351
+ }
352
+ //#endregion
353
+ export { useWorkspace as t };
@@ -0,0 +1,55 @@
1
+ import { d as sha256 } from "./path-CNI6wKIU.js";
2
+ //#region src/storage/utils.ts
3
+ async function createCurrentSnapshotFromStore(store, name) {
4
+ return await createSnapshotFromEntries(await store.list("", { recursive: true }), name);
5
+ }
6
+ async function createSnapshotFromEntries(entries, name) {
7
+ const snapshotEntries = {};
8
+ for (const entry of entries) snapshotEntries[entry.path] = {
9
+ digest: entry.digest,
10
+ metadata: entry.metadata,
11
+ size: entry.size,
12
+ type: entry.type
13
+ };
14
+ return {
15
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
16
+ entries: snapshotEntries,
17
+ id: await sha256({
18
+ entries: snapshotEntries,
19
+ name,
20
+ createdAt: Date.now()
21
+ }),
22
+ name
23
+ };
24
+ }
25
+ function diffSnapshots(from, to) {
26
+ const entries = [];
27
+ const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
28
+ for (const path of [...keys].sort()) {
29
+ const before = from?.entries[path];
30
+ const after = to.entries[path];
31
+ if (!before && after) entries.push({
32
+ path,
33
+ type: "added",
34
+ after
35
+ });
36
+ else if (before && !after) entries.push({
37
+ path,
38
+ type: "removed",
39
+ before
40
+ });
41
+ else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata))) entries.push({
42
+ path,
43
+ type: "modified",
44
+ before,
45
+ after
46
+ });
47
+ }
48
+ return {
49
+ from: from?.id,
50
+ to: to.id,
51
+ entries
52
+ };
53
+ }
54
+ //#endregion
55
+ export { createSnapshotFromEntries as n, diffSnapshots as r, createCurrentSnapshotFromStore as t };