@hasna/sandboxes 0.1.26 → 0.1.27
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.d.ts +1 -1
- package/dist/index.js +43 -0
- package/dist/mcp/http.d.ts +1 -2
- package/dist/mcp/index.js +8 -8
- package/dist/sdk.d.ts +32 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { BUILTIN_IMAGES, resolveImage, getBuiltinImageSetupScript } from "./lib/
|
|
|
15
15
|
export { getProvider } from "./providers/index.js";
|
|
16
16
|
export type { SandboxProvider, ProviderSandbox, CreateSandboxOpts, ExecOptions } from "./providers/types.js";
|
|
17
17
|
export { SandboxesSDK, createSandboxesSDK, } from "./sdk.js";
|
|
18
|
-
export type { ExecCommandResult, ProviderFactory, RunAgentOptions, SandboxesSDKOptions, WaitForSessionOptions, } from "./sdk.js";
|
|
18
|
+
export type { ExecCommandResult, ProviderFactory, RunAgentOptions, RunCommandInSandboxOptions, RunCommandInSandboxResult, RunCommandInSandboxUploadOptions, SandboxesSDKOptions, OneShotSandboxCleanup, WaitForSessionOptions, } from "./sdk.js";
|
|
19
19
|
export { createStreamCollector, addStreamListener, emitLifecycleEvent } from "./lib/stream.js";
|
|
20
20
|
export { getAgentDriver, listAgentDrivers } from "./lib/agents/index.js";
|
|
21
21
|
export type { AgentDriver } from "./lib/agents/types.js";
|
package/dist/index.js
CHANGED
|
@@ -11643,6 +11643,49 @@ class SandboxesSDK {
|
|
|
11643
11643
|
emitLifecycleEvent(sandbox.id, `uploaded ${localDir} -> ${remoteDir} (${result.bytes} bytes)`);
|
|
11644
11644
|
return result;
|
|
11645
11645
|
}
|
|
11646
|
+
async runCommandInSandbox(input) {
|
|
11647
|
+
const cleanupMode = input.cleanup ?? "delete";
|
|
11648
|
+
const sandbox = await this.createSandbox({
|
|
11649
|
+
provider: input.provider,
|
|
11650
|
+
name: input.name,
|
|
11651
|
+
image: input.image,
|
|
11652
|
+
timeout: input.sandboxTimeout,
|
|
11653
|
+
env_vars: input.sandboxEnvVars,
|
|
11654
|
+
config: input.config,
|
|
11655
|
+
project_id: input.projectId
|
|
11656
|
+
});
|
|
11657
|
+
let upload;
|
|
11658
|
+
let exec;
|
|
11659
|
+
try {
|
|
11660
|
+
if (input.upload) {
|
|
11661
|
+
upload = await this.uploadDir(sandbox.id, input.upload.localDir, input.upload.remoteDir, { exclude: input.upload.exclude });
|
|
11662
|
+
}
|
|
11663
|
+
exec = await this.execCommand(sandbox.id, input.command, {
|
|
11664
|
+
cwd: input.cwd ?? input.upload?.remoteDir,
|
|
11665
|
+
env: input.callEnvVars,
|
|
11666
|
+
timeout: input.commandTimeoutMs,
|
|
11667
|
+
onStdout: input.onStdout,
|
|
11668
|
+
onStderr: input.onStderr
|
|
11669
|
+
});
|
|
11670
|
+
} finally {
|
|
11671
|
+
if (cleanupMode === "delete") {
|
|
11672
|
+
await this.deleteSandbox(sandbox.id);
|
|
11673
|
+
} else if (cleanupMode === "stop") {
|
|
11674
|
+
await this.stopSandbox(sandbox.id);
|
|
11675
|
+
}
|
|
11676
|
+
}
|
|
11677
|
+
if (!exec) {
|
|
11678
|
+
throw new Error("Sandbox command did not produce an execution result");
|
|
11679
|
+
}
|
|
11680
|
+
return {
|
|
11681
|
+
sandbox,
|
|
11682
|
+
session: exec.session,
|
|
11683
|
+
result: exec.result,
|
|
11684
|
+
upload,
|
|
11685
|
+
remoteDir: input.upload?.remoteDir,
|
|
11686
|
+
cleanup: cleanupMode === "delete" ? "deleted" : cleanupMode === "stop" ? "stopped" : "kept"
|
|
11687
|
+
};
|
|
11688
|
+
}
|
|
11646
11689
|
async runAgent(sandboxId, opts) {
|
|
11647
11690
|
const sandbox = this.requireProviderSandbox(sandboxId);
|
|
11648
11691
|
const provider = await this.getProvider(sandbox.provider);
|
package/dist/mcp/http.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Server } from "node:http";
|
|
2
|
-
export declare const DEFAULT_MCP_HTTP_PORT =
|
|
2
|
+
export declare const DEFAULT_MCP_HTTP_PORT = 8831;
|
|
3
3
|
export declare function isHttpMode(argv: string[]): boolean;
|
|
4
|
-
export declare function isStdioMode(argv: string[]): boolean;
|
|
5
4
|
export declare function resolveMcpHttpPort(argv: string[]): number;
|
|
6
5
|
export declare function healthPayload(name?: string): {
|
|
7
6
|
status: string;
|
package/dist/mcp/index.js
CHANGED
|
@@ -16930,9 +16930,9 @@ function buildServer() {
|
|
|
16930
16930
|
import { createServer } from "http";
|
|
16931
16931
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
16932
16932
|
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
16933
|
-
var DEFAULT_MCP_HTTP_PORT =
|
|
16934
|
-
function
|
|
16935
|
-
return argv.includes("--
|
|
16933
|
+
var DEFAULT_MCP_HTTP_PORT = 8831;
|
|
16934
|
+
function isHttpMode(argv) {
|
|
16935
|
+
return argv.includes("--http") || process.env["MCP_HTTP"] === "1";
|
|
16936
16936
|
}
|
|
16937
16937
|
function resolveMcpHttpPort(argv) {
|
|
16938
16938
|
const portIdx = argv.indexOf("--port");
|
|
@@ -17014,12 +17014,12 @@ if (handleCliFlags(argv)) {
|
|
|
17014
17014
|
process.exit(0);
|
|
17015
17015
|
}
|
|
17016
17016
|
async function main() {
|
|
17017
|
-
if (
|
|
17018
|
-
|
|
17019
|
-
const transport = new StdioServerTransport;
|
|
17020
|
-
await server.connect(transport);
|
|
17017
|
+
if (isHttpMode(argv)) {
|
|
17018
|
+
startMcpHttpServer({ port: resolveMcpHttpPort(argv) });
|
|
17021
17019
|
return;
|
|
17022
17020
|
}
|
|
17023
|
-
|
|
17021
|
+
const server = buildServer();
|
|
17022
|
+
const transport = new StdioServerTransport;
|
|
17023
|
+
await server.connect(transport);
|
|
17024
17024
|
}
|
|
17025
17025
|
main().catch(console.error);
|
package/dist/sdk.d.ts
CHANGED
|
@@ -15,6 +15,37 @@ export interface ExecCommandResult {
|
|
|
15
15
|
session: SandboxSession;
|
|
16
16
|
result: ExecResult;
|
|
17
17
|
}
|
|
18
|
+
export type OneShotSandboxCleanup = "delete" | "stop" | "keep";
|
|
19
|
+
export interface RunCommandInSandboxUploadOptions {
|
|
20
|
+
localDir: string;
|
|
21
|
+
remoteDir: string;
|
|
22
|
+
exclude?: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface RunCommandInSandboxOptions {
|
|
25
|
+
command: string;
|
|
26
|
+
provider?: SandboxProviderName;
|
|
27
|
+
name?: string;
|
|
28
|
+
image?: string;
|
|
29
|
+
sandboxTimeout?: number;
|
|
30
|
+
commandTimeoutMs?: number;
|
|
31
|
+
projectId?: string;
|
|
32
|
+
config?: Record<string, unknown>;
|
|
33
|
+
sandboxEnvVars?: Record<string, string>;
|
|
34
|
+
callEnvVars?: Record<string, string>;
|
|
35
|
+
cwd?: string;
|
|
36
|
+
upload?: RunCommandInSandboxUploadOptions;
|
|
37
|
+
cleanup?: OneShotSandboxCleanup;
|
|
38
|
+
onStdout?: (data: string) => void;
|
|
39
|
+
onStderr?: (data: string) => void;
|
|
40
|
+
}
|
|
41
|
+
export interface RunCommandInSandboxResult {
|
|
42
|
+
sandbox: Sandbox;
|
|
43
|
+
session: SandboxSession;
|
|
44
|
+
result: ExecResult;
|
|
45
|
+
upload?: UploadDirResult;
|
|
46
|
+
remoteDir?: string;
|
|
47
|
+
cleanup: "deleted" | "stopped" | "kept";
|
|
48
|
+
}
|
|
18
49
|
export interface RunAgentOptions {
|
|
19
50
|
agentType: AgentType;
|
|
20
51
|
prompt: string;
|
|
@@ -54,6 +85,7 @@ export declare class SandboxesSDK {
|
|
|
54
85
|
glob?: string;
|
|
55
86
|
}): Promise<FileInfo[]>;
|
|
56
87
|
uploadDir(sandboxId: string, localDir: string, remoteDir: string, opts?: UploadDirOptions): Promise<UploadDirResult>;
|
|
88
|
+
runCommandInSandbox(input: RunCommandInSandboxOptions): Promise<RunCommandInSandboxResult>;
|
|
57
89
|
runAgent(sandboxId: string, opts: RunAgentOptions): Promise<SandboxSession>;
|
|
58
90
|
getSession(sessionId: string): SandboxSession;
|
|
59
91
|
waitForSession(sessionId: string, opts?: WaitForSessionOptions): Promise<SandboxSession>;
|