@fastgpt-sdk/sandbox-adapter 0.0.17 → 0.0.19
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,12 @@ export interface OpenSandboxConnectionConfig {
|
|
|
16
16
|
baseUrl?: string;
|
|
17
17
|
/** API key for authentication */
|
|
18
18
|
apiKey?: string;
|
|
19
|
+
/** SDK request timeout in seconds */
|
|
20
|
+
requestTimeoutSeconds?: number;
|
|
21
|
+
/** Enable SDK HTTP debug logging */
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
/** Route execd traffic through the OpenSandbox server proxy */
|
|
24
|
+
useServerProxy?: boolean;
|
|
19
25
|
/**
|
|
20
26
|
* Sandbox runtime type.
|
|
21
27
|
* @default 'docker'
|
|
@@ -60,6 +66,7 @@ export declare class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
60
66
|
private parseImageSpec;
|
|
61
67
|
private convertResourceLimits;
|
|
62
68
|
private parseResourceLimits;
|
|
69
|
+
private extractExitCode;
|
|
63
70
|
ensureRunning(): Promise<void>;
|
|
64
71
|
create(): Promise<void>;
|
|
65
72
|
connect(sandboxId: string): Promise<void>;
|
|
@@ -19,4 +19,10 @@ export interface OpenSandboxConfigType {
|
|
|
19
19
|
networkPolicy?: NetworkPolicy;
|
|
20
20
|
/** Provider-specific extensions */
|
|
21
21
|
extensions?: Record<string, unknown>;
|
|
22
|
+
/** Skip readiness checks after create/connect */
|
|
23
|
+
skipHealthCheck?: boolean;
|
|
24
|
+
/** Max seconds to wait for sandbox readiness */
|
|
25
|
+
readyTimeoutSeconds?: number;
|
|
26
|
+
/** Poll interval for readiness checks in milliseconds */
|
|
27
|
+
healthCheckPollingInterval?: number;
|
|
22
28
|
}
|
package/dist/index.js
CHANGED
|
@@ -794,7 +794,6 @@ class SealosDevboxAdapter extends BaseSandboxAdapter {
|
|
|
794
794
|
async ensureRunning() {
|
|
795
795
|
try {
|
|
796
796
|
const sandbox = await this.getInfo();
|
|
797
|
-
console.log(sandbox, 2323232);
|
|
798
797
|
if (sandbox) {
|
|
799
798
|
const status = sandbox.status.state;
|
|
800
799
|
switch (status) {
|
|
@@ -923,13 +922,16 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
923
922
|
return this._sandbox;
|
|
924
923
|
}
|
|
925
924
|
createConnectionConfig() {
|
|
926
|
-
const { baseUrl, apiKey } = this.connectionConfig;
|
|
925
|
+
const { baseUrl, apiKey, requestTimeoutSeconds, debug, useServerProxy } = this.connectionConfig;
|
|
927
926
|
if (!baseUrl) {
|
|
928
|
-
return new ConnectionConfig({ apiKey });
|
|
927
|
+
return new ConnectionConfig({ apiKey, requestTimeoutSeconds, debug, useServerProxy });
|
|
929
928
|
}
|
|
930
929
|
return new ConnectionConfig({
|
|
931
930
|
domain: baseUrl,
|
|
932
|
-
apiKey
|
|
931
|
+
apiKey,
|
|
932
|
+
requestTimeoutSeconds,
|
|
933
|
+
debug,
|
|
934
|
+
useServerProxy
|
|
933
935
|
});
|
|
934
936
|
}
|
|
935
937
|
static STATE_MAP = {
|
|
@@ -1014,6 +1016,26 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
1014
1016
|
}
|
|
1015
1017
|
return result;
|
|
1016
1018
|
}
|
|
1019
|
+
extractExitCode(execution) {
|
|
1020
|
+
const rawValue = execution.error?.value?.trim();
|
|
1021
|
+
if (rawValue) {
|
|
1022
|
+
const parsed = Number.parseInt(rawValue, 10);
|
|
1023
|
+
if (!Number.isNaN(parsed)) {
|
|
1024
|
+
return parsed;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
const traceback = execution.error?.traceback ?? [];
|
|
1028
|
+
for (const line of traceback) {
|
|
1029
|
+
const match = line.match(/exit status (\d+)/i);
|
|
1030
|
+
if (match?.[1]) {
|
|
1031
|
+
const parsed = Number.parseInt(match[1], 10);
|
|
1032
|
+
if (!Number.isNaN(parsed)) {
|
|
1033
|
+
return parsed;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return 0;
|
|
1038
|
+
}
|
|
1017
1039
|
async ensureRunning() {
|
|
1018
1040
|
return this.create();
|
|
1019
1041
|
}
|
|
@@ -1033,7 +1055,10 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
1033
1055
|
timeoutSeconds: cfg.timeout,
|
|
1034
1056
|
resource,
|
|
1035
1057
|
env: cfg.env,
|
|
1036
|
-
metadata: cfg.metadata
|
|
1058
|
+
metadata: cfg.metadata,
|
|
1059
|
+
skipHealthCheck: cfg.skipHealthCheck,
|
|
1060
|
+
readyTimeoutSeconds: cfg.readyTimeoutSeconds,
|
|
1061
|
+
healthCheckPollingInterval: cfg.healthCheckPollingInterval
|
|
1037
1062
|
});
|
|
1038
1063
|
this._id = this._sandbox.id;
|
|
1039
1064
|
this._status = { state: "Running" };
|
|
@@ -1047,7 +1072,10 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
1047
1072
|
this._status = { state: "Starting" };
|
|
1048
1073
|
this._sandbox = await Sandbox.connect({
|
|
1049
1074
|
sandboxId,
|
|
1050
|
-
connectionConfig: this._connection
|
|
1075
|
+
connectionConfig: this._connection,
|
|
1076
|
+
skipHealthCheck: this.createConfig?.skipHealthCheck,
|
|
1077
|
+
readyTimeoutSeconds: this.createConfig?.readyTimeoutSeconds,
|
|
1078
|
+
healthCheckPollingInterval: this.createConfig?.healthCheckPollingInterval
|
|
1051
1079
|
});
|
|
1052
1080
|
this._id = this._sandbox.id;
|
|
1053
1081
|
this._status = { state: "Running" };
|
|
@@ -1072,9 +1100,12 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
1072
1100
|
async stop() {
|
|
1073
1101
|
try {
|
|
1074
1102
|
this._status = { state: "Stopping" };
|
|
1075
|
-
await this.sandbox.
|
|
1103
|
+
await this.sandbox.pause();
|
|
1076
1104
|
this._status = { state: "Stopped" };
|
|
1077
1105
|
} catch (error) {
|
|
1106
|
+
if (error && typeof error === "object" && "code" in error && error.code === "SANDBOX::API_NOT_SUPPORTED") {
|
|
1107
|
+
throw new FeatureNotSupportedError("Stop/pause not supported by this runtime", "stop", this.provider);
|
|
1108
|
+
}
|
|
1078
1109
|
throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
|
|
1079
1110
|
}
|
|
1080
1111
|
}
|
|
@@ -1152,7 +1183,7 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
1152
1183
|
`);
|
|
1153
1184
|
const stderr = execution.logs.stderr.map((msg) => msg.text).join(`
|
|
1154
1185
|
`);
|
|
1155
|
-
const exitCode =
|
|
1186
|
+
const exitCode = this.extractExitCode(execution);
|
|
1156
1187
|
const stdoutLength = execution.logs.stdout.reduce((sum, msg) => sum + msg.text.length, 0);
|
|
1157
1188
|
const stderrLength = execution.logs.stderr.reduce((sum, msg) => sum + msg.text.length, 0);
|
|
1158
1189
|
const MaxOutputSize = 1024 * 1024;
|
|
@@ -1190,7 +1221,7 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
|
|
|
1190
1221
|
`);
|
|
1191
1222
|
const stderr = execution.logs.stderr.map((msg) => msg.text).join(`
|
|
1192
1223
|
`);
|
|
1193
|
-
const exitCode =
|
|
1224
|
+
const exitCode = this.extractExitCode(execution);
|
|
1194
1225
|
const stdoutLength = execution.logs.stdout.reduce((sum, msg) => sum + msg.text.length, 0);
|
|
1195
1226
|
const stderrLength = execution.logs.stderr.reduce((sum, msg) => sum + msg.text.length, 0);
|
|
1196
1227
|
const MaxOutputSize = 1024 * 1024;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastgpt-sdk/sandbox-adapter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "Unified abstraction layer for cloud sandbox providers with adapter pattern and feature polyfilling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,20 +22,6 @@
|
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=18"
|
|
24
24
|
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "bun run build.ts",
|
|
27
|
-
"dev": "tsc -p tsconfig.build.json --watch",
|
|
28
|
-
"prepublishOnly": "bun run build",
|
|
29
|
-
"lint": "eslint .",
|
|
30
|
-
"lint:fix": "eslint . --fix",
|
|
31
|
-
"format": "prettier . --write",
|
|
32
|
-
"format:check": "prettier . --check",
|
|
33
|
-
"lint-staged": "lint-staged",
|
|
34
|
-
"prepare": "husky",
|
|
35
|
-
"test": "vitest run --config ./vitest.config.mts",
|
|
36
|
-
"test:watch": "vitest watch",
|
|
37
|
-
"test:coverage": "vitest run --coverage"
|
|
38
|
-
},
|
|
39
25
|
"keywords": [
|
|
40
26
|
"sandbox",
|
|
41
27
|
"cloud",
|
|
@@ -47,7 +33,7 @@
|
|
|
47
33
|
"author": "",
|
|
48
34
|
"license": "MIT",
|
|
49
35
|
"dependencies": {
|
|
50
|
-
"@alibaba-group/opensandbox": "^0.1.
|
|
36
|
+
"@alibaba-group/opensandbox": "^0.1.4"
|
|
51
37
|
},
|
|
52
38
|
"devDependencies": {
|
|
53
39
|
"@eslint/js": "^9.39.2",
|
|
@@ -72,5 +58,17 @@
|
|
|
72
58
|
"*.{js,cjs,mjs,ts,tsx}": [
|
|
73
59
|
"eslint --max-warnings=0"
|
|
74
60
|
]
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "bun run build.ts",
|
|
64
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
65
|
+
"lint": "eslint .",
|
|
66
|
+
"lint:fix": "eslint . --fix",
|
|
67
|
+
"format": "prettier . --write",
|
|
68
|
+
"format:check": "prettier . --check",
|
|
69
|
+
"lint-staged": "lint-staged",
|
|
70
|
+
"test": "vitest run --config ./vitest.config.mts",
|
|
71
|
+
"test:watch": "vitest watch",
|
|
72
|
+
"test:coverage": "vitest run --coverage"
|
|
75
73
|
}
|
|
76
|
-
}
|
|
74
|
+
}
|