@vite-hub/workspace 0.0.2 → 0.0.4

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.
Files changed (95) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +48 -2
  3. package/dist/{ai-Cztw4eLk.js → ai-BqCC8BpY.js} +15 -4
  4. package/dist/{ai-hFdsvDHC.d.ts → ai-CjxvGqM0.d.ts} +1 -1
  5. package/dist/ai.d.ts +2 -2
  6. package/dist/ai.js +1 -1
  7. package/dist/{asset-registry-CaG9b7tf.js → asset-registry-8QI3ML3K.js} +1 -1
  8. package/dist/chunk-2rV9d50f.js +35 -0
  9. package/dist/cloudflare.d.ts +4 -2
  10. package/dist/cloudflare.js +1 -2
  11. package/dist/collections.d.ts +2 -2
  12. package/dist/collections.js +1 -1
  13. package/dist/{config--r5unwPc.js → config-Bc3c4Su1.js} +213 -120
  14. package/dist/{config-DCQ6y30R.js → config-CHLLWklZ.js} +9 -3
  15. package/dist/{config-Ca5DM8fF.d.ts → config-DE9xlaIw.d.ts} +1 -1
  16. package/dist/{file-B2q9NE18.js → file-Bc1X7pco.js} +9 -10
  17. package/dist/{files-xy0le-_U.js → files-Q6xZjDHA.js} +20 -9
  18. package/dist/{github-lIO6-2sH.js → github-DHnjxQIX.js} +27 -23
  19. package/dist/glob-CEZKeZFC.js +18 -0
  20. package/dist/host-DJH8cuoU.js +1030 -0
  21. package/dist/{artifacts-store-BAV9jZpd.js → hosted-RPeJOCFz.js} +146 -30
  22. package/dist/hosted-vercel-blob-d6C8ND5j.js +23580 -0
  23. package/dist/hosted-vercel-blob.d.ts +1 -1
  24. package/dist/hosted-vercel-blob.js +1 -25
  25. package/dist/hosted.d.ts +1 -1
  26. package/dist/hosted.js +1 -29
  27. package/dist/index.d.ts +61 -78
  28. package/dist/index.js +133 -435
  29. package/dist/lifecycle-LrL3sA4n.js +316 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/metadata-target-B0tOmVW7.js +717 -0
  33. package/dist/mountx.d.ts +10 -0
  34. package/dist/mountx.js +143 -0
  35. package/dist/nitro.d.ts +1 -1
  36. package/dist/nitro.js +1 -1
  37. package/dist/nuxt.d.ts +1 -1
  38. package/dist/nuxt.js +8 -2
  39. package/dist/{path-CNI6wKIU.js → path-Cp59koVz.js} +28 -4
  40. package/dist/{provider-CeQciesl.js → provider-B1yLjCJJ.js} +194 -47
  41. package/dist/providers/github/store.d.ts +1 -1
  42. package/dist/providers/github/store.js +1 -361
  43. package/dist/publish.d.ts +1 -1
  44. package/dist/publish.js +2 -2
  45. package/dist/registry-D3yzt8HQ.js +127 -0
  46. package/dist/{registry-CoC9JxVt.d.ts → registry-Uj6IVxes.d.ts} +3 -3
  47. package/dist/{request-execution-C8qRcReq.js → request-execution-B-dSFlGB.js} +8 -4
  48. package/dist/runtime/assets.d.ts +1 -1
  49. package/dist/runtime/assets.js +4 -2
  50. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  51. package/dist/runtime/empty-registry.d.ts +1 -1
  52. package/dist/runtime/state.d.ts +4 -4
  53. package/dist/runtime/state.js +10 -7
  54. package/dist/runtime/workspace.d.ts +1 -1
  55. package/dist/runtime/workspace.js +1 -1
  56. package/dist/runtime-options-BsPSv5O7.js +13 -0
  57. package/dist/runtime-type-iEE6BjQJ.js +34 -0
  58. package/dist/runtime.d.ts +42 -7
  59. package/dist/runtime.js +276 -100
  60. package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
  61. package/dist/server.d.ts +2 -2
  62. package/dist/server.js +24 -51
  63. package/dist/{shared-BRycRSbo.js → shared-DTR1Hhma.js} +115 -39
  64. package/dist/source-metadata.d.ts +9 -2
  65. package/dist/source-metadata.js +34 -2
  66. package/dist/{state-DSAHEsq6.d.ts → state-tYcRWEh2.d.ts} +13 -12
  67. package/dist/store-Dt_Jyys3.js +608 -0
  68. package/dist/{sync-DO42ypji.js → sync-DnTQwt8r.js} +6 -5
  69. package/dist/test.d.ts +1 -1
  70. package/dist/test.js +1 -1
  71. package/dist/token-CVzURBxC.js +61 -0
  72. package/dist/{types-DHkae7Cb.d.ts → types-CYuwjJ4V.d.ts} +94 -43
  73. package/dist/{use-d_PlAdOu.js → use-BTNDR5Rd.js} +147 -50
  74. package/dist/{use-D16tf8Ph.d.ts → use-BiHzt0xA.d.ts} +21 -4
  75. package/dist/vite-BptCrpv2.js +4526 -0
  76. package/dist/vite-CtA9guIM.d.ts +66 -0
  77. package/dist/vite.d.ts +2 -50
  78. package/dist/vite.js +2 -2
  79. package/dist/{workspace-n4wBmdaM.js → workspace-Dq08Yn72.js} +224 -545
  80. package/dist/{workspace-f2DBLmPZ.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
  81. package/package.json +20 -38
  82. package/dist/chunk-8H4AJuhK.js +0 -14
  83. package/dist/cli.d.ts +0 -31
  84. package/dist/cli.js +0 -303
  85. package/dist/cloudflare-env-CKxUs2fa.js +0 -20
  86. package/dist/glob-DeH0dzZX.js +0 -23
  87. package/dist/host-I-_vDs05.js +0 -370
  88. package/dist/lifecycle-Lhk3dAMt.js +0 -176
  89. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  90. package/dist/providers/cloudflare/artifacts-store.js +0 -2
  91. package/dist/providers/vercel/blob-store.d.ts +0 -6
  92. package/dist/providers/vercel/blob-store.js +0 -235
  93. package/dist/registry-C7DMdBXN.js +0 -74
  94. package/dist/utils-BPdaCyI6.js +0 -55
  95. package/dist/vite-NWC9mFjI.js +0 -1882
@@ -1,362 +1,2 @@
1
- import { a as matchesAny, c as normalizeWorkspacePath, n as contentStreamToBytes, o as normalizeSafeWorkspacePath, p as workspaceError, s as normalizeSafeWorkspacePattern } from "../../path-CNI6wKIU.js";
2
- import { n as createSnapshotFromEntries, r as diffSnapshots } from "../../utils-BPdaCyI6.js";
3
- import { r as workspaceStoreTarget } from "../../target-D4Bqb1eH.js";
4
- 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-BRycRSbo.js";
5
- import { posix } from "node:path";
6
- //#region src/providers/github/store.ts
7
- function isReservedWorkspacePath(path) {
8
- const root = normalizeWorkspacePath(path).split("/")[0];
9
- return root === ".git" || root === ".vitehub";
10
- }
11
- function contentLength(content) {
12
- return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
13
- }
14
- function gitHubFileMetadata(entry) {
15
- return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
16
- }
17
- function gitHubFileMode(metadata) {
18
- return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
19
- }
20
- function inheritedGitHubFileMetadata(file, current) {
21
- if (file.metadata) return file.metadata;
22
- return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
23
- }
24
- function parentDirectories(path) {
25
- const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
26
- const directories = [];
27
- for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
28
- return directories;
29
- }
30
- function resolveSymlinkTarget(path, bytes) {
31
- const target = gitSymlinkTargetFromBytes(bytes);
32
- if (!target || target.startsWith("/")) return;
33
- const base = path.split("/").slice(0, -1).join("/");
34
- const resolved = posix.normalize(base ? `${base}/${target}` : target);
35
- if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
36
- return normalizeSafeWorkspacePath(resolved);
37
- }
38
- function gitSymlinkTargetFromBytes(bytes) {
39
- return new TextDecoder().decode(bytes).replace(/\0/g, "");
40
- }
41
- var GitHubWorkspaceStore = class {
42
- workspaceName;
43
- #baseline;
44
- #baselineRefSha;
45
- #baselineTreeSha;
46
- #branch;
47
- #dirty = false;
48
- #files = /* @__PURE__ */ new Map();
49
- #ready;
50
- #remoteFiles = /* @__PURE__ */ new Map();
51
- #repository;
52
- #root;
53
- #token;
54
- constructor(options, workspaceName) {
55
- this.workspaceName = workspaceName;
56
- this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
57
- this.#branch = resolveGitHubBranchOption(options);
58
- this.#root = resolveGitHubRootOption(options, workspaceName);
59
- this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
60
- }
61
- [workspaceStoreTarget]() {
62
- return {
63
- provider: "github",
64
- branch: this.#branch,
65
- repository: this.#repository
66
- };
67
- }
68
- async readFile(path) {
69
- const normalized = normalizeSafeWorkspacePath(path);
70
- await this.#ensure({ refresh: true });
71
- return await this.#readWorkspaceFile(normalized);
72
- }
73
- async writeFile(path, file) {
74
- const normalized = normalizeSafeWorkspacePath(path);
75
- await this.#ensure({ refresh: false });
76
- const current = this.#files.get(normalized);
77
- const metadata = inheritedGitHubFileMetadata(file, current);
78
- const content = gitHubFileMode(metadata) === "120000" && typeof metadata?.symlinkTarget === "string" ? metadata.symlinkTarget : file.content;
79
- const update = await createGitHubFileUpdate(normalized, this.#root, content);
80
- if (current?.gitSha === update.gitSha) {
81
- if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
82
- this.#files.set(normalized, {
83
- ...current,
84
- mediaType: file.mediaType,
85
- metadata,
86
- size: contentLength(content)
87
- });
88
- return;
89
- }
90
- await createGitHubBlob({
91
- bytes: update.bytes,
92
- kind: "store",
93
- repository: this.#repository,
94
- token: this.#token
95
- });
96
- this.#files.set(normalized, {
97
- gitSha: update.gitSha,
98
- mediaType: file.mediaType,
99
- metadata,
100
- path: normalized,
101
- size: contentLength(content)
102
- });
103
- this.#dirty = true;
104
- }
105
- async writeFileStream(path, file) {
106
- const content = await contentStreamToBytes(file.content);
107
- await this.writeFile(path, {
108
- path: file.path,
109
- content,
110
- mediaType: file.mediaType,
111
- metadata: file.metadata
112
- });
113
- return {
114
- digest: await gitBlobSha(content),
115
- mediaType: file.mediaType,
116
- path: normalizeSafeWorkspacePath(path),
117
- size: content.byteLength,
118
- type: "file"
119
- };
120
- }
121
- async list(prefix = "", options = {}) {
122
- const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
123
- await this.#ensure({ refresh: true });
124
- return await this.#listEntries(normalizedPrefix, options);
125
- }
126
- async glob(pattern, _options = {}) {
127
- const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
128
- return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
129
- }
130
- async stat(path) {
131
- const normalized = normalizeSafeWorkspacePath(path);
132
- await this.#ensure({ refresh: true });
133
- const file = this.#files.get(normalized);
134
- if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
135
- if (this.#directoryExists(normalized)) return {
136
- path: normalized,
137
- type: "directory"
138
- };
139
- }
140
- async mkdir(path, _options = {}) {
141
- normalizeSafeWorkspacePath(path);
142
- }
143
- async rm(path, options = {}) {
144
- const normalized = normalizeSafeWorkspacePath(path);
145
- await this.#ensure({ refresh: false });
146
- if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
147
- this.#files.delete(normalized);
148
- this.#dirty = true;
149
- return;
150
- }
151
- const children = this.#publicDescendants(normalized);
152
- if (!(children.length > 0)) {
153
- if (options.force) return;
154
- throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
155
- }
156
- if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
157
- for (const child of children) this.#files.delete(child);
158
- this.#dirty = true;
159
- }
160
- async snapshot(options = {}) {
161
- await this.#ensure({ refresh: false });
162
- const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
163
- if (!this.#dirty) {
164
- this.#baseline = snapshot;
165
- return snapshot;
166
- }
167
- const remote = await readGitHubBranchState({
168
- branch: this.#branch,
169
- kind: "store",
170
- repository: this.#repository,
171
- root: this.#root,
172
- token: this.#token
173
- });
174
- 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.`);
175
- this.#remoteFiles = remote.files;
176
- this.#baselineRefSha = remote.refSha;
177
- this.#baselineTreeSha = remote.treeSha;
178
- const changedFiles = [...this.#files.values()].filter((file) => {
179
- const remote = this.#remoteFiles.get(file.path);
180
- return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
181
- });
182
- const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
183
- if (!changedFiles.length && !deletePaths.length) {
184
- this.#dirty = false;
185
- this.#baseline = snapshot;
186
- return snapshot;
187
- }
188
- const files = changedFiles.map((file) => {
189
- return {
190
- bytes: file.bytes,
191
- fullPath: joinGitPath(this.#root, file.path),
192
- gitSha: file.gitSha,
193
- mode: gitHubFileMode(file.metadata)
194
- };
195
- });
196
- const commit = await commitGitHubChanges({
197
- baseTreeSha: this.#baselineTreeSha,
198
- branch: this.#branch,
199
- branchExists: remote.branchExists,
200
- deletePaths,
201
- files,
202
- message: options.name || "chore: update workspace snapshot",
203
- parentSha: this.#baselineRefSha,
204
- repository: this.#repository,
205
- token: this.#token
206
- });
207
- this.#dirty = false;
208
- this.#baselineRefSha = commit.commitSha;
209
- this.#baselineTreeSha = commit.treeSha;
210
- this.#remoteFiles = this.#toRemoteFiles();
211
- this.#baseline = {
212
- ...snapshot,
213
- id: commit.commitSha
214
- };
215
- return this.#baseline;
216
- }
217
- async diff(options = {}) {
218
- await this.#ensure({ refresh: true });
219
- return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
220
- }
221
- async getMeta(key) {
222
- await this.#ensure({ refresh: true });
223
- const file = await this.#readWorkspaceFile(this.#metaPath(key));
224
- if (!file) return void 0;
225
- return JSON.parse(new TextDecoder().decode(file.bytes));
226
- }
227
- async setMeta(key, value) {
228
- const path = this.#metaPath(key);
229
- const content = JSON.stringify(value);
230
- const bytes = new TextEncoder().encode(content);
231
- await this.#ensure({ refresh: false });
232
- this.#files.set(path, {
233
- bytes,
234
- gitSha: await gitBlobSha(bytes),
235
- path,
236
- size: bytes.byteLength
237
- });
238
- this.#dirty = true;
239
- }
240
- async #ensure(options) {
241
- const wasReady = !!this.#ready;
242
- this.#ready ||= this.#load();
243
- await this.#ready;
244
- if (wasReady && options.refresh && !this.#dirty) await this.#load();
245
- }
246
- async #load() {
247
- const remote = await readGitHubBranchState({
248
- branch: this.#branch,
249
- kind: "store",
250
- repository: this.#repository,
251
- root: this.#root,
252
- token: this.#token
253
- });
254
- this.#baselineRefSha = remote.refSha;
255
- this.#baselineTreeSha = remote.treeSha;
256
- this.#remoteFiles = remote.files;
257
- if (!this.#dirty) {
258
- this.#files = new Map([...remote.files].map(([path, entry]) => [path, {
259
- gitSha: entry.sha,
260
- metadata: gitHubFileMetadata(entry),
261
- path,
262
- size: entry.size
263
- }]));
264
- this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), "github-workspace-store-load");
265
- }
266
- }
267
- async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
268
- const current = this.#files.get(path);
269
- if (!current) return void 0;
270
- const currentBytes = await this.#readFileBytes(current);
271
- if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
272
- const target = resolveSymlinkTarget(path, currentBytes);
273
- if (target && this.#files.has(target)) {
274
- seen.add(path);
275
- const resolved = await this.#readWorkspaceFile(target, seen);
276
- if (resolved) return {
277
- ...resolved,
278
- mediaType: current.mediaType ?? resolved.mediaType,
279
- metadata: await this.#fileMetadata(current) ?? resolved.metadata,
280
- path
281
- };
282
- }
283
- }
284
- return {
285
- content: currentBytes,
286
- bytes: currentBytes,
287
- mediaType: current.mediaType,
288
- metadata: await this.#fileMetadata(current),
289
- path
290
- };
291
- }
292
- async #readFileBytes(file) {
293
- if (!file.bytes) {
294
- file.bytes = await readGitHubBlob({
295
- kind: "store",
296
- repository: this.#repository,
297
- sha: file.gitSha,
298
- token: this.#token
299
- });
300
- file.size = file.bytes.byteLength;
301
- }
302
- return file.bytes;
303
- }
304
- async #fileMetadata(file) {
305
- if (gitHubFileMode(file.metadata) !== "120000" || typeof file.metadata?.symlinkTarget === "string") return file.metadata;
306
- return {
307
- ...file.metadata,
308
- symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
309
- };
310
- }
311
- async #listEntries(prefix, options) {
312
- const entries = /* @__PURE__ */ new Map();
313
- for (const file of this.#files.values()) {
314
- if (isReservedWorkspacePath(file.path)) continue;
315
- for (const dir of parentDirectories(file.path)) if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
316
- path: dir,
317
- type: "directory"
318
- });
319
- if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file));
320
- }
321
- return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
322
- }
323
- #entryInPrefix(path, prefix, options) {
324
- if (!prefix) return options.recursive || !path.includes("/");
325
- if (path === prefix) return false;
326
- if (!path.startsWith(`${prefix}/`)) return false;
327
- return options.recursive || !path.slice(prefix.length + 1).includes("/");
328
- }
329
- async #fileEntry(file) {
330
- return {
331
- digest: file.gitSha,
332
- mediaType: file.mediaType,
333
- metadata: await this.#fileMetadata(file),
334
- path: file.path,
335
- size: file.size,
336
- type: "file"
337
- };
338
- }
339
- #directoryExists(path) {
340
- return this.#publicDescendants(path).length > 0;
341
- }
342
- #publicDescendants(path) {
343
- return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
344
- }
345
- #metaPath(key) {
346
- return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
347
- }
348
- #toRemoteFiles() {
349
- return new Map([...this.#files.values()].map((file) => [file.path, {
350
- path: joinGitPath(this.#root, file.path),
351
- sha: file.gitSha,
352
- size: file.size,
353
- type: "blob",
354
- mode: gitHubFileMode(file.metadata)
355
- }]));
356
- }
357
- };
358
- function createGitHubWorkspaceStore(options, workspaceName) {
359
- return new GitHubWorkspaceStore(options, workspaceName);
360
- }
361
- //#endregion
1
+ import { t as createGitHubWorkspaceStore } from "../../store-Dt_Jyys3.js";
362
2
  export { createGitHubWorkspaceStore };
package/dist/publish.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as GitHubWorkspaceOption, dt as WorkspacePublisher } from "./types-DHkae7Cb.js";
1
+ import { a as GitHubWorkspaceOption, lt as WorkspacePublisher } from "./types-CYuwjJ4V.js";
2
2
 
3
3
  //#region src/publishers/manifest.d.ts
4
4
  interface ManifestPublisherOptions {
package/dist/publish.js CHANGED
@@ -1,6 +1,6 @@
1
- import { c as normalizeWorkspacePath, p as workspaceError } from "./path-CNI6wKIU.js";
1
+ import { _ as workspaceError, l as normalizeWorkspacePath } from "./path-Cp59koVz.js";
2
2
  import { n as resolveWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
3
- import { a as isWorkspaceFileEntry, d as resolveGitHubBranchOption, f as resolveGitHubOption, h as resolveGitHubTokenOption, l as readGitHubBranchState, m as resolveGitHubRootOption, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "./shared-BRycRSbo.js";
3
+ import { a as isWorkspaceFileEntry, d as requireGitHubOption, f as resolveGitHubBranchOption, g as resolveGitHubTokenOption, h as resolveGitHubRootOption, l as readGitHubBranchState, m as resolveGitHubRepositoryOption, p as resolveGitHubOption, r as createGitHubFileUpdate, t as commitGitHubChanges } from "./shared-DTR1Hhma.js";
4
4
  import { dirname, resolve } from "node:path";
5
5
  import { mkdir, writeFile } from "node:fs/promises";
6
6
  //#region src/publishers/manifest.ts
@@ -0,0 +1,127 @@
1
+ import { v as workspaceNotFoundError } from "./path-Cp59koVz.js";
2
+ import { t as hasRuntimeType } from "./runtime-type-iEE6BjQJ.js";
3
+ import { t as createWorkspace } from "./workspace-Dq08Yn72.js";
4
+ import runtimeRegistry from "#vitehub-workspace-registry";
5
+ //#region src/core/registry.ts
6
+ const workspaceRegistryStateKey = Symbol.for("vitehub.workspace.registryState");
7
+ function workspaceRegistryState() {
8
+ const scope = globalThis;
9
+ scope[workspaceRegistryStateKey] ??= {
10
+ loadingDefinitions: /* @__PURE__ */ new Map(),
11
+ loadGenerations: /* @__PURE__ */ new Map(),
12
+ loadedDefinitions: /* @__PURE__ */ new Map(),
13
+ loaders: runtimeRegistry,
14
+ registeredDefinitions: /* @__PURE__ */ new Map()
15
+ };
16
+ scope[workspaceRegistryStateKey].loadingDefinitions ??= /* @__PURE__ */ new Map();
17
+ scope[workspaceRegistryStateKey].loadGenerations ??= /* @__PURE__ */ new Map();
18
+ return scope[workspaceRegistryStateKey];
19
+ }
20
+ function pickWorkspaceFields(definition) {
21
+ const { __vitehubWorkspaceAgent: _agent, __vitehubWorkspaceAgentOptions: _agentOptions, description: _description, fallback: _fallback, instructions: _instructions, model: _model, name: _agentName, resolve: _resolve, run: _run, stepLimit: _stepLimit, workspace: _workspace, ...workspace } = definition;
22
+ return workspace;
23
+ }
24
+ function normalizeWorkspaceDefinition(name, definition) {
25
+ if (!definition) throw workspaceNotFoundError(name);
26
+ const workspaceAgentOptions = definition.__vitehubWorkspaceAgentOptions;
27
+ if (workspaceAgentOptions?.workspace) {
28
+ const injectedWorkspace = pickWorkspaceFields(definition);
29
+ const configuredWorkspace = hasRuntimeType(workspaceAgentOptions.workspace, "string") ? {} : workspaceAgentOptions.workspace;
30
+ const sources = mergeWorkspaceSources(injectedWorkspace.sources, configuredWorkspace.sources);
31
+ const normalizedWorkspace = {
32
+ ...injectedWorkspace,
33
+ ...configuredWorkspace,
34
+ rootDir: configuredWorkspace.rootDir ?? injectedWorkspace.rootDir,
35
+ sourceRootDir: configuredWorkspace.sourceRootDir ?? injectedWorkspace.sourceRootDir,
36
+ name
37
+ };
38
+ if (sources) normalizedWorkspace.sources = sources;
39
+ return normalizedWorkspace;
40
+ }
41
+ if ("name" in definition) throw new TypeError(`[vitehub] Workspace definition "${name}" must not declare a name. Workspace names are inferred from filenames.`);
42
+ return {
43
+ ...pickWorkspaceFields(definition),
44
+ name
45
+ };
46
+ }
47
+ function mergeWorkspaceSources(injected, configured) {
48
+ if (!injected && !configured) return void 0;
49
+ return {
50
+ ...injected,
51
+ ...configured
52
+ };
53
+ }
54
+ function registerWorkspace(name, definition) {
55
+ if (!name || !hasRuntimeType(name, "string")) throw new TypeError("[vitehub] registerWorkspace requires a string name.");
56
+ const registered = normalizeWorkspaceDefinition(name, definition);
57
+ workspaceRegistryState().registeredDefinitions.set(name, registered);
58
+ return registered;
59
+ }
60
+ function setWorkspaceRegistry(registry) {
61
+ const state = workspaceRegistryState();
62
+ invalidateWorkspaceLoads(state);
63
+ state.loaders = registry;
64
+ state.loadedDefinitions.clear();
65
+ }
66
+ function invalidateWorkspaceLoads(state) {
67
+ for (const [name, loading] of state.loadingDefinitions) if (state.loadGenerations.get(name) === loading.generation) state.loadGenerations.set(name, loading.generation + 1);
68
+ state.loadingDefinitions.clear();
69
+ }
70
+ async function resolveWorkspaceDefinition(name, abortSignal) {
71
+ const state = workspaceRegistryState();
72
+ const existing = state.registeredDefinitions.get(name) || state.loadedDefinitions.get(name);
73
+ if (existing) return existing;
74
+ const load = state.loaders[name];
75
+ if (!load) throw workspaceNotFoundError(name);
76
+ let loading = state.loadingDefinitions.get(name);
77
+ if (!loading || loading.load !== load) {
78
+ const generation = (state.loadGenerations.get(name) ?? 0) + 1;
79
+ state.loadGenerations.set(name, generation);
80
+ const promise = load().then((mod) => {
81
+ const definition = normalizeWorkspaceDefinition(name, mod.default);
82
+ if (state.loadGenerations.get(name) === generation && state.loaders[name] === load) state.loadedDefinitions.set(name, definition);
83
+ return definition;
84
+ });
85
+ loading = {
86
+ consumers: 0,
87
+ generation,
88
+ load,
89
+ promise
90
+ };
91
+ state.loadingDefinitions.set(name, loading);
92
+ promise.finally(() => {
93
+ if (state.loadingDefinitions.get(name) === loading) state.loadingDefinitions.delete(name);
94
+ }).catch(() => {});
95
+ }
96
+ loading.consumers++;
97
+ let aborted = false;
98
+ let rejectAbort;
99
+ const abort = new Promise((_resolve, reject) => {
100
+ rejectAbort = reject;
101
+ });
102
+ const onAbort = () => {
103
+ aborted = true;
104
+ rejectAbort(abortSignal?.reason);
105
+ };
106
+ if (abortSignal?.aborted) onAbort();
107
+ else abortSignal?.addEventListener("abort", onAbort, { once: true });
108
+ try {
109
+ if (!abortSignal) return await loading.promise;
110
+ return await Promise.race([loading.promise, abort]);
111
+ } finally {
112
+ abortSignal?.removeEventListener("abort", onAbort);
113
+ loading.consumers--;
114
+ if (aborted && loading.consumers === 0 && state.loadingDefinitions.get(name) === loading) {
115
+ state.loadingDefinitions.delete(name);
116
+ if (state.loadGenerations.get(name) === loading.generation) state.loadGenerations.set(name, loading.generation + 1);
117
+ }
118
+ }
119
+ }
120
+ async function resolveRegisteredWorkspaceDefinition(name, abortSignal) {
121
+ return resolveWorkspaceDefinition(name, abortSignal);
122
+ }
123
+ async function useRegisteredWorkspace(name) {
124
+ return createWorkspace(await resolveWorkspaceDefinition(name));
125
+ }
126
+ //#endregion
127
+ export { useRegisteredWorkspace as a, setWorkspaceRegistry as i, registerWorkspace as n, resolveRegisteredWorkspaceDefinition as r, normalizeWorkspaceDefinition as t };
@@ -1,11 +1,11 @@
1
- import { F as WorkspaceDefinitionInput, P as WorkspaceDefinition } from "./types-DHkae7Cb.js";
1
+ import { F as WorkspaceDefinition, I as WorkspaceDefinitionInput } from "./types-CYuwjJ4V.js";
2
2
 
3
3
  //#region src/core/registry.d.ts
4
4
  type WorkspaceRegistryModule = {
5
5
  default?: WorkspaceDefinitionInput;
6
6
  };
7
7
  type WorkspaceRegistry = Record<string, () => Promise<WorkspaceRegistryModule>>;
8
- declare function registerWorkspace(name: string, definition: WorkspaceDefinitionInput): void;
9
- declare function resolveRegisteredWorkspaceDefinition(name: string): Promise<WorkspaceDefinition>;
8
+ declare function registerWorkspace(name: string, definition: WorkspaceDefinitionInput): WorkspaceDefinition;
9
+ declare function resolveRegisteredWorkspaceDefinition(name: string, abortSignal?: AbortSignal): Promise<WorkspaceDefinition>;
10
10
  //#endregion
11
11
  export { registerWorkspace as n, resolveRegisteredWorkspaceDefinition as r, WorkspaceRegistry as t };
@@ -1,12 +1,16 @@
1
- import { a as normalizeWorkspaceSources, h as workspaceSourceRequestDescriptorPath, n as createSourceContext, p as getWorkspaceSourceRequestExecutor } from "./config--r5unwPc.js";
1
+ import { _ as workspaceSourceRequestDescriptorPath, a as normalizeWorkspaceSources, h as getWorkspaceSourceRequestExecutor, n as createSourceContext } from "./config-Bc3c4Su1.js";
2
2
  //#region src/sources/request-execution.ts
3
3
  const sourceRequestExecutions = /* @__PURE__ */ new WeakMap();
4
+ function isWeakKey(value) {
5
+ return Object(value) === value;
6
+ }
4
7
  function attachWorkspaceSourceRequestExecution(target, executor) {
5
8
  if (!executor) return target;
6
9
  sourceRequestExecutions.set(target, executor);
7
10
  return target;
8
11
  }
9
12
  function getWorkspaceSourceRequestExecution(input) {
13
+ if (!isWeakKey(input)) return void 0;
10
14
  return sourceRequestExecutions.get(input);
11
15
  }
12
16
  function createWorkspaceSourceRequestExecution(definition, options = {}) {
@@ -53,12 +57,12 @@ function requestShapeMatches(descriptor, input) {
53
57
  }
54
58
  function bodyShapeMatches(request, input) {
55
59
  if (request?.bodySchema) return true;
56
- if (typeof request?.body !== "undefined") return jsonEqual(input.body, request.body);
57
- return typeof input.body === "undefined";
60
+ if (request && "body" in request) return jsonEqual(input.body, request.body);
61
+ return input.body === void 0;
58
62
  }
59
63
  function queryFromUrl(url) {
60
64
  const query = {};
61
- for (const key of new Set([...url.searchParams.keys()])) {
65
+ for (const key of new Set(url.searchParams.keys())) {
62
66
  const values = url.searchParams.getAll(key);
63
67
  query[key] = values.length > 1 ? values : values[0];
64
68
  }
@@ -1,4 +1,4 @@
1
- import { D as WorkspaceAssets, j as WorkspaceContent } from "../types-DHkae7Cb.js";
1
+ import { D as WorkspaceAssets, M as WorkspaceContent } from "../types-CYuwjJ4V.js";
2
2
 
3
3
  //#region src/runtime/assets.d.ts
4
4
  interface WorkspaceAssetFile {
@@ -1,5 +1,5 @@
1
- import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, f as isWorkspaceError, i as decodeFile, o as normalizeSafeWorkspacePath, p as workspaceError } from "../path-CNI6wKIU.js";
2
- import { t as searchText } from "../search-C4REyHj9.js";
1
+ import { _ as workspaceError, a as isExcludedWorkspacePath, f as sha256, h as isWorkspaceError, i as decodeFile, l as normalizeWorkspacePath, o as matchesAny, s as normalizeSafeWorkspacePath } from "../path-Cp59koVz.js";
2
+ import { t as searchText } from "../search-BpiCF2Tw.js";
3
3
  //#region src/runtime/assets.ts
4
4
  function createMissingPathError(path) {
5
5
  return workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
@@ -79,12 +79,14 @@ function createWorkspaceAssets(files) {
79
79
  const result = /* @__PURE__ */ new Map();
80
80
  for (const directory of directorySet) {
81
81
  if (directory === normalizedPrefix) continue;
82
+ if (isExcludedWorkspacePath(directory, options.exclude)) continue;
82
83
  if (normalizedPrefix && !isNestedUnder(directory, normalizedPrefix)) continue;
83
84
  if (!options.recursive && normalizeWorkspacePath(directory.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
84
85
  result.set(directory, createDirectoryEntry(directory));
85
86
  }
86
87
  for (const path of paths) {
87
88
  if (path === normalizedPrefix) continue;
89
+ if (isExcludedWorkspacePath(path, options.exclude)) continue;
88
90
  if (normalizedPrefix && !isNestedUnder(path, normalizedPrefix)) continue;
89
91
  if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
90
92
  result.set(path, await statFile(path));
@@ -1,4 +1,4 @@
1
- import { O as WorkspaceAssetsRegistry } from "../types-DHkae7Cb.js";
1
+ import { O as WorkspaceAssetsRegistry } from "../types-CYuwjJ4V.js";
2
2
 
3
3
  //#region src/runtime/empty-assets-registry.d.ts
4
4
  declare const registry: WorkspaceAssetsRegistry;
@@ -1,4 +1,4 @@
1
- import { t as WorkspaceRegistry } from "../registry-CoC9JxVt.js";
1
+ import { t as WorkspaceRegistry } from "../registry-Uj6IVxes.js";
2
2
 
3
3
  //#region src/runtime/empty-registry.d.ts
4
4
  declare const registry: WorkspaceRegistry;
@@ -1,4 +1,4 @@
1
- import { p as useWorkspace, r as UseWorkspaceOptions, t as ReadonlyWorkspaceFacade, u as WritableWorkspaceFacade } from "../use-D16tf8Ph.js";
2
- import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "../registry-CoC9JxVt.js";
3
- import { c as setWorkspaceHostedStoreLoader, i as setActiveCloudflareEnv, l as getWorkspaceRuntimeConfig, n as setWorkspaceRuntimeRegistry, r as resetWorkspaceStoreCache, s as getWorkspaceHostedStoreLoader, t as setWorkspaceRuntimeAssetsRegistry, u as setWorkspaceRuntimeConfig } from "../state-DSAHEsq6.js";
4
- export { type ReadonlyWorkspaceFacade, type UseWorkspaceOptions, type WritableWorkspaceFacade, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, setActiveCloudflareEnv, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace };
1
+ import { _ as useWorkspace, i as ReadonlyWorkspaceFacade, m as WritableWorkspaceFacade, o as UseWorkspaceOptions } from "../use-BiHzt0xA.js";
2
+ import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "../registry-Uj6IVxes.js";
3
+ import { a as setWorkspaceRuntimeConfig, c as getWorkspaceHostedStoreLoader, d as setActiveCloudflareEnv, i as getWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, n as setWorkspaceRuntimeAssetsRegistry, r as setWorkspaceRuntimeRegistry, t as invalidateWorkspaceStore, u as resetWorkspaceStoreCache } from "../state-tYcRWEh2.js";
4
+ export { type ReadonlyWorkspaceFacade, type UseWorkspaceOptions, type WritableWorkspaceFacade, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, invalidateWorkspaceStore, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, setActiveCloudflareEnv, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace };
@@ -1,10 +1,13 @@
1
- import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, u as getWorkspaceRuntimeConfig } from "../provider-CeQciesl.js";
2
- import { n as setActiveCloudflareEnv } from "../cloudflare-env-CKxUs2fa.js";
3
- import { t as setWorkspaceAssetsRegistry } from "../asset-registry-CaG9b7tf.js";
4
- import { n as resetWorkspaceStoreCache } from "../workspace-n4wBmdaM.js";
5
- import { i as setWorkspaceRegistry, n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "../registry-C7DMdBXN.js";
6
- import { t as useWorkspace } from "../use-d_PlAdOu.js";
1
+ import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, u as getWorkspaceRuntimeConfig } from "../provider-B1yLjCJJ.js";
2
+ import { v as setActiveCloudflareEnv } from "../shared-DTR1Hhma.js";
3
+ import { t as setWorkspaceAssetsRegistry } from "../asset-registry-8QI3ML3K.js";
4
+ import { n as invalidateCachedWorkspaceStore, r as resetWorkspaceStoreCache } from "../workspace-Dq08Yn72.js";
5
+ import { i as setWorkspaceRegistry, n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "../registry-D3yzt8HQ.js";
6
+ import { t as useWorkspace } from "../use-BTNDR5Rd.js";
7
7
  //#region src/runtime/state.ts
8
+ async function invalidateWorkspaceStore(name) {
9
+ invalidateCachedWorkspaceStore(await resolveRegisteredWorkspaceDefinition(name));
10
+ }
8
11
  function setWorkspaceRuntimeRegistry(registry) {
9
12
  setWorkspaceRegistry(registry);
10
13
  }
@@ -12,4 +15,4 @@ function setWorkspaceRuntimeAssetsRegistry(registry) {
12
15
  setWorkspaceAssetsRegistry(registry);
13
16
  }
14
17
  //#endregion
15
- export { getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, setActiveCloudflareEnv, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace };
18
+ export { getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, invalidateWorkspaceStore, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, setActiveCloudflareEnv, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace };
@@ -1,2 +1,2 @@
1
- import { t as createWorkspace } from "../workspace-f2DBLmPZ.js";
1
+ import { t as createWorkspace } from "../workspace-Xddf4G1B.js";
2
2
  export { createWorkspace };
@@ -1,2 +1,2 @@
1
- import { t as createWorkspace } from "../workspace-n4wBmdaM.js";
1
+ import { t as createWorkspace } from "../workspace-Dq08Yn72.js";
2
2
  export { createWorkspace };
@@ -0,0 +1,13 @@
1
+ //#region src/sources/runtime-options.ts
2
+ function withWorkspaceRuntimeOptions(source, options) {
3
+ return {
4
+ ...source,
5
+ cache: options.cache,
6
+ materialize: options.materialize,
7
+ mount: options.mount,
8
+ sync: options.sync,
9
+ validate: options.validate
10
+ };
11
+ }
12
+ //#endregion
13
+ export { withWorkspaceRuntimeOptions as t };