@papercraneai/sandbox-agent 0.1.17-beta.0 → 0.1.17-beta.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.js +18 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -544,7 +544,20 @@ app.post("/cli/refresh", async (_req, res) => {
|
|
|
544
544
|
if (!gitRoot)
|
|
545
545
|
return;
|
|
546
546
|
const { workspaceRefresh } = await import("@papercraneai/cli/lib/workspace-ops.js");
|
|
547
|
-
|
|
547
|
+
const result = await workspaceRefresh(gitRoot);
|
|
548
|
+
// If we start seeing publishes that change npm deps frequently, enable this
|
|
549
|
+
// block so refresh re-installs node_modules and bounces the dev-server PM2
|
|
550
|
+
// process (sandbox-agent stays up). Today most refreshes are dashboard source
|
|
551
|
+
// only, so paying the install + restart cost (and brief 502s on any open
|
|
552
|
+
// preview URL) on every push isn't worth it.
|
|
553
|
+
//
|
|
554
|
+
// const packageJsonChanged = result.filesChanged?.some((f: string) => f === "package.json" || f === "package-lock.json")
|
|
555
|
+
// if (packageJsonChanged) {
|
|
556
|
+
// await runNpmInstall(gitRoot)
|
|
557
|
+
// execSync("pm2 restart dev-server")
|
|
558
|
+
// }
|
|
559
|
+
// await ensureAppScaffold(gitRoot)
|
|
560
|
+
res.json(result);
|
|
548
561
|
});
|
|
549
562
|
app.post("/cli/publish", async (req, res) => {
|
|
550
563
|
const gitRoot = await resolveGitRoot(res);
|
|
@@ -1501,14 +1514,14 @@ async function registerWithPapercrane(overrides) {
|
|
|
1501
1514
|
console.log(`Registering with Papercrane server at ${papercraneUrl}...`);
|
|
1502
1515
|
try {
|
|
1503
1516
|
const agentEndpoint = overrides?.agentEndpoint ?? `http://${cliArgs.hostMode === "lan" ? getLocalNetworkIP() : "localhost"}:${cliArgs.agentPort}`;
|
|
1504
|
-
const
|
|
1517
|
+
const devServerUrl = overrides?.devServerUrl ?? `http://${cliArgs.hostMode === "lan" ? getLocalNetworkIP() : "localhost"}:${cliArgs.devPort}`;
|
|
1505
1518
|
const res = await fetch(`${papercraneUrl}/api/environments/register`, {
|
|
1506
1519
|
method: "POST",
|
|
1507
1520
|
headers: { "Content-Type": "application/json" },
|
|
1508
1521
|
body: JSON.stringify({
|
|
1509
1522
|
connectionToken: token,
|
|
1510
1523
|
agentEndpoint,
|
|
1511
|
-
|
|
1524
|
+
devServerUrl
|
|
1512
1525
|
})
|
|
1513
1526
|
});
|
|
1514
1527
|
if (!res.ok) {
|
|
@@ -1522,7 +1535,7 @@ async function registerWithPapercrane(overrides) {
|
|
|
1522
1535
|
registeredPapercraneUrl = papercraneUrl;
|
|
1523
1536
|
console.log(`✓ Successfully registered as environment #${environmentId}`);
|
|
1524
1537
|
console.log(` Agent endpoint: ${agentEndpoint}`);
|
|
1525
|
-
console.log(`
|
|
1538
|
+
console.log(` Dev server URL: ${devServerUrl}`);
|
|
1526
1539
|
startHeartbeat();
|
|
1527
1540
|
return true;
|
|
1528
1541
|
}
|
|
@@ -1643,7 +1656,7 @@ async function start() {
|
|
|
1643
1656
|
const overrides = cliArgs.agentEndpoint && cliArgs.dashboardsEndpoint
|
|
1644
1657
|
? {
|
|
1645
1658
|
agentEndpoint: cliArgs.agentEndpoint,
|
|
1646
|
-
|
|
1659
|
+
devServerUrl: cliArgs.dashboardsEndpoint,
|
|
1647
1660
|
}
|
|
1648
1661
|
: undefined;
|
|
1649
1662
|
const success = await registerWithPapercrane(overrides);
|
|
@@ -1722,24 +1735,6 @@ async function start() {
|
|
|
1722
1735
|
console.log(` Connected to Papercrane at ${cliArgs.papercraneUrl}`);
|
|
1723
1736
|
}
|
|
1724
1737
|
console.log(`\nReady to accept connections.`);
|
|
1725
|
-
// Auto-register when running in k8s/BYOC — env vars set by KubernetesSandboxProvider
|
|
1726
|
-
if (process.env.CONNECTION_TOKEN && process.env.PAPERCRANE_URL) {
|
|
1727
|
-
// POD_IP is injected via the Kubernetes Downward API — use it so the control plane
|
|
1728
|
-
// gets a real routable IP (reachable via Tailscale subnet routing) rather than
|
|
1729
|
-
// a cluster-internal DNS name that's only resolvable inside the cluster.
|
|
1730
|
-
const podIp = process.env.POD_IP;
|
|
1731
|
-
const agentEndpoint = podIp ? `http://${podIp}:${PORT}` : (process.env.AGENT_ENDPOINT ?? `http://localhost:${PORT}`);
|
|
1732
|
-
const previewEndpoint = podIp ? `http://${podIp}:3000` : agentEndpoint.replace(`:${PORT}`, ":3000");
|
|
1733
|
-
registerWithPapercrane({
|
|
1734
|
-
token: process.env.CONNECTION_TOKEN,
|
|
1735
|
-
papercraneUrl: process.env.PAPERCRANE_URL,
|
|
1736
|
-
agentEndpoint,
|
|
1737
|
-
previewEndpoint,
|
|
1738
|
-
}).then((ok) => {
|
|
1739
|
-
if (!ok)
|
|
1740
|
-
console.error("Auto-registration failed — sandbox will not be reachable by control plane");
|
|
1741
|
-
});
|
|
1742
|
-
}
|
|
1743
1738
|
});
|
|
1744
1739
|
}
|
|
1745
1740
|
catch (error) {
|