@celestoai/sdk 0.1.5 → 0.1.6
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 +57 -0
- package/dist/{chunk-52TE4RZV.js → chunk-B4JRBDUO.js} +64 -3
- package/dist/chunk-B4JRBDUO.js.map +1 -0
- package/dist/computers/index.cjs +63 -2
- package/dist/computers/index.cjs.map +1 -1
- package/dist/computers/index.d.cts +32 -1
- package/dist/computers/index.d.ts +32 -1
- package/dist/computers/index.js +1 -1
- package/dist/index.cjs +63 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-52TE4RZV.js.map +0 -1
package/README.md
CHANGED
|
@@ -348,6 +348,9 @@ shown by the Celesto command-line tool: `celesto computer list`.
|
|
|
348
348
|
| `Computer.list()` | List computers in your account |
|
|
349
349
|
| `Computer.get(computerId)` | Get one computer by name or ID |
|
|
350
350
|
| `computer.listCommandHistory()` | List recent commands and their status |
|
|
351
|
+
| `computer.createTerminalSession()` | Create a short-lived fast terminal connection |
|
|
352
|
+
| `computer.createBrowserConnection()` | Create a short-lived CDP connection to browser-agent Chromium |
|
|
353
|
+
| `computer.createDisplayConnection({ mode: "read_only" })` | Create a short-lived RFB display connection |
|
|
351
354
|
| `computer.stop()` | Stop a running computer |
|
|
352
355
|
| `computer.start()` | Start a stopped computer |
|
|
353
356
|
| `computer.delete()` | Delete a computer |
|
|
@@ -404,6 +407,60 @@ ws.on("open", () => ws.send("pwd\n"));
|
|
|
404
407
|
`connection.url` contains a short-lived terminal token. Treat it as a secret and
|
|
405
408
|
create a new terminal session after `connection.expiresAt`.
|
|
406
409
|
|
|
410
|
+
### Browser Automation Connections
|
|
411
|
+
|
|
412
|
+
Use the `browser-agent` template when your application needs an existing
|
|
413
|
+
Chromium browser. `createBrowserConnection()` returns a short-lived Chrome
|
|
414
|
+
DevTools Protocol (CDP) WebSocket URL that Playwright can attach to.
|
|
415
|
+
|
|
416
|
+
Install Playwright Core in the application that runs this code:
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
npm install playwright-core
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
Then connect to the browser already running in the Celesto computer:
|
|
423
|
+
|
|
424
|
+
```js
|
|
425
|
+
import { Computer } from "@celestoai/sdk";
|
|
426
|
+
import { chromium } from "playwright-core";
|
|
427
|
+
|
|
428
|
+
const computer = await Computer.create({ templateId: "browser-agent" });
|
|
429
|
+
try {
|
|
430
|
+
const connection = await computer.createBrowserConnection();
|
|
431
|
+
const browser = await chromium.connectOverCDP(connection.url);
|
|
432
|
+
const context = browser.contexts()[0];
|
|
433
|
+
if (!context) throw new Error("Celesto browser did not provide a context");
|
|
434
|
+
const pages = context.pages();
|
|
435
|
+
const page = pages[0] ?? await context.newPage();
|
|
436
|
+
|
|
437
|
+
await page.goto("https://example.com");
|
|
438
|
+
console.log(await page.title());
|
|
439
|
+
} finally {
|
|
440
|
+
await computer.delete();
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### Display Connections
|
|
445
|
+
|
|
446
|
+
Use `createDisplayConnection()` when a Remote Framebuffer (RFB) client, such as
|
|
447
|
+
the browser-based noVNC viewer, needs to watch the graphical desktop.
|
|
448
|
+
Connections are read-only by default. Pass
|
|
449
|
+
`{ mode: "read_write" }` when the viewer also needs pointer and keyboard control:
|
|
450
|
+
|
|
451
|
+
```js
|
|
452
|
+
import { Computer } from "@celestoai/sdk";
|
|
453
|
+
|
|
454
|
+
const computer = await Computer.get("curie");
|
|
455
|
+
const display = await computer.createDisplayConnection({ mode: "read_only" });
|
|
456
|
+
console.log(display.mode, display.expiresAt);
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Pass `display.url` to the RFB client before it expires. Browser and display URLs
|
|
460
|
+
contain short-lived secret tokens, so do not log, persist, or share them. Create
|
|
461
|
+
a new connection after a disconnect or expiry. Browser automation and
|
|
462
|
+
read-write display connections require write access to the computer.
|
|
463
|
+
|
|
407
464
|
## Gatekeeper
|
|
408
465
|
|
|
409
466
|
Use Gatekeeper when your app needs user-approved access to an external resource,
|
|
@@ -120,18 +120,50 @@ var toCommandHistoryEntry = (payload) => ({
|
|
|
120
120
|
stderrBytes: payload.stderr_bytes,
|
|
121
121
|
errorType: payload.error_type
|
|
122
122
|
});
|
|
123
|
+
function authenticatedGatewayUrl(gatewayUrl, token) {
|
|
124
|
+
const separator = gatewayUrl.includes("?") ? "&" : "?";
|
|
125
|
+
return `${gatewayUrl}${separator}token=${encodeURIComponent(token)}`;
|
|
126
|
+
}
|
|
123
127
|
var toTerminalConnectionInfo = (payload) => {
|
|
124
|
-
const separator = payload.gateway_url.includes("?") ? "&" : "?";
|
|
125
128
|
return {
|
|
126
129
|
terminalId: payload.terminal_id,
|
|
127
130
|
gatewayUrl: payload.gateway_url,
|
|
128
|
-
url:
|
|
131
|
+
url: authenticatedGatewayUrl(payload.gateway_url, payload.token),
|
|
129
132
|
token: payload.token,
|
|
130
133
|
expiresAt: payload.expires_at,
|
|
131
134
|
headers: {},
|
|
132
135
|
firstMessage: ""
|
|
133
136
|
};
|
|
134
137
|
};
|
|
138
|
+
var toBrowserConnectionInfo = (payload) => {
|
|
139
|
+
if (typeof payload !== "object" || payload === null || typeof payload.gateway_url !== "string" || typeof payload.token !== "string" || typeof payload.expires_at !== "string") {
|
|
140
|
+
throw new CelestoError(
|
|
141
|
+
"Celesto did not return browser connection details. Call createBrowserConnection() again."
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const connection = payload;
|
|
145
|
+
return {
|
|
146
|
+
gatewayUrl: connection.gateway_url,
|
|
147
|
+
url: authenticatedGatewayUrl(connection.gateway_url, connection.token),
|
|
148
|
+
token: connection.token,
|
|
149
|
+
expiresAt: connection.expires_at
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
var toDisplayConnectionInfo = (payload) => {
|
|
153
|
+
if (typeof payload !== "object" || payload === null || payload.mode !== "read_only" && payload.mode !== "read_write") {
|
|
154
|
+
throw new CelestoError(
|
|
155
|
+
"Celesto did not return display connection details. Call createDisplayConnection() again."
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const connection = payload;
|
|
159
|
+
try {
|
|
160
|
+
return { ...toBrowserConnectionInfo(connection), mode: connection.mode };
|
|
161
|
+
} catch {
|
|
162
|
+
throw new CelestoError(
|
|
163
|
+
"Celesto did not return display connection details. Call createDisplayConnection() again."
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
135
167
|
var toSandboxTemplateInfo = (payload) => ({
|
|
136
168
|
id: payload.id,
|
|
137
169
|
displayName: payload.display_name,
|
|
@@ -586,6 +618,27 @@ var ComputersClient = class {
|
|
|
586
618
|
});
|
|
587
619
|
return toTerminalConnectionInfo(data);
|
|
588
620
|
}
|
|
621
|
+
/** Create a short-lived CDP connection for browser automation. */
|
|
622
|
+
async createBrowserConnection(computerIdOrName, options) {
|
|
623
|
+
const ctx = buildRequestContext(this.config);
|
|
624
|
+
const data = await request(ctx, {
|
|
625
|
+
method: "POST",
|
|
626
|
+
path: computersPath(`/${encodeURIComponent(computerIdOrName)}/browser`),
|
|
627
|
+
...pickOverrides(options)
|
|
628
|
+
});
|
|
629
|
+
return toBrowserConnectionInfo(data);
|
|
630
|
+
}
|
|
631
|
+
/** Create a short-lived RFB connection to watch or control the graphical display. */
|
|
632
|
+
async createDisplayConnection(computerIdOrName, params = {}, options) {
|
|
633
|
+
const ctx = buildRequestContext(this.config);
|
|
634
|
+
const data = await request(ctx, {
|
|
635
|
+
method: "POST",
|
|
636
|
+
path: computersPath(`/${encodeURIComponent(computerIdOrName)}/display`),
|
|
637
|
+
body: params.mode === void 0 ? void 0 : { mode: params.mode },
|
|
638
|
+
...pickOverrides(options)
|
|
639
|
+
});
|
|
640
|
+
return toDisplayConnectionInfo(data);
|
|
641
|
+
}
|
|
589
642
|
/** @deprecated Use createTerminalSession(). */
|
|
590
643
|
async getTerminalConnection(computerIdOrName, options) {
|
|
591
644
|
return this.createTerminalSession(computerIdOrName, options);
|
|
@@ -707,6 +760,14 @@ var Computer = class _Computer {
|
|
|
707
760
|
async createTerminalSession() {
|
|
708
761
|
return this.client.createTerminalSession(this.id);
|
|
709
762
|
}
|
|
763
|
+
/** Create a short-lived CDP connection for browser automation. */
|
|
764
|
+
async createBrowserConnection() {
|
|
765
|
+
return this.client.createBrowserConnection(this.id);
|
|
766
|
+
}
|
|
767
|
+
/** Create a short-lived RFB connection to watch or control the graphical display. */
|
|
768
|
+
async createDisplayConnection(params = {}) {
|
|
769
|
+
return this.client.createDisplayConnection(this.id, params);
|
|
770
|
+
}
|
|
710
771
|
/** @deprecated Use createTerminalSession(). */
|
|
711
772
|
async getTerminalConnection() {
|
|
712
773
|
return this.createTerminalSession();
|
|
@@ -759,4 +820,4 @@ export {
|
|
|
759
820
|
resolveClientConfig,
|
|
760
821
|
Computer
|
|
761
822
|
};
|
|
762
|
-
//# sourceMappingURL=chunk-
|
|
823
|
+
//# sourceMappingURL=chunk-B4JRBDUO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/auth.ts","../src/computers/client.ts","../src/computers/computer.ts"],"sourcesContent":["import { execFile as execFileCallback } from \"node:child_process\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { promisify } from \"node:util\";\n\nimport { parse } from \"dotenv\";\n\nimport type { ClientConfig } from \"./config\";\nimport { CelestoError } from \"./errors\";\n\nconst execFile = promisify(execFileCallback);\n\nexport const MISSING_CREDENTIALS_MESSAGE =\n \"No Celesto credentials found. Run pip install celesto && celesto auth login, or export CELESTO_API_KEY.\";\n\nexport interface CredentialResolutionOptions {\n /** Directory containing the local .env file. Defaults to process.cwd(). */\n cwd?: string;\n /** Environment variables to inspect. Defaults to process.env. */\n env?: NodeJS.ProcessEnv;\n /** Test or host override for reading .env. */\n readDotEnv?: (filePath: string) => Promise<string>;\n /** Test or host override for loading credentials saved by the Celesto CLI. */\n loadSavedApiKey?: () => Promise<string | undefined>;\n}\n\nfunction nonEmpty(value: string | undefined): string | undefined {\n const trimmed = value?.trim();\n return trimmed ? trimmed : undefined;\n}\n\nasync function readDotEnvApiKey(\n cwd: string,\n readDotEnv: (filePath: string) => Promise<string>,\n): Promise<string | undefined> {\n try {\n const contents = await readDotEnv(path.join(cwd, \".env\"));\n return nonEmpty(parse(contents).CELESTO_API_KEY);\n } catch {\n return undefined;\n }\n}\n\nasync function loadCliApiKey(): Promise<string | undefined> {\n try {\n const { stdout } = await execFile(\"celesto\", [\"auth\", \"token\"], {\n encoding: \"utf8\",\n timeout: 5_000,\n maxBuffer: 64 * 1024,\n });\n return nonEmpty(stdout);\n } catch {\n return undefined;\n }\n}\n\n/** Resolve a Celesto API key from local sources, in precedence order. */\nexport async function resolveCelestoApiKey(\n options: CredentialResolutionOptions = {},\n): Promise<string | undefined> {\n const env = options.env ?? process.env;\n const environmentKey = nonEmpty(env.CELESTO_API_KEY);\n if (environmentKey) return environmentKey;\n\n const dotEnvKey = await readDotEnvApiKey(\n options.cwd ?? process.cwd(),\n options.readDotEnv ?? ((filePath) => readFile(filePath, \"utf8\")),\n );\n if (dotEnvKey) return dotEnvKey;\n\n return (options.loadSavedApiKey ?? loadCliApiKey)();\n}\n\n/** Resolve an API key while preserving explicit SDK configuration. */\nexport async function resolveClientConfig(\n config: ClientConfig = {},\n options: CredentialResolutionOptions = {},\n): Promise<ClientConfig> {\n if (nonEmpty(config.token) || nonEmpty(config.apiKey)) return config;\n\n const apiKey = await resolveCelestoApiKey(options);\n if (!apiKey) throw new CelestoError(MISSING_CREDENTIALS_MESSAGE);\n return { ...config, token: apiKey };\n}\n","import { buildRequestContext, ClientConfig, RequestOverrides } from \"../core/config\";\nimport { CelestoError, CelestoNetworkError } from \"../core/errors\";\nimport { request, requestStream } from \"../core/http\";\nimport {\n BrowserConnectionInfo,\n ComputerCommandHistoryEntry,\n ComputerCommandHistoryResponse,\n ComputerConnectionInfo,\n ComputerExecResponse,\n ComputerExecStreamEvent,\n ComputerInfo,\n ComputerListResponse,\n NetworkPolicy,\n ComputerPublishedPortInfo,\n ComputerStatus,\n CreateComputerParams,\n DisplayConnectionInfo,\n DisplayConnectionParams,\n ExecParams,\n ListCommandHistoryParams,\n ListComputersParams,\n SandboxTemplateInfo,\n TerminalSessionInfo,\n} from \"./types\";\n\ninterface ComputerConnectionInfoWire {\n ssh?: string | null;\n access_url?: string | null;\n}\n\ninterface ComputerPublishedPortInfoWire {\n id?: string | null;\n computer_id: string;\n port: number;\n url?: string | null;\n status: ComputerPublishedPortInfo[\"status\"];\n created_at?: string | null;\n}\n\ninterface ComputerInfoWire {\n network_policy?: NetworkPolicy;\n id: string;\n name: string;\n status: ComputerStatus;\n vcpus: number;\n ram_mb: number;\n disk_size_mb: number;\n image: string;\n template_id: string;\n template_version?: string | null;\n external_volume_enabled?: boolean;\n connection?: ComputerConnectionInfoWire | null;\n published_ports?: ComputerPublishedPortInfoWire[];\n last_error?: string | null;\n created_at: string;\n stopped_at?: string | null;\n}\n\ninterface ComputerListResponseWire {\n computers: ComputerInfoWire[];\n count: number;\n}\n\ninterface ComputerExecResponseWire {\n exit_code: number;\n stdout: string;\n stderr: string;\n command_id?: string | null;\n duration_ms?: number | null;\n timed_out?: boolean | null;\n}\n\ninterface ComputerCommandHistoryEntryWire {\n command_id: string;\n source: string;\n status: string;\n started_at?: string | null;\n ended_at?: string | null;\n duration_ms?: number | null;\n timeout_seconds?: number | null;\n exit_code?: number | null;\n stdout_bytes?: number | null;\n stderr_bytes?: number | null;\n error_type?: string | null;\n}\n\ninterface ComputerCommandHistoryResponseWire {\n commands: ComputerCommandHistoryEntryWire[];\n count: number;\n}\n\ninterface TerminalConnectionInfoWire {\n terminal_id: string;\n gateway_url: string;\n token: string;\n expires_at: string;\n}\n\ninterface BrowserConnectionInfoWire {\n gateway_url: string;\n token: string;\n expires_at: string;\n}\n\ninterface DisplayConnectionInfoWire extends BrowserConnectionInfoWire {\n mode: DisplayConnectionInfo[\"mode\"];\n}\n\ninterface SandboxTemplateInfoWire {\n id: string;\n display_name: string;\n description: string;\n default_vcpus: number;\n default_ram_mb: number;\n default_disk_size_mb: number;\n version?: string | null;\n experimental: boolean;\n}\n\nconst toConnection = (\n payload: ComputerConnectionInfoWire | null | undefined,\n): ComputerConnectionInfo | undefined => {\n if (!payload) {\n return undefined;\n }\n const out: ComputerConnectionInfo = {};\n if (payload.ssh != null) {\n out.ssh = payload.ssh;\n }\n if (payload.access_url != null) {\n out.accessUrl = payload.access_url;\n }\n return out;\n};\n\nconst toPublishedPortInfo = (payload: ComputerPublishedPortInfoWire): ComputerPublishedPortInfo => ({\n id: payload.id ?? null,\n computerId: payload.computer_id,\n port: payload.port,\n url: payload.url ?? null,\n status: payload.status,\n createdAt: payload.created_at ?? null,\n});\n\nconst toComputerInfo = (payload: ComputerInfoWire): ComputerInfo => ({\n id: payload.id,\n name: payload.name,\n status: payload.status,\n vcpus: payload.vcpus,\n ramMb: payload.ram_mb,\n diskSizeMb: payload.disk_size_mb,\n image: payload.image,\n templateId: payload.template_id,\n templateVersion: payload.template_version ?? null,\n persistentHome: payload.external_volume_enabled ?? false,\n networkPolicy: payload.network_policy ?? { mode: \"open\" },\n connection: toConnection(payload.connection),\n publishedPorts: payload.published_ports?.map(toPublishedPortInfo),\n lastError: payload.last_error ?? null,\n createdAt: payload.created_at,\n stoppedAt: payload.stopped_at ?? null,\n});\n\nconst toExecResponse = (payload: ComputerExecResponseWire): ComputerExecResponse => {\n const response: ComputerExecResponse = {\n exitCode: payload.exit_code,\n stdout: payload.stdout,\n stderr: payload.stderr,\n };\n if (payload.command_id !== undefined) response.commandId = payload.command_id;\n if (payload.duration_ms !== undefined) response.durationMs = payload.duration_ms;\n if (payload.timed_out !== undefined) response.timedOut = payload.timed_out;\n return response;\n};\n\nconst toCommandHistoryEntry = (\n payload: ComputerCommandHistoryEntryWire,\n): ComputerCommandHistoryEntry => ({\n commandId: payload.command_id,\n source: payload.source,\n status: payload.status,\n startedAt: payload.started_at,\n endedAt: payload.ended_at,\n durationMs: payload.duration_ms,\n timeoutSeconds: payload.timeout_seconds,\n exitCode: payload.exit_code,\n stdoutBytes: payload.stdout_bytes,\n stderrBytes: payload.stderr_bytes,\n errorType: payload.error_type,\n});\n\nfunction authenticatedGatewayUrl(gatewayUrl: string, token: string): string {\n const separator = gatewayUrl.includes(\"?\") ? \"&\" : \"?\";\n return `${gatewayUrl}${separator}token=${encodeURIComponent(token)}`;\n}\n\nconst toTerminalConnectionInfo = (\n payload: TerminalConnectionInfoWire,\n): TerminalSessionInfo => {\n return {\n terminalId: payload.terminal_id,\n gatewayUrl: payload.gateway_url,\n url: authenticatedGatewayUrl(payload.gateway_url, payload.token),\n token: payload.token,\n expiresAt: payload.expires_at,\n headers: {},\n firstMessage: \"\",\n };\n};\n\nconst toBrowserConnectionInfo = (\n payload: unknown,\n): BrowserConnectionInfo => {\n if (\n typeof payload !== \"object\" ||\n payload === null ||\n typeof (payload as Partial<BrowserConnectionInfoWire>).gateway_url !== \"string\" ||\n typeof (payload as Partial<BrowserConnectionInfoWire>).token !== \"string\" ||\n typeof (payload as Partial<BrowserConnectionInfoWire>).expires_at !== \"string\"\n ) {\n throw new CelestoError(\n \"Celesto did not return browser connection details. Call createBrowserConnection() again.\",\n );\n }\n const connection = payload as BrowserConnectionInfoWire;\n return {\n gatewayUrl: connection.gateway_url,\n url: authenticatedGatewayUrl(connection.gateway_url, connection.token),\n token: connection.token,\n expiresAt: connection.expires_at,\n };\n};\n\nconst toDisplayConnectionInfo = (\n payload: unknown,\n): DisplayConnectionInfo => {\n if (\n typeof payload !== \"object\" ||\n payload === null ||\n ((payload as Partial<DisplayConnectionInfoWire>).mode !== \"read_only\" &&\n (payload as Partial<DisplayConnectionInfoWire>).mode !== \"read_write\")\n ) {\n throw new CelestoError(\n \"Celesto did not return display connection details. Call createDisplayConnection() again.\",\n );\n }\n const connection = payload as DisplayConnectionInfoWire;\n try {\n return { ...toBrowserConnectionInfo(connection), mode: connection.mode };\n } catch {\n throw new CelestoError(\n \"Celesto did not return display connection details. Call createDisplayConnection() again.\",\n );\n }\n};\n\nconst toSandboxTemplateInfo = (payload: SandboxTemplateInfoWire): SandboxTemplateInfo => ({\n id: payload.id,\n displayName: payload.display_name,\n description: payload.description,\n defaultVcpus: payload.default_vcpus,\n defaultRamMb: payload.default_ram_mb,\n defaultDiskSizeMb: payload.default_disk_size_mb,\n version: payload.version ?? null,\n experimental: payload.experimental,\n});\n\nconst diskUnitsToMb: Record<string, number> = {\n \"\": 1,\n m: 1,\n mb: 1,\n mib: 1,\n g: 1024,\n gb: 1024,\n gib: 1024,\n t: 1024 * 1024,\n tb: 1024 * 1024,\n tib: 1024 * 1024,\n};\n\nconst isAsciiDigit = (char: string): boolean => char >= \"0\" && char <= \"9\";\nconst isAsciiLetter = (char: string): boolean =>\n (char >= \"a\" && char <= \"z\") || (char >= \"A\" && char <= \"Z\");\nconst isSeparatorWhitespace = (char: string): boolean => char === \" \" || char === \"\\t\";\n\nconst parseDiskString = (disk: string): { amount: string; unit: string } | undefined => {\n const value = disk.trim();\n if (!value) {\n return undefined;\n }\n\n let index = 0;\n let digitCount = 0;\n let hasDecimalPoint = false;\n while (index < value.length) {\n const char = value[index]!;\n if (isAsciiDigit(char)) {\n digitCount += 1;\n index += 1;\n continue;\n }\n if (char === \".\" && !hasDecimalPoint) {\n hasDecimalPoint = true;\n index += 1;\n continue;\n }\n break;\n }\n\n if (digitCount === 0 || value[index - 1] === \".\") {\n return undefined;\n }\n\n const amount = value.slice(0, index);\n while (index < value.length && isSeparatorWhitespace(value[index]!)) {\n index += 1;\n }\n\n const unit = value.slice(index);\n if ([...unit].some((char) => !isAsciiLetter(char))) {\n return undefined;\n }\n\n return { amount, unit };\n};\n\nconst parseDiskSizeMb = (disk: number | string | undefined): number | undefined => {\n if (disk === undefined) {\n return undefined;\n }\n\n if (typeof disk === \"number\") {\n if (!Number.isInteger(disk) || disk <= 0) {\n throw new Error(\"disk as a number must be a whole number of MB.\");\n }\n return disk;\n }\n\n const parsedDisk = parseDiskString(disk);\n if (!parsedDisk) {\n throw new Error(\"disk must be a size in MB or a string like '2gb'.\");\n }\n\n const multiplier = diskUnitsToMb[parsedDisk.unit.toLowerCase()];\n if (multiplier === undefined) {\n throw new Error(\"disk must use MB, GB, or TB, for example '2048mb' or '2gb'.\");\n }\n\n const sizeMb = Number(parsedDisk.amount) * multiplier;\n if (!Number.isInteger(sizeMb) || sizeMb <= 0) {\n throw new Error(\"disk must resolve to a whole number of MB, for example '1536mb' or '1.5gb'.\");\n }\n return sizeMb;\n};\n\nconst buildCreateComputerBody = (params: CreateComputerParams): Record<string, unknown> => {\n if (params.cpus !== undefined && params.vcpus !== undefined && params.cpus !== params.vcpus) {\n throw new Error(\"cpus and vcpus must have the same value when both are provided.\");\n }\n if (params.memory !== undefined && params.ramMb !== undefined && params.memory !== params.ramMb) {\n throw new Error(\"memory and ramMb must have the same value when both are provided.\");\n }\n\n const parsedDiskSizeMb = parseDiskSizeMb(params.disk);\n if (\n parsedDiskSizeMb !== undefined &&\n params.diskSizeMb !== undefined &&\n parsedDiskSizeMb !== params.diskSizeMb\n ) {\n throw new Error(\"disk and diskSizeMb must have the same value when both are provided.\");\n }\n\n const body: Record<string, unknown> = {};\n if (params.networkPolicy !== undefined) {\n const policy = params.networkPolicy;\n if (!policy || Object.keys(policy).length !== 1 || !(\"mode\" in policy) || ![\"open\", \"off\"].includes(policy.mode)) {\n throw new Error('networkPolicy must be {mode: \"open\"} or {mode: \"off\"}.');\n }\n if (policy.mode === \"off\" && params.persistentHome) {\n throw new Error(\"External volumes require internet access; set persistentHome=false.\");\n }\n body.network_policy = { mode: policy.mode };\n }\n const vcpus = params.vcpus ?? params.cpus;\n const ramMb = params.ramMb ?? params.memory;\n const diskSizeMb = params.diskSizeMb ?? parsedDiskSizeMb;\n if (vcpus !== undefined) {\n body.vcpus = vcpus;\n }\n if (ramMb !== undefined) {\n body.ram_mb = ramMb;\n }\n if (diskSizeMb !== undefined) {\n body.disk_size_mb = diskSizeMb;\n }\n if (params.image !== undefined) {\n body.image = params.image;\n }\n if (params.templateId !== undefined) {\n body.template_id = params.templateId;\n }\n if (params.templateVersion !== undefined) {\n body.template_version = params.templateVersion;\n }\n if (params.persistentHome !== undefined) {\n body.external_volume_enabled = params.persistentHome;\n }\n return body;\n};\n\nconst computersPath = (path: string): string => `/v1/computers${path}`;\n\nconst pickOverrides = (options?: RequestOverrides): RequestOverrides => ({\n headers: options?.headers,\n signal: options?.signal,\n});\n\nconst optionalNumber = (value: unknown): number | undefined =>\n typeof value === \"number\" ? value : undefined;\n\nconst optionalBoolean = (value: unknown): boolean | undefined =>\n typeof value === \"boolean\" ? value : undefined;\n\nconst parseExecStreamEvent = (value: unknown): ComputerExecStreamEvent => {\n if (!value || typeof value !== \"object\") {\n throw new Error(\"Celesto returned an invalid command stream event.\");\n }\n\n const event = value as Record<string, unknown>;\n if (event.type === \"stdout\" || event.type === \"stderr\") {\n if (typeof event.data !== \"string\") {\n throw new Error(\"Celesto returned command output without text data.\");\n }\n return { type: event.type, data: event.data };\n }\n\n if (event.type === \"started\") {\n if (\n typeof event.command_id !== \"string\" ||\n typeof event.started_at_unix_ms !== \"number\" ||\n typeof event.timeout_seconds !== \"number\"\n ) {\n throw new Error(\"Celesto returned an invalid command-start event.\");\n }\n return {\n type: \"started\",\n commandId: event.command_id,\n startedAtUnixMs: event.started_at_unix_ms,\n timeoutSeconds: event.timeout_seconds,\n };\n }\n\n if (event.type === \"exit\") {\n if (typeof event.exit_code !== \"number\") {\n throw new Error(\"Celesto returned an invalid command-exit event.\");\n }\n const result: Extract<ComputerExecStreamEvent, { type: \"exit\" }> = {\n type: \"exit\",\n exitCode: event.exit_code,\n };\n if (typeof event.command_id === \"string\") result.commandId = event.command_id;\n const startedAtUnixMs = optionalNumber(event.started_at_unix_ms);\n const endedAtUnixMs = optionalNumber(event.ended_at_unix_ms);\n const durationMs = optionalNumber(event.duration_ms);\n const timedOut = optionalBoolean(event.timed_out);\n if (startedAtUnixMs !== undefined) result.startedAtUnixMs = startedAtUnixMs;\n if (endedAtUnixMs !== undefined) result.endedAtUnixMs = endedAtUnixMs;\n if (durationMs !== undefined) result.durationMs = durationMs;\n if (timedOut !== undefined) result.timedOut = timedOut;\n return result;\n }\n\n throw new Error(\"Celesto returned an unknown command stream event.\");\n};\n\nconst parseSseDataLine = (line: string): ComputerExecStreamEvent | undefined => {\n const text = line.trim();\n if (!text || !text.startsWith(\"data:\")) {\n return undefined;\n }\n const data = text.slice(\"data:\".length).trim();\n if (!data || data === \"[DONE]\") {\n return undefined;\n }\n try {\n return parseExecStreamEvent(JSON.parse(data));\n } catch (error) {\n if (error instanceof SyntaxError) {\n throw new Error(\"Celesto returned malformed JSON in the command stream.\");\n }\n throw error;\n }\n};\n\nconst createManagedSignal = (\n signal: AbortSignal | undefined,\n timeoutMs: number | undefined,\n): { signal: AbortSignal | undefined; cleanup: () => void } => {\n if (!timeoutMs || timeoutMs <= 0) {\n return { signal, cleanup: () => {} };\n }\n\n const controller = new AbortController();\n const abort = () => controller.abort();\n if (signal?.aborted) {\n abort();\n } else {\n signal?.addEventListener(\"abort\", abort, { once: true });\n }\n const timer = setTimeout(abort, timeoutMs);\n\n return {\n signal: controller.signal,\n cleanup: () => {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", abort);\n },\n };\n};\n\nconst toNetworkError = (error: unknown): CelestoNetworkError => {\n if (error instanceof CelestoNetworkError) return error;\n const cause = error instanceof Error ? error : new Error(String(error));\n return new CelestoNetworkError(cause.message, cause);\n};\n\nconst withFallbackCommandId = (\n event: ComputerExecStreamEvent,\n commandId: string | undefined,\n): ComputerExecStreamEvent => {\n if (event.type !== \"exit\" || event.commandId || !commandId) return event;\n return { ...event, commandId };\n};\n\n/**\n * Client for managing sandboxed computers (AI sandboxes).\n *\n * Provides computer lifecycle, buffered and streaming command execution,\n * command history, published ports, and direct terminal gateway sessions.\n *\n * @example\n * ```ts\n * const computer = await Computer.create();\n * const result = await computer.run(\"uname -a\");\n * console.log(result.stdout);\n * await computer.delete();\n * ```\n */\nexport class ComputersClient {\n private readonly config: ClientConfig;\n\n constructor(config: ClientConfig) {\n this.config = config;\n }\n\n async create(params: CreateComputerParams = {}, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(\"\"),\n body: buildCreateComputerBody(params),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async listTemplates(options?: RequestOverrides): Promise<SandboxTemplateInfo[]> {\n const ctx = buildRequestContext(this.config);\n const data = await request<SandboxTemplateInfoWire[]>(ctx, {\n method: \"GET\",\n path: computersPath(\"/templates\"),\n ...pickOverrides(options),\n });\n return data.map(toSandboxTemplateInfo);\n }\n\n async list(params: ListComputersParams = {}, options?: RequestOverrides): Promise<ComputerListResponse> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerListResponseWire>(ctx, {\n method: \"GET\",\n path: computersPath(\"\"),\n query: {\n status: params.status,\n template_id: params.templateId,\n project_id: params.projectId,\n limit: params.limit,\n },\n ...pickOverrides(options),\n });\n return {\n computers: data.computers.map(toComputerInfo),\n count: data.count,\n };\n }\n\n async get(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"GET\",\n path: computersPath(`/${encodeURIComponent(computerId)}`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async exec(\n computerId: string,\n command: string,\n params: ExecParams = {},\n options?: RequestOverrides,\n ): Promise<ComputerExecResponse> {\n const ctx = buildRequestContext(this.config);\n const managedSignal = createManagedSignal(\n params.signal ?? options?.signal,\n this.config.timeoutMs,\n );\n try {\n const data = await request<ComputerExecResponseWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/exec`),\n body: {\n command,\n timeout: params.timeout ?? 30,\n },\n headers: options?.headers,\n signal: managedSignal.signal,\n });\n return toExecResponse(data);\n } finally {\n managedSignal.cleanup();\n }\n }\n\n async *execStream(\n computerId: string,\n command: string,\n params: ExecParams = {},\n options?: RequestOverrides,\n ): AsyncGenerator<ComputerExecStreamEvent> {\n const ctx = buildRequestContext(this.config);\n const managedSignal = createManagedSignal(\n params.signal ?? options?.signal,\n this.config.timeoutMs,\n );\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n let completed = false;\n\n try {\n const response = await requestStream(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/exec/stream`),\n body: {\n command,\n timeout: params.timeout ?? 30,\n },\n headers: options?.headers,\n signal: managedSignal.signal,\n });\n if (!response.body) {\n throw new Error(\"Celesto did not return a command output stream.\");\n }\n\n const responseCommandId = response.headers.get(\"x-celesto-command-id\") ?? undefined;\n reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n while (true) {\n let chunk: ReadableStreamReadResult<Uint8Array>;\n try {\n chunk = await reader.read();\n } catch (error) {\n throw toNetworkError(error);\n }\n if (chunk.done) {\n completed = true;\n buffer += decoder.decode();\n break;\n }\n buffer += decoder.decode(chunk.value, { stream: true });\n\n let newlineIndex = buffer.indexOf(\"\\n\");\n while (newlineIndex !== -1) {\n const line = buffer.slice(0, newlineIndex).replace(/\\r$/, \"\");\n buffer = buffer.slice(newlineIndex + 1);\n const parsed = parseSseDataLine(line);\n if (parsed) {\n const event = withFallbackCommandId(parsed, responseCommandId);\n yield event;\n if (event.type === \"exit\") return;\n }\n newlineIndex = buffer.indexOf(\"\\n\");\n }\n }\n\n if (buffer) {\n const parsed = parseSseDataLine(buffer);\n if (parsed) {\n const event = withFallbackCommandId(parsed, responseCommandId);\n yield event;\n if (event.type === \"exit\") return;\n }\n }\n throw new Error(\"Command stream ended before Celesto returned an exit status.\");\n } finally {\n if (reader) {\n if (!completed) {\n try {\n await reader.cancel();\n } catch {\n // The request may already be aborted or disconnected.\n }\n }\n reader.releaseLock();\n }\n managedSignal.cleanup();\n }\n }\n\n async listCommandHistory(\n computerId: string,\n params: ListCommandHistoryParams = {},\n options?: RequestOverrides,\n ): Promise<ComputerCommandHistoryResponse> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerCommandHistoryResponseWire>(ctx, {\n method: \"GET\",\n path: computersPath(`/${encodeURIComponent(computerId)}/commands`),\n query: { limit: params.limit },\n ...pickOverrides(options),\n });\n return {\n commands: data.commands.map(toCommandHistoryEntry),\n count: data.count,\n };\n }\n\n async stop(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/stop`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async start(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/start`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async delete(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"DELETE\",\n path: computersPath(`/${encodeURIComponent(computerId)}`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async publishPort(\n computerId: string,\n port = 8000,\n options?: RequestOverrides,\n ): Promise<ComputerPublishedPortInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerPublishedPortInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/published-ports`),\n body: { port },\n ...pickOverrides(options),\n });\n return toPublishedPortInfo(data);\n }\n\n async listPublishedPorts(\n computerId: string,\n options?: RequestOverrides,\n ): Promise<ComputerPublishedPortInfo[]> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerPublishedPortInfoWire[]>(ctx, {\n method: \"GET\",\n path: computersPath(`/${encodeURIComponent(computerId)}/published-ports`),\n ...pickOverrides(options),\n });\n return data.map(toPublishedPortInfo);\n }\n\n async unpublishPort(\n computerId: string,\n port = 8000,\n options?: RequestOverrides,\n ): Promise<ComputerPublishedPortInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerPublishedPortInfoWire>(ctx, {\n method: \"DELETE\",\n path: computersPath(`/${encodeURIComponent(computerId)}/published-ports/${port}`),\n ...pickOverrides(options),\n });\n return toPublishedPortInfo(data);\n }\n\n /** Create a short-lived direct connection to Celesto's terminal gateway. */\n async createTerminalSession(\n computerIdOrName: string,\n options?: RequestOverrides,\n ): Promise<TerminalSessionInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<TerminalConnectionInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerIdOrName)}/terminals`),\n ...pickOverrides(options),\n });\n return toTerminalConnectionInfo(data);\n }\n\n /** Create a short-lived CDP connection for browser automation. */\n async createBrowserConnection(\n computerIdOrName: string,\n options?: RequestOverrides,\n ): Promise<BrowserConnectionInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<BrowserConnectionInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerIdOrName)}/browser`),\n ...pickOverrides(options),\n });\n return toBrowserConnectionInfo(data);\n }\n\n /** Create a short-lived RFB connection to watch or control the graphical display. */\n async createDisplayConnection(\n computerIdOrName: string,\n params: DisplayConnectionParams = {},\n options?: RequestOverrides,\n ): Promise<DisplayConnectionInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<DisplayConnectionInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerIdOrName)}/display`),\n body: params.mode === undefined ? undefined : { mode: params.mode },\n ...pickOverrides(options),\n });\n return toDisplayConnectionInfo(data);\n }\n\n /** @deprecated Use createTerminalSession(). */\n async getTerminalConnection(\n computerIdOrName: string,\n options?: RequestOverrides,\n ): Promise<TerminalSessionInfo> {\n return this.createTerminalSession(computerIdOrName, options);\n }\n}\n","import { resolveClientConfig } from \"../core/auth\";\nimport { ClientConfig } from \"../core/config\";\nimport { ComputersClient } from \"./client\";\nimport {\n BrowserConnectionInfo,\n ComputerCommandHistoryResponse,\n ComputerConnectionInfo,\n ComputerExecResponse,\n ComputerExecStreamEvent,\n ComputerInfo,\n ComputerPublishedPortInfo,\n ComputerStatus,\n CreateComputerParams,\n DisplayConnectionInfo,\n DisplayConnectionParams,\n ExecParams,\n ListCommandHistoryParams,\n ListComputersParams,\n SandboxTemplateInfo,\n TerminalSessionInfo,\n} from \"./types\";\n\nconst defaultConfig = (): ClientConfig => ({\n token: typeof process !== \"undefined\" ? process.env.CELESTO_API_KEY : undefined,\n});\n\n/** Convenience object for one Celesto computer. */\nexport class Computer {\n private readonly client: ComputersClient;\n private info: ComputerInfo;\n\n private constructor(client: ComputersClient, info: ComputerInfo) {\n this.client = client;\n this.info = info;\n }\n\n /** Create a new computer and return an object with methods on it. */\n static async create(params: CreateComputerParams = {}, config?: ClientConfig): Promise<Computer> {\n const client = new ComputersClient(await resolveClientConfig(config));\n const info = await client.create(params);\n return new Computer(client, info);\n }\n\n /** Load an existing computer by name or ID. */\n static async get(computerIdOrName: string, config?: ClientConfig): Promise<Computer> {\n const client = new ComputersClient(await resolveClientConfig(config));\n const info = await client.get(computerIdOrName);\n return new Computer(client, info);\n }\n\n /** List computers in the current account. */\n static async list(params: ListComputersParams = {}, config?: ClientConfig): Promise<Computer[]> {\n const client = new ComputersClient(await resolveClientConfig(config));\n const response = await client.list(params);\n return response.computers.map((info) => new Computer(client, info));\n }\n\n /** List available computer templates. */\n static async listTemplates(config?: ClientConfig): Promise<SandboxTemplateInfo[]> {\n const client = new ComputersClient(await resolveClientConfig(config));\n return client.listTemplates();\n }\n\n /** Wrap an existing API response in the convenience object. */\n static fromInfo(info: ComputerInfo, config: ClientConfig = defaultConfig()): Computer {\n return new Computer(new ComputersClient(config), info);\n }\n\n get id(): string {\n return this.info.id;\n }\n\n get name(): string {\n return this.info.name;\n }\n\n get status(): ComputerStatus {\n return this.info.status;\n }\n\n get vcpus(): number {\n return this.info.vcpus;\n }\n\n get ramMb(): number {\n return this.info.ramMb;\n }\n\n get diskSizeMb(): number {\n return this.info.diskSizeMb;\n }\n\n get image(): string {\n return this.info.image;\n }\n\n get templateId(): string {\n return this.info.templateId;\n }\n\n get templateVersion(): string | null | undefined {\n return this.info.templateVersion;\n }\n\n get connection(): ComputerConnectionInfo | undefined {\n return this.info.connection;\n }\n\n get publishedPorts(): ComputerPublishedPortInfo[] | undefined {\n return this.info.publishedPorts;\n }\n\n get lastError(): string | null | undefined {\n return this.info.lastError;\n }\n\n get createdAt(): string {\n return this.info.createdAt;\n }\n\n get stoppedAt(): string | null | undefined {\n return this.info.stoppedAt;\n }\n\n /** Get one field from the latest computer data. */\n get<K extends keyof ComputerInfo>(key: K): ComputerInfo[K] {\n return this.info[key];\n }\n\n /** Return a copy of the latest computer data. */\n toJSON(): ComputerInfo {\n return { ...this.info };\n }\n\n /** Reload this computer from Celesto. */\n async refresh(): Promise<this> {\n this.info = await this.client.get(this.id);\n return this;\n }\n\n /** Run a shell command on this computer. */\n async run(command: string, params: ExecParams = {}): Promise<ComputerExecResponse> {\n return this.client.exec(this.id, command, params);\n }\n\n /** Alias for run(). */\n async exec(command: string, params: ExecParams = {}): Promise<ComputerExecResponse> {\n return this.run(command, params);\n }\n\n /** Run a shell command and stream output and exit events as they arrive. */\n runStream(\n command: string,\n params: ExecParams = {},\n ): AsyncGenerator<ComputerExecStreamEvent> {\n return this.client.execStream(this.id, command, params);\n }\n\n /** Alias for runStream(). */\n execStream(\n command: string,\n params: ExecParams = {},\n ): AsyncGenerator<ComputerExecStreamEvent> {\n return this.runStream(command, params);\n }\n\n /** List recent commands executed on this computer. */\n async listCommandHistory(\n params: ListCommandHistoryParams = {},\n ): Promise<ComputerCommandHistoryResponse> {\n return this.client.listCommandHistory(this.id, params);\n }\n\n /** Create a short-lived direct connection to Celesto's terminal gateway. */\n async createTerminalSession(): Promise<TerminalSessionInfo> {\n return this.client.createTerminalSession(this.id);\n }\n\n /** Create a short-lived CDP connection for browser automation. */\n async createBrowserConnection(): Promise<BrowserConnectionInfo> {\n return this.client.createBrowserConnection(this.id);\n }\n\n /** Create a short-lived RFB connection to watch or control the graphical display. */\n async createDisplayConnection(\n params: DisplayConnectionParams = {},\n ): Promise<DisplayConnectionInfo> {\n return this.client.createDisplayConnection(this.id, params);\n }\n\n /** @deprecated Use createTerminalSession(). */\n async getTerminalConnection(): Promise<TerminalSessionInfo> {\n return this.createTerminalSession();\n }\n\n /** Stop this computer and update the local data. */\n async stop(): Promise<this> {\n this.info = await this.client.stop(this.id);\n return this;\n }\n\n /** Start this computer and update the local data. */\n async start(): Promise<this> {\n this.info = await this.client.start(this.id);\n return this;\n }\n\n /** Delete this computer and update the local data. */\n async delete(): Promise<this> {\n this.info = await this.client.delete(this.id);\n return this;\n }\n\n /** Publish a port and return its public URL when the API provides one. */\n async publishPort(port = 8000): Promise<string | null> {\n const published = await this.client.publishPort(this.id, port);\n const existing = this.info.publishedPorts ?? [];\n this.info = {\n ...this.info,\n publishedPorts: [...existing.filter((item) => item.port !== published.port), published],\n };\n return published.url ?? null;\n }\n\n /** List public ports for this computer. */\n async listPublishedPorts(): Promise<ComputerPublishedPortInfo[]> {\n const publishedPorts = await this.client.listPublishedPorts(this.id);\n this.info = { ...this.info, publishedPorts };\n return publishedPorts;\n }\n\n /** Remove a public port route. */\n async unpublishPort(port = 8000): Promise<ComputerPublishedPortInfo> {\n const unpublished = await this.client.unpublishPort(this.id, port);\n this.info = {\n ...this.info,\n publishedPorts: (this.info.publishedPorts ?? []).filter((item) => item.port !== port),\n };\n return unpublished;\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,YAAY,wBAA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AO,mBAAmB,KAAK,EAAE;AACnE,SAAK,OAAO,EAAE,GAAG,KAAK,MAAM,eAAe;AAC3C,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,MAAM,cAAc,OAAO,KAA0C;AACnE,UAAM,cAAc,MAAM,KAAK,OAAO,cAAc,KAAK,IAAI,IAAI;AACjE,SAAK,OAAO;AAAA,MACV,GAAG,KAAK;AAAA,MACR,iBAAiB,KAAK,KAAK,kBAAkB,CAAC,GAAG,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI;AAAA,IACtF;AACA,WAAO;AAAA,EACT;AACF;","names":["path"]}
|
package/dist/computers/index.cjs
CHANGED
|
@@ -327,18 +327,50 @@ var toCommandHistoryEntry = (payload) => ({
|
|
|
327
327
|
stderrBytes: payload.stderr_bytes,
|
|
328
328
|
errorType: payload.error_type
|
|
329
329
|
});
|
|
330
|
+
function authenticatedGatewayUrl(gatewayUrl, token) {
|
|
331
|
+
const separator = gatewayUrl.includes("?") ? "&" : "?";
|
|
332
|
+
return `${gatewayUrl}${separator}token=${encodeURIComponent(token)}`;
|
|
333
|
+
}
|
|
330
334
|
var toTerminalConnectionInfo = (payload) => {
|
|
331
|
-
const separator = payload.gateway_url.includes("?") ? "&" : "?";
|
|
332
335
|
return {
|
|
333
336
|
terminalId: payload.terminal_id,
|
|
334
337
|
gatewayUrl: payload.gateway_url,
|
|
335
|
-
url:
|
|
338
|
+
url: authenticatedGatewayUrl(payload.gateway_url, payload.token),
|
|
336
339
|
token: payload.token,
|
|
337
340
|
expiresAt: payload.expires_at,
|
|
338
341
|
headers: {},
|
|
339
342
|
firstMessage: ""
|
|
340
343
|
};
|
|
341
344
|
};
|
|
345
|
+
var toBrowserConnectionInfo = (payload) => {
|
|
346
|
+
if (typeof payload !== "object" || payload === null || typeof payload.gateway_url !== "string" || typeof payload.token !== "string" || typeof payload.expires_at !== "string") {
|
|
347
|
+
throw new CelestoError(
|
|
348
|
+
"Celesto did not return browser connection details. Call createBrowserConnection() again."
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
const connection = payload;
|
|
352
|
+
return {
|
|
353
|
+
gatewayUrl: connection.gateway_url,
|
|
354
|
+
url: authenticatedGatewayUrl(connection.gateway_url, connection.token),
|
|
355
|
+
token: connection.token,
|
|
356
|
+
expiresAt: connection.expires_at
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
var toDisplayConnectionInfo = (payload) => {
|
|
360
|
+
if (typeof payload !== "object" || payload === null || payload.mode !== "read_only" && payload.mode !== "read_write") {
|
|
361
|
+
throw new CelestoError(
|
|
362
|
+
"Celesto did not return display connection details. Call createDisplayConnection() again."
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
const connection = payload;
|
|
366
|
+
try {
|
|
367
|
+
return { ...toBrowserConnectionInfo(connection), mode: connection.mode };
|
|
368
|
+
} catch {
|
|
369
|
+
throw new CelestoError(
|
|
370
|
+
"Celesto did not return display connection details. Call createDisplayConnection() again."
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
342
374
|
var toSandboxTemplateInfo = (payload) => ({
|
|
343
375
|
id: payload.id,
|
|
344
376
|
displayName: payload.display_name,
|
|
@@ -793,6 +825,27 @@ var ComputersClient = class {
|
|
|
793
825
|
});
|
|
794
826
|
return toTerminalConnectionInfo(data);
|
|
795
827
|
}
|
|
828
|
+
/** Create a short-lived CDP connection for browser automation. */
|
|
829
|
+
async createBrowserConnection(computerIdOrName, options) {
|
|
830
|
+
const ctx = buildRequestContext(this.config);
|
|
831
|
+
const data = await request(ctx, {
|
|
832
|
+
method: "POST",
|
|
833
|
+
path: computersPath(`/${encodeURIComponent(computerIdOrName)}/browser`),
|
|
834
|
+
...pickOverrides(options)
|
|
835
|
+
});
|
|
836
|
+
return toBrowserConnectionInfo(data);
|
|
837
|
+
}
|
|
838
|
+
/** Create a short-lived RFB connection to watch or control the graphical display. */
|
|
839
|
+
async createDisplayConnection(computerIdOrName, params = {}, options) {
|
|
840
|
+
const ctx = buildRequestContext(this.config);
|
|
841
|
+
const data = await request(ctx, {
|
|
842
|
+
method: "POST",
|
|
843
|
+
path: computersPath(`/${encodeURIComponent(computerIdOrName)}/display`),
|
|
844
|
+
body: params.mode === void 0 ? void 0 : { mode: params.mode },
|
|
845
|
+
...pickOverrides(options)
|
|
846
|
+
});
|
|
847
|
+
return toDisplayConnectionInfo(data);
|
|
848
|
+
}
|
|
796
849
|
/** @deprecated Use createTerminalSession(). */
|
|
797
850
|
async getTerminalConnection(computerIdOrName, options) {
|
|
798
851
|
return this.createTerminalSession(computerIdOrName, options);
|
|
@@ -914,6 +967,14 @@ var Computer = class _Computer {
|
|
|
914
967
|
async createTerminalSession() {
|
|
915
968
|
return this.client.createTerminalSession(this.id);
|
|
916
969
|
}
|
|
970
|
+
/** Create a short-lived CDP connection for browser automation. */
|
|
971
|
+
async createBrowserConnection() {
|
|
972
|
+
return this.client.createBrowserConnection(this.id);
|
|
973
|
+
}
|
|
974
|
+
/** Create a short-lived RFB connection to watch or control the graphical display. */
|
|
975
|
+
async createDisplayConnection(params = {}) {
|
|
976
|
+
return this.client.createDisplayConnection(this.id, params);
|
|
977
|
+
}
|
|
917
978
|
/** @deprecated Use createTerminalSession(). */
|
|
918
979
|
async getTerminalConnection() {
|
|
919
980
|
return this.createTerminalSession();
|