modal 0.3.17 → 0.3.18

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.cts CHANGED
@@ -89,6 +89,12 @@ declare class Image {
89
89
  /** @ignore */
90
90
  constructor(imageId: string, tag: string, imageRegistryConfig?: ImageRegistryConfig);
91
91
  get imageId(): string;
92
+ /**
93
+ * Creates an `Image` instance from an image id
94
+ *
95
+ * @param imageId - Image id.
96
+ */
97
+ static fromId(imageId: string): Image;
92
98
  /**
93
99
  * Creates an `Image` instance from a raw registry tag, optionally using a secret for authentication.
94
100
  *
@@ -111,10 +117,11 @@ declare class Image {
111
117
  */
112
118
  static fromGcpArtifactRegistry(tag: string, secret: Secret): Image;
113
119
  /**
114
- * @internal
115
- * Build image object
120
+ * Eagerly builds an `Image` on Modal.
121
+ *
122
+ * @param app - App to use to build image.
116
123
  */
117
- _build(appId: string): Promise<Image>;
124
+ build(app: App): Promise<Image>;
118
125
  }
119
126
 
120
127
  /** File open modes supported by the filesystem API. */
@@ -252,6 +259,17 @@ declare class Sandbox {
252
259
  * @returns Sandbox with ID
253
260
  */
254
261
  static fromId(sandboxId: string): Promise<Sandbox>;
262
+ /** Get a running Sandbox by name from a deployed App.
263
+ *
264
+ * Raises a NotFoundError if no running Sandbox is found with the given name.
265
+ * A Sandbox's name is the `name` argument passed to `App.createSandbox`.
266
+ *
267
+ * @param appName - Name of the deployed app
268
+ * @param name - Name of the sandbox
269
+ * @param environment - Optional override for the environment
270
+ * @returns Promise that resolves to a Sandbox
271
+ */
272
+ static fromName(appName: string, name: string, environment?: string): Promise<Sandbox>;
255
273
  /**
256
274
  * Open a file in the sandbox filesystem.
257
275
  * @param path - Path to the file to open
@@ -306,6 +324,15 @@ declare class ContainerProcess<R extends string | Uint8Array = any> {
306
324
  wait(): Promise<number>;
307
325
  }
308
326
 
327
+ type HeartbeatFunction = () => Promise<any>;
328
+ declare class EphemeralHeartbeatManager {
329
+ private readonly heartbeatFn;
330
+ private readonly abortController;
331
+ constructor(heartbeatFn: HeartbeatFunction);
332
+ private start;
333
+ stop(): void;
334
+ }
335
+
309
336
  /** Options for `Volume.fromName()`. */
310
337
  type VolumeFromNameOptions = {
311
338
  environment?: string;
@@ -313,15 +340,23 @@ type VolumeFromNameOptions = {
313
340
  };
314
341
  /** Volumes provide persistent storage that can be mounted in Modal functions. */
315
342
  declare class Volume {
343
+ #private;
316
344
  readonly volumeId: string;
317
345
  readonly name?: string;
318
346
  private _readOnly;
319
347
  /** @ignore */
320
- constructor(volumeId: string, name?: string, readOnly?: boolean);
348
+ constructor(volumeId: string, name?: string, readOnly?: boolean, ephemeralHbManager?: EphemeralHeartbeatManager);
321
349
  static fromName(name: string, options?: VolumeFromNameOptions): Promise<Volume>;
322
350
  /** Configure Volume to mount as read-only. */
323
351
  readOnly(): Volume;
324
352
  get isReadOnly(): boolean;
353
+ /**
354
+ * Create a nameless, temporary volume.
355
+ * You will need to call `closeEphemeral()` to delete the volume.
356
+ */
357
+ static ephemeral(options?: EphemeralOptions): Promise<Volume>;
358
+ /** Delete the ephemeral volume. Only usable with `Volume.ephemeral()`. */
359
+ closeEphemeral(): void;
325
360
  }
326
361
 
327
362
  /** Options for `Proxy.fromName()`. */
@@ -410,6 +445,8 @@ type SandboxCreateOptions = {
410
445
  verbose?: boolean;
411
446
  /** Reference to a Modal Proxy to use in front of this Sandbox. */
412
447
  proxy?: Proxy;
448
+ /** Optional name for the sandbox. Unique within an app. */
449
+ name?: string;
413
450
  };
414
451
  /** Represents a deployed Modal App. */
415
452
  declare class App {
@@ -504,14 +541,60 @@ declare class Function_ {
504
541
  getWebUrl(): Promise<string | undefined>;
505
542
  }
506
543
 
544
+ /** Retry policy configuration for a Modal Function/Cls. */
545
+ declare class Retries {
546
+ readonly maxRetries: number;
547
+ readonly backoffCoefficient: number;
548
+ readonly initialDelayMs: number;
549
+ readonly maxDelayMs: number;
550
+ constructor(options: {
551
+ maxRetries: number;
552
+ backoffCoefficient?: number;
553
+ initialDelayMs?: number;
554
+ maxDelayMs?: number;
555
+ });
556
+ }
557
+
558
+ type ClsOptions = {
559
+ cpu?: number;
560
+ memory?: number;
561
+ gpu?: string;
562
+ secrets?: Secret[];
563
+ volumes?: Record<string, Volume>;
564
+ retries?: number | Retries;
565
+ maxContainers?: number;
566
+ bufferContainers?: number;
567
+ scaledownWindow?: number;
568
+ timeout?: number;
569
+ };
570
+ type ClsConcurrencyOptions = {
571
+ maxInputs: number;
572
+ targetInputs?: number;
573
+ };
574
+ type ClsBatchingOptions = {
575
+ maxBatchSize: number;
576
+ waitMs: number;
577
+ };
578
+ type ServiceOptions = ClsOptions & {
579
+ maxConcurrentInputs?: number;
580
+ targetConcurrentInputs?: number;
581
+ batchMaxSize?: number;
582
+ batchWaitMs?: number;
583
+ };
507
584
  /** Represents a deployed Modal Cls. */
508
585
  declare class Cls {
509
586
  #private;
510
587
  /** @ignore */
511
- constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string);
588
+ constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string, options?: ServiceOptions);
512
589
  static lookup(appName: string, name: string, options?: LookupOptions): Promise<Cls>;
513
- /** Create a new instance of the Cls with parameters. */
590
+ /** Create a new instance of the Cls with parameters and/or runtime options. */
514
591
  instance(params?: Record<string, any>): Promise<ClsInstance>;
592
+ /** Override the static Function configuration at runtime. */
593
+ withOptions(options: ClsOptions): Cls;
594
+ /** Create an instance of the Cls with input concurrency enabled or overridden with new values. */
595
+ withConcurrency(options: ClsConcurrencyOptions): Cls;
596
+ /** Create an instance of the Cls with dynamic batching enabled or overridden with new values. */
597
+ withBatching(options: ClsBatchingOptions): Cls;
515
598
  }
516
599
  /** Represents an instance of a deployed Modal Cls, optionally with parameters. */
517
600
  declare class ClsInstance {
@@ -536,6 +619,10 @@ declare class InternalFailure extends Error {
536
619
  declare class NotFoundError extends Error {
537
620
  constructor(message: string);
538
621
  }
622
+ /** A resource already exists. */
623
+ declare class AlreadyExistsError extends Error {
624
+ constructor(message: string);
625
+ }
539
626
  /** A request or other operation was invalid. */
540
627
  declare class InvalidError extends Error {
541
628
  constructor(message: string);
@@ -598,7 +685,7 @@ declare class Queue {
598
685
  readonly queueId: string;
599
686
  readonly name?: string;
600
687
  /** @ignore */
601
- constructor(queueId: string, name?: string, ephemeral?: boolean);
688
+ constructor(queueId: string, name?: string, ephemeralHbManager?: EphemeralHeartbeatManager);
602
689
  /**
603
690
  * Create a nameless, temporary queue.
604
691
  * You will need to call `closeEphemeral()` to delete the queue.
@@ -654,4 +741,4 @@ declare class Queue {
654
741
  iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
655
742
  }
656
743
 
657
- export { App, type ClientOptions, CloudBucketMount, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, type FunctionStats, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Proxy, type ProxyFromNameOptions, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, SandboxFile, type SandboxFileMode, type SandboxListOptions, SandboxTimeoutError, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, Tunnel, type UpdateAutoscalerOptions, Volume, type VolumeFromNameOptions, initializeClient };
744
+ export { AlreadyExistsError, App, type ClientOptions, CloudBucketMount, Cls, type ClsBatchingOptions, type ClsConcurrencyOptions, ClsInstance, type ClsOptions, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, type FunctionStats, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Proxy, type ProxyFromNameOptions, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Retries, Sandbox, type SandboxCreateOptions, SandboxFile, type SandboxFileMode, type SandboxListOptions, SandboxTimeoutError, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, Tunnel, type UpdateAutoscalerOptions, Volume, type VolumeFromNameOptions, initializeClient };
package/dist/index.d.ts CHANGED
@@ -89,6 +89,12 @@ declare class Image {
89
89
  /** @ignore */
90
90
  constructor(imageId: string, tag: string, imageRegistryConfig?: ImageRegistryConfig);
91
91
  get imageId(): string;
92
+ /**
93
+ * Creates an `Image` instance from an image id
94
+ *
95
+ * @param imageId - Image id.
96
+ */
97
+ static fromId(imageId: string): Image;
92
98
  /**
93
99
  * Creates an `Image` instance from a raw registry tag, optionally using a secret for authentication.
94
100
  *
@@ -111,10 +117,11 @@ declare class Image {
111
117
  */
112
118
  static fromGcpArtifactRegistry(tag: string, secret: Secret): Image;
113
119
  /**
114
- * @internal
115
- * Build image object
120
+ * Eagerly builds an `Image` on Modal.
121
+ *
122
+ * @param app - App to use to build image.
116
123
  */
117
- _build(appId: string): Promise<Image>;
124
+ build(app: App): Promise<Image>;
118
125
  }
119
126
 
120
127
  /** File open modes supported by the filesystem API. */
@@ -252,6 +259,17 @@ declare class Sandbox {
252
259
  * @returns Sandbox with ID
253
260
  */
254
261
  static fromId(sandboxId: string): Promise<Sandbox>;
262
+ /** Get a running Sandbox by name from a deployed App.
263
+ *
264
+ * Raises a NotFoundError if no running Sandbox is found with the given name.
265
+ * A Sandbox's name is the `name` argument passed to `App.createSandbox`.
266
+ *
267
+ * @param appName - Name of the deployed app
268
+ * @param name - Name of the sandbox
269
+ * @param environment - Optional override for the environment
270
+ * @returns Promise that resolves to a Sandbox
271
+ */
272
+ static fromName(appName: string, name: string, environment?: string): Promise<Sandbox>;
255
273
  /**
256
274
  * Open a file in the sandbox filesystem.
257
275
  * @param path - Path to the file to open
@@ -306,6 +324,15 @@ declare class ContainerProcess<R extends string | Uint8Array = any> {
306
324
  wait(): Promise<number>;
307
325
  }
308
326
 
327
+ type HeartbeatFunction = () => Promise<any>;
328
+ declare class EphemeralHeartbeatManager {
329
+ private readonly heartbeatFn;
330
+ private readonly abortController;
331
+ constructor(heartbeatFn: HeartbeatFunction);
332
+ private start;
333
+ stop(): void;
334
+ }
335
+
309
336
  /** Options for `Volume.fromName()`. */
310
337
  type VolumeFromNameOptions = {
311
338
  environment?: string;
@@ -313,15 +340,23 @@ type VolumeFromNameOptions = {
313
340
  };
314
341
  /** Volumes provide persistent storage that can be mounted in Modal functions. */
315
342
  declare class Volume {
343
+ #private;
316
344
  readonly volumeId: string;
317
345
  readonly name?: string;
318
346
  private _readOnly;
319
347
  /** @ignore */
320
- constructor(volumeId: string, name?: string, readOnly?: boolean);
348
+ constructor(volumeId: string, name?: string, readOnly?: boolean, ephemeralHbManager?: EphemeralHeartbeatManager);
321
349
  static fromName(name: string, options?: VolumeFromNameOptions): Promise<Volume>;
322
350
  /** Configure Volume to mount as read-only. */
323
351
  readOnly(): Volume;
324
352
  get isReadOnly(): boolean;
353
+ /**
354
+ * Create a nameless, temporary volume.
355
+ * You will need to call `closeEphemeral()` to delete the volume.
356
+ */
357
+ static ephemeral(options?: EphemeralOptions): Promise<Volume>;
358
+ /** Delete the ephemeral volume. Only usable with `Volume.ephemeral()`. */
359
+ closeEphemeral(): void;
325
360
  }
326
361
 
327
362
  /** Options for `Proxy.fromName()`. */
@@ -410,6 +445,8 @@ type SandboxCreateOptions = {
410
445
  verbose?: boolean;
411
446
  /** Reference to a Modal Proxy to use in front of this Sandbox. */
412
447
  proxy?: Proxy;
448
+ /** Optional name for the sandbox. Unique within an app. */
449
+ name?: string;
413
450
  };
414
451
  /** Represents a deployed Modal App. */
415
452
  declare class App {
@@ -504,14 +541,60 @@ declare class Function_ {
504
541
  getWebUrl(): Promise<string | undefined>;
505
542
  }
506
543
 
544
+ /** Retry policy configuration for a Modal Function/Cls. */
545
+ declare class Retries {
546
+ readonly maxRetries: number;
547
+ readonly backoffCoefficient: number;
548
+ readonly initialDelayMs: number;
549
+ readonly maxDelayMs: number;
550
+ constructor(options: {
551
+ maxRetries: number;
552
+ backoffCoefficient?: number;
553
+ initialDelayMs?: number;
554
+ maxDelayMs?: number;
555
+ });
556
+ }
557
+
558
+ type ClsOptions = {
559
+ cpu?: number;
560
+ memory?: number;
561
+ gpu?: string;
562
+ secrets?: Secret[];
563
+ volumes?: Record<string, Volume>;
564
+ retries?: number | Retries;
565
+ maxContainers?: number;
566
+ bufferContainers?: number;
567
+ scaledownWindow?: number;
568
+ timeout?: number;
569
+ };
570
+ type ClsConcurrencyOptions = {
571
+ maxInputs: number;
572
+ targetInputs?: number;
573
+ };
574
+ type ClsBatchingOptions = {
575
+ maxBatchSize: number;
576
+ waitMs: number;
577
+ };
578
+ type ServiceOptions = ClsOptions & {
579
+ maxConcurrentInputs?: number;
580
+ targetConcurrentInputs?: number;
581
+ batchMaxSize?: number;
582
+ batchWaitMs?: number;
583
+ };
507
584
  /** Represents a deployed Modal Cls. */
508
585
  declare class Cls {
509
586
  #private;
510
587
  /** @ignore */
511
- constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string);
588
+ constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string, options?: ServiceOptions);
512
589
  static lookup(appName: string, name: string, options?: LookupOptions): Promise<Cls>;
513
- /** Create a new instance of the Cls with parameters. */
590
+ /** Create a new instance of the Cls with parameters and/or runtime options. */
514
591
  instance(params?: Record<string, any>): Promise<ClsInstance>;
592
+ /** Override the static Function configuration at runtime. */
593
+ withOptions(options: ClsOptions): Cls;
594
+ /** Create an instance of the Cls with input concurrency enabled or overridden with new values. */
595
+ withConcurrency(options: ClsConcurrencyOptions): Cls;
596
+ /** Create an instance of the Cls with dynamic batching enabled or overridden with new values. */
597
+ withBatching(options: ClsBatchingOptions): Cls;
515
598
  }
516
599
  /** Represents an instance of a deployed Modal Cls, optionally with parameters. */
517
600
  declare class ClsInstance {
@@ -536,6 +619,10 @@ declare class InternalFailure extends Error {
536
619
  declare class NotFoundError extends Error {
537
620
  constructor(message: string);
538
621
  }
622
+ /** A resource already exists. */
623
+ declare class AlreadyExistsError extends Error {
624
+ constructor(message: string);
625
+ }
539
626
  /** A request or other operation was invalid. */
540
627
  declare class InvalidError extends Error {
541
628
  constructor(message: string);
@@ -598,7 +685,7 @@ declare class Queue {
598
685
  readonly queueId: string;
599
686
  readonly name?: string;
600
687
  /** @ignore */
601
- constructor(queueId: string, name?: string, ephemeral?: boolean);
688
+ constructor(queueId: string, name?: string, ephemeralHbManager?: EphemeralHeartbeatManager);
602
689
  /**
603
690
  * Create a nameless, temporary queue.
604
691
  * You will need to call `closeEphemeral()` to delete the queue.
@@ -654,4 +741,4 @@ declare class Queue {
654
741
  iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
655
742
  }
656
743
 
657
- export { App, type ClientOptions, CloudBucketMount, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, type FunctionStats, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Proxy, type ProxyFromNameOptions, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, SandboxFile, type SandboxFileMode, type SandboxListOptions, SandboxTimeoutError, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, Tunnel, type UpdateAutoscalerOptions, Volume, type VolumeFromNameOptions, initializeClient };
744
+ export { AlreadyExistsError, App, type ClientOptions, CloudBucketMount, Cls, type ClsBatchingOptions, type ClsConcurrencyOptions, ClsInstance, type ClsOptions, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, type FunctionStats, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Proxy, type ProxyFromNameOptions, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Retries, Sandbox, type SandboxCreateOptions, SandboxFile, type SandboxFileMode, type SandboxListOptions, SandboxTimeoutError, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, Tunnel, type UpdateAutoscalerOptions, Volume, type VolumeFromNameOptions, initializeClient };