@fastgpt-sdk/sandbox-adapter 0.0.37 → 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.
|
@@ -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} */
|
|
@@ -45,6 +45,7 @@ export declare class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
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() {
|
|
@@ -45924,6 +45929,9 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45924
45929
|
async getEndpoint(selector) {
|
|
45925
45930
|
const port = typeof selector === "number" ? selector : SEALOS_DEVBOX_CODE_SERVER_PORT;
|
|
45926
45931
|
const target = await this.getHttpgateTarget(port);
|
|
45932
|
+
if (selector === "code-server") {
|
|
45933
|
+
await this.waitForCodeServerHealthz(target);
|
|
45934
|
+
}
|
|
45927
45935
|
const url = new URL(target.origin);
|
|
45928
45936
|
return {
|
|
45929
45937
|
host: url.host,
|
|
@@ -45945,6 +45953,30 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45945
45953
|
...target.password ? { password: target.password } : {}
|
|
45946
45954
|
};
|
|
45947
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
|
+
}
|
|
45948
45980
|
async getHttpgateTarget(port) {
|
|
45949
45981
|
const res = await this.api.info(this._id);
|
|
45950
45982
|
if (res.code !== 200 || !res.data) {
|
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() {
|
|
@@ -45908,6 +45913,9 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45908
45913
|
async getEndpoint(selector) {
|
|
45909
45914
|
const port = typeof selector === "number" ? selector : SEALOS_DEVBOX_CODE_SERVER_PORT;
|
|
45910
45915
|
const target = await this.getHttpgateTarget(port);
|
|
45916
|
+
if (selector === "code-server") {
|
|
45917
|
+
await this.waitForCodeServerHealthz(target);
|
|
45918
|
+
}
|
|
45911
45919
|
const url = new URL(target.origin);
|
|
45912
45920
|
return {
|
|
45913
45921
|
host: url.host,
|
|
@@ -45929,6 +45937,30 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
45929
45937
|
...target.password ? { password: target.password } : {}
|
|
45930
45938
|
};
|
|
45931
45939
|
}
|
|
45940
|
+
async waitForCodeServerHealthz(target) {
|
|
45941
|
+
const healthUrl = joinUrlPath(joinUrlPath(target.origin, target.basePath), "/healthz");
|
|
45942
|
+
const timeoutMs = 60000;
|
|
45943
|
+
const intervalMs = 500;
|
|
45944
|
+
const requestTimeoutMs = 3000;
|
|
45945
|
+
const deadline = Date.now() + timeoutMs;
|
|
45946
|
+
let lastResult = "not checked";
|
|
45947
|
+
while (Date.now() < deadline) {
|
|
45948
|
+
try {
|
|
45949
|
+
const res = await fetch(healthUrl, {
|
|
45950
|
+
method: "GET",
|
|
45951
|
+
signal: AbortSignal.timeout(requestTimeoutMs)
|
|
45952
|
+
});
|
|
45953
|
+
if (res.status >= 200 && res.status < 400) {
|
|
45954
|
+
return;
|
|
45955
|
+
}
|
|
45956
|
+
lastResult = `status ${res.status}`;
|
|
45957
|
+
} catch (error) {
|
|
45958
|
+
lastResult = error instanceof Error ? error.message : String(error);
|
|
45959
|
+
}
|
|
45960
|
+
await this.sleep(intervalMs);
|
|
45961
|
+
}
|
|
45962
|
+
throw new ConnectionError(`Devbox code-server health check ${healthUrl} did not become ready within ${timeoutMs}ms. Last result: ${lastResult}`, this.config.baseUrl);
|
|
45963
|
+
}
|
|
45932
45964
|
async getHttpgateTarget(port) {
|
|
45933
45965
|
const res = await this.api.info(this._id);
|
|
45934
45966
|
if (res.code !== 200 || !res.data) {
|
package/package.json
CHANGED