@luxorai/sandbox
Version:
TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud
41 lines • 2.01 kB
JavaScript
import { createClient } from "@connectrpc/connect";
import { createGrpcTransport } from "@connectrpc/connect-node";
import { createAuthInterceptor, resolveAuthToken } from "./auth.js";
import { CLOUD_API_URL_ENVS, DEFAULT_BASE_URL } from "./constants.js";
import { readEnv } from "./env.js";
import { DrainingHttp2SessionManager } from "./http2-drain.js";
import * as pb from "./internal/proto/tenki/cloud/workspace/v1beta1/secrets_pb.js";
import * as variablesPb from "./internal/proto/tenki/cloud/workspace/v1beta1/variables_pb.js";
import { Secrets } from "./workspace-secrets.js";
import { Variables } from "./workspace-variables.js";
/** Owns workspace scope, authentication, and connection lifetime. */
export class WorkspaceClient {
secrets;
variables;
sessionManager;
constructor(options = {}) {
const token = resolveAuthToken(options.authToken, options.apiKey);
const baseUrl = options.baseUrl || readEnv(CLOUD_API_URL_ENVS) || DEFAULT_BASE_URL;
this.sessionManager = options.transport
? undefined
: new DrainingHttp2SessionManager(baseUrl, undefined, options.rootCertificates !== undefined ? { ca: options.rootCertificates } : undefined);
const transport = options.transport ??
createGrpcTransport({
baseUrl,
defaultTimeoutMs: options.timeoutMs ?? 30_000,
sessionManager: this.sessionManager,
interceptors: [createAuthInterceptor(token)],
});
const workspaceId = options.workspaceId ?? "";
const secrets = createClient(pb.WorkspaceSecretsService, transport);
this.secrets = new Secrets(workspaceId, secrets);
this.variables = new Variables(workspaceId, createClient(variablesPb.WorkspaceVariablesService, transport), secrets);
}
async close() {
await this.sessionManager?.abort();
}
async [Symbol.asyncDispose]() {
await this.close();
}
}
//# sourceMappingURL=workspace.js.map