@drej/opensandbox 0.1.2
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/dist/control.d.ts +28 -0
- package/dist/exec.d.ts +41 -0
- package/dist/index.d.ts +4 -0
- package/dist/types.d.ts +162 -0
- package/package.json +18 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Sandbox, CreateSandboxOptions, ListSandboxesOptions, Snapshot, ListSnapshotsOptions, SandboxEndpoint, DiagnosticLog, DiagnosticEvent } from "./types";
|
|
2
|
+
export declare class OpenSandboxError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
constructor(message: string, status: number);
|
|
5
|
+
}
|
|
6
|
+
export declare class ControlClient {
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private apiKey;
|
|
9
|
+
constructor(options: {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
});
|
|
13
|
+
private request;
|
|
14
|
+
createSandbox(options: CreateSandboxOptions): Promise<Sandbox>;
|
|
15
|
+
listSandboxes(options?: ListSandboxesOptions): Promise<Sandbox[]>;
|
|
16
|
+
getSandbox(id: string): Promise<Sandbox>;
|
|
17
|
+
deleteSandbox(id: string): Promise<void>;
|
|
18
|
+
pauseSandbox(id: string): Promise<void>;
|
|
19
|
+
resumeSandbox(id: string): Promise<void>;
|
|
20
|
+
renewExpiration(id: string): Promise<void>;
|
|
21
|
+
getEndpoint(sandboxId: string, port: number): Promise<SandboxEndpoint>;
|
|
22
|
+
getDiagnosticLogs(sandboxId: string): Promise<DiagnosticLog[]>;
|
|
23
|
+
getDiagnosticEvents(sandboxId: string): Promise<DiagnosticEvent[]>;
|
|
24
|
+
createSnapshot(sandboxId: string): Promise<Snapshot>;
|
|
25
|
+
listSnapshots(options?: ListSnapshotsOptions): Promise<Snapshot[]>;
|
|
26
|
+
getSnapshot(id: string): Promise<Snapshot>;
|
|
27
|
+
deleteSnapshot(id: string): Promise<void>;
|
|
28
|
+
}
|
package/dist/exec.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { SSEEvent, CodeContext, ExecuteCodeOptions, ExecuteCommandOptions, CommandStatus, FileInfo, FileReplacement, DirectoryEntry, Metrics } from "./types";
|
|
2
|
+
export declare class ExecClient {
|
|
3
|
+
private baseUrl;
|
|
4
|
+
private accessToken;
|
|
5
|
+
constructor(options: {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
accessToken: string;
|
|
8
|
+
});
|
|
9
|
+
private get authHeader();
|
|
10
|
+
private request;
|
|
11
|
+
private streamRequest;
|
|
12
|
+
ping(): Promise<{
|
|
13
|
+
status: string;
|
|
14
|
+
}>;
|
|
15
|
+
listContexts(language?: string): Promise<CodeContext[]>;
|
|
16
|
+
clearContexts(language?: string): Promise<void>;
|
|
17
|
+
deleteContext(contextId: string): Promise<void>;
|
|
18
|
+
createContext(language: string): Promise<CodeContext>;
|
|
19
|
+
executeCode(options: ExecuteCodeOptions): AsyncGenerator<SSEEvent>;
|
|
20
|
+
interruptCode(): Promise<void>;
|
|
21
|
+
executeCommand(options: ExecuteCommandOptions): AsyncGenerator<SSEEvent>;
|
|
22
|
+
interruptCommand(): Promise<void>;
|
|
23
|
+
getCommandStatus(session: string): Promise<CommandStatus>;
|
|
24
|
+
getCommandOutput(session: string): Promise<{
|
|
25
|
+
stdout: string;
|
|
26
|
+
stderr: string;
|
|
27
|
+
}>;
|
|
28
|
+
getFileInfo(path: string): Promise<FileInfo>;
|
|
29
|
+
deleteFile(path: string): Promise<void>;
|
|
30
|
+
setPermissions(path: string, mode: string): Promise<void>;
|
|
31
|
+
moveFile(from: string, to: string): Promise<void>;
|
|
32
|
+
searchFiles(pattern: string, dir?: string): Promise<string[]>;
|
|
33
|
+
replaceInFiles(replacements: FileReplacement[]): Promise<void>;
|
|
34
|
+
uploadFile(path: string, content: Blob | BufferSource | string): Promise<void>;
|
|
35
|
+
downloadFile(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
36
|
+
listDirectory(path: string, depth?: number): Promise<DirectoryEntry[]>;
|
|
37
|
+
createDirectory(path: string): Promise<void>;
|
|
38
|
+
deleteDirectory(path: string): Promise<void>;
|
|
39
|
+
getMetrics(): Promise<Metrics>;
|
|
40
|
+
watchMetrics(): AsyncGenerator<SSEEvent>;
|
|
41
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ControlClient, OpenSandboxError } from "./control";
|
|
2
|
+
export { ExecClient } from "./exec";
|
|
3
|
+
export { SandboxState, SnapshotState, SSEEventType } from "./types";
|
|
4
|
+
export type { Resources, ImageAuth, ImageSpec, Sandbox, SandboxStatus, CreateSandboxOptions, ListSandboxesOptions, Snapshot, ListSnapshotsOptions, SandboxEndpoint, DiagnosticLog, DiagnosticEvent, SSEEvent, CodeContext, ExecuteCodeOptions, ExecuteCommandOptions, CommandStatus, FileInfo, FileReplacement, DirectoryEntry, Metrics, } from "./types";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export interface Resources {
|
|
2
|
+
cpu?: string;
|
|
3
|
+
memory?: string;
|
|
4
|
+
gpu?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ImageAuth {
|
|
7
|
+
username: string;
|
|
8
|
+
password: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ImageSpec {
|
|
11
|
+
uri: string;
|
|
12
|
+
auth?: ImageAuth;
|
|
13
|
+
}
|
|
14
|
+
export declare enum SandboxState {
|
|
15
|
+
Pending = "Pending",
|
|
16
|
+
Running = "Running",
|
|
17
|
+
Pausing = "Pausing",
|
|
18
|
+
Paused = "Paused",
|
|
19
|
+
Resuming = "Resuming",
|
|
20
|
+
Stopping = "Stopping",
|
|
21
|
+
Terminated = "Terminated",
|
|
22
|
+
Failed = "Failed",
|
|
23
|
+
Unknown = "Unknown"
|
|
24
|
+
}
|
|
25
|
+
export interface SandboxStatus {
|
|
26
|
+
state: SandboxState;
|
|
27
|
+
reason?: string;
|
|
28
|
+
message?: string;
|
|
29
|
+
lastTransitionAt?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface Sandbox {
|
|
32
|
+
id: string;
|
|
33
|
+
status: SandboxStatus;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
expiresAt?: string | null;
|
|
36
|
+
image?: ImageSpec;
|
|
37
|
+
snapshotId?: string;
|
|
38
|
+
entrypoint?: string[];
|
|
39
|
+
metadata?: Record<string, string>;
|
|
40
|
+
platform?: unknown;
|
|
41
|
+
}
|
|
42
|
+
export interface CreateSandboxOptions {
|
|
43
|
+
image?: ImageSpec;
|
|
44
|
+
snapshotId?: string;
|
|
45
|
+
timeout?: number;
|
|
46
|
+
resourceLimits?: Resources;
|
|
47
|
+
entrypoint?: string[];
|
|
48
|
+
env?: Record<string, string>;
|
|
49
|
+
metadata?: Record<string, string>;
|
|
50
|
+
secureAccess?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface ListSandboxesOptions {
|
|
53
|
+
state?: SandboxState;
|
|
54
|
+
limit?: number;
|
|
55
|
+
offset?: number;
|
|
56
|
+
}
|
|
57
|
+
export declare enum SnapshotState {
|
|
58
|
+
Pending = "Pending",
|
|
59
|
+
Committing = "Committing",
|
|
60
|
+
Pushing = "Pushing",
|
|
61
|
+
Ready = "Ready",
|
|
62
|
+
Failed = "Failed"
|
|
63
|
+
}
|
|
64
|
+
export interface Snapshot {
|
|
65
|
+
id: string;
|
|
66
|
+
sandboxId: string;
|
|
67
|
+
state: SnapshotState;
|
|
68
|
+
createdAt: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ListSnapshotsOptions {
|
|
71
|
+
sandboxId?: string;
|
|
72
|
+
limit?: number;
|
|
73
|
+
offset?: number;
|
|
74
|
+
}
|
|
75
|
+
export interface SandboxEndpoint {
|
|
76
|
+
endpoint: string;
|
|
77
|
+
headers?: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
export interface DiagnosticLog {
|
|
80
|
+
name: string;
|
|
81
|
+
size: number;
|
|
82
|
+
url?: string;
|
|
83
|
+
inline?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface DiagnosticEvent {
|
|
86
|
+
timestamp: string;
|
|
87
|
+
type: string;
|
|
88
|
+
message: string;
|
|
89
|
+
}
|
|
90
|
+
export declare enum SSEEventType {
|
|
91
|
+
Init = "init",
|
|
92
|
+
Status = "status",
|
|
93
|
+
Stdout = "stdout",
|
|
94
|
+
Stderr = "stderr",
|
|
95
|
+
Result = "result",
|
|
96
|
+
ExecutionComplete = "execution_complete",
|
|
97
|
+
ExecutionCount = "execution_count",
|
|
98
|
+
Error = "error",
|
|
99
|
+
Ping = "ping",
|
|
100
|
+
Message = "message"
|
|
101
|
+
}
|
|
102
|
+
export interface SSEEvent {
|
|
103
|
+
type: SSEEventType;
|
|
104
|
+
text?: string;
|
|
105
|
+
results?: Record<string, string>;
|
|
106
|
+
error?: {
|
|
107
|
+
name?: string;
|
|
108
|
+
message: string;
|
|
109
|
+
evalue?: string;
|
|
110
|
+
};
|
|
111
|
+
execution_count?: number;
|
|
112
|
+
execution_time?: number;
|
|
113
|
+
timestamp: number;
|
|
114
|
+
}
|
|
115
|
+
export interface CodeContext {
|
|
116
|
+
id: string;
|
|
117
|
+
language: string;
|
|
118
|
+
}
|
|
119
|
+
export interface ExecuteCodeOptions {
|
|
120
|
+
code: string;
|
|
121
|
+
context?: {
|
|
122
|
+
id: string;
|
|
123
|
+
language: string;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export interface ExecuteCommandOptions {
|
|
127
|
+
command: string;
|
|
128
|
+
cwd?: string;
|
|
129
|
+
background?: boolean;
|
|
130
|
+
timeout?: number;
|
|
131
|
+
uid?: number;
|
|
132
|
+
gid?: number;
|
|
133
|
+
envs?: Record<string, string>;
|
|
134
|
+
}
|
|
135
|
+
export interface CommandStatus {
|
|
136
|
+
session: string;
|
|
137
|
+
status: "running" | "completed" | "failed";
|
|
138
|
+
exitCode?: number;
|
|
139
|
+
}
|
|
140
|
+
export interface FileInfo {
|
|
141
|
+
path: string;
|
|
142
|
+
size: number;
|
|
143
|
+
mode: string;
|
|
144
|
+
modifiedAt: string;
|
|
145
|
+
isDirectory: boolean;
|
|
146
|
+
}
|
|
147
|
+
export interface DirectoryEntry {
|
|
148
|
+
name: string;
|
|
149
|
+
path: string;
|
|
150
|
+
isDirectory: boolean;
|
|
151
|
+
size?: number;
|
|
152
|
+
}
|
|
153
|
+
export interface FileReplacement {
|
|
154
|
+
path: string;
|
|
155
|
+
old: string;
|
|
156
|
+
new: string;
|
|
157
|
+
}
|
|
158
|
+
export interface Metrics {
|
|
159
|
+
cpu: number;
|
|
160
|
+
memory: number;
|
|
161
|
+
timestamp: string;
|
|
162
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@drej/opensandbox",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"main": "./src/index.ts",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"publishConfig": { "access": "public" },
|
|
10
|
+
"scripts": {
|
|
11
|
+
"typecheck": "bunx tsc --noEmit",
|
|
12
|
+
"build:types": "tsc --project tsconfig.build.json"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"bun-types": "latest",
|
|
16
|
+
"typescript": "latest"
|
|
17
|
+
}
|
|
18
|
+
}
|