@hyperbrowser/sdk 0.84.0 → 0.85.0
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 +103 -0
- package/dist/client.d.ts +20 -2
- package/dist/client.js +12 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -3
- package/dist/sandbox/base.d.ts +28 -0
- package/dist/sandbox/base.js +242 -0
- package/dist/sandbox/files.d.ts +92 -0
- package/dist/sandbox/files.js +508 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/index.js +15 -0
- package/dist/sandbox/process.d.ts +25 -0
- package/dist/sandbox/process.js +230 -0
- package/dist/sandbox/terminal.d.ts +45 -0
- package/dist/sandbox/terminal.js +217 -0
- package/dist/sandbox/ws.d.ts +18 -0
- package/dist/sandbox/ws.js +188 -0
- package/dist/services/base.js +43 -3
- package/dist/services/sandboxes.d.ts +56 -0
- package/dist/services/sandboxes.js +273 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/sandbox.d.ts +270 -0
- package/dist/types/sandbox.js +2 -0
- package/package.json +9 -3
package/dist/services/base.js
CHANGED
|
@@ -6,6 +6,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BaseService = void 0;
|
|
7
7
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
8
|
const client_1 = require("../client");
|
|
9
|
+
const RETRYABLE_STATUS_CODES = new Set([429, 502, 503, 504]);
|
|
10
|
+
const RETRYABLE_NETWORK_CODES = new Set([
|
|
11
|
+
"ECONNRESET",
|
|
12
|
+
"ECONNREFUSED",
|
|
13
|
+
"EAI_AGAIN",
|
|
14
|
+
"ETIMEDOUT",
|
|
15
|
+
"ESOCKETTIMEDOUT",
|
|
16
|
+
]);
|
|
17
|
+
const getRequestId = (response) => {
|
|
18
|
+
return response.headers.get("x-request-id") || response.headers.get("request-id") || undefined;
|
|
19
|
+
};
|
|
20
|
+
const isRetryableNetworkError = (error) => {
|
|
21
|
+
if (!(error instanceof Error)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const networkError = error;
|
|
25
|
+
return (networkError.name === "AbortError" ||
|
|
26
|
+
networkError.type === "request-timeout" ||
|
|
27
|
+
(networkError.code ? RETRYABLE_NETWORK_CODES.has(networkError.code) : false));
|
|
28
|
+
};
|
|
9
29
|
class BaseService {
|
|
10
30
|
constructor(apiKey, baseUrl, timeout = 30000) {
|
|
11
31
|
this.apiKey = apiKey;
|
|
@@ -44,15 +64,26 @@ class BaseService {
|
|
|
44
64
|
});
|
|
45
65
|
if (!response.ok) {
|
|
46
66
|
let errorMessage;
|
|
67
|
+
let errorDetails;
|
|
68
|
+
let errorCode;
|
|
47
69
|
try {
|
|
48
70
|
const errorData = await response.json();
|
|
71
|
+
errorDetails = errorData;
|
|
72
|
+
errorCode = typeof errorData?.code === "string" ? errorData.code : undefined;
|
|
49
73
|
errorMessage =
|
|
50
74
|
errorData.message || errorData.error || `HTTP error! status: ${response.status}`;
|
|
51
75
|
}
|
|
52
76
|
catch {
|
|
53
77
|
errorMessage = `HTTP error! status: ${response.status}`;
|
|
54
78
|
}
|
|
55
|
-
throw new client_1.HyperbrowserError(errorMessage,
|
|
79
|
+
throw new client_1.HyperbrowserError(errorMessage, {
|
|
80
|
+
statusCode: response.status,
|
|
81
|
+
code: errorCode,
|
|
82
|
+
requestId: getRequestId(response),
|
|
83
|
+
retryable: RETRYABLE_STATUS_CODES.has(response.status),
|
|
84
|
+
service: "control",
|
|
85
|
+
details: errorDetails,
|
|
86
|
+
});
|
|
56
87
|
}
|
|
57
88
|
if (response.headers.get("content-length") === "0") {
|
|
58
89
|
return {};
|
|
@@ -61,14 +92,23 @@ class BaseService {
|
|
|
61
92
|
return (await response.json());
|
|
62
93
|
}
|
|
63
94
|
catch {
|
|
64
|
-
throw new client_1.HyperbrowserError("Failed to parse JSON response",
|
|
95
|
+
throw new client_1.HyperbrowserError("Failed to parse JSON response", {
|
|
96
|
+
statusCode: response.status,
|
|
97
|
+
requestId: getRequestId(response),
|
|
98
|
+
retryable: false,
|
|
99
|
+
service: "control",
|
|
100
|
+
});
|
|
65
101
|
}
|
|
66
102
|
}
|
|
67
103
|
catch (error) {
|
|
68
104
|
if (error instanceof client_1.HyperbrowserError) {
|
|
69
105
|
throw error;
|
|
70
106
|
}
|
|
71
|
-
throw new client_1.HyperbrowserError(error instanceof Error ? error.message : "Unknown error occurred",
|
|
107
|
+
throw new client_1.HyperbrowserError(error instanceof Error ? error.message : "Unknown error occurred", {
|
|
108
|
+
retryable: isRetryableNetworkError(error),
|
|
109
|
+
service: "control",
|
|
110
|
+
cause: error,
|
|
111
|
+
});
|
|
72
112
|
}
|
|
73
113
|
}
|
|
74
114
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SandboxFilesApi } from "../sandbox/files";
|
|
2
|
+
import { SandboxProcessHandle, SandboxProcessesApi } from "../sandbox/process";
|
|
3
|
+
import { SandboxTerminalApi } from "../sandbox/terminal";
|
|
4
|
+
import { BasicResponse } from "../types/session";
|
|
5
|
+
import { CreateSandboxParams, SandboxDetail, SandboxExposeParams, SandboxExposeResult, SandboxExecParams, SandboxMemorySnapshotParams, SandboxMemorySnapshotResult, SandboxProcessResult, SandboxRuntimeTarget } from "../types/sandbox";
|
|
6
|
+
import { BaseService } from "./base";
|
|
7
|
+
export declare class SandboxHandle {
|
|
8
|
+
private readonly service;
|
|
9
|
+
readonly processes: SandboxProcessesApi;
|
|
10
|
+
readonly files: SandboxFilesApi;
|
|
11
|
+
readonly terminal: SandboxTerminalApi;
|
|
12
|
+
readonly pty: SandboxTerminalApi;
|
|
13
|
+
private readonly transport;
|
|
14
|
+
private detail;
|
|
15
|
+
private runtimeSession;
|
|
16
|
+
constructor(service: SandboxesService, detail: SandboxDetail);
|
|
17
|
+
get id(): string;
|
|
18
|
+
get status(): SandboxDetail["status"];
|
|
19
|
+
get region(): SandboxDetail["region"];
|
|
20
|
+
get runtime(): SandboxDetail["runtime"];
|
|
21
|
+
get tokenExpiresAt(): string | null;
|
|
22
|
+
get sessionUrl(): string;
|
|
23
|
+
toJSON(): SandboxDetail;
|
|
24
|
+
info(): Promise<SandboxDetail>;
|
|
25
|
+
refresh(): Promise<SandboxHandle>;
|
|
26
|
+
connect(): Promise<SandboxHandle>;
|
|
27
|
+
stop(): Promise<BasicResponse>;
|
|
28
|
+
createMemorySnapshot(params?: SandboxMemorySnapshotParams): Promise<SandboxMemorySnapshotResult>;
|
|
29
|
+
expose(params: SandboxExposeParams): Promise<SandboxExposeResult>;
|
|
30
|
+
getExposedUrl(port: number): string;
|
|
31
|
+
exec(input: string | SandboxExecParams): Promise<SandboxProcessResult>;
|
|
32
|
+
getProcess(processId: string): Promise<SandboxProcessHandle>;
|
|
33
|
+
private hydrate;
|
|
34
|
+
private resolveRuntimeConnection;
|
|
35
|
+
private resolveRuntimeSocketConnectionInfo;
|
|
36
|
+
private isRuntimeSessionExpiring;
|
|
37
|
+
private ensureRuntimeSession;
|
|
38
|
+
private applyRuntimeSession;
|
|
39
|
+
private clearRuntimeSession;
|
|
40
|
+
private assertRuntimeAvailable;
|
|
41
|
+
private static toRuntimeSession;
|
|
42
|
+
}
|
|
43
|
+
export declare class SandboxesService extends BaseService {
|
|
44
|
+
readonly runtimeTimeout: number;
|
|
45
|
+
readonly runtimeProxyOverride?: string;
|
|
46
|
+
constructor(apiKey: string, baseUrl: string, timeout: number, runtimeProxyOverride?: string);
|
|
47
|
+
create(params: CreateSandboxParams): Promise<SandboxHandle>;
|
|
48
|
+
get(id: string): Promise<SandboxHandle>;
|
|
49
|
+
connect(id: string): Promise<SandboxHandle>;
|
|
50
|
+
stop(id: string): Promise<BasicResponse>;
|
|
51
|
+
getDetail(id: string): Promise<SandboxDetail>;
|
|
52
|
+
attach(detail: SandboxDetail): SandboxHandle;
|
|
53
|
+
createMemorySnapshot(id: string, params?: SandboxMemorySnapshotParams): Promise<SandboxMemorySnapshotResult>;
|
|
54
|
+
expose(id: string, params: SandboxExposeParams, runtime?: SandboxRuntimeTarget): Promise<SandboxExposeResult>;
|
|
55
|
+
private createDetail;
|
|
56
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxesService = exports.SandboxHandle = void 0;
|
|
4
|
+
const client_1 = require("../client");
|
|
5
|
+
const files_1 = require("../sandbox/files");
|
|
6
|
+
const base_1 = require("../sandbox/base");
|
|
7
|
+
const process_1 = require("../sandbox/process");
|
|
8
|
+
const terminal_1 = require("../sandbox/terminal");
|
|
9
|
+
const base_2 = require("./base");
|
|
10
|
+
const RUNTIME_SESSION_REFRESH_BUFFER_MS = 60000;
|
|
11
|
+
const buildSandboxExposedUrl = (runtime, port) => {
|
|
12
|
+
const url = new URL(runtime.baseUrl);
|
|
13
|
+
url.hostname = `${port}-${url.hostname}`;
|
|
14
|
+
return url.toString().replace(/\/$/, "");
|
|
15
|
+
};
|
|
16
|
+
class SandboxHandle {
|
|
17
|
+
constructor(service, detail) {
|
|
18
|
+
this.service = service;
|
|
19
|
+
this.detail = detail;
|
|
20
|
+
this.runtimeSession = SandboxHandle.toRuntimeSession(detail);
|
|
21
|
+
this.transport = new base_1.RuntimeTransport((forceRefresh) => this.resolveRuntimeConnection(forceRefresh), service.runtimeTimeout, service.runtimeProxyOverride);
|
|
22
|
+
this.processes = new process_1.SandboxProcessesApi(this.transport);
|
|
23
|
+
this.files = new files_1.SandboxFilesApi(this.transport, () => this.resolveRuntimeSocketConnectionInfo(), service.runtimeProxyOverride);
|
|
24
|
+
this.terminal = new terminal_1.SandboxTerminalApi(this.transport, () => this.resolveRuntimeSocketConnectionInfo(), service.runtimeProxyOverride);
|
|
25
|
+
this.pty = this.terminal;
|
|
26
|
+
}
|
|
27
|
+
get id() {
|
|
28
|
+
return this.detail.id;
|
|
29
|
+
}
|
|
30
|
+
get status() {
|
|
31
|
+
return this.detail.status;
|
|
32
|
+
}
|
|
33
|
+
get region() {
|
|
34
|
+
return this.detail.region;
|
|
35
|
+
}
|
|
36
|
+
get runtime() {
|
|
37
|
+
return this.detail.runtime;
|
|
38
|
+
}
|
|
39
|
+
get tokenExpiresAt() {
|
|
40
|
+
return this.detail.tokenExpiresAt;
|
|
41
|
+
}
|
|
42
|
+
get sessionUrl() {
|
|
43
|
+
return this.detail.sessionUrl;
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return { ...this.detail };
|
|
47
|
+
}
|
|
48
|
+
async info() {
|
|
49
|
+
const detail = await this.service.getDetail(this.id);
|
|
50
|
+
this.hydrate(detail);
|
|
51
|
+
return this.toJSON();
|
|
52
|
+
}
|
|
53
|
+
async refresh() {
|
|
54
|
+
await this.info();
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
async connect() {
|
|
58
|
+
await this.ensureRuntimeSession(true);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
async stop() {
|
|
62
|
+
const response = await this.service.stop(this.id);
|
|
63
|
+
this.clearRuntimeSession("closed");
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
async createMemorySnapshot(params = {}) {
|
|
67
|
+
return this.service.createMemorySnapshot(this.id, params);
|
|
68
|
+
}
|
|
69
|
+
async expose(params) {
|
|
70
|
+
return this.service.expose(this.id, params, this.runtime);
|
|
71
|
+
}
|
|
72
|
+
getExposedUrl(port) {
|
|
73
|
+
return buildSandboxExposedUrl(this.runtime, port);
|
|
74
|
+
}
|
|
75
|
+
async exec(input) {
|
|
76
|
+
const params = typeof input === "string"
|
|
77
|
+
? {
|
|
78
|
+
command: input,
|
|
79
|
+
}
|
|
80
|
+
: input;
|
|
81
|
+
return this.processes.exec(params);
|
|
82
|
+
}
|
|
83
|
+
async getProcess(processId) {
|
|
84
|
+
return this.processes.get(processId);
|
|
85
|
+
}
|
|
86
|
+
hydrate(detail) {
|
|
87
|
+
this.detail = detail;
|
|
88
|
+
this.runtimeSession = SandboxHandle.toRuntimeSession(detail);
|
|
89
|
+
}
|
|
90
|
+
async resolveRuntimeConnection(forceRefresh = false) {
|
|
91
|
+
const session = await this.ensureRuntimeSession(forceRefresh);
|
|
92
|
+
return {
|
|
93
|
+
sandboxId: this.id,
|
|
94
|
+
baseUrl: session.runtime.baseUrl,
|
|
95
|
+
token: session.token,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async resolveRuntimeSocketConnectionInfo() {
|
|
99
|
+
const session = await this.ensureRuntimeSession();
|
|
100
|
+
return {
|
|
101
|
+
sandboxId: this.id,
|
|
102
|
+
baseUrl: session.runtime.baseUrl,
|
|
103
|
+
token: session.token,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
isRuntimeSessionExpiring() {
|
|
107
|
+
if (!this.runtimeSession?.tokenExpiresAt) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const expiresAt = Date.parse(this.runtimeSession.tokenExpiresAt);
|
|
111
|
+
if (Number.isNaN(expiresAt)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return expiresAt - Date.now() <= RUNTIME_SESSION_REFRESH_BUFFER_MS;
|
|
115
|
+
}
|
|
116
|
+
async ensureRuntimeSession(forceRefresh = false) {
|
|
117
|
+
this.assertRuntimeAvailable();
|
|
118
|
+
if (!forceRefresh && this.runtimeSession && !this.isRuntimeSessionExpiring()) {
|
|
119
|
+
return { ...this.runtimeSession };
|
|
120
|
+
}
|
|
121
|
+
const detail = await this.service.getDetail(this.id);
|
|
122
|
+
this.hydrate(detail);
|
|
123
|
+
if (!this.runtimeSession) {
|
|
124
|
+
throw new client_1.HyperbrowserError(`Sandbox ${this.id} is not running`, {
|
|
125
|
+
statusCode: 409,
|
|
126
|
+
code: "sandbox_not_running",
|
|
127
|
+
retryable: false,
|
|
128
|
+
service: "runtime",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return { ...this.runtimeSession };
|
|
132
|
+
}
|
|
133
|
+
applyRuntimeSession(session) {
|
|
134
|
+
this.runtimeSession = { ...session };
|
|
135
|
+
this.detail = {
|
|
136
|
+
...this.detail,
|
|
137
|
+
status: session.status,
|
|
138
|
+
region: session.region,
|
|
139
|
+
runtime: session.runtime,
|
|
140
|
+
token: session.token,
|
|
141
|
+
tokenExpiresAt: session.tokenExpiresAt,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
clearRuntimeSession(status = this.detail.status) {
|
|
145
|
+
this.runtimeSession = null;
|
|
146
|
+
this.detail = {
|
|
147
|
+
...this.detail,
|
|
148
|
+
status,
|
|
149
|
+
token: null,
|
|
150
|
+
tokenExpiresAt: null,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
assertRuntimeAvailable() {
|
|
154
|
+
if (this.detail.status === "closed" || this.detail.status === "error") {
|
|
155
|
+
throw new client_1.HyperbrowserError(`Sandbox ${this.id} is not running`, {
|
|
156
|
+
statusCode: 409,
|
|
157
|
+
code: "sandbox_not_running",
|
|
158
|
+
retryable: false,
|
|
159
|
+
service: "runtime",
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
static toRuntimeSession(detail) {
|
|
164
|
+
if (!detail.token) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
sandboxId: detail.id,
|
|
169
|
+
status: detail.status,
|
|
170
|
+
region: detail.region,
|
|
171
|
+
token: detail.token,
|
|
172
|
+
tokenExpiresAt: detail.tokenExpiresAt,
|
|
173
|
+
runtime: detail.runtime,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.SandboxHandle = SandboxHandle;
|
|
178
|
+
class SandboxesService extends base_2.BaseService {
|
|
179
|
+
constructor(apiKey, baseUrl, timeout, runtimeProxyOverride) {
|
|
180
|
+
super(apiKey, baseUrl, timeout);
|
|
181
|
+
this.runtimeTimeout = timeout;
|
|
182
|
+
this.runtimeProxyOverride = runtimeProxyOverride;
|
|
183
|
+
}
|
|
184
|
+
async create(params) {
|
|
185
|
+
const detail = await this.createDetail(params);
|
|
186
|
+
return this.attach(detail);
|
|
187
|
+
}
|
|
188
|
+
async get(id) {
|
|
189
|
+
const detail = await this.getDetail(id);
|
|
190
|
+
return this.attach(detail);
|
|
191
|
+
}
|
|
192
|
+
async connect(id) {
|
|
193
|
+
const handle = await this.get(id);
|
|
194
|
+
await handle.connect();
|
|
195
|
+
return handle;
|
|
196
|
+
}
|
|
197
|
+
async stop(id) {
|
|
198
|
+
try {
|
|
199
|
+
return await this.request(`/sandbox/${id}/stop`, {
|
|
200
|
+
method: "PUT",
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
throw new client_1.HyperbrowserError(`Failed to stop sandbox ${id}`, undefined);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async getDetail(id) {
|
|
211
|
+
try {
|
|
212
|
+
return await this.request(`/sandbox/${id}`);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
throw new client_1.HyperbrowserError(`Failed to get sandbox ${id}`, undefined);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
attach(detail) {
|
|
222
|
+
return new SandboxHandle(this, detail);
|
|
223
|
+
}
|
|
224
|
+
async createMemorySnapshot(id, params = {}) {
|
|
225
|
+
try {
|
|
226
|
+
return await this.request(`/sandbox/${id}/snapshot`, {
|
|
227
|
+
method: "POST",
|
|
228
|
+
body: JSON.stringify(params),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
throw new client_1.HyperbrowserError(`Failed to create memory snapshot for sandbox ${id}`, undefined);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async expose(id, params, runtime) {
|
|
239
|
+
try {
|
|
240
|
+
const response = await this.request(`/sandbox/${id}/expose`, {
|
|
241
|
+
method: "POST",
|
|
242
|
+
body: JSON.stringify(params),
|
|
243
|
+
});
|
|
244
|
+
const targetRuntime = runtime ?? (await this.getDetail(id)).runtime;
|
|
245
|
+
return {
|
|
246
|
+
port: response.port,
|
|
247
|
+
auth: response.auth,
|
|
248
|
+
url: buildSandboxExposedUrl(targetRuntime, response.port),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
throw new client_1.HyperbrowserError(`Failed to expose port ${params.port} for sandbox ${id}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async createDetail(params) {
|
|
259
|
+
try {
|
|
260
|
+
return await this.request("/sandbox", {
|
|
261
|
+
method: "POST",
|
|
262
|
+
body: JSON.stringify(params),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
throw new client_1.HyperbrowserError("Failed to create sandbox", undefined);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.SandboxesService = SandboxesService;
|
package/dist/types/config.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { StartCuaTaskParams, StartCuaTaskResponse, CuaTaskStatusResponse, CuaTas
|
|
|
8
8
|
export { StartHyperAgentTaskParams, StartHyperAgentTaskResponse, HyperAgentTaskStatusResponse, HyperAgentTaskResponse, HyperAgentTaskData, HyperAgentStep, HyperAgentOutput, HyperAgentActionOutput, HyperAgentApiKeys, HyperAgentTaskMetadata, HyperAgentOutputV110, HyperAgentStepV110, } from "./agents/hyper-agent";
|
|
9
9
|
export { StartGeminiComputerUseTaskParams, StartGeminiComputerUseTaskResponse, GeminiComputerUseTaskStatusResponse, GeminiComputerUseTaskResponse, GeminiComputerUseTaskData, GeminiComputerUseStepResponse, GeminiComputerUseApiKeys, GeminiComputerUseTaskMetadata, } from "./agents/gemini-computer-use";
|
|
10
10
|
export { BasicResponse, SessionStatus, Session, SessionDetail, SessionGetParams, SessionListParams, SessionListResponse, ScreenConfig, CreateSessionParams, GetSessionDownloadsUrlResponse, GetSessionVideoRecordingUrlResponse, GetSessionRecordingUrlResponse, ImageCaptchaParam, UploadFileResponse, UploadFileOptions, GetActiveSessionsCountResponse, SessionEventLogListParams, SessionEventLogListResponse, SessionEventLog, SessionProfile, SessionLaunchState, UpdateSessionProfileParams, } from "./session";
|
|
11
|
+
export { SandboxStatus, SandboxRuntimeTarget, Sandbox, SandboxDetail, CreateSandboxParams, SandboxMemorySnapshotParams, SandboxMemorySnapshotResult, SandboxExposeParams, SandboxExposeResult, SandboxProcessStatus, SandboxExecParams, SandboxProcessSummary, SandboxProcessResult, SandboxProcessListParams, SandboxProcessListResponse, SandboxProcessWaitParams, SandboxProcessSignal, SandboxProcessStdinParams, SandboxProcessStreamEvent, SandboxFileType, SandboxFileInfo, SandboxFileWriteInfo, SandboxFileListOptions, SandboxFileReadFormat, SandboxFileReadOptions, SandboxFileWriteData, SandboxFileWriteEntry, SandboxFileTextWriteOptions, SandboxFileBytesWriteOptions, SandboxFileMakeDirOptions, SandboxFileCopyParams, SandboxFileChmodParams, SandboxFileChownParams, SandboxFileTransferResult, SandboxFileSystemEventType, SandboxFileSystemEvent, SandboxWatchDirOptions, SandboxPresignFileParams, SandboxPresignedUrl, SandboxTerminalCreateParams, SandboxTerminalOutputChunk, SandboxTerminalStatus, SandboxTerminalWaitParams, SandboxTerminalKillParams, SandboxTerminalEvent, } from "./sandbox";
|
|
11
12
|
export { CreateProfileParams, ProfileResponse, CreateProfileResponse, ProfileListParams, ProfileListResponse, } from "./profile";
|
|
12
13
|
export { CreateExtensionParams, CreateExtensionResponse, ListExtensionsResponse, } from "./extension";
|
|
13
14
|
export { ExtractJobStatus, BrowserUseTaskStatus, BrowserUseLlm, ClaudeComputerUseLlm, CuaLlm, GeminiComputerUseLlm, ScrapeScreenshotFormat, ScrapeJobStatus, CrawlJobStatus, Country, State, ISO639_1, OperatingSystem, Platform, ScrapeFormat, ScrapeWaitUntil, ScrapePageStatus, CrawlPageStatus, RecordingStatus, DownloadsStatus, HyperAgentLlm, HyperAgentTaskStatus, ClaudeComputerUseTaskStatus, CuaTaskStatus, GeminiComputerUseTaskStatus, SessionEventLogType, SessionRegion, BrowserUseVersion, HyperAgentVersion, } from "./constants";
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import type { Blob } from "buffer";
|
|
2
|
+
import type { ReadableStream } from "node:stream/web";
|
|
3
|
+
import { SessionRegion } from "./constants";
|
|
4
|
+
import { SessionLaunchState, SessionStatus } from "./session";
|
|
5
|
+
export type SandboxStatus = SessionStatus;
|
|
6
|
+
export interface SandboxRuntimeTarget {
|
|
7
|
+
transport: "regional_proxy";
|
|
8
|
+
host: string;
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
}
|
|
11
|
+
export interface Sandbox {
|
|
12
|
+
id: string;
|
|
13
|
+
teamId: string;
|
|
14
|
+
status: SandboxStatus;
|
|
15
|
+
endTime?: number | null;
|
|
16
|
+
startTime?: number | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
closeReason?: string | null;
|
|
20
|
+
dataConsumed?: number;
|
|
21
|
+
proxyDataConsumed?: number;
|
|
22
|
+
usageType?: string;
|
|
23
|
+
jobId?: string | null;
|
|
24
|
+
launchState?: SessionLaunchState | null;
|
|
25
|
+
creditsUsed: number | null;
|
|
26
|
+
region: SessionRegion;
|
|
27
|
+
sessionUrl: string;
|
|
28
|
+
duration: number;
|
|
29
|
+
proxyBytesUsed: number;
|
|
30
|
+
runtime: SandboxRuntimeTarget;
|
|
31
|
+
}
|
|
32
|
+
export interface SandboxDetail extends Sandbox {
|
|
33
|
+
token: string | null;
|
|
34
|
+
tokenExpiresAt: string | null;
|
|
35
|
+
}
|
|
36
|
+
interface SandboxCreateCommonParams {
|
|
37
|
+
region?: SessionRegion;
|
|
38
|
+
enableRecording?: boolean;
|
|
39
|
+
timeoutMinutes?: number;
|
|
40
|
+
}
|
|
41
|
+
export type CreateSandboxParams = (SandboxCreateCommonParams & {
|
|
42
|
+
snapshotName: string;
|
|
43
|
+
snapshotId?: string;
|
|
44
|
+
imageName?: never;
|
|
45
|
+
imageId?: never;
|
|
46
|
+
}) | (SandboxCreateCommonParams & {
|
|
47
|
+
snapshotName?: never;
|
|
48
|
+
snapshotId?: never;
|
|
49
|
+
imageName: string;
|
|
50
|
+
imageId?: string;
|
|
51
|
+
});
|
|
52
|
+
export interface SandboxMemorySnapshotParams {
|
|
53
|
+
snapshotName?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface SandboxMemorySnapshotResult {
|
|
56
|
+
snapshotName: string;
|
|
57
|
+
snapshotId: string;
|
|
58
|
+
namespace: string;
|
|
59
|
+
status: string;
|
|
60
|
+
imageName: string;
|
|
61
|
+
imageId: string;
|
|
62
|
+
imageNamespace: string;
|
|
63
|
+
}
|
|
64
|
+
export interface SandboxExposeParams {
|
|
65
|
+
port: number;
|
|
66
|
+
auth?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface SandboxExposeResult {
|
|
69
|
+
port: number;
|
|
70
|
+
auth: boolean;
|
|
71
|
+
url: string;
|
|
72
|
+
}
|
|
73
|
+
export type SandboxProcessStatus = "queued" | "running" | "exited" | "failed" | "killed" | "timed_out";
|
|
74
|
+
export interface SandboxExecParams {
|
|
75
|
+
command: string;
|
|
76
|
+
args?: string[];
|
|
77
|
+
cwd?: string;
|
|
78
|
+
env?: Record<string, string>;
|
|
79
|
+
timeoutMs?: number;
|
|
80
|
+
timeoutSec?: number;
|
|
81
|
+
useShell?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface SandboxProcessSummary {
|
|
84
|
+
id: string;
|
|
85
|
+
status: SandboxProcessStatus;
|
|
86
|
+
command: string;
|
|
87
|
+
args?: string[];
|
|
88
|
+
cwd: string;
|
|
89
|
+
pid?: number;
|
|
90
|
+
exitCode?: number | null;
|
|
91
|
+
startedAt: number;
|
|
92
|
+
completedAt?: number;
|
|
93
|
+
}
|
|
94
|
+
export interface SandboxProcessResult {
|
|
95
|
+
id: string;
|
|
96
|
+
status: SandboxProcessStatus;
|
|
97
|
+
exitCode?: number | null;
|
|
98
|
+
stdout: string;
|
|
99
|
+
stderr: string;
|
|
100
|
+
startedAt: number;
|
|
101
|
+
completedAt?: number;
|
|
102
|
+
error?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface SandboxProcessListParams {
|
|
105
|
+
status?: SandboxProcessStatus | SandboxProcessStatus[];
|
|
106
|
+
limit?: number;
|
|
107
|
+
cursor?: string | number;
|
|
108
|
+
createdAfter?: number;
|
|
109
|
+
createdBefore?: number;
|
|
110
|
+
}
|
|
111
|
+
export interface SandboxProcessListResponse {
|
|
112
|
+
data: SandboxProcessSummary[];
|
|
113
|
+
nextCursor?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface SandboxProcessWaitParams {
|
|
116
|
+
timeoutMs?: number;
|
|
117
|
+
timeoutSec?: number;
|
|
118
|
+
}
|
|
119
|
+
export type SandboxProcessSignal = "TERM" | "KILL" | "INT" | "HUP" | "QUIT" | string;
|
|
120
|
+
export interface SandboxProcessStdinParams {
|
|
121
|
+
data?: string | Uint8Array;
|
|
122
|
+
encoding?: "utf8" | "base64";
|
|
123
|
+
eof?: boolean;
|
|
124
|
+
}
|
|
125
|
+
export type SandboxProcessStreamEvent = {
|
|
126
|
+
type: "stdout" | "stderr" | "system";
|
|
127
|
+
seq: number;
|
|
128
|
+
data: string;
|
|
129
|
+
timestamp: number;
|
|
130
|
+
} | {
|
|
131
|
+
type: "exit";
|
|
132
|
+
result: SandboxProcessResult;
|
|
133
|
+
};
|
|
134
|
+
export type SandboxFileType = "file" | "dir";
|
|
135
|
+
export interface SandboxFileInfo {
|
|
136
|
+
path: string;
|
|
137
|
+
name: string;
|
|
138
|
+
type: SandboxFileType;
|
|
139
|
+
size: number;
|
|
140
|
+
mode: number;
|
|
141
|
+
permissions: string;
|
|
142
|
+
owner: string;
|
|
143
|
+
group: string;
|
|
144
|
+
modifiedTime?: Date;
|
|
145
|
+
symlinkTarget?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface SandboxFileWriteInfo {
|
|
148
|
+
path: string;
|
|
149
|
+
name: string;
|
|
150
|
+
type?: SandboxFileType;
|
|
151
|
+
}
|
|
152
|
+
export interface SandboxFileListOptions {
|
|
153
|
+
depth?: number;
|
|
154
|
+
}
|
|
155
|
+
export type SandboxFileReadFormat = "text" | "bytes" | "blob" | "stream";
|
|
156
|
+
export interface SandboxFileReadOptions {
|
|
157
|
+
offset?: number;
|
|
158
|
+
length?: number;
|
|
159
|
+
format?: SandboxFileReadFormat;
|
|
160
|
+
}
|
|
161
|
+
export type SandboxFileWriteData = string | Uint8Array | Buffer | ArrayBuffer | Blob | ReadableStream<Uint8Array>;
|
|
162
|
+
export interface SandboxFileWriteEntry {
|
|
163
|
+
path: string;
|
|
164
|
+
data: SandboxFileWriteData;
|
|
165
|
+
}
|
|
166
|
+
export interface SandboxFileTextWriteOptions {
|
|
167
|
+
append?: boolean;
|
|
168
|
+
mode?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface SandboxFileBytesWriteOptions {
|
|
171
|
+
append?: boolean;
|
|
172
|
+
mode?: string;
|
|
173
|
+
}
|
|
174
|
+
export interface SandboxFileRemoveOptions {
|
|
175
|
+
recursive?: boolean;
|
|
176
|
+
}
|
|
177
|
+
export interface SandboxFileMakeDirOptions {
|
|
178
|
+
parents?: boolean;
|
|
179
|
+
mode?: string;
|
|
180
|
+
}
|
|
181
|
+
export interface SandboxFileTransferResult {
|
|
182
|
+
path: string;
|
|
183
|
+
bytesWritten: number;
|
|
184
|
+
}
|
|
185
|
+
export interface SandboxFileCopyParams {
|
|
186
|
+
source: string;
|
|
187
|
+
destination: string;
|
|
188
|
+
recursive?: boolean;
|
|
189
|
+
overwrite?: boolean;
|
|
190
|
+
}
|
|
191
|
+
export interface SandboxFileChmodParams {
|
|
192
|
+
path: string;
|
|
193
|
+
mode: string;
|
|
194
|
+
recursive?: boolean;
|
|
195
|
+
}
|
|
196
|
+
export interface SandboxFileChownParams {
|
|
197
|
+
path: string;
|
|
198
|
+
uid?: number;
|
|
199
|
+
gid?: number;
|
|
200
|
+
recursive?: boolean;
|
|
201
|
+
}
|
|
202
|
+
export type SandboxFileSystemEventType = "chmod" | "create" | "remove" | "rename" | "write";
|
|
203
|
+
export interface SandboxFileSystemEvent {
|
|
204
|
+
name: string;
|
|
205
|
+
type: SandboxFileSystemEventType;
|
|
206
|
+
}
|
|
207
|
+
export interface SandboxWatchDirOptions {
|
|
208
|
+
recursive?: boolean;
|
|
209
|
+
timeoutMs?: number;
|
|
210
|
+
onExit?: (error?: Error) => void | Promise<void>;
|
|
211
|
+
}
|
|
212
|
+
export interface SandboxPresignFileParams {
|
|
213
|
+
path: string;
|
|
214
|
+
expiresInSeconds?: number;
|
|
215
|
+
oneTime?: boolean;
|
|
216
|
+
}
|
|
217
|
+
export interface SandboxPresignedUrl {
|
|
218
|
+
token: string;
|
|
219
|
+
path: string;
|
|
220
|
+
method: string;
|
|
221
|
+
expiresAt: number;
|
|
222
|
+
url: string;
|
|
223
|
+
}
|
|
224
|
+
export interface SandboxTerminalCreateParams {
|
|
225
|
+
command: string;
|
|
226
|
+
args?: string[];
|
|
227
|
+
cwd?: string;
|
|
228
|
+
env?: Record<string, string>;
|
|
229
|
+
useShell?: boolean;
|
|
230
|
+
rows?: number;
|
|
231
|
+
cols?: number;
|
|
232
|
+
timeoutMs?: number;
|
|
233
|
+
}
|
|
234
|
+
export interface SandboxTerminalOutputChunk {
|
|
235
|
+
seq: number;
|
|
236
|
+
data: string;
|
|
237
|
+
raw: Buffer;
|
|
238
|
+
timestamp: number;
|
|
239
|
+
}
|
|
240
|
+
export interface SandboxTerminalStatus {
|
|
241
|
+
id: string;
|
|
242
|
+
command: string;
|
|
243
|
+
args?: string[];
|
|
244
|
+
cwd: string;
|
|
245
|
+
pid?: number;
|
|
246
|
+
running: boolean;
|
|
247
|
+
exitCode?: number | null;
|
|
248
|
+
error?: string;
|
|
249
|
+
timedOut?: boolean;
|
|
250
|
+
rows: number;
|
|
251
|
+
cols: number;
|
|
252
|
+
startedAt: number;
|
|
253
|
+
finishedAt?: number;
|
|
254
|
+
output?: SandboxTerminalOutputChunk[];
|
|
255
|
+
}
|
|
256
|
+
export interface SandboxTerminalWaitParams {
|
|
257
|
+
timeoutMs?: number;
|
|
258
|
+
includeOutput?: boolean;
|
|
259
|
+
}
|
|
260
|
+
export interface SandboxTerminalKillParams {
|
|
261
|
+
signal?: string;
|
|
262
|
+
timeoutMs?: number;
|
|
263
|
+
}
|
|
264
|
+
export type SandboxTerminalEvent = ({
|
|
265
|
+
type: "output";
|
|
266
|
+
} & SandboxTerminalOutputChunk) | {
|
|
267
|
+
type: "exit";
|
|
268
|
+
status: SandboxTerminalStatus;
|
|
269
|
+
};
|
|
270
|
+
export {};
|