@fastgpt-sdk/sandbox-adapter 0.0.1
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 +163 -0
- package/dist/adapters/BaseSandboxAdapter.d.ts +59 -0
- package/dist/adapters/FastGPTSandboxAdapter/index.d.ts +85 -0
- package/dist/adapters/MinimalProviderAdapter.d.ts +52 -0
- package/dist/adapters/OpenSandboxAdapter.d.ts +229 -0
- package/dist/adapters/index.d.ts +26 -0
- package/dist/errors/CommandExecutionError.d.ts +16 -0
- package/dist/errors/ConnectionError.d.ts +8 -0
- package/dist/errors/FeatureNotSupportedError.d.ts +10 -0
- package/dist/errors/FileOperationError.d.ts +13 -0
- package/dist/errors/SandboxException.d.ts +17 -0
- package/dist/errors/SandboxStateError.d.ts +9 -0
- package/dist/errors/TimeoutError.d.ts +15 -0
- package/dist/errors/index.d.ts +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1225 -0
- package/dist/interfaces/ICommandExecution.d.ts +41 -0
- package/dist/interfaces/IFileSystem.d.ts +99 -0
- package/dist/interfaces/IHealthCheck.d.ts +23 -0
- package/dist/interfaces/ISandbox.d.ts +23 -0
- package/dist/interfaces/ISandboxLifecycle.d.ts +54 -0
- package/dist/interfaces/index.d.ts +5 -0
- package/dist/polyfill/CommandPolyfillService.d.ts +122 -0
- package/dist/types/execution.d.ts +61 -0
- package/dist/types/filesystem.d.ts +106 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/sandbox.d.ts +92 -0
- package/dist/utils/base64.d.ts +20 -0
- package/dist/utils/streams.d.ts +26 -0
- package/package.json +87 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ExecuteOptions, ExecuteResult, StreamHandlers } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for command execution within a sandbox.
|
|
4
|
+
* Follows Interface Segregation Principle.
|
|
5
|
+
*/
|
|
6
|
+
export interface ICommandExecution {
|
|
7
|
+
/**
|
|
8
|
+
* Execute a command and wait for completion.
|
|
9
|
+
* @param command The command to execute
|
|
10
|
+
* @param options Execution options
|
|
11
|
+
* @returns Execution result with stdout, stderr, and exit code
|
|
12
|
+
* @throws {CommandExecutionError} If command fails
|
|
13
|
+
* @throws {TimeoutError} If execution times out
|
|
14
|
+
*/
|
|
15
|
+
execute(command: string, options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a command with streaming output.
|
|
18
|
+
* Provides real-time access to stdout/stderr via handlers.
|
|
19
|
+
* @param command The command to execute
|
|
20
|
+
* @param handlers Stream handlers for output
|
|
21
|
+
* @param options Execution options
|
|
22
|
+
* @throws {CommandExecutionError} If command fails
|
|
23
|
+
*/
|
|
24
|
+
executeStream(command: string, handlers: StreamHandlers, options?: ExecuteOptions): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute a command in the background.
|
|
27
|
+
* Returns immediately with a handle to control the execution.
|
|
28
|
+
* @param command The command to execute
|
|
29
|
+
* @param options Execution options
|
|
30
|
+
* @returns Handle for background execution
|
|
31
|
+
*/
|
|
32
|
+
executeBackground(command: string, options?: ExecuteOptions): Promise<{
|
|
33
|
+
sessionId: string;
|
|
34
|
+
kill(): Promise<void>;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Interrupt/kill a running command session.
|
|
38
|
+
* @param sessionId The session ID from executeBackground
|
|
39
|
+
*/
|
|
40
|
+
interrupt(sessionId: string): Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ContentReplaceEntry, DirectoryEntry, FileDeleteResult, FileInfo, FileReadResult, FileWriteEntry, FileWriteResult, MoveEntry, PermissionEntry, ReadFileOptions, SearchResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for filesystem operations within a sandbox.
|
|
4
|
+
* Follows Interface Segregation Principle.
|
|
5
|
+
*
|
|
6
|
+
* All methods support batch operations for efficiency.
|
|
7
|
+
* Providers without native batch support will have operations
|
|
8
|
+
* automatically parallelized by the base adapter.
|
|
9
|
+
*/
|
|
10
|
+
export interface IFileSystem {
|
|
11
|
+
/**
|
|
12
|
+
* Read files from the sandbox.
|
|
13
|
+
* @param paths Array of file paths to read
|
|
14
|
+
* @param options Read options
|
|
15
|
+
* @returns Array of results (one per path, may include errors)
|
|
16
|
+
*/
|
|
17
|
+
readFiles(paths: string[], options?: ReadFileOptions): Promise<FileReadResult[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Write files to the sandbox.
|
|
20
|
+
* Supports strings, bytes, and streams.
|
|
21
|
+
* @param entries Files to write
|
|
22
|
+
* @returns Array of results with bytes written
|
|
23
|
+
*/
|
|
24
|
+
writeFiles(entries: FileWriteEntry[]): Promise<FileWriteResult[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Delete files from the sandbox.
|
|
27
|
+
* @param paths Files to delete
|
|
28
|
+
* @returns Array of results
|
|
29
|
+
*/
|
|
30
|
+
deleteFiles(paths: string[]): Promise<FileDeleteResult[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Move/rename files within the sandbox.
|
|
33
|
+
* @param entries Move operations to perform
|
|
34
|
+
*/
|
|
35
|
+
moveFiles(entries: MoveEntry[]): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Replace content within files.
|
|
38
|
+
* @param entries Replacement operations
|
|
39
|
+
*/
|
|
40
|
+
replaceContent(entries: ContentReplaceEntry[]): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Read a file as a stream.
|
|
43
|
+
* Efficient for large files.
|
|
44
|
+
* @param path File path
|
|
45
|
+
* @returns Async iterable of file chunks
|
|
46
|
+
*/
|
|
47
|
+
readFileStream(path: string): AsyncIterable<Uint8Array>;
|
|
48
|
+
/**
|
|
49
|
+
* Write a file from a stream.
|
|
50
|
+
* Efficient for large files.
|
|
51
|
+
* @param path File path
|
|
52
|
+
* @param stream Data stream
|
|
53
|
+
*/
|
|
54
|
+
writeFileStream(path: string, stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Create directories.
|
|
57
|
+
* Creates parent directories as needed.
|
|
58
|
+
* @param paths Directories to create
|
|
59
|
+
* @param options Directory options (mode, owner, group)
|
|
60
|
+
*/
|
|
61
|
+
createDirectories(paths: string[], options?: {
|
|
62
|
+
mode?: number;
|
|
63
|
+
owner?: string;
|
|
64
|
+
group?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete directories and their contents.
|
|
68
|
+
* @param paths Directories to delete
|
|
69
|
+
* @param options Options (recursive, force)
|
|
70
|
+
*/
|
|
71
|
+
deleteDirectories(paths: string[], options?: {
|
|
72
|
+
recursive?: boolean;
|
|
73
|
+
force?: boolean;
|
|
74
|
+
}): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* List directory contents.
|
|
77
|
+
* @param path Directory path
|
|
78
|
+
* @returns Array of directory entries
|
|
79
|
+
*/
|
|
80
|
+
listDirectory(path: string): Promise<DirectoryEntry[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Get file/directory information.
|
|
83
|
+
* @param paths Paths to query
|
|
84
|
+
* @returns Map of path to file info
|
|
85
|
+
*/
|
|
86
|
+
getFileInfo(paths: string[]): Promise<Map<string, FileInfo>>;
|
|
87
|
+
/**
|
|
88
|
+
* Set file permissions.
|
|
89
|
+
* @param entries Permission changes to apply
|
|
90
|
+
*/
|
|
91
|
+
setPermissions(entries: PermissionEntry[]): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Search for files matching a pattern.
|
|
94
|
+
* @param pattern Search pattern (glob or regex, provider-dependent)
|
|
95
|
+
* @param path Directory to search in
|
|
96
|
+
* @returns Array of matching results
|
|
97
|
+
*/
|
|
98
|
+
search(pattern: string, path?: string): Promise<SearchResult[]>;
|
|
99
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SandboxMetrics } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for health checking and metrics.
|
|
4
|
+
* Follows Interface Segregation Principle.
|
|
5
|
+
*/
|
|
6
|
+
export interface IHealthCheck {
|
|
7
|
+
/**
|
|
8
|
+
* Check if the sandbox is healthy and responsive.
|
|
9
|
+
* @returns true if healthy, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
ping(): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Get current resource metrics.
|
|
14
|
+
* @returns Current metrics (CPU, memory usage)
|
|
15
|
+
*/
|
|
16
|
+
getMetrics(): Promise<SandboxMetrics>;
|
|
17
|
+
/**
|
|
18
|
+
* Stream metrics in real-time.
|
|
19
|
+
* Not all providers support this.
|
|
20
|
+
* @returns Async iterable of metric snapshots
|
|
21
|
+
*/
|
|
22
|
+
streamMetrics?(): AsyncIterable<SandboxMetrics>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ICommandExecution } from './ICommandExecution';
|
|
2
|
+
import type { IFileSystem } from './IFileSystem';
|
|
3
|
+
import type { IHealthCheck } from './IHealthCheck';
|
|
4
|
+
import type { ISandboxLifecycle } from './ISandboxLifecycle';
|
|
5
|
+
/**
|
|
6
|
+
* Unified sandbox interface.
|
|
7
|
+
* Composes all sandbox behaviors into a single interface.
|
|
8
|
+
*
|
|
9
|
+
* This is the primary interface that consumers interact with.
|
|
10
|
+
* All concrete adapters must implement this interface.
|
|
11
|
+
*
|
|
12
|
+
* Following Interface Segregation Principle, this interface
|
|
13
|
+
* is composed of smaller, focused interfaces.
|
|
14
|
+
*/
|
|
15
|
+
export interface ISandbox extends ISandboxLifecycle, ICommandExecution, IFileSystem, IHealthCheck {
|
|
16
|
+
/** Provider name (e.g., 'opensandbox') */
|
|
17
|
+
readonly provider: string;
|
|
18
|
+
/**
|
|
19
|
+
* Close the connection and release resources.
|
|
20
|
+
* Should be called when done with the sandbox.
|
|
21
|
+
*/
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { SandboxConfig, SandboxId, SandboxInfo, SandboxStatus } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for sandbox lifecycle operations.
|
|
4
|
+
* Follows Interface Segregation Principle - only lifecycle methods.
|
|
5
|
+
*/
|
|
6
|
+
export interface ISandboxLifecycle {
|
|
7
|
+
/** Unique identifier for this sandbox */
|
|
8
|
+
readonly id: SandboxId;
|
|
9
|
+
/** Current status of the sandbox */
|
|
10
|
+
readonly status: SandboxStatus;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new sandbox with the given configuration.
|
|
13
|
+
* The sandbox ID is assigned after creation.
|
|
14
|
+
*/
|
|
15
|
+
create(config: SandboxConfig): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Start a stopped sandbox.
|
|
18
|
+
*/
|
|
19
|
+
start(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Stop a running sandbox (graceful shutdown).
|
|
22
|
+
*/
|
|
23
|
+
stop(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Pause a running sandbox.
|
|
26
|
+
* Not all providers support this.
|
|
27
|
+
*/
|
|
28
|
+
pause(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Resume a paused sandbox.
|
|
31
|
+
* Not all providers support this.
|
|
32
|
+
*/
|
|
33
|
+
resume(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete the sandbox permanently.
|
|
36
|
+
*/
|
|
37
|
+
delete(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Get detailed information about the sandbox.
|
|
40
|
+
*/
|
|
41
|
+
getInfo(): Promise<SandboxInfo | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Wait until the sandbox is ready (healthy and responsive).
|
|
44
|
+
* @param timeoutMs Maximum time to wait in milliseconds
|
|
45
|
+
* @throws {SandboxReadyTimeoutError} If timeout is exceeded
|
|
46
|
+
*/
|
|
47
|
+
waitUntilReady(timeoutMs?: number): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Renew the sandbox expiration, extending its lifetime.
|
|
50
|
+
* Not all providers support this.
|
|
51
|
+
* @param additionalSeconds Seconds to extend
|
|
52
|
+
*/
|
|
53
|
+
renewExpiration(additionalSeconds: number): Promise<void>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ICommandExecution } from './ICommandExecution';
|
|
2
|
+
export type { IFileSystem } from './IFileSystem';
|
|
3
|
+
export type { IHealthCheck } from './IHealthCheck';
|
|
4
|
+
export type { ISandbox } from './ISandbox';
|
|
5
|
+
export type { ISandboxLifecycle } from './ISandboxLifecycle';
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { ICommandExecution } from '../interfaces';
|
|
2
|
+
import type { DirectoryEntry, FileInfo, SearchResult } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Service that implements filesystem operations via command execution.
|
|
5
|
+
*
|
|
6
|
+
* This is the core polyfill mechanism that enables feature parity
|
|
7
|
+
* for providers that only offer raw command execution without
|
|
8
|
+
* native filesystem APIs.
|
|
9
|
+
*
|
|
10
|
+
* All commands use POSIX-compliant syntax for maximum compatibility.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CommandPolyfillService {
|
|
13
|
+
private readonly executor;
|
|
14
|
+
constructor(executor: ICommandExecution);
|
|
15
|
+
/**
|
|
16
|
+
* Read a file via base64 encoding.
|
|
17
|
+
* Uses: cat <file> | base64
|
|
18
|
+
*/
|
|
19
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
20
|
+
/**
|
|
21
|
+
* Read a portion of a file via dd + base64.
|
|
22
|
+
*/
|
|
23
|
+
readFileRange(path: string, start: number, end?: number): Promise<Uint8Array>;
|
|
24
|
+
/**
|
|
25
|
+
* Write a file via base64 decoding.
|
|
26
|
+
* Uses: echo <base64> | base64 -d > <file>
|
|
27
|
+
*/
|
|
28
|
+
writeFile(path: string, data: Uint8Array): Promise<number>;
|
|
29
|
+
/**
|
|
30
|
+
* Write a text file directly.
|
|
31
|
+
*/
|
|
32
|
+
writeTextFile(path: string, content: string): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Delete files via rm command.
|
|
35
|
+
*/
|
|
36
|
+
deleteFiles(paths: string[]): Promise<{
|
|
37
|
+
path: string;
|
|
38
|
+
success: boolean;
|
|
39
|
+
error?: Error;
|
|
40
|
+
}[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Create directories via mkdir -p.
|
|
43
|
+
*/
|
|
44
|
+
createDirectories(paths: string[], options?: {
|
|
45
|
+
mode?: number;
|
|
46
|
+
owner?: string;
|
|
47
|
+
group?: string;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Delete directories via rm -rf.
|
|
51
|
+
*/
|
|
52
|
+
deleteDirectories(paths: string[], options?: {
|
|
53
|
+
recursive?: boolean;
|
|
54
|
+
force?: boolean;
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* List directory contents via ls -la.
|
|
58
|
+
*/
|
|
59
|
+
listDirectory(path: string): Promise<DirectoryEntry[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Create parent directory for a file path.
|
|
62
|
+
*/
|
|
63
|
+
private createParentDirectory;
|
|
64
|
+
/**
|
|
65
|
+
* Get file information via stat.
|
|
66
|
+
*/
|
|
67
|
+
getFileInfo(paths: string[]): Promise<Map<string, FileInfo>>;
|
|
68
|
+
/**
|
|
69
|
+
* Set file permissions via chmod.
|
|
70
|
+
*/
|
|
71
|
+
setPermissions(entries: {
|
|
72
|
+
path: string;
|
|
73
|
+
mode?: number;
|
|
74
|
+
owner?: string;
|
|
75
|
+
group?: string;
|
|
76
|
+
}[]): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Search for files via find command.
|
|
79
|
+
*/
|
|
80
|
+
search(pattern: string, path?: string): Promise<SearchResult[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Move/rename files via mv command.
|
|
83
|
+
*/
|
|
84
|
+
moveFiles(entries: {
|
|
85
|
+
source: string;
|
|
86
|
+
destination: string;
|
|
87
|
+
}[]): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Replace content in files via sed.
|
|
90
|
+
*/
|
|
91
|
+
replaceContent(entries: {
|
|
92
|
+
path: string;
|
|
93
|
+
oldContent: string;
|
|
94
|
+
newContent: string;
|
|
95
|
+
}[]): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Simple health check via echo command.
|
|
98
|
+
*/
|
|
99
|
+
ping(): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Get metrics via /proc filesystem.
|
|
102
|
+
*/
|
|
103
|
+
getMetrics(): Promise<{
|
|
104
|
+
cpuCount: number;
|
|
105
|
+
cpuUsedPercentage: number;
|
|
106
|
+
memoryTotalMiB: number;
|
|
107
|
+
memoryUsedMiB: number;
|
|
108
|
+
timestamp: number;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* Escape a path for safe shell usage.
|
|
112
|
+
*/
|
|
113
|
+
private escapePath;
|
|
114
|
+
/**
|
|
115
|
+
* Parse ls -la output into DirectoryEntry objects.
|
|
116
|
+
*/
|
|
117
|
+
private parseLsOutput;
|
|
118
|
+
/**
|
|
119
|
+
* Create a FileOperationError from stderr.
|
|
120
|
+
*/
|
|
121
|
+
private createFileError;
|
|
122
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for executing commands.
|
|
3
|
+
*/
|
|
4
|
+
export interface ExecuteOptions {
|
|
5
|
+
/** Working directory for execution */
|
|
6
|
+
workingDirectory?: string;
|
|
7
|
+
/** Run in background (don't wait for completion) */
|
|
8
|
+
background?: boolean;
|
|
9
|
+
/** Timeout in milliseconds */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
/** Environment variables to set */
|
|
12
|
+
env?: Record<string, string>;
|
|
13
|
+
/** Abort signal for cancellation */
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Result of command execution.
|
|
18
|
+
*/
|
|
19
|
+
export interface ExecuteResult {
|
|
20
|
+
/** Standard output */
|
|
21
|
+
stdout: string;
|
|
22
|
+
/** Standard error */
|
|
23
|
+
stderr: string;
|
|
24
|
+
/** Exit code (null if not completed) */
|
|
25
|
+
exitCode: number | null;
|
|
26
|
+
/** Whether output was truncated */
|
|
27
|
+
truncated?: boolean;
|
|
28
|
+
/** Execution duration in milliseconds */
|
|
29
|
+
durationMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Output message from streaming execution.
|
|
33
|
+
*/
|
|
34
|
+
export interface OutputMessage {
|
|
35
|
+
/** Message content */
|
|
36
|
+
text: string;
|
|
37
|
+
/** Timestamp (Unix milliseconds) */
|
|
38
|
+
timestamp?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Handlers for streaming command output.
|
|
42
|
+
*/
|
|
43
|
+
export interface StreamHandlers {
|
|
44
|
+
/** Called for each stdout message */
|
|
45
|
+
onStdout?: (msg: OutputMessage) => void | Promise<void>;
|
|
46
|
+
/** Called for each stderr message */
|
|
47
|
+
onStderr?: (msg: OutputMessage) => void | Promise<void>;
|
|
48
|
+
/** Called when execution completes */
|
|
49
|
+
onComplete?: (result: ExecuteResult) => void | Promise<void>;
|
|
50
|
+
/** Called on error */
|
|
51
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Background execution handle.
|
|
55
|
+
*/
|
|
56
|
+
export interface BackgroundExecution {
|
|
57
|
+
/** Session ID for the background execution */
|
|
58
|
+
sessionId: string;
|
|
59
|
+
/** Kill the background execution */
|
|
60
|
+
kill(): Promise<void>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File information/metadata.
|
|
3
|
+
*/
|
|
4
|
+
export interface FileInfo {
|
|
5
|
+
path: string;
|
|
6
|
+
size?: number;
|
|
7
|
+
modifiedAt?: Date;
|
|
8
|
+
createdAt?: Date;
|
|
9
|
+
mode?: number;
|
|
10
|
+
owner?: string;
|
|
11
|
+
group?: string;
|
|
12
|
+
isDirectory?: boolean;
|
|
13
|
+
isFile?: boolean;
|
|
14
|
+
isSymlink?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Directory entry.
|
|
18
|
+
*/
|
|
19
|
+
export interface DirectoryEntry {
|
|
20
|
+
name: string;
|
|
21
|
+
path: string;
|
|
22
|
+
isDirectory: boolean;
|
|
23
|
+
isFile: boolean;
|
|
24
|
+
size?: number;
|
|
25
|
+
modifiedAt?: Date;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Entry for writing a file.
|
|
29
|
+
*/
|
|
30
|
+
export interface FileWriteEntry {
|
|
31
|
+
/** File path */
|
|
32
|
+
path: string;
|
|
33
|
+
/** File content (various types supported) */
|
|
34
|
+
data: string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array>;
|
|
35
|
+
/** File permissions (octal) */
|
|
36
|
+
mode?: number;
|
|
37
|
+
/** Owner */
|
|
38
|
+
owner?: string;
|
|
39
|
+
/** Group */
|
|
40
|
+
group?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Entry for permission changes.
|
|
44
|
+
*/
|
|
45
|
+
export interface PermissionEntry {
|
|
46
|
+
path: string;
|
|
47
|
+
mode?: number;
|
|
48
|
+
owner?: string;
|
|
49
|
+
group?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Result of reading a file.
|
|
53
|
+
*/
|
|
54
|
+
export interface FileReadResult {
|
|
55
|
+
path: string;
|
|
56
|
+
content: Uint8Array;
|
|
57
|
+
error: Error | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Result of writing a file.
|
|
61
|
+
*/
|
|
62
|
+
export interface FileWriteResult {
|
|
63
|
+
path: string;
|
|
64
|
+
bytesWritten: number;
|
|
65
|
+
error: Error | null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Result of deleting a file.
|
|
69
|
+
*/
|
|
70
|
+
export interface FileDeleteResult {
|
|
71
|
+
path: string;
|
|
72
|
+
success: boolean;
|
|
73
|
+
error: Error | null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Search result.
|
|
77
|
+
*/
|
|
78
|
+
export interface SearchResult {
|
|
79
|
+
path: string;
|
|
80
|
+
isDirectory?: boolean;
|
|
81
|
+
isFile?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Move/rename entry.
|
|
85
|
+
*/
|
|
86
|
+
export interface MoveEntry {
|
|
87
|
+
source: string;
|
|
88
|
+
destination: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Content replacement entry.
|
|
92
|
+
*/
|
|
93
|
+
export interface ContentReplaceEntry {
|
|
94
|
+
path: string;
|
|
95
|
+
oldContent: string;
|
|
96
|
+
newContent: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* File read options.
|
|
100
|
+
*/
|
|
101
|
+
export interface ReadFileOptions {
|
|
102
|
+
/** Character encoding (default: binary/Uint8Array) */
|
|
103
|
+
encoding?: 'utf-8' | 'base64' | 'binary';
|
|
104
|
+
/** Byte range to read (format: "start-end" or "start-") */
|
|
105
|
+
range?: string;
|
|
106
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { BackgroundExecution, ExecuteOptions, ExecuteResult, OutputMessage, StreamHandlers } from './execution';
|
|
2
|
+
export type { ContentReplaceEntry, DirectoryEntry, FileDeleteResult, FileInfo, FileReadResult, FileWriteEntry, FileWriteResult, MoveEntry, PermissionEntry, ReadFileOptions, SearchResult } from './filesystem';
|
|
3
|
+
export type { Endpoint, ImageSpec, NetworkPolicy, ResourceLimits, SandboxConfig, SandboxId, SandboxInfo, SandboxMetrics, SandboxState, SandboxStatus } from './sandbox';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unique identifier for a sandbox.
|
|
3
|
+
*/
|
|
4
|
+
export type SandboxId = string;
|
|
5
|
+
/**
|
|
6
|
+
* Sandbox status states.
|
|
7
|
+
*/
|
|
8
|
+
export type SandboxState = 'Creating' | 'Running' | 'Pausing' | 'Paused' | 'Resuming' | 'Deleting' | 'Deleted' | 'Error' | string;
|
|
9
|
+
/**
|
|
10
|
+
* Sandbox status information.
|
|
11
|
+
*/
|
|
12
|
+
export interface SandboxStatus {
|
|
13
|
+
state: SandboxState;
|
|
14
|
+
reason?: string;
|
|
15
|
+
message?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resource limits for a sandbox.
|
|
19
|
+
*/
|
|
20
|
+
export interface ResourceLimits {
|
|
21
|
+
cpuCount?: number;
|
|
22
|
+
memoryMiB?: number;
|
|
23
|
+
diskGiB?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Image specification for sandbox creation.
|
|
27
|
+
*/
|
|
28
|
+
export interface ImageSpec {
|
|
29
|
+
repository: string;
|
|
30
|
+
tag?: string;
|
|
31
|
+
digest?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Network policy for sandbox.
|
|
35
|
+
*/
|
|
36
|
+
export interface NetworkPolicy {
|
|
37
|
+
allowEgress?: boolean;
|
|
38
|
+
allowedHosts?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Configuration for creating a sandbox.
|
|
42
|
+
*/
|
|
43
|
+
export interface SandboxConfig {
|
|
44
|
+
/** Container image specification */
|
|
45
|
+
image: ImageSpec;
|
|
46
|
+
/** Entrypoint command */
|
|
47
|
+
entrypoint?: string[];
|
|
48
|
+
/** Timeout in seconds (0 for no timeout) */
|
|
49
|
+
timeout?: number;
|
|
50
|
+
/** Resource limits */
|
|
51
|
+
resourceLimits?: ResourceLimits;
|
|
52
|
+
/** Environment variables */
|
|
53
|
+
env?: Record<string, string>;
|
|
54
|
+
/** Metadata for the sandbox */
|
|
55
|
+
metadata?: Record<string, any>;
|
|
56
|
+
/** Network access policy */
|
|
57
|
+
networkPolicy?: NetworkPolicy;
|
|
58
|
+
/** Provider-specific extensions */
|
|
59
|
+
extensions?: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Information about a sandbox.
|
|
63
|
+
*/
|
|
64
|
+
export interface SandboxInfo {
|
|
65
|
+
id: SandboxId;
|
|
66
|
+
image: ImageSpec;
|
|
67
|
+
entrypoint: string[];
|
|
68
|
+
metadata?: Record<string, string>;
|
|
69
|
+
status: SandboxStatus;
|
|
70
|
+
createdAt: Date;
|
|
71
|
+
expiresAt?: Date;
|
|
72
|
+
resourceLimits?: ResourceLimits;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sandbox metrics.
|
|
76
|
+
*/
|
|
77
|
+
export interface SandboxMetrics {
|
|
78
|
+
cpuCount: number;
|
|
79
|
+
cpuUsedPercentage: number;
|
|
80
|
+
memoryTotalMiB: number;
|
|
81
|
+
memoryUsedMiB: number;
|
|
82
|
+
timestamp: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Endpoint information for accessing sandbox services.
|
|
86
|
+
*/
|
|
87
|
+
export interface Endpoint {
|
|
88
|
+
host: string;
|
|
89
|
+
port: number;
|
|
90
|
+
protocol: 'http' | 'https';
|
|
91
|
+
url: string;
|
|
92
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64 encoding/decoding utilities.
|
|
3
|
+
* Works in both Node.js and browser environments.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Encode a Uint8Array to base64 string.
|
|
7
|
+
*/
|
|
8
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
9
|
+
/**
|
|
10
|
+
* Decode a base64 string to Uint8Array.
|
|
11
|
+
*/
|
|
12
|
+
export declare function base64ToBytes(base64: string): Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* Encode a string to base64.
|
|
15
|
+
*/
|
|
16
|
+
export declare function stringToBase64(str: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Decode a base64 string to utf-8 string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function base64ToString(base64: string): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream utilities for working with ReadableStream and AsyncIterable.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Convert an AsyncIterable to a Uint8Array.
|
|
6
|
+
* Collects all chunks into a single buffer.
|
|
7
|
+
*/
|
|
8
|
+
export declare function asyncIterableToBuffer(iterable: AsyncIterable<Uint8Array>): Promise<Uint8Array>;
|
|
9
|
+
/**
|
|
10
|
+
* Convert a Uint8Array to a ReadableStream.
|
|
11
|
+
*/
|
|
12
|
+
export declare function bufferToReadableStream(buffer: Uint8Array): ReadableStream<Uint8Array>;
|
|
13
|
+
/**
|
|
14
|
+
* Convert a string to a ReadableStream.
|
|
15
|
+
*/
|
|
16
|
+
export declare function stringToReadableStream(str: string): ReadableStream<Uint8Array>;
|
|
17
|
+
/**
|
|
18
|
+
* Convert a ReadableStream to an AsyncIterable.
|
|
19
|
+
* (Native ReadableStream is already async iterable in modern environments,
|
|
20
|
+
* but this ensures compatibility.)
|
|
21
|
+
*/
|
|
22
|
+
export declare function readableStreamToAsyncIterable(stream: ReadableStream<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
23
|
+
/**
|
|
24
|
+
* Read a stream and convert to string.
|
|
25
|
+
*/
|
|
26
|
+
export declare function streamToString(stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>): Promise<string>;
|