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