@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.
- package/README.md +225 -17
- package/dist/{ai-Bk3LLnit.js → ai-Ce3PtWFW.js} +160 -29
- package/dist/ai-nmHdzjCM.d.ts +162 -0
- package/dist/ai.d.ts +2 -85
- package/dist/ai.js +1 -1
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/cloudflare.d.ts +18 -0
- package/dist/cloudflare.js +2 -0
- package/dist/collections/client.d.ts +39 -0
- package/dist/collections/client.js +137 -0
- package/dist/collections.d.ts +59 -0
- package/dist/collections.js +159 -0
- package/dist/config-3I1BnsdO.d.ts +28 -0
- package/dist/config-CDoyls2X.js +30 -0
- package/dist/config-CZLO0m9h.js +7811 -0
- package/dist/file-CHfsZpso.js +23 -0
- package/dist/{files-DbsIjBya.js → files-QRV55OCx.js} +6 -5
- package/dist/github-CfA5vpJ5.js +189 -0
- package/dist/glob-D0vD_wRY.js +17 -0
- package/dist/host-CAnbugpI.js +370 -0
- package/dist/hosted-C1-tTTTf.js +581 -0
- package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +100 -19
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +2 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +2 -0
- package/dist/index.d.ts +129 -102
- package/dist/index.js +477 -599
- package/dist/lifecycle-BYoa9hVb.js +176 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/mountx.d.ts +10 -0
- package/dist/mountx.js +143 -0
- package/dist/nitro.d.ts +2 -31
- package/dist/nitro.js +2 -2
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/{provider-BZuKAV4e.js → provider-C3_elpEh.js} +142 -37
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +2 -0
- package/dist/publish.d.ts +3 -2
- package/dist/publish.js +48 -142
- package/dist/{registry-D4Qzq26I.d.ts → registry-BIQVCBWI.d.ts} +3 -2
- package/dist/registry-CqyDTW9Y.js +74 -0
- package/dist/request-execution-u9mgUXKX.js +80 -0
- package/dist/runtime/assets.d.ts +2 -1
- package/dist/runtime/assets.js +5 -5
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +1 -1
- package/dist/runtime/state.d.ts +4 -21
- package/dist/runtime/state.js +7 -4
- package/dist/runtime/workspace.d.ts +2 -0
- package/dist/runtime/workspace.js +2 -0
- package/dist/runtime-options-BsPSv5O7.js +13 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.js +626 -0
- package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
- package/dist/server.d.ts +65 -0
- package/dist/server.js +355 -0
- package/dist/shared-jfogBrd5.js +273 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-TTqa3x3Y.d.ts +25 -0
- package/dist/store-Bs1SLh55.js +414 -0
- package/dist/sync-DiuDmSGk.js +269 -0
- package/dist/target-D4Bqb1eH.js +11 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/types-60Yn149G.d.ts +612 -0
- package/dist/use-CUFSnFCS.d.ts +86 -0
- package/dist/use-CsV3oIxH.js +336 -0
- package/dist/vite-tbfDxtlu.js +2191 -0
- package/dist/vite.d.ts +33 -5
- package/dist/vite.js +2 -131
- package/dist/workspace-66SKyiec.d.ts +6 -0
- package/dist/workspace-C4k92Ow8.js +1460 -0
- package/package.json +143 -62
- package/dist/asset-registry-CMuQbyvl.js +0 -14
- package/dist/cloudflare-env-DL94Uvpz.js +0 -12
- package/dist/config-CvS-7sre.js +0 -49
- package/dist/errors-BUL8SoFS.js +0 -21
- package/dist/lifecycle-uD82JeGh.js +0 -92
- package/dist/module-8LZUMEXC.js +0 -922
- package/dist/path-BVv9OXhg.js +0 -63
- package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
- package/dist/providers/cloudflare/artifacts-store.js +0 -384
- package/dist/providers/vercel/blob-store.d.ts +0 -6
- package/dist/registry-Cnr0NoKv.js +0 -932
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -14
- package/dist/sandbox-DtGXCWRq.js +0 -198
- package/dist/types-CwNcWTdt.d.ts +0 -378
- package/dist/utils-BtAm_K5P.js +0 -51
- /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import { c as normalizeWorkspacePath, p as workspaceError } from "./path-CNI6wKIU.js";
|
|
2
|
+
import { a as copyWorkspacePath, i as appendWorkspaceFile, n as getWorkspaceDependencyRuntimeLoaders, r as setWorkspaceDependencyRuntimeLoaders, t as createWorkspaceTools } from "./ai-Ce3PtWFW.js";
|
|
3
|
+
import { a as normalizeWorkspaceSources, f as getWorkspaceSourceRequestDescriptor, g as markLiveWorkspaceSource, h as workspaceSourceRequestDescriptorPath, i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, m as isWorkspaceSourceRequestOnly, o as normalizeWorkspaceSourcesMetadata, r as normalizeWorkspaceSource, t as copyWorkspaceSourceMetadata } from "./config-CZLO0m9h.js";
|
|
4
|
+
import { n as createWorkspaceSourceRequestExecution, r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-u9mgUXKX.js";
|
|
5
|
+
import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, s as createMemoryWorkspaceStore, u as getWorkspaceRuntimeConfig } from "./provider-C3_elpEh.js";
|
|
6
|
+
import { t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
7
|
+
import { d as createBasicWorkspaceSession, l as createWorkspaceWritePolicy, n as resetWorkspaceStoreCache, r as createWorkspaceSourceView, s as resolveWorkspacePath } from "./workspace-C4k92Ow8.js";
|
|
8
|
+
import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "./registry-CqyDTW9Y.js";
|
|
9
|
+
import { t as useWorkspace } from "./use-CsV3oIxH.js";
|
|
10
|
+
import { setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeRegistry } from "./runtime/state.js";
|
|
11
|
+
//#region src/sources/resolution.ts
|
|
12
|
+
function hasWorkspaceSourceResolvers(definition) {
|
|
13
|
+
return normalizeWorkspaceSources(definition?.sources).some((source) => typeof source.source.resolve === "function");
|
|
14
|
+
}
|
|
15
|
+
function isWritableWorkspaceFacade(workspace) {
|
|
16
|
+
return typeof workspace.fs.writeFile === "function";
|
|
17
|
+
}
|
|
18
|
+
function workspaceSessionStarter(workspace) {
|
|
19
|
+
return typeof workspace.startSession === "function" ? workspace : void 0;
|
|
20
|
+
}
|
|
21
|
+
function writeOperations(options) {
|
|
22
|
+
return {
|
|
23
|
+
appendFile: options?.appendFile !== false,
|
|
24
|
+
copyPath: options?.copyPath !== false,
|
|
25
|
+
deletePath: options?.deletePath !== false,
|
|
26
|
+
makeDir: options?.makeDir !== false,
|
|
27
|
+
movePath: options?.movePath !== false,
|
|
28
|
+
writeFile: options?.writeFile !== false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function createOverlaySourceStore(workspace, fallback) {
|
|
32
|
+
const memory = createMemoryWorkspaceStore();
|
|
33
|
+
async function readBaseFile(path) {
|
|
34
|
+
if (!fallback(path)) return;
|
|
35
|
+
if (!await workspace.fs.exists(path)) return;
|
|
36
|
+
const stat = await workspace.fs.stat(path).catch(() => void 0);
|
|
37
|
+
if (stat?.type === "directory") return;
|
|
38
|
+
return {
|
|
39
|
+
content: await workspace.fs.readFile(path, { encoding: "binary" }),
|
|
40
|
+
mediaType: stat?.mediaType,
|
|
41
|
+
path
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async function baseEntries(path = "", options) {
|
|
45
|
+
try {
|
|
46
|
+
return (await workspace.fs.list(path, options)).filter((entry) => fallback(entry.path));
|
|
47
|
+
} catch {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function baseGlob(pattern, options) {
|
|
52
|
+
try {
|
|
53
|
+
return (await workspace.fs.glob(pattern, options)).filter((entry) => fallback(entry.path));
|
|
54
|
+
} catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function baseStat(path) {
|
|
59
|
+
if (!fallback(path)) return;
|
|
60
|
+
try {
|
|
61
|
+
return await workspace.fs.stat(path);
|
|
62
|
+
} catch {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
async readFile(path) {
|
|
68
|
+
return await memory.readFile(path) || await readBaseFile(path);
|
|
69
|
+
},
|
|
70
|
+
async writeFile(path, file) {
|
|
71
|
+
await memory.writeFile(path, file);
|
|
72
|
+
},
|
|
73
|
+
async list(path, options) {
|
|
74
|
+
return mergeEntries(await baseEntries(path, options), await memory.list(path, options));
|
|
75
|
+
},
|
|
76
|
+
async glob(pattern, options) {
|
|
77
|
+
return mergeEntries(await baseGlob(pattern, options), await memory.glob(pattern, options));
|
|
78
|
+
},
|
|
79
|
+
async stat(path) {
|
|
80
|
+
return await memory.stat(path) || await baseStat(path);
|
|
81
|
+
},
|
|
82
|
+
async mkdir(path, options) {
|
|
83
|
+
await memory.mkdir(path, options);
|
|
84
|
+
},
|
|
85
|
+
async rm(path, options) {
|
|
86
|
+
await memory.rm(path, options);
|
|
87
|
+
},
|
|
88
|
+
async snapshot(options) {
|
|
89
|
+
return await memory.snapshot(options);
|
|
90
|
+
},
|
|
91
|
+
async diff(options) {
|
|
92
|
+
return await memory.diff(options);
|
|
93
|
+
},
|
|
94
|
+
async getMeta(key) {
|
|
95
|
+
return await memory.getMeta?.(key);
|
|
96
|
+
},
|
|
97
|
+
async setMeta(key, value) {
|
|
98
|
+
await memory.setMeta?.(key, value);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function createWritableFacadeStore(workspace) {
|
|
103
|
+
const meta = /* @__PURE__ */ new Map();
|
|
104
|
+
const metadata = workspace;
|
|
105
|
+
const store = {
|
|
106
|
+
async readFile(path) {
|
|
107
|
+
try {
|
|
108
|
+
const stat = await workspace.fs.stat(path);
|
|
109
|
+
if (stat.type === "directory") return;
|
|
110
|
+
return {
|
|
111
|
+
content: await workspace.fs.readFile(path, { encoding: "binary" }),
|
|
112
|
+
mediaType: stat.mediaType,
|
|
113
|
+
path
|
|
114
|
+
};
|
|
115
|
+
} catch {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
async writeFile(path, file) {
|
|
120
|
+
await workspace.fs.writeFile(path, file.content, { mediaType: file.mediaType });
|
|
121
|
+
},
|
|
122
|
+
async list(path, options) {
|
|
123
|
+
return await workspace.fs.list(path, options);
|
|
124
|
+
},
|
|
125
|
+
async glob(pattern, options) {
|
|
126
|
+
return await workspace.fs.glob(pattern, options);
|
|
127
|
+
},
|
|
128
|
+
async stat(path) {
|
|
129
|
+
try {
|
|
130
|
+
return await workspace.fs.stat(path);
|
|
131
|
+
} catch {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
async mkdir(path, options) {
|
|
136
|
+
await workspace.fs.mkdir(path, options);
|
|
137
|
+
},
|
|
138
|
+
async rm(path, options) {
|
|
139
|
+
await workspace.fs.rm(path, options);
|
|
140
|
+
},
|
|
141
|
+
async snapshot(options) {
|
|
142
|
+
return await workspace.snapshot(options);
|
|
143
|
+
},
|
|
144
|
+
async diff(options) {
|
|
145
|
+
return await workspace.diff(options);
|
|
146
|
+
},
|
|
147
|
+
async getMeta(key) {
|
|
148
|
+
if (metadata.getMeta) return await metadata.getMeta(key);
|
|
149
|
+
return meta.get(key);
|
|
150
|
+
},
|
|
151
|
+
async setMeta(key, value) {
|
|
152
|
+
if (metadata.setMeta) {
|
|
153
|
+
await metadata.setMeta(key, value);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
meta.set(key, value);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
forwardWorkspaceStoreTarget(workspace, store);
|
|
160
|
+
return store;
|
|
161
|
+
}
|
|
162
|
+
async function startOverlayWorkspaceSession(_definition, workspace, options) {
|
|
163
|
+
const host = options?.host;
|
|
164
|
+
if (host) {
|
|
165
|
+
const { createHostedWorkspaceSession } = await import("./host-CAnbugpI.js");
|
|
166
|
+
return await createHostedWorkspaceSession(workspace, {
|
|
167
|
+
...options,
|
|
168
|
+
host
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return await createBasicWorkspaceSession(workspace, options);
|
|
172
|
+
}
|
|
173
|
+
async function resolveWorkspaceSources(definition, options) {
|
|
174
|
+
if (!hasWorkspaceSourceResolvers(definition) && !options.selectedWorkspaceScope) return definition;
|
|
175
|
+
const sources = {};
|
|
176
|
+
for (const [key, source] of Object.entries(definition.sources || {})) {
|
|
177
|
+
const resolved = await resolveWorkspaceSource(definition, key, source, options);
|
|
178
|
+
if (resolved) sources[key] = resolved;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
...definition,
|
|
182
|
+
sources
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async function createWorkspaceSourceResolutionFacade(workspace, definition, options) {
|
|
186
|
+
const resolvedDefinition = await resolveWorkspaceSources(definition, options);
|
|
187
|
+
const sourceRequestExecution = createWorkspaceSourceRequestExecution(resolvedDefinition, { selectedWorkspaceScope: options.selectedWorkspaceScope }) ?? getWorkspaceSourceRequestExecution(workspace.fs);
|
|
188
|
+
if (!options.overlay && resolvedDefinition === definition && !sourceRequestExecution) return {
|
|
189
|
+
definition,
|
|
190
|
+
workspace
|
|
191
|
+
};
|
|
192
|
+
const selectedWorkspaceScope = options.selectedWorkspaceScope;
|
|
193
|
+
const sourceView = createWorkspaceSourceView(createScopedSourceViewDefinition(resolvedDefinition, selectedWorkspaceScope), createOverlaySourceStore(workspace, (path) => !isLazySourcePath(resolvedDefinition, path)));
|
|
194
|
+
const materializeSources = async (options = {}) => await sourceView.materializeSources(options);
|
|
195
|
+
let readWorkspace;
|
|
196
|
+
const fs = attachWorkspaceSourceRequestExecution({
|
|
197
|
+
async readFile(path, options) {
|
|
198
|
+
if (isSourcePath(resolvedDefinition, path)) return await sourceView.readFile(path, options);
|
|
199
|
+
if (selectedScopeCanRead(selectedWorkspaceScope, path) && await sourceViewHasPath(resolvedDefinition, sourceView, path)) return await sourceView.readFile(path, options);
|
|
200
|
+
return await workspace.fs.readFile(path, options);
|
|
201
|
+
},
|
|
202
|
+
async stat(path) {
|
|
203
|
+
if (isSourcePath(resolvedDefinition, path)) return await sourceView.stat(path);
|
|
204
|
+
if (selectedScopeCanSee(selectedWorkspaceScope, path) && await sourceViewHasPath(resolvedDefinition, sourceView, path)) return await sourceView.stat(path);
|
|
205
|
+
return await workspace.fs.stat(path);
|
|
206
|
+
},
|
|
207
|
+
async exists(path) {
|
|
208
|
+
if (isSourcePath(resolvedDefinition, path)) return await sourceView.exists(path);
|
|
209
|
+
return selectedScopeCanSee(selectedWorkspaceScope, path) && await sourceViewHasPath(resolvedDefinition, sourceView, path) || await workspace.fs.exists(path);
|
|
210
|
+
},
|
|
211
|
+
async list(path = "", options = {}) {
|
|
212
|
+
const normalized = normalizeWorkspacePath(path);
|
|
213
|
+
if (normalized && isSourcePath(resolvedDefinition, normalized)) return filterScopedEntries(selectedWorkspaceScope, await sourceView.list(normalized, options));
|
|
214
|
+
const [baseEntries, sourceEntries] = await Promise.all([workspace.fs.list(path, options), selectedScopeCanSee(selectedWorkspaceScope, normalized) && sourcePathIntersects(resolvedDefinition, normalized) ? sourceView.list(normalized, options) : Promise.resolve([])]);
|
|
215
|
+
return mergeEntries(filterBaseEntries(resolvedDefinition, baseEntries), filterScopedEntries(selectedWorkspaceScope, sourceEntries));
|
|
216
|
+
},
|
|
217
|
+
async glob(pattern, options) {
|
|
218
|
+
const [baseEntries, sourceEntries] = await Promise.all([workspace.fs.glob(pattern, options), sourceView.glob(pattern, options)]);
|
|
219
|
+
return mergeEntries(filterBaseEntries(resolvedDefinition, baseEntries), filterScopedEntries(selectedWorkspaceScope, sourceEntries));
|
|
220
|
+
},
|
|
221
|
+
async search(query) {
|
|
222
|
+
const scopedToSource = searchQueryTargetsSource(resolvedDefinition, query);
|
|
223
|
+
const [baseHits, sourceHits] = await Promise.all([scopedToSource ? Promise.resolve([]) : workspace.fs.search(query), sourceView.search(query)]);
|
|
224
|
+
return mergeHits(filterBaseHits(resolvedDefinition, baseHits), filterScopedHits(selectedWorkspaceScope, sourceHits)).slice(0, query.limit ?? 100);
|
|
225
|
+
},
|
|
226
|
+
materializeSources,
|
|
227
|
+
startSession: async (options) => {
|
|
228
|
+
const paths = options?.paths?.length ? options.paths : [""];
|
|
229
|
+
await Promise.all(paths.map((path) => materializeSources({ path })));
|
|
230
|
+
return await startOverlayWorkspaceSession(resolvedDefinition, readWorkspace, options);
|
|
231
|
+
}
|
|
232
|
+
}, sourceRequestExecution);
|
|
233
|
+
readWorkspace = attachWorkspaceSourceRequestExecution({
|
|
234
|
+
name: resolvedDefinition.name,
|
|
235
|
+
exists: fs.exists,
|
|
236
|
+
glob: fs.glob,
|
|
237
|
+
list: fs.list,
|
|
238
|
+
materializeSources,
|
|
239
|
+
readFile: fs.readFile,
|
|
240
|
+
search: fs.search,
|
|
241
|
+
startSession: fs.startSession,
|
|
242
|
+
stat: fs.stat
|
|
243
|
+
}, sourceRequestExecution);
|
|
244
|
+
const createTools = (options) => createWorkspaceTools(fs, {
|
|
245
|
+
broadSearchPaths: options?.broadSearchPaths,
|
|
246
|
+
cwd: options?.cwd,
|
|
247
|
+
maxShellCalls: options?.maxShellCalls,
|
|
248
|
+
maxOutputLength: options?.maxOutputLength,
|
|
249
|
+
operations: {
|
|
250
|
+
list: options?.list,
|
|
251
|
+
materialize: options?.materialize ?? true,
|
|
252
|
+
read: options?.read,
|
|
253
|
+
search: options?.search
|
|
254
|
+
},
|
|
255
|
+
timeout: options?.timeout
|
|
256
|
+
});
|
|
257
|
+
const tools = createTools();
|
|
258
|
+
tools.inspect = createTools;
|
|
259
|
+
tools.none = (() => ({}));
|
|
260
|
+
if (isWritableWorkspaceFacade(workspace)) {
|
|
261
|
+
const writePolicy = createWorkspaceWritePolicy(resolvedDefinition);
|
|
262
|
+
const syncStore = createWritableFacadeStore(workspace);
|
|
263
|
+
let writeWorkspace;
|
|
264
|
+
async function previousStat(path) {
|
|
265
|
+
try {
|
|
266
|
+
return await workspace.fs.stat(path);
|
|
267
|
+
} catch {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async function writeWithPolicy(input, write) {
|
|
272
|
+
await sourceView.assertWritable(input.path);
|
|
273
|
+
const next = await writePolicy.before({
|
|
274
|
+
...input,
|
|
275
|
+
path: normalizeWorkspacePath(input.path),
|
|
276
|
+
previous: await previousStat(input.path),
|
|
277
|
+
workspace: resolvedDefinition.name
|
|
278
|
+
});
|
|
279
|
+
try {
|
|
280
|
+
await sourceView.assertWritable(next.path);
|
|
281
|
+
await write(next);
|
|
282
|
+
await writePolicy.after(next);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
await writePolicy.error(next, error);
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function withSessionSourceGuards(session) {
|
|
289
|
+
return {
|
|
290
|
+
...session,
|
|
291
|
+
async mkdir(path, options) {
|
|
292
|
+
await sourceView.assertWritable(path);
|
|
293
|
+
await session.mkdir(path, options);
|
|
294
|
+
},
|
|
295
|
+
async rm(path, options) {
|
|
296
|
+
await sourceView.assertWritable(path);
|
|
297
|
+
await session.rm(path, options);
|
|
298
|
+
},
|
|
299
|
+
async writeFile(path, content, options) {
|
|
300
|
+
await sourceView.assertWritable(path);
|
|
301
|
+
await session.writeFile(path, content, options);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const writeFs = attachWorkspaceSourceRequestExecution({
|
|
306
|
+
appendFile: async (path, content) => await appendWorkspaceFile(writeWorkspace, path, content),
|
|
307
|
+
copyPath: async (from, to, options) => await copyWorkspacePath(writeWorkspace, from, to, options?.overwrite),
|
|
308
|
+
exists: fs.exists,
|
|
309
|
+
glob: fs.glob,
|
|
310
|
+
list: fs.list,
|
|
311
|
+
mkdir: async (path, options) => await writeWithPolicy({
|
|
312
|
+
operation: "mkdir",
|
|
313
|
+
path
|
|
314
|
+
}, async (input) => await workspace.fs.mkdir(input.path, options)),
|
|
315
|
+
movePath: async (from, to, options) => {
|
|
316
|
+
await sourceView.assertWritable(from);
|
|
317
|
+
await sourceView.assertWritable(to);
|
|
318
|
+
await copyWorkspacePath(writeWorkspace, from, to, options?.overwrite);
|
|
319
|
+
await writeWorkspace.rm(from, {
|
|
320
|
+
recursive: true,
|
|
321
|
+
force: true
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
readFile: fs.readFile,
|
|
325
|
+
rm: async (path, options) => await writeWithPolicy({
|
|
326
|
+
operation: "rm",
|
|
327
|
+
path
|
|
328
|
+
}, async (input) => await workspace.fs.rm(input.path, options)),
|
|
329
|
+
search: fs.search,
|
|
330
|
+
stat: fs.stat,
|
|
331
|
+
writeFile: async (path, content, options) => await writeWithPolicy({
|
|
332
|
+
content,
|
|
333
|
+
mediaType: options?.mediaType,
|
|
334
|
+
metadata: options?.metadata,
|
|
335
|
+
operation: "writeFile",
|
|
336
|
+
path
|
|
337
|
+
}, async (input) => {
|
|
338
|
+
const writeOptions = options === void 0 && input.mediaType === void 0 && input.metadata === void 0 ? void 0 : {
|
|
339
|
+
...options,
|
|
340
|
+
mediaType: input.mediaType,
|
|
341
|
+
metadata: input.metadata
|
|
342
|
+
};
|
|
343
|
+
await workspace.fs.writeFile(input.path, input.content ?? content, writeOptions);
|
|
344
|
+
})
|
|
345
|
+
}, sourceRequestExecution);
|
|
346
|
+
writeWorkspace = attachWorkspaceSourceRequestExecution({
|
|
347
|
+
name: resolvedDefinition.name,
|
|
348
|
+
diff: workspace.diff,
|
|
349
|
+
exists: writeFs.exists,
|
|
350
|
+
glob: writeFs.glob,
|
|
351
|
+
list: writeFs.list,
|
|
352
|
+
materializeSources,
|
|
353
|
+
mkdir: writeFs.mkdir,
|
|
354
|
+
publish: async (options) => {
|
|
355
|
+
const { publishWorkspace } = await import("./lifecycle-BYoa9hVb.js").then((n) => n.t);
|
|
356
|
+
await publishWorkspace(resolvedDefinition, createWritableFacadeStore({
|
|
357
|
+
...workspace,
|
|
358
|
+
fs: writeFs
|
|
359
|
+
}), options);
|
|
360
|
+
},
|
|
361
|
+
readFile: writeFs.readFile,
|
|
362
|
+
rm: writeFs.rm,
|
|
363
|
+
search: writeFs.search,
|
|
364
|
+
snapshot: workspace.snapshot,
|
|
365
|
+
startSession: async (options) => {
|
|
366
|
+
const paths = options?.paths?.length ? options.paths : [""];
|
|
367
|
+
await Promise.all(paths.map((path) => materializeSources({ path })));
|
|
368
|
+
const startBoxSession = workspace[Symbol.for("vitehub.workspace.start-box-session")];
|
|
369
|
+
return withSessionSourceGuards(options?.host ? await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options) : typeof startBoxSession === "function" ? await startBoxSession(writeWorkspace, options) : await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options));
|
|
370
|
+
},
|
|
371
|
+
stat: writeFs.stat,
|
|
372
|
+
sync: async (options) => {
|
|
373
|
+
const { syncWorkspaceSources } = await import("./sync-DiuDmSGk.js");
|
|
374
|
+
return await syncWorkspaceSources(resolvedDefinition, syncStore, options);
|
|
375
|
+
},
|
|
376
|
+
writeFile: writeFs.writeFile
|
|
377
|
+
}, sourceRequestExecution);
|
|
378
|
+
const createWriteTools = (options) => createWorkspaceTools(writeWorkspace, {
|
|
379
|
+
broadSearchPaths: options?.broadSearchPaths,
|
|
380
|
+
cwd: options?.cwd,
|
|
381
|
+
maxShellCalls: options?.maxShellCalls,
|
|
382
|
+
maxOutputLength: options?.maxOutputLength,
|
|
383
|
+
operations: {
|
|
384
|
+
list: options?.list,
|
|
385
|
+
materialize: options?.materialize ?? true,
|
|
386
|
+
read: options?.read,
|
|
387
|
+
search: options?.search,
|
|
388
|
+
write: writeOperations(options)
|
|
389
|
+
},
|
|
390
|
+
timeout: options?.timeout
|
|
391
|
+
});
|
|
392
|
+
const writeTools = createWriteTools();
|
|
393
|
+
writeTools.inspect = createTools;
|
|
394
|
+
writeTools.none = (() => ({}));
|
|
395
|
+
writeTools.write = createWriteTools;
|
|
396
|
+
return {
|
|
397
|
+
definition: resolvedDefinition,
|
|
398
|
+
workspace: {
|
|
399
|
+
...workspace,
|
|
400
|
+
diff: writeWorkspace.diff,
|
|
401
|
+
fs: writeFs,
|
|
402
|
+
materializeSources,
|
|
403
|
+
publish: writeWorkspace.publish,
|
|
404
|
+
snapshot: writeWorkspace.snapshot,
|
|
405
|
+
startSession: writeWorkspace.startSession,
|
|
406
|
+
sync: writeWorkspace.sync,
|
|
407
|
+
tools: writeTools
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
const readonlyWorkspace = {
|
|
412
|
+
fs,
|
|
413
|
+
tools
|
|
414
|
+
};
|
|
415
|
+
const starter = workspaceSessionStarter(workspace);
|
|
416
|
+
if (starter) readonlyWorkspace.startSession = async (options) => await starter.startSession(options);
|
|
417
|
+
return {
|
|
418
|
+
definition: resolvedDefinition,
|
|
419
|
+
workspace: readonlyWorkspace
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
async function resolveWorkspaceSource(definition, key, input, options) {
|
|
423
|
+
const declared = normalizeWorkspaceSource(key, input);
|
|
424
|
+
const source = declared.source;
|
|
425
|
+
if (!source.resolve) return selectedScopeIntersectsSource(options.selectedWorkspaceScope, declared) ? input : void 0;
|
|
426
|
+
const context = {
|
|
427
|
+
...Object.fromEntries(options.invocation.context.entries()),
|
|
428
|
+
invocation: options.invocation,
|
|
429
|
+
selectedWorkspaceScope: options.selectedWorkspaceScope,
|
|
430
|
+
source: {
|
|
431
|
+
key,
|
|
432
|
+
mountPath: declared.mountPath
|
|
433
|
+
},
|
|
434
|
+
workspace: {
|
|
435
|
+
name: definition.name,
|
|
436
|
+
rootDir: definition.rootDir,
|
|
437
|
+
sourceRootDir: definition.sourceRootDir
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
const resolve = source.resolve;
|
|
441
|
+
const resolved = await resolve(context);
|
|
442
|
+
if (!resolved) return void 0;
|
|
443
|
+
const resolvedSource = withResolvedSourceRuntimeDefaults(applyResolvedWorkspaceSourceBinding(input, resolved));
|
|
444
|
+
const normalized = normalizeWorkspaceSource(key, resolvedSource);
|
|
445
|
+
if (!selectedScopeIntersectsSource(options.selectedWorkspaceScope, normalized)) return void 0;
|
|
446
|
+
return copyWorkspaceSourceMetadata(resolvedSource, {
|
|
447
|
+
...resolvedSource,
|
|
448
|
+
fingerprint: {
|
|
449
|
+
source: resolvedSource.fingerprint,
|
|
450
|
+
sourceResolution: { selectedWorkspaceScope: options.selectedWorkspaceScope ? {
|
|
451
|
+
all: options.selectedWorkspaceScope.all,
|
|
452
|
+
name: options.selectedWorkspaceScope.name,
|
|
453
|
+
paths: options.selectedWorkspaceScope.paths,
|
|
454
|
+
role: options.selectedWorkspaceScope.role,
|
|
455
|
+
sources: options.selectedWorkspaceScope.sources
|
|
456
|
+
} : void 0 }
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
function applyResolvedWorkspaceSourceBinding(input, source) {
|
|
461
|
+
if (!isPlainRecord(input)) return source;
|
|
462
|
+
const next = { ...source };
|
|
463
|
+
copyWorkspaceSourceMetadata(source, next);
|
|
464
|
+
if (!("source" in input)) return next;
|
|
465
|
+
copyDefinedWorkspaceBindingOption(next, input, "cache");
|
|
466
|
+
copyDefinedWorkspaceBindingOption(next, input, "materialize");
|
|
467
|
+
copyDefinedWorkspaceBindingOption(next, input, "mount");
|
|
468
|
+
copyDefinedWorkspaceBindingOption(next, input, "sync");
|
|
469
|
+
copyDefinedWorkspaceBindingOption(next, input, "validate");
|
|
470
|
+
return next;
|
|
471
|
+
}
|
|
472
|
+
function copyDefinedWorkspaceBindingOption(target, input, key) {
|
|
473
|
+
if (input[key] !== void 0) target[key] = input[key];
|
|
474
|
+
}
|
|
475
|
+
function withResolvedSourceRuntimeDefaults(source) {
|
|
476
|
+
if (source.materialize || source.mount && typeof source.mount === "object" && source.mount.materialize) return source;
|
|
477
|
+
if (source.sync) return source;
|
|
478
|
+
return copyWorkspaceSourceMetadata(source, {
|
|
479
|
+
...source,
|
|
480
|
+
materialize: "lazy"
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
function isPlainRecord(input) {
|
|
484
|
+
return !!input && typeof input === "object" && !Array.isArray(input);
|
|
485
|
+
}
|
|
486
|
+
function isSourcePath(definition, path) {
|
|
487
|
+
if (isWorkspaceMetadataPath(path)) return false;
|
|
488
|
+
return resolveWorkspacePath(definition, path).type === "source";
|
|
489
|
+
}
|
|
490
|
+
async function sourceViewHasPath(definition, sourceView, path) {
|
|
491
|
+
if (!sourcePathIntersects(definition, normalizeWorkspacePath(path))) return false;
|
|
492
|
+
try {
|
|
493
|
+
return await sourceView.exists(path);
|
|
494
|
+
} catch {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function sourcePathIntersects(definition, path) {
|
|
499
|
+
if (isWorkspaceMetadataPath(path)) return sourceDescriptorPathIntersects(definition, path);
|
|
500
|
+
return normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize !== "none").some((source) => pathIntersects(source.mountPath, path));
|
|
501
|
+
}
|
|
502
|
+
function isWorkspaceMetadataPath(path) {
|
|
503
|
+
const normalized = normalizeWorkspacePath(path);
|
|
504
|
+
return normalized === ".vitehub" || normalized.startsWith(".vitehub/");
|
|
505
|
+
}
|
|
506
|
+
function sourceDescriptorPathIntersects(definition, path) {
|
|
507
|
+
const normalized = normalizeWorkspacePath(path);
|
|
508
|
+
return normalizeWorkspaceSources(definition.sources).some((source) => source.requestDescriptor && pathIntersects(workspaceSourceRequestDescriptorPath(source.key), normalized));
|
|
509
|
+
}
|
|
510
|
+
function isLazySourcePath(definition, path) {
|
|
511
|
+
const normalized = normalizeWorkspacePath(path);
|
|
512
|
+
return normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize === "lazy").some((source) => pathIntersects(source.mountPath, normalized));
|
|
513
|
+
}
|
|
514
|
+
function searchQueryTargetsSource(definition, query) {
|
|
515
|
+
return (query.paths?.length ? query.paths : [query.cwd || ""]).every((path) => isSourcePath(definition, path));
|
|
516
|
+
}
|
|
517
|
+
function filterBaseEntries(definition, entries) {
|
|
518
|
+
return entries.filter((entry) => !isSourcePath(definition, entry.path));
|
|
519
|
+
}
|
|
520
|
+
function filterBaseHits(definition, hits) {
|
|
521
|
+
return hits.filter((hit) => !isSourcePath(definition, hit.path));
|
|
522
|
+
}
|
|
523
|
+
function createScopedSourceViewDefinition(definition, scope) {
|
|
524
|
+
if (!scope || scope.all) return definition;
|
|
525
|
+
const sources = {};
|
|
526
|
+
for (const source of normalizeWorkspaceSources(definition.sources)) sources[source.key] = scopedWorkspaceSource(source, scope);
|
|
527
|
+
return {
|
|
528
|
+
...definition,
|
|
529
|
+
sources
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
function scopedWorkspaceSource(source, scope) {
|
|
533
|
+
const scopedLivePaths = source.livePaths ? {} : void 0;
|
|
534
|
+
syncScopedLivePaths(scopedLivePaths, source.livePaths, scope);
|
|
535
|
+
const scoped = {
|
|
536
|
+
...source.source,
|
|
537
|
+
...scopedLivePaths ? { async prepare(ctx) {
|
|
538
|
+
await source.source.prepare?.(ctx);
|
|
539
|
+
syncScopedLivePaths(scopedLivePaths, source.livePaths, scope);
|
|
540
|
+
} } : {},
|
|
541
|
+
...source.source.getItems ? { getItems: async (ctx) => (await source.source.getItems(ctx)).filter((item) => selectedScopeCanRead(scope, sourceItemWorkspacePath(source, item.path || item.key))) } : {},
|
|
542
|
+
getKeys: async (ctx) => (await source.source.getKeys(ctx)).filter((key) => selectedScopeCanRead(scope, sourceItemWorkspacePath(source, key))),
|
|
543
|
+
getItem: async (key, ctx) => {
|
|
544
|
+
const path = sourceItemWorkspacePath(source, key);
|
|
545
|
+
if (!selectedScopeCanRead(scope, path)) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
546
|
+
return await source.source.getItem(key, ctx);
|
|
547
|
+
},
|
|
548
|
+
...source.source.getMeta ? { getMeta: async (key, ctx) => {
|
|
549
|
+
if (!selectedScopeCanRead(scope, sourceItemWorkspacePath(source, key))) return void 0;
|
|
550
|
+
return await source.source.getMeta(key, ctx);
|
|
551
|
+
} } : {},
|
|
552
|
+
...source.source.search ? { search: async (query, ctx) => {
|
|
553
|
+
const paths = selectedScopeQueryPaths(scope, query).filter((path) => pathIntersects(source.mountPath, path));
|
|
554
|
+
if (!paths.length) return [];
|
|
555
|
+
return filterScopedHits(scope, await source.source.search({
|
|
556
|
+
...query,
|
|
557
|
+
paths
|
|
558
|
+
}, ctx));
|
|
559
|
+
} } : {}
|
|
560
|
+
};
|
|
561
|
+
if (!source.requestDescriptor || selectedScopeCanRead(scope, workspaceSourceRequestDescriptorPath(source.key))) copyWorkspaceSourceMetadata(source.source, scoped);
|
|
562
|
+
if (scopedLivePaths) markLiveWorkspaceSource(scoped, scopedLivePaths);
|
|
563
|
+
return scoped;
|
|
564
|
+
}
|
|
565
|
+
function syncScopedLivePaths(target, source, scope) {
|
|
566
|
+
if (!target || !source) return;
|
|
567
|
+
for (const path of Object.keys(target)) delete target[path];
|
|
568
|
+
for (const [path, value] of Object.entries(source)) if (selectedScopeCanRead(scope, path)) target[path] = value;
|
|
569
|
+
}
|
|
570
|
+
function sourceItemWorkspacePath(source, sourcePath) {
|
|
571
|
+
const normalized = normalizeWorkspacePath(sourcePath);
|
|
572
|
+
return normalizeWorkspacePath(source.mountPath ? `${source.mountPath}/${normalized}` : normalized);
|
|
573
|
+
}
|
|
574
|
+
function selectedScopeQueryPaths(scope, query) {
|
|
575
|
+
const requestedPaths = (query.paths?.length ? query.paths : [query.cwd || ""]).map((path) => normalizeWorkspacePath(path));
|
|
576
|
+
const scopedPaths = (scope.paths || []).map((path) => normalizeWorkspacePath(path));
|
|
577
|
+
const paths = /* @__PURE__ */ new Set();
|
|
578
|
+
for (const scopedPath of scopedPaths) for (const requestedPath of requestedPaths) if (pathContains(scopedPath, requestedPath)) paths.add(requestedPath);
|
|
579
|
+
else if (pathContains(requestedPath, scopedPath)) paths.add(scopedPath);
|
|
580
|
+
return [...paths];
|
|
581
|
+
}
|
|
582
|
+
function selectedScopeCanRead(scope, path) {
|
|
583
|
+
if (!scope || scope.all) return true;
|
|
584
|
+
const normalized = normalizeWorkspacePath(path);
|
|
585
|
+
return Boolean(scope.paths?.some((prefix) => pathContains(normalizeWorkspacePath(prefix), normalized)));
|
|
586
|
+
}
|
|
587
|
+
function selectedScopeCanSee(scope, path) {
|
|
588
|
+
if (!scope || scope.all) return true;
|
|
589
|
+
const normalized = normalizeWorkspacePath(path);
|
|
590
|
+
return Boolean(scope.paths?.some((prefix) => pathIntersects(normalizeWorkspacePath(prefix), normalized)));
|
|
591
|
+
}
|
|
592
|
+
function filterScopedEntries(scope, entries) {
|
|
593
|
+
return entries.filter((entry) => selectedScopeCanSee(scope, entry.path));
|
|
594
|
+
}
|
|
595
|
+
function filterScopedHits(scope, hits) {
|
|
596
|
+
return hits.filter((hit) => selectedScopeCanRead(scope, hit.path));
|
|
597
|
+
}
|
|
598
|
+
function mergeEntries(base, source) {
|
|
599
|
+
const entries = /* @__PURE__ */ new Map();
|
|
600
|
+
for (const entry of base) entries.set(entry.path, entry);
|
|
601
|
+
for (const entry of source) entries.set(entry.path, entry);
|
|
602
|
+
return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
603
|
+
}
|
|
604
|
+
function mergeHits(base, source) {
|
|
605
|
+
const seen = /* @__PURE__ */ new Set();
|
|
606
|
+
return [...base, ...source].filter((hit) => {
|
|
607
|
+
const key = `${hit.path}:${hit.line}:${hit.column}:${hit.text}`;
|
|
608
|
+
if (seen.has(key)) return false;
|
|
609
|
+
seen.add(key);
|
|
610
|
+
return true;
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
function selectedScopeIntersectsSource(scope, source) {
|
|
614
|
+
if (!scope || scope.all) return true;
|
|
615
|
+
if (scope.sources?.includes(source.key)) return true;
|
|
616
|
+
const sourcePaths = source.requestOnly ? [workspaceSourceRequestDescriptorPath(source.key)] : source.probeKeys?.length ? source.probeKeys.map((key) => [source.mountPath, key].filter(Boolean).join("/")) : [source.mountPath];
|
|
617
|
+
return Boolean(scope.paths?.some((path) => sourcePaths.some((sourcePath) => pathIntersects(path, sourcePath))));
|
|
618
|
+
}
|
|
619
|
+
function pathContains(container, path) {
|
|
620
|
+
return !container || path === container || path.startsWith(`${container}/`);
|
|
621
|
+
}
|
|
622
|
+
function pathIntersects(left, right) {
|
|
623
|
+
return pathContains(left, right) || pathContains(right, left);
|
|
624
|
+
}
|
|
625
|
+
//#endregion
|
|
626
|
+
export { attachWorkspaceSourceRequestExecution, createWorkspaceSourceResolutionFacade, getWorkspaceDependencyRuntimeLoaders, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, getWorkspaceSourceRequestDescriptor, getWorkspaceSourceRequestExecution, hasWorkspaceSourceResolvers, isWorkspaceSourceRequestOnly, markLiveWorkspaceSource, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, resolveWorkspaceSources, setWorkspaceDependencyRuntimeLoaders, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace, workspaceSourceGrantPaths, workspaceSourceRequestDescriptorPath };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
|
+
import { c as normalizeWorkspacePath } from "./path-CNI6wKIU.js";
|
|
3
3
|
//#region src/core/search.ts
|
|
4
4
|
var search_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
searchText: () => searchText,
|