instavm 0.8.3 → 0.13.0

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
@@ -15,7 +15,7 @@ interface HttpClientConfig {
15
15
  apiKey: string;
16
16
  }
17
17
  interface RequestConfig {
18
- method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
18
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
19
19
  url: string;
20
20
  headers?: Record<string, string>;
21
21
  data?: any;
@@ -65,6 +65,18 @@ declare class HTTPClient {
65
65
  * DELETE request
66
66
  */
67
67
  delete<T = any>(url: string, headers?: Record<string, string>): Promise<T>;
68
+ /**
69
+ * PUT request
70
+ */
71
+ put<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<T>;
72
+ /**
73
+ * PATCH request
74
+ */
75
+ patch<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<T>;
76
+ /**
77
+ * OPTIONS request
78
+ */
79
+ options<T = any>(url: string, headers?: Record<string, string>, params?: Record<string, any>): Promise<T>;
68
80
  /**
69
81
  * POST request that returns raw binary data (for file downloads)
70
82
  */
@@ -310,6 +322,320 @@ declare class BrowserManager {
310
322
  dispose(): Promise<void>;
311
323
  }
312
324
 
325
+ type JsonMap = Record<string, any>;
326
+ interface VMCreateRequest extends JsonMap {
327
+ session_id?: string | null;
328
+ vm_lifetime_seconds?: number | null;
329
+ memory_mb?: number | null;
330
+ vcpu_count?: number | null;
331
+ metadata?: JsonMap | null;
332
+ egress_policy?: JsonMap | null;
333
+ snapshot_id?: string | null;
334
+ snapshot_on_terminate?: boolean | null;
335
+ snapshot_name?: string | null;
336
+ share?: JsonMap | null;
337
+ custom_domain?: JsonMap | null;
338
+ image_variant?: string | null;
339
+ volumes?: VMVolumeMountRequest[] | null;
340
+ }
341
+ interface VMUpdateRequest extends JsonMap {
342
+ memory_mb?: number | null;
343
+ egress_policy?: JsonMap | null;
344
+ snapshot_on_terminate?: boolean | null;
345
+ snapshot_name?: string | null;
346
+ }
347
+ interface VMCloneRequest extends JsonMap {
348
+ snapshot_name?: string | null;
349
+ }
350
+ interface VMSnapshotRequest extends JsonMap {
351
+ name?: string | null;
352
+ }
353
+ interface SnapshotBuildArgs extends JsonMap {
354
+ extra_apt_packages?: string | null;
355
+ extra_pip_packages?: string | null;
356
+ extra_npm_packages?: string | null;
357
+ git_clone_url?: string | null;
358
+ git_clone_branch?: string | null;
359
+ disk_size_gb?: number | null;
360
+ envs?: Record<string, string> | null;
361
+ post_build_cmd?: string | null;
362
+ }
363
+ interface SnapshotCreateRequest extends JsonMap {
364
+ oci_image: string;
365
+ name?: string | null;
366
+ vcpu_count?: number;
367
+ memory_mb?: number;
368
+ build_args?: SnapshotBuildArgs | null;
369
+ type?: 'user' | 'system';
370
+ }
371
+ interface SnapshotQueryOptions {
372
+ type?: 'user' | 'system';
373
+ }
374
+ interface VolumeCreateRequest extends JsonMap {
375
+ name: string;
376
+ quota_bytes: number;
377
+ }
378
+ interface VolumeUpdateRequest extends JsonMap {
379
+ name?: string | null;
380
+ quota_bytes?: number | null;
381
+ }
382
+ interface VolumeResponse extends JsonMap {
383
+ id: string;
384
+ name: string;
385
+ quota_bytes: number;
386
+ used_bytes: number;
387
+ status: string;
388
+ created_at?: string | null;
389
+ updated_at?: string | null;
390
+ }
391
+ interface VolumeCheckpointCreateRequest extends JsonMap {
392
+ name?: string | null;
393
+ }
394
+ interface VolumeCheckpointResponse extends JsonMap {
395
+ id: string;
396
+ volume_id: string;
397
+ name?: string | null;
398
+ status: string;
399
+ created_at?: string | null;
400
+ }
401
+ interface VolumeFileEntry extends JsonMap {
402
+ path: string;
403
+ filename: string;
404
+ size: number;
405
+ }
406
+ interface VolumeFileDownloadResponse extends JsonMap {
407
+ path: string;
408
+ filename: string;
409
+ size: number;
410
+ content: Buffer;
411
+ }
412
+ interface VolumeFileUploadRequest extends JsonMap {
413
+ path: string;
414
+ overwrite?: boolean;
415
+ filePath?: string;
416
+ fileContent?: Buffer | string;
417
+ filename?: string;
418
+ }
419
+ interface VolumeFileListQuery {
420
+ prefix?: string;
421
+ recursive?: boolean;
422
+ limit?: number;
423
+ }
424
+ interface VMVolumeMountRequest extends JsonMap {
425
+ volume_id: string;
426
+ mount_path: string;
427
+ mode?: string;
428
+ checkpoint_id?: string | null;
429
+ }
430
+ interface VMMountedVolumeResponse extends JsonMap {
431
+ volume_id: string;
432
+ mount_path: string;
433
+ mode: string;
434
+ checkpoint_id?: string | null;
435
+ status: string;
436
+ }
437
+ interface ShareCreateRequest extends JsonMap {
438
+ session_id?: string | null;
439
+ vm_id?: string | null;
440
+ port: number;
441
+ is_public?: boolean;
442
+ }
443
+ interface ShareUpdateRequest extends JsonMap {
444
+ is_public?: boolean | null;
445
+ revoke?: boolean | null;
446
+ }
447
+ interface CustomDomainCreateRequest extends JsonMap {
448
+ domain: string;
449
+ share_id: string;
450
+ dns_provider: string;
451
+ dns_credentials?: Record<string, string> | null;
452
+ }
453
+ interface ComputerUseProxyOptions {
454
+ params?: Record<string, any>;
455
+ body?: any;
456
+ }
457
+ interface APIKeyCreateRequest extends JsonMap {
458
+ description?: string | null;
459
+ expires_at?: string | null;
460
+ }
461
+ interface APIKey extends JsonMap {
462
+ id?: number;
463
+ description?: string | null;
464
+ /** @deprecated Use key_prefix instead */
465
+ prefix?: string;
466
+ key_prefix?: string;
467
+ full_key?: string;
468
+ created_at?: string;
469
+ expires_at?: string | null;
470
+ }
471
+ interface AuditEventQuery {
472
+ event_group?: string;
473
+ event_type?: string;
474
+ status?: string;
475
+ user_id?: number;
476
+ vm_id?: string;
477
+ session_id?: string;
478
+ cursor?: string;
479
+ limit?: number;
480
+ }
481
+ interface WebhookEndpointCreateRequest extends JsonMap {
482
+ url: string;
483
+ description?: string | null;
484
+ event_patterns?: string[] | null;
485
+ timeout_seconds?: number;
486
+ max_retries?: number;
487
+ }
488
+ interface WebhookEndpointUpdateRequest extends JsonMap {
489
+ url?: string | null;
490
+ description?: string | null;
491
+ enabled?: boolean | null;
492
+ event_patterns?: string[] | null;
493
+ timeout_seconds?: number | null;
494
+ max_retries?: number | null;
495
+ }
496
+ interface WebhookDeliveryQuery {
497
+ endpoint_id?: string;
498
+ status?: string;
499
+ event_type?: string;
500
+ cursor?: string;
501
+ limit?: number;
502
+ }
503
+
504
+ declare class VMsManager {
505
+ private httpClient;
506
+ private local;
507
+ constructor(httpClient: HTTPClient, local?: boolean);
508
+ private ensureCloud;
509
+ create(payload?: VMCreateRequest, wait?: boolean): Promise<JsonMap>;
510
+ list(): Promise<JsonMap[]>;
511
+ listAll(): Promise<JsonMap[]>;
512
+ /**
513
+ * Calls GET /v1/vms/ (trailing slash), a distinct route from GET /v1/vms.
514
+ */
515
+ listAllRecords(): Promise<JsonMap[]>;
516
+ get(itemId: string | number): Promise<JsonMap>;
517
+ update(vmId: string, payload?: VMUpdateRequest): Promise<JsonMap>;
518
+ delete(vmId: string): Promise<JsonMap>;
519
+ clone(vmId: string, payload?: VMCloneRequest, wait?: boolean): Promise<JsonMap>;
520
+ snapshot(vmId: string, payload?: VMSnapshotRequest, wait?: boolean): Promise<JsonMap>;
521
+ mountVolume(vmId: string, payload: VMVolumeMountRequest, wait?: boolean): Promise<VMMountedVolumeResponse>;
522
+ listVolumes(vmId: string): Promise<VMMountedVolumeResponse[]>;
523
+ unmountVolume(vmId: string, volumeId: string, mountPath: string, wait?: boolean): Promise<JsonMap>;
524
+ }
525
+
526
+ declare class SnapshotsManager {
527
+ private httpClient;
528
+ private local;
529
+ constructor(httpClient: HTTPClient, local?: boolean);
530
+ private ensureCloud;
531
+ create(payload: SnapshotCreateRequest): Promise<JsonMap>;
532
+ list(options?: SnapshotQueryOptions): Promise<JsonMap[]>;
533
+ get(snapshotId: string): Promise<JsonMap>;
534
+ delete(snapshotId: string): Promise<JsonMap>;
535
+ }
536
+
537
+ declare class SharesManager {
538
+ private httpClient;
539
+ private local;
540
+ private getSessionId;
541
+ constructor(httpClient: HTTPClient, local?: boolean, getSessionId?: () => string | null);
542
+ private ensureCloud;
543
+ create(payload: ShareCreateRequest): Promise<JsonMap>;
544
+ update(shareId: string, payload: ShareUpdateRequest): Promise<JsonMap>;
545
+ }
546
+
547
+ declare class CustomDomainsManager {
548
+ private httpClient;
549
+ private local;
550
+ constructor(httpClient: HTTPClient, local?: boolean);
551
+ private ensureCloud;
552
+ create(payload: CustomDomainCreateRequest): Promise<JsonMap>;
553
+ list(): Promise<JsonMap[]>;
554
+ health(domainId: number): Promise<JsonMap>;
555
+ verify(domainId: number): Promise<JsonMap>;
556
+ delete(domainId: number): Promise<JsonMap>;
557
+ }
558
+
559
+ type ProxyMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
560
+ declare class ComputerUseManager {
561
+ private httpClient;
562
+ private local;
563
+ constructor(httpClient: HTTPClient, local?: boolean);
564
+ private ensureCloud;
565
+ viewerUrl(sessionId: string): Promise<JsonMap>;
566
+ proxy(sessionId: string, path: string, method?: ProxyMethod, options?: ComputerUseProxyOptions): Promise<any>;
567
+ get(sessionId: string, path: string, params?: Record<string, any>): Promise<any>;
568
+ post(sessionId: string, path: string, body?: any): Promise<any>;
569
+ put(sessionId: string, path: string, body?: any): Promise<any>;
570
+ patch(sessionId: string, path: string, body?: any): Promise<any>;
571
+ delete(sessionId: string, path: string, params?: Record<string, any>): Promise<any>;
572
+ options(sessionId: string, path: string, params?: Record<string, any>): Promise<any>;
573
+ head(sessionId: string, path: string, params?: Record<string, any>): Promise<any>;
574
+ /**
575
+ * Get the VNC WebSocket URL for a computer-use session.
576
+ * Returns the URL to connect to; the actual connection requires a WebSocket client.
577
+ */
578
+ vncWebsockify(sessionId: string): Promise<JsonMap>;
579
+ }
580
+
581
+ declare class APIKeysManager {
582
+ private httpClient;
583
+ private local;
584
+ constructor(httpClient: HTTPClient, local?: boolean);
585
+ private ensureCloud;
586
+ create(payload?: APIKeyCreateRequest): Promise<APIKey>;
587
+ list(): Promise<APIKey[]>;
588
+ get(itemId: number): Promise<APIKey>;
589
+ update(itemId: number, payload: APIKeyCreateRequest): Promise<APIKey>;
590
+ delete(itemId: number): Promise<JsonMap>;
591
+ }
592
+
593
+ declare class AuditManager {
594
+ private httpClient;
595
+ private local;
596
+ constructor(httpClient: HTTPClient, local?: boolean);
597
+ private ensureCloud;
598
+ catalog(): Promise<JsonMap>;
599
+ events(query?: AuditEventQuery): Promise<JsonMap>;
600
+ getEvent(eventId: string): Promise<JsonMap>;
601
+ }
602
+
603
+ declare class WebhooksManager {
604
+ private httpClient;
605
+ private local;
606
+ constructor(httpClient: HTTPClient, local?: boolean);
607
+ private ensureCloud;
608
+ createEndpoint(payload: WebhookEndpointCreateRequest): Promise<JsonMap>;
609
+ listEndpoints(): Promise<JsonMap[]>;
610
+ getEndpoint(endpointId: string): Promise<JsonMap>;
611
+ updateEndpoint(endpointId: string, payload: WebhookEndpointUpdateRequest): Promise<JsonMap>;
612
+ deleteEndpoint(endpointId: string): Promise<JsonMap>;
613
+ rotateSecret(endpointId: string): Promise<JsonMap>;
614
+ sendTestEvent(endpointId: string): Promise<JsonMap>;
615
+ verifyEndpoint(endpointId: string): Promise<JsonMap>;
616
+ listDeliveries(query?: WebhookDeliveryQuery): Promise<JsonMap>;
617
+ replayDelivery(deliveryId: string): Promise<JsonMap>;
618
+ }
619
+
620
+ declare class VolumesManager {
621
+ private httpClient;
622
+ private local;
623
+ constructor(httpClient: HTTPClient, local?: boolean);
624
+ private ensureCloud;
625
+ create(payload: VolumeCreateRequest): Promise<VolumeResponse>;
626
+ list(refreshUsage?: boolean): Promise<VolumeResponse[]>;
627
+ get(volumeId: string, refreshUsage?: boolean): Promise<VolumeResponse>;
628
+ update(volumeId: string, payload: VolumeUpdateRequest): Promise<VolumeResponse>;
629
+ delete(volumeId: string): Promise<JsonMap>;
630
+ createCheckpoint(volumeId: string, payload?: VolumeCheckpointCreateRequest): Promise<VolumeCheckpointResponse>;
631
+ listCheckpoints(volumeId: string): Promise<VolumeCheckpointResponse[]>;
632
+ deleteCheckpoint(volumeId: string, checkpointId: string): Promise<JsonMap>;
633
+ uploadFile(volumeId: string, payload: VolumeFileUploadRequest): Promise<VolumeFileEntry>;
634
+ downloadFile(volumeId: string, path: string): Promise<VolumeFileDownloadResponse>;
635
+ listFiles(volumeId: string, options?: VolumeFileListQuery): Promise<VolumeFileEntry[]>;
636
+ deleteFile(volumeId: string, targetPath: string): Promise<JsonMap>;
637
+ }
638
+
313
639
  interface ExecuteOptions {
314
640
  language?: 'python' | 'bash';
315
641
  timeout?: number;
@@ -372,6 +698,29 @@ interface DownloadResult {
372
698
  size: number;
373
699
  }
374
700
 
701
+ interface EgressPolicy {
702
+ allowPackageManagers: boolean;
703
+ allowHttp: boolean;
704
+ allowHttps: boolean;
705
+ allowedDomains: string[];
706
+ allowedCidrs: string[];
707
+ }
708
+ interface EgressPolicyOptions {
709
+ allowPackageManagers?: boolean;
710
+ allowHttp?: boolean;
711
+ allowHttps?: boolean;
712
+ allowedDomains?: string[];
713
+ allowedCidrs?: string[];
714
+ }
715
+
716
+ interface SSHKey {
717
+ id: number;
718
+ fingerprint: string;
719
+ keyType: string;
720
+ comment: string | null;
721
+ createdAt: string;
722
+ }
723
+
375
724
  interface InstaVMOptions {
376
725
  baseURL?: string;
377
726
  /**
@@ -383,6 +732,14 @@ interface InstaVMOptions {
383
732
  retryDelay?: number;
384
733
  local?: boolean;
385
734
  localURL?: string;
735
+ /** VM memory in megabytes (optional). Range: 128-8192 MB */
736
+ memory_mb?: number;
737
+ /** VM vCPU count (optional). Valid values: 1, 2, 4, 6, 8 */
738
+ cpu_count?: number;
739
+ /** Optional user-defined metadata for filtering */
740
+ metadata?: Record<string, any>;
741
+ /** Optional environment variables to set in the VM */
742
+ env?: Record<string, any>;
386
743
  }
387
744
  /**
388
745
  * Main InstaVM client class
@@ -391,8 +748,22 @@ declare class InstaVM {
391
748
  private httpClient;
392
749
  private _sessionId;
393
750
  readonly browser: BrowserManager;
751
+ readonly vms: VMsManager;
752
+ readonly snapshots: SnapshotsManager;
753
+ readonly shares: SharesManager;
754
+ readonly customDomains: CustomDomainsManager;
755
+ readonly computerUse: ComputerUseManager;
756
+ readonly apiKeys: APIKeysManager;
757
+ readonly audit: AuditManager;
758
+ readonly webhooks: WebhooksManager;
759
+ readonly volumes: VolumesManager;
394
760
  readonly local: boolean;
395
761
  private readonly timeout;
762
+ readonly memory_mb?: number;
763
+ readonly cpu_count?: number;
764
+ readonly metadata?: Record<string, any>;
765
+ readonly env?: Record<string, any>;
766
+ private _vmUsed;
396
767
  constructor(apiKey: string, options?: InstaVMOptions);
397
768
  /**
398
769
  * Ensure operation is not called in local mode
@@ -440,6 +811,23 @@ declare class InstaVM {
440
811
  * @returns true if session is active, false otherwise
441
812
  */
442
813
  isSessionActive(sessionId?: string): Promise<boolean>;
814
+ /**
815
+ * Get the app URL for a session
816
+ *
817
+ * @param sessionId - Session ID (uses current session if not provided)
818
+ * @param port - Port to expose (1-65535, default: 80)
819
+ */
820
+ getSessionAppUrl(sessionId?: string, port?: number): Promise<Record<string, any>>;
821
+ /**
822
+ * List sandbox records with optional filtering
823
+ *
824
+ * @param options.metadata - JSON-serializable metadata filters
825
+ * @param options.limit - Maximum number of results (1-1000, default: 100)
826
+ */
827
+ listSandboxes(options?: {
828
+ metadata?: Record<string, any>;
829
+ limit?: number;
830
+ }): Promise<Record<string, any>[]>;
443
831
  /**
444
832
  * Get usage statistics for a session
445
833
  */
@@ -452,6 +840,52 @@ declare class InstaVM {
452
840
  * Get the current session ID
453
841
  */
454
842
  get sessionId(): string | null;
843
+ /**
844
+ * Kill the VM associated with a session
845
+ *
846
+ * @param sessionId - The session UUID whose VM should be killed. If not provided, uses current sessionId
847
+ * @returns Result containing success message and killed VM ID
848
+ */
849
+ kill(sessionId?: string): Promise<{
850
+ success: boolean;
851
+ killed: string;
852
+ }>;
853
+ /**
854
+ * Set egress policy for a session
855
+ */
856
+ setSessionEgress(options?: EgressPolicyOptions, sessionId?: string): Promise<{
857
+ status: string;
858
+ sessionId: string;
859
+ }>;
860
+ /**
861
+ * Get egress policy for a session
862
+ */
863
+ getSessionEgress(sessionId?: string): Promise<EgressPolicy>;
864
+ /**
865
+ * Set egress policy for a specific VM
866
+ */
867
+ setVmEgress(vmId: string, options?: EgressPolicyOptions): Promise<{
868
+ status: string;
869
+ vmId: string;
870
+ }>;
871
+ /**
872
+ * Get egress policy for a specific VM
873
+ */
874
+ getVmEgress(vmId: string): Promise<EgressPolicy>;
875
+ /**
876
+ * Add an SSH public key
877
+ */
878
+ addSshKey(publicKey: string): Promise<SSHKey>;
879
+ /**
880
+ * List all active SSH keys
881
+ */
882
+ listSshKeys(): Promise<SSHKey[]>;
883
+ /**
884
+ * Delete an SSH key by ID
885
+ */
886
+ deleteSshKey(keyId: number): Promise<{
887
+ status: string;
888
+ }>;
455
889
  /**
456
890
  * Clean up resources
457
891
  */
@@ -556,4 +990,4 @@ declare class UnsupportedOperationError extends InstaVMError {
556
990
  constructor(message?: string, options?: any);
557
991
  }
558
992
 
559
- export { type ApiResponse, type AsyncExecutionResult, AuthenticationError, BrowserError, BrowserInteractionError, BrowserManager, BrowserNavigationError, BrowserSession, BrowserSessionError, type BrowserSessionInfo, type BrowserSessionOptions, BrowserTimeoutError, type ClickOptions, type ContentAnchor, type DownloadOptions, type DownloadResult, ElementNotFoundError, type ExecuteOptions, ExecutionError, type ExecutionResult, type ExtractContentOptions, type ExtractOptions, type ExtractedContent, type ExtractedElement, type FileUpload, type FillOptions, type HttpClientConfig, InstaVM, InstaVMError, type InstaVMOptions, type InteractiveElement, type NavigateOptions, type NavigationResult, NetworkError, QuotaExceededError, RateLimitError, type RequestConfig, type RetryConfig, type ScreenshotOptions, type ScrollOptions, SessionError, type TypeOptions, UnsupportedOperationError, type UploadOptions, type UploadResult, type UsageStats, type WaitCondition };
993
+ export { type APIKey, type APIKeyCreateRequest, APIKeysManager, type ApiResponse, type AsyncExecutionResult, type AuditEventQuery, AuditManager, AuthenticationError, BrowserError, BrowserInteractionError, BrowserManager, BrowserNavigationError, BrowserSession, BrowserSessionError, type BrowserSessionInfo, type BrowserSessionOptions, BrowserTimeoutError, type ClickOptions, ComputerUseManager, type ComputerUseProxyOptions, type ContentAnchor, type CustomDomainCreateRequest, CustomDomainsManager, type DownloadOptions, type DownloadResult, type EgressPolicy, type EgressPolicyOptions, ElementNotFoundError, type ExecuteOptions, ExecutionError, type ExecutionResult, type ExtractContentOptions, type ExtractOptions, type ExtractedContent, type ExtractedElement, type FileUpload, type FillOptions, type HttpClientConfig, InstaVM, InstaVMError, type InstaVMOptions, type InteractiveElement, type JsonMap, type NavigateOptions, type NavigationResult, NetworkError, QuotaExceededError, RateLimitError, type RequestConfig, type RetryConfig, type SSHKey, type ScreenshotOptions, type ScrollOptions, SessionError, type ShareCreateRequest, type ShareUpdateRequest, SharesManager, type SnapshotBuildArgs, type SnapshotCreateRequest, type SnapshotQueryOptions, SnapshotsManager, type TypeOptions, UnsupportedOperationError, type UploadOptions, type UploadResult, type UsageStats, type VMCloneRequest, type VMCreateRequest, type VMMountedVolumeResponse, type VMSnapshotRequest, type VMUpdateRequest, type VMVolumeMountRequest, VMsManager, type VolumeCheckpointCreateRequest, type VolumeCheckpointResponse, type VolumeCreateRequest, type VolumeFileDownloadResponse, type VolumeFileEntry, type VolumeFileListQuery, type VolumeFileUploadRequest, type VolumeResponse, type VolumeUpdateRequest, VolumesManager, type WaitCondition, type WebhookDeliveryQuery, type WebhookEndpointCreateRequest, type WebhookEndpointUpdateRequest, WebhooksManager };