mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-16 22:03:52 +00:00
feat: download batch
This commit is contained in:
parent
3545139cd3
commit
e1a09564e4
14 changed files with 702 additions and 91 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import { SandboxAgent } from "sandbox-agent";
|
||||
import { detectAgent, buildInspectorUrl } from "@sandbox-agent/example-shared";
|
||||
import { startDockerSandbox } from "@sandbox-agent/example-shared/docker";
|
||||
import * as tar from "tar";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
|
@ -23,14 +22,9 @@ console.log(" Created 3 files in my-project/");
|
|||
console.log("Uploading files via batch tar...");
|
||||
const client = await SandboxAgent.connect({ baseUrl });
|
||||
|
||||
const tarPath = path.join(tmpDir, "upload.tar");
|
||||
await tar.create(
|
||||
{ file: tarPath, cwd: tmpDir },
|
||||
["my-project"],
|
||||
);
|
||||
const tarBuffer = await fs.promises.readFile(tarPath);
|
||||
const uploadResult = await client.uploadFsBatch(tarBuffer, { path: "/opt" });
|
||||
console.log(` Uploaded ${uploadResult.paths.length} files: ${uploadResult.paths.join(", ")}`);
|
||||
// Requires `tar` to be installed (optional peer dependency of `sandbox-agent`).
|
||||
const uploadResult = await client.uploadFsBatch({ sourcePath: projectDir }, { path: "/opt/my-project" });
|
||||
console.log(` Uploaded ${uploadResult.paths.length} entries: ${uploadResult.paths.join(", ")}`);
|
||||
|
||||
// Cleanup temp files
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
|
|
@ -46,6 +40,22 @@ const readmeBytes = await client.readFsFile({ path: "/opt/my-project/README.md"
|
|||
const readmeText = new TextDecoder().decode(readmeBytes);
|
||||
console.log(` README.md content: ${readmeText.trim()}`);
|
||||
|
||||
console.log("Downloading the uploaded project via batch tar...");
|
||||
const downloadTmp = path.resolve(__dirname, "../.tmp-download");
|
||||
fs.rmSync(downloadTmp, { recursive: true, force: true });
|
||||
fs.mkdirSync(downloadTmp, { recursive: true });
|
||||
await client.downloadFsBatch(
|
||||
{ path: "/opt/my-project" },
|
||||
{ outPath: path.join(downloadTmp, "my-project.tar"), extractTo: downloadTmp },
|
||||
);
|
||||
console.log(` Extracted to: ${downloadTmp}`);
|
||||
for (const entry of fs.readdirSync(downloadTmp)) {
|
||||
if (entry.endsWith(".tar")) {
|
||||
continue;
|
||||
}
|
||||
console.log(` ${entry}`);
|
||||
}
|
||||
|
||||
console.log("Creating session...");
|
||||
const session = await client.createSession({ agent: detectAgent(), sessionInit: { cwd: "/opt/my-project", mcpServers: [] } });
|
||||
const sessionId = session.id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue