@fastgpt-sdk/sandbox-adapter 0.0.20 → 0.0.22

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/README.md CHANGED
@@ -10,6 +10,24 @@ A unified, high-level abstraction layer for cloud sandbox providers. It offers a
10
10
  pnpm add @fastgpt/sandbox
11
11
  ```
12
12
 
13
+ ## Next.js 集成
14
+
15
+ 如果在 Next.js 项目中使用,需要配置以处理 ESM 依赖。在 `next.config.js` 中添加:
16
+
17
+ ```javascript
18
+ /** @type {import('next').NextConfig} */
19
+ const nextConfig = {
20
+ transpilePackages: ['@fastgpt-sdk/sandbox-adapter'],
21
+ experimental: {
22
+ esmExternals: 'loose',
23
+ },
24
+ };
25
+
26
+ module.exports = nextConfig;
27
+ ```
28
+
29
+ 详细说明请参考 [Next.js 集成指南](./docs/NEXTJS_INTEGRATION.md)。
30
+
13
31
  ## 用途
14
32
 
15
33
  ### 1. 操作沙盒
@@ -1,20 +1,26 @@
1
1
  import { BaseSandboxAdapter } from '../BaseSandboxAdapter';
2
2
  import type { ExecuteOptions, ExecuteResult, SandboxId, SandboxInfo, FileWriteEntry, FileWriteResult, FileDeleteResult, FileReadResult, MoveEntry, DirectoryEntry } from '@/types';
3
- import type { E2BConfig, E2BCreateConfig } from './type';
3
+ import type { E2BConfig } from './type';
4
4
  /**
5
5
  * E2B 沙盒适配器 - 使用官方 SDK
6
+ *
7
+ * 使用 metadata 映射上游 sandboxId 到 E2B 实际 ID
6
8
  */
7
9
  export declare class E2BAdapter extends BaseSandboxAdapter {
8
10
  private config;
9
11
  readonly provider: "e2b";
10
12
  private sandbox;
11
13
  private _id;
12
- private createConfig?;
13
- constructor(config: E2BConfig, createConfig?: E2BCreateConfig);
14
+ constructor(config: E2BConfig);
14
15
  get id(): SandboxId;
16
+ /**
17
+ * 通过 metadata 查找 E2B 沙盒实例
18
+ * @returns E2B Sandbox 实例,如果未找到则返回 null
19
+ */
20
+ private findSandbox;
21
+ private ensureSandbox;
15
22
  ensureRunning(): Promise<void>;
16
23
  create(): Promise<void>;
17
- connect(): Promise<void>;
18
24
  start(): Promise<void>;
19
25
  stop(): Promise<void>;
20
26
  delete(): Promise<void>;
@@ -29,4 +35,4 @@ export declare class E2BAdapter extends BaseSandboxAdapter {
29
35
  listDirectory(path: string): Promise<DirectoryEntry[]>;
30
36
  ping(): Promise<boolean>;
31
37
  }
32
- export type { E2BConfig, E2BCreateConfig } from './type';
38
+ export type { E2BConfig } from './type';
@@ -5,7 +5,7 @@ export interface E2BConfig {
5
5
  /** E2B API Key */
6
6
  apiKey: string;
7
7
  /** 可选的沙盒 ID,用于连接到已存在的沙盒 */
8
- sandboxId?: string;
8
+ sandboxId: string;
9
9
  /** 可选的模板 ID,用于创建新沙盒 */
10
10
  template?: string;
11
11
  /** 可选的超时时间(秒) */
@@ -15,8 +15,3 @@ export interface E2BConfig {
15
15
  /** 可选的元数据 */
16
16
  metadata?: Record<string, string>;
17
17
  }
18
- /**
19
- * E2B 创建沙盒配置(用于覆盖构造函数中的配置)
20
- * 继承自 E2BConfig 但排除 apiKey 和 sandboxId
21
- */
22
- export type E2BCreateConfig = Omit<E2BConfig, 'apiKey' | 'sandboxId'>;
@@ -1,4 +1,5 @@
1
1
  import { ImageSpec, NetworkPolicy, ResourceLimits } from '@/types';
2
+ import type { Volume } from '@alibaba-group/opensandbox';
2
3
  /**
3
4
  * Configuration for creating a sandbox.
4
5
  */
@@ -17,6 +18,8 @@ export interface OpenSandboxConfigType {
17
18
  metadata?: Record<string, any>;
18
19
  /** Network access policy */
19
20
  networkPolicy?: NetworkPolicy;
21
+ /** Optional volume mounts for persistent storage */
22
+ volumes?: Volume[];
20
23
  /** Provider-specific extensions */
21
24
  extensions?: Record<string, unknown>;
22
25
  /** Skip readiness checks after create/connect */
@@ -1,19 +1,19 @@
1
1
  import { type SealosDevboxConfig } from './SealosDevboxAdapter';
2
2
  import { type OpenSandboxConnectionConfig, type OpenSandboxConfigType } from './OpenSandboxAdapter';
3
- import { type E2BConfig, type E2BCreateConfig } from './E2BAdapter';
3
+ import { type E2BConfig } from './E2BAdapter';
4
4
  import { ISandbox } from '@/interfaces';
5
5
  export { SealosDevboxAdapter } from './SealosDevboxAdapter';
6
6
  export type { SealosDevboxConfig } from './SealosDevboxAdapter';
7
7
  export { OpenSandboxAdapter } from './OpenSandboxAdapter';
8
8
  export type { OpenSandboxConfigType, OpenSandboxConnectionConfig } from './OpenSandboxAdapter';
9
9
  export { E2BAdapter } from './E2BAdapter';
10
- export type { E2BConfig, E2BCreateConfig } from './E2BAdapter';
10
+ export type { E2BConfig } from './E2BAdapter';
11
11
  export type SandboxProviderType = 'opensandbox' | 'sealosdevbox' | 'e2b';
12
12
  /** Maps each provider name to the ISandbox config type it exposes. */
13
13
  interface SandboxConfigMap {
14
14
  opensandbox: OpenSandboxConfigType;
15
15
  sealosdevbox: undefined;
16
- e2b: E2BCreateConfig;
16
+ e2b: undefined;
17
17
  }
18
18
  /** Resolves the concrete ISandbox type for a given provider. */
19
19
  /** Maps each provider name to its constructor (connection) config type. */