@vite-hub/workspace 0.0.1 → 0.0.3

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 (95) hide show
  1. package/README.md +225 -17
  2. package/dist/{ai-Bk3LLnit.js → ai-Ce3PtWFW.js} +160 -29
  3. package/dist/ai-nmHdzjCM.d.ts +162 -0
  4. package/dist/ai.d.ts +2 -85
  5. package/dist/ai.js +1 -1
  6. package/dist/asset-registry-CaG9b7tf.js +19 -0
  7. package/dist/cloudflare.d.ts +18 -0
  8. package/dist/cloudflare.js +2 -0
  9. package/dist/collections/client.d.ts +39 -0
  10. package/dist/collections/client.js +137 -0
  11. package/dist/collections.d.ts +59 -0
  12. package/dist/collections.js +159 -0
  13. package/dist/config-3I1BnsdO.d.ts +28 -0
  14. package/dist/config-CDoyls2X.js +30 -0
  15. package/dist/config-CZLO0m9h.js +7811 -0
  16. package/dist/file-CHfsZpso.js +23 -0
  17. package/dist/{files-DbsIjBya.js → files-QRV55OCx.js} +6 -5
  18. package/dist/github-CfA5vpJ5.js +189 -0
  19. package/dist/glob-D0vD_wRY.js +17 -0
  20. package/dist/host-CAnbugpI.js +370 -0
  21. package/dist/hosted-C1-tTTTf.js +581 -0
  22. package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +100 -19
  23. package/dist/hosted-vercel-blob.d.ts +15 -0
  24. package/dist/hosted-vercel-blob.js +2 -0
  25. package/dist/hosted.d.ts +18 -0
  26. package/dist/hosted.js +2 -0
  27. package/dist/index.d.ts +129 -102
  28. package/dist/index.js +477 -599
  29. package/dist/lifecycle-BYoa9hVb.js +176 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/mountx.d.ts +10 -0
  33. package/dist/mountx.js +143 -0
  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-C3_elpEh.js} +142 -37
  40. package/dist/providers/github/store.d.ts +6 -0
  41. package/dist/providers/github/store.js +2 -0
  42. package/dist/publish.d.ts +3 -2
  43. package/dist/publish.js +48 -142
  44. package/dist/{registry-D4Qzq26I.d.ts → registry-BIQVCBWI.d.ts} +3 -2
  45. package/dist/registry-CqyDTW9Y.js +74 -0
  46. package/dist/request-execution-u9mgUXKX.js +80 -0
  47. package/dist/runtime/assets.d.ts +2 -1
  48. package/dist/runtime/assets.js +5 -5
  49. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  50. package/dist/runtime/empty-registry.d.ts +1 -1
  51. package/dist/runtime/state.d.ts +4 -21
  52. package/dist/runtime/state.js +7 -4
  53. package/dist/runtime/workspace.d.ts +2 -0
  54. package/dist/runtime/workspace.js +2 -0
  55. package/dist/runtime-options-BsPSv5O7.js +13 -0
  56. package/dist/runtime.d.ts +38 -0
  57. package/dist/runtime.js +626 -0
  58. package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
  59. package/dist/server.d.ts +65 -0
  60. package/dist/server.js +355 -0
  61. package/dist/shared-jfogBrd5.js +273 -0
  62. package/dist/source-metadata.d.ts +2 -0
  63. package/dist/source-metadata.js +2 -0
  64. package/dist/state-TTqa3x3Y.d.ts +25 -0
  65. package/dist/store-Bs1SLh55.js +414 -0
  66. package/dist/sync-DiuDmSGk.js +269 -0
  67. package/dist/target-D4Bqb1eH.js +11 -0
  68. package/dist/test.d.ts +1 -1
  69. package/dist/test.js +1 -1
  70. package/dist/types-60Yn149G.d.ts +612 -0
  71. package/dist/use-CUFSnFCS.d.ts +86 -0
  72. package/dist/use-CsV3oIxH.js +336 -0
  73. package/dist/vite-tbfDxtlu.js +2191 -0
  74. package/dist/vite.d.ts +33 -5
  75. package/dist/vite.js +2 -131
  76. package/dist/workspace-66SKyiec.d.ts +6 -0
  77. package/dist/workspace-C4k92Ow8.js +1460 -0
  78. package/package.json +143 -62
  79. package/dist/asset-registry-CMuQbyvl.js +0 -14
  80. package/dist/cloudflare-env-DL94Uvpz.js +0 -12
  81. package/dist/config-CvS-7sre.js +0 -49
  82. package/dist/errors-BUL8SoFS.js +0 -21
  83. package/dist/lifecycle-uD82JeGh.js +0 -92
  84. package/dist/module-8LZUMEXC.js +0 -922
  85. package/dist/path-BVv9OXhg.js +0 -63
  86. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  87. package/dist/providers/cloudflare/artifacts-store.js +0 -384
  88. package/dist/providers/vercel/blob-store.d.ts +0 -6
  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/utils-BtAm_K5P.js +0 -51
  95. /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
@@ -0,0 +1,86 @@
1
+ import { D as WorkspaceAssets, E as WorkspaceAssetPath, Gt as WorkspaceSourceSyncResult, I as WorkspaceDiff, P as WorkspaceDefinition, Q as WorkspaceMaterializeSourcesOptions, R as WorkspaceEntry, Zt as WorkspaceSyncOptions, _ as ReadFileResult, b as RmOptions, bt as WorkspaceSnapshot, c as ListOptions, cn as WriteFileOptions, et as WorkspaceMaterializeSourcesResult, ft as WorkspaceSearchHit, g as ReadFileOptions, ht as WorkspaceSession, j as WorkspaceContent, m as MkdirOptions, n as DiffOptions, pt as WorkspaceSearchQuery, qt as WorkspaceStat, rt as WorkspaceName, s as GlobOptions, st as WorkspacePublishOptions, x as SnapshotOptions, yt as WorkspaceSessionOptions } from "./types-60Yn149G.js";
2
+ import { a as WorkspaceReadOperations, d as WorkspaceWriteToolMap, n as ShellEnabled, o as WorkspaceShellResult, u as WorkspaceWriteOperations } from "./ai-nmHdzjCM.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,336 @@
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-Ce3PtWFW.js";
3
+ import { r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-u9mgUXKX.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-C4k92Ow8.js";
7
+ import { a as useRegisteredWorkspace } from "./registry-CqyDTW9Y.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
+ return attachWorkspaceSourceRequestExecution({
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
+ }, { async executeSourceRequest(input) {
126
+ const executor = getWorkspaceSourceRequestExecution(await resolveSyncedWorkspace());
127
+ if (!executor) throw new Error("[vitehub] No API-backed Source request executor is available for this workspace.");
128
+ return await executor.executeSourceRequest(input);
129
+ } });
130
+ }
131
+ function createWritableFs(workspace) {
132
+ return attachWorkspaceSourceRequestExecution({
133
+ readFile: async (path, options) => await workspace.readFile(normalizePath(path), options),
134
+ writeFile: async (path, content, options) => await workspace.writeFile(normalizePath(path), content, options),
135
+ appendFile: async (path, content) => await appendWorkspaceFile(workspace, normalizePath(path), content),
136
+ stat: async (path) => await workspace.stat(normalizePath(path)),
137
+ exists: async (path) => await workspace.exists(normalizePath(path)),
138
+ list: async (path, options) => await workspace.list(path ? normalizeListPath(path) : "", options),
139
+ glob: async (pattern, options) => await workspace.glob(normalizePattern(pattern), options),
140
+ search: async (query) => await workspace.search({
141
+ ...query,
142
+ cwd: query.cwd ? normalizeListPath(query.cwd) : query.cwd,
143
+ paths: query.paths?.map((path) => normalizeListPath(path))
144
+ }),
145
+ mkdir: async (path, options) => await workspace.mkdir(normalizePath(path), options),
146
+ rm: async (path, options) => await workspace.rm(normalizePath(path), options),
147
+ movePath: async (from, to, options) => {
148
+ const source = normalizePath(from);
149
+ await copyWorkspacePath(workspace, source, normalizePath(to), options?.overwrite);
150
+ await workspace.rm(source, {
151
+ recursive: true,
152
+ force: true
153
+ });
154
+ },
155
+ copyPath: async (from, to, options) => await copyWorkspacePath(workspace, normalizePath(from), normalizePath(to), options?.overwrite)
156
+ }, getWorkspaceSourceRequestExecution(workspace));
157
+ }
158
+ function useOptionalWorkspaceAssets(name) {
159
+ try {
160
+ return useWorkspaceAssets(name);
161
+ } catch (error) {
162
+ if (getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND") return void 0;
163
+ throw error;
164
+ }
165
+ }
166
+ async function ignoreMissingWorkspace(operation) {
167
+ try {
168
+ return await operation();
169
+ } catch (error) {
170
+ if (isMissingWorkspaceRead(error)) return void 0;
171
+ throw error;
172
+ }
173
+ }
174
+ function isMissingWorkspaceRead(error) {
175
+ 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:");
176
+ }
177
+ function mergeEntries(primary = [], fallback = []) {
178
+ const entries = /* @__PURE__ */ new Map();
179
+ for (const entry of fallback) entries.set(entry.path, entry);
180
+ for (const entry of primary) entries.set(entry.path, entry);
181
+ return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
182
+ }
183
+ function mergeSearchHits(primary = [], fallback = []) {
184
+ const seen = /* @__PURE__ */ new Set();
185
+ return [...primary, ...fallback].filter((hit) => {
186
+ const key = `${hit.path}:${hit.line}:${hit.column}:${hit.text}`;
187
+ if (seen.has(key)) return false;
188
+ seen.add(key);
189
+ return true;
190
+ });
191
+ }
192
+ function createReadonlyFs(name, workspace) {
193
+ const assets = useOptionalWorkspaceAssets(name);
194
+ return attachWorkspaceSourceRequestExecution({
195
+ readFile: async (path, options) => {
196
+ const normalized = normalizePath(path);
197
+ try {
198
+ return await workspace.readFile(normalized, options);
199
+ } catch (error) {
200
+ if (assets && isMissingWorkspaceRead(error)) return await assets.readFile(normalized, options);
201
+ throw error;
202
+ }
203
+ },
204
+ stat: async (path) => {
205
+ const normalized = normalizePath(path);
206
+ try {
207
+ return await workspace.stat(normalized);
208
+ } catch (error) {
209
+ if (assets && isMissingWorkspaceRead(error)) return await assets.stat(normalized);
210
+ throw error;
211
+ }
212
+ },
213
+ exists: async (path) => {
214
+ const normalized = normalizePath(path);
215
+ return await ignoreMissingWorkspace(() => workspace.exists(normalized)) ?? (assets ? await assets.exists(normalized) : false);
216
+ },
217
+ list: async (path, options) => {
218
+ const normalized = path ? normalizeListPath(path) : "";
219
+ const workspaceEntries = await ignoreMissingWorkspace(() => workspace.list(normalized, options)) ?? [];
220
+ if (normalized && workspaceEntries.length) return workspaceEntries;
221
+ let assetEntries = assets ? await assets.list(normalized, options) : [];
222
+ if (!normalized && options?.recursive && workspaceEntries.length) {
223
+ const workspaceRoots = new Set(workspaceEntries.filter((entry) => entry.type === "directory").map((entry) => entry.path.split("/")[0]));
224
+ assetEntries = assetEntries.filter((entry) => !workspaceRoots.has(entry.path.split("/")[0]));
225
+ }
226
+ return mergeEntries(assetEntries, workspaceEntries);
227
+ },
228
+ glob: async (pattern, options) => {
229
+ const normalized = normalizePattern(pattern);
230
+ return mergeEntries(assets ? await assets.glob(normalized, options) : [], await ignoreMissingWorkspace(() => workspace.glob(normalized, options)) ?? []);
231
+ },
232
+ search: async (query) => {
233
+ const normalized = {
234
+ ...query,
235
+ cwd: query.cwd ? normalizeListPath(query.cwd) : query.cwd,
236
+ paths: query.paths?.map((path) => normalizeListPath(path))
237
+ };
238
+ const limit = normalized.limit ?? 100;
239
+ return mergeSearchHits(assets ? await assets.search(normalized) : [], await ignoreMissingWorkspace(() => workspace.search(normalized)) ?? []).slice(0, limit);
240
+ },
241
+ materializeSources: async (options) => await workspace.materializeSources?.(options) ?? {
242
+ bytes: 0,
243
+ directories: 0,
244
+ durationMs: 0,
245
+ files: 0,
246
+ path: options?.path || "",
247
+ sources: []
248
+ },
249
+ startSession: async (options) => await workspace.startSession(options)
250
+ }, getWorkspaceSourceRequestExecution(workspace));
251
+ }
252
+ function toReadOperations(options) {
253
+ return {
254
+ list: options?.list,
255
+ materialize: options?.materialize ?? true,
256
+ read: options?.read,
257
+ search: options?.search
258
+ };
259
+ }
260
+ function toWriteOperations(options) {
261
+ return {
262
+ ...toReadOperations(options),
263
+ write: {
264
+ appendFile: options?.appendFile !== false,
265
+ copyPath: options?.copyPath !== false,
266
+ deletePath: options?.deletePath !== false,
267
+ makeDir: options?.makeDir !== false,
268
+ movePath: options?.movePath !== false,
269
+ writeFile: options?.writeFile !== false
270
+ }
271
+ };
272
+ }
273
+ function createDefaultToolSet(createTools) {
274
+ return createTools();
275
+ }
276
+ function emptyTools() {
277
+ return {};
278
+ }
279
+ function useWorkspace(name, options) {
280
+ if (options?.mode === "write") {
281
+ const workspace = createLazyWorkspace(name, options.definition);
282
+ const createTools = (opts) => createWorkspaceTools(workspace, {
283
+ broadSearchPaths: opts?.broadSearchPaths,
284
+ cwd: opts?.cwd,
285
+ maxShellCalls: opts?.maxShellCalls,
286
+ maxOutputLength: opts?.maxOutputLength,
287
+ operations: toWriteOperations(opts),
288
+ timeout: opts?.timeout
289
+ });
290
+ const createReadTools = (opts) => createWorkspaceTools(createReadonlyFs(name, workspace), {
291
+ broadSearchPaths: opts?.broadSearchPaths,
292
+ cwd: opts?.cwd,
293
+ maxShellCalls: opts?.maxShellCalls,
294
+ maxOutputLength: opts?.maxOutputLength,
295
+ operations: toReadOperations(opts),
296
+ timeout: opts?.timeout
297
+ });
298
+ const tools = createDefaultToolSet(createTools);
299
+ tools.inspect = createReadTools;
300
+ tools.write = createTools;
301
+ tools.none = emptyTools;
302
+ return {
303
+ [workspaceStoreTarget]: async () => {
304
+ return await workspace[workspaceStoreTarget]?.();
305
+ },
306
+ diff: async (options) => await workspace.diff(options),
307
+ fs: createWritableFs(workspace),
308
+ getMeta: async (key) => await workspace.getMeta?.(key),
309
+ materializeSources: async (options) => await materializeWorkspaceSources(workspace, options),
310
+ publish: async (options) => await workspace.publish(options),
311
+ setMeta: async (key, value) => await workspace.setMeta?.(key, value),
312
+ snapshot: async (options) => await workspace.snapshot(options),
313
+ startSession: async (options) => await workspace.startSession(options),
314
+ sync: async (options) => await workspace.sync(options),
315
+ tools
316
+ };
317
+ }
318
+ const fs = createReadonlyFs(name, createLazyWorkspace(name, options?.definition));
319
+ const createTools = (opts) => createWorkspaceTools(fs, {
320
+ broadSearchPaths: opts?.broadSearchPaths,
321
+ cwd: opts?.cwd,
322
+ maxShellCalls: opts?.maxShellCalls,
323
+ maxOutputLength: opts?.maxOutputLength,
324
+ operations: toReadOperations(opts),
325
+ timeout: opts?.timeout
326
+ });
327
+ const tools = createDefaultToolSet(createTools);
328
+ tools.inspect = createTools;
329
+ tools.none = emptyTools;
330
+ return {
331
+ fs,
332
+ tools
333
+ };
334
+ }
335
+ //#endregion
336
+ export { useWorkspace as t };