@vite-hub/workspace 0.0.3 → 0.1.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/LICENSE +201 -0
- package/README.md +236 -58
- package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/host-CFnrTXTK.js +1086 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +76 -64
- package/dist/index.js +162 -457
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +10 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-Bp-8UUfG.js +129 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
- package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
- package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +9 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +84 -15
- package/dist/runtime.js +561 -108
- package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -355
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +7 -1
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CO62GglH.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
- package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
- package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/workspace-6pxkOuxr.js +1286 -0
- package/dist/workspace-BWJQBK1u.d.ts +7 -0
- package/package.json +90 -59
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-CDoyls2X.js +0 -30
- package/dist/config-CZLO0m9h.js +0 -7811
- package/dist/file-CHfsZpso.js +0 -23
- package/dist/glob-D0vD_wRY.js +0 -17
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/provider-C3_elpEh.js +0 -599
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/shared-jfogBrd5.js +0 -273
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
- package/dist/workspace-66SKyiec.d.ts +0 -6
- package/dist/workspace-C4k92Ow8.js +0 -1460
|
@@ -1,12 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { r as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import {
|
|
1
|
+
import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
+
import { c as normalizeSafeWorkspacePattern, f as sha256 } from "./path-CNAwN7pw.js";
|
|
3
|
+
import { r as workspaceStoreTarget, t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
4
|
+
import { a as copyWorkspacePath, i as appendWorkspaceFile, t as createWorkspaceTools } from "./ai-BZyLwULx.js";
|
|
5
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
|
|
6
|
+
import { r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-Dk9rY-Yh.js";
|
|
7
|
+
import { d as normalizeHistoryRef, f as requireWorkspaceHistory, l as historyConflict, p as validateHistoryMessage } from "./utils-Blrh4N2n.js";
|
|
8
|
+
import { i as assertPublicWorkspaceMetaKey, t as createWorkspace } from "./workspace-6pxkOuxr.js";
|
|
9
|
+
import { c as workspaceInternalMetadataCapability, o as resolveWorkspaceMetadataTarget, r as forwardWorkspaceMetadataTarget, t as attachWorkspaceMetadataTarget } from "./metadata-target-DZEZQGHA.js";
|
|
10
|
+
import { n as useWorkspaceAssets } from "./asset-registry-DfBV5kmw.js";
|
|
11
|
+
import { a as useRegisteredWorkspace } from "./registry-Bp-8UUfG.js";
|
|
12
|
+
import { t as createHostedWorkspaceSession } from "./host-CFnrTXTK.js";
|
|
8
13
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
9
14
|
//#region src/core/use.ts
|
|
15
|
+
const workspaceDefinitionSyncStates = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
async function workspaceDefinitionSyncState(workspace) {
|
|
17
|
+
const owner = await resolveWorkspaceMetadataTarget(workspace) ?? workspace;
|
|
18
|
+
const key = workspace.__workspaceDefinitionSyncKey ?? workspace;
|
|
19
|
+
let states = workspaceDefinitionSyncStates.get(owner);
|
|
20
|
+
if (!states) {
|
|
21
|
+
states = /* @__PURE__ */ new WeakMap();
|
|
22
|
+
workspaceDefinitionSyncStates.set(owner, states);
|
|
23
|
+
}
|
|
24
|
+
let state = states.get(key);
|
|
25
|
+
if (!state) {
|
|
26
|
+
state = {};
|
|
27
|
+
states.set(key, state);
|
|
28
|
+
}
|
|
29
|
+
return state;
|
|
30
|
+
}
|
|
31
|
+
async function waitForWorkspaceSync(pending, signal) {
|
|
32
|
+
if (!signal) return await pending;
|
|
33
|
+
signal.throwIfAborted();
|
|
34
|
+
let onAbort;
|
|
35
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
36
|
+
onAbort = () => reject(signal.reason);
|
|
37
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
return await Promise.race([pending, aborted]);
|
|
41
|
+
} finally {
|
|
42
|
+
signal.removeEventListener("abort", onAbort);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
10
45
|
function normalizePath(path, allowEmpty = false) {
|
|
11
46
|
const reserved = normalizeSafeWorkspacePath(path, {
|
|
12
47
|
allowEmpty,
|
|
@@ -37,43 +72,106 @@ async function materializeWorkspaceSources(workspace, options) {
|
|
|
37
72
|
if (!workspace.materializeSources) throw workspaceError("[vitehub] Workspace source materialization is unavailable.");
|
|
38
73
|
return await workspace.materializeSources(options);
|
|
39
74
|
}
|
|
40
|
-
function createLazyWorkspace(name, definition) {
|
|
75
|
+
function createLazyWorkspace(name, definition, options = {}) {
|
|
41
76
|
let workspacePromise;
|
|
42
|
-
let syncPromise;
|
|
43
77
|
async function resolveWorkspace() {
|
|
44
|
-
workspacePromise ||= definition ? Promise.resolve(createWorkspace(definition)) : useRegisteredWorkspace(name);
|
|
78
|
+
workspacePromise ||= definition ? Promise.resolve(createWorkspace(definition, options)) : useRegisteredWorkspace(name, options);
|
|
45
79
|
return await workspacePromise;
|
|
46
80
|
}
|
|
47
|
-
async function resolveSyncedWorkspace() {
|
|
81
|
+
async function resolveSyncedWorkspace(abortSignal) {
|
|
48
82
|
const workspace = await resolveWorkspace();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
83
|
+
const sync = await workspaceDefinitionSyncState(workspace);
|
|
84
|
+
while (true) {
|
|
85
|
+
if (sync.explicitPromise) {
|
|
86
|
+
const explicit = sync.explicitPromise;
|
|
87
|
+
await waitForWorkspaceSync(explicit, abortSignal);
|
|
88
|
+
if (sync.explicitPromise === explicit) sync.explicitPromise = void 0;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!sync.promise) {
|
|
92
|
+
const next = workspace.__syncWorkspaceDefinition?.(abortSignal) ?? Promise.resolve();
|
|
93
|
+
sync.promise = next;
|
|
94
|
+
sync.abortSignal = abortSignal;
|
|
95
|
+
next.catch(() => {
|
|
96
|
+
if (sync.promise === next) {
|
|
97
|
+
sync.promise = void 0;
|
|
98
|
+
sync.abortSignal = void 0;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const current = sync.promise;
|
|
103
|
+
const currentAbortSignal = sync.abortSignal;
|
|
104
|
+
try {
|
|
105
|
+
await waitForWorkspaceSync(current, abortSignal);
|
|
106
|
+
return workspace;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (abortSignal?.aborted) {
|
|
109
|
+
if (abortSignal === currentAbortSignal) await current.catch(() => {});
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
if (!currentAbortSignal?.aborted) throw error;
|
|
113
|
+
if (sync.promise === current) {
|
|
114
|
+
sync.promise = void 0;
|
|
115
|
+
sync.abortSignal = void 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
55
118
|
}
|
|
56
|
-
await syncPromise;
|
|
57
|
-
return workspace;
|
|
58
119
|
}
|
|
59
|
-
|
|
120
|
+
const workspace = {
|
|
60
121
|
name,
|
|
122
|
+
history: {
|
|
123
|
+
digest: async (bytes) => {
|
|
124
|
+
const history = (await resolveWorkspace()).history;
|
|
125
|
+
return history?.digest ? await history.digest(bytes) : await sha256(bytes);
|
|
126
|
+
},
|
|
127
|
+
forksFrom: async (ref) => await (await resolveWorkspace()).history?.forksFrom?.(ref),
|
|
128
|
+
pullRequests: async (options) => await (await resolveWorkspace()).history?.pullRequests?.(options) ?? [],
|
|
129
|
+
merge: async (options) => {
|
|
130
|
+
const history = (await resolveWorkspace()).history;
|
|
131
|
+
if (!history?.merge) throw workspaceError("[vitehub] This Workspace Store cannot merge refs.");
|
|
132
|
+
return await history.merge(options);
|
|
133
|
+
},
|
|
134
|
+
openPullRequest: async (options) => {
|
|
135
|
+
const history = (await resolveWorkspace()).history;
|
|
136
|
+
if (!history?.openPullRequest) throw workspaceError("[vitehub] This Workspace Store cannot open pull requests.");
|
|
137
|
+
return await history.openPullRequest(options);
|
|
138
|
+
},
|
|
139
|
+
head: async (options) => await requireWorkspaceHistory(await resolveWorkspace()).head(options),
|
|
140
|
+
list: async (options) => await requireWorkspaceHistory(await resolveWorkspace()).list(options),
|
|
141
|
+
refs: async () => await requireWorkspaceHistory(await resolveWorkspace()).refs(),
|
|
142
|
+
open: async (id) => await requireWorkspaceHistory(await resolveWorkspace()).open(id),
|
|
143
|
+
usage: async () => await requireWorkspaceHistory(await resolveWorkspace()).usage(),
|
|
144
|
+
commit: async (options) => {
|
|
145
|
+
const history = requireWorkspaceHistory(await resolveWorkspace());
|
|
146
|
+
validateHistoryMessage(options.message);
|
|
147
|
+
const ref = normalizeHistoryRef(options.ref);
|
|
148
|
+
const head = await history.head({ ref });
|
|
149
|
+
if ((head?.id ?? null) !== options.ifHead) throw historyConflict(ref, options.ifHead, head?.id ?? null);
|
|
150
|
+
return await requireWorkspaceHistory(await resolveSyncedWorkspace()).commit(options);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
async capabilities() {
|
|
154
|
+
return await (await resolveWorkspace()).capabilities?.() ?? { conditionalWrites: false };
|
|
155
|
+
},
|
|
61
156
|
async [workspaceStoreTarget]() {
|
|
62
157
|
return await (await resolveWorkspace())[workspaceStoreTarget]?.();
|
|
63
158
|
},
|
|
64
159
|
async sync(options) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
next.
|
|
68
|
-
|
|
69
|
-
|
|
160
|
+
const resolved = await resolveWorkspace();
|
|
161
|
+
const sync = await workspaceDefinitionSyncState(resolved);
|
|
162
|
+
const next = resolved.sync(options);
|
|
163
|
+
const pending = next.then(() => void 0);
|
|
164
|
+
sync.explicitPromise = pending;
|
|
165
|
+
pending.finally(() => {
|
|
166
|
+
if (sync.explicitPromise === pending) sync.explicitPromise = void 0;
|
|
167
|
+
}).catch(() => void 0);
|
|
70
168
|
return await next;
|
|
71
169
|
},
|
|
72
170
|
async readFile(path, options) {
|
|
73
171
|
return await (await resolveSyncedWorkspace()).readFile(normalizePath(path), options);
|
|
74
172
|
},
|
|
75
173
|
async writeFile(path, content, options) {
|
|
76
|
-
await (await resolveSyncedWorkspace()).writeFile(normalizePath(path), content, options);
|
|
174
|
+
return await (await resolveSyncedWorkspace()).writeFile(normalizePath(path), content, options);
|
|
77
175
|
},
|
|
78
176
|
async list(path, options) {
|
|
79
177
|
return await (await resolveSyncedWorkspace()).list(path ? normalizeListPath(path) : "", options);
|
|
@@ -101,34 +199,39 @@ function createLazyWorkspace(name, definition) {
|
|
|
101
199
|
await (await resolveSyncedWorkspace()).rm(normalizePath(path), options);
|
|
102
200
|
},
|
|
103
201
|
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);
|
|
202
|
+
return await materializeWorkspaceSources(await resolveSyncedWorkspace(options?.abortSignal), options);
|
|
109
203
|
},
|
|
110
204
|
async snapshot(options) {
|
|
111
205
|
return await (await resolveSyncedWorkspace()).snapshot(options);
|
|
112
206
|
},
|
|
207
|
+
async rebase(options) {
|
|
208
|
+
await (await resolveSyncedWorkspace()).rebase({
|
|
209
|
+
...options,
|
|
210
|
+
takeRemote: options?.takeRemote?.map((path) => normalizePath(path))
|
|
211
|
+
});
|
|
212
|
+
},
|
|
113
213
|
async diff(options) {
|
|
114
214
|
return await (await resolveSyncedWorkspace()).diff(options);
|
|
115
215
|
},
|
|
116
216
|
async getMeta(key) {
|
|
117
217
|
return await (await resolveWorkspace()).getMeta?.(key);
|
|
118
218
|
},
|
|
119
|
-
async setMeta(key, value) {
|
|
120
|
-
await (await resolveWorkspace()).setMeta?.(key, value);
|
|
219
|
+
async setMeta(key, value, capability) {
|
|
220
|
+
await (await resolveWorkspace()).setMeta?.(capability === workspaceInternalMetadataCapability ? key : assertPublicWorkspaceMetaKey(key), value, capability);
|
|
121
221
|
},
|
|
122
222
|
async startSession(options) {
|
|
123
223
|
return await (await resolveSyncedWorkspace()).startSession(options);
|
|
124
224
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
225
|
+
};
|
|
226
|
+
attachWorkspaceMetadataTarget(workspace, async () => await resolveWorkspaceMetadataTarget(await resolveWorkspace()));
|
|
227
|
+
return attachWorkspaceSourceRequestExecution(workspace, { async executeSourceRequest(input) {
|
|
228
|
+
const resolved = await resolveSyncedWorkspace();
|
|
229
|
+
const executor = getWorkspaceSourceRequestExecution(resolved);
|
|
230
|
+
if (!executor) throw workspaceErrorDiagnostics.WORKSPACE_R0025({ message: "[vitehub] No API-backed Source request executor is available for this workspace." });
|
|
128
231
|
return await executor.executeSourceRequest(input);
|
|
129
232
|
} });
|
|
130
233
|
}
|
|
131
|
-
function createWritableFs(workspace) {
|
|
234
|
+
function createWritableFs(name, workspace) {
|
|
132
235
|
return attachWorkspaceSourceRequestExecution({
|
|
133
236
|
readFile: async (path, options) => await workspace.readFile(normalizePath(path), options),
|
|
134
237
|
writeFile: async (path, content, options) => await workspace.writeFile(normalizePath(path), content, options),
|
|
@@ -191,7 +294,8 @@ function mergeSearchHits(primary = [], fallback = []) {
|
|
|
191
294
|
}
|
|
192
295
|
function createReadonlyFs(name, workspace) {
|
|
193
296
|
const assets = useOptionalWorkspaceAssets(name);
|
|
194
|
-
|
|
297
|
+
let readonlyFs;
|
|
298
|
+
readonlyFs = attachWorkspaceSourceRequestExecution({
|
|
195
299
|
readFile: async (path, options) => {
|
|
196
300
|
const normalized = normalizePath(path);
|
|
197
301
|
try {
|
|
@@ -246,8 +350,37 @@ function createReadonlyFs(name, workspace) {
|
|
|
246
350
|
path: options?.path || "",
|
|
247
351
|
sources: []
|
|
248
352
|
},
|
|
249
|
-
startSession: async (options) =>
|
|
353
|
+
startSession: async (options) => {
|
|
354
|
+
if (!assets || !options?.host) return await workspace.startSession(options);
|
|
355
|
+
const overlay = Object.assign(Object.create(workspace), {
|
|
356
|
+
exists: readonlyFs.exists,
|
|
357
|
+
glob: readonlyFs.glob,
|
|
358
|
+
list: readonlyFs.list,
|
|
359
|
+
readFile: readonlyFs.readFile,
|
|
360
|
+
search: readonlyFs.search,
|
|
361
|
+
stat: readonlyFs.stat
|
|
362
|
+
});
|
|
363
|
+
return await createHostedWorkspaceSession(overlay, {
|
|
364
|
+
...options,
|
|
365
|
+
host: options.host
|
|
366
|
+
});
|
|
367
|
+
}
|
|
250
368
|
}, getWorkspaceSourceRequestExecution(workspace));
|
|
369
|
+
attachWorkspaceMetadataTarget(readonlyFs, async () => {
|
|
370
|
+
const metadata = await ignoreMissingWorkspace(async () => await resolveWorkspaceMetadataTarget(workspace));
|
|
371
|
+
if (!metadata && !assets) return;
|
|
372
|
+
const target = {
|
|
373
|
+
workspaceName: metadata?.workspaceName,
|
|
374
|
+
getMeta: metadata?.getMeta?.bind(metadata),
|
|
375
|
+
list: async (path, options) => {
|
|
376
|
+
const assetPath = path;
|
|
377
|
+
return mergeEntries(assets ? await assets.list(assetPath, options) : [], await metadata?.list?.(path, options) ?? []);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
if (metadata) forwardWorkspaceStoreTarget(metadata, target);
|
|
381
|
+
return target;
|
|
382
|
+
});
|
|
383
|
+
return readonlyFs;
|
|
251
384
|
}
|
|
252
385
|
function toReadOperations(options) {
|
|
253
386
|
return {
|
|
@@ -285,6 +418,7 @@ function useWorkspace(name, options) {
|
|
|
285
418
|
maxShellCalls: opts?.maxShellCalls,
|
|
286
419
|
maxOutputLength: opts?.maxOutputLength,
|
|
287
420
|
operations: toWriteOperations(opts),
|
|
421
|
+
sourceRequests: opts?.sourceRequests,
|
|
288
422
|
timeout: opts?.timeout
|
|
289
423
|
});
|
|
290
424
|
const createReadTools = (opts) => createWorkspaceTools(createReadonlyFs(name, workspace), {
|
|
@@ -293,44 +427,65 @@ function useWorkspace(name, options) {
|
|
|
293
427
|
maxShellCalls: opts?.maxShellCalls,
|
|
294
428
|
maxOutputLength: opts?.maxOutputLength,
|
|
295
429
|
operations: toReadOperations(opts),
|
|
430
|
+
sourceRequests: opts?.sourceRequests,
|
|
296
431
|
timeout: opts?.timeout
|
|
297
432
|
});
|
|
298
433
|
const tools = createDefaultToolSet(createTools);
|
|
299
434
|
tools.inspect = createReadTools;
|
|
300
435
|
tools.write = createTools;
|
|
301
436
|
tools.none = emptyTools;
|
|
302
|
-
|
|
437
|
+
const facade = {
|
|
303
438
|
[workspaceStoreTarget]: async () => {
|
|
304
439
|
return await workspace[workspaceStoreTarget]?.();
|
|
305
440
|
},
|
|
441
|
+
capabilities: async () => await workspace.capabilities(),
|
|
306
442
|
diff: async (options) => await workspace.diff(options),
|
|
307
|
-
fs: createWritableFs(workspace),
|
|
443
|
+
fs: createWritableFs(name, workspace),
|
|
444
|
+
history: {
|
|
445
|
+
...workspace.history,
|
|
446
|
+
checkpoint: async (options) => await workspace.snapshot({ name: options?.message }),
|
|
447
|
+
rebase: async (options) => await workspace.rebase(options)
|
|
448
|
+
},
|
|
308
449
|
getMeta: async (key) => await workspace.getMeta?.(key),
|
|
309
450
|
materializeSources: async (options) => await materializeWorkspaceSources(workspace, options),
|
|
310
|
-
|
|
311
|
-
setMeta: async (key, value) => await workspace.setMeta?.(key, value),
|
|
451
|
+
setMeta: async (key, value, capability) => await workspace.setMeta?.(key, value, capability),
|
|
312
452
|
snapshot: async (options) => await workspace.snapshot(options),
|
|
313
453
|
startSession: async (options) => await workspace.startSession(options),
|
|
314
454
|
sync: async (options) => await workspace.sync(options),
|
|
315
455
|
tools
|
|
316
456
|
};
|
|
457
|
+
forwardWorkspaceMetadataTarget(workspace, facade);
|
|
458
|
+
return facade;
|
|
317
459
|
}
|
|
318
|
-
const
|
|
460
|
+
const workspace = createLazyWorkspace(name, options?.definition, { reuseStartupSnapshots: options?.refresh === false });
|
|
461
|
+
const fs = createReadonlyFs(name, workspace);
|
|
319
462
|
const createTools = (opts) => createWorkspaceTools(fs, {
|
|
320
463
|
broadSearchPaths: opts?.broadSearchPaths,
|
|
321
464
|
cwd: opts?.cwd,
|
|
322
465
|
maxShellCalls: opts?.maxShellCalls,
|
|
323
466
|
maxOutputLength: opts?.maxOutputLength,
|
|
324
467
|
operations: toReadOperations(opts),
|
|
468
|
+
sourceRequests: opts?.sourceRequests,
|
|
325
469
|
timeout: opts?.timeout
|
|
326
470
|
});
|
|
327
471
|
const tools = createDefaultToolSet(createTools);
|
|
328
472
|
tools.inspect = createTools;
|
|
329
473
|
tools.none = emptyTools;
|
|
330
|
-
|
|
474
|
+
const facade = {
|
|
331
475
|
fs,
|
|
476
|
+
history: {
|
|
477
|
+
head: (options) => requireWorkspaceHistory(workspace).head(options),
|
|
478
|
+
list: (options) => requireWorkspaceHistory(workspace).list(options),
|
|
479
|
+
refs: () => requireWorkspaceHistory(workspace).refs(),
|
|
480
|
+
open: (id) => requireWorkspaceHistory(workspace).open(id),
|
|
481
|
+
usage: () => requireWorkspaceHistory(workspace).usage()
|
|
482
|
+
},
|
|
483
|
+
getMeta: async (key) => await workspace.getMeta?.(key),
|
|
332
484
|
tools
|
|
333
485
|
};
|
|
486
|
+
forwardWorkspaceMetadataTarget(fs, facade);
|
|
487
|
+
forwardWorkspaceStoreTarget(workspace, facade);
|
|
488
|
+
return facade;
|
|
334
489
|
}
|
|
335
490
|
//#endregion
|
|
336
491
|
export { useWorkspace as t };
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import { D as WorkspaceAssets, E as WorkspaceAssetPath,
|
|
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, F as WorkspaceDefinition, Ft as WorkspaceSearchHit, Ht as WorkspaceSessionOptions, In as WriteFileOptions, It as WorkspaceSearchQuery, L as WorkspaceDiff, M as WorkspaceContent, Ot as WorkspaceRebaseOptions, Rt as WorkspaceSession, St as WorkspaceName, Tn as WorkspaceSyncOptions, Wt as WorkspaceSnapshot, _ as ReadFileResult, _n as WorkspaceSourceSyncResult, b as RmOptions, c as GlobOptions, ft as WorkspaceMaterializeSourcesOptions, g as ReadFileOptions, h as MkdirOptions, j as WorkspaceCapabilities, kt as WorkspaceRetainedHistory, l as ListOptions, mt as WorkspaceMaterializeSourcesResult, n as DiffOptions, nt as WorkspaceHistoryReader, x as SnapshotOptions, yn as WorkspaceStat, z as WorkspaceEntry } from "./types-DeK9GIxy.js";
|
|
2
|
+
import { a as WorkspaceReadOperations, d as WorkspaceWriteToolMap, n as ShellEnabled, o as WorkspaceShellResult, u as WorkspaceWriteOperations } from "./ai-BW2ZhizI.js";
|
|
3
|
+
import { ExecutionBudget } from "@vite-hub/runtime";
|
|
3
4
|
import { Tool, ToolSet } from "ai";
|
|
4
|
-
|
|
5
5
|
//#region src/core/use.d.ts
|
|
6
6
|
type WorkspaceWritablePath<Name extends WorkspaceName> = WorkspaceAssetPath<Name> | (string & {});
|
|
7
7
|
interface UseWorkspaceOptions {
|
|
8
8
|
definition?: WorkspaceDefinition;
|
|
9
9
|
mode?: "read" | "write";
|
|
10
|
+
refresh?: boolean;
|
|
10
11
|
}
|
|
11
12
|
interface WorkspaceFacadeToolOptions extends WorkspaceReadOperations {
|
|
12
13
|
broadSearchPaths?: string[];
|
|
13
14
|
cwd?: string;
|
|
15
|
+
executionBudget?: ExecutionBudget;
|
|
14
16
|
maxShellCalls?: number;
|
|
15
17
|
maxOutputLength?: number;
|
|
18
|
+
sourceRequests?: boolean;
|
|
16
19
|
timeout?: number;
|
|
17
20
|
}
|
|
18
21
|
interface WritableWorkspaceFacadeToolOptions extends WorkspaceFacadeToolOptions, WorkspaceWriteOperations {}
|
|
19
22
|
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
|
|
23
|
+
type WorkspaceReadTools<Options = undefined> = ((ShellEnabled<Options, Options extends {
|
|
24
|
+
sourceRequests: true;
|
|
25
|
+
} ? true : false> extends true ? {
|
|
21
26
|
shell: Tool<{
|
|
22
27
|
command: string;
|
|
23
28
|
}, WorkspaceShellResult>;
|
|
@@ -29,7 +34,7 @@ type WorkspaceReadTools<Options = undefined> = ((ShellEnabled<Options> extends t
|
|
|
29
34
|
sources?: string[];
|
|
30
35
|
}, WorkspaceMaterializeSourcesResult>;
|
|
31
36
|
} : {}) & ToolSet);
|
|
32
|
-
type WorkspaceWriteTools<Options = undefined> = WorkspaceReadTools<Options> & { [Key in keyof WorkspaceWriteToolMap as EnabledWriteCapability<Options, Key> extends true ? Key : never]: WorkspaceWriteToolMap[Key] } & ToolSet;
|
|
37
|
+
type WorkspaceWriteTools<Options = undefined> = WorkspaceReadTools<Options> & { [Key in keyof WorkspaceWriteToolMap as EnabledWriteCapability<Options, Key> extends true ? Key : never]: WorkspaceWriteToolMap[Key]; } & ToolSet;
|
|
33
38
|
type WorkspaceReadToolSet = WorkspaceReadTools & {
|
|
34
39
|
inspect: <Options extends WorkspaceFacadeToolOptions | undefined = undefined>(options?: Options) => WorkspaceReadTools<Options>;
|
|
35
40
|
none: () => ToolSet;
|
|
@@ -40,9 +45,20 @@ type WorkspaceWriteToolSet = WorkspaceWriteTools & {
|
|
|
40
45
|
write: <Options extends WritableWorkspaceFacadeToolOptions | undefined = undefined>(options?: Options) => WorkspaceWriteTools<Options>;
|
|
41
46
|
};
|
|
42
47
|
type ReadonlyWorkspaceFs<Name extends WorkspaceName = WorkspaceName> = WorkspaceAssets<WorkspaceAssetPath<Name>>;
|
|
48
|
+
interface HistoryCheckpoint {
|
|
49
|
+
createdAt: string;
|
|
50
|
+
id: string;
|
|
51
|
+
name?: string;
|
|
52
|
+
}
|
|
53
|
+
interface HistoryCheckpointOptions {
|
|
54
|
+
message?: string;
|
|
55
|
+
}
|
|
56
|
+
interface History<TCheckpoint extends HistoryCheckpoint = HistoryCheckpoint> {
|
|
57
|
+
checkpoint(options?: HistoryCheckpointOptions): Promise<TCheckpoint>;
|
|
58
|
+
}
|
|
43
59
|
interface WritableWorkspaceFs<Name extends WorkspaceName = WorkspaceName> {
|
|
44
60
|
readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: WorkspaceWritablePath<Name>, options?: TOptions): Promise<ReadFileResult<TOptions>>;
|
|
45
|
-
writeFile(path: WorkspaceWritablePath<Name>, content: WorkspaceContent, options?: WriteFileOptions): Promise<
|
|
61
|
+
writeFile(path: WorkspaceWritablePath<Name>, content: WorkspaceContent, options?: WriteFileOptions): Promise<string>;
|
|
46
62
|
appendFile(path: WorkspaceWritablePath<Name>, content: string): Promise<void>;
|
|
47
63
|
stat(path: WorkspaceWritablePath<Name>): Promise<WorkspaceStat>;
|
|
48
64
|
exists(path: WorkspaceWritablePath<Name>): Promise<boolean>;
|
|
@@ -60,15 +76,21 @@ interface WritableWorkspaceFs<Name extends WorkspaceName = WorkspaceName> {
|
|
|
60
76
|
}
|
|
61
77
|
interface ReadonlyWorkspaceFacade<Name extends WorkspaceName = WorkspaceName> {
|
|
62
78
|
fs: ReadonlyWorkspaceFs<Name>;
|
|
79
|
+
history: WorkspaceHistoryReader;
|
|
80
|
+
getMeta?(key: string): Promise<unknown>;
|
|
63
81
|
tools: WorkspaceReadToolSet;
|
|
64
82
|
}
|
|
83
|
+
interface WorkspaceHistory extends History<WorkspaceSnapshot>, WorkspaceRetainedHistory {
|
|
84
|
+
rebase(options?: WorkspaceRebaseOptions): Promise<void>;
|
|
85
|
+
}
|
|
65
86
|
interface WritableWorkspaceFacade<Name extends WorkspaceName = WorkspaceName> {
|
|
87
|
+
capabilities(): Promise<WorkspaceCapabilities>;
|
|
66
88
|
diff(options?: DiffOptions): Promise<WorkspaceDiff>;
|
|
67
89
|
fs: WritableWorkspaceFs<Name>;
|
|
90
|
+
history: WorkspaceHistory;
|
|
68
91
|
getMeta?(key: string): Promise<unknown>;
|
|
69
92
|
materializeSources(options?: WorkspaceMaterializeSourcesOptions): Promise<WorkspaceMaterializeSourcesResult>;
|
|
70
|
-
|
|
71
|
-
setMeta?(key: string, value: unknown): Promise<void>;
|
|
93
|
+
setMeta?(key: string, value: unknown, capability?: symbol): Promise<void>;
|
|
72
94
|
snapshot(options?: SnapshotOptions): Promise<WorkspaceSnapshot>;
|
|
73
95
|
startSession(options?: WorkspaceSessionOptions): Promise<WorkspaceSession>;
|
|
74
96
|
sync(options: WorkspaceSyncOptions): Promise<WorkspaceSourceSyncResult>;
|
|
@@ -76,11 +98,11 @@ interface WritableWorkspaceFacade<Name extends WorkspaceName = WorkspaceName> {
|
|
|
76
98
|
}
|
|
77
99
|
type WorkspaceFacade<Name extends WorkspaceName = WorkspaceName, Mode extends UseWorkspaceOptions["mode"] = "read"> = Mode extends "write" ? WritableWorkspaceFacade<Name> : ReadonlyWorkspaceFacade<Name>;
|
|
78
100
|
declare function useWorkspace<Name extends WorkspaceName>(name: Name): ReadonlyWorkspaceFacade<Name>;
|
|
79
|
-
declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: {
|
|
80
|
-
mode
|
|
101
|
+
declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: UseWorkspaceOptions & {
|
|
102
|
+
mode?: "read";
|
|
81
103
|
}): ReadonlyWorkspaceFacade<Name>;
|
|
82
|
-
declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: {
|
|
104
|
+
declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: UseWorkspaceOptions & {
|
|
83
105
|
mode: "write";
|
|
84
106
|
}): WritableWorkspaceFacade<Name>;
|
|
85
107
|
//#endregion
|
|
86
|
-
export {
|
|
108
|
+
export { useWorkspace as _, ReadonlyWorkspaceFs as a, WorkspaceFacadeToolOptions as c, WorkspaceReadTools as d, WorkspaceWriteToolSet as f, WritableWorkspaceFs as g, WritableWorkspaceFacadeToolOptions as h, ReadonlyWorkspaceFacade as i, WorkspaceHistory as l, WritableWorkspaceFacade as m, HistoryCheckpoint as n, UseWorkspaceOptions as o, WorkspaceWriteTools as p, HistoryCheckpointOptions as r, WorkspaceFacade as s, History as t, WorkspaceReadToolSet as u };
|