@vite-hub/workspace 0.0.0 → 0.0.2

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 (84) hide show
  1. package/README.md +262 -1
  2. package/dist/ai-Cztw4eLk.js +472 -0
  3. package/dist/ai-hFdsvDHC.d.ts +162 -0
  4. package/dist/ai.d.ts +3 -0
  5. package/dist/ai.js +2 -0
  6. package/dist/artifacts-store-BAV9jZpd.js +555 -0
  7. package/dist/asset-registry-CaG9b7tf.js +19 -0
  8. package/dist/chunk-8H4AJuhK.js +14 -0
  9. package/dist/cli.d.ts +31 -0
  10. package/dist/cli.js +303 -0
  11. package/dist/cloudflare-env-CKxUs2fa.js +20 -0
  12. package/dist/cloudflare.d.ts +16 -0
  13. package/dist/cloudflare.js +3 -0
  14. package/dist/collections/client.d.ts +39 -0
  15. package/dist/collections/client.js +137 -0
  16. package/dist/collections.d.ts +59 -0
  17. package/dist/collections.js +159 -0
  18. package/dist/config--r5unwPc.js +7811 -0
  19. package/dist/config-Ca5DM8fF.d.ts +28 -0
  20. package/dist/config-DCQ6y30R.js +30 -0
  21. package/dist/file-B2q9NE18.js +24 -0
  22. package/dist/files-xy0le-_U.js +51 -0
  23. package/dist/github-lIO6-2sH.js +194 -0
  24. package/dist/glob-DeH0dzZX.js +23 -0
  25. package/dist/host-I-_vDs05.js +370 -0
  26. package/dist/hosted-vercel-blob.d.ts +15 -0
  27. package/dist/hosted-vercel-blob.js +26 -0
  28. package/dist/hosted.d.ts +18 -0
  29. package/dist/hosted.js +30 -0
  30. package/dist/index.d.ts +185 -0
  31. package/dist/index.js +541 -0
  32. package/dist/lifecycle-Lhk3dAMt.js +176 -0
  33. package/dist/loader.d.ts +17 -0
  34. package/dist/loader.js +22 -0
  35. package/dist/nitro.d.ts +2 -0
  36. package/dist/nitro.js +2 -0
  37. package/dist/nuxt.d.ts +26 -0
  38. package/dist/nuxt.js +36 -0
  39. package/dist/path-CNI6wKIU.js +115 -0
  40. package/dist/provider-CeQciesl.js +599 -0
  41. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  42. package/dist/providers/cloudflare/artifacts-store.js +2 -0
  43. package/dist/providers/github/store.d.ts +6 -0
  44. package/dist/providers/github/store.js +362 -0
  45. package/dist/providers/vercel/blob-store.d.ts +6 -0
  46. package/dist/providers/vercel/blob-store.js +235 -0
  47. package/dist/publish.d.ts +35 -0
  48. package/dist/publish.js +112 -0
  49. package/dist/registry-C7DMdBXN.js +74 -0
  50. package/dist/registry-CoC9JxVt.d.ts +11 -0
  51. package/dist/request-execution-C8qRcReq.js +80 -0
  52. package/dist/runtime/assets.d.ts +12 -0
  53. package/dist/runtime/assets.js +138 -0
  54. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  55. package/dist/runtime/empty-assets-registry.js +4 -0
  56. package/dist/runtime/empty-registry.d.ts +6 -0
  57. package/dist/runtime/empty-registry.js +4 -0
  58. package/dist/runtime/state.d.ts +4 -0
  59. package/dist/runtime/state.js +15 -0
  60. package/dist/runtime/workspace.d.ts +2 -0
  61. package/dist/runtime/workspace.js +2 -0
  62. package/dist/runtime.d.ts +38 -0
  63. package/dist/runtime.js +643 -0
  64. package/dist/search-C4REyHj9.js +39 -0
  65. package/dist/server.d.ts +65 -0
  66. package/dist/server.js +355 -0
  67. package/dist/shared-BRycRSbo.js +255 -0
  68. package/dist/source-metadata.d.ts +2 -0
  69. package/dist/source-metadata.js +2 -0
  70. package/dist/state-DSAHEsq6.d.ts +25 -0
  71. package/dist/sync-DO42ypji.js +269 -0
  72. package/dist/target-D4Bqb1eH.js +11 -0
  73. package/dist/test.d.ts +2 -0
  74. package/dist/test.js +2 -0
  75. package/dist/types-DHkae7Cb.d.ts +628 -0
  76. package/dist/use-D16tf8Ph.d.ts +86 -0
  77. package/dist/use-d_PlAdOu.js +353 -0
  78. package/dist/utils-BPdaCyI6.js +55 -0
  79. package/dist/vite-NWC9mFjI.js +1882 -0
  80. package/dist/vite.d.ts +50 -0
  81. package/dist/vite.js +2 -0
  82. package/dist/workspace-f2DBLmPZ.d.ts +6 -0
  83. package/dist/workspace-n4wBmdaM.js +1476 -0
  84. package/package.json +197 -5
@@ -0,0 +1,472 @@
1
+ import { f as isWorkspaceError, o as normalizeSafeWorkspacePath, p as workspaceError } from "./path-CNI6wKIU.js";
2
+ import { r as getWorkspaceSourceRequestExecution } from "./request-execution-C8qRcReq.js";
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 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 workspaceError("[vitehub] Source and destination must be different.");
15
+ const source = await workspace.stat(from);
16
+ if (source.type === "directory" && to.startsWith(`${from}/`)) throw 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 (!isWorkspaceError(error)) throw error;
38
+ }
39
+ await workspace.writeFile(path, `${current}${content}`);
40
+ }
41
+ //#endregion
42
+ //#region src/runtime/dependency-loaders.ts
43
+ const shellWorkspaceSpecifier = "@vite-hub/shell/workspace";
44
+ const defaultWorkspaceDependencyRuntimeLoaders = { shellWorkspace: () => import(
45
+ /* @vite-ignore */
46
+ shellWorkspaceSpecifier
47
+ ) };
48
+ function workspaceDependencyRuntimeLoadersKey() {
49
+ return Symbol.for("vitehub.workspace.dependencyRuntimeLoaders");
50
+ }
51
+ function workspaceDependencyRuntimeLoadersGlobal() {
52
+ return globalThis;
53
+ }
54
+ function setWorkspaceDependencyRuntimeLoaders(loaders) {
55
+ workspaceDependencyRuntimeLoadersGlobal()[workspaceDependencyRuntimeLoadersKey()] = loaders ? {
56
+ ...defaultWorkspaceDependencyRuntimeLoaders,
57
+ ...loaders
58
+ } : void 0;
59
+ }
60
+ function getWorkspaceDependencyRuntimeLoaders() {
61
+ return workspaceDependencyRuntimeLoadersGlobal()[workspaceDependencyRuntimeLoadersKey()] ?? defaultWorkspaceDependencyRuntimeLoaders;
62
+ }
63
+ function loadWorkspaceShellModule() {
64
+ return getWorkspaceDependencyRuntimeLoaders().shellWorkspace();
65
+ }
66
+ //#endregion
67
+ //#region src/ai.ts
68
+ const defaultMaxOutputLength = 3e4;
69
+ const workspaceMountPoint = "/workspace";
70
+ const aiSchemaSymbol = Symbol.for("vercel.ai.schema");
71
+ function jsonSchema(schema, { validate } = {}) {
72
+ let resolved = schema;
73
+ return {
74
+ [aiSchemaSymbol]: true,
75
+ _type: void 0,
76
+ get jsonSchema() {
77
+ if (typeof resolved === "function") resolved = resolved();
78
+ return resolved;
79
+ },
80
+ validate
81
+ };
82
+ }
83
+ function tool(definition) {
84
+ return definition;
85
+ }
86
+ function isWorkspace(input) {
87
+ return "sync" in input;
88
+ }
89
+ function getWorkspaceSessionStarter(input) {
90
+ return typeof input.startSession === "function" ? input : void 0;
91
+ }
92
+ function createWorkspaceSessionShellProvider(starter) {
93
+ return {
94
+ boundary: {
95
+ cwd: true,
96
+ env: true,
97
+ filesystem: {
98
+ mountPoint: workspaceMountPoint,
99
+ writable: true
100
+ },
101
+ network: "unknown",
102
+ processes: {
103
+ background: false,
104
+ interactive: false
105
+ },
106
+ streaming: false,
107
+ timeout: {
108
+ enforcedBy: "provider",
109
+ supported: true
110
+ }
111
+ },
112
+ async exec(command, execOptions = {}) {
113
+ const session = await starter.startSession({ paths: execOptions.workspacePaths });
114
+ let observation;
115
+ try {
116
+ const result = await session.exec("sh", ["-lc", command], {
117
+ cwd: execOptions.cwd || workspaceMountPoint,
118
+ env: execOptions.env,
119
+ timeout: execOptions.timeout
120
+ });
121
+ execOptions.onStdout?.(result.stdout);
122
+ execOptions.onStderr?.(result.stderr);
123
+ const timedOut = result.exitCode === 124 && /timed out/i.test(result.stderr);
124
+ observation = {
125
+ command,
126
+ cwd: execOptions.cwd,
127
+ event: timedOut ? "command_timed_out" : "command_finished",
128
+ exitCode: result.exitCode,
129
+ stderr: result.stderr,
130
+ stdout: result.stdout,
131
+ timedOut
132
+ };
133
+ } catch (error) {
134
+ try {
135
+ await session.close();
136
+ } catch (closeError) {
137
+ throw new AggregateError([error, closeError], "[vitehub] Workspace shell execution failed and session cleanup also failed.");
138
+ }
139
+ throw error;
140
+ }
141
+ await session.close();
142
+ return observation;
143
+ }
144
+ };
145
+ }
146
+ async function resolveExecutionProvider(provider) {
147
+ return typeof provider === "function" ? await provider() : provider;
148
+ }
149
+ function isUnavailableWorkspaceSession(error) {
150
+ const message = error instanceof Error ? error.message : String(error);
151
+ return message.includes("Workspace exec requires an executable runtime") || message.includes("Workspace exec requires a Box session host") || message.includes("Workspace") && message.includes("is not registered");
152
+ }
153
+ function cleanWorkspaceShellPath(path) {
154
+ return normalizeSafeWorkspacePath(path.replace(/^\/workspace(?:\/|$)/, ""), { allowEmpty: true });
155
+ }
156
+ function cleanMutationPath(path) {
157
+ const normalized = cleanWorkspaceShellPath(path);
158
+ if (!normalized) throw new Error("[vitehub] Workspace root is not a valid mutation target.");
159
+ return normalized;
160
+ }
161
+ function resolveReadOperations(operations) {
162
+ return {
163
+ list: operations?.list !== false,
164
+ materialize: operations?.materialize === true,
165
+ read: operations?.read !== false,
166
+ search: operations?.search !== false
167
+ };
168
+ }
169
+ function resolveWriteOperations(write) {
170
+ if (write === true) return {
171
+ appendFile: true,
172
+ copyPath: true,
173
+ deletePath: true,
174
+ makeDir: true,
175
+ movePath: true,
176
+ writeFile: true
177
+ };
178
+ return {
179
+ appendFile: write?.appendFile === true,
180
+ copyPath: write?.copyPath === true,
181
+ deletePath: write?.deletePath === true,
182
+ makeDir: write?.makeDir === true,
183
+ movePath: write?.movePath === true,
184
+ writeFile: write?.writeFile === true
185
+ };
186
+ }
187
+ function shellCommandsFor(operations) {
188
+ const commands = [];
189
+ if (operations.list) commands.push("pwd", "ls", "find");
190
+ if (operations.read) commands.push("cat", "head", "tail", "wc");
191
+ if (operations.search) commands.push("grep", "rg");
192
+ return commands;
193
+ }
194
+ function describeShellCommands(commands, options = {}) {
195
+ const supported = new Set(commands);
196
+ const available = [
197
+ supported.has("pwd") && "`pwd`",
198
+ supported.has("ls") && "`ls`",
199
+ supported.has("find") && "`find`",
200
+ (supported.has("rg") || supported.has("grep")) && "`rg [-i] pattern [path...]`, `grep -ri pattern [path...]`",
201
+ supported.has("cat") && "`cat`",
202
+ supported.has("head") && "`head`",
203
+ supported.has("tail") && "`tail`",
204
+ supported.has("wc") && "`wc`",
205
+ options.sourceRequests && "controlled `curl` for API-backed Sources listed under `.vitehub/sources/*.json`"
206
+ ].filter(Boolean);
207
+ const examples = [
208
+ supported.has("rg") && supported.has("head") && "`rg 'siff|PLC' ingestion forecasting-engine | head -n 20`",
209
+ supported.has("rg") && !supported.has("head") && "`rg 'siff|PLC' ingestion forecasting-engine`",
210
+ supported.has("find") && "`find ingestion -type f -name '*.sql'`",
211
+ supported.has("cat") && supported.has("head") && "`cat forecasting-engine/README.md | head -n 40`",
212
+ options.sourceRequests && "`curl --json '{\"region\":\"eu\"}' https://example.com/api/source`"
213
+ ].filter(Boolean);
214
+ return [
215
+ "Inspect files in `/workspace` with a Bash-compatible shell.",
216
+ `Use these commands: ${available.join(", ")}.`,
217
+ options.sourceRequests && "For controlled `curl`, inspect the matching `.vitehub/sources/<sourceKey>.json` descriptor first; ViteHub validates the request against the Source Request Shape and injects Source credentials.",
218
+ "Pipes, redirects, chaining, quoted patterns, and multiline scripts are supported.",
219
+ "Skip unsupported helpers such as `xargs`, `awk`, `sed`, `sort`, `cut`, or `python`.",
220
+ "Answer conversational messages directly; do not use shell commands such as `echo` to compose replies.",
221
+ examples.length && `Examples: ${examples.join("; ")}.`
222
+ ].filter(Boolean).join(" ");
223
+ }
224
+ async function runShellCommand(input, command, options) {
225
+ const networkGrants = getWorkspaceSourceRequestExecution(input);
226
+ const { createReadonlyWorkspaceFs, runWorkspaceInspectionCommand } = await loadWorkspaceShellModule();
227
+ const inspectionOptions = {
228
+ broadSearchPaths: options.broadSearchPaths,
229
+ commands: networkGrants ? [...options.commands, "curl"] : options.commands,
230
+ cwd: options.cwd,
231
+ fs: createReadonlyWorkspaceFs(input),
232
+ maxOutputLength: options.maxOutputLength,
233
+ networkGrants,
234
+ timeout: options.timeout
235
+ };
236
+ const starter = getWorkspaceSessionStarter(input);
237
+ if (starter) try {
238
+ return await runWorkspaceInspectionCommand(input, command, {
239
+ ...inspectionOptions,
240
+ provider: createWorkspaceSessionShellProvider(starter)
241
+ });
242
+ } catch (error) {
243
+ if (!isUnavailableWorkspaceSession(error)) throw error;
244
+ }
245
+ const provider = await resolveExecutionProvider(options.executionProvider);
246
+ return await runWorkspaceInspectionCommand(input, command, {
247
+ ...inspectionOptions,
248
+ ...provider ? { provider } : {}
249
+ });
250
+ }
251
+ function sizeOf(content) {
252
+ return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
253
+ }
254
+ async function materializeWorkspaceSourcesTool(input, options) {
255
+ if ("materializeSources" in input && typeof input.materializeSources === "function") return await input.materializeSources(options);
256
+ const started = Date.now();
257
+ const path = cleanWorkspaceShellPath(options.path || "") || "";
258
+ const entries = await input.list(path, { recursive: true });
259
+ let bytes = 0;
260
+ let directories = 0;
261
+ let files = 0;
262
+ for (const entry of entries) {
263
+ if (entry.type === "directory") {
264
+ directories++;
265
+ continue;
266
+ }
267
+ const content = await input.readFile(entry.path, { encoding: "binary" });
268
+ bytes += sizeOf(content);
269
+ files++;
270
+ }
271
+ return {
272
+ bytes,
273
+ directories,
274
+ durationMs: Date.now() - started,
275
+ files,
276
+ path,
277
+ sources: []
278
+ };
279
+ }
280
+ function createWriteTools(workspace, enabled) {
281
+ const result = {};
282
+ if (enabled.writeFile) result.writeFile = tool({
283
+ description: "Write a text file to the workspace.",
284
+ inputSchema: jsonSchema({
285
+ additionalProperties: false,
286
+ properties: {
287
+ content: { type: "string" },
288
+ mediaType: { type: "string" },
289
+ path: { type: "string" }
290
+ },
291
+ required: ["path", "content"],
292
+ type: "object"
293
+ }),
294
+ execute: async ({ content, mediaType, path }) => {
295
+ const normalized = cleanMutationPath(path);
296
+ await workspace.writeFile(normalized, content, { mediaType });
297
+ return { path: normalized };
298
+ }
299
+ });
300
+ if (enabled.appendFile) result.appendFile = tool({
301
+ description: "Append text to a workspace file, creating it if it does not exist.",
302
+ inputSchema: jsonSchema({
303
+ additionalProperties: false,
304
+ properties: {
305
+ content: { type: "string" },
306
+ path: { type: "string" }
307
+ },
308
+ required: ["path", "content"],
309
+ type: "object"
310
+ }),
311
+ execute: async ({ content, path }) => {
312
+ const normalized = cleanMutationPath(path);
313
+ await appendWorkspaceFile(workspace, normalized, content);
314
+ return { path: normalized };
315
+ }
316
+ });
317
+ if (enabled.deletePath) result.deletePath = tool({
318
+ description: "Delete a file or directory from the workspace.",
319
+ inputSchema: jsonSchema({
320
+ additionalProperties: false,
321
+ properties: {
322
+ force: { type: "boolean" },
323
+ path: { type: "string" },
324
+ recursive: { type: "boolean" }
325
+ },
326
+ required: ["path"],
327
+ type: "object"
328
+ }),
329
+ execute: async ({ force, path, recursive }) => {
330
+ const normalized = cleanMutationPath(path);
331
+ await workspace.rm(normalized, {
332
+ force,
333
+ recursive
334
+ });
335
+ return { path: normalized };
336
+ }
337
+ });
338
+ if (enabled.makeDir) result.makeDir = tool({
339
+ description: "Create a directory in the workspace.",
340
+ inputSchema: jsonSchema({
341
+ additionalProperties: false,
342
+ properties: {
343
+ path: { type: "string" },
344
+ recursive: { type: "boolean" }
345
+ },
346
+ required: ["path"],
347
+ type: "object"
348
+ }),
349
+ execute: async ({ path, recursive }) => {
350
+ const normalized = cleanMutationPath(path);
351
+ await workspace.mkdir(normalized, { recursive });
352
+ return { path: normalized };
353
+ }
354
+ });
355
+ if (enabled.copyPath) result.copyPath = tool({
356
+ description: "Copy a file or directory inside the workspace.",
357
+ inputSchema: jsonSchema({
358
+ additionalProperties: false,
359
+ properties: {
360
+ from: { type: "string" },
361
+ overwrite: { type: "boolean" },
362
+ to: { type: "string" }
363
+ },
364
+ required: ["from", "to"],
365
+ type: "object"
366
+ }),
367
+ execute: async ({ from, overwrite = false, to }) => {
368
+ const source = cleanMutationPath(from);
369
+ const target = cleanMutationPath(to);
370
+ await copyWorkspacePath(workspace, source, target, overwrite);
371
+ return {
372
+ from: source,
373
+ to: target
374
+ };
375
+ }
376
+ });
377
+ if (enabled.movePath) result.movePath = tool({
378
+ description: "Move or rename a file or directory inside the workspace.",
379
+ inputSchema: jsonSchema({
380
+ additionalProperties: false,
381
+ properties: {
382
+ from: { type: "string" },
383
+ overwrite: { type: "boolean" },
384
+ to: { type: "string" }
385
+ },
386
+ required: ["from", "to"],
387
+ type: "object"
388
+ }),
389
+ execute: async ({ from, overwrite = false, to }) => {
390
+ const source = cleanMutationPath(from);
391
+ const target = cleanMutationPath(to);
392
+ await copyWorkspacePath(workspace, source, target, overwrite);
393
+ await workspace.rm(source, {
394
+ recursive: true,
395
+ force: true
396
+ });
397
+ return {
398
+ from: source,
399
+ to: target
400
+ };
401
+ }
402
+ });
403
+ return result;
404
+ }
405
+ function createWorkspaceTools(input, options = {}) {
406
+ const resolved = {
407
+ broadSearchPaths: options.broadSearchPaths || [],
408
+ commands: shellCommandsFor(resolveReadOperations(options.operations)),
409
+ cwd: options.cwd || workspaceMountPoint,
410
+ executionProvider: options.executionProvider,
411
+ materialize: resolveReadOperations(options.operations).materialize,
412
+ maxShellCalls: options.maxShellCalls,
413
+ maxOutputLength: options.maxOutputLength || defaultMaxOutputLength,
414
+ timeout: options.timeout,
415
+ write: resolveWriteOperations(options.operations?.write)
416
+ };
417
+ let shellCalls = 0;
418
+ const writeEnabled = Object.values(resolved.write).some(Boolean);
419
+ if (!resolved.commands.length && !resolved.materialize && !writeEnabled) throw new TypeError("[vitehub] createWorkspaceTools requires at least one enabled workspace operation.");
420
+ if (writeEnabled && !isWorkspace(input)) throw new TypeError("[vitehub] Write operations require a mutable Workspace. A useWorkspace(name, { mode: \"write\" }).tools.write() call provides one.");
421
+ const result = {};
422
+ if (resolved.commands.length) result.shell = tool({
423
+ description: describeShellCommands(resolved.commands, { sourceRequests: Boolean(getWorkspaceSourceRequestExecution(input)) }),
424
+ inputSchema: jsonSchema({
425
+ additionalProperties: false,
426
+ properties: { command: {
427
+ description: "A Bash-compatible workspace shell command. Use pipes, redirects, chaining, and quoted patterns as needed.",
428
+ type: "string"
429
+ } },
430
+ required: ["command"],
431
+ type: "object"
432
+ }),
433
+ execute: async ({ command }) => {
434
+ if (typeof resolved.maxShellCalls === "number" && shellCalls >= resolved.maxShellCalls) return {
435
+ command,
436
+ cwd: resolved.cwd,
437
+ event: "policy_denied",
438
+ exitCode: 126,
439
+ stderr: `[vitehub] Workspace shell command budget exhausted after ${resolved.maxShellCalls} calls. The Workspace Tools shell call budget is exhausted for this run.\n`,
440
+ stdout: ""
441
+ };
442
+ shellCalls += 1;
443
+ return await runShellCommand(input, command, resolved);
444
+ }
445
+ });
446
+ if (resolved.materialize) result.materialize_sources = tool({
447
+ 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(" "),
448
+ inputSchema: jsonSchema({
449
+ additionalProperties: false,
450
+ properties: {
451
+ path: {
452
+ description: "Workspace path prefix to materialize. Defaults to the workspace root.",
453
+ type: "string"
454
+ },
455
+ sources: {
456
+ description: "Optional source names to materialize.",
457
+ items: { type: "string" },
458
+ type: "array"
459
+ }
460
+ },
461
+ type: "object"
462
+ }),
463
+ execute: async ({ path, sources }) => await materializeWorkspaceSourcesTool(input, {
464
+ path,
465
+ sources
466
+ })
467
+ });
468
+ if (writeEnabled) Object.assign(result, createWriteTools(input, resolved.write));
469
+ return result;
470
+ }
471
+ //#endregion
472
+ export { copyWorkspacePath as a, appendWorkspaceFile as i, getWorkspaceDependencyRuntimeLoaders as n, setWorkspaceDependencyRuntimeLoaders as r, createWorkspaceTools as t };
@@ -0,0 +1,162 @@
1
+ import { D as WorkspaceAssets, T as Workspace, et as WorkspaceMaterializeSourcesResult } from "./types-DHkae7Cb.js";
2
+ import { Tool, ToolSet } from "ai";
3
+
4
+ //#region src/ai.d.ts
5
+ type ShellObservationEvent = "command_finished" | "command_timed_out" | "policy_denied" | "session_disposed";
6
+ interface ShellRuntimeExecOptions {
7
+ cwd?: string;
8
+ env?: Record<string, string>;
9
+ onStderr?: (chunk: string) => void;
10
+ onStdout?: (chunk: string) => void;
11
+ stdin?: string;
12
+ timeout?: number;
13
+ workspacePaths?: string[];
14
+ }
15
+ interface ShellObservation {
16
+ command?: string;
17
+ cwd?: string;
18
+ durationMs?: number;
19
+ event: ShellObservationEvent;
20
+ exitCode: number | null;
21
+ maxOutputLength?: number;
22
+ outputTruncated?: boolean;
23
+ stderr: string;
24
+ stdout: string;
25
+ timedOut?: boolean;
26
+ workspaceGuardrail?: {
27
+ kind: "broad_search" | "missing_path" | "no_match" | "timeout";
28
+ path?: string;
29
+ };
30
+ }
31
+ interface ShellAnalyzeOptions {
32
+ maxInputBytes?: number;
33
+ timeoutMs?: number;
34
+ }
35
+ interface ShellAnalyzeResult {
36
+ commands?: string[];
37
+ error?: string;
38
+ hasCommandSubstitution?: boolean;
39
+ hasHeredocs?: boolean;
40
+ hasPipelines?: boolean;
41
+ hasRedirects?: boolean;
42
+ ok: boolean;
43
+ parser: "sh-syntax";
44
+ }
45
+ interface ShellProcess {
46
+ id: string;
47
+ command: string;
48
+ cwd?: string;
49
+ stop(): Promise<ShellObservation>;
50
+ }
51
+ interface ShellBoundary {
52
+ cwd: boolean;
53
+ env: boolean;
54
+ filesystem: {
55
+ mountPoint?: string;
56
+ writable: boolean;
57
+ };
58
+ network: boolean | "unknown";
59
+ processes: {
60
+ background: boolean;
61
+ interactive: boolean;
62
+ };
63
+ streaming: boolean;
64
+ timeout: {
65
+ enforcedBy: "provider" | "runtime" | "unsupported";
66
+ supported: boolean;
67
+ };
68
+ }
69
+ interface ShellExecutionProvider {
70
+ analyze?: (command: string, options?: ShellAnalyzeOptions) => Promise<ShellAnalyzeResult>;
71
+ boundary: ShellBoundary;
72
+ exec(command: string, options?: ShellRuntimeExecOptions): Promise<ShellObservation>;
73
+ startProcess?: (command: string, options?: ShellRuntimeExecOptions) => Promise<ShellProcess>;
74
+ }
75
+ interface ShellSessionPolicy {
76
+ maxOutputLength?: number;
77
+ maxShellCalls?: number;
78
+ timeout?: number;
79
+ }
80
+ type WorkspaceShellResult = ShellObservation;
81
+ interface WorkspacePathResult {
82
+ path: string;
83
+ }
84
+ interface WorkspaceMoveResult {
85
+ from: string;
86
+ to: string;
87
+ }
88
+ interface WorkspaceReadOperations {
89
+ list?: boolean;
90
+ materialize?: boolean;
91
+ read?: boolean;
92
+ search?: boolean;
93
+ }
94
+ interface WorkspaceWriteOperations {
95
+ appendFile?: boolean;
96
+ copyPath?: boolean;
97
+ deletePath?: boolean;
98
+ makeDir?: boolean;
99
+ movePath?: boolean;
100
+ writeFile?: boolean;
101
+ }
102
+ type WorkspaceToolOperations = WorkspaceReadOperations & {
103
+ write?: true | WorkspaceWriteOperations;
104
+ };
105
+ interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
106
+ broadSearchPaths?: string[];
107
+ cwd?: string;
108
+ executionProvider?: ShellExecutionProvider | (() => MaybePromise<ShellExecutionProvider | undefined>);
109
+ operations?: Operations;
110
+ }
111
+ type EnabledReadCapability<Operations, Key extends keyof WorkspaceReadOperations> = Operations extends Record<Key, infer Value> ? Value extends false ? false : true : true;
112
+ type ShellEnabled<Operations> = true extends EnabledReadCapability<Operations, "list"> | EnabledReadCapability<Operations, "read"> | EnabledReadCapability<Operations, "search"> ? true : false;
113
+ type ResolvedWriteOperations<Operations> = Operations extends {
114
+ write: infer Write;
115
+ } ? Write : false;
116
+ type WorkspaceWriteToolMap = {
117
+ appendFile: Tool<{
118
+ content: string;
119
+ path: string;
120
+ }, WorkspacePathResult>;
121
+ copyPath: Tool<{
122
+ from: string;
123
+ overwrite?: boolean;
124
+ to: string;
125
+ }, WorkspaceMoveResult>;
126
+ deletePath: Tool<{
127
+ force?: boolean;
128
+ path: string;
129
+ recursive?: boolean;
130
+ }, WorkspacePathResult>;
131
+ makeDir: Tool<{
132
+ path: string;
133
+ recursive?: boolean;
134
+ }, WorkspacePathResult>;
135
+ movePath: Tool<{
136
+ from: string;
137
+ overwrite?: boolean;
138
+ to: string;
139
+ }, WorkspaceMoveResult>;
140
+ writeFile: Tool<{
141
+ content: string;
142
+ mediaType?: string;
143
+ path: string;
144
+ }, WorkspacePathResult>;
145
+ };
146
+ 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] } : {};
147
+ type WorkspaceTools<Operations = undefined> = ((ShellEnabled<Operations> extends true ? {
148
+ shell: Tool<{
149
+ command: string;
150
+ }, WorkspaceShellResult>;
151
+ } : {}) & EnabledWriteTools<ResolvedWriteOperations<Operations>> & (Operations extends {
152
+ materialize: true;
153
+ } ? {
154
+ materialize_sources: Tool<{
155
+ path?: string;
156
+ sources?: string[];
157
+ }, WorkspaceMaterializeSourcesResult>;
158
+ } : {})) & ToolSet;
159
+ type MaybePromise<T> = T | Promise<T>;
160
+ declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations>): WorkspaceTools<Operations>;
161
+ //#endregion
162
+ export { WorkspaceReadOperations as a, WorkspaceToolOptions as c, WorkspaceWriteToolMap as d, createWorkspaceTools as f, WorkspacePathResult as i, WorkspaceTools as l, ShellEnabled as n, WorkspaceShellResult as o, WorkspaceMoveResult as r, WorkspaceToolOperations as s, EnabledReadCapability as t, WorkspaceWriteOperations as u };
package/dist/ai.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { et as WorkspaceMaterializeSourcesResult } from "./types-DHkae7Cb.js";
2
+ import { a as WorkspaceReadOperations, c as WorkspaceToolOptions, d as WorkspaceWriteToolMap, f as createWorkspaceTools, i as WorkspacePathResult, l as WorkspaceTools, n as ShellEnabled, o as WorkspaceShellResult, r as WorkspaceMoveResult, s as WorkspaceToolOperations, t as EnabledReadCapability, u as WorkspaceWriteOperations } from "./ai-hFdsvDHC.js";
3
+ 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-Cztw4eLk.js";
2
+ export { createWorkspaceTools };