cerevox
Version:
TypeScript SDK for browser automation and secure command execution in highly available and scalable micro computer environments
60 lines • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cerevox = void 0;
const session_1 = require("./session");
require("dotenv/config");
const logger_1 = require("../utils/logger");
const sandbox_1 = require("./sandbox");
class Cerevox {
constructor(options = {}) {
this.debug = false;
this.apiKey = options.apiKey || process.env.CEREVOX_API_KEY || '';
this.debug = !!options.debug;
// 当 debug 为 true 时默认值为 debug,否则默认值为 error
this.logLevel = options.logLevel || (this.debug ? 'debug' : 'error');
this.logger = (0, logger_1.createClassLogger)('Cerevox', {}, this.logLevel);
}
get workspace() {
return this.apiKey.slice(3, 19);
}
getLogger() {
return this.logger;
}
async createSandbox(timeout = 60, keepAliveMS = 5000, metadata) {
const logger = this.logger;
const sandbox = await (0, sandbox_1.createSandbox)(this.apiKey, logger, timeout, keepAliveMS, metadata);
return sandbox;
}
async connectSandbox(sandboxId, keepAliveMS = 5000) {
const logger = this.logger;
const sandbox = await (0, sandbox_1.connectSandbox)(this.apiKey, logger, sandboxId, keepAliveMS);
return sandbox;
}
async launch(config = {}) {
const { timeout, keepAliveMS, metadata } = config;
const sandbox = await this.createSandbox(timeout, keepAliveMS, metadata);
const session = new session_1.Session(sandbox, {
envs: {
SANDBOX_ID: sandbox.sandboxId,
},
logLevel: this.logLevel,
workspace: this.workspace,
});
await session.connect();
return session;
}
async connect(sandboxId, keepAliveMS = 5000) {
const sandbox = await this.connectSandbox(sandboxId, keepAliveMS);
const session = new session_1.Session(sandbox, {
envs: {
SANDBOX_ID: sandboxId,
},
logLevel: this.logLevel,
workspace: this.workspace,
});
await session.connect();
return session;
}
}
exports.Cerevox = Cerevox;
//# sourceMappingURL=cerevox.js.map