@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.
- package/README.md +190 -17
- package/dist/{ai-Bk3LLnit.js → ai-Cztw4eLk.js} +149 -29
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +2 -85
- package/dist/ai.js +1 -1
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +303 -0
- package/dist/cloudflare-env-CKxUs2fa.js +20 -0
- package/dist/cloudflare.d.ts +16 -0
- package/dist/cloudflare.js +3 -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--r5unwPc.js +7811 -0
- package/dist/config-Ca5DM8fF.d.ts +28 -0
- package/dist/config-DCQ6y30R.js +30 -0
- package/dist/file-B2q9NE18.js +24 -0
- package/dist/{files-DbsIjBya.js → files-xy0le-_U.js} +6 -5
- package/dist/github-lIO6-2sH.js +194 -0
- package/dist/glob-DeH0dzZX.js +23 -0
- package/dist/host-I-_vDs05.js +370 -0
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +26 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +30 -0
- package/dist/index.d.ts +137 -102
- package/dist/index.js +479 -594
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- 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-CeQciesl.js} +142 -37
- package/dist/providers/cloudflare/artifacts-store.d.ts +1 -1
- package/dist/providers/cloudflare/artifacts-store.js +1 -383
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +362 -0
- package/dist/providers/vercel/blob-store.d.ts +1 -1
- package/dist/providers/vercel/blob-store.js +77 -18
- package/dist/publish.d.ts +3 -2
- package/dist/publish.js +48 -142
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/{registry-D4Qzq26I.d.ts → registry-CoC9JxVt.d.ts} +3 -2
- package/dist/request-execution-C8qRcReq.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.d.ts +38 -0
- package/dist/runtime.js +643 -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-BRycRSbo.js +255 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-DSAHEsq6.d.ts +25 -0
- package/dist/sync-DO42ypji.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-DHkae7Cb.d.ts +628 -0
- package/dist/use-D16tf8Ph.d.ts +86 -0
- package/dist/use-d_PlAdOu.js +353 -0
- package/dist/{utils-BtAm_K5P.js → utils-BPdaCyI6.js} +7 -3
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +33 -5
- package/dist/vite.js +2 -131
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +158 -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/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/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
|
@@ -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 };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as sha256 } from "./path-CNI6wKIU.js";
|
|
2
2
|
//#region src/storage/utils.ts
|
|
3
|
+
async function createCurrentSnapshotFromStore(store, name) {
|
|
4
|
+
return await createSnapshotFromEntries(await store.list("", { recursive: true }), name);
|
|
5
|
+
}
|
|
3
6
|
async function createSnapshotFromEntries(entries, name) {
|
|
4
7
|
const snapshotEntries = {};
|
|
5
8
|
for (const entry of entries) snapshotEntries[entry.path] = {
|
|
6
9
|
digest: entry.digest,
|
|
10
|
+
metadata: entry.metadata,
|
|
7
11
|
size: entry.size,
|
|
8
12
|
type: entry.type
|
|
9
13
|
};
|
|
@@ -34,7 +38,7 @@ function diffSnapshots(from, to) {
|
|
|
34
38
|
type: "removed",
|
|
35
39
|
before
|
|
36
40
|
});
|
|
37
|
-
else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size)) entries.push({
|
|
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({
|
|
38
42
|
path,
|
|
39
43
|
type: "modified",
|
|
40
44
|
before,
|
|
@@ -48,4 +52,4 @@ function diffSnapshots(from, to) {
|
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
54
|
//#endregion
|
|
51
|
-
export {
|
|
55
|
+
export { createSnapshotFromEntries as n, diffSnapshots as r, createCurrentSnapshotFromStore as t };
|