aicomputer 0.2.0 → 0.2.1

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/dist/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- import { ComputerImageResponse, AccessSessionResponse, createPublicApiClient, ListPublishedPortsResponse, PublishedPortResponse, PublishedPortMutationResponse, ListSharesResponse, ShareResponse, ListSnapshotsResponse, SnapshotResponse, ComputerResponse, ComputerConnectionResponse, CreateSSHCertificateRequest, SSHCertificateResponse, CreateComputerRequest, ListSSHKeysResponse, CreateSSHKeyRequest, SSHKeyEnvelope, PublicApiClientOptions, AccessTokenProvider, MeResponse, UsageEnvelope, ResolveShareResponse, CreateAccessSessionRequest, AccessSessionEnvelope, OperationResponse } from '@microagentcomputer/public-api-client';
2
- export { AccessSessionEnvelope, AccessSessionResponse, AccessTokenProvider, ComputerConnectionResponse, ComputerImageResponse, ComputerMutationResponse, ComputerResponse, CreateAccessSessionRequest, CreateComputerRequest, CreateEmailShareRequest, CreateLinkShareRequest, CreatePublishedPortRequest, CreateSSHCertificateRequest, CreateSSHKeyRequest, ExecCommandRequest, ExecCommandResponse, MeResponse, OperationResponse, PublicApiError, PublishedPortResponse, ResolveShareResponse, RestoreSnapshotRequest, SSHCertificateResponse, ShareResponse, SnapshotResponse, UpdateComputerRequest, UsageEnvelope } from '@microagentcomputer/public-api-client';
1
+ import { ComputerImageResponse, AccessSessionResponse, createPublicApiClient, ComputerFileEntry, ComputerFileStat, ComputerFileGrepMatch, FuseMountResponse, ListPublishedPortsResponse, PublishedPortResponse, PublishedPortMutationResponse, ListSharesResponse, ShareResponse, ListSnapshotsResponse, SnapshotResponse, ComputerResponse, ComputerUsageEnvelope, ComputerConnectionResponse, CreateSSHCertificateRequest, SSHCertificateResponse, ComputerCapacityCheckResponse, CreateComputerRequest, ListSSHKeysResponse, CreateSSHKeyRequest, SSHKeyEnvelope, PublicApiClientOptions, AccessTokenProvider, MeResponse, UsageEnvelope, ResolveShareResponse, CreateAccessSessionRequest, AccessSessionEnvelope, OperationResponse } from '@microagentcomputer/public-api-client';
2
+ export { AccessSessionEnvelope, AccessSessionResponse, AccessTokenProvider, ComputerCapacityCheckRequest, ComputerCapacityCheckResponse, ComputerConnectionResponse, ComputerFileEntry, ComputerFileGrepMatch, ComputerFileStat, ComputerImageResponse, ComputerMutationResponse, ComputerResponse, ComputerUsageEnvelope, CreateAccessSessionRequest, CreateComputerRequest, CreateFuseMountRequest, CreateLinkShareRequest, CreatePublishedPortRequest, CreateSSHCertificateRequest, CreateSSHKeyRequest, ExecCommandRequest, ExecCommandResponse, FuseMountMutationResponse, FuseMountResponse, ListFuseMountsResponse, MeResponse, OperationResponse, PublicApiError, PublishedPortResponse, ResizeComputerRequest, ResolveShareResponse, RestoreSnapshotRequest, SSHCertificateResponse, ShareResponse, SnapshotResponse, TransferComputerRequest, UpdateComputerRequest, UsageEnvelope } from '@microagentcomputer/public-api-client';
3
3
 
4
4
  type LowLevelClient = ReturnType<typeof createPublicApiClient>;
5
5
  type ComputerState = ComputerResponse["state"];
6
6
  type ComputerSource = CreateComputerRequest["source"];
7
7
  type ComputerCapability = "process" | "files" | "git" | (string & {});
8
+ type FileEntry = ComputerFileEntry;
9
+ type FileStat = ComputerFileStat;
10
+ type FileGrepMatch = ComputerFileGrepMatch;
8
11
  type WaitOptions = {
9
12
  pollIntervalMs?: number;
10
13
  timeoutMs?: number;
@@ -24,6 +27,8 @@ type ComputerCreateOptions = {
24
27
  displayName?: string;
25
28
  source?: ComputerSource;
26
29
  sizePreset?: string;
30
+ memoryMiB?: number;
31
+ storageBytes?: number;
27
32
  authorizedKeys?: string[];
28
33
  };
29
34
  type ComputerEnsureOptions = ComputerCreateOptions & {
@@ -34,6 +39,35 @@ type ComputerEnsureOptions = ComputerCreateOptions & {
34
39
  type ComputerUpdateOptions = {
35
40
  displayName?: string;
36
41
  };
42
+ type ComputerResizeOptions = {
43
+ sizePreset: string;
44
+ memoryMiB?: never;
45
+ storageBytes?: never;
46
+ signal?: AbortSignal;
47
+ } | {
48
+ sizePreset?: "custom";
49
+ memoryMiB: number;
50
+ storageBytes: number;
51
+ signal?: AbortSignal;
52
+ };
53
+ type LowLevelComputerResizeOptions = {
54
+ size_preset: string;
55
+ requested_memory_mib?: never;
56
+ requested_storage_bytes?: never;
57
+ signal?: AbortSignal;
58
+ } | {
59
+ size_preset?: "custom";
60
+ requested_memory_mib: number;
61
+ requested_storage_bytes: number;
62
+ signal?: AbortSignal;
63
+ };
64
+ type ComputerCapacityOptions = {
65
+ sizePreset?: string;
66
+ memoryMiB?: number;
67
+ storageBytes?: number;
68
+ excludeComputerId?: string;
69
+ computerId?: string;
70
+ };
37
71
  type CommandRunOptions = {
38
72
  cwd?: string;
39
73
  env?: Record<string, string>;
@@ -93,18 +127,63 @@ type PtyResult = {
93
127
  status: string;
94
128
  error?: string;
95
129
  };
130
+ type FileReadOptions = {
131
+ signal?: AbortSignal;
132
+ };
133
+ type FileWriteOptions = {
134
+ mode?: number;
135
+ signal?: AbortSignal;
136
+ };
137
+ type FileRemoveOptions = {
138
+ recursive?: boolean;
139
+ signal?: AbortSignal;
140
+ };
141
+ type FileListOptions = {
142
+ recursive?: boolean;
143
+ signal?: AbortSignal;
144
+ };
145
+ type FilePatchOptions = {
146
+ signal?: AbortSignal;
147
+ };
148
+ type FileReadRange = {
149
+ offset: number;
150
+ length: number;
151
+ };
152
+ type FileWriteRange = {
153
+ offset: number;
154
+ };
155
+ type FileMkdirOptions = {
156
+ recursive?: boolean;
157
+ signal?: AbortSignal;
158
+ };
159
+ type FilePatchEdit = {
160
+ find: string;
161
+ replace: string;
162
+ };
163
+ type FilePatchRequest = FilePatchEdit[] | {
164
+ setContents: string;
165
+ };
166
+ type FileGrepOptions = {
167
+ path?: string;
168
+ regex?: boolean;
169
+ caseInsensitive?: boolean;
170
+ maxMatches?: number;
171
+ signal?: AbortSignal;
172
+ };
96
173
  type ShareLinkOptions = {
97
174
  expiresAt?: string;
98
175
  allowBrowser?: boolean;
99
176
  allowVnc?: boolean;
100
177
  signal?: AbortSignal;
101
178
  };
102
- type ShareEmailOptions = ShareLinkOptions & {
103
- email: string;
179
+ type TransferComputerOptions = {
180
+ targetOrgId: string;
181
+ signal?: AbortSignal;
104
182
  };
105
183
  type PublishPortOptions = {
106
184
  port: number;
107
185
  name?: string;
186
+ visibility?: "public" | "private";
108
187
  signal?: AbortSignal;
109
188
  };
110
189
  type SnapshotRestoreOptions = {
@@ -159,6 +238,7 @@ declare class ComputersClient {
159
238
  get(computerId: string, signal?: AbortSignal): Promise<Computer>;
160
239
  getByHandle(handle: string, signal?: AbortSignal): Promise<Computer | null>;
161
240
  resolve(idOrHandle: string, signal?: AbortSignal): Promise<Computer>;
241
+ checkCapacity(options?: ComputerCapacityOptions, signal?: AbortSignal): Promise<ComputerCapacityCheckResponse>;
162
242
  create(options?: ComputerCreateOptions, signal?: AbortSignal): Promise<Computer>;
163
243
  ensure(options?: ComputerEnsureOptions, signal?: AbortSignal): Promise<Computer>;
164
244
  private defaultSource;
@@ -170,6 +250,7 @@ declare class Computer {
170
250
  readonly pty: ComputerPtyClient;
171
251
  readonly files: ComputerFilesClient;
172
252
  readonly git: ComputerGitClient;
253
+ readonly mounts: ComputerMountsClient;
173
254
  readonly ports: ComputerPortsClient;
174
255
  readonly shares: ComputerSharesClient;
175
256
  readonly snapshots: ComputerSnapshotsClient;
@@ -191,7 +272,11 @@ declare class Computer {
191
272
  update(options: ComputerUpdateOptions, signal?: AbortSignal): Promise<Computer>;
192
273
  start(signal?: AbortSignal): Promise<Computer>;
193
274
  stop(signal?: AbortSignal): Promise<Computer>;
275
+ resize(options: ComputerResizeOptions | LowLevelComputerResizeOptions, signal?: AbortSignal): Promise<Computer>;
194
276
  delete(signal?: AbortSignal): Promise<void>;
277
+ transfer(options: TransferComputerOptions): Promise<Computer>;
278
+ usage(signal?: AbortSignal): Promise<ComputerUsageEnvelope>;
279
+ ensureReady(options?: WaitOptions): Promise<Computer>;
195
280
  ensureRunning(options?: WaitOptions): Promise<Computer>;
196
281
  ensureStopped(options?: WaitOptions): Promise<Computer>;
197
282
  waitUntilRunning(options?: WaitOptions): Promise<Computer>;
@@ -331,9 +416,23 @@ declare class ComputerPtyClient {
331
416
  declare class ComputerFilesClient {
332
417
  private readonly computer;
333
418
  constructor(computer: Computer);
334
- readText(path: string, signal?: AbortSignal): Promise<string>;
335
- writeText(path: string, content: string, signal?: AbortSignal): Promise<void>;
336
- remove(path: string, signal?: AbortSignal): Promise<void>;
419
+ readText(path: string, opts?: FileReadOptions | AbortSignal): Promise<string>;
420
+ readBytes(path: string, opts?: FileReadOptions): Promise<Uint8Array>;
421
+ writeText(path: string, content: string, opts?: FileWriteOptions | AbortSignal): Promise<void>;
422
+ writeBytes(path: string, content: Uint8Array, opts?: FileWriteOptions): Promise<void>;
423
+ remove(path: string, opts?: FileRemoveOptions | AbortSignal): Promise<void>;
424
+ list(path: string, opts?: FileListOptions): Promise<FileEntry[]>;
425
+ stat(path: string, opts?: FileReadOptions): Promise<FileStat>;
426
+ exists(path: string, opts?: FileReadOptions): Promise<boolean>;
427
+ patch(path: string, edits: FilePatchRequest, opts?: FilePatchOptions): Promise<{
428
+ version: number;
429
+ }>;
430
+ readRange(path: string, range: FileReadRange, opts?: FileReadOptions): Promise<Uint8Array>;
431
+ writeRange(path: string, range: FileWriteRange, content: Uint8Array, opts?: FileWriteOptions): Promise<void>;
432
+ mkdir(path: string, opts?: FileMkdirOptions): Promise<void>;
433
+ move(from: string, to: string, opts?: FileReadOptions): Promise<void>;
434
+ grep(pattern: string, opts?: FileGrepOptions): Promise<FileGrepMatch[]>;
435
+ private operate;
337
436
  }
338
437
  declare class ComputerGitClient {
339
438
  private readonly computer;
@@ -342,6 +441,26 @@ declare class ComputerGitClient {
342
441
  clone(repoUrl: string, signal?: AbortSignal): Promise<void>;
343
442
  pull(signal?: AbortSignal): Promise<void>;
344
443
  }
444
+ type AttachMountOptions = {
445
+ kind: "r2" | "s3" | "gcs" | "webdav";
446
+ targetPath: string;
447
+ bucket: string;
448
+ accessKeyId: string;
449
+ secretAccessKey: string;
450
+ endpoint?: string;
451
+ region?: string;
452
+ readOnly?: boolean;
453
+ vfsCacheMode?: string;
454
+ signal?: AbortSignal;
455
+ };
456
+ declare class ComputerMountsClient {
457
+ private readonly computer;
458
+ constructor(computer: Computer);
459
+ list(signal?: AbortSignal): Promise<FuseMountResponse[]>;
460
+ attach(options: AttachMountOptions): Promise<FuseMountResponse>;
461
+ detach(mountId: string, signal?: AbortSignal): Promise<FuseMountResponse>;
462
+ private find;
463
+ }
345
464
  declare class ComputerPortsClient {
346
465
  private readonly computer;
347
466
  constructor(computer: Computer);
@@ -354,7 +473,6 @@ declare class ComputerSharesClient {
354
473
  constructor(computer: Computer);
355
474
  list(signal?: AbortSignal): Promise<ListSharesResponse["shares"]>;
356
475
  createLink(options?: ShareLinkOptions): Promise<ShareResponse>;
357
- createEmail(options: ShareEmailOptions): Promise<ShareResponse>;
358
476
  delete(shareId: string, signal?: AbortSignal): Promise<void>;
359
477
  }
360
478
  declare class ComputerSnapshotsClient {
@@ -378,4 +496,4 @@ declare class SSHKeysClient {
378
496
  delete(sshKeyId: string, signal?: AbortSignal): Promise<void>;
379
497
  }
380
498
 
381
- export { AgentComputer, type AgentComputerOptions, CommandExitError, CommandHandle, type CommandInfo, type CommandOutputHandler, type CommandResult, type CommandRunOptions, type CommandSelector, type CommandSignal, type CommandStartOptions, Computer, type ComputerCapability, ComputerCommandsClient, type ComputerCreateOptions, type ComputerEnsureOptions, ComputerFilesClient, ComputerGitClient, ComputerImagesClient, ComputerPortsClient, ComputerPtyClient, ComputerSharesClient, ComputerSnapshotsClient, type ComputerSource, type ComputerState, type ComputerUpdateOptions, ComputersClient, type ExecSessionCreateOptions, ExecTransportError, type PtyOutputHandler, type PtyResult, PtySession, type PtyStartOptions, type PublishPortOptions, SSHKeysClient, type ShareEmailOptions, type ShareLinkOptions, type SnapshotRestoreOptions, SnapshotsClient, UnsupportedCapabilityError, type WaitOptions };
499
+ export { AgentComputer, type AgentComputerOptions, type AttachMountOptions, CommandExitError, CommandHandle, type CommandInfo, type CommandOutputHandler, type CommandResult, type CommandRunOptions, type CommandSelector, type CommandSignal, type CommandStartOptions, Computer, type ComputerCapability, type ComputerCapacityOptions, ComputerCommandsClient, type ComputerCreateOptions, type ComputerEnsureOptions, ComputerFilesClient, ComputerGitClient, ComputerImagesClient, ComputerMountsClient, ComputerPortsClient, ComputerPtyClient, type ComputerResizeOptions, ComputerSharesClient, ComputerSnapshotsClient, type ComputerSource, type ComputerState, type ComputerUpdateOptions, ComputersClient, type ExecSessionCreateOptions, ExecTransportError, type FileEntry, type FileGrepMatch, type FileGrepOptions, type FileListOptions, type FileMkdirOptions, type FilePatchEdit, type FilePatchOptions, type FilePatchRequest, type FileReadOptions, type FileReadRange, type FileRemoveOptions, type FileStat, type FileWriteOptions, type FileWriteRange, type LowLevelComputerResizeOptions, type PtyOutputHandler, type PtyResult, PtySession, type PtyStartOptions, type PublishPortOptions, SSHKeysClient, type ShareLinkOptions, type SnapshotRestoreOptions, SnapshotsClient, type TransferComputerOptions, UnsupportedCapabilityError, type WaitOptions };
package/dist/index.js CHANGED
@@ -92,9 +92,23 @@ function createPublicApiClient(options) {
92
92
  async getUsage(signal) {
93
93
  return request("/v1/usage", { signal });
94
94
  },
95
+ async updateBillingPreferences(body, signal) {
96
+ return request("/v1/billing/preferences", {
97
+ method: "PATCH",
98
+ body: JSON.stringify(body),
99
+ signal
100
+ });
101
+ },
95
102
  async listComputerSizePresets(signal) {
96
103
  return requestNoAuth("/v1/computer-size-presets", { signal });
97
104
  },
105
+ async checkComputerCapacity(body, signal) {
106
+ return request("/v1/computer-capacity/check", {
107
+ method: "POST",
108
+ body: JSON.stringify(body),
109
+ signal
110
+ });
111
+ },
98
112
  async listComputerImages(signal) {
99
113
  return request("/v1/computer-images", { signal });
100
114
  },
@@ -139,6 +153,20 @@ function createPublicApiClient(options) {
139
153
  signal
140
154
  });
141
155
  },
156
+ async resizeComputer(computerId, body, signal) {
157
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/actions/resize`, {
158
+ method: "POST",
159
+ body: JSON.stringify(body),
160
+ signal
161
+ });
162
+ },
163
+ async transferComputer(computerId, body, signal) {
164
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/actions/transfer`, {
165
+ method: "POST",
166
+ body: JSON.stringify(body),
167
+ signal
168
+ });
169
+ },
142
170
  async getComputerConnection(computerId, signal) {
143
171
  return request(`/v1/computers/${encodeURIComponent(computerId)}/connection`, { signal });
144
172
  },
@@ -149,6 +177,22 @@ function createPublicApiClient(options) {
149
177
  signal
150
178
  });
151
179
  },
180
+ async operateComputerFiles(computerId, body, signal) {
181
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/files/ops`, {
182
+ method: "POST",
183
+ body: JSON.stringify(body),
184
+ signal
185
+ });
186
+ },
187
+ async getComputerUsage(computerId, signal) {
188
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/usage`, { signal });
189
+ },
190
+ async ensureReadyComputer(computerId, signal) {
191
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/actions/ensure-ready`, {
192
+ method: "POST",
193
+ signal
194
+ });
195
+ },
152
196
  async getOperation(operationId, signal) {
153
197
  return request(`/v1/operations/${encodeURIComponent(operationId)}`, { signal });
154
198
  },
@@ -225,19 +269,6 @@ function createPublicApiClient(options) {
225
269
  signal
226
270
  });
227
271
  },
228
- async createEmailShare(computerId, body, signal) {
229
- return request(`/v1/computers/${encodeURIComponent(computerId)}/shares/emails`, {
230
- method: "POST",
231
- body: JSON.stringify(body),
232
- signal
233
- });
234
- },
235
- async deleteEmailShare(computerId, shareId, signal) {
236
- return request(`/v1/computers/${encodeURIComponent(computerId)}/shares/emails/${encodeURIComponent(shareId)}`, {
237
- method: "DELETE",
238
- signal
239
- });
240
- },
241
272
  async resolveShare(shareToken, signal) {
242
273
  return requestNoAuth(`/v1/shares/${encodeURIComponent(shareToken)}`, { signal });
243
274
  },
@@ -288,6 +319,22 @@ function createPublicApiClient(options) {
288
319
  method: "DELETE",
289
320
  signal
290
321
  });
322
+ },
323
+ async listFuseMounts(computerId, signal) {
324
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/mounts`, { signal });
325
+ },
326
+ async createFuseMount(computerId, body, signal) {
327
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/mounts`, {
328
+ method: "POST",
329
+ body: JSON.stringify(body),
330
+ signal
331
+ });
332
+ },
333
+ async deleteFuseMount(computerId, mountId, signal) {
334
+ return request(`/v1/computers/${encodeURIComponent(computerId)}/mounts/${encodeURIComponent(mountId)}`, {
335
+ method: "DELETE",
336
+ signal
337
+ });
291
338
  }
292
339
  };
293
340
  return client;
@@ -316,7 +363,6 @@ var DEFAULT_COMPUTER_STATE_TIMEOUT_MS = 3e5;
316
363
  var DEFAULT_CONNECT_REQUEST_TIMEOUT_MS = 3e4;
317
364
  var NOT_FOUND_CODES = /* @__PURE__ */ new Set(["computer_not_found", "snapshot_not_found"]);
318
365
  var COMPUTER_FAILURE_STATES = /* @__PURE__ */ new Set(["failed", "deleted", "deleting"]);
319
- var defaultComputerSizePreset = "ram-2g";
320
366
  var AgentComputer = class {
321
367
  images;
322
368
  computers;
@@ -483,13 +529,27 @@ var ComputersClient = class {
483
529
  }
484
530
  throw new PublicApiError(404, `computer ${idOrHandle} not found`, "computer_not_found");
485
531
  }
532
+ async checkCapacity(options = {}, signal) {
533
+ return this.sdk.internalClient().checkComputerCapacity(
534
+ {
535
+ size_preset: options.sizePreset,
536
+ requested_memory_mib: options.memoryMiB,
537
+ requested_storage_bytes: options.storageBytes,
538
+ exclude_computer_id: options.excludeComputerId,
539
+ computer_id: options.computerId
540
+ },
541
+ signal
542
+ );
543
+ }
486
544
  async create(options = {}, signal) {
487
545
  const source = options.source ?? await this.defaultSource(signal);
488
546
  const response = await this.sdk.internalClient().createComputer(
489
547
  {
490
548
  handle: options.handle,
491
549
  display_name: options.displayName,
492
- size_preset: source.kind === "image" ? options.sizePreset ?? defaultComputerSizePreset : options.sizePreset,
550
+ size_preset: options.sizePreset,
551
+ requested_memory_mib: options.memoryMiB,
552
+ requested_storage_bytes: options.storageBytes,
493
553
  source,
494
554
  guest: options.authorizedKeys && options.authorizedKeys.length > 0 ? { authorized_keys: options.authorizedKeys } : void 0
495
555
  },
@@ -538,6 +598,7 @@ var Computer = class {
538
598
  this.pty = new ComputerPtyClient(this);
539
599
  this.files = new ComputerFilesClient(this);
540
600
  this.git = new ComputerGitClient(this);
601
+ this.mounts = new ComputerMountsClient(this);
541
602
  this.ports = new ComputerPortsClient(this);
542
603
  this.shares = new ComputerSharesClient(this);
543
604
  this.snapshots = new ComputerSnapshotsClient(this);
@@ -548,6 +609,7 @@ var Computer = class {
548
609
  pty;
549
610
  files;
550
611
  git;
612
+ mounts;
551
613
  ports;
552
614
  shares;
553
615
  snapshots;
@@ -618,12 +680,48 @@ var Computer = class {
618
680
  this.computer = (await this.sdk.internalClient().getComputer(this.id, signal)).computer;
619
681
  return this;
620
682
  }
683
+ async resize(options, signal) {
684
+ const lowLevelOptions = options;
685
+ const highLevelOptions = options;
686
+ const sizePreset = "size_preset" in options ? lowLevelOptions.size_preset : highLevelOptions.sizePreset;
687
+ const requestedMemoryMiB = "requested_memory_mib" in options ? lowLevelOptions.requested_memory_mib : highLevelOptions.memoryMiB;
688
+ const requestedStorageBytes = "requested_storage_bytes" in options ? lowLevelOptions.requested_storage_bytes : highLevelOptions.storageBytes;
689
+ const requestSignal = "signal" in options && options.signal !== void 0 ? options.signal : signal;
690
+ if ((!sizePreset || sizePreset === "custom") && (requestedMemoryMiB === void 0 || requestedStorageBytes === void 0)) {
691
+ throw new Error("resize requires sizePreset or memoryMiB plus storageBytes");
692
+ }
693
+ const response = await this.sdk.internalClient().resizeComputer(
694
+ this.id,
695
+ {
696
+ size_preset: sizePreset,
697
+ requested_memory_mib: requestedMemoryMiB,
698
+ requested_storage_bytes: requestedStorageBytes
699
+ },
700
+ requestSignal
701
+ );
702
+ await waitForOperationIfPresent(this.sdk, response.operation, requestSignal);
703
+ this.computer = (await this.sdk.internalClient().getComputer(this.id, requestSignal)).computer;
704
+ return this;
705
+ }
621
706
  async delete(signal) {
622
707
  const response = await this.sdk.internalClient().deleteComputer(this.id, signal);
623
708
  await waitForOperationIfPresent(this.sdk, response.operation, signal);
624
709
  this.computer = response.computer;
625
710
  }
626
- async ensureRunning(options = {}) {
711
+ async transfer(options) {
712
+ const response = await this.sdk.internalClient().transferComputer(
713
+ this.id,
714
+ { target_org_id: options.targetOrgId },
715
+ options.signal
716
+ );
717
+ await waitForOperationIfPresent(this.sdk, response.operation, options.signal);
718
+ this.computer = response.computer;
719
+ return this;
720
+ }
721
+ async usage(signal) {
722
+ return this.sdk.internalClient().getComputerUsage(this.id, signal);
723
+ }
724
+ async ensureReady(options = {}) {
627
725
  await this.refresh(options.signal);
628
726
  if (this.state === "running") {
629
727
  return this;
@@ -638,12 +736,18 @@ var Computer = class {
638
736
  this.computer
639
737
  );
640
738
  }
641
- if (this.state === "stopped") {
642
- await this.start(options.signal);
739
+ const response = await this.sdk.internalClient().ensureReadyComputer(this.id, options.signal);
740
+ await waitForOperationIfPresent(this.sdk, response.operation, options.signal);
741
+ if (response.computer.state !== "running") {
742
+ await this.waitUntilRunning(options);
743
+ } else {
744
+ this.computer = response.computer;
643
745
  }
644
- await this.waitUntilRunning(options);
645
746
  return this;
646
747
  }
748
+ async ensureRunning(options = {}) {
749
+ return this.ensureReady(options);
750
+ }
647
751
  async ensureStopped(options = {}) {
648
752
  await this.refresh(options.signal);
649
753
  if (this.state === "stopped") {
@@ -1400,29 +1504,171 @@ var ComputerPtyClient = class {
1400
1504
  var ComputerFilesClient = class {
1401
1505
  constructor(computer) {
1402
1506
  this.computer = computer;
1403
- void computer;
1404
1507
  }
1405
1508
  computer;
1406
- async readText(path, signal) {
1407
- await this.computer.requireCapability("files", signal);
1408
- throw new ExecTransportError("files capability is advertised but the SDK file transport is not implemented yet", {
1409
- code: "files_transport_unimplemented",
1410
- details: { computerId: this.computer.id, path }
1411
- });
1509
+ async readText(path, opts) {
1510
+ const response = await this.operate({
1511
+ operation: "read_text",
1512
+ path
1513
+ }, signalFromFileOptions(opts));
1514
+ return response.content ?? "";
1515
+ }
1516
+ async readBytes(path, opts) {
1517
+ const response = await this.operate(
1518
+ {
1519
+ operation: "read_bytes",
1520
+ path
1521
+ },
1522
+ opts?.signal
1523
+ );
1524
+ return base64ToBytes(response.content_base64 ?? "");
1412
1525
  }
1413
- async writeText(path, content, signal) {
1414
- await this.computer.requireCapability("files", signal);
1415
- throw new ExecTransportError("files capability is advertised but the SDK file transport is not implemented yet", {
1416
- code: "files_transport_unimplemented",
1417
- details: { computerId: this.computer.id, path, size: content.length }
1418
- });
1526
+ async writeText(path, content, opts) {
1527
+ const normalized = normalizeFileWriteOptions(opts);
1528
+ await this.operate(
1529
+ {
1530
+ operation: "write_text",
1531
+ path,
1532
+ content,
1533
+ mode: normalized.mode
1534
+ },
1535
+ normalized.signal
1536
+ );
1419
1537
  }
1420
- async remove(path, signal) {
1421
- await this.computer.requireCapability("files", signal);
1422
- throw new ExecTransportError("files capability is advertised but the SDK file transport is not implemented yet", {
1423
- code: "files_transport_unimplemented",
1424
- details: { computerId: this.computer.id, path }
1425
- });
1538
+ async writeBytes(path, content, opts) {
1539
+ await this.operate(
1540
+ {
1541
+ operation: "write_bytes",
1542
+ path,
1543
+ content_base64: bytesToBase64(content),
1544
+ mode: opts?.mode
1545
+ },
1546
+ opts?.signal
1547
+ );
1548
+ }
1549
+ async remove(path, opts) {
1550
+ const normalized = normalizeFileRemoveOptions(opts);
1551
+ await this.operate(
1552
+ {
1553
+ operation: "remove",
1554
+ path,
1555
+ recursive: normalized.recursive
1556
+ },
1557
+ normalized.signal
1558
+ );
1559
+ }
1560
+ async list(path, opts = {}) {
1561
+ const response = await this.operate(
1562
+ {
1563
+ operation: "list",
1564
+ path,
1565
+ recursive: opts.recursive
1566
+ },
1567
+ opts.signal
1568
+ );
1569
+ return response.entries ?? [];
1570
+ }
1571
+ async stat(path, opts = {}) {
1572
+ const response = await this.operate(
1573
+ {
1574
+ operation: "stat",
1575
+ path
1576
+ },
1577
+ opts.signal
1578
+ );
1579
+ if (!response.stat) {
1580
+ throw new PublicApiError(500, "file stat response missing stat payload", "file_stat_missing", {
1581
+ computer_id: this.computer.id,
1582
+ path
1583
+ });
1584
+ }
1585
+ return response.stat;
1586
+ }
1587
+ async exists(path, opts = {}) {
1588
+ const response = await this.operate(
1589
+ {
1590
+ operation: "exists",
1591
+ path
1592
+ },
1593
+ opts.signal
1594
+ );
1595
+ return response.exists ?? false;
1596
+ }
1597
+ async patch(path, edits, opts = {}) {
1598
+ const response = await this.operate(
1599
+ Array.isArray(edits) ? {
1600
+ operation: "patch",
1601
+ path,
1602
+ edits
1603
+ } : {
1604
+ operation: "patch",
1605
+ path,
1606
+ set_contents: edits.setContents
1607
+ },
1608
+ opts.signal
1609
+ );
1610
+ return { version: response.version ?? 0 };
1611
+ }
1612
+ async readRange(path, range, opts = {}) {
1613
+ const response = await this.operate(
1614
+ {
1615
+ operation: "read_range",
1616
+ path,
1617
+ offset: range.offset,
1618
+ length: range.length
1619
+ },
1620
+ opts.signal
1621
+ );
1622
+ return base64ToBytes(response.content_base64 ?? "");
1623
+ }
1624
+ async writeRange(path, range, content, opts = {}) {
1625
+ await this.operate(
1626
+ {
1627
+ operation: "write_range",
1628
+ path,
1629
+ offset: range.offset,
1630
+ content_base64: bytesToBase64(content),
1631
+ mode: opts.mode
1632
+ },
1633
+ opts.signal
1634
+ );
1635
+ }
1636
+ async mkdir(path, opts = {}) {
1637
+ await this.operate(
1638
+ {
1639
+ operation: "mkdir",
1640
+ path,
1641
+ recursive: opts.recursive
1642
+ },
1643
+ opts.signal
1644
+ );
1645
+ }
1646
+ async move(from, to, opts = {}) {
1647
+ await this.operate(
1648
+ {
1649
+ operation: "move",
1650
+ path: from,
1651
+ to
1652
+ },
1653
+ opts.signal
1654
+ );
1655
+ }
1656
+ async grep(pattern, opts = {}) {
1657
+ const response = await this.operate(
1658
+ {
1659
+ operation: "grep",
1660
+ path: opts.path,
1661
+ pattern,
1662
+ regex: opts.regex,
1663
+ case_insensitive: opts.caseInsensitive,
1664
+ max_matches: opts.maxMatches
1665
+ },
1666
+ opts.signal
1667
+ );
1668
+ return response.matches ?? [];
1669
+ }
1670
+ operate(body, signal) {
1671
+ return this.computer.internalSdk().internalClient().operateComputerFiles(this.computer.id, body, signal);
1426
1672
  }
1427
1673
  };
1428
1674
  var ComputerGitClient = class {
@@ -1453,6 +1699,51 @@ var ComputerGitClient = class {
1453
1699
  });
1454
1700
  }
1455
1701
  };
1702
+ var ComputerMountsClient = class {
1703
+ constructor(computer) {
1704
+ this.computer = computer;
1705
+ }
1706
+ computer;
1707
+ async list(signal) {
1708
+ const response = await this.computer.internalSdk().internalClient().listFuseMounts(
1709
+ this.computer.id,
1710
+ signal
1711
+ );
1712
+ return response.mounts;
1713
+ }
1714
+ async attach(options) {
1715
+ const response = await this.computer.internalSdk().internalClient().createFuseMount(
1716
+ this.computer.id,
1717
+ {
1718
+ kind: options.kind,
1719
+ target_path: options.targetPath,
1720
+ bucket: options.bucket,
1721
+ access_key_id: options.accessKeyId,
1722
+ secret_access_key: options.secretAccessKey,
1723
+ endpoint: options.endpoint,
1724
+ region: options.region,
1725
+ read_only: options.readOnly,
1726
+ vfs_cache_mode: options.vfsCacheMode
1727
+ },
1728
+ options.signal
1729
+ );
1730
+ await waitForOperationIfPresent(this.computer.internalSdk(), response.operation, options.signal);
1731
+ return await this.find(response.mount.id, options.signal) ?? response.mount;
1732
+ }
1733
+ async detach(mountId, signal) {
1734
+ const response = await this.computer.internalSdk().internalClient().deleteFuseMount(
1735
+ this.computer.id,
1736
+ mountId,
1737
+ signal
1738
+ );
1739
+ await waitForOperationIfPresent(this.computer.internalSdk(), response.operation, signal);
1740
+ return await this.find(response.mount.id, signal) ?? response.mount;
1741
+ }
1742
+ async find(mountId, signal) {
1743
+ const mounts = await this.list(signal);
1744
+ return mounts.find((mount) => mount.id === mountId) ?? null;
1745
+ }
1746
+ };
1456
1747
  var ComputerPortsClient = class {
1457
1748
  constructor(computer) {
1458
1749
  this.computer = computer;
@@ -1470,7 +1761,8 @@ var ComputerPortsClient = class {
1470
1761
  this.computer.id,
1471
1762
  {
1472
1763
  port: options.port,
1473
- name: options.name
1764
+ name: options.name,
1765
+ visibility: options.visibility
1474
1766
  },
1475
1767
  options.signal
1476
1768
  );
@@ -1511,29 +1803,7 @@ var ComputerSharesClient = class {
1511
1803
  );
1512
1804
  return response.share;
1513
1805
  }
1514
- async createEmail(options) {
1515
- const response = await this.computer.internalSdk().internalClient().createEmailShare(
1516
- this.computer.id,
1517
- {
1518
- email: options.email,
1519
- expires_at: options.expiresAt,
1520
- allow_browser: options.allowBrowser,
1521
- allow_vnc: options.allowVnc
1522
- },
1523
- options.signal
1524
- );
1525
- return response.share;
1526
- }
1527
1806
  async delete(shareId, signal) {
1528
- const shares = await this.list(signal);
1529
- const existing = shares.find((share) => share.id === shareId);
1530
- if (!existing) {
1531
- throw new PublicApiError(404, `share ${shareId} not found`, "share_not_found");
1532
- }
1533
- if (existing.kind === "email") {
1534
- await this.computer.internalSdk().internalClient().deleteEmailShare(this.computer.id, shareId, signal);
1535
- return;
1536
- }
1537
1807
  await this.computer.internalSdk().internalClient().deleteLinkShare(this.computer.id, shareId, signal);
1538
1808
  }
1539
1809
  };
@@ -1691,6 +1961,36 @@ function shellQuote(value) {
1691
1961
  function encodeData(data) {
1692
1962
  return typeof data === "string" ? new TextEncoder().encode(data) : data;
1693
1963
  }
1964
+ function isAbortSignal(value) {
1965
+ return typeof AbortSignal !== "undefined" && value instanceof AbortSignal;
1966
+ }
1967
+ function signalFromFileOptions(options) {
1968
+ if (!options) {
1969
+ return void 0;
1970
+ }
1971
+ if (isAbortSignal(options)) {
1972
+ return options;
1973
+ }
1974
+ return options.signal;
1975
+ }
1976
+ function normalizeFileWriteOptions(options) {
1977
+ if (!options) {
1978
+ return {};
1979
+ }
1980
+ if (isAbortSignal(options)) {
1981
+ return { signal: options };
1982
+ }
1983
+ return options;
1984
+ }
1985
+ function normalizeFileRemoveOptions(options) {
1986
+ if (!options) {
1987
+ return {};
1988
+ }
1989
+ if (isAbortSignal(options)) {
1990
+ return { signal: options };
1991
+ }
1992
+ return options;
1993
+ }
1694
1994
  function bytesToBase64(bytes) {
1695
1995
  let binary = "";
1696
1996
  for (const byte of bytes) {
@@ -1847,6 +2147,7 @@ export {
1847
2147
  ComputerFilesClient,
1848
2148
  ComputerGitClient,
1849
2149
  ComputerImagesClient,
2150
+ ComputerMountsClient,
1850
2151
  ComputerPortsClient,
1851
2152
  ComputerPtyClient,
1852
2153
  ComputerSharesClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicomputer",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "High-level TypeScript SDK for AgentComputer computers and execution workflows.",
6
6
  "license": "MIT",