@mastra/platform-workspace 1.13.0 → 1.13.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.
- package/dist/_types/{@internal_workspace@0.0.21 → @internal_workspace@0.0.22}/dist/commands-api-process-manager.d.ts +11 -1
- package/dist/e2b-exec.d.ts +1 -1
- package/dist/index.cjs +40 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -6
- package/dist/index.js.map +1 -1
- package/dist/sandbox-filesystem.d.ts +2 -2
- package/dist/sandbox.d.ts +13 -1
- package/dist/sandbox.d.ts.map +1 -1
- package/package.json +5 -5
- /package/dist/_types/{@internal_workspace@0.0.21 → @internal_workspace@0.0.22}/dist/file-commands.d.ts +0 -0
- /package/dist/_types/{@internal_workspace@0.0.21 → @internal_workspace@0.0.22}/dist/files-api-filesystem.d.ts +0 -0
- /package/dist/_types/{@internal_workspace@0.0.21 → @internal_workspace@0.0.22}/dist/index.d.ts +0 -0
- /package/dist/_types/{@internal_workspace@0.0.21 → @internal_workspace@0.0.22}/dist/repo-clone.d.ts +0 -0
- /package/dist/_types/{@internal_workspace@0.0.21 → @internal_workspace@0.0.22}/dist/setup-marker.d.ts +0 -0
- /package/dist/_types/{@internal_workspace@0.0.21 → @internal_workspace@0.0.22}/package.json +0 -0
package/dist/index.js
CHANGED
|
@@ -1149,7 +1149,8 @@ var CommandsApiProcessHandle = class extends ProcessHandle {
|
|
|
1149
1149
|
await (await commands.run(killDescendants(this.inner.pid), {
|
|
1150
1150
|
background: true,
|
|
1151
1151
|
stdin: false,
|
|
1152
|
-
timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS
|
|
1152
|
+
timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS,
|
|
1153
|
+
...this.manager.defaultUser !== void 0 && { user: this.manager.defaultUser }
|
|
1153
1154
|
})).wait();
|
|
1154
1155
|
} catch {}
|
|
1155
1156
|
return commands.kill(this.inner.pid);
|
|
@@ -1170,9 +1171,12 @@ var CommandsApiProcessHandle = class extends ProcessHandle {
|
|
|
1170
1171
|
*/
|
|
1171
1172
|
var CommandsApiProcessManager = class extends SandboxProcessManager {
|
|
1172
1173
|
defaultTimeout;
|
|
1173
|
-
|
|
1174
|
+
/** Read by {@link CommandsApiProcessHandle.kill}, which must run as the same user. */
|
|
1175
|
+
defaultUser;
|
|
1176
|
+
constructor({ defaultTimeout, user, ...options } = {}) {
|
|
1174
1177
|
super(options);
|
|
1175
1178
|
this.defaultTimeout = defaultTimeout;
|
|
1179
|
+
this.defaultUser = user;
|
|
1176
1180
|
}
|
|
1177
1181
|
/** Wrap a started or attached command. Providers override this to supply their own handle. */
|
|
1178
1182
|
createHandle(inner, stdinMode, options) {
|
|
@@ -1192,6 +1196,7 @@ var CommandsApiProcessManager = class extends SandboxProcessManager {
|
|
|
1192
1196
|
cwd: options.cwd ?? this.defaultCwd(),
|
|
1193
1197
|
envs,
|
|
1194
1198
|
timeoutMs: options.timeout ?? this.defaultTimeout,
|
|
1199
|
+
...this.defaultUser !== void 0 && { user: this.defaultUser },
|
|
1195
1200
|
onStdout: output.onStdout,
|
|
1196
1201
|
onStderr: output.onStderr
|
|
1197
1202
|
});
|
|
@@ -1781,6 +1786,29 @@ function shellQuote(arg) {
|
|
|
1781
1786
|
if (/^[a-zA-Z0-9._\-/=:@]+$/.test(arg)) return arg;
|
|
1782
1787
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
1783
1788
|
}
|
|
1789
|
+
/**
|
|
1790
|
+
* `command` run from `cwd` by a leading shell `cd`, with the transports left to
|
|
1791
|
+
* start in the working directory. The exec transports report a `cwd` that
|
|
1792
|
+
* doesn't exist as a broken connection (retried, then "transport failed"), so
|
|
1793
|
+
* changing directory in the shell turns it into an ordinary failed command.
|
|
1794
|
+
*
|
|
1795
|
+
* A relative `cwd` resolves under `workingDirectory`. An absolute one outside it
|
|
1796
|
+
* that doesn't exist falls back to the same path under `workingDirectory`: the
|
|
1797
|
+
* workspace file tools read absolute paths that way (`/repo` is
|
|
1798
|
+
* `<workingDirectory>/repo`), so agents pass command `cwd`s the same way.
|
|
1799
|
+
*/
|
|
1800
|
+
function commandInCwd(command, cwd, workingDirectory) {
|
|
1801
|
+
if (!cwd) return command;
|
|
1802
|
+
const normalize = (dir) => posix.normalize(dir).replace(/(.)\/$/, "$1");
|
|
1803
|
+
const base = workingDirectory ? normalize(workingDirectory) : void 0;
|
|
1804
|
+
const target = normalize(base && !cwd.startsWith("/") ? posix.join(base, cwd) : cwd);
|
|
1805
|
+
if (target === base) return command;
|
|
1806
|
+
const candidates = [target];
|
|
1807
|
+
if (base && cwd.startsWith("/") && !target.startsWith(`${base}/`)) candidates.push(posix.join(base, target));
|
|
1808
|
+
const branches = candidates.map((dir, i) => `${i === 0 ? "if" : "elif"} [ -d ${shellQuote(dir)} ]; then cd -- ${shellQuote(dir)} || exit 1`);
|
|
1809
|
+
const notFound = shellQuote(`Working directory not found: ${target}${candidates.length > 1 ? ` (also tried ${candidates[1]})` : ""}`);
|
|
1810
|
+
return `${branches.join("; ")}; else echo ${notFound} >&2; exit 1; fi\n${command}`;
|
|
1811
|
+
}
|
|
1784
1812
|
var PlatformProcessHandle = class extends ProcessHandle {
|
|
1785
1813
|
pid;
|
|
1786
1814
|
resultPromise;
|
|
@@ -1842,6 +1870,10 @@ const withCommands = Symbol("withCommands");
|
|
|
1842
1870
|
* process runs, `kill` stops it, and `list` reports what is running in the VM.
|
|
1843
1871
|
*/
|
|
1844
1872
|
var PlatformCommandsProcessManager = class extends CommandsApiProcessManager {
|
|
1873
|
+
async spawn(command, options = {}) {
|
|
1874
|
+
const { cwd, ...rest } = options;
|
|
1875
|
+
return super.spawn(commandInCwd(command, cwd, this.sandbox.workingDirectory), rest);
|
|
1876
|
+
}
|
|
1845
1877
|
runCommands(operation, fn) {
|
|
1846
1878
|
return this.sandbox[withCommands](operation, fn);
|
|
1847
1879
|
}
|
|
@@ -2601,17 +2633,19 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
2601
2633
|
const fullCommand = buildCommand(command, args);
|
|
2602
2634
|
const effectiveTimeout = options?.timeout ?? this._timeout;
|
|
2603
2635
|
const sandboxEnv = this.getEnv();
|
|
2636
|
+
const { cwd, ...restOptions } = options ?? {};
|
|
2637
|
+
const execCommand = commandInCwd(fullCommand, cwd, this.workingDirectory);
|
|
2604
2638
|
const execCallOptions = Object.keys(sandboxEnv).length > 0 ? {
|
|
2605
|
-
...
|
|
2639
|
+
...restOptions,
|
|
2606
2640
|
env: {
|
|
2607
2641
|
...sandboxEnv,
|
|
2608
2642
|
...options?.env
|
|
2609
2643
|
}
|
|
2610
|
-
} :
|
|
2644
|
+
} : restOptions;
|
|
2611
2645
|
await this._awaitTransportReady();
|
|
2612
2646
|
const instanceUrl = once ? void 0 : this._addressRegistry?.get(this._sandboxId);
|
|
2613
2647
|
if (instanceUrl) {
|
|
2614
|
-
const privateNet = await this._tryExecViaPrivateNetwork(instanceUrl,
|
|
2648
|
+
const privateNet = await this._tryExecViaPrivateNetwork(instanceUrl, execCommand, effectiveTimeout, execCallOptions);
|
|
2615
2649
|
if (privateNet) {
|
|
2616
2650
|
const privateExit = privateNet.exitCode ?? 124;
|
|
2617
2651
|
return {
|
|
@@ -2625,7 +2659,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
2625
2659
|
};
|
|
2626
2660
|
}
|
|
2627
2661
|
}
|
|
2628
|
-
const result = await this._runDirectExec(
|
|
2662
|
+
const result = await this._runDirectExec(execCommand, effectiveTimeout, execCallOptions, once ? 1 : 2);
|
|
2629
2663
|
const exitCode = result.exitCode ?? 124;
|
|
2630
2664
|
return {
|
|
2631
2665
|
success: exitCode === 0,
|