@celestoai/sdk 0.1.2 → 0.1.4

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.
@@ -0,0 +1,747 @@
1
+ import {
2
+ CelestoError,
3
+ CelestoNetworkError,
4
+ buildRequestContext,
5
+ request,
6
+ requestStream
7
+ } from "./chunk-JS6BTDP5.js";
8
+
9
+ // src/core/auth.ts
10
+ import { execFile as execFileCallback } from "child_process";
11
+ import { readFile } from "fs/promises";
12
+ import path from "path";
13
+ import { promisify } from "util";
14
+ import { parse } from "dotenv";
15
+ var execFile = promisify(execFileCallback);
16
+ var MISSING_CREDENTIALS_MESSAGE = "No Celesto credentials found. Run pip install celesto && celesto auth login, or export CELESTO_API_KEY.";
17
+ function nonEmpty(value) {
18
+ const trimmed = value?.trim();
19
+ return trimmed ? trimmed : void 0;
20
+ }
21
+ async function readDotEnvApiKey(cwd, readDotEnv) {
22
+ try {
23
+ const contents = await readDotEnv(path.join(cwd, ".env"));
24
+ return nonEmpty(parse(contents).CELESTO_API_KEY);
25
+ } catch {
26
+ return void 0;
27
+ }
28
+ }
29
+ async function loadCliApiKey() {
30
+ try {
31
+ const { stdout } = await execFile("celesto", ["auth", "token"], {
32
+ encoding: "utf8",
33
+ timeout: 5e3,
34
+ maxBuffer: 64 * 1024
35
+ });
36
+ return nonEmpty(stdout);
37
+ } catch {
38
+ return void 0;
39
+ }
40
+ }
41
+ async function resolveCelestoApiKey(options = {}) {
42
+ const env = options.env ?? process.env;
43
+ const environmentKey = nonEmpty(env.CELESTO_API_KEY);
44
+ if (environmentKey) return environmentKey;
45
+ const dotEnvKey = await readDotEnvApiKey(
46
+ options.cwd ?? process.cwd(),
47
+ options.readDotEnv ?? ((filePath) => readFile(filePath, "utf8"))
48
+ );
49
+ if (dotEnvKey) return dotEnvKey;
50
+ return (options.loadSavedApiKey ?? loadCliApiKey)();
51
+ }
52
+ async function resolveClientConfig(config = {}, options = {}) {
53
+ if (nonEmpty(config.token) || nonEmpty(config.apiKey)) return config;
54
+ const apiKey = await resolveCelestoApiKey(options);
55
+ if (!apiKey) throw new CelestoError(MISSING_CREDENTIALS_MESSAGE);
56
+ return { ...config, token: apiKey };
57
+ }
58
+
59
+ // src/computers/client.ts
60
+ var toConnection = (payload) => {
61
+ if (!payload) {
62
+ return void 0;
63
+ }
64
+ const out = {};
65
+ if (payload.ssh != null) {
66
+ out.ssh = payload.ssh;
67
+ }
68
+ if (payload.access_url != null) {
69
+ out.accessUrl = payload.access_url;
70
+ }
71
+ return out;
72
+ };
73
+ var toPublishedPortInfo = (payload) => ({
74
+ id: payload.id ?? null,
75
+ computerId: payload.computer_id,
76
+ port: payload.port,
77
+ url: payload.url ?? null,
78
+ status: payload.status,
79
+ createdAt: payload.created_at ?? null
80
+ });
81
+ var toComputerInfo = (payload) => ({
82
+ id: payload.id,
83
+ name: payload.name,
84
+ status: payload.status,
85
+ vcpus: payload.vcpus,
86
+ ramMb: payload.ram_mb,
87
+ diskSizeMb: payload.disk_size_mb,
88
+ image: payload.image,
89
+ templateId: payload.template_id,
90
+ templateVersion: payload.template_version ?? null,
91
+ connection: toConnection(payload.connection),
92
+ publishedPorts: payload.published_ports?.map(toPublishedPortInfo),
93
+ lastError: payload.last_error ?? null,
94
+ createdAt: payload.created_at,
95
+ stoppedAt: payload.stopped_at ?? null
96
+ });
97
+ var toExecResponse = (payload) => {
98
+ const response = {
99
+ exitCode: payload.exit_code,
100
+ stdout: payload.stdout,
101
+ stderr: payload.stderr
102
+ };
103
+ if (payload.command_id !== void 0) response.commandId = payload.command_id;
104
+ if (payload.duration_ms !== void 0) response.durationMs = payload.duration_ms;
105
+ if (payload.timed_out !== void 0) response.timedOut = payload.timed_out;
106
+ return response;
107
+ };
108
+ var toCommandHistoryEntry = (payload) => ({
109
+ commandId: payload.command_id,
110
+ source: payload.source,
111
+ status: payload.status,
112
+ startedAt: payload.started_at,
113
+ endedAt: payload.ended_at,
114
+ durationMs: payload.duration_ms,
115
+ timeoutSeconds: payload.timeout_seconds,
116
+ exitCode: payload.exit_code,
117
+ stdoutBytes: payload.stdout_bytes,
118
+ stderrBytes: payload.stderr_bytes,
119
+ errorType: payload.error_type
120
+ });
121
+ var toTerminalConnectionInfo = (payload) => {
122
+ const separator = payload.gateway_url.includes("?") ? "&" : "?";
123
+ return {
124
+ terminalId: payload.terminal_id,
125
+ gatewayUrl: payload.gateway_url,
126
+ url: `${payload.gateway_url}${separator}token=${encodeURIComponent(payload.token)}`,
127
+ token: payload.token,
128
+ expiresAt: payload.expires_at,
129
+ headers: {},
130
+ firstMessage: ""
131
+ };
132
+ };
133
+ var toSandboxTemplateInfo = (payload) => ({
134
+ id: payload.id,
135
+ displayName: payload.display_name,
136
+ description: payload.description,
137
+ defaultVcpus: payload.default_vcpus,
138
+ defaultRamMb: payload.default_ram_mb,
139
+ defaultDiskSizeMb: payload.default_disk_size_mb,
140
+ version: payload.version ?? null,
141
+ experimental: payload.experimental
142
+ });
143
+ var diskUnitsToMb = {
144
+ "": 1,
145
+ m: 1,
146
+ mb: 1,
147
+ mib: 1,
148
+ g: 1024,
149
+ gb: 1024,
150
+ gib: 1024,
151
+ t: 1024 * 1024,
152
+ tb: 1024 * 1024,
153
+ tib: 1024 * 1024
154
+ };
155
+ var isAsciiDigit = (char) => char >= "0" && char <= "9";
156
+ var isAsciiLetter = (char) => char >= "a" && char <= "z" || char >= "A" && char <= "Z";
157
+ var isSeparatorWhitespace = (char) => char === " " || char === " ";
158
+ var parseDiskString = (disk) => {
159
+ const value = disk.trim();
160
+ if (!value) {
161
+ return void 0;
162
+ }
163
+ let index = 0;
164
+ let digitCount = 0;
165
+ let hasDecimalPoint = false;
166
+ while (index < value.length) {
167
+ const char = value[index];
168
+ if (isAsciiDigit(char)) {
169
+ digitCount += 1;
170
+ index += 1;
171
+ continue;
172
+ }
173
+ if (char === "." && !hasDecimalPoint) {
174
+ hasDecimalPoint = true;
175
+ index += 1;
176
+ continue;
177
+ }
178
+ break;
179
+ }
180
+ if (digitCount === 0 || value[index - 1] === ".") {
181
+ return void 0;
182
+ }
183
+ const amount = value.slice(0, index);
184
+ while (index < value.length && isSeparatorWhitespace(value[index])) {
185
+ index += 1;
186
+ }
187
+ const unit = value.slice(index);
188
+ if ([...unit].some((char) => !isAsciiLetter(char))) {
189
+ return void 0;
190
+ }
191
+ return { amount, unit };
192
+ };
193
+ var parseDiskSizeMb = (disk) => {
194
+ if (disk === void 0) {
195
+ return void 0;
196
+ }
197
+ if (typeof disk === "number") {
198
+ if (!Number.isInteger(disk) || disk <= 0) {
199
+ throw new Error("disk as a number must be a whole number of MB.");
200
+ }
201
+ return disk;
202
+ }
203
+ const parsedDisk = parseDiskString(disk);
204
+ if (!parsedDisk) {
205
+ throw new Error("disk must be a size in MB or a string like '2gb'.");
206
+ }
207
+ const multiplier = diskUnitsToMb[parsedDisk.unit.toLowerCase()];
208
+ if (multiplier === void 0) {
209
+ throw new Error("disk must use MB, GB, or TB, for example '2048mb' or '2gb'.");
210
+ }
211
+ const sizeMb = Number(parsedDisk.amount) * multiplier;
212
+ if (!Number.isInteger(sizeMb) || sizeMb <= 0) {
213
+ throw new Error("disk must resolve to a whole number of MB, for example '1536mb' or '1.5gb'.");
214
+ }
215
+ return sizeMb;
216
+ };
217
+ var buildCreateComputerBody = (params) => {
218
+ if (params.cpus !== void 0 && params.vcpus !== void 0 && params.cpus !== params.vcpus) {
219
+ throw new Error("cpus and vcpus must have the same value when both are provided.");
220
+ }
221
+ if (params.memory !== void 0 && params.ramMb !== void 0 && params.memory !== params.ramMb) {
222
+ throw new Error("memory and ramMb must have the same value when both are provided.");
223
+ }
224
+ const parsedDiskSizeMb = parseDiskSizeMb(params.disk);
225
+ if (parsedDiskSizeMb !== void 0 && params.diskSizeMb !== void 0 && parsedDiskSizeMb !== params.diskSizeMb) {
226
+ throw new Error("disk and diskSizeMb must have the same value when both are provided.");
227
+ }
228
+ const body = {};
229
+ const vcpus = params.vcpus ?? params.cpus;
230
+ const ramMb = params.ramMb ?? params.memory;
231
+ const diskSizeMb = params.diskSizeMb ?? parsedDiskSizeMb;
232
+ if (vcpus !== void 0) {
233
+ body.vcpus = vcpus;
234
+ }
235
+ if (ramMb !== void 0) {
236
+ body.ram_mb = ramMb;
237
+ }
238
+ if (diskSizeMb !== void 0) {
239
+ body.disk_size_mb = diskSizeMb;
240
+ }
241
+ if (params.image !== void 0) {
242
+ body.image = params.image;
243
+ }
244
+ if (params.templateId !== void 0) {
245
+ body.template_id = params.templateId;
246
+ }
247
+ if (params.templateVersion !== void 0) {
248
+ body.template_version = params.templateVersion;
249
+ }
250
+ return body;
251
+ };
252
+ var computersPath = (path2) => `/v1/computers${path2}`;
253
+ var pickOverrides = (options) => ({
254
+ headers: options?.headers,
255
+ signal: options?.signal
256
+ });
257
+ var optionalNumber = (value) => typeof value === "number" ? value : void 0;
258
+ var optionalBoolean = (value) => typeof value === "boolean" ? value : void 0;
259
+ var parseExecStreamEvent = (value) => {
260
+ if (!value || typeof value !== "object") {
261
+ throw new Error("Celesto returned an invalid command stream event.");
262
+ }
263
+ const event = value;
264
+ if (event.type === "stdout" || event.type === "stderr") {
265
+ if (typeof event.data !== "string") {
266
+ throw new Error("Celesto returned command output without text data.");
267
+ }
268
+ return { type: event.type, data: event.data };
269
+ }
270
+ if (event.type === "started") {
271
+ if (typeof event.command_id !== "string" || typeof event.started_at_unix_ms !== "number" || typeof event.timeout_seconds !== "number") {
272
+ throw new Error("Celesto returned an invalid command-start event.");
273
+ }
274
+ return {
275
+ type: "started",
276
+ commandId: event.command_id,
277
+ startedAtUnixMs: event.started_at_unix_ms,
278
+ timeoutSeconds: event.timeout_seconds
279
+ };
280
+ }
281
+ if (event.type === "exit") {
282
+ if (typeof event.exit_code !== "number") {
283
+ throw new Error("Celesto returned an invalid command-exit event.");
284
+ }
285
+ const result = {
286
+ type: "exit",
287
+ exitCode: event.exit_code
288
+ };
289
+ if (typeof event.command_id === "string") result.commandId = event.command_id;
290
+ const startedAtUnixMs = optionalNumber(event.started_at_unix_ms);
291
+ const endedAtUnixMs = optionalNumber(event.ended_at_unix_ms);
292
+ const durationMs = optionalNumber(event.duration_ms);
293
+ const timedOut = optionalBoolean(event.timed_out);
294
+ if (startedAtUnixMs !== void 0) result.startedAtUnixMs = startedAtUnixMs;
295
+ if (endedAtUnixMs !== void 0) result.endedAtUnixMs = endedAtUnixMs;
296
+ if (durationMs !== void 0) result.durationMs = durationMs;
297
+ if (timedOut !== void 0) result.timedOut = timedOut;
298
+ return result;
299
+ }
300
+ throw new Error("Celesto returned an unknown command stream event.");
301
+ };
302
+ var parseSseDataLine = (line) => {
303
+ const text = line.trim();
304
+ if (!text || !text.startsWith("data:")) {
305
+ return void 0;
306
+ }
307
+ const data = text.slice("data:".length).trim();
308
+ if (!data || data === "[DONE]") {
309
+ return void 0;
310
+ }
311
+ try {
312
+ return parseExecStreamEvent(JSON.parse(data));
313
+ } catch (error) {
314
+ if (error instanceof SyntaxError) {
315
+ throw new Error("Celesto returned malformed JSON in the command stream.");
316
+ }
317
+ throw error;
318
+ }
319
+ };
320
+ var createManagedSignal = (signal, timeoutMs) => {
321
+ if (!timeoutMs || timeoutMs <= 0) {
322
+ return { signal, cleanup: () => {
323
+ } };
324
+ }
325
+ const controller = new AbortController();
326
+ const abort = () => controller.abort();
327
+ if (signal?.aborted) {
328
+ abort();
329
+ } else {
330
+ signal?.addEventListener("abort", abort, { once: true });
331
+ }
332
+ const timer = setTimeout(abort, timeoutMs);
333
+ return {
334
+ signal: controller.signal,
335
+ cleanup: () => {
336
+ clearTimeout(timer);
337
+ signal?.removeEventListener("abort", abort);
338
+ }
339
+ };
340
+ };
341
+ var toNetworkError = (error) => {
342
+ if (error instanceof CelestoNetworkError) return error;
343
+ const cause = error instanceof Error ? error : new Error(String(error));
344
+ return new CelestoNetworkError(cause.message, cause);
345
+ };
346
+ var withFallbackCommandId = (event, commandId) => {
347
+ if (event.type !== "exit" || event.commandId || !commandId) return event;
348
+ return { ...event, commandId };
349
+ };
350
+ var ComputersClient = class {
351
+ constructor(config) {
352
+ this.config = config;
353
+ }
354
+ async create(params = {}, options) {
355
+ const ctx = buildRequestContext(this.config);
356
+ const data = await request(ctx, {
357
+ method: "POST",
358
+ path: computersPath(""),
359
+ body: buildCreateComputerBody(params),
360
+ ...pickOverrides(options)
361
+ });
362
+ return toComputerInfo(data);
363
+ }
364
+ async listTemplates(options) {
365
+ const ctx = buildRequestContext(this.config);
366
+ const data = await request(ctx, {
367
+ method: "GET",
368
+ path: computersPath("/templates"),
369
+ ...pickOverrides(options)
370
+ });
371
+ return data.map(toSandboxTemplateInfo);
372
+ }
373
+ async list(params = {}, options) {
374
+ const ctx = buildRequestContext(this.config);
375
+ const data = await request(ctx, {
376
+ method: "GET",
377
+ path: computersPath(""),
378
+ query: {
379
+ status: params.status,
380
+ template_id: params.templateId,
381
+ project_id: params.projectId,
382
+ limit: params.limit
383
+ },
384
+ ...pickOverrides(options)
385
+ });
386
+ return {
387
+ computers: data.computers.map(toComputerInfo),
388
+ count: data.count
389
+ };
390
+ }
391
+ async get(computerId, options) {
392
+ const ctx = buildRequestContext(this.config);
393
+ const data = await request(ctx, {
394
+ method: "GET",
395
+ path: computersPath(`/${encodeURIComponent(computerId)}`),
396
+ ...pickOverrides(options)
397
+ });
398
+ return toComputerInfo(data);
399
+ }
400
+ async exec(computerId, command, params = {}, options) {
401
+ const ctx = buildRequestContext(this.config);
402
+ const managedSignal = createManagedSignal(
403
+ params.signal ?? options?.signal,
404
+ this.config.timeoutMs
405
+ );
406
+ try {
407
+ const data = await request(ctx, {
408
+ method: "POST",
409
+ path: computersPath(`/${encodeURIComponent(computerId)}/exec`),
410
+ body: {
411
+ command,
412
+ timeout: params.timeout ?? 30
413
+ },
414
+ headers: options?.headers,
415
+ signal: managedSignal.signal
416
+ });
417
+ return toExecResponse(data);
418
+ } finally {
419
+ managedSignal.cleanup();
420
+ }
421
+ }
422
+ async *execStream(computerId, command, params = {}, options) {
423
+ const ctx = buildRequestContext(this.config);
424
+ const managedSignal = createManagedSignal(
425
+ params.signal ?? options?.signal,
426
+ this.config.timeoutMs
427
+ );
428
+ let reader;
429
+ let completed = false;
430
+ try {
431
+ const response = await requestStream(ctx, {
432
+ method: "POST",
433
+ path: computersPath(`/${encodeURIComponent(computerId)}/exec/stream`),
434
+ body: {
435
+ command,
436
+ timeout: params.timeout ?? 30
437
+ },
438
+ headers: options?.headers,
439
+ signal: managedSignal.signal
440
+ });
441
+ if (!response.body) {
442
+ throw new Error("Celesto did not return a command output stream.");
443
+ }
444
+ const responseCommandId = response.headers.get("x-celesto-command-id") ?? void 0;
445
+ reader = response.body.getReader();
446
+ const decoder = new TextDecoder();
447
+ let buffer = "";
448
+ while (true) {
449
+ let chunk;
450
+ try {
451
+ chunk = await reader.read();
452
+ } catch (error) {
453
+ throw toNetworkError(error);
454
+ }
455
+ if (chunk.done) {
456
+ completed = true;
457
+ buffer += decoder.decode();
458
+ break;
459
+ }
460
+ buffer += decoder.decode(chunk.value, { stream: true });
461
+ let newlineIndex = buffer.indexOf("\n");
462
+ while (newlineIndex !== -1) {
463
+ const line = buffer.slice(0, newlineIndex).replace(/\r$/, "");
464
+ buffer = buffer.slice(newlineIndex + 1);
465
+ const parsed = parseSseDataLine(line);
466
+ if (parsed) {
467
+ const event = withFallbackCommandId(parsed, responseCommandId);
468
+ yield event;
469
+ if (event.type === "exit") return;
470
+ }
471
+ newlineIndex = buffer.indexOf("\n");
472
+ }
473
+ }
474
+ if (buffer) {
475
+ const parsed = parseSseDataLine(buffer);
476
+ if (parsed) {
477
+ const event = withFallbackCommandId(parsed, responseCommandId);
478
+ yield event;
479
+ if (event.type === "exit") return;
480
+ }
481
+ }
482
+ throw new Error("Command stream ended before Celesto returned an exit status.");
483
+ } finally {
484
+ if (reader) {
485
+ if (!completed) {
486
+ try {
487
+ await reader.cancel();
488
+ } catch {
489
+ }
490
+ }
491
+ reader.releaseLock();
492
+ }
493
+ managedSignal.cleanup();
494
+ }
495
+ }
496
+ async listCommandHistory(computerId, params = {}, options) {
497
+ const ctx = buildRequestContext(this.config);
498
+ const data = await request(ctx, {
499
+ method: "GET",
500
+ path: computersPath(`/${encodeURIComponent(computerId)}/commands`),
501
+ query: { limit: params.limit },
502
+ ...pickOverrides(options)
503
+ });
504
+ return {
505
+ commands: data.commands.map(toCommandHistoryEntry),
506
+ count: data.count
507
+ };
508
+ }
509
+ async stop(computerId, options) {
510
+ const ctx = buildRequestContext(this.config);
511
+ const data = await request(ctx, {
512
+ method: "POST",
513
+ path: computersPath(`/${encodeURIComponent(computerId)}/stop`),
514
+ ...pickOverrides(options)
515
+ });
516
+ return toComputerInfo(data);
517
+ }
518
+ async start(computerId, options) {
519
+ const ctx = buildRequestContext(this.config);
520
+ const data = await request(ctx, {
521
+ method: "POST",
522
+ path: computersPath(`/${encodeURIComponent(computerId)}/start`),
523
+ ...pickOverrides(options)
524
+ });
525
+ return toComputerInfo(data);
526
+ }
527
+ async delete(computerId, options) {
528
+ const ctx = buildRequestContext(this.config);
529
+ const data = await request(ctx, {
530
+ method: "DELETE",
531
+ path: computersPath(`/${encodeURIComponent(computerId)}`),
532
+ ...pickOverrides(options)
533
+ });
534
+ return toComputerInfo(data);
535
+ }
536
+ async publishPort(computerId, port = 8e3, options) {
537
+ const ctx = buildRequestContext(this.config);
538
+ const data = await request(ctx, {
539
+ method: "POST",
540
+ path: computersPath(`/${encodeURIComponent(computerId)}/published-ports`),
541
+ body: { port },
542
+ ...pickOverrides(options)
543
+ });
544
+ return toPublishedPortInfo(data);
545
+ }
546
+ async listPublishedPorts(computerId, options) {
547
+ const ctx = buildRequestContext(this.config);
548
+ const data = await request(ctx, {
549
+ method: "GET",
550
+ path: computersPath(`/${encodeURIComponent(computerId)}/published-ports`),
551
+ ...pickOverrides(options)
552
+ });
553
+ return data.map(toPublishedPortInfo);
554
+ }
555
+ async unpublishPort(computerId, port = 8e3, options) {
556
+ const ctx = buildRequestContext(this.config);
557
+ const data = await request(ctx, {
558
+ method: "DELETE",
559
+ path: computersPath(`/${encodeURIComponent(computerId)}/published-ports/${port}`),
560
+ ...pickOverrides(options)
561
+ });
562
+ return toPublishedPortInfo(data);
563
+ }
564
+ /** Create a short-lived direct connection to Celesto's terminal gateway. */
565
+ async createTerminalSession(computerIdOrName, options) {
566
+ const ctx = buildRequestContext(this.config);
567
+ const data = await request(ctx, {
568
+ method: "POST",
569
+ path: computersPath(`/${encodeURIComponent(computerIdOrName)}/terminals`),
570
+ ...pickOverrides(options)
571
+ });
572
+ return toTerminalConnectionInfo(data);
573
+ }
574
+ /** @deprecated Use createTerminalSession(). */
575
+ async getTerminalConnection(computerIdOrName, options) {
576
+ return this.createTerminalSession(computerIdOrName, options);
577
+ }
578
+ };
579
+
580
+ // src/computers/computer.ts
581
+ var defaultConfig = () => ({
582
+ token: typeof process !== "undefined" ? process.env.CELESTO_API_KEY : void 0
583
+ });
584
+ var Computer = class _Computer {
585
+ constructor(client, info) {
586
+ this.client = client;
587
+ this.info = info;
588
+ }
589
+ /** Create a new computer and return an object with methods on it. */
590
+ static async create(params = {}, config) {
591
+ const client = new ComputersClient(await resolveClientConfig(config));
592
+ const info = await client.create(params);
593
+ return new _Computer(client, info);
594
+ }
595
+ /** Load an existing computer by name or ID. */
596
+ static async get(computerIdOrName, config) {
597
+ const client = new ComputersClient(await resolveClientConfig(config));
598
+ const info = await client.get(computerIdOrName);
599
+ return new _Computer(client, info);
600
+ }
601
+ /** List computers in the current account. */
602
+ static async list(params = {}, config) {
603
+ const client = new ComputersClient(await resolveClientConfig(config));
604
+ const response = await client.list(params);
605
+ return response.computers.map((info) => new _Computer(client, info));
606
+ }
607
+ /** List available computer templates. */
608
+ static async listTemplates(config) {
609
+ const client = new ComputersClient(await resolveClientConfig(config));
610
+ return client.listTemplates();
611
+ }
612
+ /** Wrap an existing API response in the convenience object. */
613
+ static fromInfo(info, config = defaultConfig()) {
614
+ return new _Computer(new ComputersClient(config), info);
615
+ }
616
+ get id() {
617
+ return this.info.id;
618
+ }
619
+ get name() {
620
+ return this.info.name;
621
+ }
622
+ get status() {
623
+ return this.info.status;
624
+ }
625
+ get vcpus() {
626
+ return this.info.vcpus;
627
+ }
628
+ get ramMb() {
629
+ return this.info.ramMb;
630
+ }
631
+ get diskSizeMb() {
632
+ return this.info.diskSizeMb;
633
+ }
634
+ get image() {
635
+ return this.info.image;
636
+ }
637
+ get templateId() {
638
+ return this.info.templateId;
639
+ }
640
+ get templateVersion() {
641
+ return this.info.templateVersion;
642
+ }
643
+ get connection() {
644
+ return this.info.connection;
645
+ }
646
+ get publishedPorts() {
647
+ return this.info.publishedPorts;
648
+ }
649
+ get lastError() {
650
+ return this.info.lastError;
651
+ }
652
+ get createdAt() {
653
+ return this.info.createdAt;
654
+ }
655
+ get stoppedAt() {
656
+ return this.info.stoppedAt;
657
+ }
658
+ /** Get one field from the latest computer data. */
659
+ get(key) {
660
+ return this.info[key];
661
+ }
662
+ /** Return a copy of the latest computer data. */
663
+ toJSON() {
664
+ return { ...this.info };
665
+ }
666
+ /** Reload this computer from Celesto. */
667
+ async refresh() {
668
+ this.info = await this.client.get(this.id);
669
+ return this;
670
+ }
671
+ /** Run a shell command on this computer. */
672
+ async run(command, params = {}) {
673
+ return this.client.exec(this.id, command, params);
674
+ }
675
+ /** Alias for run(). */
676
+ async exec(command, params = {}) {
677
+ return this.run(command, params);
678
+ }
679
+ /** Run a shell command and stream output and exit events as they arrive. */
680
+ runStream(command, params = {}) {
681
+ return this.client.execStream(this.id, command, params);
682
+ }
683
+ /** Alias for runStream(). */
684
+ execStream(command, params = {}) {
685
+ return this.runStream(command, params);
686
+ }
687
+ /** List recent commands executed on this computer. */
688
+ async listCommandHistory(params = {}) {
689
+ return this.client.listCommandHistory(this.id, params);
690
+ }
691
+ /** Create a short-lived direct connection to Celesto's terminal gateway. */
692
+ async createTerminalSession() {
693
+ return this.client.createTerminalSession(this.id);
694
+ }
695
+ /** @deprecated Use createTerminalSession(). */
696
+ async getTerminalConnection() {
697
+ return this.createTerminalSession();
698
+ }
699
+ /** Stop this computer and update the local data. */
700
+ async stop() {
701
+ this.info = await this.client.stop(this.id);
702
+ return this;
703
+ }
704
+ /** Start this computer and update the local data. */
705
+ async start() {
706
+ this.info = await this.client.start(this.id);
707
+ return this;
708
+ }
709
+ /** Delete this computer and update the local data. */
710
+ async delete() {
711
+ this.info = await this.client.delete(this.id);
712
+ return this;
713
+ }
714
+ /** Publish a port and return its public URL when the API provides one. */
715
+ async publishPort(port = 8e3) {
716
+ const published = await this.client.publishPort(this.id, port);
717
+ const existing = this.info.publishedPorts ?? [];
718
+ this.info = {
719
+ ...this.info,
720
+ publishedPorts: [...existing.filter((item) => item.port !== published.port), published]
721
+ };
722
+ return published.url ?? null;
723
+ }
724
+ /** List public ports for this computer. */
725
+ async listPublishedPorts() {
726
+ const publishedPorts = await this.client.listPublishedPorts(this.id);
727
+ this.info = { ...this.info, publishedPorts };
728
+ return publishedPorts;
729
+ }
730
+ /** Remove a public port route. */
731
+ async unpublishPort(port = 8e3) {
732
+ const unpublished = await this.client.unpublishPort(this.id, port);
733
+ this.info = {
734
+ ...this.info,
735
+ publishedPorts: (this.info.publishedPorts ?? []).filter((item) => item.port !== port)
736
+ };
737
+ return unpublished;
738
+ }
739
+ };
740
+
741
+ export {
742
+ MISSING_CREDENTIALS_MESSAGE,
743
+ resolveCelestoApiKey,
744
+ resolveClientConfig,
745
+ Computer
746
+ };
747
+ //# sourceMappingURL=chunk-XNTZDOKY.js.map