orbitx 0.1.0 → 0.1.1
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.
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export declare class MCPComputer {
|
|
2
2
|
#private;
|
|
3
|
-
constructor(mountPath: string, ports: number[], image?: string);
|
|
3
|
+
constructor(mountPath: string, ports: number[] | "*", image?: string);
|
|
4
4
|
getIPCSocketPath(): string;
|
|
5
|
-
/** Host-side path where presented files land (mounted into the container at /home/ubuntu/presents). */
|
|
6
5
|
getPresentsHostPath(): string;
|
|
6
|
+
isHostNetwork(): boolean;
|
|
7
|
+
getPortUrl(port: number, host?: string): string;
|
|
7
8
|
buildDockerArgs(): string[];
|
|
8
9
|
start(): import("node:child_process").ChildProcess;
|
|
10
|
+
stop(): void;
|
|
9
11
|
getInstructions(): string;
|
|
10
12
|
}
|
|
11
13
|
export default MCPComputer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-computer.d.ts","sourceRoot":"","sources":["../../src/core/mcp-computer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp-computer.d.ts","sourceRoot":"","sources":["../../src/core/mcp-computer.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAW;;gBAUR,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,KAAK,GAAE,MAA6B;IAuB1F,gBAAgB,IAAI,MAAM;IAI1B,mBAAmB,IAAI,MAAM;IAI7B,aAAa,IAAI,OAAO;IAIxB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAoB,GAAG,MAAM;IAqC5D,eAAe,IAAI,MAAM,EAAE;IA6B3B,KAAK;IAmBL,IAAI;IAUJ,eAAe,IAAI,MAAM;CAmB5B;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// TODO Add Host ability to docker to open any ports
|
|
2
1
|
import os from "os";
|
|
3
2
|
import { randomUUID } from "crypto";
|
|
4
3
|
import { spawn, execFileSync } from "child_process";
|
|
@@ -7,14 +6,22 @@ import path from "path";
|
|
|
7
6
|
export class MCPComputer {
|
|
8
7
|
#mountPath;
|
|
9
8
|
#ports;
|
|
9
|
+
#hostNetwork;
|
|
10
10
|
#image;
|
|
11
11
|
#ipcPath;
|
|
12
12
|
#containerName;
|
|
13
|
+
#child = null;
|
|
14
|
+
#exitHandler = null;
|
|
13
15
|
constructor(mountPath, ports, image = "orbitx-sandbox:0.1") {
|
|
14
16
|
if (os.platform() === "win32") {
|
|
15
17
|
throw new Error("This feature is not currently supported natively on Windows. " +
|
|
16
18
|
"Please run via WSL, or use a Unix-like filesystem (this feature needs one).");
|
|
17
19
|
}
|
|
20
|
+
this.#hostNetwork = ports === "*";
|
|
21
|
+
if (this.#hostNetwork && os.platform() !== "linux") {
|
|
22
|
+
throw new Error("Host network mode (ports: \"*\") requires Docker's --network host, " +
|
|
23
|
+
"which is only supported on Linux. Pass an explicit array of ports instead.");
|
|
24
|
+
}
|
|
18
25
|
this.#mountPath = path.resolve(mountPath);
|
|
19
26
|
this.#ports = ports;
|
|
20
27
|
this.#image = image;
|
|
@@ -24,10 +31,20 @@ export class MCPComputer {
|
|
|
24
31
|
getIPCSocketPath() {
|
|
25
32
|
return `${this.#ipcPath}/socket.sock`;
|
|
26
33
|
}
|
|
27
|
-
/** Host-side path where presented files land (mounted into the container at /home/ubuntu/presents). */
|
|
28
34
|
getPresentsHostPath() {
|
|
29
35
|
return path.join(this.#mountPath, "presents");
|
|
30
36
|
}
|
|
37
|
+
isHostNetwork() {
|
|
38
|
+
return this.#hostNetwork;
|
|
39
|
+
}
|
|
40
|
+
getPortUrl(port, host = "localhost") {
|
|
41
|
+
if (!this.#hostNetwork && !this.#ports.includes(port)) {
|
|
42
|
+
throw new Error(`Port ${port} was not exposed for this sandbox. ` +
|
|
43
|
+
`Available ports: ${this.#ports.join(", ") || "none"}. ` +
|
|
44
|
+
`Pass ports: "*" at construction time to allow any port.`);
|
|
45
|
+
}
|
|
46
|
+
return `http://${host}:${port}`;
|
|
47
|
+
}
|
|
31
48
|
#prepareHostPaths(containerUid = 1000, containerGid = 1000) {
|
|
32
49
|
const workspaceHost = path.join(this.#mountPath, "workspace");
|
|
33
50
|
const storageHost = path.join(this.#mountPath, "mcp-server-storage");
|
|
@@ -70,8 +87,13 @@ export class MCPComputer {
|
|
|
70
87
|
"-v", `${this.#ipcPath}:/tmp/mcp-server`,
|
|
71
88
|
"-e", "PRESENT_PATH=/home/ubuntu/presents",
|
|
72
89
|
];
|
|
73
|
-
|
|
74
|
-
args.push("
|
|
90
|
+
if (this.#hostNetwork) {
|
|
91
|
+
args.push("--network", "host");
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
for (const port of this.#ports) {
|
|
95
|
+
args.push("-p", `${port}:${port}`);
|
|
96
|
+
}
|
|
75
97
|
}
|
|
76
98
|
args.push(this.#image);
|
|
77
99
|
return args;
|
|
@@ -79,24 +101,36 @@ export class MCPComputer {
|
|
|
79
101
|
start() {
|
|
80
102
|
this.#prepareHostPaths();
|
|
81
103
|
const args = this.buildDockerArgs();
|
|
82
|
-
const child = spawn("docker", args, { stdio: "
|
|
83
|
-
|
|
104
|
+
const child = spawn("docker", args, { stdio: "ignore" });
|
|
105
|
+
this.#child = child;
|
|
106
|
+
this.#exitHandler = () => {
|
|
84
107
|
try {
|
|
85
108
|
execFileSync("docker", ["kill", this.#containerName], { stdio: "ignore" });
|
|
86
109
|
}
|
|
87
110
|
catch {
|
|
88
111
|
// already stopped, fine
|
|
89
112
|
}
|
|
90
|
-
}
|
|
113
|
+
};
|
|
114
|
+
process.on("exit", this.#exitHandler);
|
|
91
115
|
return child;
|
|
92
116
|
}
|
|
117
|
+
stop() {
|
|
118
|
+
if (this.#exitHandler) {
|
|
119
|
+
this.#exitHandler();
|
|
120
|
+
process.off("exit", this.#exitHandler);
|
|
121
|
+
this.#exitHandler = null;
|
|
122
|
+
}
|
|
123
|
+
this.#child = null;
|
|
124
|
+
}
|
|
93
125
|
getInstructions() {
|
|
94
126
|
const workspacePath = "/home/ubuntu/workspace";
|
|
95
127
|
const presentsPath = "/home/ubuntu/presents";
|
|
96
128
|
const userInputsPath = "/home/ubuntu/user-inputs";
|
|
97
|
-
const portsList = this.#
|
|
98
|
-
?
|
|
99
|
-
:
|
|
129
|
+
const portsList = this.#hostNetwork
|
|
130
|
+
? "any (host network mode — all ports are shared with the host)"
|
|
131
|
+
: this.#ports.length > 0
|
|
132
|
+
? this.#ports.join(", ")
|
|
133
|
+
: "none";
|
|
100
134
|
return [
|
|
101
135
|
`SandBox info`,
|
|
102
136
|
`Workspace path: ${workspacePath}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-computer.js","sourceRoot":"","sources":["../../src/core/mcp-computer.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"mcp-computer.js","sourceRoot":"","sources":["../../src/core/mcp-computer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,OAAO,WAAW;IACpB,UAAU,CAAS;IACnB,MAAM,CAAiB;IACvB,YAAY,CAAU;IACtB,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,cAAc,CAAS;IACvB,MAAM,GAAoC,IAAI,CAAC;IAC/C,YAAY,GAAwB,IAAI,CAAC;IAEzC,YAAY,SAAiB,EAAE,KAAqB,EAAE,QAAgB,oBAAoB;QACtF,IAAI,EAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACX,+DAA+D;gBAC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