@mastra/e2b 0.11.0-alpha.2 → 0.11.0-alpha.4
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 +70 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -4
- package/dist/index.js.map +1 -1
- package/dist/utils/repo-template.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1553,6 +1553,31 @@ var E2BSandbox = class E2BSandbox extends MastraSandbox {
|
|
|
1553
1553
|
}
|
|
1554
1554
|
};
|
|
1555
1555
|
//#endregion
|
|
1556
|
+
//#region ../../packages/_internals/workspace/dist/index.js
|
|
1557
|
+
/**
|
|
1558
|
+
* Setup completion marker shared by repo templates and their consumers.
|
|
1559
|
+
*
|
|
1560
|
+
* A repo template writes this file beside the checkout as its last build
|
|
1561
|
+
* step, so it exists only in images where every setup command succeeded. Its
|
|
1562
|
+
* content is a digest of the setup commands the image ran, letting a sandbox
|
|
1563
|
+
* booted from the image tell whether the setup it is about to run already
|
|
1564
|
+
* happened. Relative to the template's build cwd, which is also the runtime
|
|
1565
|
+
* working directory the repo was cloned into.
|
|
1566
|
+
*/
|
|
1567
|
+
const SETUP_MARKER_PATH = ".mastra-sandbox/setup";
|
|
1568
|
+
/** Blank entries never become build steps, so they never count toward the digest either. */
|
|
1569
|
+
function normalizeSetupCommands$1(setupCommand) {
|
|
1570
|
+
return (setupCommand === void 0 ? [] : Array.isArray(setupCommand) ? setupCommand : [setupCommand]).filter((command) => command.trim() !== "");
|
|
1571
|
+
}
|
|
1572
|
+
/** The marker content for a setup command list: `sha256:<hex>` over the commands joined by newlines. */
|
|
1573
|
+
function setupMarkerContent(setupCommand) {
|
|
1574
|
+
return `sha256:${createHash("sha256").update(normalizeSetupCommands$1(setupCommand).join("\n")).digest("hex")}`;
|
|
1575
|
+
}
|
|
1576
|
+
/** Shell step that writes the marker relative to the cwd. `content` is a digest, so it is shell-safe. */
|
|
1577
|
+
function setupMarkerCommand(content) {
|
|
1578
|
+
return `mkdir -p "$(dirname "${SETUP_MARKER_PATH}")" && printf '%s' '${content}' > "${SETUP_MARKER_PATH}"`;
|
|
1579
|
+
}
|
|
1580
|
+
//#endregion
|
|
1556
1581
|
//#region src/utils/repo-template.ts
|
|
1557
1582
|
/**
|
|
1558
1583
|
* Sha-tagged repo templates.
|
|
@@ -1772,7 +1797,9 @@ function buildRepoTemplateSpec(identity, token) {
|
|
|
1772
1797
|
}
|
|
1773
1798
|
template = template.runCmd(`git ${auth}clone ${cloneUrl} "${repoDir}"`);
|
|
1774
1799
|
if (sha) template = template.runCmd(`git -C "${repoDir}" ${auth}fetch origin ${sha}`).runCmd(`git -C "${repoDir}" checkout ${sha}`);
|
|
1775
|
-
|
|
1800
|
+
const setupCommands = normalizeSetupCommands(setupCommand);
|
|
1801
|
+
for (const command of setupCommands) template = template.runCmd(`cd "${repoDir}" && ${command}`);
|
|
1802
|
+
template = template.runCmd(setupMarkerCommand(setupMarkerContent(setupCommands)));
|
|
1776
1803
|
return {
|
|
1777
1804
|
ref: repoTemplateRef(identity),
|
|
1778
1805
|
template,
|
|
@@ -1785,13 +1812,52 @@ function buildRepoTemplateSpec(identity, token) {
|
|
|
1785
1812
|
};
|
|
1786
1813
|
}
|
|
1787
1814
|
/**
|
|
1788
|
-
*
|
|
1789
|
-
*
|
|
1790
|
-
*
|
|
1815
|
+
* `owner/repo` for a github.com clone URL, else undefined. Only the public
|
|
1816
|
+
* host is API-resolvable: GitHub Enterprise and other forges keep the git
|
|
1817
|
+
* path.
|
|
1818
|
+
*/
|
|
1819
|
+
function parseGithubRepo(cloneUrl) {
|
|
1820
|
+
let url;
|
|
1821
|
+
try {
|
|
1822
|
+
url = new URL(cloneUrl);
|
|
1823
|
+
} catch {
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
if (url.hostname.toLowerCase() !== "github.com") return void 0;
|
|
1827
|
+
const [owner, repo, ...rest] = url.pathname.split("/").filter(Boolean);
|
|
1828
|
+
if (!owner || !repo || rest.length > 0) return void 0;
|
|
1829
|
+
return {
|
|
1830
|
+
owner,
|
|
1831
|
+
repo: repo.replace(/\.git$/i, "")
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Resolve the repository's current default-branch head without cloning.
|
|
1836
|
+
* github.com repositories go through the REST API so resolution works
|
|
1837
|
+
* wherever the host runs, including images without a git binary; other
|
|
1838
|
+
* hosts use `git ls-remote <url> HEAD`, authenticated via an in-process
|
|
1839
|
+
* `http.extraheader` when a token is provided. Returns undefined when the
|
|
1791
1840
|
* head cannot be resolved (inaccessible repo, offline, no git binary);
|
|
1792
1841
|
* callers degrade to the untagged template ref.
|
|
1793
1842
|
*/
|
|
1794
1843
|
async function resolveDefaultBranchHead(cloneUrl, token) {
|
|
1844
|
+
const github = parseGithubRepo(cloneUrl);
|
|
1845
|
+
if (github) try {
|
|
1846
|
+
const response = await fetch(`https://api.github.com/repos/${github.owner}/${github.repo}/commits/HEAD`, {
|
|
1847
|
+
headers: {
|
|
1848
|
+
Accept: "application/vnd.github.sha",
|
|
1849
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
1850
|
+
"User-Agent": "mastra-e2b",
|
|
1851
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
1852
|
+
},
|
|
1853
|
+
signal: AbortSignal.timeout(1e4)
|
|
1854
|
+
});
|
|
1855
|
+
if (!response.ok) return void 0;
|
|
1856
|
+
const sha = (await response.text()).trim();
|
|
1857
|
+
return SHA_PATTERN.test(sha) ? sha : void 0;
|
|
1858
|
+
} catch {
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1795
1861
|
try {
|
|
1796
1862
|
const authArgs = token ? ["-c", `http.extraheader=AUTHORIZATION: basic ${Buffer.from(`x-access-token:${token}`).toString("base64")}`] : [];
|
|
1797
1863
|
const { stdout } = await execFileAsync("git", [
|