@fastgpt-sdk/sandbox-adapter 0.0.37 → 0.0.38-beta.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.
- package/dist/adapters/BaseSandboxAdapter.d.ts +1 -1
- package/dist/adapters/E2BAdapter/index.d.ts +1 -1
- package/dist/adapters/OpenSandboxAdapter/index.d.ts +1 -1
- package/dist/adapters/SealosDevboxAdapter/api.d.ts +2 -0
- package/dist/adapters/SealosDevboxAdapter/index.d.ts +2 -1
- package/dist/adapters/SealosDevboxAdapter/type.d.ts +2 -1
- package/dist/index.cjs +48 -6
- package/dist/index.js +48 -6
- package/dist/interfaces/ISandboxLifecycle.d.ts +5 -1
- package/package.json +1 -1
|
@@ -32,7 +32,7 @@ export declare abstract class BaseSandboxAdapter implements ISandbox {
|
|
|
32
32
|
abstract create(): Promise<void>;
|
|
33
33
|
abstract start(): Promise<void>;
|
|
34
34
|
abstract stop(): Promise<void>;
|
|
35
|
-
abstract delete(): Promise<void>;
|
|
35
|
+
abstract delete(sandboxId?: SandboxId): Promise<void>;
|
|
36
36
|
abstract getInfo(): Promise<SandboxInfo | null>;
|
|
37
37
|
waitUntilReady(timeoutMs?: number): Promise<void>;
|
|
38
38
|
waitUntilDeleted(timeoutMs?: number): Promise<void>;
|
|
@@ -24,7 +24,7 @@ export declare class E2BAdapter extends BaseSandboxAdapter {
|
|
|
24
24
|
create(): Promise<void>;
|
|
25
25
|
start(): Promise<void>;
|
|
26
26
|
stop(): Promise<void>;
|
|
27
|
-
delete(): Promise<void>;
|
|
27
|
+
delete(sandboxId?: SandboxId): Promise<void>;
|
|
28
28
|
getInfo(): Promise<SandboxInfo | null>;
|
|
29
29
|
execute(command: string, options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
30
30
|
readFiles(paths: string[]): Promise<FileReadResult[]>;
|
|
@@ -80,7 +80,7 @@ export declare class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
80
80
|
private resume;
|
|
81
81
|
start(): Promise<void>;
|
|
82
82
|
stop(): Promise<void>;
|
|
83
|
-
delete(): Promise<void>;
|
|
83
|
+
delete(sandboxId?: SandboxId): Promise<void>;
|
|
84
84
|
/**
|
|
85
85
|
* Release client-side resources owned by this Sandbox instance.
|
|
86
86
|
* Does NOT stop or delete the container - the sandbox keeps running.
|
|
@@ -16,6 +16,8 @@ export declare class DevboxApi {
|
|
|
16
16
|
info(name: string): Promise<DevboxApiResponse<DevboxInfoData>>;
|
|
17
17
|
/** POST /api/v1/devbox/{name}/pause */
|
|
18
18
|
pause(name: string): Promise<DevboxApiResponse<DevboxMutationData>>;
|
|
19
|
+
/** POST /api/v1/devbox/{name}/stop */
|
|
20
|
+
stop(name: string): Promise<DevboxApiResponse<DevboxMutationData>>;
|
|
19
21
|
/** POST /api/v1/devbox/{name}/resume */
|
|
20
22
|
resume(name: string): Promise<DevboxApiResponse<DevboxMutationData>>;
|
|
21
23
|
/** DELETE /api/v1/devbox/{name} */
|
|
@@ -41,10 +41,11 @@ export declare class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
41
41
|
create(): Promise<void>;
|
|
42
42
|
stop(): Promise<void>;
|
|
43
43
|
start(): Promise<void>;
|
|
44
|
-
delete(): Promise<void>;
|
|
44
|
+
delete(sandboxId?: SandboxId): Promise<void>;
|
|
45
45
|
execute(command: string, options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
46
46
|
getEndpoint(selector: SandboxEndpointSelector): Promise<Endpoint>;
|
|
47
47
|
getProxyTarget(service?: SandboxProxyService): Promise<SandboxProxyTarget>;
|
|
48
|
+
private waitForCodeServerHealthz;
|
|
48
49
|
private getHttpgateTarget;
|
|
49
50
|
private getGatewayUniqueID;
|
|
50
51
|
private getHttpgateDomain;
|
|
@@ -46,9 +46,10 @@ export interface ExecResponseData {
|
|
|
46
46
|
stderr: string;
|
|
47
47
|
executedAt: string;
|
|
48
48
|
}
|
|
49
|
-
/** Response data from create/pause/resume/delete endpoints. */
|
|
49
|
+
/** Response data from create/pause/stop/resume/delete endpoints. */
|
|
50
50
|
export interface DevboxMutationData {
|
|
51
51
|
name: string;
|
|
52
|
+
namespace?: string;
|
|
52
53
|
state?: string;
|
|
53
54
|
status?: string;
|
|
54
55
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -45667,6 +45667,11 @@ class DevboxApi {
|
|
|
45667
45667
|
method: "POST"
|
|
45668
45668
|
});
|
|
45669
45669
|
}
|
|
45670
|
+
async stop(name) {
|
|
45671
|
+
return this.request(this.url(`/api/v1/devbox/${name}/stop`), {
|
|
45672
|
+
method: "POST"
|
|
45673
|
+
});
|
|
45674
|
+
}
|
|
45670
45675
|
async resume(name) {
|
|
45671
45676
|
return this.request(this.url(`/api/v1/devbox/${name}/resume`), {
|
|
45672
45677
|
method: "POST"
|
|
@@ -45876,10 +45881,10 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45876
45881
|
async stop() {
|
|
45877
45882
|
try {
|
|
45878
45883
|
this._status = { state: "Stopping" };
|
|
45879
|
-
await this.api.
|
|
45884
|
+
await this.api.stop(this._id);
|
|
45880
45885
|
this._status = { state: "Stopped" };
|
|
45881
45886
|
} catch (error) {
|
|
45882
|
-
throw new CommandExecutionError("Failed to
|
|
45887
|
+
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
45883
45888
|
}
|
|
45884
45889
|
}
|
|
45885
45890
|
async start() {
|
|
@@ -45892,10 +45897,12 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45892
45897
|
throw new CommandExecutionError("Failed to resume sandbox", "resume", error instanceof Error ? error : undefined);
|
|
45893
45898
|
}
|
|
45894
45899
|
}
|
|
45895
|
-
async delete() {
|
|
45900
|
+
async delete(sandboxId) {
|
|
45896
45901
|
try {
|
|
45902
|
+
const targetId = sandboxId ?? this._id;
|
|
45897
45903
|
this._status = { state: "Deleting" };
|
|
45898
|
-
await this.api.delete(
|
|
45904
|
+
await this.api.delete(targetId);
|
|
45905
|
+
this._id = targetId;
|
|
45899
45906
|
await this.waitUntilDeleted();
|
|
45900
45907
|
this._status = { state: "UnExist" };
|
|
45901
45908
|
} catch (error) {
|
|
@@ -45924,6 +45931,9 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45924
45931
|
async getEndpoint(selector) {
|
|
45925
45932
|
const port = typeof selector === "number" ? selector : SEALOS_DEVBOX_CODE_SERVER_PORT;
|
|
45926
45933
|
const target = await this.getHttpgateTarget(port);
|
|
45934
|
+
if (selector === "code-server") {
|
|
45935
|
+
await this.waitForCodeServerHealthz(target);
|
|
45936
|
+
}
|
|
45927
45937
|
const url = new URL(target.origin);
|
|
45928
45938
|
return {
|
|
45929
45939
|
host: url.host,
|
|
@@ -45945,6 +45955,30 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45945
45955
|
...target.password ? { password: target.password } : {}
|
|
45946
45956
|
};
|
|
45947
45957
|
}
|
|
45958
|
+
async waitForCodeServerHealthz(target) {
|
|
45959
|
+
const healthUrl = joinUrlPath(joinUrlPath(target.origin, target.basePath), "/healthz");
|
|
45960
|
+
const timeoutMs = 60000;
|
|
45961
|
+
const intervalMs = 500;
|
|
45962
|
+
const requestTimeoutMs = 3000;
|
|
45963
|
+
const deadline = Date.now() + timeoutMs;
|
|
45964
|
+
let lastResult = "not checked";
|
|
45965
|
+
while (Date.now() < deadline) {
|
|
45966
|
+
try {
|
|
45967
|
+
const res = await fetch(healthUrl, {
|
|
45968
|
+
method: "GET",
|
|
45969
|
+
signal: AbortSignal.timeout(requestTimeoutMs)
|
|
45970
|
+
});
|
|
45971
|
+
if (res.status >= 200 && res.status < 400) {
|
|
45972
|
+
return;
|
|
45973
|
+
}
|
|
45974
|
+
lastResult = `status ${res.status}`;
|
|
45975
|
+
} catch (error) {
|
|
45976
|
+
lastResult = error instanceof Error ? error.message : String(error);
|
|
45977
|
+
}
|
|
45978
|
+
await this.sleep(intervalMs);
|
|
45979
|
+
}
|
|
45980
|
+
throw new ConnectionError(`Devbox code-server health check ${healthUrl} did not become ready within ${timeoutMs}ms. Last result: ${lastResult}`, this.config.baseUrl);
|
|
45981
|
+
}
|
|
45948
45982
|
async getHttpgateTarget(port) {
|
|
45949
45983
|
const res = await this.api.info(this._id);
|
|
45950
45984
|
if (res.code !== 200 || !res.data) {
|
|
@@ -48469,9 +48503,13 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48469
48503
|
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48470
48504
|
}
|
|
48471
48505
|
}
|
|
48472
|
-
async delete() {
|
|
48506
|
+
async delete(sandboxId) {
|
|
48473
48507
|
try {
|
|
48474
48508
|
this._status = { state: "Deleting" };
|
|
48509
|
+
if (sandboxId && (!this._sandbox || sandboxId !== this._id)) {
|
|
48510
|
+
await this.connect(sandboxId);
|
|
48511
|
+
this._status = { state: "Deleting" };
|
|
48512
|
+
}
|
|
48475
48513
|
await this.sandbox.kill();
|
|
48476
48514
|
this.sandbox = undefined;
|
|
48477
48515
|
this._status = { state: "UnExist" };
|
|
@@ -48840,7 +48878,11 @@ class E2BAdapter extends BaseSandboxAdapter {
|
|
|
48840
48878
|
throw new CommandExecutionError("Failed to pause E2B sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48841
48879
|
}
|
|
48842
48880
|
}
|
|
48843
|
-
async delete() {
|
|
48881
|
+
async delete(sandboxId) {
|
|
48882
|
+
if (sandboxId) {
|
|
48883
|
+
this._id = sandboxId;
|
|
48884
|
+
this.sandbox = null;
|
|
48885
|
+
}
|
|
48844
48886
|
const sandbox = await this.ensureSandbox();
|
|
48845
48887
|
try {
|
|
48846
48888
|
this._status = { state: "Deleting" };
|
package/dist/index.js
CHANGED
|
@@ -45651,6 +45651,11 @@ class DevboxApi {
|
|
|
45651
45651
|
method: "POST"
|
|
45652
45652
|
});
|
|
45653
45653
|
}
|
|
45654
|
+
async stop(name) {
|
|
45655
|
+
return this.request(this.url(`/api/v1/devbox/${name}/stop`), {
|
|
45656
|
+
method: "POST"
|
|
45657
|
+
});
|
|
45658
|
+
}
|
|
45654
45659
|
async resume(name) {
|
|
45655
45660
|
return this.request(this.url(`/api/v1/devbox/${name}/resume`), {
|
|
45656
45661
|
method: "POST"
|
|
@@ -45860,10 +45865,10 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45860
45865
|
async stop() {
|
|
45861
45866
|
try {
|
|
45862
45867
|
this._status = { state: "Stopping" };
|
|
45863
|
-
await this.api.
|
|
45868
|
+
await this.api.stop(this._id);
|
|
45864
45869
|
this._status = { state: "Stopped" };
|
|
45865
45870
|
} catch (error) {
|
|
45866
|
-
throw new CommandExecutionError("Failed to
|
|
45871
|
+
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
45867
45872
|
}
|
|
45868
45873
|
}
|
|
45869
45874
|
async start() {
|
|
@@ -45876,10 +45881,12 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45876
45881
|
throw new CommandExecutionError("Failed to resume sandbox", "resume", error instanceof Error ? error : undefined);
|
|
45877
45882
|
}
|
|
45878
45883
|
}
|
|
45879
|
-
async delete() {
|
|
45884
|
+
async delete(sandboxId) {
|
|
45880
45885
|
try {
|
|
45886
|
+
const targetId = sandboxId ?? this._id;
|
|
45881
45887
|
this._status = { state: "Deleting" };
|
|
45882
|
-
await this.api.delete(
|
|
45888
|
+
await this.api.delete(targetId);
|
|
45889
|
+
this._id = targetId;
|
|
45883
45890
|
await this.waitUntilDeleted();
|
|
45884
45891
|
this._status = { state: "UnExist" };
|
|
45885
45892
|
} catch (error) {
|
|
@@ -45908,6 +45915,9 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45908
45915
|
async getEndpoint(selector) {
|
|
45909
45916
|
const port = typeof selector === "number" ? selector : SEALOS_DEVBOX_CODE_SERVER_PORT;
|
|
45910
45917
|
const target = await this.getHttpgateTarget(port);
|
|
45918
|
+
if (selector === "code-server") {
|
|
45919
|
+
await this.waitForCodeServerHealthz(target);
|
|
45920
|
+
}
|
|
45911
45921
|
const url = new URL(target.origin);
|
|
45912
45922
|
return {
|
|
45913
45923
|
host: url.host,
|
|
@@ -45929,6 +45939,30 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45929
45939
|
...target.password ? { password: target.password } : {}
|
|
45930
45940
|
};
|
|
45931
45941
|
}
|
|
45942
|
+
async waitForCodeServerHealthz(target) {
|
|
45943
|
+
const healthUrl = joinUrlPath(joinUrlPath(target.origin, target.basePath), "/healthz");
|
|
45944
|
+
const timeoutMs = 60000;
|
|
45945
|
+
const intervalMs = 500;
|
|
45946
|
+
const requestTimeoutMs = 3000;
|
|
45947
|
+
const deadline = Date.now() + timeoutMs;
|
|
45948
|
+
let lastResult = "not checked";
|
|
45949
|
+
while (Date.now() < deadline) {
|
|
45950
|
+
try {
|
|
45951
|
+
const res = await fetch(healthUrl, {
|
|
45952
|
+
method: "GET",
|
|
45953
|
+
signal: AbortSignal.timeout(requestTimeoutMs)
|
|
45954
|
+
});
|
|
45955
|
+
if (res.status >= 200 && res.status < 400) {
|
|
45956
|
+
return;
|
|
45957
|
+
}
|
|
45958
|
+
lastResult = `status ${res.status}`;
|
|
45959
|
+
} catch (error) {
|
|
45960
|
+
lastResult = error instanceof Error ? error.message : String(error);
|
|
45961
|
+
}
|
|
45962
|
+
await this.sleep(intervalMs);
|
|
45963
|
+
}
|
|
45964
|
+
throw new ConnectionError(`Devbox code-server health check ${healthUrl} did not become ready within ${timeoutMs}ms. Last result: ${lastResult}`, this.config.baseUrl);
|
|
45965
|
+
}
|
|
45932
45966
|
async getHttpgateTarget(port) {
|
|
45933
45967
|
const res = await this.api.info(this._id);
|
|
45934
45968
|
if (res.code !== 200 || !res.data) {
|
|
@@ -48453,9 +48487,13 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48453
48487
|
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48454
48488
|
}
|
|
48455
48489
|
}
|
|
48456
|
-
async delete() {
|
|
48490
|
+
async delete(sandboxId) {
|
|
48457
48491
|
try {
|
|
48458
48492
|
this._status = { state: "Deleting" };
|
|
48493
|
+
if (sandboxId && (!this._sandbox || sandboxId !== this._id)) {
|
|
48494
|
+
await this.connect(sandboxId);
|
|
48495
|
+
this._status = { state: "Deleting" };
|
|
48496
|
+
}
|
|
48459
48497
|
await this.sandbox.kill();
|
|
48460
48498
|
this.sandbox = undefined;
|
|
48461
48499
|
this._status = { state: "UnExist" };
|
|
@@ -48824,7 +48862,11 @@ class E2BAdapter extends BaseSandboxAdapter {
|
|
|
48824
48862
|
throw new CommandExecutionError("Failed to pause E2B sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48825
48863
|
}
|
|
48826
48864
|
}
|
|
48827
|
-
async delete() {
|
|
48865
|
+
async delete(sandboxId) {
|
|
48866
|
+
if (sandboxId) {
|
|
48867
|
+
this._id = sandboxId;
|
|
48868
|
+
this.sandbox = null;
|
|
48869
|
+
}
|
|
48828
48870
|
const sandbox = await this.ensureSandbox();
|
|
48829
48871
|
try {
|
|
48830
48872
|
this._status = { state: "Deleting" };
|
|
@@ -27,8 +27,12 @@ export interface ISandboxLifecycle {
|
|
|
27
27
|
stop(): Promise<void>;
|
|
28
28
|
/**
|
|
29
29
|
* Delete the sandbox permanently.
|
|
30
|
+
*
|
|
31
|
+
* When `sandboxId` is provided, implementations should delete that provider
|
|
32
|
+
* sandbox directly without requiring callers to first bind the adapter via
|
|
33
|
+
* `connect()`.
|
|
30
34
|
*/
|
|
31
|
-
delete(): Promise<void>;
|
|
35
|
+
delete(sandboxId?: SandboxId): Promise<void>;
|
|
32
36
|
/**
|
|
33
37
|
* Get detailed information about the sandbox.
|
|
34
38
|
*/
|
package/package.json
CHANGED