@vite-hub/workspace 0.0.0 → 0.0.1

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 (47) hide show
  1. package/README.md +89 -1
  2. package/dist/ai-Bk3LLnit.js +352 -0
  3. package/dist/ai.d.ts +86 -0
  4. package/dist/ai.js +2 -0
  5. package/dist/asset-registry-CMuQbyvl.js +14 -0
  6. package/dist/chunk-DrSxFLj_.js +14 -0
  7. package/dist/cloudflare-env-DL94Uvpz.js +12 -0
  8. package/dist/config-CvS-7sre.js +49 -0
  9. package/dist/errors-BUL8SoFS.js +21 -0
  10. package/dist/files-DbsIjBya.js +50 -0
  11. package/dist/index.d.ts +150 -0
  12. package/dist/index.js +656 -0
  13. package/dist/lifecycle-uD82JeGh.js +92 -0
  14. package/dist/loader.d.ts +17 -0
  15. package/dist/loader.js +22 -0
  16. package/dist/module-8LZUMEXC.js +922 -0
  17. package/dist/nitro.d.ts +31 -0
  18. package/dist/nitro.js +2 -0
  19. package/dist/path-BVv9OXhg.js +63 -0
  20. package/dist/provider-BZuKAV4e.js +494 -0
  21. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  22. package/dist/providers/cloudflare/artifacts-store.js +384 -0
  23. package/dist/providers/vercel/blob-store.d.ts +6 -0
  24. package/dist/providers/vercel/blob-store.js +176 -0
  25. package/dist/publish.d.ts +34 -0
  26. package/dist/publish.js +206 -0
  27. package/dist/registry-Cnr0NoKv.js +932 -0
  28. package/dist/registry-D4Qzq26I.d.ts +10 -0
  29. package/dist/runtime/assets.d.ts +11 -0
  30. package/dist/runtime/assets.js +138 -0
  31. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  32. package/dist/runtime/empty-assets-registry.js +4 -0
  33. package/dist/runtime/empty-registry.d.ts +6 -0
  34. package/dist/runtime/empty-registry.js +4 -0
  35. package/dist/runtime/nitro-plugin.d.ts +6 -0
  36. package/dist/runtime/nitro-plugin.js +14 -0
  37. package/dist/runtime/state.d.ts +21 -0
  38. package/dist/runtime/state.js +12 -0
  39. package/dist/sandbox-DtGXCWRq.js +198 -0
  40. package/dist/search-DtaEyjpO.js +39 -0
  41. package/dist/test.d.ts +2 -0
  42. package/dist/test.js +2 -0
  43. package/dist/types-CwNcWTdt.d.ts +378 -0
  44. package/dist/utils-BtAm_K5P.js +51 -0
  45. package/dist/vite.d.ts +22 -0
  46. package/dist/vite.js +131 -0
  47. package/package.json +101 -5
package/README.md CHANGED
@@ -1,3 +1,91 @@
1
1
  # @vite-hub/workspace
2
2
 
3
- Reserved package name for ViteHub.
3
+ <p>
4
+ <a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/badge/ViteHub-vitehub.dev-646cff?style=flat-square"></a>
5
+ <img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-ready-3178c6?style=flat-square">
6
+ <img alt="Vite" src="https://img.shields.io/badge/Vite-discovery-646cff?style=flat-square">
7
+ <img alt="Nitro" src="https://img.shields.io/badge/Nitro-runtime-00dc82?style=flat-square">
8
+ </p>
9
+
10
+ `@vite-hub/workspace` gives agents and server code a file-system context they can read, diff, and, when opened in write mode, update.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ pnpm add @vite-hub/workspace
16
+ ```
17
+
18
+ ## Minimal API
19
+
20
+ ```text
21
+ server/
22
+ workspaces/
23
+ docs/
24
+ README.md
25
+ config.ts
26
+ api/
27
+ docs.get.ts
28
+ vite.config.ts
29
+ ```
30
+
31
+ ```ts
32
+ // server/workspaces/docs/config.ts
33
+ import { defineWorkspace, source } from "@vite-hub/workspace"
34
+
35
+ export default defineWorkspace({
36
+ store: {
37
+ provider: "local",
38
+ root: ".vitehub/workspaces/docs",
39
+ },
40
+ sources: {
41
+ readme: source.file("README.md"),
42
+ vitehubDocs: source.github({
43
+ repo: "vite-hub/vitehub",
44
+ root: "docs/content/docs",
45
+ }),
46
+ guide: source.file({
47
+ workspacePath: "guide.md",
48
+ content: "# Guide\n",
49
+ }),
50
+ },
51
+ })
52
+ ```
53
+
54
+ ```ts
55
+ // server/api/docs.get.ts
56
+ import { useWorkspace } from "@vite-hub/workspace"
57
+ import { defineEventHandler } from "h3"
58
+
59
+ export default defineEventHandler(async () => {
60
+ const workspace = useWorkspace("docs", { mode: "write" })
61
+
62
+ await workspace.fs.writeFile("generated/notes.md", "Generated by ViteHub\n")
63
+
64
+ return {
65
+ files: await workspace.fs.glob("**/*.md"),
66
+ diff: await workspace.diff(),
67
+ }
68
+ })
69
+ ```
70
+
71
+ ```ts
72
+ // vite.config.ts
73
+ import { hubWorkspace } from "@vite-hub/workspace/vite"
74
+ import { defineConfig } from "vite"
75
+
76
+ export default defineConfig({
77
+ plugins: [hubWorkspace()],
78
+ })
79
+ ```
80
+
81
+ ## Sandbox sessions
82
+
83
+ Need the workspace to run generated code instead of only reading and writing files? Pair it with [`@vite-hub/sandbox`](../sandbox/README.md) so sessions can execute inside an isolated provider runtime.
84
+
85
+ ## Vite and Nitro
86
+
87
+ Nitro workspaces live under `server/workspaces/**`; an agent can also colocate one at `server/agents/<name>/config.ts` by adding `workspace` to its `defineAgent()` call. Vite emits the workspace manifest for local development, and `@vite-hub/workspace/nitro` registers the runtime store.
88
+
89
+ Built on [`@vite-hub/source`](../source/README.md), [`@vite-hub/shell`](../shell/README.md), [files-sdk](https://files-sdk.dev/), and [isomorphic-git](https://isomorphic-git.org/).
90
+
91
+ Learn more at [vitehub.dev](https://vitehub.dev).
@@ -0,0 +1,352 @@
1
+ import { t as WorkspaceError } from "./errors-BUL8SoFS.js";
2
+ import { cleanWorkspaceShellPath, createReadonlyWorkspaceFs, runWorkspaceInspectionCommand } from "@vite-hub/shell/workspace";
3
+ import { posix } from "node:path";
4
+ //#region src/fs-ops.ts
5
+ async function ensureMissingOrReplaceable(workspace, path, overwrite = false) {
6
+ if (!await workspace.exists(path)) return;
7
+ if (!overwrite) throw new WorkspaceError(`[vitehub] Workspace path already exists: ${path}.`);
8
+ await workspace.rm(path, {
9
+ recursive: true,
10
+ force: true
11
+ });
12
+ }
13
+ async function copyWorkspacePath(workspace, from, to, overwrite = false) {
14
+ if (from === to) throw new WorkspaceError("[vitehub] Source and destination must be different.");
15
+ const source = await workspace.stat(from);
16
+ if (source.type === "directory" && to.startsWith(`${from}/`)) throw new WorkspaceError("[vitehub] Destination cannot be nested inside the source directory.");
17
+ await ensureMissingOrReplaceable(workspace, to, overwrite);
18
+ if (source.type === "file") {
19
+ const content = await workspace.readFile(from, { encoding: "binary" });
20
+ await workspace.writeFile(to, content, { mediaType: source.mediaType });
21
+ return;
22
+ }
23
+ const entries = await workspace.list(from, { recursive: true });
24
+ await workspace.mkdir(to, { recursive: true });
25
+ const directories = entries.filter((entry) => entry.type === "directory").sort((left, right) => left.path.length - right.path.length);
26
+ for (const entry of directories) await workspace.mkdir(posix.join(to, posix.relative(from, entry.path)), { recursive: true });
27
+ await Promise.all(entries.filter((entry) => entry.type === "file").map(async (entry) => {
28
+ const content = await workspace.readFile(entry.path, { encoding: "binary" });
29
+ await workspace.writeFile(posix.join(to, posix.relative(from, entry.path)), content, { mediaType: entry.mediaType });
30
+ }));
31
+ }
32
+ async function appendWorkspaceFile(workspace, path, content) {
33
+ let current = "";
34
+ try {
35
+ current = String(await workspace.readFile(path));
36
+ } catch (error) {
37
+ if (!(error instanceof WorkspaceError)) throw error;
38
+ }
39
+ await workspace.writeFile(path, `${current}${content}`);
40
+ }
41
+ //#endregion
42
+ //#region src/ai.ts
43
+ const defaultMaxOutputLength = 3e4;
44
+ const workspaceMountPoint = "/workspace";
45
+ const aiSchemaSymbol = Symbol.for("vercel.ai.schema");
46
+ function jsonSchema(schema, { validate } = {}) {
47
+ let resolved = schema;
48
+ return {
49
+ [aiSchemaSymbol]: true,
50
+ _type: void 0,
51
+ get jsonSchema() {
52
+ if (typeof resolved === "function") resolved = resolved();
53
+ return resolved;
54
+ },
55
+ validate
56
+ };
57
+ }
58
+ function tool(definition) {
59
+ return definition;
60
+ }
61
+ function isWorkspace(input) {
62
+ return "sync" in input;
63
+ }
64
+ function cleanMutationPath(path) {
65
+ const normalized = cleanWorkspaceShellPath(path);
66
+ if (!normalized) throw new Error("[vitehub] Workspace root is not a valid mutation target.");
67
+ return normalized;
68
+ }
69
+ function resolveReadOperations(operations) {
70
+ return {
71
+ list: operations?.list !== false,
72
+ materialize: operations?.materialize === true,
73
+ read: operations?.read !== false,
74
+ search: operations?.search !== false
75
+ };
76
+ }
77
+ function resolveWriteOperations(write) {
78
+ if (write === true) return {
79
+ appendFile: true,
80
+ copyPath: true,
81
+ deletePath: true,
82
+ makeDir: true,
83
+ movePath: true,
84
+ writeFile: true
85
+ };
86
+ return {
87
+ appendFile: write?.appendFile === true,
88
+ copyPath: write?.copyPath === true,
89
+ deletePath: write?.deletePath === true,
90
+ makeDir: write?.makeDir === true,
91
+ movePath: write?.movePath === true,
92
+ writeFile: write?.writeFile === true
93
+ };
94
+ }
95
+ function shellCommandsFor(operations) {
96
+ const commands = [];
97
+ if (operations.list) commands.push("pwd", "ls", "find");
98
+ if (operations.read) commands.push("cat", "head", "tail", "wc");
99
+ if (operations.search) commands.push("grep", "rg");
100
+ return commands;
101
+ }
102
+ function describeShellCommands(commands) {
103
+ const supported = new Set(commands);
104
+ return [
105
+ "Run a real Bash-compatible workspace shell command over files mounted at `/workspace`.",
106
+ `Available workspace commands include: ${[
107
+ supported.has("pwd") && "`pwd`",
108
+ supported.has("ls") && "`ls`",
109
+ supported.has("find") && "`find`",
110
+ (supported.has("rg") || supported.has("grep")) && "`rg [-i] pattern [path...]`, `grep -ri pattern [path...]`",
111
+ supported.has("cat") && "`cat`",
112
+ supported.has("head") && "`head`",
113
+ supported.has("tail") && "`tail`",
114
+ supported.has("wc") && "`wc`"
115
+ ].filter(Boolean).join(", ")}.`,
116
+ "Pipes, redirects, chaining, quoted patterns, and multiline shell scripts are supported by the shell runtime.",
117
+ "The workspace filesystem controls whether writes are allowed; read-only tools reject mutation commands at execution time.",
118
+ "Do not use shell commands such as `echo` to compose assistant replies; answer conversational messages directly.",
119
+ "Examples: `rg 'siff|PLC' ingestion forecasting-engine | head -n 20`; `find ingestion -type f -name '*.sql'`; `cat forecasting-engine/README.md | head -n 40`."
120
+ ].join(" ");
121
+ }
122
+ async function runShellCommand(input, command, options) {
123
+ return await runWorkspaceInspectionCommand(input, command, {
124
+ broadSearchPaths: options.broadSearchPaths,
125
+ commands: options.commands,
126
+ cwd: options.cwd,
127
+ fs: createReadonlyWorkspaceFs(input),
128
+ maxOutputLength: options.maxOutputLength,
129
+ timeout: options.timeout
130
+ });
131
+ }
132
+ function sizeOf(content) {
133
+ return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
134
+ }
135
+ async function materializeWorkspaceSourcesTool(input, options) {
136
+ if ("materializeSources" in input && typeof input.materializeSources === "function") return await input.materializeSources(options);
137
+ const started = Date.now();
138
+ const path = cleanWorkspaceShellPath(options.path || "") || "";
139
+ const entries = await input.list(path, { recursive: true });
140
+ let bytes = 0;
141
+ let directories = 0;
142
+ let files = 0;
143
+ for (const entry of entries) {
144
+ if (entry.type === "directory") {
145
+ directories++;
146
+ continue;
147
+ }
148
+ const content = await input.readFile(entry.path, { encoding: "binary" });
149
+ bytes += sizeOf(content);
150
+ files++;
151
+ }
152
+ return {
153
+ bytes,
154
+ directories,
155
+ durationMs: Date.now() - started,
156
+ files,
157
+ path,
158
+ sources: []
159
+ };
160
+ }
161
+ function createWriteTools(workspace, enabled) {
162
+ const result = {};
163
+ if (enabled.writeFile) result.writeFile = tool({
164
+ description: "Write a text file to the workspace.",
165
+ inputSchema: jsonSchema({
166
+ additionalProperties: false,
167
+ properties: {
168
+ content: { type: "string" },
169
+ mediaType: { type: "string" },
170
+ path: { type: "string" }
171
+ },
172
+ required: ["path", "content"],
173
+ type: "object"
174
+ }),
175
+ execute: async ({ content, mediaType, path }) => {
176
+ const normalized = cleanMutationPath(path);
177
+ await workspace.writeFile(normalized, content, { mediaType });
178
+ return { path: normalized };
179
+ }
180
+ });
181
+ if (enabled.appendFile) result.appendFile = tool({
182
+ description: "Append text to a workspace file, creating it if it does not exist.",
183
+ inputSchema: jsonSchema({
184
+ additionalProperties: false,
185
+ properties: {
186
+ content: { type: "string" },
187
+ path: { type: "string" }
188
+ },
189
+ required: ["path", "content"],
190
+ type: "object"
191
+ }),
192
+ execute: async ({ content, path }) => {
193
+ const normalized = cleanMutationPath(path);
194
+ await appendWorkspaceFile(workspace, normalized, content);
195
+ return { path: normalized };
196
+ }
197
+ });
198
+ if (enabled.deletePath) result.deletePath = tool({
199
+ description: "Delete a file or directory from the workspace.",
200
+ inputSchema: jsonSchema({
201
+ additionalProperties: false,
202
+ properties: {
203
+ force: { type: "boolean" },
204
+ path: { type: "string" },
205
+ recursive: { type: "boolean" }
206
+ },
207
+ required: ["path"],
208
+ type: "object"
209
+ }),
210
+ execute: async ({ force, path, recursive }) => {
211
+ const normalized = cleanMutationPath(path);
212
+ await workspace.rm(normalized, {
213
+ force,
214
+ recursive
215
+ });
216
+ return { path: normalized };
217
+ }
218
+ });
219
+ if (enabled.makeDir) result.makeDir = tool({
220
+ description: "Create a directory in the workspace.",
221
+ inputSchema: jsonSchema({
222
+ additionalProperties: false,
223
+ properties: {
224
+ path: { type: "string" },
225
+ recursive: { type: "boolean" }
226
+ },
227
+ required: ["path"],
228
+ type: "object"
229
+ }),
230
+ execute: async ({ path, recursive }) => {
231
+ const normalized = cleanMutationPath(path);
232
+ await workspace.mkdir(normalized, { recursive });
233
+ return { path: normalized };
234
+ }
235
+ });
236
+ if (enabled.copyPath) result.copyPath = tool({
237
+ description: "Copy a file or directory inside the workspace.",
238
+ inputSchema: jsonSchema({
239
+ additionalProperties: false,
240
+ properties: {
241
+ from: { type: "string" },
242
+ overwrite: { type: "boolean" },
243
+ to: { type: "string" }
244
+ },
245
+ required: ["from", "to"],
246
+ type: "object"
247
+ }),
248
+ execute: async ({ from, overwrite = false, to }) => {
249
+ const source = cleanMutationPath(from);
250
+ const target = cleanMutationPath(to);
251
+ await copyWorkspacePath(workspace, source, target, overwrite);
252
+ return {
253
+ from: source,
254
+ to: target
255
+ };
256
+ }
257
+ });
258
+ if (enabled.movePath) result.movePath = tool({
259
+ description: "Move or rename a file or directory inside the workspace.",
260
+ inputSchema: jsonSchema({
261
+ additionalProperties: false,
262
+ properties: {
263
+ from: { type: "string" },
264
+ overwrite: { type: "boolean" },
265
+ to: { type: "string" }
266
+ },
267
+ required: ["from", "to"],
268
+ type: "object"
269
+ }),
270
+ execute: async ({ from, overwrite = false, to }) => {
271
+ const source = cleanMutationPath(from);
272
+ const target = cleanMutationPath(to);
273
+ await copyWorkspacePath(workspace, source, target, overwrite);
274
+ await workspace.rm(source, {
275
+ recursive: true,
276
+ force: true
277
+ });
278
+ return {
279
+ from: source,
280
+ to: target
281
+ };
282
+ }
283
+ });
284
+ return result;
285
+ }
286
+ function createWorkspaceTools(input, options = {}) {
287
+ const resolved = {
288
+ broadSearchPaths: options.broadSearchPaths || [],
289
+ commands: shellCommandsFor(resolveReadOperations(options.operations)),
290
+ cwd: options.cwd || workspaceMountPoint,
291
+ materialize: resolveReadOperations(options.operations).materialize,
292
+ maxShellCalls: options.maxShellCalls,
293
+ maxOutputLength: options.maxOutputLength || defaultMaxOutputLength,
294
+ timeout: options.timeout,
295
+ write: resolveWriteOperations(options.operations?.write)
296
+ };
297
+ let shellCalls = 0;
298
+ const writeEnabled = Object.values(resolved.write).some(Boolean);
299
+ if (!resolved.commands.length && !resolved.materialize && !writeEnabled) throw new TypeError("[vitehub] createWorkspaceTools requires at least one enabled workspace operation.");
300
+ if (writeEnabled && !isWorkspace(input)) throw new TypeError("[vitehub] Write operations require a mutable Workspace. Use useWorkspace(name, { mode: \"write\" }).tools.write().");
301
+ const result = {};
302
+ if (resolved.commands.length) result.shell = tool({
303
+ description: describeShellCommands(resolved.commands),
304
+ inputSchema: jsonSchema({
305
+ additionalProperties: false,
306
+ properties: { command: {
307
+ description: "A Bash-compatible workspace shell command. Use pipes, redirects, chaining, and quoted patterns as needed.",
308
+ type: "string"
309
+ } },
310
+ required: ["command"],
311
+ type: "object"
312
+ }),
313
+ execute: async ({ command }) => {
314
+ if (typeof resolved.maxShellCalls === "number" && shellCalls >= resolved.maxShellCalls) return {
315
+ command,
316
+ cwd: resolved.cwd,
317
+ event: "policy_denied",
318
+ exitCode: 126,
319
+ stderr: `[vitehub] Workspace shell command budget exhausted after ${resolved.maxShellCalls} calls. Answer from the evidence already collected instead of running more shell commands.\n`,
320
+ stdout: ""
321
+ };
322
+ shellCalls += 1;
323
+ return await runShellCommand(input, command, resolved);
324
+ }
325
+ });
326
+ if (resolved.materialize) result.materialize_sources = tool({
327
+ description: ["Materialize complete workspace source snapshots as an explicit tool step before shell inspection.", "This prepares whole sources, not individual files or partial limits."].join(" "),
328
+ inputSchema: jsonSchema({
329
+ additionalProperties: false,
330
+ properties: {
331
+ path: {
332
+ description: "Workspace path prefix to materialize. Defaults to the workspace root.",
333
+ type: "string"
334
+ },
335
+ sources: {
336
+ description: "Optional source names to materialize.",
337
+ items: { type: "string" },
338
+ type: "array"
339
+ }
340
+ },
341
+ type: "object"
342
+ }),
343
+ execute: async ({ path, sources }) => await materializeWorkspaceSourcesTool(input, {
344
+ path,
345
+ sources
346
+ })
347
+ });
348
+ if (writeEnabled) Object.assign(result, createWriteTools(input, resolved.write));
349
+ return result;
350
+ }
351
+ //#endregion
352
+ export { appendWorkspaceFile as n, copyWorkspacePath as r, createWorkspaceTools as t };
package/dist/ai.d.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { B as WorkspaceMaterializeSourcesResult, C as WorkspaceAssets, x as Workspace } from "./types-CwNcWTdt.js";
2
+ import { ShellObservation, ShellSessionPolicy } from "@vite-hub/shell";
3
+ import { Tool, ToolSet } from "ai";
4
+
5
+ //#region src/ai.d.ts
6
+ type WorkspaceShellResult = ShellObservation;
7
+ interface WorkspacePathResult {
8
+ path: string;
9
+ }
10
+ interface WorkspaceMoveResult {
11
+ from: string;
12
+ to: string;
13
+ }
14
+ interface WorkspaceReadOperations {
15
+ list?: boolean;
16
+ materialize?: boolean;
17
+ read?: boolean;
18
+ search?: boolean;
19
+ }
20
+ interface WorkspaceWriteOperations {
21
+ appendFile?: boolean;
22
+ copyPath?: boolean;
23
+ deletePath?: boolean;
24
+ makeDir?: boolean;
25
+ movePath?: boolean;
26
+ writeFile?: boolean;
27
+ }
28
+ type WorkspaceToolOperations = WorkspaceReadOperations & {
29
+ write?: true | WorkspaceWriteOperations;
30
+ };
31
+ interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
32
+ broadSearchPaths?: string[];
33
+ cwd?: string;
34
+ operations?: Operations;
35
+ }
36
+ type EnabledReadCapability<Operations, Key extends keyof WorkspaceReadOperations> = Operations extends Record<Key, infer Value> ? Value extends false ? false : true : true;
37
+ type ShellEnabled<Operations> = true extends EnabledReadCapability<Operations, "list"> | EnabledReadCapability<Operations, "read"> | EnabledReadCapability<Operations, "search"> ? true : false;
38
+ type ResolvedWriteOperations<Operations> = Operations extends {
39
+ write: infer Write;
40
+ } ? Write : false;
41
+ type WorkspaceWriteToolMap = {
42
+ appendFile: Tool<{
43
+ content: string;
44
+ path: string;
45
+ }, WorkspacePathResult>;
46
+ copyPath: Tool<{
47
+ from: string;
48
+ overwrite?: boolean;
49
+ to: string;
50
+ }, WorkspaceMoveResult>;
51
+ deletePath: Tool<{
52
+ force?: boolean;
53
+ path: string;
54
+ recursive?: boolean;
55
+ }, WorkspacePathResult>;
56
+ makeDir: Tool<{
57
+ path: string;
58
+ recursive?: boolean;
59
+ }, WorkspacePathResult>;
60
+ movePath: Tool<{
61
+ from: string;
62
+ overwrite?: boolean;
63
+ to: string;
64
+ }, WorkspaceMoveResult>;
65
+ writeFile: Tool<{
66
+ content: string;
67
+ mediaType?: string;
68
+ path: string;
69
+ }, WorkspacePathResult>;
70
+ };
71
+ type EnabledWriteTools<Selection> = Selection extends true ? WorkspaceWriteToolMap : Selection extends WorkspaceWriteOperations ? { [Key in keyof WorkspaceWriteToolMap as Key extends keyof Selection ? Selection[Key] extends true ? Key : never : never]: WorkspaceWriteToolMap[Key] } : {};
72
+ type WorkspaceTools<Operations = undefined> = ((ShellEnabled<Operations> extends true ? {
73
+ shell: Tool<{
74
+ command: string;
75
+ }, WorkspaceShellResult>;
76
+ } : {}) & EnabledWriteTools<ResolvedWriteOperations<Operations>> & (Operations extends {
77
+ materialize: true;
78
+ } ? {
79
+ materialize_sources: Tool<{
80
+ path?: string;
81
+ sources?: string[];
82
+ }, WorkspaceMaterializeSourcesResult>;
83
+ } : {})) & ToolSet;
84
+ declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations>): WorkspaceTools<Operations>;
85
+ //#endregion
86
+ export { EnabledReadCapability, ShellEnabled, type WorkspaceMaterializeSourcesResult, WorkspaceMoveResult, WorkspacePathResult, WorkspaceReadOperations, WorkspaceShellResult, WorkspaceToolOperations, WorkspaceToolOptions, WorkspaceTools, WorkspaceWriteOperations, WorkspaceWriteToolMap, createWorkspaceTools };
package/dist/ai.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as createWorkspaceTools } from "./ai-Bk3LLnit.js";
2
+ export { createWorkspaceTools };
@@ -0,0 +1,14 @@
1
+ import { n as WorkspaceNotFoundError } from "./errors-BUL8SoFS.js";
2
+ import workspaceAssetsRegistry from "#vitehub-workspace-assets-registry";
3
+ //#region src/asset-registry.ts
4
+ let assetsRegistry = workspaceAssetsRegistry;
5
+ function setWorkspaceAssetsRegistry(registry) {
6
+ assetsRegistry = registry;
7
+ }
8
+ function useWorkspaceAssets(name) {
9
+ const assets = assetsRegistry[name];
10
+ if (!assets) throw new WorkspaceNotFoundError(name);
11
+ return assets;
12
+ }
13
+ //#endregion
14
+ export { useWorkspaceAssets as n, setWorkspaceAssetsRegistry as t };
@@ -0,0 +1,14 @@
1
+ import "node:module";
2
+ //#region \0rolldown/runtime.js
3
+ var __defProp = Object.defineProperty;
4
+ var __exportAll = (all, no_symbols) => {
5
+ let target = {};
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
+ return target;
12
+ };
13
+ //#endregion
14
+ export { __exportAll as t };
@@ -0,0 +1,12 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ //#region ../internal/src/runtime/cloudflare-env.ts
3
+ let activeEnv;
4
+ const activeEnvStorage = new AsyncLocalStorage();
5
+ function getActiveCloudflareEnv() {
6
+ return activeEnvStorage.getStore() ?? activeEnv ?? globalThis.__env__;
7
+ }
8
+ function getActiveCloudflareBinding(name) {
9
+ return getActiveCloudflareEnv()?.[name];
10
+ }
11
+ //#endregion
12
+ export { getActiveCloudflareBinding as t };
@@ -0,0 +1,49 @@
1
+ import { i as normalizeSafeWorkspacePath } from "./path-BVv9OXhg.js";
2
+ import { defu } from "defu";
3
+ //#region src/sources/config.ts
4
+ const liveSourcePaths = /* @__PURE__ */ new WeakMap();
5
+ function markLiveWorkspaceSource(source, paths) {
6
+ liveSourcePaths.set(source, paths);
7
+ return source;
8
+ }
9
+ function createSourceContext(definition) {
10
+ return {
11
+ rootDir: definition.rootDir || process.cwd(),
12
+ sourceRootDir: definition.sourceRootDir,
13
+ workspace: definition.name
14
+ };
15
+ }
16
+ function normalizeWorkspaceSources(sources) {
17
+ if (!sources) return [];
18
+ return Object.entries(sources).map(([key, source]) => normalizeWorkspaceSource(key, source)).sort((left, right) => right.mountPath.length - left.mountPath.length || left.key.localeCompare(right.key));
19
+ }
20
+ function normalizeWorkspaceSource(key, source) {
21
+ const mount = normalizeSourceMount(source);
22
+ const cache = mount.cache ?? normalizeSourceCache(source) ?? false;
23
+ return {
24
+ key,
25
+ source,
26
+ mountPath: normalizeSafeWorkspacePath(typeof mount.path === "string" ? mount.path : key, { allowEmpty: true }),
27
+ materialize: mount.materialize || source.materialize || (cache ? "lazy" : "build"),
28
+ cache,
29
+ validate: mount.validate ?? source.validate ?? false,
30
+ livePaths: liveSourcePaths.get(source),
31
+ readonly: true
32
+ };
33
+ }
34
+ function sourceMountContainsPath(source, workspacePath) {
35
+ return workspacePath === source.mountPath || !!source.mountPath && workspacePath.startsWith(`${source.mountPath}/`);
36
+ }
37
+ function sourceMountIntersectsPath(source, workspacePath) {
38
+ return !workspacePath || !source.mountPath || sourceMountContainsPath(source, workspacePath) || source.mountPath.startsWith(`${workspacePath}/`);
39
+ }
40
+ function normalizeSourceMount(source) {
41
+ if (typeof source.mount === "string") return { path: source.mount };
42
+ return source.mount || {};
43
+ }
44
+ function normalizeSourceCache(source) {
45
+ if (source.cache === false) return false;
46
+ if (source.cache) return defu(source.cache, {});
47
+ }
48
+ //#endregion
49
+ export { sourceMountIntersectsPath as a, sourceMountContainsPath as i, markLiveWorkspaceSource as n, normalizeWorkspaceSources as r, createSourceContext as t };
@@ -0,0 +1,21 @@
1
+ //#region src/core/errors.ts
2
+ var WorkspaceError = class extends Error {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ this.name = "WorkspaceError";
6
+ }
7
+ };
8
+ var WorkspaceNotFoundError = class extends WorkspaceError {
9
+ constructor(name) {
10
+ super(`[vitehub] Workspace "${name}" is not registered.`);
11
+ this.name = "WorkspaceNotFoundError";
12
+ }
13
+ };
14
+ var WorkspacePathError = class extends WorkspaceError {
15
+ constructor(path) {
16
+ super(`[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(path)}.`);
17
+ this.name = "WorkspacePathError";
18
+ }
19
+ };
20
+ //#endregion
21
+ export { WorkspaceNotFoundError as n, WorkspacePathError as r, WorkspaceError as t };