@vite-hub/workspace 0.0.2 → 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 +35 -0
- package/dist/{ai-Cztw4eLk.js → ai-Ce3PtWFW.js} +14 -3
- package/dist/{ai-hFdsvDHC.d.ts → ai-nmHdzjCM.d.ts} +1 -1
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/cloudflare.d.ts +4 -2
- package/dist/cloudflare.js +1 -2
- package/dist/collections.d.ts +2 -2
- package/dist/collections.js +1 -1
- package/dist/{config-Ca5DM8fF.d.ts → config-3I1BnsdO.d.ts} +1 -1
- package/dist/{config-DCQ6y30R.js → config-CDoyls2X.js} +1 -1
- package/dist/{config--r5unwPc.js → config-CZLO0m9h.js} +3 -3
- package/dist/{file-B2q9NE18.js → file-CHfsZpso.js} +7 -8
- package/dist/{files-xy0le-_U.js → files-QRV55OCx.js} +1 -1
- package/dist/{github-lIO6-2sH.js → github-CfA5vpJ5.js} +5 -10
- package/dist/{glob-DeH0dzZX.js → glob-D0vD_wRY.js} +6 -12
- package/dist/{host-I-_vDs05.js → host-CAnbugpI.js} +2 -2
- package/dist/{artifacts-store-BAV9jZpd.js → hosted-C1-tTTTf.js} +29 -3
- package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +26 -4
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +1 -25
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +1 -29
- package/dist/index.d.ts +27 -35
- package/dist/index.js +18 -25
- package/dist/{lifecycle-Lhk3dAMt.js → lifecycle-BYoa9hVb.js} +3 -3
- 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.js +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +1 -1
- package/dist/{provider-CeQciesl.js → provider-C3_elpEh.js} +1 -1
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -361
- package/dist/publish.d.ts +1 -1
- package/dist/publish.js +1 -1
- package/dist/{registry-CoC9JxVt.d.ts → registry-BIQVCBWI.d.ts} +1 -1
- package/dist/{registry-C7DMdBXN.js → registry-CqyDTW9Y.js} +1 -1
- package/dist/{request-execution-C8qRcReq.js → request-execution-u9mgUXKX.js} +1 -1
- package/dist/runtime/assets.d.ts +1 -1
- 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 +3 -3
- package/dist/runtime/state.js +5 -5
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime-options-BsPSv5O7.js +13 -0
- package/dist/runtime.d.ts +5 -5
- package/dist/runtime.js +11 -28
- package/dist/server.d.ts +2 -2
- package/dist/server.js +3 -3
- package/dist/{shared-BRycRSbo.js → shared-jfogBrd5.js} +20 -2
- package/dist/source-metadata.d.ts +1 -1
- package/dist/source-metadata.js +1 -1
- package/dist/{state-DSAHEsq6.d.ts → state-TTqa3x3Y.d.ts} +2 -2
- package/dist/store-Bs1SLh55.js +414 -0
- package/dist/{sync-DO42ypji.js → sync-DiuDmSGk.js} +3 -3
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-DHkae7Cb.d.ts → types-60Yn149G.d.ts} +1 -17
- package/dist/{use-D16tf8Ph.d.ts → use-CUFSnFCS.d.ts} +2 -2
- package/dist/{use-d_PlAdOu.js → use-CsV3oIxH.js} +6 -23
- package/dist/{vite-NWC9mFjI.js → vite-tbfDxtlu.js} +332 -23
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/dist/{workspace-f2DBLmPZ.d.ts → workspace-66SKyiec.d.ts} +1 -1
- package/dist/{workspace-n4wBmdaM.js → workspace-C4k92Ow8.js} +8 -24
- package/package.json +13 -28
- package/dist/cli.d.ts +0 -31
- package/dist/cli.js +0 -303
- package/dist/cloudflare-env-CKxUs2fa.js +0 -20
- package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
- package/dist/providers/cloudflare/artifacts-store.js +0 -2
- package/dist/providers/vercel/blob-store.d.ts +0 -6
- package/dist/utils-BPdaCyI6.js +0 -55
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, n as contentStreamToBytes, o as normalizeSafeWorkspacePath, p as workspaceError, s as normalizeSafeWorkspacePattern } from "./path-CNI6wKIU.js";
|
|
2
|
+
import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
|
+
import { c as readGitHubBlob, d as resolveGitHubBranchOption, h as resolveGitHubTokenOption, i as gitBlobSha, l as readGitHubBranchState, m as resolveGitHubRootOption, n as createGitHubBlob, o as joinGitPath, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "./shared-jfogBrd5.js";
|
|
4
|
+
import { posix } from "node:path";
|
|
5
|
+
//#region src/storage/utils.ts
|
|
6
|
+
async function createCurrentSnapshotFromStore(store, name) {
|
|
7
|
+
return await createSnapshotFromEntries(await store.list("", { recursive: true }), name);
|
|
8
|
+
}
|
|
9
|
+
async function createSnapshotFromEntries(entries, name) {
|
|
10
|
+
const snapshotEntries = {};
|
|
11
|
+
for (const entry of entries) snapshotEntries[entry.path] = {
|
|
12
|
+
digest: entry.digest,
|
|
13
|
+
metadata: entry.metadata,
|
|
14
|
+
size: entry.size,
|
|
15
|
+
type: entry.type
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19
|
+
entries: snapshotEntries,
|
|
20
|
+
id: await sha256({
|
|
21
|
+
entries: snapshotEntries,
|
|
22
|
+
name,
|
|
23
|
+
createdAt: Date.now()
|
|
24
|
+
}),
|
|
25
|
+
name
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function diffSnapshots(from, to) {
|
|
29
|
+
const entries = [];
|
|
30
|
+
const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
|
|
31
|
+
for (const path of [...keys].sort()) {
|
|
32
|
+
const before = from?.entries[path];
|
|
33
|
+
const after = to.entries[path];
|
|
34
|
+
if (!before && after) entries.push({
|
|
35
|
+
path,
|
|
36
|
+
type: "added",
|
|
37
|
+
after
|
|
38
|
+
});
|
|
39
|
+
else if (before && !after) entries.push({
|
|
40
|
+
path,
|
|
41
|
+
type: "removed",
|
|
42
|
+
before
|
|
43
|
+
});
|
|
44
|
+
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({
|
|
45
|
+
path,
|
|
46
|
+
type: "modified",
|
|
47
|
+
before,
|
|
48
|
+
after
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
from: from?.id,
|
|
53
|
+
to: to.id,
|
|
54
|
+
entries
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/providers/github/store.ts
|
|
59
|
+
function isReservedWorkspacePath(path) {
|
|
60
|
+
const root = normalizeWorkspacePath(path).split("/")[0];
|
|
61
|
+
return root === ".git" || root === ".vitehub";
|
|
62
|
+
}
|
|
63
|
+
function contentLength(content) {
|
|
64
|
+
return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
65
|
+
}
|
|
66
|
+
function gitHubFileMetadata(entry) {
|
|
67
|
+
return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
|
|
68
|
+
}
|
|
69
|
+
function gitHubFileMode(metadata) {
|
|
70
|
+
return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
|
|
71
|
+
}
|
|
72
|
+
function inheritedGitHubFileMetadata(file, current) {
|
|
73
|
+
if (file.metadata) return file.metadata;
|
|
74
|
+
return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
|
|
75
|
+
}
|
|
76
|
+
function parentDirectories(path) {
|
|
77
|
+
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
78
|
+
const directories = [];
|
|
79
|
+
for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
|
|
80
|
+
return directories;
|
|
81
|
+
}
|
|
82
|
+
function resolveSymlinkTarget(path, bytes) {
|
|
83
|
+
const target = gitSymlinkTargetFromBytes(bytes);
|
|
84
|
+
if (!target || target.startsWith("/")) return;
|
|
85
|
+
const base = path.split("/").slice(0, -1).join("/");
|
|
86
|
+
const resolved = posix.normalize(base ? `${base}/${target}` : target);
|
|
87
|
+
if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
|
|
88
|
+
return normalizeSafeWorkspacePath(resolved);
|
|
89
|
+
}
|
|
90
|
+
function gitSymlinkTargetFromBytes(bytes) {
|
|
91
|
+
return new TextDecoder().decode(bytes).replace(/\0/g, "");
|
|
92
|
+
}
|
|
93
|
+
var GitHubWorkspaceStore = class {
|
|
94
|
+
workspaceName;
|
|
95
|
+
#baseline;
|
|
96
|
+
#baselineRefSha;
|
|
97
|
+
#baselineTreeSha;
|
|
98
|
+
#branch;
|
|
99
|
+
#dirty = false;
|
|
100
|
+
#files = /* @__PURE__ */ new Map();
|
|
101
|
+
#ready;
|
|
102
|
+
#remoteFiles = /* @__PURE__ */ new Map();
|
|
103
|
+
#repository;
|
|
104
|
+
#root;
|
|
105
|
+
#token;
|
|
106
|
+
constructor(options, workspaceName) {
|
|
107
|
+
this.workspaceName = workspaceName;
|
|
108
|
+
this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
|
|
109
|
+
this.#branch = resolveGitHubBranchOption(options);
|
|
110
|
+
this.#root = resolveGitHubRootOption(options, workspaceName);
|
|
111
|
+
this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
|
|
112
|
+
}
|
|
113
|
+
[workspaceStoreTarget]() {
|
|
114
|
+
return {
|
|
115
|
+
provider: "github",
|
|
116
|
+
branch: this.#branch,
|
|
117
|
+
repository: this.#repository
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async readFile(path) {
|
|
121
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
122
|
+
await this.#ensure({ refresh: true });
|
|
123
|
+
return await this.#readWorkspaceFile(normalized);
|
|
124
|
+
}
|
|
125
|
+
async writeFile(path, file) {
|
|
126
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
127
|
+
await this.#ensure({ refresh: false });
|
|
128
|
+
const current = this.#files.get(normalized);
|
|
129
|
+
const metadata = inheritedGitHubFileMetadata(file, current);
|
|
130
|
+
const content = gitHubFileMode(metadata) === "120000" && typeof metadata?.symlinkTarget === "string" ? metadata.symlinkTarget : file.content;
|
|
131
|
+
const update = await createGitHubFileUpdate(normalized, this.#root, content);
|
|
132
|
+
if (current?.gitSha === update.gitSha) {
|
|
133
|
+
if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
|
|
134
|
+
this.#files.set(normalized, {
|
|
135
|
+
...current,
|
|
136
|
+
mediaType: file.mediaType,
|
|
137
|
+
metadata,
|
|
138
|
+
size: contentLength(content)
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
await createGitHubBlob({
|
|
143
|
+
bytes: update.bytes,
|
|
144
|
+
kind: "store",
|
|
145
|
+
repository: this.#repository,
|
|
146
|
+
token: this.#token
|
|
147
|
+
});
|
|
148
|
+
this.#files.set(normalized, {
|
|
149
|
+
gitSha: update.gitSha,
|
|
150
|
+
mediaType: file.mediaType,
|
|
151
|
+
metadata,
|
|
152
|
+
path: normalized,
|
|
153
|
+
size: contentLength(content)
|
|
154
|
+
});
|
|
155
|
+
this.#dirty = true;
|
|
156
|
+
}
|
|
157
|
+
async writeFileStream(path, file) {
|
|
158
|
+
const content = await contentStreamToBytes(file.content);
|
|
159
|
+
await this.writeFile(path, {
|
|
160
|
+
path: file.path,
|
|
161
|
+
content,
|
|
162
|
+
mediaType: file.mediaType,
|
|
163
|
+
metadata: file.metadata
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
digest: await gitBlobSha(content),
|
|
167
|
+
mediaType: file.mediaType,
|
|
168
|
+
path: normalizeSafeWorkspacePath(path),
|
|
169
|
+
size: content.byteLength,
|
|
170
|
+
type: "file"
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
async list(prefix = "", options = {}) {
|
|
174
|
+
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
175
|
+
await this.#ensure({ refresh: true });
|
|
176
|
+
return await this.#listEntries(normalizedPrefix, options);
|
|
177
|
+
}
|
|
178
|
+
async glob(pattern, _options = {}) {
|
|
179
|
+
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
180
|
+
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
|
|
181
|
+
}
|
|
182
|
+
async stat(path) {
|
|
183
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
184
|
+
await this.#ensure({ refresh: true });
|
|
185
|
+
const file = this.#files.get(normalized);
|
|
186
|
+
if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
|
|
187
|
+
if (this.#directoryExists(normalized)) return {
|
|
188
|
+
path: normalized,
|
|
189
|
+
type: "directory"
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
async mkdir(path, _options = {}) {
|
|
193
|
+
normalizeSafeWorkspacePath(path);
|
|
194
|
+
}
|
|
195
|
+
async rm(path, options = {}) {
|
|
196
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
197
|
+
await this.#ensure({ refresh: false });
|
|
198
|
+
if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
|
|
199
|
+
this.#files.delete(normalized);
|
|
200
|
+
this.#dirty = true;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const children = this.#publicDescendants(normalized);
|
|
204
|
+
if (!(children.length > 0)) {
|
|
205
|
+
if (options.force) return;
|
|
206
|
+
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
207
|
+
}
|
|
208
|
+
if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
209
|
+
for (const child of children) this.#files.delete(child);
|
|
210
|
+
this.#dirty = true;
|
|
211
|
+
}
|
|
212
|
+
async snapshot(options = {}) {
|
|
213
|
+
await this.#ensure({ refresh: false });
|
|
214
|
+
const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
|
|
215
|
+
if (!this.#dirty) {
|
|
216
|
+
this.#baseline = snapshot;
|
|
217
|
+
return snapshot;
|
|
218
|
+
}
|
|
219
|
+
const remote = await readGitHubBranchState({
|
|
220
|
+
branch: this.#branch,
|
|
221
|
+
kind: "store",
|
|
222
|
+
repository: this.#repository,
|
|
223
|
+
root: this.#root,
|
|
224
|
+
token: this.#token
|
|
225
|
+
});
|
|
226
|
+
if (this.#baselineRefSha && remote.refSha !== this.#baselineRefSha) throw workspaceError(`[vitehub] GitHub Workspace Store conflict for ${this.#repository}@${this.#branch}: the branch changed after this Workspace Store loaded. Snapshotting requires a Workspace Store loaded from the current branch head.`);
|
|
227
|
+
this.#remoteFiles = remote.files;
|
|
228
|
+
this.#baselineRefSha = remote.refSha;
|
|
229
|
+
this.#baselineTreeSha = remote.treeSha;
|
|
230
|
+
const changedFiles = [...this.#files.values()].filter((file) => {
|
|
231
|
+
const remote = this.#remoteFiles.get(file.path);
|
|
232
|
+
return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
|
|
233
|
+
});
|
|
234
|
+
const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
|
|
235
|
+
if (!changedFiles.length && !deletePaths.length) {
|
|
236
|
+
this.#dirty = false;
|
|
237
|
+
this.#baseline = snapshot;
|
|
238
|
+
return snapshot;
|
|
239
|
+
}
|
|
240
|
+
const files = changedFiles.map((file) => {
|
|
241
|
+
return {
|
|
242
|
+
bytes: file.bytes,
|
|
243
|
+
fullPath: joinGitPath(this.#root, file.path),
|
|
244
|
+
gitSha: file.gitSha,
|
|
245
|
+
mode: gitHubFileMode(file.metadata)
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
const commit = await commitGitHubChanges({
|
|
249
|
+
baseTreeSha: this.#baselineTreeSha,
|
|
250
|
+
branch: this.#branch,
|
|
251
|
+
branchExists: remote.branchExists,
|
|
252
|
+
deletePaths,
|
|
253
|
+
files,
|
|
254
|
+
message: options.name || "chore: update workspace snapshot",
|
|
255
|
+
parentSha: this.#baselineRefSha,
|
|
256
|
+
repository: this.#repository,
|
|
257
|
+
token: this.#token
|
|
258
|
+
});
|
|
259
|
+
this.#dirty = false;
|
|
260
|
+
this.#baselineRefSha = commit.commitSha;
|
|
261
|
+
this.#baselineTreeSha = commit.treeSha;
|
|
262
|
+
this.#remoteFiles = this.#toRemoteFiles();
|
|
263
|
+
this.#baseline = {
|
|
264
|
+
...snapshot,
|
|
265
|
+
id: commit.commitSha
|
|
266
|
+
};
|
|
267
|
+
return this.#baseline;
|
|
268
|
+
}
|
|
269
|
+
async diff(options = {}) {
|
|
270
|
+
await this.#ensure({ refresh: true });
|
|
271
|
+
return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
|
|
272
|
+
}
|
|
273
|
+
async getMeta(key) {
|
|
274
|
+
await this.#ensure({ refresh: true });
|
|
275
|
+
const file = await this.#readWorkspaceFile(this.#metaPath(key));
|
|
276
|
+
if (!file) return void 0;
|
|
277
|
+
return JSON.parse(new TextDecoder().decode(file.bytes));
|
|
278
|
+
}
|
|
279
|
+
async setMeta(key, value) {
|
|
280
|
+
const path = this.#metaPath(key);
|
|
281
|
+
const content = JSON.stringify(value);
|
|
282
|
+
const bytes = new TextEncoder().encode(content);
|
|
283
|
+
await this.#ensure({ refresh: false });
|
|
284
|
+
this.#files.set(path, {
|
|
285
|
+
bytes,
|
|
286
|
+
gitSha: await gitBlobSha(bytes),
|
|
287
|
+
path,
|
|
288
|
+
size: bytes.byteLength
|
|
289
|
+
});
|
|
290
|
+
this.#dirty = true;
|
|
291
|
+
}
|
|
292
|
+
async #ensure(options) {
|
|
293
|
+
const wasReady = !!this.#ready;
|
|
294
|
+
this.#ready ||= this.#load();
|
|
295
|
+
await this.#ready;
|
|
296
|
+
if (wasReady && options.refresh && !this.#dirty) await this.#load();
|
|
297
|
+
}
|
|
298
|
+
async #load() {
|
|
299
|
+
const remote = await readGitHubBranchState({
|
|
300
|
+
branch: this.#branch,
|
|
301
|
+
kind: "store",
|
|
302
|
+
repository: this.#repository,
|
|
303
|
+
root: this.#root,
|
|
304
|
+
token: this.#token
|
|
305
|
+
});
|
|
306
|
+
this.#baselineRefSha = remote.refSha;
|
|
307
|
+
this.#baselineTreeSha = remote.treeSha;
|
|
308
|
+
this.#remoteFiles = remote.files;
|
|
309
|
+
if (!this.#dirty) {
|
|
310
|
+
this.#files = new Map([...remote.files].map(([path, entry]) => [path, {
|
|
311
|
+
gitSha: entry.sha,
|
|
312
|
+
metadata: gitHubFileMetadata(entry),
|
|
313
|
+
path,
|
|
314
|
+
size: entry.size
|
|
315
|
+
}]));
|
|
316
|
+
this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), "github-workspace-store-load");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
|
|
320
|
+
const current = this.#files.get(path);
|
|
321
|
+
if (!current) return void 0;
|
|
322
|
+
const currentBytes = await this.#readFileBytes(current);
|
|
323
|
+
if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
|
|
324
|
+
const target = resolveSymlinkTarget(path, currentBytes);
|
|
325
|
+
if (target && this.#files.has(target)) {
|
|
326
|
+
seen.add(path);
|
|
327
|
+
const resolved = await this.#readWorkspaceFile(target, seen);
|
|
328
|
+
if (resolved) return {
|
|
329
|
+
...resolved,
|
|
330
|
+
mediaType: current.mediaType ?? resolved.mediaType,
|
|
331
|
+
metadata: await this.#fileMetadata(current) ?? resolved.metadata,
|
|
332
|
+
path
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
content: currentBytes,
|
|
338
|
+
bytes: currentBytes,
|
|
339
|
+
mediaType: current.mediaType,
|
|
340
|
+
metadata: await this.#fileMetadata(current),
|
|
341
|
+
path
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
async #readFileBytes(file) {
|
|
345
|
+
if (!file.bytes) {
|
|
346
|
+
file.bytes = await readGitHubBlob({
|
|
347
|
+
kind: "store",
|
|
348
|
+
repository: this.#repository,
|
|
349
|
+
sha: file.gitSha,
|
|
350
|
+
token: this.#token
|
|
351
|
+
});
|
|
352
|
+
file.size = file.bytes.byteLength;
|
|
353
|
+
}
|
|
354
|
+
return file.bytes;
|
|
355
|
+
}
|
|
356
|
+
async #fileMetadata(file) {
|
|
357
|
+
if (gitHubFileMode(file.metadata) !== "120000" || typeof file.metadata?.symlinkTarget === "string") return file.metadata;
|
|
358
|
+
return {
|
|
359
|
+
...file.metadata,
|
|
360
|
+
symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
async #listEntries(prefix, options) {
|
|
364
|
+
const entries = /* @__PURE__ */ new Map();
|
|
365
|
+
for (const file of this.#files.values()) {
|
|
366
|
+
if (isReservedWorkspacePath(file.path)) continue;
|
|
367
|
+
for (const dir of parentDirectories(file.path)) if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
|
|
368
|
+
path: dir,
|
|
369
|
+
type: "directory"
|
|
370
|
+
});
|
|
371
|
+
if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file));
|
|
372
|
+
}
|
|
373
|
+
return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
374
|
+
}
|
|
375
|
+
#entryInPrefix(path, prefix, options) {
|
|
376
|
+
if (!prefix) return options.recursive || !path.includes("/");
|
|
377
|
+
if (path === prefix) return false;
|
|
378
|
+
if (!path.startsWith(`${prefix}/`)) return false;
|
|
379
|
+
return options.recursive || !path.slice(prefix.length + 1).includes("/");
|
|
380
|
+
}
|
|
381
|
+
async #fileEntry(file) {
|
|
382
|
+
return {
|
|
383
|
+
digest: file.gitSha,
|
|
384
|
+
mediaType: file.mediaType,
|
|
385
|
+
metadata: await this.#fileMetadata(file),
|
|
386
|
+
path: file.path,
|
|
387
|
+
size: file.size,
|
|
388
|
+
type: "file"
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
#directoryExists(path) {
|
|
392
|
+
return this.#publicDescendants(path).length > 0;
|
|
393
|
+
}
|
|
394
|
+
#publicDescendants(path) {
|
|
395
|
+
return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
|
|
396
|
+
}
|
|
397
|
+
#metaPath(key) {
|
|
398
|
+
return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
|
|
399
|
+
}
|
|
400
|
+
#toRemoteFiles() {
|
|
401
|
+
return new Map([...this.#files.values()].map((file) => [file.path, {
|
|
402
|
+
path: joinGitPath(this.#root, file.path),
|
|
403
|
+
sha: file.gitSha,
|
|
404
|
+
size: file.size,
|
|
405
|
+
type: "blob",
|
|
406
|
+
mode: gitHubFileMode(file.metadata)
|
|
407
|
+
}]));
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
function createGitHubWorkspaceStore(options, workspaceName) {
|
|
411
|
+
return new GitHubWorkspaceStore(options, workspaceName);
|
|
412
|
+
}
|
|
413
|
+
//#endregion
|
|
414
|
+
export { diffSnapshots as i, createCurrentSnapshotFromStore as n, createSnapshotFromEntries as r, createGitHubWorkspaceStore as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as sha256, n as contentStreamToBytes, p as workspaceError } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { a as normalizeWorkspaceSources, n as createSourceContext, s as sourceMountContainsPath } from "./config
|
|
3
|
-
import { a as sourceSyncMetaKey, c as normalizeSourceItemPath, i as readWorkspaceSourceSyncState, o as workspaceSourceSyncStateEquals } from "./workspace-
|
|
2
|
+
import { a as normalizeWorkspaceSources, n as createSourceContext, s as sourceMountContainsPath } from "./config-CZLO0m9h.js";
|
|
3
|
+
import { a as sourceSyncMetaKey, c as normalizeSourceItemPath, i as readWorkspaceSourceSyncState, o as workspaceSourceSyncStateEquals } from "./workspace-C4k92Ow8.js";
|
|
4
4
|
//#region src/sources/sync.ts
|
|
5
5
|
const sourceSyncLocks = /* @__PURE__ */ new Map();
|
|
6
6
|
function zeroCounts() {
|
|
@@ -177,7 +177,7 @@ async function snapshotSyncedWorkspace(definition, store, options) {
|
|
|
177
177
|
const snapshotOptions = typeof options.snapshot === "object" ? options.snapshot : {};
|
|
178
178
|
const snapshot = await store.snapshot(normalizeSnapshotOptions(snapshotOptions));
|
|
179
179
|
if (options.publish) {
|
|
180
|
-
const { publishWorkspaceSnapshot } = await import("./lifecycle-
|
|
180
|
+
const { publishWorkspaceSnapshot } = await import("./lifecycle-BYoa9hVb.js").then((n) => n.t);
|
|
181
181
|
await publishWorkspaceSnapshot(definition, store, snapshot);
|
|
182
182
|
}
|
|
183
183
|
return snapshot;
|
package/dist/test.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as registerWorkspace } from "./registry-
|
|
1
|
+
import { n as registerWorkspace } from "./registry-BIQVCBWI.js";
|
|
2
2
|
export { registerWorkspace };
|
package/dist/test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as registerWorkspace } from "./registry-
|
|
1
|
+
import { n as registerWorkspace } from "./registry-CqyDTW9Y.js";
|
|
2
2
|
export { registerWorkspace };
|
|
@@ -145,21 +145,6 @@ interface WorkspaceSessionHost {
|
|
|
145
145
|
stdout: string;
|
|
146
146
|
}>;
|
|
147
147
|
}
|
|
148
|
-
type WorkspaceMountMode = "read-only" | "read-write" | "copy-on-write";
|
|
149
|
-
interface WorkspaceMountOptions {
|
|
150
|
-
mode: WorkspaceMountMode;
|
|
151
|
-
target?: string;
|
|
152
|
-
}
|
|
153
|
-
interface WorkspaceMount {
|
|
154
|
-
workspace: Workspace;
|
|
155
|
-
mode: WorkspaceMountMode;
|
|
156
|
-
target: string;
|
|
157
|
-
diff(): Promise<WorkspaceDiff>;
|
|
158
|
-
commit(options?: {
|
|
159
|
-
message?: string;
|
|
160
|
-
}): Promise<void>;
|
|
161
|
-
export(): Promise<WorkspaceSnapshot>;
|
|
162
|
-
}
|
|
163
148
|
interface ExecOptions {
|
|
164
149
|
abortSignal?: AbortSignal;
|
|
165
150
|
cwd?: string;
|
|
@@ -553,7 +538,6 @@ interface Workspace {
|
|
|
553
538
|
snapshot(options?: SnapshotOptions): Promise<WorkspaceSnapshot>;
|
|
554
539
|
diff(options?: DiffOptions): Promise<WorkspaceDiff>;
|
|
555
540
|
startSession(options?: WorkspaceSessionOptions): Promise<WorkspaceSession>;
|
|
556
|
-
mount(options?: WorkspaceMountOptions): WorkspaceMount;
|
|
557
541
|
}
|
|
558
542
|
interface WorkspaceSourceSyncCounts {
|
|
559
543
|
added: number;
|
|
@@ -625,4 +609,4 @@ interface WorkspaceMaterializeSourcesResult {
|
|
|
625
609
|
sources: WorkspaceSourceMaterializationStatus[];
|
|
626
610
|
}
|
|
627
611
|
//#endregion
|
|
628
|
-
export { WorkspaceMaterializeSourcesProgressEvent as $,
|
|
612
|
+
export { WorkspaceMaterializeSourcesProgressEvent as $, WorkspaceSyncSnapshotOptions as $t, WorkspaceCacheOptions as A, WorkspaceSourceRequestExecutionInput as At, WorkspaceFetchSourceRequestOptions as B, WorkspaceSourceSelection as Bt, SourceContextWorkspaceFiles as C, WorkspaceSourceDefinition as Ct, WorkspaceAssets as D, WorkspaceSourceMount as Dt, WorkspaceAssetPath as E, WorkspaceSourceMaterializationStatus as Et, WorkspaceDefinitionInput as F, WorkspaceSourceResolutionContextMap as Ft, WorkspaceHookContext as G, WorkspaceSourceSyncResult as Gt, WorkspaceFileSourceInput as H, WorkspaceSourceSyncCounts as Ht, WorkspaceDiff as I, WorkspaceSourceResolutionContextValueReader as It, WorkspaceInstructionBindingValue as J, WorkspaceStore as Jt, WorkspaceHooks as K, WorkspaceSourceSyncStatus as Kt, WorkspaceDiffEntry as L, WorkspaceSourceResolutionInvocation as Lt, WorkspaceContentStream as M, WorkspaceSourceRequestExecutor as Mt, WorkspaceCustomSourceInput as N, WorkspaceSourceRequestMethod as Nt, WorkspaceAssetsRegistry as O, WorkspaceSourceMountOptions as Ot, WorkspaceDefinition as P, WorkspaceSourceResolutionContext as Pt, WorkspaceMaterializeSourcesOptions as Q, WorkspaceSyncResultDetails as Qt, WorkspaceEntry as R, WorkspaceSourceResolutionResult as Rt, SourceContext as S, WorkspaceSourceBindingInput as St, Workspace as T, WorkspaceSourceItem as Tt, WorkspaceGitHubSourceInput as U, WorkspaceSourceSyncPathResult as Ut, WorkspaceFile as V, WorkspaceSourceSyncConfig as Vt, WorkspaceGlobSourceInput as W, WorkspaceSourceSyncPolicy as Wt, WorkspaceLoaderSource as X, WorkspaceStreamFile as Xt, WorkspaceLoader as Y, WorkspaceStoreOptions as Yt, WorkspaceMaterializeMode as Z, WorkspaceSyncOptions as Zt, ReadFileResult as _, WorkspaceSessionHostFileEntry as _t, GitHubWorkspaceOption as a, WorkspaceWriteOperation as an, WorkspacePlugin as at, RmOptions as b, WorkspaceSnapshot as bt, ListOptions as c, WriteFileOptions as cn, WorkspacePublisher as ct, Logger as d, WorkspaceScopeName as dt, WorkspaceValidateMode as en, WorkspaceMaterializeSourcesResult as et, MaybePromise as f, WorkspaceSearchHit as ft, ReadFileOptions as g, WorkspaceSessionHost as gt, PublishContext as h, WorkspaceSession as ht, ExecResult as i, WorkspaceWriteMode as in, WorkspaceNameMap as it, WorkspaceContent as j, WorkspaceSourceRequestExecutionResult as jt, WorkspaceAutoCommitPlan as k, WorkspaceSourceRequestDescriptor as kt, LoaderContext as l, WorkspaceRule as lt, MkdirOptions as m, WorkspaceSelectedScope as mt, DiffOptions as n, WorkspaceWriteHook as nn, WorkspaceModuleOptions as nt, GitHubWorkspaceStoreOptions as o, WorkspaceWriteValidator as on, WorkspacePrepareSessionProgressEvent as ot, MemoryWorkspaceStoreOptions as p, WorkspaceSearchQuery as pt, WorkspaceInstructionBinding as q, WorkspaceStat as qt, ExecOptions as r, WorkspaceWriteInput as rn, WorkspaceName as rt, GlobOptions as s, WorkspaceWriteValidatorResult as sn, WorkspacePublishOptions as st, CloudflareArtifactsWorkspaceStoreOptions as t, WorkspaceWriteErrorHook as tn, WorkspaceMcpResourcesSourceInput as tt, LocalWorkspaceStoreOptions as u, WorkspaceRules as ut, ResolvedWorkspaceModuleOptions as v, WorkspaceSessionHostFiles as vt, VercelBlobWorkspaceStoreOptions as w, WorkspaceSourceInput as wt, SnapshotOptions as x, WorkspaceSource as xt, ResolvedWorkspaceRule as y, WorkspaceSessionOptions as yt, WorkspaceFetchSourceInput as z, WorkspaceSourceResolver as zt };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as WorkspaceReadOperations, d as WorkspaceWriteToolMap, n as ShellEnabled, o as WorkspaceShellResult, u as WorkspaceWriteOperations } from "./ai-
|
|
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
3
|
import { Tool, ToolSet } from "ai";
|
|
4
4
|
|
|
5
5
|
//#region src/core/use.d.ts
|
|
@@ -1,10 +1,10 @@
|
|
|
1
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-
|
|
3
|
-
import { r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-
|
|
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
4
|
import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
5
5
|
import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
|
|
6
|
-
import { t as createWorkspace } from "./workspace-
|
|
7
|
-
import { a as useRegisteredWorkspace } from "./registry-
|
|
6
|
+
import { t as createWorkspace } from "./workspace-C4k92Ow8.js";
|
|
7
|
+
import { a as useRegisteredWorkspace } from "./registry-CqyDTW9Y.js";
|
|
8
8
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
9
9
|
//#region src/core/use.ts
|
|
10
10
|
function normalizePath(path, allowEmpty = false) {
|
|
@@ -56,7 +56,7 @@ function createLazyWorkspace(name, definition) {
|
|
|
56
56
|
await syncPromise;
|
|
57
57
|
return workspace;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
return attachWorkspaceSourceRequestExecution({
|
|
60
60
|
name,
|
|
61
61
|
async [workspaceStoreTarget]() {
|
|
62
62
|
return await (await resolveWorkspace())[workspaceStoreTarget]?.();
|
|
@@ -121,25 +121,8 @@ function createLazyWorkspace(name, definition) {
|
|
|
121
121
|
},
|
|
122
122
|
async startSession(options) {
|
|
123
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
124
|
}
|
|
141
|
-
}
|
|
142
|
-
return attachWorkspaceSourceRequestExecution(workspace, { async executeSourceRequest(input) {
|
|
125
|
+
}, { async executeSourceRequest(input) {
|
|
143
126
|
const executor = getWorkspaceSourceRequestExecution(await resolveSyncedWorkspace());
|
|
144
127
|
if (!executor) throw new Error("[vitehub] No API-backed Source request executor is available for this workspace.");
|
|
145
128
|
return await executor.executeSourceRequest(input);
|