@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,235 +0,0 @@
1
- import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes, s as normalizeSafeWorkspacePattern } from "../../path-CNI6wKIU.js";
2
- import { a as resolveRuntimeVercelBlobWorkspaceStore } from "../../provider-CeQciesl.js";
3
- import { n as createSnapshotFromEntries, r as diffSnapshots } from "../../utils-BPdaCyI6.js";
4
- //#region src/providers/vercel/blob-store.ts
5
- function joinBlobPath(...parts) {
6
- return parts.map((part) => normalizeWorkspacePath(part)).filter(Boolean).join("/");
7
- }
8
- function contentType(path, fallback) {
9
- if (fallback) return fallback;
10
- if (path.endsWith(".json")) return "application/json; charset=utf-8";
11
- if (path.endsWith(".md") || path.endsWith(".txt")) return "text/plain; charset=utf-8";
12
- }
13
- function auth(options) {
14
- return options.token ? { token: options.token } : {};
15
- }
16
- async function createVercelBlobClient(options) {
17
- const blob = await importVercelBlobPeer();
18
- const access = options.access || "private";
19
- return {
20
- async delete(key) {
21
- await blob.del(key, auth(options));
22
- },
23
- async download(key) {
24
- const result = await blob.get(key, {
25
- access,
26
- ...auth(options)
27
- });
28
- if (!result || result.statusCode !== 200 || !result.stream) throw Object.assign(/* @__PURE__ */ new Error("not found"), { code: "NotFound" });
29
- return await new Response(result.stream, { headers: result.blob.contentType ? { "content-type": result.blob.contentType } : void 0 }).blob();
30
- },
31
- async head(key) {
32
- const result = await blob.head(key, auth(options));
33
- return {
34
- key: result.pathname,
35
- lastModified: result.uploadedAt.getTime(),
36
- size: result.size,
37
- type: result.contentType
38
- };
39
- },
40
- async list(optionsInput) {
41
- const result = await blob.list({
42
- ...optionsInput,
43
- ...auth(options)
44
- });
45
- return {
46
- cursor: result.cursor,
47
- items: result.blobs.map((item) => ({
48
- key: item.pathname,
49
- lastModified: item.uploadedAt?.getTime(),
50
- size: item.size
51
- }))
52
- };
53
- },
54
- async upload(key, body, uploadOptions = {}) {
55
- await blob.put(key, body, {
56
- access,
57
- addRandomSuffix: false,
58
- allowOverwrite: true,
59
- contentType: uploadOptions.contentType,
60
- ...auth(options)
61
- });
62
- }
63
- };
64
- }
65
- const vercelBlobPeerSpecifier = "@vercel/blob";
66
- async function importVercelBlobPeer() {
67
- try {
68
- const testImport = globalThis.__vitehubWorkspaceImportVercelBlobPeer;
69
- if (testImport) return await testImport();
70
- return await import(vercelBlobPeerSpecifier);
71
- } catch (error) {
72
- handleVercelBlobImportError(error);
73
- }
74
- }
75
- function handleVercelBlobImportError(error) {
76
- if (isMissingVercelBlobError(error)) throw workspaceError("[vitehub] @vercel/blob is required for the Vercel Blob Workspace Store. Package: @vercel/blob.", { cause: error });
77
- throw error;
78
- }
79
- function isMissingVercelBlobError(error) {
80
- if (!(error instanceof Error)) return false;
81
- const code = error.code;
82
- if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") return false;
83
- return error.message.includes("Cannot find package '@vercel/blob'") || error.message.includes("Cannot find module '@vercel/blob'");
84
- }
85
- var VercelBlobWorkspaceStore = class {
86
- workspaceName;
87
- #baseline;
88
- #options;
89
- #files;
90
- constructor(options, workspaceName) {
91
- this.workspaceName = workspaceName;
92
- this.#options = resolveRuntimeVercelBlobWorkspaceStore(options, typeof process !== "undefined" ? process.env : {});
93
- }
94
- get #root() {
95
- return joinBlobPath(this.#options.prefix || ".vitehub/workspaces", this.workspaceName);
96
- }
97
- #fileKey(path, options = {}) {
98
- return joinBlobPath(this.#root, "files", normalizeSafeWorkspacePath(path, { allowEmpty: options.allowEmpty }));
99
- }
100
- async #client() {
101
- this.#files ||= createVercelBlobClient(this.#options);
102
- return await this.#files;
103
- }
104
- #metaKey(key) {
105
- return joinBlobPath(this.#root, ".vitehub/meta", normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`));
106
- }
107
- #snapshotKey(id) {
108
- return joinBlobPath(this.#root, ".vitehub/snapshots", `${id}.json`);
109
- }
110
- async readFile(path) {
111
- const normalized = normalizeSafeWorkspacePath(path);
112
- const pathname = this.#fileKey(normalized);
113
- const file = await (await this.#client()).download(pathname).catch(() => null);
114
- if (!file) return void 0;
115
- const bytes = await file.arrayBuffer();
116
- return {
117
- path: normalized,
118
- content: new Uint8Array(bytes)
119
- };
120
- }
121
- async writeFile(path, file) {
122
- const normalized = normalizeSafeWorkspacePath(path);
123
- await (await this.#client()).upload(this.#fileKey(normalized), new Blob([contentToBytes(file.content)]), { contentType: contentType(normalized, file.mediaType) });
124
- }
125
- async list(prefix = "", options = {}) {
126
- const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
127
- const filePrefix = this.#fileKey(normalizedPrefix, { allowEmpty: true });
128
- const files = await this.#listBlobs(normalizedPrefix ? `${filePrefix}/` : `${this.#fileKey("", { allowEmpty: true })}/`);
129
- const entries = /* @__PURE__ */ new Map();
130
- for (const blob of files) {
131
- const path = normalizeWorkspacePath(blob.key.slice(`${this.#fileKey("", { allowEmpty: true })}/`.length));
132
- if (!path) continue;
133
- if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
134
- if (!options.recursive && normalizedPrefix && path.slice(normalizedPrefix.length + 1).includes("/")) continue;
135
- if (!options.recursive && !normalizedPrefix && path.includes("/")) {
136
- entries.set(path.split("/")[0], {
137
- path: path.split("/")[0],
138
- type: "directory"
139
- });
140
- continue;
141
- }
142
- entries.set(path, {
143
- mtime: blob.lastModified,
144
- path,
145
- size: blob.size,
146
- type: "file"
147
- });
148
- if (options.recursive) {
149
- const parts = path.split("/");
150
- for (let index = 1; index < parts.length; index++) {
151
- const dir = parts.slice(0, index).join("/");
152
- entries.set(dir, {
153
- path: dir,
154
- type: "directory"
155
- });
156
- }
157
- }
158
- }
159
- return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
160
- }
161
- async glob(pattern, _options = {}) {
162
- const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
163
- return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
164
- }
165
- async stat(path) {
166
- const normalized = normalizeSafeWorkspacePath(path);
167
- const file = await this.readFile(normalized);
168
- if (file) {
169
- const bytes = contentToBytes(file.content);
170
- return {
171
- digest: await sha256(bytes),
172
- path: normalized,
173
- size: bytes.byteLength,
174
- type: "file"
175
- };
176
- }
177
- return (await this.list(normalized, { recursive: false })).length ? {
178
- path: normalized,
179
- type: "directory"
180
- } : void 0;
181
- }
182
- async mkdir(path, _options = {}) {
183
- normalizeSafeWorkspacePath(path);
184
- }
185
- async rm(path, options = {}) {
186
- const normalized = normalizeSafeWorkspacePath(path);
187
- const client = await this.#client();
188
- const targets = [];
189
- if (await client.head(this.#fileKey(normalized)).catch(() => null)) targets.push(this.#fileKey(normalized));
190
- else if (options.recursive) for (const blob of await this.#listBlobs(`${this.#fileKey(normalized)}/`)) targets.push(blob.key);
191
- if (!targets.length) {
192
- if (options.force) return;
193
- throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
194
- }
195
- await Promise.all(targets.map((target) => client.delete(target)));
196
- }
197
- async snapshot(options = {}) {
198
- const snapshot = await createSnapshotFromEntries(await this.list("", { recursive: true }), options.name);
199
- await (await this.#client()).upload(this.#snapshotKey(snapshot.id), JSON.stringify(snapshot), { contentType: "application/json; charset=utf-8" });
200
- this.#baseline = snapshot;
201
- return snapshot;
202
- }
203
- async diff(options = {}) {
204
- return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.list("", { recursive: true })));
205
- }
206
- async getMeta(key) {
207
- return await this.#readJson(this.#metaKey(key));
208
- }
209
- async setMeta(key, value) {
210
- await (await this.#client()).upload(this.#metaKey(key), JSON.stringify(value), { contentType: "application/json; charset=utf-8" });
211
- }
212
- async #listBlobs(prefix) {
213
- const blobs = [];
214
- let cursor;
215
- do {
216
- const result = await (await this.#client()).list({
217
- cursor,
218
- limit: 1e3,
219
- prefix
220
- });
221
- blobs.push(...result.items);
222
- cursor = result.cursor;
223
- } while (cursor);
224
- return blobs;
225
- }
226
- async #readJson(pathname) {
227
- const file = await (await this.#client()).download(pathname).catch(() => null);
228
- return file ? JSON.parse(await file.text()) : void 0;
229
- }
230
- };
231
- function createVercelBlobWorkspaceStore(options, workspaceName) {
232
- return new VercelBlobWorkspaceStore(options, workspaceName);
233
- }
234
- //#endregion
235
- export { createVercelBlobWorkspaceStore };
@@ -1,74 +0,0 @@
1
- import { m as workspaceNotFoundError } from "./path-CNI6wKIU.js";
2
- import { t as createWorkspace } from "./workspace-n4wBmdaM.js";
3
- import runtimeRegistry from "#vitehub-workspace-registry";
4
- //#region src/core/registry.ts
5
- const workspaceRegistryStateKey = Symbol.for("vitehub.workspace.registryState");
6
- function workspaceRegistryState() {
7
- const scope = globalThis;
8
- scope[workspaceRegistryStateKey] ??= {
9
- loadedDefinitions: /* @__PURE__ */ new Map(),
10
- loaders: runtimeRegistry,
11
- registeredDefinitions: /* @__PURE__ */ new Map()
12
- };
13
- return scope[workspaceRegistryStateKey];
14
- }
15
- function pickWorkspaceFields(definition) {
16
- 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;
17
- return workspace;
18
- }
19
- function normalizeWorkspaceDefinition(name, definition) {
20
- if (!definition) throw workspaceNotFoundError(name);
21
- const workspaceAgentOptions = definition.__vitehubWorkspaceAgentOptions;
22
- if (workspaceAgentOptions?.workspace) {
23
- const injectedWorkspace = pickWorkspaceFields(definition);
24
- const configuredWorkspace = typeof workspaceAgentOptions.workspace === "string" ? {} : workspaceAgentOptions.workspace;
25
- const sources = mergeWorkspaceSources(injectedWorkspace.sources, configuredWorkspace.sources);
26
- return {
27
- ...injectedWorkspace,
28
- ...configuredWorkspace,
29
- ...sources ? { sources } : {},
30
- rootDir: configuredWorkspace.rootDir ?? injectedWorkspace.rootDir,
31
- sourceRootDir: configuredWorkspace.sourceRootDir ?? injectedWorkspace.sourceRootDir,
32
- name
33
- };
34
- }
35
- if ("name" in definition) throw new TypeError(`[vitehub] Workspace definition "${name}" must not declare a name. Workspace names are inferred from filenames.`);
36
- return {
37
- ...pickWorkspaceFields(definition),
38
- name
39
- };
40
- }
41
- function mergeWorkspaceSources(injected, configured) {
42
- if (!injected && !configured) return void 0;
43
- return {
44
- ...injected,
45
- ...configured
46
- };
47
- }
48
- function registerWorkspace(name, definition) {
49
- if (!name || typeof name !== "string") throw new TypeError("[vitehub] registerWorkspace requires a string name.");
50
- workspaceRegistryState().registeredDefinitions.set(name, normalizeWorkspaceDefinition(name, definition));
51
- }
52
- function setWorkspaceRegistry(registry) {
53
- const state = workspaceRegistryState();
54
- state.loaders = registry;
55
- state.loadedDefinitions.clear();
56
- }
57
- async function resolveWorkspaceDefinition(name) {
58
- const state = workspaceRegistryState();
59
- const existing = state.registeredDefinitions.get(name) || state.loadedDefinitions.get(name);
60
- if (existing) return existing;
61
- const load = state.loaders[name];
62
- if (!load) throw workspaceNotFoundError(name);
63
- const definition = normalizeWorkspaceDefinition(name, (await load()).default);
64
- state.loadedDefinitions.set(name, definition);
65
- return definition;
66
- }
67
- async function resolveRegisteredWorkspaceDefinition(name) {
68
- return resolveWorkspaceDefinition(name);
69
- }
70
- async function useRegisteredWorkspace(name) {
71
- return createWorkspace(await resolveWorkspaceDefinition(name));
72
- }
73
- //#endregion
74
- export { useRegisteredWorkspace as a, setWorkspaceRegistry as i, registerWorkspace as n, resolveRegisteredWorkspaceDefinition as r, normalizeWorkspaceDefinition as t };
@@ -1,55 +0,0 @@
1
- import { d as sha256 } from "./path-CNI6wKIU.js";
2
- //#region src/storage/utils.ts
3
- async function createCurrentSnapshotFromStore(store, name) {
4
- return await createSnapshotFromEntries(await store.list("", { recursive: true }), name);
5
- }
6
- async function createSnapshotFromEntries(entries, name) {
7
- const snapshotEntries = {};
8
- for (const entry of entries) snapshotEntries[entry.path] = {
9
- digest: entry.digest,
10
- metadata: entry.metadata,
11
- size: entry.size,
12
- type: entry.type
13
- };
14
- return {
15
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
16
- entries: snapshotEntries,
17
- id: await sha256({
18
- entries: snapshotEntries,
19
- name,
20
- createdAt: Date.now()
21
- }),
22
- name
23
- };
24
- }
25
- function diffSnapshots(from, to) {
26
- const entries = [];
27
- const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
28
- for (const path of [...keys].sort()) {
29
- const before = from?.entries[path];
30
- const after = to.entries[path];
31
- if (!before && after) entries.push({
32
- path,
33
- type: "added",
34
- after
35
- });
36
- else if (before && !after) entries.push({
37
- path,
38
- type: "removed",
39
- before
40
- });
41
- else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata))) entries.push({
42
- path,
43
- type: "modified",
44
- before,
45
- after
46
- });
47
- }
48
- return {
49
- from: from?.id,
50
- to: to.id,
51
- entries
52
- };
53
- }
54
- //#endregion
55
- export { createSnapshotFromEntries as n, diffSnapshots as r, createCurrentSnapshotFromStore as t };