@fastgpt-sdk/sandbox-adapter 0.0.18 → 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
@@ -922,13 +922,16 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
922
922
  return this._sandbox;
923
923
  }
924
924
  createConnectionConfig() {
925
- const { baseUrl, apiKey } = this.connectionConfig;
925
+ const { baseUrl, apiKey, requestTimeoutSeconds, debug, useServerProxy } = this.connectionConfig;
926
926
  if (!baseUrl) {
927
- return new ConnectionConfig({ apiKey });
927
+ return new ConnectionConfig({ apiKey, requestTimeoutSeconds, debug, useServerProxy });
928
928
  }
929
929
  return new ConnectionConfig({
930
930
  domain: baseUrl,
931
- apiKey
931
+ apiKey,
932
+ requestTimeoutSeconds,
933
+ debug,
934
+ useServerProxy
932
935
  });
933
936
  }
934
937
  static STATE_MAP = {
@@ -1013,6 +1016,26 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
1013
1016
  }
1014
1017
  return result;
1015
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
+ }
1016
1039
  async ensureRunning() {
1017
1040
  return this.create();
1018
1041
  }
@@ -1032,7 +1055,10 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
1032
1055
  timeoutSeconds: cfg.timeout,
1033
1056
  resource,
1034
1057
  env: cfg.env,
1035
- metadata: cfg.metadata
1058
+ metadata: cfg.metadata,
1059
+ skipHealthCheck: cfg.skipHealthCheck,
1060
+ readyTimeoutSeconds: cfg.readyTimeoutSeconds,
1061
+ healthCheckPollingInterval: cfg.healthCheckPollingInterval
1036
1062
  });
1037
1063
  this._id = this._sandbox.id;
1038
1064
  this._status = { state: "Running" };
@@ -1046,7 +1072,10 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
1046
1072
  this._status = { state: "Starting" };
1047
1073
  this._sandbox = await Sandbox.connect({
1048
1074
  sandboxId,
1049
- connectionConfig: this._connection
1075
+ connectionConfig: this._connection,
1076
+ skipHealthCheck: this.createConfig?.skipHealthCheck,
1077
+ readyTimeoutSeconds: this.createConfig?.readyTimeoutSeconds,
1078
+ healthCheckPollingInterval: this.createConfig?.healthCheckPollingInterval
1050
1079
  });
1051
1080
  this._id = this._sandbox.id;
1052
1081
  this._status = { state: "Running" };
@@ -1071,9 +1100,12 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
1071
1100
  async stop() {
1072
1101
  try {
1073
1102
  this._status = { state: "Stopping" };
1074
- await this.sandbox.kill();
1103
+ await this.sandbox.pause();
1075
1104
  this._status = { state: "Stopped" };
1076
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
+ }
1077
1109
  throw new CommandExecutionError("Failed to stop sandbox", "stop", error instanceof Error ? error : undefined);
1078
1110
  }
1079
1111
  }
@@ -1151,7 +1183,7 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
1151
1183
  `);
1152
1184
  const stderr = execution.logs.stderr.map((msg) => msg.text).join(`
1153
1185
  `);
1154
- const exitCode = 0;
1186
+ const exitCode = this.extractExitCode(execution);
1155
1187
  const stdoutLength = execution.logs.stdout.reduce((sum, msg) => sum + msg.text.length, 0);
1156
1188
  const stderrLength = execution.logs.stderr.reduce((sum, msg) => sum + msg.text.length, 0);
1157
1189
  const MaxOutputSize = 1024 * 1024;
@@ -1189,7 +1221,7 @@ class OpenSandboxAdapter extends BaseSandboxAdapter {
1189
1221
  `);
1190
1222
  const stderr = execution.logs.stderr.map((msg) => msg.text).join(`
1191
1223
  `);
1192
- const exitCode = 0;
1224
+ const exitCode = this.extractExitCode(execution);
1193
1225
  const stdoutLength = execution.logs.stdout.reduce((sum, msg) => sum + msg.text.length, 0);
1194
1226
  const stderrLength = execution.logs.stderr.reduce((sum, msg) => sum + msg.text.length, 0);
1195
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.18",
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.3"
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
+ }