@vite-hub/workspace 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +236 -58
- package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/host-CFnrTXTK.js +1086 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +76 -64
- package/dist/index.js +162 -457
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +10 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-Bp-8UUfG.js +129 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
- package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
- package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +9 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +84 -15
- package/dist/runtime.js +561 -108
- package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -355
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +7 -1
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CO62GglH.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
- package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
- package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/workspace-6pxkOuxr.js +1286 -0
- package/dist/workspace-BWJQBK1u.d.ts +7 -0
- package/package.json +90 -59
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-CDoyls2X.js +0 -30
- package/dist/config-CZLO0m9h.js +0 -7811
- package/dist/file-CHfsZpso.js +0 -23
- package/dist/glob-D0vD_wRY.js +0 -17
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/provider-C3_elpEh.js +0 -599
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/shared-jfogBrd5.js +0 -273
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
- package/dist/workspace-66SKyiec.d.ts +0 -6
- package/dist/workspace-C4k92Ow8.js +0 -1460
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { D as WorkspaceAssets, T as Workspace,
|
|
1
|
+
import { D as WorkspaceAssets, T as Workspace, mt as WorkspaceMaterializeSourcesResult } from "./types-DeK9GIxy.js";
|
|
2
|
+
import { ExecutionBudget } from "@vite-hub/runtime";
|
|
2
3
|
import { Tool, ToolSet } from "ai";
|
|
3
|
-
|
|
4
4
|
//#region src/ai.d.ts
|
|
5
5
|
type ShellObservationEvent = "command_finished" | "command_timed_out" | "policy_denied" | "session_disposed";
|
|
6
6
|
interface ShellRuntimeExecOptions {
|
|
7
|
+
budget?: ExecutionBudget;
|
|
7
8
|
cwd?: string;
|
|
8
9
|
env?: Record<string, string>;
|
|
10
|
+
maxOutputLength?: number;
|
|
9
11
|
onStderr?: (chunk: string) => void;
|
|
10
12
|
onStdout?: (chunk: string) => void;
|
|
13
|
+
signal?: AbortSignal;
|
|
11
14
|
stdin?: string;
|
|
12
15
|
timeout?: number;
|
|
13
16
|
workspacePaths?: string[];
|
|
@@ -65,6 +68,16 @@ interface ShellBoundary {
|
|
|
65
68
|
enforcedBy: "provider" | "runtime" | "unsupported";
|
|
66
69
|
supported: boolean;
|
|
67
70
|
};
|
|
71
|
+
execution?: {
|
|
72
|
+
isolation: "in_process" | "process" | "provider_managed" | "unknown";
|
|
73
|
+
model: "virtual" | "host" | "unknown";
|
|
74
|
+
};
|
|
75
|
+
resources?: {
|
|
76
|
+
output: {
|
|
77
|
+
enforcedBy: "provider" | "runtime" | "unsupported";
|
|
78
|
+
unit: "characters";
|
|
79
|
+
};
|
|
80
|
+
};
|
|
68
81
|
}
|
|
69
82
|
interface ShellExecutionProvider {
|
|
70
83
|
analyze?: (command: string, options?: ShellAnalyzeOptions) => Promise<ShellAnalyzeResult>;
|
|
@@ -102,14 +115,16 @@ interface WorkspaceWriteOperations {
|
|
|
102
115
|
type WorkspaceToolOperations = WorkspaceReadOperations & {
|
|
103
116
|
write?: true | WorkspaceWriteOperations;
|
|
104
117
|
};
|
|
105
|
-
interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
|
|
118
|
+
interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined, SourceRequests extends boolean = boolean> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
|
|
106
119
|
broadSearchPaths?: string[];
|
|
107
120
|
cwd?: string;
|
|
121
|
+
executionBudget?: ExecutionBudget;
|
|
108
122
|
executionProvider?: ShellExecutionProvider | (() => MaybePromise<ShellExecutionProvider | undefined>);
|
|
109
123
|
operations?: Operations;
|
|
124
|
+
sourceRequests?: SourceRequests;
|
|
110
125
|
}
|
|
111
126
|
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;
|
|
127
|
+
type ShellEnabled<Operations, SourceRequests extends boolean = false> = true extends SourceRequests | EnabledReadCapability<Operations, "list"> | EnabledReadCapability<Operations, "read"> | EnabledReadCapability<Operations, "search"> ? true : false;
|
|
113
128
|
type ResolvedWriteOperations<Operations> = Operations extends {
|
|
114
129
|
write: infer Write;
|
|
115
130
|
} ? Write : false;
|
|
@@ -143,8 +158,8 @@ type WorkspaceWriteToolMap = {
|
|
|
143
158
|
path: string;
|
|
144
159
|
}, WorkspacePathResult>;
|
|
145
160
|
};
|
|
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 ? {
|
|
161
|
+
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]; } : {};
|
|
162
|
+
type WorkspaceTools<Operations = undefined, SourceRequests extends boolean = false> = ((ShellEnabled<Operations, SourceRequests> extends true ? {
|
|
148
163
|
shell: Tool<{
|
|
149
164
|
command: string;
|
|
150
165
|
}, WorkspaceShellResult>;
|
|
@@ -157,6 +172,6 @@ type WorkspaceTools<Operations = undefined> = ((ShellEnabled<Operations> extends
|
|
|
157
172
|
}, WorkspaceMaterializeSourcesResult>;
|
|
158
173
|
} : {})) & ToolSet;
|
|
159
174
|
type MaybePromise<T> = T | Promise<T>;
|
|
160
|
-
declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations>): WorkspaceTools<Operations>;
|
|
175
|
+
declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined, SourceRequests extends boolean = false>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations, SourceRequests>): WorkspaceTools<Operations, SourceRequests>;
|
|
161
176
|
//#endregion
|
|
162
177
|
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 };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { i as isWorkspaceError, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
+
import { n as resolveWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
|
|
4
|
+
import { r as getWorkspaceSourceRequestExecution } from "./request-execution-Dk9rY-Yh.js";
|
|
3
5
|
import { posix } from "node:path";
|
|
6
|
+
import { executionBudgetCharged, executionBudgetOverride, markExecutionBudgetHandled } from "@vite-hub/runtime/internal/execution-budget";
|
|
4
7
|
//#region src/fs-ops.ts
|
|
5
8
|
async function ensureMissingOrReplaceable(workspace, path, overwrite = false) {
|
|
6
9
|
if (!await workspace.exists(path)) return;
|
|
@@ -14,6 +17,8 @@ async function copyWorkspacePath(workspace, from, to, overwrite = false) {
|
|
|
14
17
|
if (from === to) throw workspaceError("[vitehub] Source and destination must be different.");
|
|
15
18
|
const source = await workspace.stat(from);
|
|
16
19
|
if (source.type === "directory" && to.startsWith(`${from}/`)) throw workspaceError("[vitehub] Destination cannot be nested inside the source directory.");
|
|
20
|
+
if (from.startsWith(`${to}/`)) throw workspaceError("[vitehub] Destination cannot contain the source.");
|
|
21
|
+
if (overwrite && await (await resolveWorkspaceStoreTarget(workspace))?.containsPath?.(to, from)) throw workspaceError("[vitehub] Destination cannot contain the source.");
|
|
17
22
|
await ensureMissingOrReplaceable(workspace, to, overwrite);
|
|
18
23
|
if (source.type === "file") {
|
|
19
24
|
const content = await workspace.readFile(from, { encoding: "binary" });
|
|
@@ -95,10 +100,28 @@ function tool(definition) {
|
|
|
95
100
|
return definition;
|
|
96
101
|
}
|
|
97
102
|
function isWorkspace(input) {
|
|
98
|
-
return "sync"
|
|
103
|
+
return hasOwnMethod(input, "sync");
|
|
104
|
+
}
|
|
105
|
+
function hasWriteCapabilities(workspace, enabled) {
|
|
106
|
+
const required = /* @__PURE__ */ new Set();
|
|
107
|
+
if (enabled.writeFile || enabled.appendFile) required.add("writeFile");
|
|
108
|
+
if (enabled.appendFile) required.add("readFile");
|
|
109
|
+
if (enabled.deletePath || enabled.movePath) required.add("rm");
|
|
110
|
+
if (enabled.makeDir || enabled.copyPath || enabled.movePath) required.add("mkdir");
|
|
111
|
+
if (enabled.copyPath || enabled.movePath) {
|
|
112
|
+
required.add("writeFile");
|
|
113
|
+
required.add("stat");
|
|
114
|
+
required.add("exists");
|
|
115
|
+
required.add("readFile");
|
|
116
|
+
required.add("list");
|
|
117
|
+
}
|
|
118
|
+
return [...required].every((key) => hasOwnMethod(workspace, key));
|
|
99
119
|
}
|
|
100
120
|
function getWorkspaceSessionStarter(input) {
|
|
101
|
-
return
|
|
121
|
+
return hasOwnMethod(input, "startSession") ? input : void 0;
|
|
122
|
+
}
|
|
123
|
+
function hasOwnMethod(value, key) {
|
|
124
|
+
return Object.hasOwn(value, key) && typeof Reflect.get(value, key) === "function";
|
|
102
125
|
}
|
|
103
126
|
function createWorkspaceSessionShellProvider(starter) {
|
|
104
127
|
return {
|
|
@@ -121,12 +144,16 @@ function createWorkspaceSessionShellProvider(starter) {
|
|
|
121
144
|
}
|
|
122
145
|
},
|
|
123
146
|
async exec(command, execOptions = {}) {
|
|
124
|
-
const session = await starter.startSession({
|
|
147
|
+
const session = await starter.startSession({
|
|
148
|
+
...execOptions.signal ? { abortSignal: execOptions.signal } : {},
|
|
149
|
+
paths: execOptions.workspacePaths
|
|
150
|
+
});
|
|
125
151
|
let observation;
|
|
126
152
|
try {
|
|
127
153
|
const result = await session.exec("sh", ["-lc", command], {
|
|
128
154
|
cwd: execOptions.cwd || workspaceMountPoint,
|
|
129
155
|
env: execOptions.env,
|
|
156
|
+
...execOptions.signal ? { abortSignal: execOptions.signal } : {},
|
|
130
157
|
timeout: execOptions.timeout
|
|
131
158
|
});
|
|
132
159
|
execOptions.onStdout?.(result.stdout);
|
|
@@ -159,14 +186,14 @@ async function resolveExecutionProvider(provider) {
|
|
|
159
186
|
}
|
|
160
187
|
function isUnavailableWorkspaceSession(error) {
|
|
161
188
|
const message = error instanceof Error ? error.message : String(error);
|
|
162
|
-
return message.includes("Workspace exec requires an executable runtime") || message.includes("Workspace exec requires a
|
|
189
|
+
return message.includes("Workspace exec requires an executable runtime") || message.includes("Workspace exec requires a Sandbox session host") || message.includes("Workspace") && message.includes("is not registered");
|
|
163
190
|
}
|
|
164
191
|
function cleanWorkspaceShellPath(path) {
|
|
165
192
|
return normalizeSafeWorkspacePath(path.replace(/^\/workspace(?:\/|$)/, ""), { allowEmpty: true });
|
|
166
193
|
}
|
|
167
194
|
function cleanMutationPath(path) {
|
|
168
195
|
const normalized = cleanWorkspaceShellPath(path);
|
|
169
|
-
if (!normalized) throw
|
|
196
|
+
if (!normalized) throw workspaceErrorDiagnostics.WORKSPACE_R0001({ message: "[vitehub] Workspace root is not a valid mutation target." });
|
|
170
197
|
return normalized;
|
|
171
198
|
}
|
|
172
199
|
function resolveReadOperations(operations) {
|
|
@@ -236,34 +263,41 @@ async function runShellCommand(input, command, options) {
|
|
|
236
263
|
const networkGrants = getWorkspaceSourceRequestExecution(input);
|
|
237
264
|
const { createReadonlyWorkspaceFs, runWorkspaceInspectionCommand } = await loadWorkspaceShellModule();
|
|
238
265
|
const inspectionOptions = {
|
|
266
|
+
budget: options.budget,
|
|
267
|
+
budgetCharged: options.budgetCharged,
|
|
239
268
|
broadSearchPaths: options.broadSearchPaths,
|
|
240
|
-
commands:
|
|
269
|
+
commands: options.commands,
|
|
241
270
|
cwd: options.cwd,
|
|
242
271
|
fs: createReadonlyWorkspaceFs(input),
|
|
243
272
|
maxOutputLength: options.maxOutputLength,
|
|
244
273
|
networkGrants,
|
|
274
|
+
signal: options.budget ? options.signal ? AbortSignal.any([options.signal, options.budget.signal]) : options.budget.signal : options.signal,
|
|
245
275
|
timeout: options.timeout
|
|
246
276
|
};
|
|
247
277
|
const starter = getWorkspaceSessionStarter(input);
|
|
248
278
|
if (starter) try {
|
|
249
|
-
|
|
279
|
+
const result = await runWorkspaceInspectionCommand(input, command, {
|
|
250
280
|
...inspectionOptions,
|
|
251
281
|
provider: createWorkspaceSessionShellProvider(starter)
|
|
252
282
|
});
|
|
283
|
+
if (options.budget?.signal.aborted) throw options.budget.signal.reason;
|
|
284
|
+
return result;
|
|
253
285
|
} catch (error) {
|
|
254
286
|
if (!isUnavailableWorkspaceSession(error)) throw error;
|
|
255
287
|
}
|
|
256
288
|
const provider = await resolveExecutionProvider(options.executionProvider);
|
|
257
|
-
|
|
289
|
+
const result = await runWorkspaceInspectionCommand(input, command, {
|
|
258
290
|
...inspectionOptions,
|
|
259
291
|
...provider ? { provider } : {}
|
|
260
292
|
});
|
|
293
|
+
if (options.budget?.signal.aborted) throw options.budget.signal.reason;
|
|
294
|
+
return result;
|
|
261
295
|
}
|
|
262
296
|
function sizeOf(content) {
|
|
263
297
|
return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
264
298
|
}
|
|
265
299
|
async function materializeWorkspaceSourcesTool(input, options) {
|
|
266
|
-
if ("materializeSources"
|
|
300
|
+
if (hasOwnMethod(input, "materializeSources") && typeof input.materializeSources === "function") return await input.materializeSources(options);
|
|
267
301
|
const started = Date.now();
|
|
268
302
|
const path = cleanWorkspaceShellPath(options.path || "") || "";
|
|
269
303
|
const entries = await input.list(path, { recursive: true });
|
|
@@ -288,7 +322,15 @@ async function materializeWorkspaceSourcesTool(input, options) {
|
|
|
288
322
|
sources: []
|
|
289
323
|
};
|
|
290
324
|
}
|
|
291
|
-
function createWriteTools(workspace, enabled) {
|
|
325
|
+
function createWriteTools(workspace, enabled, budget) {
|
|
326
|
+
const charge = (executionOptions, inputBytes = 0) => {
|
|
327
|
+
if (!Boolean(executionOptions?.[executionBudgetCharged])) try {
|
|
328
|
+
budget?.recordToolCall(inputBytes);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
budget?.cancel(error);
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
292
334
|
const result = {};
|
|
293
335
|
if (enabled.writeFile) result.writeFile = tool({
|
|
294
336
|
description: "Write a text file to the workspace.",
|
|
@@ -302,7 +344,8 @@ function createWriteTools(workspace, enabled) {
|
|
|
302
344
|
required: ["path", "content"],
|
|
303
345
|
type: "object"
|
|
304
346
|
}),
|
|
305
|
-
execute: async ({ content, mediaType, path }) => {
|
|
347
|
+
execute: async ({ content, mediaType, path }, executionOptions) => {
|
|
348
|
+
charge(executionOptions, sizeOf(content));
|
|
306
349
|
const normalized = cleanMutationPath(path);
|
|
307
350
|
await workspace.writeFile(normalized, content, { mediaType });
|
|
308
351
|
return { path: normalized };
|
|
@@ -319,7 +362,8 @@ function createWriteTools(workspace, enabled) {
|
|
|
319
362
|
required: ["path", "content"],
|
|
320
363
|
type: "object"
|
|
321
364
|
}),
|
|
322
|
-
execute: async ({ content, path }) => {
|
|
365
|
+
execute: async ({ content, path }, executionOptions) => {
|
|
366
|
+
charge(executionOptions, sizeOf(content));
|
|
323
367
|
const normalized = cleanMutationPath(path);
|
|
324
368
|
await appendWorkspaceFile(workspace, normalized, content);
|
|
325
369
|
return { path: normalized };
|
|
@@ -337,7 +381,8 @@ function createWriteTools(workspace, enabled) {
|
|
|
337
381
|
required: ["path"],
|
|
338
382
|
type: "object"
|
|
339
383
|
}),
|
|
340
|
-
execute: async ({ force, path, recursive }) => {
|
|
384
|
+
execute: async ({ force, path, recursive }, executionOptions) => {
|
|
385
|
+
charge(executionOptions);
|
|
341
386
|
const normalized = cleanMutationPath(path);
|
|
342
387
|
await workspace.rm(normalized, {
|
|
343
388
|
force,
|
|
@@ -357,7 +402,8 @@ function createWriteTools(workspace, enabled) {
|
|
|
357
402
|
required: ["path"],
|
|
358
403
|
type: "object"
|
|
359
404
|
}),
|
|
360
|
-
execute: async ({ path, recursive }) => {
|
|
405
|
+
execute: async ({ path, recursive }, executionOptions) => {
|
|
406
|
+
charge(executionOptions);
|
|
361
407
|
const normalized = cleanMutationPath(path);
|
|
362
408
|
await workspace.mkdir(normalized, { recursive });
|
|
363
409
|
return { path: normalized };
|
|
@@ -375,7 +421,8 @@ function createWriteTools(workspace, enabled) {
|
|
|
375
421
|
required: ["from", "to"],
|
|
376
422
|
type: "object"
|
|
377
423
|
}),
|
|
378
|
-
execute: async ({ from, overwrite = false, to }) => {
|
|
424
|
+
execute: async ({ from, overwrite = false, to }, executionOptions) => {
|
|
425
|
+
charge(executionOptions);
|
|
379
426
|
const source = cleanMutationPath(from);
|
|
380
427
|
const target = cleanMutationPath(to);
|
|
381
428
|
await copyWorkspacePath(workspace, source, target, overwrite);
|
|
@@ -397,7 +444,8 @@ function createWriteTools(workspace, enabled) {
|
|
|
397
444
|
required: ["from", "to"],
|
|
398
445
|
type: "object"
|
|
399
446
|
}),
|
|
400
|
-
execute: async ({ from, overwrite = false, to }) => {
|
|
447
|
+
execute: async ({ from, overwrite = false, to }, executionOptions) => {
|
|
448
|
+
charge(executionOptions);
|
|
401
449
|
const source = cleanMutationPath(from);
|
|
402
450
|
const target = cleanMutationPath(to);
|
|
403
451
|
await copyWorkspacePath(workspace, source, target, overwrite);
|
|
@@ -419,64 +467,97 @@ function createWorkspaceTools(input, options = {}) {
|
|
|
419
467
|
commands: shellCommandsFor(resolveReadOperations(options.operations)),
|
|
420
468
|
cwd: options.cwd || workspaceMountPoint,
|
|
421
469
|
executionProvider: options.executionProvider,
|
|
470
|
+
budget: options.executionBudget,
|
|
422
471
|
materialize: resolveReadOperations(options.operations).materialize,
|
|
423
472
|
maxShellCalls: options.maxShellCalls,
|
|
424
|
-
maxOutputLength: options.maxOutputLength
|
|
473
|
+
maxOutputLength: options.maxOutputLength ?? defaultMaxOutputLength,
|
|
425
474
|
timeout: options.timeout,
|
|
426
475
|
write: resolveWriteOperations(options.operations?.write)
|
|
427
476
|
};
|
|
477
|
+
if (options.sourceRequests && getWorkspaceSourceRequestExecution(input)) resolved.commands.push("curl");
|
|
428
478
|
let shellCalls = 0;
|
|
429
479
|
const writeEnabled = Object.values(resolved.write).some(Boolean);
|
|
430
|
-
if (!resolved.commands.length && !resolved.materialize && !writeEnabled) throw
|
|
431
|
-
if (writeEnabled && !isWorkspace(input)) throw
|
|
480
|
+
if (!resolved.commands.length && !resolved.materialize && !writeEnabled) throw workspaceErrorDiagnostics.WORKSPACE_R0002({ message: "[vitehub] createWorkspaceTools requires at least one enabled workspace operation." });
|
|
481
|
+
if (writeEnabled && (!isWorkspace(input) || !hasWriteCapabilities(input, resolved.write))) throw workspaceErrorDiagnostics.WORKSPACE_R0003({ message: "[vitehub] Write operations require a mutable Workspace. A useWorkspace(name, { mode: \"write\" }).tools.write() call provides one." });
|
|
432
482
|
const result = {};
|
|
433
|
-
if (resolved.commands.length)
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
} },
|
|
441
|
-
required: ["command"],
|
|
442
|
-
type: "object"
|
|
443
|
-
}),
|
|
444
|
-
execute: async ({ command }) => {
|
|
445
|
-
if (typeof resolved.maxShellCalls === "number" && shellCalls >= resolved.maxShellCalls) return {
|
|
446
|
-
command,
|
|
447
|
-
cwd: resolved.cwd,
|
|
448
|
-
event: "policy_denied",
|
|
449
|
-
exitCode: 126,
|
|
450
|
-
stderr: `[vitehub] Workspace shell command budget exhausted after ${resolved.maxShellCalls} calls. The Workspace Tools shell call budget is exhausted for this run.\n`,
|
|
451
|
-
stdout: ""
|
|
452
|
-
};
|
|
453
|
-
shellCalls += 1;
|
|
454
|
-
return await runShellCommand(input, command, resolved);
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
if (resolved.materialize) result.materialize_sources = tool({
|
|
458
|
-
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(" "),
|
|
459
|
-
inputSchema: jsonSchema({
|
|
460
|
-
additionalProperties: false,
|
|
461
|
-
properties: {
|
|
462
|
-
path: {
|
|
463
|
-
description: "Workspace path prefix to materialize. Defaults to the workspace root.",
|
|
483
|
+
if (resolved.commands.length) {
|
|
484
|
+
result.shell = Object.assign(tool({
|
|
485
|
+
description: describeShellCommands(resolved.commands, { sourceRequests: resolved.commands.includes("curl") }),
|
|
486
|
+
inputSchema: jsonSchema({
|
|
487
|
+
additionalProperties: false,
|
|
488
|
+
properties: { command: {
|
|
489
|
+
description: "A Bash-compatible workspace shell command. Use pipes, redirects, chaining, and quoted patterns as needed.",
|
|
464
490
|
type: "string"
|
|
465
|
-
},
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
491
|
+
} },
|
|
492
|
+
required: ["command"],
|
|
493
|
+
type: "object"
|
|
494
|
+
}),
|
|
495
|
+
execute: async ({ command }, executionOptions) => {
|
|
496
|
+
const abortSignal = executionOptions?.abortSignal;
|
|
497
|
+
const executionBudget = executionOptions?.[executionBudgetOverride] ?? resolved.budget;
|
|
498
|
+
if (typeof resolved.maxShellCalls === "number" && shellCalls >= resolved.maxShellCalls) return {
|
|
499
|
+
command,
|
|
500
|
+
cwd: resolved.cwd,
|
|
501
|
+
event: "policy_denied",
|
|
502
|
+
exitCode: 126,
|
|
503
|
+
stderr: `[vitehub] Workspace shell command budget exhausted after ${resolved.maxShellCalls} calls. The Workspace Tools shell call budget is exhausted for this run.\n`,
|
|
504
|
+
stdout: ""
|
|
505
|
+
};
|
|
506
|
+
shellCalls += 1;
|
|
507
|
+
if (!Boolean(executionOptions?.[executionBudgetCharged])) try {
|
|
508
|
+
executionBudget?.recordToolCall();
|
|
509
|
+
} catch (error) {
|
|
510
|
+
executionBudget?.cancel(error);
|
|
511
|
+
throw error;
|
|
470
512
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
513
|
+
return await runShellCommand(input, command, {
|
|
514
|
+
...resolved,
|
|
515
|
+
budget: executionBudget,
|
|
516
|
+
budgetCharged: Boolean(executionBudget),
|
|
517
|
+
signal: abortSignal
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}));
|
|
521
|
+
if (resolved.budget) markExecutionBudgetHandled(result.shell, resolved.budget);
|
|
522
|
+
}
|
|
523
|
+
if (resolved.materialize) {
|
|
524
|
+
result.materialize_sources = Object.assign(tool({
|
|
525
|
+
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(" "),
|
|
526
|
+
inputSchema: jsonSchema({
|
|
527
|
+
additionalProperties: false,
|
|
528
|
+
properties: {
|
|
529
|
+
path: {
|
|
530
|
+
description: "Workspace path prefix to materialize. Defaults to the workspace root.",
|
|
531
|
+
type: "string"
|
|
532
|
+
},
|
|
533
|
+
sources: {
|
|
534
|
+
description: "Optional source names to materialize.",
|
|
535
|
+
items: { type: "string" },
|
|
536
|
+
type: "array"
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
type: "object"
|
|
540
|
+
}),
|
|
541
|
+
execute: async ({ path, sources }, executionOptions) => {
|
|
542
|
+
if (!executionOptions?.[executionBudgetCharged]) resolved.budget?.recordToolCall();
|
|
543
|
+
return await materializeWorkspaceSourcesTool(input, {
|
|
544
|
+
path,
|
|
545
|
+
sources
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}), {
|
|
549
|
+
icon: "i-lucide-folder-sync",
|
|
550
|
+
title: "Materialized Workspace sources"
|
|
551
|
+
});
|
|
552
|
+
if (resolved.budget) markExecutionBudgetHandled(result.materialize_sources, resolved.budget);
|
|
553
|
+
}
|
|
554
|
+
if (writeEnabled) {
|
|
555
|
+
const writeTools = createWriteTools(input, resolved.write, resolved.budget);
|
|
556
|
+
Object.assign(result, writeTools);
|
|
557
|
+
if (resolved.budget) {
|
|
558
|
+
for (const writeTool of Object.values(writeTools)) if (writeTool) markExecutionBudgetHandled(writeTool, resolved.budget);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
480
561
|
return result;
|
|
481
562
|
}
|
|
482
563
|
//#endregion
|
package/dist/ai.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
1
|
+
import { mt as WorkspaceMaterializeSourcesResult } from "./types-DeK9GIxy.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-BW2ZhizI.js";
|
|
3
3
|
export { EnabledReadCapability, ShellEnabled, type WorkspaceMaterializeSourcesResult, WorkspaceMoveResult, WorkspacePathResult, WorkspaceReadOperations, WorkspaceShellResult, WorkspaceToolOperations, WorkspaceToolOptions, WorkspaceTools, WorkspaceWriteOperations, WorkspaceWriteToolMap, createWorkspaceTools };
|
package/dist/ai.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createWorkspaceTools } from "./ai-
|
|
1
|
+
import { t as createWorkspaceTools } from "./ai-BZyLwULx.js";
|
|
2
2
|
export { createWorkspaceTools };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as workspaceNotFoundError } from "./path-DrSIenjj.js";
|
|
2
2
|
import runtimeAssetsRegistry from "#vitehub-workspace-assets-registry";
|
|
3
3
|
//#region src/asset-registry.ts
|
|
4
4
|
const workspaceAssetsRegistryKey = Symbol.for("vitehub.workspace.assetsRegistry");
|
|
@@ -11,7 +11,8 @@ function setWorkspaceAssetsRegistry(registry) {
|
|
|
11
11
|
workspaceAssetsRegistryGlobal()[workspaceAssetsRegistryKey] = registry;
|
|
12
12
|
}
|
|
13
13
|
function useWorkspaceAssets(name) {
|
|
14
|
-
const
|
|
14
|
+
const registry = workspaceAssetsRegistryGlobal()[workspaceAssetsRegistryKey];
|
|
15
|
+
const assets = registry && Object.hasOwn(registry, name) ? registry[name] : void 0;
|
|
15
16
|
if (!assets) throw workspaceNotFoundError(name);
|
|
16
17
|
return assets;
|
|
17
18
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region ../forge/dist/association-Cm0dUTDU-CDDhJnIh.js
|
|
2
|
+
const AUTHOR_ASSOCIATIONS = {
|
|
3
|
+
OWNER: "owner",
|
|
4
|
+
MEMBER: "member",
|
|
5
|
+
COLLABORATOR: "collaborator",
|
|
6
|
+
CONTRIBUTOR: "contributor",
|
|
7
|
+
FIRST_TIME_CONTRIBUTOR: "first_time_contributor",
|
|
8
|
+
FIRST_TIMER: "first_timer",
|
|
9
|
+
MANNEQUIN: "none",
|
|
10
|
+
NONE: "none"
|
|
11
|
+
};
|
|
12
|
+
function toAuthorAssociation(raw) {
|
|
13
|
+
return raw ? {
|
|
14
|
+
authorAssociation: AUTHOR_ASSOCIATIONS[raw] ?? "unknown",
|
|
15
|
+
authorAssociationRaw: raw
|
|
16
|
+
} : {};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { toAuthorAssociation as t };
|