@vite-hub/workspace 0.6.1 → 0.7.0
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 +5 -5
- package/dist/{asset-registry-0CdRAjIV.js → asset-registry-DJyE42kr.js} +1 -1
- package/dist/blob-database.d.ts +1 -1
- package/dist/blob-database.js +6 -6
- package/dist/checkout.js +2 -2
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/{config-jo5QgE1w.js → config--ZzAvhMp.js} +14 -9
- package/dist/{config-DeA287c0.d.ts → config-DF6sqKXB.d.ts} +1 -1
- package/dist/durability.d.ts +1 -1
- package/dist/durability.js +2 -2
- package/dist/{error-diagnostics-B4me-ouV.js → error-diagnostics-CHgE8TQM.js} +16 -0
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{file-BrNAXQgY.js → file-DQ5-TBTD.js} +1 -1
- package/dist/{file-metadata-Bpsvjw_X.js → file-metadata-Dqpldj0h.js} +7 -2
- package/dist/{files--z2dLC5z.js → files-D1UkSjzX.js} +2 -2
- package/dist/files.d.ts +5 -5
- package/dist/files.js +5 -5
- package/dist/{github-k--_LCrX.js → github-BECfOMaw.js} +4 -4
- package/dist/{glob-BreFjNAV.js → glob-BIg9O4yY.js} +2 -2
- package/dist/{glob-BEutagp1.js → glob-BIsxLusH.js} +1 -1
- package/dist/{host-C8yZizfk.js → host-BYBRcSnh.js} +7 -7
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +464 -1
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +917 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +13 -13
- package/dist/internal/path.js +108 -1
- package/dist/internal/workspace.d.ts +2 -3
- package/dist/internal/workspace.js +2 -2
- package/dist/{lifecycle-IReZfi0b.js → lifecycle-BK7WNfcP.js} +8 -8
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +2 -2
- package/dist/{mcp-resources-DeJnbOaw.js → mcp-resources-F4SJF4_P.js} +2 -2
- package/dist/{memory-BlSRrBH1.js → memory-BCZl_ZsJ.js} +26 -4
- package/dist/{metadata-target-CaGLY4ay.js → metadata-target-DPGF6L68.js} +59 -24
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-BALFFdKj.d.ts} +1 -0
- package/dist/{operations-BIaK_uYG.js → operations-DJ_7W0gs.js} +8 -7
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +1327 -2
- package/dist/{path-Bb9OIc_F.js → path-DYHw5KNk.js} +11 -3
- package/dist/plugins-BYxsPDBH.d.ts +12 -0
- package/dist/{provider-CN14ewvx.js → provider-fcI7kJ5k.js} +256 -70
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1994 -1
- package/dist/{registry-BbUg9vJB.js → registry-CFeUQsja.js} +3 -3
- package/dist/{registry-B0g19sdy.d.ts → registry-h1-cT-cE.d.ts} +1 -1
- package/dist/{registry-s2Ob9PeX.d.ts → registry-hnARUKNF.d.ts} +2 -2
- package/dist/replacement-CVZVsflC.js +76 -0
- package/dist/{request-scope-CXCI_wCb.js → request-scope-jH4H0Sbm.js} +3 -1
- package/dist/{rule-keys-BLEbi1h5.js → rule-keys-xMpiTLq1.js} +1 -1
- package/dist/{rules-BPDXypZV.js → rules-DYQCKYdt.js} +4 -4
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +4 -4
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +1 -1
- package/dist/runtime/request.js +1 -1
- package/dist/runtime/state.d.ts +17 -6
- package/dist/runtime/state.js +7 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +38 -23
- package/dist/{search-C_nVorq7.js → search-CG6UNOtn.js} +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +301 -1
- package/dist/{shared-C20Wh1mp.js → shared-PFnkYidS.js} +59 -21
- package/dist/source-metadata.d.ts +2 -2
- package/dist/source-metadata.js +3 -3
- package/dist/{sync-BBfR4g5y.js → sync-CUkCuP_g.js} +5 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-Bel5IDmF.d.ts → types-BnSUug2v.d.ts} +13 -1
- package/dist/{use-D0DyTMxM.js → use-BCMkT-kC.js} +15 -51
- package/dist/{use-CpphIBof.d.ts → use-CJ5rdIrW.d.ts} +1 -1
- package/dist/{use-tools-CHduR5k6.js → use-tools-CcXs2hFA.js} +4 -4
- package/dist/{use-tools-CAK10LTc.d.ts → use-tools-DFVqZwgc.d.ts} +2 -2
- package/dist/{utils-DXP9xfXo.js → utils-Bv1NBg8r.js} +5 -5
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +368 -62
- package/dist/{workspace-BOuxrZrP.d.ts → workspace-B6QreLJd.d.ts} +1 -1
- package/dist/{workspace-CLuPkyZR.js → workspace-D1m00MCM.js} +340 -104
- package/dist/workspace-inspection-scanner-BlJ8bCAB.js +140 -0
- package/package.json +12 -12
- package/dist/errors-CnFDXxeJ.d.ts +0 -4
- package/dist/hosted-8BTKAtMX.js +0 -883
- package/dist/hosted-vercel-blob-B6kygYqn.js +0 -408
- package/dist/operations-DS1C4uXd.js +0 -1308
- package/dist/path-CuYE8-X6.js +0 -57
- package/dist/plugins-CLc32jvL.d.ts +0 -8
- package/dist/server-aa1a4rkV.js +0 -301
- package/dist/state-BdDfBtOR.d.ts +0 -17
- package/dist/store-cx3OqNTi.js +0 -1971
package/dist/server.js
CHANGED
|
@@ -1 +1,301 @@
|
|
|
1
|
-
|
|
1
|
+
import { s as matchesAny } from "./path-DYHw5KNk.js";
|
|
2
|
+
import { normalizeSafeWorkspacePath } from "./internal/path.js";
|
|
3
|
+
import { i as workspaceDefinitionPlugins, n as resolveWorkspaceAutoCommit } from "./rules-DYQCKYdt.js";
|
|
4
|
+
import { r as useWorkspaceFiles } from "./use-BCMkT-kC.js";
|
|
5
|
+
import { r as withWorkspaceProgress } from "./host-BYBRcSnh.js";
|
|
6
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CHgE8TQM.js";
|
|
7
|
+
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
8
|
+
import { lookup } from "mrmime";
|
|
9
|
+
// ../internal/src/secret.ts
|
|
10
|
+
const secretEncoder = new TextEncoder();
|
|
11
|
+
/**
|
|
12
|
+
* Compares a request value with an expected secret in constant time for the length of `expected`. Returns `false`
|
|
13
|
+
* when either value is missing or empty. It uses no Node API, so it also runs in Worker runtimes.
|
|
14
|
+
*/
|
|
15
|
+
function isViteHubSecretEqual(actual, expected) {
|
|
16
|
+
if (!actual || !expected) return false;
|
|
17
|
+
const left = secretEncoder.encode(actual);
|
|
18
|
+
const right = secretEncoder.encode(expected);
|
|
19
|
+
let difference = left.length ^ right.length;
|
|
20
|
+
for (let index = 0; index < right.length; index += 1) difference |= (left[index] ?? 0) ^ right[index];
|
|
21
|
+
return difference === 0;
|
|
22
|
+
}
|
|
23
|
+
Object.freeze({ prefix: "sha256=" });
|
|
24
|
+
// src/server.ts
|
|
25
|
+
const workspaceDevRoute = "/__vitehub/workspace/dev";
|
|
26
|
+
const workspaceDevHeader = "x-vitehub-workspace-dev";
|
|
27
|
+
const workspaceDevHeaderValue = "1";
|
|
28
|
+
const workspaceDevTokenHeader = "x-vitehub-dev-token";
|
|
29
|
+
function hasWorkspaceCommitRules(definition) {
|
|
30
|
+
return [...Object.values(definition.rules || {}), ...workspaceDefinitionPlugins(definition).flatMap((plugin) => Object.values(plugin.rules || {}))].some((rule) => rule.commit !== void 0);
|
|
31
|
+
}
|
|
32
|
+
const workspaceDevTokensKey = Symbol.for("vitehub.workspace.devTokens");
|
|
33
|
+
function workspaceDevTokens() {
|
|
34
|
+
const scope = globalThis;
|
|
35
|
+
scope[workspaceDevTokensKey] ??= /* @__PURE__ */ new Map();
|
|
36
|
+
return scope[workspaceDevTokensKey];
|
|
37
|
+
}
|
|
38
|
+
function workspaceDevTokenServerId(port) {
|
|
39
|
+
return `${process.pid}:${port ?? "unknown"}`;
|
|
40
|
+
}
|
|
41
|
+
async function workspaceDevTokenRoot(rootDir, options = {}) {
|
|
42
|
+
const [{ createHash }, { tmpdir }, { join, resolve }] = await Promise.all([
|
|
43
|
+
import("node:crypto"),
|
|
44
|
+
import("node:os"),
|
|
45
|
+
import("node:path")
|
|
46
|
+
]);
|
|
47
|
+
const resolvedRoot = resolve(rootDir);
|
|
48
|
+
const rootKey = createHash("sha256").update(resolvedRoot).digest("hex");
|
|
49
|
+
const serverKey = createHash("sha256").update(options.serverId || "default").digest("hex");
|
|
50
|
+
return {
|
|
51
|
+
file: join(tmpdir(), "vitehub-workspace-dev", rootKey, serverKey, "dev-token"),
|
|
52
|
+
key: `${rootKey}:${serverKey}`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function headerValue(headers, name, expectedToken) {
|
|
56
|
+
try {
|
|
57
|
+
const prototype = Object.getPrototypeOf(headers);
|
|
58
|
+
const constructor = prototype ? Object.getOwnPropertyDescriptor(prototype, "constructor")?.value : void 0;
|
|
59
|
+
const constructorSource = typeof constructor === "function" ? Function.prototype.toString.call(constructor) : "";
|
|
60
|
+
const prototypeGet = prototype ? Object.getOwnPropertyDescriptor(prototype, "get")?.value : void 0;
|
|
61
|
+
const realmHeaders = typeof Headers === "function" ? Headers : void 0;
|
|
62
|
+
if (typeof constructor === "function" && Reflect.get(constructor, "name") === "Headers" && (constructor === realmHeaders || /^class\s+Headers\b/.test(constructorSource) && constructorSource.includes("#") || /^function\s+Headers\(\)\s*\{\s*\[native code\]\s*\}$/.test(constructorSource) || constructorSource.includes("webidl.brandCheck") || constructorSource.includes("#")) && Reflect.get(constructor, "prototype") === prototype && (() => {
|
|
63
|
+
try {
|
|
64
|
+
return headers instanceof constructor;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
})() && typeof prototypeGet === "function") {
|
|
69
|
+
const get = typeof Headers === "function" ? Reflect.get(Headers.prototype, "get") : void 0;
|
|
70
|
+
for (const getter of [get, prototypeGet]) {
|
|
71
|
+
if (typeof getter !== "function") continue;
|
|
72
|
+
try {
|
|
73
|
+
const value = Reflect.apply(getter, headers, [name]);
|
|
74
|
+
return typeof value === "string" && value ? value : void 0;
|
|
75
|
+
} catch {}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const ownGet = Object.hasOwn(headers, "get") ? Reflect.get(headers, "get") : void 0;
|
|
80
|
+
if (typeof ownGet === "function") {
|
|
81
|
+
const value = Reflect.apply(ownGet, headers, [name]);
|
|
82
|
+
return typeof value === "string" && value ? value : void 0;
|
|
83
|
+
}
|
|
84
|
+
if (!Object.hasOwn(headers, name)) return void 0;
|
|
85
|
+
const value = Reflect.get(headers, name);
|
|
86
|
+
if (Array.isArray(value)) return typeof value[0] === "string" ? value[0] : void 0;
|
|
87
|
+
return typeof value === "string" ? value : void 0;
|
|
88
|
+
} catch {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function randomToken() {
|
|
96
|
+
return [...globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
97
|
+
}
|
|
98
|
+
async function refreshWorkspaceDevToken(rootDir, options = {}) {
|
|
99
|
+
const token = randomToken();
|
|
100
|
+
const tokenRoot = await workspaceDevTokenRoot(rootDir, options);
|
|
101
|
+
workspaceDevTokens().set(tokenRoot.key, token);
|
|
102
|
+
const [{ mkdir, writeFile }, { dirname }] = await Promise.all([import("node:fs/promises"), import("node:path")]);
|
|
103
|
+
const file = tokenRoot.file;
|
|
104
|
+
await mkdir(dirname(file), {
|
|
105
|
+
mode: 448,
|
|
106
|
+
recursive: true
|
|
107
|
+
});
|
|
108
|
+
await writeFile(file, `${token}\n`, { mode: 384 });
|
|
109
|
+
return token;
|
|
110
|
+
}
|
|
111
|
+
async function ensureWorkspaceDevToken(rootDir, options = {}) {
|
|
112
|
+
return workspaceDevTokens().get((await workspaceDevTokenRoot(rootDir, options)).key) || await refreshWorkspaceDevToken(rootDir, options);
|
|
113
|
+
}
|
|
114
|
+
async function readWorkspaceDevToken(rootDir, options = {}) {
|
|
115
|
+
try {
|
|
116
|
+
const { readFile } = await import("node:fs/promises");
|
|
117
|
+
return (await readFile((await workspaceDevTokenRoot(rootDir, options)).file, "utf8")).trim() || void 0;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return;
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function validateWorkspaceDevToken(rootDir, headers, options = {}) {
|
|
124
|
+
const expectedToken = await ensureWorkspaceDevToken(rootDir, options);
|
|
125
|
+
return isViteHubSecretEqual(headerValue(headers, workspaceDevTokenHeader, expectedToken), expectedToken);
|
|
126
|
+
}
|
|
127
|
+
async function resolveWorkspace(workspace) {
|
|
128
|
+
if (typeof workspace === "string") return useWorkspaceFiles(workspace);
|
|
129
|
+
if (typeof workspace === "function") return await workspace();
|
|
130
|
+
return workspace;
|
|
131
|
+
}
|
|
132
|
+
function resolveWorkspaceFilePath(path, root) {
|
|
133
|
+
const normalizedPath = normalizeSafeWorkspacePath(path, { allowEmpty: false });
|
|
134
|
+
if (!root) return normalizedPath;
|
|
135
|
+
return `${normalizeSafeWorkspacePath(root, { allowEmpty: false })}/${normalizedPath}`;
|
|
136
|
+
}
|
|
137
|
+
function resolveContentType(path, mediaType, contentTypes) {
|
|
138
|
+
if (mediaType) return mediaType;
|
|
139
|
+
if (contentTypes && Object.hasOwn(contentTypes, path) && contentTypes[path]) return contentTypes[path];
|
|
140
|
+
const extension = path.includes(".") ? `.${path.split(".").at(-1)}` : "";
|
|
141
|
+
if (extension && contentTypes && Object.hasOwn(contentTypes, extension) && contentTypes[extension]) return contentTypes[extension];
|
|
142
|
+
return lookup(path) || "application/octet-stream";
|
|
143
|
+
}
|
|
144
|
+
function errorMessage(error) {
|
|
145
|
+
if (Object(error) !== error) return;
|
|
146
|
+
try {
|
|
147
|
+
const message = Object.getOwnPropertyDescriptor(error, "message")?.value;
|
|
148
|
+
return message === String(message) ? String(message) : void 0;
|
|
149
|
+
} catch {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function isNotFoundError(error) {
|
|
154
|
+
const code = getViteHubErrorShape(error)?.code;
|
|
155
|
+
const message = errorMessage(error);
|
|
156
|
+
return code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID" || message?.includes("Workspace file does not exist:") === true || message?.includes("Workspace path does not exist:") === true;
|
|
157
|
+
}
|
|
158
|
+
function workspaceSessionStarter(input) {
|
|
159
|
+
return input && typeof input === "object" && typeof input.startSession === "function" ? input : void 0;
|
|
160
|
+
}
|
|
161
|
+
function workspaceSourceMaterializer(input) {
|
|
162
|
+
return input && typeof input === "object" && typeof input.materializeSources === "function" ? input.materializeSources.bind(input) : void 0;
|
|
163
|
+
}
|
|
164
|
+
async function materializeWorkspaceDevSources(workspace, input) {
|
|
165
|
+
const materialize = workspaceSourceMaterializer(workspace) ?? workspaceSourceMaterializer(workspace.fs);
|
|
166
|
+
if (!materialize) return;
|
|
167
|
+
const paths = input.paths?.length ? input.paths : [""];
|
|
168
|
+
await withWorkspaceProgress(input.onProgress, {
|
|
169
|
+
data: { paths },
|
|
170
|
+
id: "workspace.dev.materialize",
|
|
171
|
+
label: "Materializing workspace sources"
|
|
172
|
+
}, async () => {
|
|
173
|
+
await Promise.all(paths.map(async (path) => {
|
|
174
|
+
await materialize({
|
|
175
|
+
abortSignal: input.abortSignal,
|
|
176
|
+
onProgress: async (event) => await input.onProgress?.({
|
|
177
|
+
data: { ...event },
|
|
178
|
+
durationMs: event.durationMs,
|
|
179
|
+
error: event.error,
|
|
180
|
+
id: `workspace.dev.materialize.${event.source}`,
|
|
181
|
+
label: `Materializing source ${event.source}`,
|
|
182
|
+
status: event.status
|
|
183
|
+
}),
|
|
184
|
+
path
|
|
185
|
+
}).catch((error) => {
|
|
186
|
+
if (path && isNotFoundError(error)) return;
|
|
187
|
+
throw error;
|
|
188
|
+
});
|
|
189
|
+
}));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function workspaceFileNotFound() {
|
|
193
|
+
return Response.json({
|
|
194
|
+
status: 404,
|
|
195
|
+
message: "Workspace file not found."
|
|
196
|
+
}, { status: 404 });
|
|
197
|
+
}
|
|
198
|
+
/** Read a Workspace file as a Response. A missing, disallowed, or unsafe path gets a 404 Response. */
|
|
199
|
+
async function readWorkspaceFileResponse(options) {
|
|
200
|
+
let filePath;
|
|
201
|
+
try {
|
|
202
|
+
filePath = resolveWorkspaceFilePath(options.path, options.root);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (isNotFoundError(error)) return workspaceFileNotFound();
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
if (!matchesAny(filePath, options.allow)) return workspaceFileNotFound();
|
|
208
|
+
const workspace = await resolveWorkspace(options.workspace);
|
|
209
|
+
try {
|
|
210
|
+
const [content, stat] = await Promise.all([workspace.fs.readFile(filePath, { encoding: "binary" }), workspace.fs.stat(filePath)]);
|
|
211
|
+
if (stat.type !== "file") return workspaceFileNotFound();
|
|
212
|
+
const headers = new Headers(options.headers);
|
|
213
|
+
headers.set("content-type", resolveContentType(filePath, stat.mediaType, options.contentTypes));
|
|
214
|
+
headers.set("x-content-type-options", "nosniff");
|
|
215
|
+
if (options.cacheControl) headers.set("cache-control", options.cacheControl);
|
|
216
|
+
return new Response(content, { headers });
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (isNotFoundError(error)) return workspaceFileNotFound();
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Serve Workspace files from a route. The file path is the part of the URL path after `base`, percent-decoded, so
|
|
224
|
+
* `/files/my%20file.md` serves `my file.md`. A path that is not valid percent-encoding gets a 400 Response.
|
|
225
|
+
*/
|
|
226
|
+
function defineWorkspaceFileHandler(options) {
|
|
227
|
+
const { base, baseURL, ...fileOptions } = options;
|
|
228
|
+
const segments = [baseURL ?? "", base].map((part) => part.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
|
|
229
|
+
const prefix = segments ? `/${segments}/` : "/";
|
|
230
|
+
return { async fetch(request) {
|
|
231
|
+
const pathname = new URL(request.url).pathname;
|
|
232
|
+
if (baseURL !== void 0 && !pathname.startsWith(prefix)) return workspaceFileNotFound();
|
|
233
|
+
const start = baseURL === void 0 ? pathname.indexOf(prefix) : 0;
|
|
234
|
+
if (start < 0) return workspaceFileNotFound();
|
|
235
|
+
let path;
|
|
236
|
+
try {
|
|
237
|
+
path = decodeURIComponent(pathname.slice(start + prefix.length));
|
|
238
|
+
} catch {
|
|
239
|
+
return Response.json({
|
|
240
|
+
status: 400,
|
|
241
|
+
message: "Workspace file path is not valid percent-encoding."
|
|
242
|
+
}, { status: 400 });
|
|
243
|
+
}
|
|
244
|
+
return await readWorkspaceFileResponse({
|
|
245
|
+
...fileOptions,
|
|
246
|
+
path
|
|
247
|
+
});
|
|
248
|
+
} };
|
|
249
|
+
}
|
|
250
|
+
async function runWorkspaceDevCommand(input) {
|
|
251
|
+
const command = input.command.trim();
|
|
252
|
+
if (!command) throw workspaceErrorDiagnostics.WORKSPACE_R0040({ message: "Workspace Dev command cannot be empty." });
|
|
253
|
+
const definition = input.definition;
|
|
254
|
+
const workspace = typeof input.workspace === "string" ? await useWorkspaceFiles(input.workspace, definition ? {
|
|
255
|
+
definition,
|
|
256
|
+
mode: "write"
|
|
257
|
+
} : { mode: "write" }) : input.workspace;
|
|
258
|
+
const starter = workspaceSessionStarter(workspace) ?? workspaceSessionStarter(workspace.fs);
|
|
259
|
+
const startSession = starter?.startSession.bind(starter);
|
|
260
|
+
if (!startSession) throw workspaceErrorDiagnostics.WORKSPACE_R0041({ message: "Workspace Dev command requires a Workspace Session." });
|
|
261
|
+
await materializeWorkspaceDevSources(workspace, input);
|
|
262
|
+
let session;
|
|
263
|
+
const execOptions = {
|
|
264
|
+
abortSignal: input.abortSignal,
|
|
265
|
+
timeout: input.timeout
|
|
266
|
+
};
|
|
267
|
+
let result;
|
|
268
|
+
try {
|
|
269
|
+
await withWorkspaceProgress(input.onProgress, {
|
|
270
|
+
data: { paths: input.paths ?? null },
|
|
271
|
+
id: "workspace.dev.start-session",
|
|
272
|
+
label: "Starting workspace session"
|
|
273
|
+
}, async () => {
|
|
274
|
+
session = await startSession({
|
|
275
|
+
abortSignal: input.abortSignal,
|
|
276
|
+
host: input.host,
|
|
277
|
+
paths: input.paths
|
|
278
|
+
});
|
|
279
|
+
return session;
|
|
280
|
+
});
|
|
281
|
+
if (!session) throw workspaceErrorDiagnostics.WORKSPACE_R0042({ message: "Workspace Dev Session did not start." });
|
|
282
|
+
result = input.args ? await session.exec(command, input.args, execOptions) : await session.exec("sh", ["-c", command], execOptions);
|
|
283
|
+
const diff = result.exitCode === 0 ? await session.diff() : void 0;
|
|
284
|
+
if (diff?.entries.length) {
|
|
285
|
+
const commit = definition ? resolveWorkspaceAutoCommit(definition, diff) : void 0;
|
|
286
|
+
if (!definition || !hasWorkspaceCommitRules(definition) || commit) await session.commit({ message: commit?.message || "workspace dev command" });
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (!session) throw error;
|
|
290
|
+
try {
|
|
291
|
+
await session.close();
|
|
292
|
+
} catch (closeError) {
|
|
293
|
+
throw new AggregateError([error, closeError], "[vitehub] Workspace Dev command failed and session cleanup also failed.");
|
|
294
|
+
}
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
if (!session) throw workspaceErrorDiagnostics.WORKSPACE_R0043({ message: "Workspace Dev Session did not start." });
|
|
298
|
+
await session.close();
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
export { defineWorkspaceFileHandler, ensureWorkspaceDevToken, readWorkspaceDevToken, readWorkspaceFileResponse, refreshWorkspaceDevToken, runWorkspaceDevCommand, isViteHubSecretEqual as t, validateWorkspaceDevToken, workspaceDevHeader, workspaceDevHeaderValue, workspaceDevRoute, workspaceDevTokenHeader, workspaceDevTokenServerId };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as abortable } from "./abort-CQGxJBqa.js";
|
|
2
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import {
|
|
4
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-
|
|
5
|
-
import { l as normalizeWorkspacePath } from "./path-
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-CsiNo_oI.js";
|
|
3
|
+
import { i as workspaceConflict, normalizeSafeWorkspacePath, o as workspaceError } from "./internal/path.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CHgE8TQM.js";
|
|
5
|
+
import { l as normalizeWorkspacePath } from "./path-DYHw5KNk.js";
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
7
|
import { gunzipSync } from "node:zlib";
|
|
8
8
|
// ../internal/src/forge.ts
|
|
@@ -14,55 +14,92 @@ import { gunzipSync } from "node:zlib";
|
|
|
14
14
|
*/
|
|
15
15
|
const forgeEnv = {
|
|
16
16
|
github: {
|
|
17
|
-
appId: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
appId: {
|
|
18
|
+
names: ["VITEHUB_GITHUB_APP_ID", "FORGES_GITHUB_APP_ID"],
|
|
19
|
+
description: "GitHub App ID that signs in as the GitHub App with the private key."
|
|
20
|
+
},
|
|
21
|
+
baseUrl: {
|
|
22
|
+
names: ["VITEHUB_GITHUB_BASE_URL", "FORGES_GITHUB_BASE_URL"],
|
|
23
|
+
description: "GitHub API URL for GitHub Enterprise Server."
|
|
24
|
+
},
|
|
25
|
+
installationId: {
|
|
26
|
+
names: ["VITEHUB_GITHUB_INSTALLATION_ID", "FORGES_GITHUB_INSTALLATION_ID"],
|
|
27
|
+
description: "GitHub App installation ID for the repositories of one owner."
|
|
28
|
+
},
|
|
29
|
+
appOwner: {
|
|
30
|
+
names: ["VITEHUB_GITHUB_APP_OWNER"],
|
|
31
|
+
description: "Repository owner of the GitHub App installation ID."
|
|
32
|
+
},
|
|
33
|
+
appInstallations: {
|
|
34
|
+
names: ["VITEHUB_GITHUB_APP_INSTALLATIONS"],
|
|
35
|
+
description: "JSON object that maps each repository owner to its GitHub App installation ID."
|
|
36
|
+
},
|
|
21
37
|
privateKey: {
|
|
22
38
|
names: ["VITEHUB_GITHUB_PRIVATE_KEY", "FORGES_GITHUB_PRIVATE_KEY"],
|
|
23
|
-
secret: true
|
|
39
|
+
secret: true,
|
|
40
|
+
description: "GitHub App private key in PEM format that signs the GitHub App tokens."
|
|
41
|
+
},
|
|
42
|
+
privateKeyPath: {
|
|
43
|
+
names: ["VITEHUB_GITHUB_PRIVATE_KEY_PATH"],
|
|
44
|
+
description: "Path of the GitHub App private key file when the private key is not set."
|
|
24
45
|
},
|
|
25
|
-
privateKeyPath: { names: ["VITEHUB_GITHUB_PRIVATE_KEY_PATH"] },
|
|
26
46
|
token: {
|
|
27
47
|
names: ["VITEHUB_GITHUB_TOKEN", "FORGES_GITHUB_TOKEN"],
|
|
28
|
-
secret: true
|
|
48
|
+
secret: true,
|
|
49
|
+
description: "GitHub access token that calls the GitHub API."
|
|
29
50
|
},
|
|
30
51
|
webhookSecret: {
|
|
31
52
|
names: ["VITEHUB_GITHUB_WEBHOOK_SECRET", "FORGES_GITHUB_WEBHOOK_SECRET"],
|
|
32
|
-
secret: true
|
|
53
|
+
secret: true,
|
|
54
|
+
description: "Secret that checks the signature of each GitHub webhook request."
|
|
33
55
|
}
|
|
34
56
|
},
|
|
35
57
|
gitlab: {
|
|
36
|
-
baseUrl: {
|
|
58
|
+
baseUrl: {
|
|
59
|
+
names: ["VITEHUB_GITLAB_BASE_URL", "FORGES_GITLAB_BASE_URL"],
|
|
60
|
+
description: "GitLab URL for a self-managed GitLab instance."
|
|
61
|
+
},
|
|
37
62
|
token: {
|
|
38
63
|
names: ["VITEHUB_GITLAB_TOKEN", "FORGES_GITLAB_TOKEN"],
|
|
39
|
-
secret: true
|
|
64
|
+
secret: true,
|
|
65
|
+
description: "GitLab access token that calls the GitLab API."
|
|
40
66
|
},
|
|
41
67
|
webhookSecret: {
|
|
42
68
|
names: ["VITEHUB_GITLAB_WEBHOOK_SECRET", "FORGES_GITLAB_WEBHOOK_SECRET"],
|
|
43
|
-
secret: true
|
|
69
|
+
secret: true,
|
|
70
|
+
description: "Secret that checks each GitLab webhook request."
|
|
44
71
|
}
|
|
45
72
|
},
|
|
46
73
|
forgejo: {
|
|
47
|
-
baseUrl: {
|
|
74
|
+
baseUrl: {
|
|
75
|
+
names: ["VITEHUB_FORGEJO_BASE_URL", "FORGES_FORGEJO_BASE_URL"],
|
|
76
|
+
description: "URL of the Forgejo instance."
|
|
77
|
+
},
|
|
48
78
|
token: {
|
|
49
79
|
names: ["VITEHUB_FORGEJO_TOKEN", "FORGES_FORGEJO_TOKEN"],
|
|
50
|
-
secret: true
|
|
80
|
+
secret: true,
|
|
81
|
+
description: "Forgejo access token that calls the Forgejo API."
|
|
51
82
|
},
|
|
52
83
|
webhookSecret: {
|
|
53
84
|
names: ["VITEHUB_FORGEJO_WEBHOOK_SECRET", "FORGES_FORGEJO_WEBHOOK_SECRET"],
|
|
54
|
-
secret: true
|
|
85
|
+
secret: true,
|
|
86
|
+
description: "Secret that checks each Forgejo webhook request."
|
|
55
87
|
}
|
|
56
88
|
},
|
|
57
89
|
gitea: {
|
|
58
|
-
baseUrl: {
|
|
90
|
+
baseUrl: {
|
|
91
|
+
names: ["VITEHUB_GITEA_BASE_URL", "FORGES_GITEA_BASE_URL"],
|
|
92
|
+
description: "URL of the Gitea instance."
|
|
93
|
+
},
|
|
59
94
|
token: {
|
|
60
95
|
names: ["VITEHUB_GITEA_TOKEN", "FORGES_GITEA_TOKEN"],
|
|
61
|
-
secret: true
|
|
96
|
+
secret: true,
|
|
97
|
+
description: "Gitea access token that calls the Gitea API."
|
|
62
98
|
},
|
|
63
99
|
webhookSecret: {
|
|
64
100
|
names: ["VITEHUB_GITEA_WEBHOOK_SECRET", "FORGES_GITEA_WEBHOOK_SECRET"],
|
|
65
|
-
secret: true
|
|
101
|
+
secret: true,
|
|
102
|
+
description: "Secret that checks each Gitea webhook request."
|
|
66
103
|
}
|
|
67
104
|
}
|
|
68
105
|
};
|
|
@@ -570,6 +607,7 @@ function readGitHubEnvApp(env = typeof process !== "undefined" ? process.env : {
|
|
|
570
607
|
let forge;
|
|
571
608
|
return () => forge ??= loadForge().then(({ useForge }) => useForge({
|
|
572
609
|
env: lookup,
|
|
610
|
+
baseUrl: "https://api.github.com",
|
|
573
611
|
fetch: requestGitHub,
|
|
574
612
|
userAgent: "vitehub-workspace"
|
|
575
613
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as WorkspaceEntry, in as WorkspaceSourceMaterializationStatus, zt as WorkspaceRules } from "./types-
|
|
2
|
-
import { i as workspaceSourceGrantPaths, n as normalizeWorkspaceSourceMetadata, r as normalizeWorkspaceSourcesMetadata, t as WorkspaceSourceMetadata } from "./config-
|
|
1
|
+
import { V as WorkspaceEntry, in as WorkspaceSourceMaterializationStatus, zt as WorkspaceRules } from "./types-BnSUug2v.js";
|
|
2
|
+
import { i as workspaceSourceGrantPaths, n as normalizeWorkspaceSourceMetadata, r as normalizeWorkspaceSourcesMetadata, t as WorkspaceSourceMetadata } from "./config-DF6sqKXB.js";
|
|
3
3
|
/** Rejects rule keys that ViteHub does not enforce, such as `read`, so that a rule never looks like a protection it is not. */
|
|
4
4
|
export declare function assertWorkspaceRules(rules: WorkspaceRules | undefined): void;
|
|
5
5
|
export declare function listMaterializedWorkspaceEntries(workspace: unknown): Promise<WorkspaceEntry[] | undefined>;
|
package/dist/source-metadata.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { m as readCurrentSourceSnapshot, o as resolveWorkspaceMetadataTarget } from "./metadata-target-
|
|
2
|
-
import { t as assertWorkspaceRules } from "./rule-keys-
|
|
3
|
-
import { i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata } from "./config
|
|
1
|
+
import { m as readCurrentSourceSnapshot, o as resolveWorkspaceMetadataTarget } from "./metadata-target-DPGF6L68.js";
|
|
2
|
+
import { t as assertWorkspaceRules } from "./rule-keys-xMpiTLq1.js";
|
|
3
|
+
import { i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata } from "./config--ZzAvhMp.js";
|
|
4
4
|
// src/source-metadata.ts
|
|
5
5
|
async function listMaterializedWorkspaceEntries(workspace) {
|
|
6
6
|
return await (await resolveWorkspaceMetadataTarget(workspace))?.list?.("", { recursive: true });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as normalizeWorkspaceSources, f as prepareWorkspaceSource, n as createSourceContext, s as sourceMountContainsPath } from "./config
|
|
4
|
-
import { C as withWorkspaceStoreMutation, E as normalizeSourceFileMetadata, S as sourceMountOwnsPath, T as normalizeMetadataValue, w as normalizeSourceItemPath, x as createWorkspaceSourceMountAuthority } from "./metadata-target-
|
|
5
|
-
import { d as sourceSyncPathClaims, f as workspaceSourceSyncStateEquals, l as readWorkspaceSourceSyncState, u as sourceSyncMetaKey } from "./workspace-
|
|
1
|
+
import { o as workspaceError } from "./internal/path.js";
|
|
2
|
+
import { f as sha256, n as contentStreamToBytes } from "./path-DYHw5KNk.js";
|
|
3
|
+
import { a as normalizeWorkspaceSources, f as prepareWorkspaceSource, n as createSourceContext, s as sourceMountContainsPath } from "./config--ZzAvhMp.js";
|
|
4
|
+
import { C as withWorkspaceStoreMutation, E as normalizeSourceFileMetadata, S as sourceMountOwnsPath, T as normalizeMetadataValue, w as normalizeSourceItemPath, x as createWorkspaceSourceMountAuthority } from "./metadata-target-DPGF6L68.js";
|
|
5
|
+
import { d as sourceSyncPathClaims, f as workspaceSourceSyncStateEquals, l as readWorkspaceSourceSyncState, u as sourceSyncMetaKey } from "./workspace-D1m00MCM.js";
|
|
6
6
|
// src/sources/sync.ts
|
|
7
7
|
const sourceSyncLocks = /* @__PURE__ */ new Map();
|
|
8
8
|
const sourceSyncGrants = createWorkspaceSourceMountAuthority("Source Sync");
|
package/dist/test.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as registerWorkspace } from "./registry-
|
|
1
|
+
import { n as registerWorkspace } from "./registry-hnARUKNF.js";
|
|
2
2
|
export { registerWorkspace };
|
package/dist/test.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { r as registerWorkspace } from "./registry-
|
|
1
|
+
export { r as registerWorkspace } from "./registry-CFeUQsja.js";
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ExecutionAuthority } from "@vite-hub/runtime";
|
|
2
2
|
import { FileSourceOptions, GitHubSourceOptions, GlobSourceOptions, Source, SourceContext, SourceRevision } from "@vite-hub/source";
|
|
3
3
|
import { McpResourcesSourceOptions } from "@vite-hub/source/mcp";
|
|
4
|
+
declare function resolveWorkspaceAutoCommit(definition: WorkspaceDefinition, diff: WorkspaceDiff): WorkspaceAutoCommitPlan | undefined;
|
|
5
|
+
declare const replaceStorePath: unique symbol;
|
|
6
|
+
interface WorkspaceReplacement {
|
|
7
|
+
path: string;
|
|
8
|
+
directories: readonly string[];
|
|
9
|
+
files: readonly WorkspaceFile[];
|
|
10
|
+
removeTree: boolean;
|
|
11
|
+
}
|
|
4
12
|
type WorkspaceContent = string | Uint8Array;
|
|
5
13
|
type WorkspaceContentStream = ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
6
14
|
interface ReadFileOptions {
|
|
@@ -151,6 +159,7 @@ interface WorkspaceSessionOptions {
|
|
|
151
159
|
materializeSources?: false;
|
|
152
160
|
onProgress?: (event: WorkspacePrepareSessionProgressEvent) => void | Promise<void>;
|
|
153
161
|
paths?: readonly string[];
|
|
162
|
+
/** Host directory of the Session. Defaults to `host.workspaceTarget`, then `/workspace`. */
|
|
154
163
|
target?: string;
|
|
155
164
|
writeBack?: false | {
|
|
156
165
|
exclude?: readonly string[];
|
|
@@ -191,6 +200,8 @@ interface WorkspaceSessionHost {
|
|
|
191
200
|
readonly archiveMaxBytes?: number;
|
|
192
201
|
readonly executionAuthority: ExecutionAuthority;
|
|
193
202
|
readonly inspectionConcurrency?: number;
|
|
203
|
+
/** Absolute default target that a Workspace Session may empty and populate. */
|
|
204
|
+
readonly workspaceTarget?: string;
|
|
194
205
|
/** Maximum independent workspace files copied into this host concurrently. Defaults to 1. */
|
|
195
206
|
readonly materializationConcurrency?: number;
|
|
196
207
|
detachAbortSignal?(): void;
|
|
@@ -587,6 +598,7 @@ interface WorkspaceRebaseOptions {
|
|
|
587
598
|
takeRemote?: string[];
|
|
588
599
|
}
|
|
589
600
|
interface WorkspaceStore {
|
|
601
|
+
[replaceStorePath]?(replacement: WorkspaceReplacement): Promise<void>;
|
|
590
602
|
history?: WorkspaceStoreHistory;
|
|
591
603
|
readFile(path: string): Promise<WorkspaceFile | undefined>;
|
|
592
604
|
writeFile(path: string, file: WorkspaceFile): Promise<void>;
|
|
@@ -1023,4 +1035,4 @@ interface WorkspaceMaterializeSourcesResult {
|
|
|
1023
1035
|
path: string;
|
|
1024
1036
|
sources: WorkspaceSourceMaterializationStatus[];
|
|
1025
1037
|
}
|
|
1026
|
-
export { WorkspaceHistoryDiffOptions as $, WorkspaceSourceDefinition as $t, WorkspaceAuthor as A, WorkspaceStreamFile as An, WorkspaceOptions as At, WorkspaceDiffEntry as B, WorkspaceWriteOperation as Bn, WorkspaceScopeName as Bt, SourceContextWorkspaceFiles as C, WorkspaceSourceSyncResult as Cn, WorkspaceMergeConflict as Ct, WorkspaceAssetPath as D, WorkspaceStoreHistory as Dn, WorkspaceName as Dt, Workspace as E, WorkspaceStore as En, WorkspaceMergeResolution as Et, WorkspaceContentStream as F, WorkspaceWriteCommit as Fn, WorkspaceRetainedHistory as Ft, WorkspaceFileSourceInput as G, WorkspaceSessionHost as Gt, WorkspaceFetchSourceInput as H, WorkspaceWriteValidatorResult as Hn, WorkspaceSearchQuery as Ht, WorkspaceCustomSourceInput as I, WorkspaceWriteErrorHook as In, WorkspaceRevision as It, WorkspaceHistoryChanges as J, WorkspaceSessionOptions as Jt, WorkspaceGitHubSourceInput as K, WorkspaceSessionHostFileEntry as Kt, WorkspaceDefinition as L, WorkspaceWriteHook as Ln, WorkspaceRevisionView as Lt, WorkspaceCacheOptions as M, WorkspaceSyncResultDetails as Mn, WorkspacePrepareSessionProgressEvent as Mt, WorkspaceCapabilities as N, WorkspaceSyncSnapshotOptions as Nn, WorkspacePullRequest as Nt, WorkspaceAssets as O, WorkspaceStoreHistoryCommitOptions as On, WorkspaceNameMap as Ot, WorkspaceContent as P, WorkspaceValidateMode as Pn, WorkspaceRebaseOptions as Pt, WorkspaceHistoryDeleteRefOptions as Q, WorkspaceSourceBindingInput as Qt, WorkspaceDefinitionInput as R, WorkspaceWriteInput as Rn, WorkspaceRule as Rt, SourceContext$1 as S, WorkspaceSourceSyncPolicy as Sn, WorkspaceMergeCommit as St, VercelBlobWorkspaceStoreOptions as T, WorkspaceStat as Tn, WorkspaceMergeOptions as Tt, WorkspaceFetchSourceRequestOptions as U, WriteFileOptions as Un, WorkspaceSelectedScope as Ut, WorkspaceEntry as V, WorkspaceWriteValidator as Vn, WorkspaceSearchHit as Vt, WorkspaceFile as W, WorkspaceSession as Wt, WorkspaceHistoryCommitBase as X, WorkspaceSnapshot as Xt, WorkspaceHistoryChangesCommitOptions as Y, WorkspaceSessionWriteFileOptions as Yt, WorkspaceHistoryCommitOptions as Z, WorkspaceSource as Zt, ReadFileResult as _, WorkspaceSourceResolver as _n, WorkspaceMaterializeMode as _t, GitHubWorkspaceOption as a, WorkspaceSourceMount as an, WorkspaceHistoryListResult as at, RmOptions as b, WorkspaceSourceSyncCounts as bn, WorkspaceMaterializeSourcesResult as bt, GlobOptions as c, WorkspaceSourceRequestExecutionInput as cn, WorkspaceHistoryRefOptions as ct, LocalWorkspaceStoreOptions as d, WorkspaceSourceRequestMethod as dn, WorkspaceInstructionBinding as dt, WorkspaceSourceInput as en, WorkspaceHistoryExtensions as et, Logger as f, WorkspaceSourceResolutionContext as fn, WorkspaceInstructionBindingValue as ft, ReadFileOptions as g, WorkspaceSourceResolutionResult as gn, WorkspaceLookupName as gt, MkdirOptions as h, WorkspaceSourceResolutionInvocation as hn, WorkspaceLoaderSource as ht, ExecResult as i, WorkspaceSourceMaterializationStatus as in, WorkspaceHistoryListOptions as it, WorkspaceAutoCommitPlan as j, WorkspaceSyncOptions as jn, WorkspacePlugin as jt, WorkspaceAssetsRegistry as k, WorkspaceStoreOptions as kn, WorkspaceOpenPullRequestOptions as kt, ListOptions as l, WorkspaceSourceRequestExecutionResult as ln, WorkspaceHookContext as lt, MemoryWorkspaceStoreOptions as m, WorkspaceSourceResolutionContextValueReader as mn, WorkspaceLoader as mt, DiffOptions as n, WorkspaceSourceMaterializationCounts as nn, WorkspaceHistoryFileInput as nt, GitHubWorkspaceRefs as o, WorkspaceSourceMountOptions as on, WorkspaceHistoryReader as ot, MaybePromise as p, WorkspaceSourceResolutionContextMap as pn, WorkspaceLastChange as pt, WorkspaceGlobSourceInput as q, WorkspaceSessionHostFiles as qt, ExecOptions as r, WorkspaceSourceMaterializationPathResult as rn, WorkspaceHistoryFilesCommitOptions as rt, GitHubWorkspaceStoreOptions as s, WorkspaceSourceRequestDescriptor as sn, WorkspaceHistoryRef as st, CloudflareArtifactsWorkspaceStoreOptions as t, WorkspaceSourceItem as tn, WorkspaceHistoryFile as tt, LoaderContext as u, WorkspaceSourceRequestExecutor as un, WorkspaceHooks as ut, ResolvedWorkspaceModuleOptions as v, WorkspaceSourceSelection as vn, WorkspaceMaterializeSourcesOptions as vt, ValidatedWorkspaceName as w, WorkspaceSourceSyncStatus as wn, WorkspaceMergeConflictContext as wt, SnapshotOptions as x, WorkspaceSourceSyncPathResult as xn, WorkspaceMcpResourcesSourceInput as xt, ResolvedWorkspaceRule as y, WorkspaceSourceSyncConfig as yn, WorkspaceMaterializeSourcesProgressEvent as yt, WorkspaceDiff as z, WorkspaceWriteMode as zn, WorkspaceRules as zt };
|
|
1038
|
+
export { WorkspaceHistoryDiffOptions as $, WorkspaceSourceDefinition as $t, WorkspaceAuthor as A, WorkspaceStreamFile as An, WorkspaceOptions as At, WorkspaceDiffEntry as B, WorkspaceWriteOperation as Bn, WorkspaceScopeName as Bt, SourceContextWorkspaceFiles as C, WorkspaceSourceSyncResult as Cn, WorkspaceMergeConflict as Ct, WorkspaceAssetPath as D, WorkspaceStoreHistory as Dn, WorkspaceName as Dt, Workspace as E, WorkspaceStore as En, WorkspaceMergeResolution as Et, WorkspaceContentStream as F, WorkspaceWriteCommit as Fn, WorkspaceRetainedHistory as Ft, WorkspaceFileSourceInput as G, WorkspaceSessionHost as Gt, WorkspaceFetchSourceInput as H, WorkspaceWriteValidatorResult as Hn, WorkspaceSearchQuery as Ht, WorkspaceCustomSourceInput as I, WorkspaceWriteErrorHook as In, WorkspaceRevision as It, WorkspaceHistoryChanges as J, WorkspaceSessionOptions as Jt, WorkspaceGitHubSourceInput as K, WorkspaceSessionHostFileEntry as Kt, WorkspaceDefinition as L, WorkspaceWriteHook as Ln, WorkspaceRevisionView as Lt, WorkspaceCacheOptions as M, WorkspaceSyncResultDetails as Mn, WorkspacePrepareSessionProgressEvent as Mt, WorkspaceCapabilities as N, WorkspaceSyncSnapshotOptions as Nn, WorkspacePullRequest as Nt, WorkspaceAssets as O, WorkspaceStoreHistoryCommitOptions as On, WorkspaceNameMap as Ot, WorkspaceContent as P, WorkspaceValidateMode as Pn, WorkspaceRebaseOptions as Pt, WorkspaceHistoryDeleteRefOptions as Q, WorkspaceSourceBindingInput as Qt, WorkspaceDefinitionInput as R, WorkspaceWriteInput as Rn, WorkspaceRule as Rt, SourceContext$1 as S, WorkspaceSourceSyncPolicy as Sn, WorkspaceMergeCommit as St, VercelBlobWorkspaceStoreOptions as T, WorkspaceStat as Tn, WorkspaceMergeOptions as Tt, WorkspaceFetchSourceRequestOptions as U, WriteFileOptions as Un, WorkspaceSelectedScope as Ut, WorkspaceEntry as V, WorkspaceWriteValidator as Vn, WorkspaceSearchHit as Vt, WorkspaceFile as W, resolveWorkspaceAutoCommit as Wn, WorkspaceSession as Wt, WorkspaceHistoryCommitBase as X, WorkspaceSnapshot as Xt, WorkspaceHistoryChangesCommitOptions as Y, WorkspaceSessionWriteFileOptions as Yt, WorkspaceHistoryCommitOptions as Z, WorkspaceSource as Zt, ReadFileResult as _, WorkspaceSourceResolver as _n, WorkspaceMaterializeMode as _t, GitHubWorkspaceOption as a, WorkspaceSourceMount as an, WorkspaceHistoryListResult as at, RmOptions as b, WorkspaceSourceSyncCounts as bn, WorkspaceMaterializeSourcesResult as bt, GlobOptions as c, WorkspaceSourceRequestExecutionInput as cn, WorkspaceHistoryRefOptions as ct, LocalWorkspaceStoreOptions as d, WorkspaceSourceRequestMethod as dn, WorkspaceInstructionBinding as dt, WorkspaceSourceInput as en, WorkspaceHistoryExtensions as et, Logger as f, WorkspaceSourceResolutionContext as fn, WorkspaceInstructionBindingValue as ft, ReadFileOptions as g, WorkspaceSourceResolutionResult as gn, WorkspaceLookupName as gt, MkdirOptions as h, WorkspaceSourceResolutionInvocation as hn, WorkspaceLoaderSource as ht, ExecResult as i, WorkspaceSourceMaterializationStatus as in, WorkspaceHistoryListOptions as it, WorkspaceAutoCommitPlan as j, WorkspaceSyncOptions as jn, WorkspacePlugin as jt, WorkspaceAssetsRegistry as k, WorkspaceStoreOptions as kn, WorkspaceOpenPullRequestOptions as kt, ListOptions as l, WorkspaceSourceRequestExecutionResult as ln, WorkspaceHookContext as lt, MemoryWorkspaceStoreOptions as m, WorkspaceSourceResolutionContextValueReader as mn, WorkspaceLoader as mt, DiffOptions as n, WorkspaceSourceMaterializationCounts as nn, WorkspaceHistoryFileInput as nt, GitHubWorkspaceRefs as o, WorkspaceSourceMountOptions as on, WorkspaceHistoryReader as ot, MaybePromise as p, WorkspaceSourceResolutionContextMap as pn, WorkspaceLastChange as pt, WorkspaceGlobSourceInput as q, WorkspaceSessionHostFiles as qt, ExecOptions as r, WorkspaceSourceMaterializationPathResult as rn, WorkspaceHistoryFilesCommitOptions as rt, GitHubWorkspaceStoreOptions as s, WorkspaceSourceRequestDescriptor as sn, WorkspaceHistoryRef as st, CloudflareArtifactsWorkspaceStoreOptions as t, WorkspaceSourceItem as tn, WorkspaceHistoryFile as tt, LoaderContext as u, WorkspaceSourceRequestExecutor as un, WorkspaceHooks as ut, ResolvedWorkspaceModuleOptions as v, WorkspaceSourceSelection as vn, WorkspaceMaterializeSourcesOptions as vt, ValidatedWorkspaceName as w, WorkspaceSourceSyncStatus as wn, WorkspaceMergeConflictContext as wt, SnapshotOptions as x, WorkspaceSourceSyncPathResult as xn, WorkspaceMcpResourcesSourceInput as xt, ResolvedWorkspaceRule as y, WorkspaceSourceSyncConfig as yn, WorkspaceMaterializeSourcesProgressEvent as yt, WorkspaceDiff as z, WorkspaceWriteMode as zn, WorkspaceRules as zt };
|
|
@@ -1,54 +1,15 @@
|
|
|
1
|
-
import { n as useWorkspaceAssets } from "./asset-registry-
|
|
2
|
-
import {
|
|
3
|
-
import { f as normalizeHistoryRef, g as validateHistoryMessage, h as requireWorkspaceHistory, m as rejectHistoryHead, s as deleteWorkspaceHistoryRef, u as historyConflict } from "./utils-
|
|
1
|
+
import { n as useWorkspaceAssets } from "./asset-registry-DJyE42kr.js";
|
|
2
|
+
import { normalizeSafeWorkspacePath, o as workspaceError } from "./internal/path.js";
|
|
3
|
+
import { f as normalizeHistoryRef, g as validateHistoryMessage, h as requireWorkspaceHistory, m as rejectHistoryHead, s as deleteWorkspaceHistoryRef, u as historyConflict } from "./utils-Bv1NBg8r.js";
|
|
4
|
+
import { _ as attachWorkspaceSourceRequestExecution, g as copyWorkspacePath, h as appendWorkspaceFile, i as assertPublicWorkspaceMetaKey, t as createWorkspace, y as getWorkspaceSourceRequestExecution } from "./workspace-D1m00MCM.js";
|
|
5
|
+
import { c as normalizeSafeWorkspacePattern, f as sha256 } from "./path-DYHw5KNk.js";
|
|
6
|
+
import { s as useRegisteredWorkspace } from "./registry-CFeUQsja.js";
|
|
4
7
|
import { a as provideWorkspaceStoreTarget, i as forwardWorkspaceStoreTarget, o as resolveWorkspaceStoreTarget } from "./vitehub-grants-Co713QTg.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { t as createHostedWorkspaceSession } from "./host-C8yZizfk.js";
|
|
10
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-B4me-ouV.js";
|
|
8
|
+
import { o as requireWorkspaceReplacement, t as attachWorkspaceReplacement } from "./replacement-CVZVsflC.js";
|
|
9
|
+
import { c as workspaceInternalMetadataCapability, o as resolveWorkspaceMetadataTarget, r as forwardWorkspaceMetadataTarget, t as attachWorkspaceMetadataTarget } from "./metadata-target-DPGF6L68.js";
|
|
10
|
+
import { t as createHostedWorkspaceSession } from "./host-BYBRcSnh.js";
|
|
11
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CHgE8TQM.js";
|
|
11
12
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
12
|
-
import { posix } from "node:path";
|
|
13
|
-
// src/fs-ops.ts
|
|
14
|
-
async function ensureMissingOrReplaceable(workspace, path, overwrite = false) {
|
|
15
|
-
if (!await workspace.exists(path)) return;
|
|
16
|
-
if (!overwrite) throw workspaceError(`[vitehub] Workspace path already exists: ${path}.`);
|
|
17
|
-
await workspace.rm(path, {
|
|
18
|
-
recursive: true,
|
|
19
|
-
force: true
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
async function copyWorkspacePath(workspace, from, to, overwrite = false) {
|
|
23
|
-
if (from === to) throw workspaceError("[vitehub] Source and destination must be different.");
|
|
24
|
-
const source = await workspace.stat(from);
|
|
25
|
-
if (source.type === "directory" && to.startsWith(`${from}/`)) throw workspaceError("[vitehub] Destination cannot be nested inside the source directory.");
|
|
26
|
-
if (from.startsWith(`${to}/`)) throw workspaceError("[vitehub] Destination cannot contain the source.");
|
|
27
|
-
if (overwrite && await (await resolveWorkspaceStoreTarget(workspace))?.containsPath?.(to, from)) throw workspaceError("[vitehub] Destination cannot contain the source.");
|
|
28
|
-
await ensureMissingOrReplaceable(workspace, to, overwrite);
|
|
29
|
-
if (source.type === "file") {
|
|
30
|
-
const content = await workspace.readFile(from, { encoding: "binary" });
|
|
31
|
-
await workspace.writeFile(to, content, { mediaType: source.mediaType });
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const entries = await workspace.list(from, { recursive: true });
|
|
35
|
-
await workspace.mkdir(to, { recursive: true });
|
|
36
|
-
const directories = entries.filter((entry) => entry.type === "directory").sort((left, right) => left.path.length - right.path.length);
|
|
37
|
-
for (const entry of directories) await workspace.mkdir(posix.join(to, posix.relative(from, entry.path)), { recursive: true });
|
|
38
|
-
await Promise.all(entries.filter((entry) => entry.type === "file").map(async (entry) => {
|
|
39
|
-
const content = await workspace.readFile(entry.path, { encoding: "binary" });
|
|
40
|
-
await workspace.writeFile(posix.join(to, posix.relative(from, entry.path)), content, { mediaType: entry.mediaType });
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
async function appendWorkspaceFile(workspace, path, content) {
|
|
44
|
-
let current = "";
|
|
45
|
-
try {
|
|
46
|
-
current = String(await workspace.readFile(path));
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if (!isWorkspaceError(error)) throw error;
|
|
49
|
-
}
|
|
50
|
-
await workspace.writeFile(path, `${current}${content}`);
|
|
51
|
-
}
|
|
52
13
|
// src/core/use.ts
|
|
53
14
|
const workspaceDefinitionSyncStates = /* @__PURE__ */ new WeakMap();
|
|
54
15
|
async function workspaceDefinitionSyncState(workspace) {
|
|
@@ -263,6 +224,7 @@ function createLazyWorkspace(name, definition, options = {}) {
|
|
|
263
224
|
return await (await resolveSyncedWorkspace()).startSession(options);
|
|
264
225
|
}
|
|
265
226
|
};
|
|
227
|
+
attachWorkspaceReplacement(workspace, async (replacement, check) => await requireWorkspaceReplacement(await resolveSyncedWorkspace())(replacement, check));
|
|
266
228
|
provideWorkspaceStoreTarget(workspace, async () => await resolveWorkspaceStoreTarget(await resolveWorkspace()));
|
|
267
229
|
attachWorkspaceMetadataTarget(workspace, async () => await resolveWorkspaceMetadataTarget(await resolveWorkspace()));
|
|
268
230
|
return attachWorkspaceSourceRequestExecution(workspace, { async executeSourceRequest(input) {
|
|
@@ -273,7 +235,7 @@ function createLazyWorkspace(name, definition, options = {}) {
|
|
|
273
235
|
} });
|
|
274
236
|
}
|
|
275
237
|
function createWritableFs(name, workspace) {
|
|
276
|
-
|
|
238
|
+
const fs = attachWorkspaceSourceRequestExecution({
|
|
277
239
|
readFile: async (path, options) => await workspace.readFile(normalizePath(path), options),
|
|
278
240
|
writeFile: async (path, content, options) => await workspace.writeFile(normalizePath(path), content, options),
|
|
279
241
|
appendFile: async (path, content) => await appendWorkspaceFile(workspace, normalizePath(path), content),
|
|
@@ -298,6 +260,8 @@ function createWritableFs(name, workspace) {
|
|
|
298
260
|
},
|
|
299
261
|
copyPath: async (from, to, options) => await copyWorkspacePath(workspace, normalizePath(from), normalizePath(to), options?.overwrite)
|
|
300
262
|
}, getWorkspaceSourceRequestExecution(workspace));
|
|
263
|
+
attachWorkspaceReplacement(fs, requireWorkspaceReplacement(workspace));
|
|
264
|
+
return fs;
|
|
301
265
|
}
|
|
302
266
|
function useOptionalWorkspaceAssets(name) {
|
|
303
267
|
try {
|
|
@@ -479,4 +443,4 @@ function createWorkspaceFileRuntime(name, options) {
|
|
|
479
443
|
function useWorkspaceFiles(name, options) {
|
|
480
444
|
return createWorkspaceFileRuntime(name, options).facade;
|
|
481
445
|
}
|
|
482
|
-
export {
|
|
446
|
+
export { createWorkspaceFileRuntime as n, useWorkspaceFiles as r, createReadonlyFs as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as WorkspaceHistoryDiffOptions, A as WorkspaceAuthor, Cn as WorkspaceSourceSyncResult, D as WorkspaceAssetPath, Dt as WorkspaceName, E as Workspace, Ft as WorkspaceRetainedHistory, Ht as WorkspaceSearchQuery, It as WorkspaceRevision, Jt as WorkspaceSessionOptions, L as WorkspaceDefinition, Lt as WorkspaceRevisionView, N as WorkspaceCapabilities, O as WorkspaceAssets, P as WorkspaceContent, Pt as WorkspaceRebaseOptions, Q as WorkspaceHistoryDeleteRefOptions, Tn as WorkspaceStat, Un as WriteFileOptions, V as WorkspaceEntry, Vt as WorkspaceSearchHit, Wt as WorkspaceSession, Xt as WorkspaceSnapshot, _ as ReadFileResult, at as WorkspaceHistoryListResult, b as RmOptions, bt as WorkspaceMaterializeSourcesResult, c as GlobOptions, ct as WorkspaceHistoryRefOptions, g as ReadFileOptions, gt as WorkspaceLookupName, h as MkdirOptions, it as WorkspaceHistoryListOptions, jn as WorkspaceSyncOptions, l as ListOptions, n as DiffOptions, ot as WorkspaceHistoryReader, st as WorkspaceHistoryRef, vt as WorkspaceMaterializeSourcesOptions, x as SnapshotOptions, z as WorkspaceDiff } from "./types-
|
|
1
|
+
import { $ as WorkspaceHistoryDiffOptions, A as WorkspaceAuthor, Cn as WorkspaceSourceSyncResult, D as WorkspaceAssetPath, Dt as WorkspaceName, E as Workspace, Ft as WorkspaceRetainedHistory, Ht as WorkspaceSearchQuery, It as WorkspaceRevision, Jt as WorkspaceSessionOptions, L as WorkspaceDefinition, Lt as WorkspaceRevisionView, N as WorkspaceCapabilities, O as WorkspaceAssets, P as WorkspaceContent, Pt as WorkspaceRebaseOptions, Q as WorkspaceHistoryDeleteRefOptions, Tn as WorkspaceStat, Un as WriteFileOptions, V as WorkspaceEntry, Vt as WorkspaceSearchHit, Wt as WorkspaceSession, Xt as WorkspaceSnapshot, _ as ReadFileResult, at as WorkspaceHistoryListResult, b as RmOptions, bt as WorkspaceMaterializeSourcesResult, c as GlobOptions, ct as WorkspaceHistoryRefOptions, g as ReadFileOptions, gt as WorkspaceLookupName, h as MkdirOptions, it as WorkspaceHistoryListOptions, jn as WorkspaceSyncOptions, l as ListOptions, n as DiffOptions, ot as WorkspaceHistoryReader, st as WorkspaceHistoryRef, vt as WorkspaceMaterializeSourcesOptions, x as SnapshotOptions, z as WorkspaceDiff } from "./types-BnSUug2v.js";
|
|
2
2
|
import { ExecutionBudget } from "@vite-hub/runtime";
|
|
3
3
|
import { Tool, ToolSet } from "ai";
|
|
4
4
|
type ShellObservationEvent = "command_finished" | "command_timed_out" | "policy_denied" | "session_disposed";
|