@fastgpt-sdk/sandbox-adapter 0.0.30 → 0.0.32

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.
@@ -1,19 +0,0 @@
1
- import {
2
- CommandsAdapter,
3
- FilesystemAdapter,
4
- HealthAdapter,
5
- MetricsAdapter,
6
- SandboxesAdapter,
7
- createExecdClient,
8
- createLifecycleClient
9
- } from "./chunk-PHJSF3IJ.js";
10
- export {
11
- CommandsAdapter,
12
- FilesystemAdapter,
13
- HealthAdapter,
14
- MetricsAdapter,
15
- SandboxesAdapter,
16
- createExecdClient,
17
- createLifecycleClient
18
- };
19
- //# sourceMappingURL=internal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,15 +0,0 @@
1
- {
2
- "name": "@alibaba-group/opensandbox",
3
- "version": "0.1.5",
4
- "type": "module",
5
- "main": "./cjs/index.cjs",
6
- "module": "./index.js",
7
- "types": "./index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./index.d.ts",
11
- "import": "./index.js",
12
- "require": "./cjs/index.cjs"
13
- }
14
- }
15
- }
@@ -1,498 +0,0 @@
1
- /**
2
- * Domain models for filesystem.
3
- *
4
- * IMPORTANT:
5
- * - These are NOT OpenAPI-generated types.
6
- * - They are intentionally stable and JS-friendly.
7
- */
8
- interface FileInfo extends Record<string, unknown> {
9
- path: string;
10
- size?: number;
11
- /**
12
- * Last modification time.
13
- */
14
- modifiedAt?: Date;
15
- /**
16
- * Creation time.
17
- */
18
- createdAt?: Date;
19
- mode?: number;
20
- owner?: string;
21
- group?: string;
22
- }
23
- interface Permission extends Record<string, unknown> {
24
- mode: number;
25
- owner?: string;
26
- group?: string;
27
- }
28
- interface FileMetadata extends Record<string, unknown> {
29
- path: string;
30
- mode?: number;
31
- owner?: string;
32
- group?: string;
33
- }
34
- interface RenameFileItem extends Record<string, unknown> {
35
- src: string;
36
- dest: string;
37
- }
38
- interface ReplaceFileContentItem extends Record<string, unknown> {
39
- old: string;
40
- new: string;
41
- }
42
- type FilesInfoResponse = Record<string, FileInfo>;
43
- type SearchFilesResponse = FileInfo[];
44
- interface WriteEntry {
45
- path: string;
46
- /**
47
- * File data to upload.
48
- *
49
- * Supports:
50
- * - string / bytes / Blob (in-memory)
51
- * - AsyncIterable<Uint8Array> or ReadableStream<Uint8Array> (streaming upload for large files)
52
- */
53
- data?: string | Uint8Array | ArrayBuffer | Blob | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>;
54
- mode?: number;
55
- owner?: string;
56
- group?: string;
57
- }
58
- interface SearchEntry {
59
- path: string;
60
- pattern?: string;
61
- }
62
- interface MoveEntry {
63
- src: string;
64
- dest: string;
65
- }
66
- interface ContentReplaceEntry {
67
- path: string;
68
- oldContent: string;
69
- newContent: string;
70
- }
71
- interface SetPermissionEntry {
72
- path: string;
73
- mode: number;
74
- owner?: string;
75
- group?: string;
76
- }
77
-
78
- /**
79
- * High-level filesystem facade (JS-friendly).
80
- *
81
- * This interface provides a convenience layer over the underlying execd filesystem API:
82
- * it offers common operations (read/write/search/move/delete) and supports streaming I/O for large files.
83
- */
84
- interface SandboxFiles {
85
- getFileInfo(paths: string[]): Promise<Record<string, FileInfo>>;
86
- search(entry: SearchEntry): Promise<SearchFilesResponse>;
87
- createDirectories(entries: Pick<WriteEntry, "path" | "mode" | "owner" | "group">[]): Promise<void>;
88
- deleteDirectories(paths: string[]): Promise<void>;
89
- writeFiles(entries: WriteEntry[]): Promise<void>;
90
- readFile(path: string, opts?: {
91
- encoding?: string;
92
- range?: string;
93
- }): Promise<string>;
94
- readBytes(path: string, opts?: {
95
- range?: string;
96
- }): Promise<Uint8Array>;
97
- readBytesStream(path: string, opts?: {
98
- range?: string;
99
- }): AsyncIterable<Uint8Array>;
100
- deleteFiles(paths: string[]): Promise<void>;
101
- moveFiles(entries: MoveEntry[]): Promise<void>;
102
- replaceContents(entries: ContentReplaceEntry[]): Promise<void>;
103
- setPermissions(entries: SetPermissionEntry[]): Promise<void>;
104
- }
105
-
106
- /**
107
- * Domain models for sandbox lifecycle.
108
- *
109
- * IMPORTANT:
110
- * - These are NOT OpenAPI-generated types.
111
- * - They are intentionally stable and JS-friendly.
112
- *
113
- * The internal OpenAPI schemas may change frequently; adapters map responses into these models.
114
- */
115
- type SandboxId = string;
116
- interface ImageAuth extends Record<string, unknown> {
117
- username?: string;
118
- password?: string;
119
- token?: string;
120
- }
121
- interface ImageSpec {
122
- uri: string;
123
- auth?: ImageAuth;
124
- }
125
- type ResourceLimits = Record<string, string>;
126
- type NetworkRuleAction = "allow" | "deny";
127
- interface NetworkRule extends Record<string, unknown> {
128
- /**
129
- * Whether to allow or deny matching targets.
130
- */
131
- action: NetworkRuleAction;
132
- /**
133
- * FQDN or wildcard domain (e.g., "example.com", "*.example.com").
134
- * IP/CIDR is not supported in the egress MVP.
135
- */
136
- target: string;
137
- }
138
- interface NetworkPolicy extends Record<string, unknown> {
139
- /**
140
- * Default action when no egress rule matches. Defaults to "deny".
141
- */
142
- defaultAction?: NetworkRuleAction;
143
- /**
144
- * List of egress rules evaluated in order.
145
- */
146
- egress?: NetworkRule[];
147
- }
148
- /**
149
- * Host path bind mount backend.
150
- *
151
- * Maps a directory on the host filesystem into the container.
152
- * Only available when the runtime supports host mounts.
153
- */
154
- interface Host extends Record<string, unknown> {
155
- /**
156
- * Absolute path on the host filesystem to mount.
157
- */
158
- path: string;
159
- }
160
- /**
161
- * Kubernetes PersistentVolumeClaim mount backend.
162
- *
163
- * References an existing PVC in the same namespace as the sandbox pod.
164
- * Only available in Kubernetes runtime.
165
- */
166
- interface PVC extends Record<string, unknown> {
167
- /**
168
- * Name of the PersistentVolumeClaim in the same namespace.
169
- */
170
- claimName: string;
171
- }
172
- /**
173
- * Storage mount definition for a sandbox.
174
- *
175
- * Each volume entry contains:
176
- * - A unique name identifier
177
- * - Exactly one backend (host, pvc) with backend-specific fields
178
- * - Common mount settings (mountPath, readOnly, subPath)
179
- */
180
- interface Volume extends Record<string, unknown> {
181
- /**
182
- * Unique identifier for the volume within the sandbox.
183
- */
184
- name: string;
185
- /**
186
- * Host path bind mount backend (mutually exclusive with pvc).
187
- */
188
- host?: Host;
189
- /**
190
- * Kubernetes PVC mount backend (mutually exclusive with host).
191
- */
192
- pvc?: PVC;
193
- /**
194
- * Absolute path inside the container where the volume is mounted.
195
- */
196
- mountPath: string;
197
- /**
198
- * If true, the volume is mounted as read-only. Defaults to false (read-write).
199
- */
200
- readOnly?: boolean;
201
- /**
202
- * Optional subdirectory under the backend path to mount.
203
- */
204
- subPath?: string;
205
- }
206
- type SandboxState = "Creating" | "Running" | "Pausing" | "Paused" | "Resuming" | "Deleting" | "Deleted" | "Error" | string;
207
- interface SandboxStatus extends Record<string, unknown> {
208
- state: SandboxState;
209
- reason?: string;
210
- message?: string;
211
- }
212
- interface SandboxInfo extends Record<string, unknown> {
213
- id: SandboxId;
214
- image: ImageSpec;
215
- entrypoint: string[];
216
- metadata?: Record<string, string>;
217
- status: SandboxStatus;
218
- /**
219
- * Sandbox creation time.
220
- */
221
- createdAt: Date;
222
- /**
223
- * Sandbox expiration time (server-side TTL).
224
- */
225
- expiresAt: Date | null;
226
- }
227
- interface CreateSandboxRequest extends Record<string, unknown> {
228
- image: ImageSpec;
229
- entrypoint: string[];
230
- /**
231
- * Timeout in seconds (server semantics).
232
- */
233
- timeout?: number | null;
234
- resourceLimits: ResourceLimits;
235
- env?: Record<string, string>;
236
- metadata?: Record<string, string>;
237
- /**
238
- * Optional outbound network policy for the sandbox.
239
- */
240
- networkPolicy?: NetworkPolicy;
241
- /**
242
- * Optional list of volume mounts for persistent storage.
243
- */
244
- volumes?: Volume[];
245
- extensions?: Record<string, unknown>;
246
- }
247
- interface CreateSandboxResponse extends Record<string, unknown> {
248
- id: SandboxId;
249
- status: SandboxStatus;
250
- metadata?: Record<string, string>;
251
- /**
252
- * Sandbox expiration time after creation.
253
- */
254
- expiresAt: Date | null;
255
- /**
256
- * Sandbox creation time.
257
- */
258
- createdAt: Date;
259
- entrypoint: string[];
260
- }
261
- interface PaginationInfo extends Record<string, unknown> {
262
- page: number;
263
- pageSize: number;
264
- totalItems: number;
265
- totalPages: number;
266
- hasNextPage: boolean;
267
- }
268
- interface ListSandboxesResponse extends Record<string, unknown> {
269
- items: SandboxInfo[];
270
- pagination?: PaginationInfo;
271
- }
272
- interface RenewSandboxExpirationRequest {
273
- expiresAt: string;
274
- }
275
- interface RenewSandboxExpirationResponse extends Record<string, unknown> {
276
- /**
277
- * Updated expiration time (if the server returns it).
278
- */
279
- expiresAt?: Date;
280
- }
281
- interface Endpoint extends Record<string, unknown> {
282
- endpoint: string;
283
- /**
284
- * Headers that must be included on every request targeting this endpoint
285
- * (e.g. when the server requires them for routing or auth). Omit or empty if not required.
286
- */
287
- headers?: Record<string, string>;
288
- }
289
- interface ListSandboxesParams {
290
- /**
291
- * Filter by lifecycle state (the API supports multiple `state` query params).
292
- * Example: `{ states: ["Running", "Paused"] }`
293
- */
294
- states?: string[];
295
- /**
296
- * Filter by metadata key-value pairs.
297
- * NOTE: This will be encoded to a single `metadata` query parameter as described in the spec.
298
- */
299
- metadata?: Record<string, string>;
300
- page?: number;
301
- pageSize?: number;
302
- }
303
-
304
- interface OutputMessage {
305
- text: string;
306
- timestamp: number;
307
- isError?: boolean;
308
- }
309
- interface ExecutionResult {
310
- text?: string;
311
- timestamp: number;
312
- /**
313
- * Raw mime map from execd event (e.g. "text/plain", "text/html", ...)
314
- */
315
- raw?: Record<string, unknown>;
316
- }
317
- interface ExecutionError {
318
- name: string;
319
- value: string;
320
- timestamp: number;
321
- traceback: string[];
322
- }
323
- interface ExecutionComplete {
324
- timestamp: number;
325
- executionTimeMs: number;
326
- }
327
- interface ExecutionInit {
328
- id: string;
329
- timestamp: number;
330
- }
331
- interface Execution {
332
- id?: string;
333
- executionCount?: number;
334
- logs: {
335
- stdout: OutputMessage[];
336
- stderr: OutputMessage[];
337
- };
338
- result: ExecutionResult[];
339
- error?: ExecutionError;
340
- complete?: ExecutionComplete;
341
- exitCode?: number | null;
342
- }
343
- interface ExecutionHandlers {
344
- /**
345
- * Optional low-level hook for every server-sent event (SSE) received.
346
- * Kept as `unknown` to avoid coupling to a specific OpenAPI schema module.
347
- */
348
- onEvent?: (ev: unknown) => void | Promise<void>;
349
- onStdout?: (msg: OutputMessage) => void | Promise<void>;
350
- onStderr?: (msg: OutputMessage) => void | Promise<void>;
351
- onResult?: (res: ExecutionResult) => void | Promise<void>;
352
- onExecutionComplete?: (c: ExecutionComplete) => void | Promise<void>;
353
- onError?: (err: ExecutionError) => void | Promise<void>;
354
- onInit?: (init: ExecutionInit) => void | Promise<void>;
355
- }
356
-
357
- /**
358
- * Domain models for execd interactions.
359
- *
360
- * IMPORTANT:
361
- * - These are NOT OpenAPI-generated types.
362
- * - They are intentionally stable and JS-friendly.
363
- */
364
- interface ServerStreamEvent extends Record<string, unknown> {
365
- type: "init" | "stdout" | "stderr" | "result" | "execution_count" | "execution_complete" | "error" | string;
366
- timestamp?: number;
367
- text?: string;
368
- results?: Record<string, unknown>;
369
- error?: Record<string, unknown>;
370
- }
371
- interface CodeContextRequest extends Record<string, unknown> {
372
- language: string;
373
- }
374
- type SupportedLanguage = "python" | "go" | "javascript" | "typescript" | "bash" | "java";
375
- interface RunCommandOpts {
376
- /**
377
- * Working directory for command execution (maps to API `cwd`).
378
- */
379
- workingDirectory?: string;
380
- /**
381
- * Run command in detached mode.
382
- */
383
- background?: boolean;
384
- /**
385
- * Maximum execution time in seconds; server will terminate the command when reached.
386
- * If omitted, the server will not enforce any timeout.
387
- */
388
- timeoutSeconds?: number;
389
- /**
390
- * Unix user ID used to run the command process.
391
- */
392
- uid?: number;
393
- /**
394
- * Unix group ID used to run the command process. Requires `uid`.
395
- */
396
- gid?: number;
397
- /**
398
- * Environment variables injected into the command process.
399
- */
400
- envs?: Record<string, string>;
401
- }
402
- interface CommandStatus {
403
- id?: string;
404
- content?: string;
405
- running?: boolean;
406
- exitCode?: number | null;
407
- error?: string;
408
- startedAt?: Date;
409
- finishedAt?: Date | null;
410
- }
411
- interface CommandLogs {
412
- content: string;
413
- cursor?: number;
414
- }
415
- type CommandExecution = Execution;
416
- interface Metrics extends Record<string, unknown> {
417
- cpu_count?: number;
418
- cpu_used_pct?: number;
419
- mem_total_mib?: number;
420
- mem_used_mib?: number;
421
- timestamp?: number;
422
- }
423
- /**
424
- * Normalized, JS-friendly metrics.
425
- */
426
- interface SandboxMetrics {
427
- cpuCount: number;
428
- cpuUsedPercentage: number;
429
- memoryTotalMiB: number;
430
- memoryUsedMiB: number;
431
- timestamp: number;
432
- }
433
- type PingResponse = Record<string, unknown>;
434
-
435
- interface ExecdCommands {
436
- /**
437
- * Run a command and stream server events (SSE). This is the lowest-level API.
438
- */
439
- runStream(command: string, opts?: RunCommandOpts, signal?: AbortSignal): AsyncIterable<ServerStreamEvent>;
440
- /**
441
- * Convenience: run a command, consume the stream, and build a structured execution result.
442
- */
443
- run(command: string, opts?: RunCommandOpts, handlers?: ExecutionHandlers, signal?: AbortSignal): Promise<CommandExecution>;
444
- /**
445
- * Interrupt the current execution in the given context/session.
446
- *
447
- * Note: Execd spec uses `DELETE /command?id=<sessionId>`.
448
- */
449
- interrupt(sessionId: string): Promise<void>;
450
- /**
451
- * Get the current running status for a command id.
452
- */
453
- getCommandStatus(commandId: string): Promise<CommandStatus>;
454
- /**
455
- * Get background command logs (non-streamed).
456
- */
457
- getBackgroundCommandLogs(commandId: string, cursor?: number): Promise<CommandLogs>;
458
- /**
459
- * Create a bash session with optional working directory.
460
- * Returns session ID for use with runInSession and deleteSession.
461
- */
462
- createSession(options?: {
463
- cwd?: string;
464
- }): Promise<string>;
465
- /**
466
- * Run shell code in an existing bash session (SSE stream, same event shape as run).
467
- * Optional cwd and timeoutMs apply to this run only; session state (e.g. env) persists.
468
- */
469
- runInSession(sessionId: string, code: string, options?: {
470
- cwd?: string;
471
- timeoutMs?: number;
472
- }, handlers?: ExecutionHandlers, signal?: AbortSignal): Promise<CommandExecution>;
473
- /**
474
- * Delete a bash session by ID. Frees resources; session ID must have been returned by createSession.
475
- */
476
- deleteSession(sessionId: string): Promise<void>;
477
- }
478
-
479
- interface ExecdHealth {
480
- ping(): Promise<boolean>;
481
- }
482
-
483
- interface ExecdMetrics {
484
- getMetrics(): Promise<SandboxMetrics>;
485
- }
486
-
487
- interface Sandboxes {
488
- createSandbox(req: CreateSandboxRequest): Promise<CreateSandboxResponse>;
489
- getSandbox(sandboxId: SandboxId): Promise<SandboxInfo>;
490
- listSandboxes(params?: ListSandboxesParams): Promise<ListSandboxesResponse>;
491
- deleteSandbox(sandboxId: SandboxId): Promise<void>;
492
- pauseSandbox(sandboxId: SandboxId): Promise<void>;
493
- resumeSandbox(sandboxId: SandboxId): Promise<void>;
494
- renewSandboxExpiration(sandboxId: SandboxId, req: RenewSandboxExpirationRequest): Promise<RenewSandboxExpirationResponse>;
495
- getSandboxEndpoint(sandboxId: SandboxId, port: number, useServerProxy?: boolean): Promise<Endpoint>;
496
- }
497
-
498
- export type { Permission as A, PingResponse as B, CodeContextRequest as C, RenameFileItem as D, ExecdCommands as E, FileInfo as F, RenewSandboxExpirationRequest as G, Host as H, ReplaceFileContentItem as I, RunCommandOpts as J, SearchEntry as K, ListSandboxesResponse as L, Metrics as M, NetworkPolicy as N, OutputMessage as O, PVC as P, SearchFilesResponse as Q, RenewSandboxExpirationResponse as R, Sandboxes as S, SetPermissionEntry as T, SupportedLanguage as U, Volume as V, WriteEntry as W, NetworkRule as a, SandboxFiles as b, ExecdHealth as c, ExecdMetrics as d, SandboxId as e, SandboxInfo as f, Execution as g, ExecutionHandlers as h, ServerStreamEvent as i, SandboxMetrics as j, Endpoint as k, CommandExecution as l, CommandLogs as m, CommandStatus as n, ContentReplaceEntry as o, CreateSandboxRequest as p, CreateSandboxResponse as q, ExecutionComplete as r, ExecutionError as s, ExecutionInit as t, ExecutionResult as u, FileMetadata as v, FilesInfoResponse as w, ListSandboxesParams as x, MoveEntry as y, NetworkRuleAction as z };