@fastgpt-sdk/sandbox-adapter 0.0.36 → 0.0.38-beta.0
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/adapters/BaseSandboxAdapter.d.ts +3 -1
- package/dist/adapters/OpenSandboxAdapter/index.d.ts +11 -7
- package/dist/adapters/OpenSandboxAdapter/type.d.ts +1 -1
- package/dist/adapters/SealosDevboxAdapter/api.d.ts +4 -2
- package/dist/adapters/SealosDevboxAdapter/index.d.ts +26 -2
- package/dist/adapters/SealosDevboxAdapter/type.d.ts +32 -1
- package/dist/adapters/index.d.ts +3 -3
- package/dist/adapters/ports.d.ts +7 -0
- package/dist/index.cjs +282 -47
- package/dist/index.js +280 -45
- package/dist/interfaces/ISandbox.d.ts +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/sandbox.d.ts +45 -0
- package/dist/utils/image.d.ts +3 -0
- package/dist/utils/url.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,39 +4,60 @@ var __defProp = Object.defineProperty;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
21
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
22
|
for (let key of __getOwnPropNames(mod))
|
|
11
23
|
if (!__hasOwnProp.call(to, key))
|
|
12
24
|
__defProp(to, key, {
|
|
13
|
-
get: (
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
14
26
|
enumerable: true
|
|
15
27
|
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
16
30
|
return to;
|
|
17
31
|
};
|
|
18
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
19
32
|
var __toCommonJS = (from) => {
|
|
20
|
-
var entry = __moduleCache.get(from), desc;
|
|
33
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
21
34
|
if (entry)
|
|
22
35
|
return entry;
|
|
23
36
|
entry = __defProp({}, "__esModule", { value: true });
|
|
24
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (var key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(entry, key))
|
|
40
|
+
__defProp(entry, key, {
|
|
41
|
+
get: __accessProp.bind(from, key),
|
|
42
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
+
});
|
|
44
|
+
}
|
|
29
45
|
__moduleCache.set(from, entry);
|
|
30
46
|
return entry;
|
|
31
47
|
};
|
|
48
|
+
var __moduleCache;
|
|
32
49
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
50
|
+
var __returnValue = (v) => v;
|
|
51
|
+
function __exportSetter(name, newValue) {
|
|
52
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
53
|
+
}
|
|
33
54
|
var __export = (target, all) => {
|
|
34
55
|
for (var name in all)
|
|
35
56
|
__defProp(target, name, {
|
|
36
57
|
get: all[name],
|
|
37
58
|
enumerable: true,
|
|
38
59
|
configurable: true,
|
|
39
|
-
set: (
|
|
60
|
+
set: __exportSetter.bind(all, name)
|
|
40
61
|
});
|
|
41
62
|
};
|
|
42
63
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
@@ -19139,7 +19160,7 @@ var require_frame = __commonJS((exports2, module2) => {
|
|
|
19139
19160
|
var BUFFER_SIZE = 8 * 1024;
|
|
19140
19161
|
var buffer = null;
|
|
19141
19162
|
var bufIdx = BUFFER_SIZE;
|
|
19142
|
-
var randomFillSync = runtimeFeatures.has("crypto") ? require("node:crypto").randomFillSync : function
|
|
19163
|
+
var randomFillSync = runtimeFeatures.has("crypto") ? require("node:crypto").randomFillSync : function randomFillSync2(buffer2, _offset, _size) {
|
|
19143
19164
|
for (let i = 0;i < buffer2.length; ++i) {
|
|
19144
19165
|
buffer2[i] = Math.random() * 255 | 0;
|
|
19145
19166
|
}
|
|
@@ -21083,7 +21104,7 @@ var require_eventsource = __commonJS((exports2, module2) => {
|
|
|
21083
21104
|
|
|
21084
21105
|
// node_modules/undici/index.js
|
|
21085
21106
|
var require_undici = __commonJS((exports2, module2) => {
|
|
21086
|
-
var __filename = "/
|
|
21107
|
+
var __filename = "/Users/sealos/Documents/GitHub/agent-sandbox-adaptor/node_modules/undici/index.js";
|
|
21087
21108
|
var Client = require_client();
|
|
21088
21109
|
var Dispatcher = require_dispatcher();
|
|
21089
21110
|
var Pool = require_pool();
|
|
@@ -21206,7 +21227,7 @@ var require_undici = __commonJS((exports2, module2) => {
|
|
|
21206
21227
|
err.stack = stack ? `${stack}
|
|
21207
21228
|
${captureLines}` : capture.stack;
|
|
21208
21229
|
}
|
|
21209
|
-
module2.exports.fetch = function
|
|
21230
|
+
module2.exports.fetch = function fetch2(init, options = undefined) {
|
|
21210
21231
|
return fetchImpl(init, options).catch((err) => {
|
|
21211
21232
|
appendFetchStackTrace(err, __filename);
|
|
21212
21233
|
throw err;
|
|
@@ -45388,6 +45409,12 @@ class BaseSandboxAdapter {
|
|
|
45388
45409
|
async renewExpiration(_additionalSeconds) {
|
|
45389
45410
|
throw new FeatureNotSupportedError("Sandbox expiration renewal not supported by this provider", "renewExpiration", this.provider);
|
|
45390
45411
|
}
|
|
45412
|
+
async getEndpoint(_selector) {
|
|
45413
|
+
throw new FeatureNotSupportedError("Endpoint resolution not supported by this provider", "getEndpoint", this.provider);
|
|
45414
|
+
}
|
|
45415
|
+
async getProxyTarget(_service = "code-server") {
|
|
45416
|
+
throw new FeatureNotSupportedError("Proxy target resolution not supported by this provider", "getProxyTarget", this.provider);
|
|
45417
|
+
}
|
|
45391
45418
|
async executeStream(command, handlers, options) {
|
|
45392
45419
|
const result = await this.execute(command, options);
|
|
45393
45420
|
if (handlers.onStdout && result.stdout) {
|
|
@@ -45624,10 +45651,10 @@ class DevboxApi {
|
|
|
45624
45651
|
const result = await res.json();
|
|
45625
45652
|
return result;
|
|
45626
45653
|
}
|
|
45627
|
-
async create(
|
|
45654
|
+
async create(req) {
|
|
45628
45655
|
return this.request(this.url("/api/v1/devbox"), {
|
|
45629
45656
|
method: "POST",
|
|
45630
|
-
body: JSON.stringify(
|
|
45657
|
+
body: JSON.stringify(req)
|
|
45631
45658
|
});
|
|
45632
45659
|
}
|
|
45633
45660
|
async info(name) {
|
|
@@ -45640,6 +45667,11 @@ class DevboxApi {
|
|
|
45640
45667
|
method: "POST"
|
|
45641
45668
|
});
|
|
45642
45669
|
}
|
|
45670
|
+
async stop(name) {
|
|
45671
|
+
return this.request(this.url(`/api/v1/devbox/${name}/stop`), {
|
|
45672
|
+
method: "POST"
|
|
45673
|
+
});
|
|
45674
|
+
}
|
|
45643
45675
|
async resume(name) {
|
|
45644
45676
|
return this.request(this.url(`/api/v1/devbox/${name}/resume`), {
|
|
45645
45677
|
method: "POST"
|
|
@@ -45685,18 +45717,60 @@ class DevboxApi {
|
|
|
45685
45717
|
}
|
|
45686
45718
|
}
|
|
45687
45719
|
|
|
45720
|
+
// src/adapters/ports.ts
|
|
45721
|
+
var OPEN_SANDBOX_EXECD_PORT = 44772;
|
|
45722
|
+
var OPEN_SANDBOX_CODE_SERVER_PORT = 8080;
|
|
45723
|
+
var SEALOS_DEVBOX_CODE_SERVER_PORT = 1318;
|
|
45724
|
+
|
|
45725
|
+
// src/utils/image.ts
|
|
45726
|
+
function formatImageSpec(image) {
|
|
45727
|
+
const parts = [image.repository];
|
|
45728
|
+
if (image.tag)
|
|
45729
|
+
parts.push(":", image.tag);
|
|
45730
|
+
if (image.digest)
|
|
45731
|
+
parts.push("@", image.digest);
|
|
45732
|
+
return parts.join("");
|
|
45733
|
+
}
|
|
45734
|
+
function parseImageSpec(image) {
|
|
45735
|
+
if (!image)
|
|
45736
|
+
return { repository: "" };
|
|
45737
|
+
const atIndex = image.indexOf("@");
|
|
45738
|
+
if (atIndex > -1) {
|
|
45739
|
+
return { repository: image.slice(0, atIndex), digest: image.slice(atIndex + 1) };
|
|
45740
|
+
}
|
|
45741
|
+
const colonIndex = image.indexOf(":");
|
|
45742
|
+
if (colonIndex > -1) {
|
|
45743
|
+
return { repository: image.slice(0, colonIndex), tag: image.slice(colonIndex + 1) };
|
|
45744
|
+
}
|
|
45745
|
+
return { repository: image };
|
|
45746
|
+
}
|
|
45747
|
+
|
|
45748
|
+
// src/utils/url.ts
|
|
45749
|
+
function normalizePathPrefix(path) {
|
|
45750
|
+
if (!path)
|
|
45751
|
+
return "";
|
|
45752
|
+
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
45753
|
+
return normalized.length > 1 ? normalized.replace(/\/+$/, "") : "";
|
|
45754
|
+
}
|
|
45755
|
+
function joinUrlPath(url, path) {
|
|
45756
|
+
const normalizedPath = normalizePathPrefix(path);
|
|
45757
|
+
return normalizedPath ? `${url.replace(/\/+$/, "")}${normalizedPath}` : url.replace(/\/+$/, "");
|
|
45758
|
+
}
|
|
45759
|
+
|
|
45688
45760
|
// src/adapters/SealosDevboxAdapter/index.ts
|
|
45689
45761
|
class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
45690
45762
|
config;
|
|
45763
|
+
createConfig;
|
|
45691
45764
|
provider = "sealosdevbox";
|
|
45692
45765
|
get rootPath() {
|
|
45693
45766
|
return "/home/devbox/workspace";
|
|
45694
45767
|
}
|
|
45695
45768
|
api;
|
|
45696
45769
|
_id;
|
|
45697
|
-
constructor(config) {
|
|
45770
|
+
constructor(config, createConfig) {
|
|
45698
45771
|
super();
|
|
45699
45772
|
this.config = config;
|
|
45773
|
+
this.createConfig = createConfig;
|
|
45700
45774
|
this.api = new DevboxApi({ baseUrl: config.baseUrl, token: config.token });
|
|
45701
45775
|
this._id = config.sandboxId;
|
|
45702
45776
|
this.polyfillService = new CommandPolyfillService(this);
|
|
@@ -45721,6 +45795,26 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45721
45795
|
return "Error";
|
|
45722
45796
|
}
|
|
45723
45797
|
}
|
|
45798
|
+
buildCreateRequest() {
|
|
45799
|
+
const spec = this.createConfig ?? {};
|
|
45800
|
+
const env = { ...spec.env ?? {} };
|
|
45801
|
+
if (spec.workingDir && !env.CODEX_GATEWAY_CWD) {
|
|
45802
|
+
env.CODEX_GATEWAY_CWD = spec.workingDir;
|
|
45803
|
+
}
|
|
45804
|
+
return this.removeUndefined({
|
|
45805
|
+
name: this._id,
|
|
45806
|
+
image: spec.image ? formatImageSpec(spec.image) : undefined,
|
|
45807
|
+
env: Object.keys(env).length > 0 ? env : undefined,
|
|
45808
|
+
labels: spec.labels,
|
|
45809
|
+
upstreamID: spec.upstreamID,
|
|
45810
|
+
kubeAccess: spec.kubeAccess,
|
|
45811
|
+
pauseAt: spec.lifecycle?.pauseAt,
|
|
45812
|
+
archiveAfterPauseTime: spec.lifecycle?.archiveAfterPauseTime
|
|
45813
|
+
});
|
|
45814
|
+
}
|
|
45815
|
+
removeUndefined(obj) {
|
|
45816
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
|
|
45817
|
+
}
|
|
45724
45818
|
async getInfo() {
|
|
45725
45819
|
try {
|
|
45726
45820
|
const res = await this.api.info(this._id);
|
|
@@ -45732,10 +45826,10 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45732
45826
|
this._status = { state: this.StatusAdapt(data), message: res.message };
|
|
45733
45827
|
return {
|
|
45734
45828
|
id: data.name,
|
|
45735
|
-
image:
|
|
45829
|
+
image: parseImageSpec(data.image),
|
|
45736
45830
|
entrypoint: [],
|
|
45737
45831
|
status: this._status,
|
|
45738
|
-
createdAt: new Date
|
|
45832
|
+
createdAt: data.creationTimestamp ? new Date(data.creationTimestamp) : new Date
|
|
45739
45833
|
};
|
|
45740
45834
|
} catch (error) {
|
|
45741
45835
|
throw new CommandExecutionError(`Failed to get sandbox info`, "getInfo", error instanceof Error ? error : undefined);
|
|
@@ -45773,7 +45867,10 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45773
45867
|
async create() {
|
|
45774
45868
|
try {
|
|
45775
45869
|
this._status = { state: "Creating" };
|
|
45776
|
-
await this.api.create(this.
|
|
45870
|
+
const res = await this.api.create(this.buildCreateRequest());
|
|
45871
|
+
if (res.code !== 200 && res.code !== 201) {
|
|
45872
|
+
throw new Error(res.message || `Devbox create failed with code ${res.code}`);
|
|
45873
|
+
}
|
|
45777
45874
|
await this.waitUntilReady();
|
|
45778
45875
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
45779
45876
|
this._status = { state: "Running" };
|
|
@@ -45784,10 +45881,10 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45784
45881
|
async stop() {
|
|
45785
45882
|
try {
|
|
45786
45883
|
this._status = { state: "Stopping" };
|
|
45787
|
-
await this.api.
|
|
45884
|
+
await this.api.stop(this._id);
|
|
45788
45885
|
this._status = { state: "Stopped" };
|
|
45789
45886
|
} catch (error) {
|
|
45790
|
-
throw new CommandExecutionError("Failed to
|
|
45887
|
+
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
45791
45888
|
}
|
|
45792
45889
|
}
|
|
45793
45890
|
async start() {
|
|
@@ -45829,11 +45926,125 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45829
45926
|
throw new CommandExecutionError(`Command execution failed: ${error?.message || error?.code}`, command, error instanceof Error ? error : undefined);
|
|
45830
45927
|
}
|
|
45831
45928
|
}
|
|
45929
|
+
async getEndpoint(selector) {
|
|
45930
|
+
const port = typeof selector === "number" ? selector : SEALOS_DEVBOX_CODE_SERVER_PORT;
|
|
45931
|
+
const target = await this.getHttpgateTarget(port);
|
|
45932
|
+
if (selector === "code-server") {
|
|
45933
|
+
await this.waitForCodeServerHealthz(target);
|
|
45934
|
+
}
|
|
45935
|
+
const url = new URL(target.origin);
|
|
45936
|
+
return {
|
|
45937
|
+
host: url.host,
|
|
45938
|
+
port: target.port,
|
|
45939
|
+
protocol: url.protocol === "https:" ? "https" : "http",
|
|
45940
|
+
url: joinUrlPath(target.origin, target.basePath)
|
|
45941
|
+
};
|
|
45942
|
+
}
|
|
45943
|
+
async getProxyTarget(service = "code-server") {
|
|
45944
|
+
if (service !== "code-server") {
|
|
45945
|
+
throw new FeatureNotSupportedError(`Proxy service "${service}" is not supported by this provider`, "getProxyTarget", this.provider);
|
|
45946
|
+
}
|
|
45947
|
+
const target = await this.getHttpgateTarget(SEALOS_DEVBOX_CODE_SERVER_PORT);
|
|
45948
|
+
return {
|
|
45949
|
+
service,
|
|
45950
|
+
origin: target.origin,
|
|
45951
|
+
basePath: target.basePath,
|
|
45952
|
+
auth: "code-server",
|
|
45953
|
+
...target.password ? { password: target.password } : {}
|
|
45954
|
+
};
|
|
45955
|
+
}
|
|
45956
|
+
async waitForCodeServerHealthz(target) {
|
|
45957
|
+
const healthUrl = joinUrlPath(joinUrlPath(target.origin, target.basePath), "/healthz");
|
|
45958
|
+
const timeoutMs = 60000;
|
|
45959
|
+
const intervalMs = 500;
|
|
45960
|
+
const requestTimeoutMs = 3000;
|
|
45961
|
+
const deadline = Date.now() + timeoutMs;
|
|
45962
|
+
let lastResult = "not checked";
|
|
45963
|
+
while (Date.now() < deadline) {
|
|
45964
|
+
try {
|
|
45965
|
+
const res = await fetch(healthUrl, {
|
|
45966
|
+
method: "GET",
|
|
45967
|
+
signal: AbortSignal.timeout(requestTimeoutMs)
|
|
45968
|
+
});
|
|
45969
|
+
if (res.status >= 200 && res.status < 400) {
|
|
45970
|
+
return;
|
|
45971
|
+
}
|
|
45972
|
+
lastResult = `status ${res.status}`;
|
|
45973
|
+
} catch (error) {
|
|
45974
|
+
lastResult = error instanceof Error ? error.message : String(error);
|
|
45975
|
+
}
|
|
45976
|
+
await this.sleep(intervalMs);
|
|
45977
|
+
}
|
|
45978
|
+
throw new ConnectionError(`Devbox code-server health check ${healthUrl} did not become ready within ${timeoutMs}ms. Last result: ${lastResult}`, this.config.baseUrl);
|
|
45979
|
+
}
|
|
45980
|
+
async getHttpgateTarget(port) {
|
|
45981
|
+
const res = await this.api.info(this._id);
|
|
45982
|
+
if (res.code !== 200 || !res.data) {
|
|
45983
|
+
throw new ConnectionError(`Failed to get devbox info: ${res.message}`, this.config.baseUrl);
|
|
45984
|
+
}
|
|
45985
|
+
if (port === SEALOS_DEVBOX_CODE_SERVER_PORT) {
|
|
45986
|
+
const gateway2 = res.data.codeServerGateway;
|
|
45987
|
+
if (!gateway2?.url) {
|
|
45988
|
+
throw new ConnectionError("Devbox info does not include codeServerGateway.url; cannot resolve code-server endpoint", this.config.baseUrl);
|
|
45989
|
+
}
|
|
45990
|
+
const codeServerUrl = new URL(gateway2.url);
|
|
45991
|
+
return {
|
|
45992
|
+
origin: codeServerUrl.origin,
|
|
45993
|
+
basePath: normalizePathPrefix(codeServerUrl.pathname),
|
|
45994
|
+
port: gateway2.port ?? port,
|
|
45995
|
+
password: gateway2.password
|
|
45996
|
+
};
|
|
45997
|
+
}
|
|
45998
|
+
const gatewayUrl = res.data.gateway?.url;
|
|
45999
|
+
if (!gatewayUrl) {
|
|
46000
|
+
throw new ConnectionError("Devbox info does not include gateway.url; cannot derive httpgate endpoint", this.config.baseUrl);
|
|
46001
|
+
}
|
|
46002
|
+
const gateway = new URL(gatewayUrl);
|
|
46003
|
+
const uniqueID = this.getGatewayUniqueID(res.data, gateway);
|
|
46004
|
+
const domain = this.getHttpgateDomain(gateway);
|
|
46005
|
+
return {
|
|
46006
|
+
origin: `${gateway.protocol}//devbox-${uniqueID}-${port}.${domain}`,
|
|
46007
|
+
basePath: "",
|
|
46008
|
+
port
|
|
46009
|
+
};
|
|
46010
|
+
}
|
|
46011
|
+
getGatewayUniqueID(data, gateway) {
|
|
46012
|
+
if (data.gateway?.uniqueID)
|
|
46013
|
+
return data.gateway.uniqueID;
|
|
46014
|
+
const parts = gateway.pathname.split("/").filter(Boolean);
|
|
46015
|
+
const uniqueID = parts[parts.length - 1];
|
|
46016
|
+
if (!uniqueID) {
|
|
46017
|
+
throw new ConnectionError("Devbox gateway.url does not include uniqueID; cannot derive httpgate endpoint", this.config.baseUrl);
|
|
46018
|
+
}
|
|
46019
|
+
return uniqueID;
|
|
46020
|
+
}
|
|
46021
|
+
getHttpgateDomain(gateway) {
|
|
46022
|
+
if (this.config.httpgateDomain) {
|
|
46023
|
+
return this.normalizeHttpgateDomain(this.config.httpgateDomain);
|
|
46024
|
+
}
|
|
46025
|
+
const prefix = "devbox-gateway.";
|
|
46026
|
+
if (!gateway.host.startsWith(prefix)) {
|
|
46027
|
+
throw new ConnectionError(`Cannot derive httpgate domain from gateway host "${gateway.host}"`, this.config.baseUrl);
|
|
46028
|
+
}
|
|
46029
|
+
return gateway.host.slice(prefix.length);
|
|
46030
|
+
}
|
|
46031
|
+
normalizeHttpgateDomain(domain) {
|
|
46032
|
+
const trimmed = domain.trim().replace(/^\.+|\.+$/g, "");
|
|
46033
|
+
if (!trimmed) {
|
|
46034
|
+
throw new ConnectionError("httpgateDomain is empty", this.config.baseUrl);
|
|
46035
|
+
}
|
|
46036
|
+
if (trimmed.includes("://")) {
|
|
46037
|
+
return new URL(trimmed).host;
|
|
46038
|
+
}
|
|
46039
|
+
return trimmed;
|
|
46040
|
+
}
|
|
45832
46041
|
async ping() {
|
|
45833
46042
|
try {
|
|
45834
46043
|
const res = await this.api.info(this._id);
|
|
45835
46044
|
if (res.code !== 200)
|
|
45836
46045
|
return false;
|
|
46046
|
+
if (!res.data)
|
|
46047
|
+
return false;
|
|
45837
46048
|
return res.data.state.phase === "Running" /* Running */;
|
|
45838
46049
|
} catch {
|
|
45839
46050
|
return false;
|
|
@@ -47425,7 +47636,7 @@ function createNodeFetch() {
|
|
|
47425
47636
|
const nodeFetch = async (input, init) => {
|
|
47426
47637
|
dispatcherPromise ??= (async () => {
|
|
47427
47638
|
try {
|
|
47428
|
-
const mod = await Promise.resolve().then(() => __toESM(require_undici()));
|
|
47639
|
+
const mod = await Promise.resolve().then(() => __toESM(require_undici(), 1));
|
|
47429
47640
|
const Agent = mod.Agent;
|
|
47430
47641
|
if (!Agent) {
|
|
47431
47642
|
return;
|
|
@@ -48085,27 +48296,6 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48085
48296
|
message: sdkStatus.message
|
|
48086
48297
|
};
|
|
48087
48298
|
}
|
|
48088
|
-
convertImageSpec(image) {
|
|
48089
|
-
const parts = [image.repository];
|
|
48090
|
-
if (image.tag) {
|
|
48091
|
-
parts.push(":", image.tag);
|
|
48092
|
-
}
|
|
48093
|
-
if (image.digest) {
|
|
48094
|
-
parts.push("@", image.digest);
|
|
48095
|
-
}
|
|
48096
|
-
return parts.join("");
|
|
48097
|
-
}
|
|
48098
|
-
parseImageSpec(image) {
|
|
48099
|
-
const atIndex = image.indexOf("@");
|
|
48100
|
-
if (atIndex > -1) {
|
|
48101
|
-
return { repository: image.slice(0, atIndex), digest: image.slice(atIndex + 1) };
|
|
48102
|
-
}
|
|
48103
|
-
const colonIndex = image.indexOf(":");
|
|
48104
|
-
if (colonIndex > -1) {
|
|
48105
|
-
return { repository: image.slice(0, colonIndex), tag: image.slice(colonIndex + 1) };
|
|
48106
|
-
}
|
|
48107
|
-
return { repository: image };
|
|
48108
|
-
}
|
|
48109
48299
|
convertResourceLimits(resourceLimits) {
|
|
48110
48300
|
if (!resourceLimits)
|
|
48111
48301
|
return;
|
|
@@ -48220,7 +48410,7 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48220
48410
|
}
|
|
48221
48411
|
try {
|
|
48222
48412
|
this._status = { state: "Creating" };
|
|
48223
|
-
const image =
|
|
48413
|
+
const image = formatImageSpec(cfg.image);
|
|
48224
48414
|
const resource = this.convertResourceLimits(cfg.resourceLimits);
|
|
48225
48415
|
this.sandbox = await Sandbox.create({
|
|
48226
48416
|
connectionConfig: this._connection,
|
|
@@ -48324,7 +48514,18 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48324
48514
|
async close() {
|
|
48325
48515
|
await this.sandbox.close();
|
|
48326
48516
|
}
|
|
48327
|
-
async getEndpoint(
|
|
48517
|
+
async getEndpoint(selector) {
|
|
48518
|
+
const port = typeof selector === "number" ? selector : OPEN_SANDBOX_EXECD_PORT;
|
|
48519
|
+
const endpoint = await this.getOpenSandboxEndpoint(port);
|
|
48520
|
+
if (selector === "code-server") {
|
|
48521
|
+
return {
|
|
48522
|
+
...endpoint,
|
|
48523
|
+
url: joinUrlPath(endpoint.url, `/proxy/${OPEN_SANDBOX_CODE_SERVER_PORT}`)
|
|
48524
|
+
};
|
|
48525
|
+
}
|
|
48526
|
+
return endpoint;
|
|
48527
|
+
}
|
|
48528
|
+
async getOpenSandboxEndpoint(port) {
|
|
48328
48529
|
const sdkEndpoint = await this.sandbox.getEndpoint(port);
|
|
48329
48530
|
const raw = sdkEndpoint.endpoint;
|
|
48330
48531
|
const colonIdx = raw.lastIndexOf(":");
|
|
@@ -48343,6 +48544,40 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48343
48544
|
url: `https://${raw}`
|
|
48344
48545
|
};
|
|
48345
48546
|
}
|
|
48547
|
+
async getProxyTarget(service = "code-server") {
|
|
48548
|
+
if (service !== "code-server") {
|
|
48549
|
+
throw new FeatureNotSupportedError(`Proxy service "${service}" is not supported by this provider`, "getProxyTarget", this.provider);
|
|
48550
|
+
}
|
|
48551
|
+
return {
|
|
48552
|
+
service,
|
|
48553
|
+
origin: await this.getDirectEndpointOrigin(OPEN_SANDBOX_EXECD_PORT),
|
|
48554
|
+
basePath: `/proxy/${OPEN_SANDBOX_CODE_SERVER_PORT}`,
|
|
48555
|
+
auth: "code-server"
|
|
48556
|
+
};
|
|
48557
|
+
}
|
|
48558
|
+
async getDirectEndpointOrigin(port) {
|
|
48559
|
+
if (!this.id) {
|
|
48560
|
+
throw new SandboxStateError("Sandbox not initialized. Call create() or connect() first.", "UnExist", "Running");
|
|
48561
|
+
}
|
|
48562
|
+
const headers = {
|
|
48563
|
+
...this._connection.headers,
|
|
48564
|
+
Accept: "application/json"
|
|
48565
|
+
};
|
|
48566
|
+
const response = await this._connection.fetch(`${this._connection.getBaseUrl()}/sandboxes/${this.id}/endpoints/${port}?use_server_proxy=false`, { method: "GET", headers });
|
|
48567
|
+
if (!response.ok) {
|
|
48568
|
+
throw new ConnectionError(`OpenSandbox endpoint lookup failed: HTTP ${response.status}`, this.connectionConfig.baseUrl);
|
|
48569
|
+
}
|
|
48570
|
+
const data = await response.json();
|
|
48571
|
+
if (!data.endpoint) {
|
|
48572
|
+
throw new ConnectionError("OpenSandbox returned no endpoint", this.connectionConfig.baseUrl);
|
|
48573
|
+
}
|
|
48574
|
+
let hostPort = data.endpoint.replace(/\/proxy\/\d+\/?$/, "");
|
|
48575
|
+
if (this.connectionConfig.replaceDockerInternalWithLocalhost) {
|
|
48576
|
+
hostPort = hostPort.replace(/^host\.docker\.internal\b/, "localhost");
|
|
48577
|
+
}
|
|
48578
|
+
const url = new URL(/^https?:\/\//.test(hostPort) ? hostPort : `http://${hostPort}`);
|
|
48579
|
+
return url.origin;
|
|
48580
|
+
}
|
|
48346
48581
|
async getInfo() {
|
|
48347
48582
|
if (!this._sandbox) {
|
|
48348
48583
|
return null;
|
|
@@ -48351,7 +48586,7 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48351
48586
|
const info = await this.sandbox.getInfo();
|
|
48352
48587
|
return {
|
|
48353
48588
|
id: info.id,
|
|
48354
|
-
image: typeof info.image === "string" ?
|
|
48589
|
+
image: typeof info.image === "string" ? parseImageSpec(info.image) : ("uri" in info.image) ? parseImageSpec(info.image.uri) : info.image,
|
|
48355
48590
|
entrypoint: info.entrypoint,
|
|
48356
48591
|
metadata: info.metadata,
|
|
48357
48592
|
status: this.mapStatus(info.status),
|
|
@@ -48533,7 +48768,7 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48533
48768
|
}
|
|
48534
48769
|
|
|
48535
48770
|
// src/adapters/E2BAdapter/index.ts
|
|
48536
|
-
var import_code_interpreter = __toESM(require_dist3());
|
|
48771
|
+
var import_code_interpreter = __toESM(require_dist3(), 1);
|
|
48537
48772
|
class E2BAdapter extends BaseSandboxAdapter {
|
|
48538
48773
|
config;
|
|
48539
48774
|
provider = "e2b";
|
|
@@ -48853,7 +49088,7 @@ function createSandbox(provider, config, createConfig) {
|
|
|
48853
49088
|
case "opensandbox":
|
|
48854
49089
|
return new OpenSandboxAdapter(config, createConfig);
|
|
48855
49090
|
case "sealosdevbox":
|
|
48856
|
-
return new SealosDevboxAdapter(config);
|
|
49091
|
+
return new SealosDevboxAdapter(config, createConfig);
|
|
48857
49092
|
case "e2b":
|
|
48858
49093
|
return new E2BAdapter(config);
|
|
48859
49094
|
default:
|