@fastgpt-sdk/sandbox-adapter 0.0.38 → 0.0.40-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 +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 +1 -1
- package/dist/adapters/SealosDevboxAdapter/type.d.ts +2 -1
- package/dist/index.cjs +48 -9
- package/dist/index.js +48 -9
- 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,7 +41,7 @@ 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>;
|
|
@@ -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
|
@@ -17393,7 +17393,7 @@ var require_fetch = __commonJS((exports2, module2) => {
|
|
|
17393
17393
|
request.cache = "no-store";
|
|
17394
17394
|
}
|
|
17395
17395
|
const newConnection = forceNewConnection ? "yes" : "no";
|
|
17396
|
-
if (request.mode === "websocket") {}
|
|
17396
|
+
if (request.mode === "websocket") {}
|
|
17397
17397
|
let requestBody = null;
|
|
17398
17398
|
if (request.body == null && fetchParams.processRequestEndOfBody) {
|
|
17399
17399
|
queueMicrotask(() => fetchParams.processRequestEndOfBody());
|
|
@@ -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"
|
|
@@ -45783,8 +45788,12 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45783
45788
|
case "Pending" /* Pending */:
|
|
45784
45789
|
return "Creating";
|
|
45785
45790
|
case "Paused" /* Paused */:
|
|
45791
|
+
case "Stopped" /* Stopped */:
|
|
45792
|
+
case "Shutdown" /* Shutdown */:
|
|
45786
45793
|
return "Stopped";
|
|
45787
45794
|
case "Pausing" /* Pausing */:
|
|
45795
|
+
case "Stopping" /* Stopping */:
|
|
45796
|
+
case "Shutting" /* Shutting */:
|
|
45788
45797
|
return "Stopping";
|
|
45789
45798
|
default:
|
|
45790
45799
|
return "Error";
|
|
@@ -45818,7 +45827,11 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45818
45827
|
if (!res.data)
|
|
45819
45828
|
return Promise.reject(res.message);
|
|
45820
45829
|
const data = res.data;
|
|
45821
|
-
this._status = {
|
|
45830
|
+
this._status = {
|
|
45831
|
+
state: this.StatusAdapt(data),
|
|
45832
|
+
reason: data.state.phase,
|
|
45833
|
+
message: res.message
|
|
45834
|
+
};
|
|
45822
45835
|
return {
|
|
45823
45836
|
id: data.name,
|
|
45824
45837
|
image: parseImageSpec(data.image),
|
|
@@ -45850,12 +45863,17 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45850
45863
|
await this.waitUntilDeleted();
|
|
45851
45864
|
await this.create();
|
|
45852
45865
|
return;
|
|
45866
|
+
case "Error":
|
|
45867
|
+
throw new ConnectionError(`Sandbox ${sandbox.id} is in error state: ${sandbox.status.reason ?? sandbox.status.message ?? "unknown"}`, this.config.baseUrl);
|
|
45853
45868
|
default:
|
|
45854
|
-
throw new ConnectionError(`
|
|
45869
|
+
throw new ConnectionError(`Sandbox state ${status} not supported`, this.config.baseUrl);
|
|
45855
45870
|
}
|
|
45856
45871
|
}
|
|
45857
45872
|
await this.create();
|
|
45858
45873
|
} catch (error) {
|
|
45874
|
+
if (error instanceof ConnectionError) {
|
|
45875
|
+
throw error;
|
|
45876
|
+
}
|
|
45859
45877
|
throw new ConnectionError(`Failed to ensure sandbox running`, this.config.baseUrl, error);
|
|
45860
45878
|
}
|
|
45861
45879
|
}
|
|
@@ -45876,10 +45894,10 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45876
45894
|
async stop() {
|
|
45877
45895
|
try {
|
|
45878
45896
|
this._status = { state: "Stopping" };
|
|
45879
|
-
await this.api.
|
|
45897
|
+
await this.api.stop(this._id);
|
|
45880
45898
|
this._status = { state: "Stopped" };
|
|
45881
45899
|
} catch (error) {
|
|
45882
|
-
throw new CommandExecutionError("Failed to
|
|
45900
|
+
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
45883
45901
|
}
|
|
45884
45902
|
}
|
|
45885
45903
|
async start() {
|
|
@@ -45892,10 +45910,12 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45892
45910
|
throw new CommandExecutionError("Failed to resume sandbox", "resume", error instanceof Error ? error : undefined);
|
|
45893
45911
|
}
|
|
45894
45912
|
}
|
|
45895
|
-
async delete() {
|
|
45913
|
+
async delete(sandboxId) {
|
|
45896
45914
|
try {
|
|
45915
|
+
const targetId = sandboxId ?? this._id;
|
|
45897
45916
|
this._status = { state: "Deleting" };
|
|
45898
|
-
await this.api.delete(
|
|
45917
|
+
await this.api.delete(targetId);
|
|
45918
|
+
this._id = targetId;
|
|
45899
45919
|
await this.waitUntilDeleted();
|
|
45900
45920
|
this._status = { state: "UnExist" };
|
|
45901
45921
|
} catch (error) {
|
|
@@ -48496,9 +48516,24 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48496
48516
|
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48497
48517
|
}
|
|
48498
48518
|
}
|
|
48499
|
-
async delete() {
|
|
48519
|
+
async delete(sandboxId) {
|
|
48500
48520
|
try {
|
|
48501
48521
|
this._status = { state: "Deleting" };
|
|
48522
|
+
if (sandboxId) {
|
|
48523
|
+
const manager = SandboxManager.create({ connectionConfig: this._connection });
|
|
48524
|
+
try {
|
|
48525
|
+
await manager.killSandbox(sandboxId);
|
|
48526
|
+
} finally {
|
|
48527
|
+
await manager.close().catch(() => {
|
|
48528
|
+
return;
|
|
48529
|
+
});
|
|
48530
|
+
}
|
|
48531
|
+
if (sandboxId === this._id) {
|
|
48532
|
+
this.sandbox = undefined;
|
|
48533
|
+
}
|
|
48534
|
+
this._status = { state: "UnExist" };
|
|
48535
|
+
return;
|
|
48536
|
+
}
|
|
48502
48537
|
await this.sandbox.kill();
|
|
48503
48538
|
this.sandbox = undefined;
|
|
48504
48539
|
this._status = { state: "UnExist" };
|
|
@@ -48867,7 +48902,11 @@ class E2BAdapter extends BaseSandboxAdapter {
|
|
|
48867
48902
|
throw new CommandExecutionError("Failed to pause E2B sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48868
48903
|
}
|
|
48869
48904
|
}
|
|
48870
|
-
async delete() {
|
|
48905
|
+
async delete(sandboxId) {
|
|
48906
|
+
if (sandboxId) {
|
|
48907
|
+
this._id = sandboxId;
|
|
48908
|
+
this.sandbox = null;
|
|
48909
|
+
}
|
|
48871
48910
|
const sandbox = await this.ensureSandbox();
|
|
48872
48911
|
try {
|
|
48873
48912
|
this._status = { state: "Deleting" };
|
package/dist/index.js
CHANGED
|
@@ -17395,7 +17395,7 @@ var require_fetch = __commonJS((exports, module) => {
|
|
|
17395
17395
|
request.cache = "no-store";
|
|
17396
17396
|
}
|
|
17397
17397
|
const newConnection = forceNewConnection ? "yes" : "no";
|
|
17398
|
-
if (request.mode === "websocket") {}
|
|
17398
|
+
if (request.mode === "websocket") {}
|
|
17399
17399
|
let requestBody = null;
|
|
17400
17400
|
if (request.body == null && fetchParams.processRequestEndOfBody) {
|
|
17401
17401
|
queueMicrotask(() => fetchParams.processRequestEndOfBody());
|
|
@@ -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"
|
|
@@ -45767,8 +45772,12 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45767
45772
|
case "Pending" /* Pending */:
|
|
45768
45773
|
return "Creating";
|
|
45769
45774
|
case "Paused" /* Paused */:
|
|
45775
|
+
case "Stopped" /* Stopped */:
|
|
45776
|
+
case "Shutdown" /* Shutdown */:
|
|
45770
45777
|
return "Stopped";
|
|
45771
45778
|
case "Pausing" /* Pausing */:
|
|
45779
|
+
case "Stopping" /* Stopping */:
|
|
45780
|
+
case "Shutting" /* Shutting */:
|
|
45772
45781
|
return "Stopping";
|
|
45773
45782
|
default:
|
|
45774
45783
|
return "Error";
|
|
@@ -45802,7 +45811,11 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45802
45811
|
if (!res.data)
|
|
45803
45812
|
return Promise.reject(res.message);
|
|
45804
45813
|
const data = res.data;
|
|
45805
|
-
this._status = {
|
|
45814
|
+
this._status = {
|
|
45815
|
+
state: this.StatusAdapt(data),
|
|
45816
|
+
reason: data.state.phase,
|
|
45817
|
+
message: res.message
|
|
45818
|
+
};
|
|
45806
45819
|
return {
|
|
45807
45820
|
id: data.name,
|
|
45808
45821
|
image: parseImageSpec(data.image),
|
|
@@ -45834,12 +45847,17 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45834
45847
|
await this.waitUntilDeleted();
|
|
45835
45848
|
await this.create();
|
|
45836
45849
|
return;
|
|
45850
|
+
case "Error":
|
|
45851
|
+
throw new ConnectionError(`Sandbox ${sandbox.id} is in error state: ${sandbox.status.reason ?? sandbox.status.message ?? "unknown"}`, this.config.baseUrl);
|
|
45837
45852
|
default:
|
|
45838
|
-
throw new ConnectionError(`
|
|
45853
|
+
throw new ConnectionError(`Sandbox state ${status} not supported`, this.config.baseUrl);
|
|
45839
45854
|
}
|
|
45840
45855
|
}
|
|
45841
45856
|
await this.create();
|
|
45842
45857
|
} catch (error) {
|
|
45858
|
+
if (error instanceof ConnectionError) {
|
|
45859
|
+
throw error;
|
|
45860
|
+
}
|
|
45843
45861
|
throw new ConnectionError(`Failed to ensure sandbox running`, this.config.baseUrl, error);
|
|
45844
45862
|
}
|
|
45845
45863
|
}
|
|
@@ -45860,10 +45878,10 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45860
45878
|
async stop() {
|
|
45861
45879
|
try {
|
|
45862
45880
|
this._status = { state: "Stopping" };
|
|
45863
|
-
await this.api.
|
|
45881
|
+
await this.api.stop(this._id);
|
|
45864
45882
|
this._status = { state: "Stopped" };
|
|
45865
45883
|
} catch (error) {
|
|
45866
|
-
throw new CommandExecutionError("Failed to
|
|
45884
|
+
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
45867
45885
|
}
|
|
45868
45886
|
}
|
|
45869
45887
|
async start() {
|
|
@@ -45876,10 +45894,12 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45876
45894
|
throw new CommandExecutionError("Failed to resume sandbox", "resume", error instanceof Error ? error : undefined);
|
|
45877
45895
|
}
|
|
45878
45896
|
}
|
|
45879
|
-
async delete() {
|
|
45897
|
+
async delete(sandboxId) {
|
|
45880
45898
|
try {
|
|
45899
|
+
const targetId = sandboxId ?? this._id;
|
|
45881
45900
|
this._status = { state: "Deleting" };
|
|
45882
|
-
await this.api.delete(
|
|
45901
|
+
await this.api.delete(targetId);
|
|
45902
|
+
this._id = targetId;
|
|
45883
45903
|
await this.waitUntilDeleted();
|
|
45884
45904
|
this._status = { state: "UnExist" };
|
|
45885
45905
|
} catch (error) {
|
|
@@ -48480,9 +48500,24 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
48480
48500
|
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48481
48501
|
}
|
|
48482
48502
|
}
|
|
48483
|
-
async delete() {
|
|
48503
|
+
async delete(sandboxId) {
|
|
48484
48504
|
try {
|
|
48485
48505
|
this._status = { state: "Deleting" };
|
|
48506
|
+
if (sandboxId) {
|
|
48507
|
+
const manager = SandboxManager.create({ connectionConfig: this._connection });
|
|
48508
|
+
try {
|
|
48509
|
+
await manager.killSandbox(sandboxId);
|
|
48510
|
+
} finally {
|
|
48511
|
+
await manager.close().catch(() => {
|
|
48512
|
+
return;
|
|
48513
|
+
});
|
|
48514
|
+
}
|
|
48515
|
+
if (sandboxId === this._id) {
|
|
48516
|
+
this.sandbox = undefined;
|
|
48517
|
+
}
|
|
48518
|
+
this._status = { state: "UnExist" };
|
|
48519
|
+
return;
|
|
48520
|
+
}
|
|
48486
48521
|
await this.sandbox.kill();
|
|
48487
48522
|
this.sandbox = undefined;
|
|
48488
48523
|
this._status = { state: "UnExist" };
|
|
@@ -48851,7 +48886,11 @@ class E2BAdapter extends BaseSandboxAdapter {
|
|
|
48851
48886
|
throw new CommandExecutionError("Failed to pause E2B sandbox", "stop", error instanceof Error ? error : undefined);
|
|
48852
48887
|
}
|
|
48853
48888
|
}
|
|
48854
|
-
async delete() {
|
|
48889
|
+
async delete(sandboxId) {
|
|
48890
|
+
if (sandboxId) {
|
|
48891
|
+
this._id = sandboxId;
|
|
48892
|
+
this.sandbox = null;
|
|
48893
|
+
}
|
|
48855
48894
|
const sandbox = await this.ensureSandbox();
|
|
48856
48895
|
try {
|
|
48857
48896
|
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