@mastra/e2b 0.11.0-alpha.0 → 0.11.0-alpha.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.
- package/dist/index.cjs +33 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -14
- package/dist/index.js.map +1 -1
- package/dist/utils/repo-template.d.ts +12 -5
- package/dist/utils/repo-template.d.ts.map +1 -1
- package/package.json +5 -6
- package/CHANGELOG.md +0 -1047
package/dist/index.cjs
CHANGED
|
@@ -551,7 +551,7 @@ var E2BProcessManager = class extends _mastra_core_workspace.SandboxProcessManag
|
|
|
551
551
|
handle = new E2BProcessHandle(await e2b.commands.run(command, {
|
|
552
552
|
background: true,
|
|
553
553
|
stdin: true,
|
|
554
|
-
cwd: options.cwd,
|
|
554
|
+
cwd: options.cwd ?? this.sandbox.workingDirectory,
|
|
555
555
|
envs,
|
|
556
556
|
timeoutMs: options.timeout,
|
|
557
557
|
onStdout: (data) => handle.emitStdout(data),
|
|
@@ -1563,7 +1563,7 @@ var E2BSandbox = class E2BSandbox extends _mastra_core_workspace.MastraSandbox {
|
|
|
1563
1563
|
* need `git fetch` + checkout of their actual ref plus setup drift, instead
|
|
1564
1564
|
* of a cold clone + full install.
|
|
1565
1565
|
*
|
|
1566
|
-
* There is exactly ONE template per (repo, setup command,
|
|
1566
|
+
* There is exactly ONE template per (repo, setup command, repoDir): the
|
|
1567
1567
|
* template name is a deterministic `mastra-repo-<hash>` over those inputs,
|
|
1568
1568
|
* and the commit sha rides as a docker-style TAG on that name
|
|
1569
1569
|
* (`mastra-repo-<hash>:sha-<sha>`). A moved default branch produces a new
|
|
@@ -1643,7 +1643,8 @@ function repoTemplateName(identity) {
|
|
|
1643
1643
|
identity.setupCommand ?? null,
|
|
1644
1644
|
identity.buildEnv ? Object.entries(identity.buildEnv).sort(([a], [b]) => a.localeCompare(b)) : null,
|
|
1645
1645
|
identity.cpuCount ?? 2,
|
|
1646
|
-
identity.memoryMB ?? 1024
|
|
1646
|
+
identity.memoryMB ?? 1024,
|
|
1647
|
+
...identity.workingDirectory !== void 0 ? [identity.workingDirectory] : []
|
|
1647
1648
|
];
|
|
1648
1649
|
const hash = (0, crypto.createHash)("sha256").update(JSON.stringify(config)).digest("hex").slice(0, 8);
|
|
1649
1650
|
const { owner, repo } = parseCloneUrl(cloneUrl);
|
|
@@ -1699,10 +1700,11 @@ async function resolveSpecAtHead(options) {
|
|
|
1699
1700
|
spec: buildRepoTemplateSpec({
|
|
1700
1701
|
cloneUrl,
|
|
1701
1702
|
...sha ? { sha } : {},
|
|
1702
|
-
...options.setupCommand ? { setupCommand: options.setupCommand } : {},
|
|
1703
|
+
...normalizeSetupCommands(options.setupCommand).length > 0 ? { setupCommand: options.setupCommand } : {},
|
|
1703
1704
|
...buildEnv ? { buildEnv } : {},
|
|
1704
1705
|
...options.cpuCount !== void 0 ? { cpuCount: options.cpuCount } : {},
|
|
1705
|
-
...options.memoryMB !== void 0 ? { memoryMB: options.memoryMB } : {}
|
|
1706
|
+
...options.memoryMB !== void 0 ? { memoryMB: options.memoryMB } : {},
|
|
1707
|
+
...options.workingDirectory !== void 0 ? { workingDirectory: trimTrailingSlashes(assertWorkingDirectory(options.workingDirectory)) } : {}
|
|
1706
1708
|
}, token),
|
|
1707
1709
|
...sha ? { sha } : {}
|
|
1708
1710
|
};
|
|
@@ -1740,7 +1742,7 @@ async function refreshRepoTemplate(options, connection) {
|
|
|
1740
1742
|
}
|
|
1741
1743
|
/**
|
|
1742
1744
|
* The clone URL is the only untrusted input that reaches a build command,
|
|
1743
|
-
* so it is checked before it can be interpolated into one. The
|
|
1745
|
+
* so it is checked before it can be interpolated into one. The repoDir is
|
|
1744
1746
|
* derived from it rather than supplied, so it needs no separate guard.
|
|
1745
1747
|
*/
|
|
1746
1748
|
function assertCloneUrl(cloneUrl) {
|
|
@@ -1757,18 +1759,21 @@ function gitAuthFlag() {
|
|
|
1757
1759
|
return `-c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$${BUILD_TOKEN_ENV}" | base64 -w0)"`;
|
|
1758
1760
|
}
|
|
1759
1761
|
function buildRepoTemplateSpec(identity, token) {
|
|
1760
|
-
const { sha, setupCommand, buildEnv } = identity;
|
|
1762
|
+
const { sha, setupCommand, buildEnv, workingDirectory } = identity;
|
|
1761
1763
|
const cloneUrl = normalizeCloneUrl(identity.cloneUrl);
|
|
1762
|
-
const
|
|
1764
|
+
const repoDir = repoDirName(cloneUrl);
|
|
1763
1765
|
const auth = token ? `${gitAuthFlag()} ` : "";
|
|
1764
|
-
const steps = [`git ${auth}clone ${cloneUrl} "${workdir}"`];
|
|
1765
|
-
if (sha) steps.push(`git -C "${workdir}" ${auth}fetch origin ${sha}`, `git -C "${workdir}" checkout ${sha}`);
|
|
1766
|
-
if (setupCommand) steps.push(`cd "${workdir}" && ${setupCommand}`);
|
|
1767
1766
|
let template = createDefaultMountableTemplate().template;
|
|
1768
1767
|
const env = { ...buildEnv };
|
|
1769
1768
|
if (token) env[BUILD_TOKEN_ENV] = token;
|
|
1770
1769
|
if (Object.keys(env).length > 0) template = template.setEnvs(env);
|
|
1771
|
-
|
|
1770
|
+
if (workingDirectory) {
|
|
1771
|
+
const dir = trimTrailingSlashes(workingDirectory);
|
|
1772
|
+
template = template.runCmd(`mkdir -p "${dir}"`).setWorkdir(dir);
|
|
1773
|
+
}
|
|
1774
|
+
template = template.runCmd(`git ${auth}clone ${cloneUrl} "${repoDir}"`);
|
|
1775
|
+
if (sha) template = template.runCmd(`git -C "${repoDir}" ${auth}fetch origin ${sha}`).runCmd(`git -C "${repoDir}" checkout ${sha}`);
|
|
1776
|
+
for (const command of normalizeSetupCommands(setupCommand)) template = template.runCmd(`cd "${repoDir}" && ${command}`);
|
|
1772
1777
|
return {
|
|
1773
1778
|
ref: repoTemplateRef(identity),
|
|
1774
1779
|
template,
|
|
@@ -1835,9 +1840,23 @@ function parseCloneUrl(cloneUrl) {
|
|
|
1835
1840
|
repo
|
|
1836
1841
|
};
|
|
1837
1842
|
}
|
|
1838
|
-
|
|
1843
|
+
/** Normalize setup commands and drop blank entries that would produce invalid shell steps. */
|
|
1844
|
+
function normalizeSetupCommands(setupCommand) {
|
|
1845
|
+
return (setupCommand === void 0 ? [] : Array.isArray(setupCommand) ? setupCommand : [setupCommand]).filter((command) => command.trim() !== "");
|
|
1846
|
+
}
|
|
1847
|
+
function repoDirName(cloneUrl) {
|
|
1839
1848
|
const { repo } = parseCloneUrl(cloneUrl);
|
|
1840
|
-
return
|
|
1849
|
+
return repo.replace(/[^\w.-]/g, "-").replace(/^\.+/, "") || "repo";
|
|
1850
|
+
}
|
|
1851
|
+
function trimTrailingSlashes(path) {
|
|
1852
|
+
let end = path.length;
|
|
1853
|
+
while (end > 1 && path[end - 1] === "/") end--;
|
|
1854
|
+
return path.slice(0, end);
|
|
1855
|
+
}
|
|
1856
|
+
/** Validate a literal absolute path before embedding it in shell build steps. */
|
|
1857
|
+
function assertWorkingDirectory(dir) {
|
|
1858
|
+
if (!(/^\/[A-Za-z0-9._/-]*$/.test(dir) && !dir.split("/").includes(".."))) throw new Error(`Repo template workingDirectory must be an absolute path of plain path characters (got ${JSON.stringify(dir)}); ~ and $HOME are not expanded.`);
|
|
1859
|
+
return dir;
|
|
1841
1860
|
}
|
|
1842
1861
|
//#endregion
|
|
1843
1862
|
//#region src/provider.ts
|