modal 0.3.16 → 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
@@ -15,6 +15,15 @@ declare enum ParameterType {
15
15
  PARAM_TYPE_BOOL = 9,
16
16
  UNRECOGNIZED = -1
17
17
  }
18
+ declare enum RegistryAuthType {
19
+ /** REGISTRY_AUTH_TYPE_UNSPECIFIED - Older clients send this instead of "public". */
20
+ REGISTRY_AUTH_TYPE_UNSPECIFIED = 0,
21
+ REGISTRY_AUTH_TYPE_AWS = 1,
22
+ REGISTRY_AUTH_TYPE_GCP = 2,
23
+ REGISTRY_AUTH_TYPE_PUBLIC = 3,
24
+ REGISTRY_AUTH_TYPE_STATIC_CREDS = 4,
25
+ UNRECOGNIZED = -1
26
+ }
18
27
  /** TODO: rename into NamedPayloadType or similar */
19
28
  interface ClassParameterSpec {
20
29
  name: string;
@@ -37,6 +46,11 @@ interface GenericPayloadType {
37
46
  subTypes: GenericPayloadType[];
38
47
  }
39
48
  declare const GenericPayloadType: MessageFns<GenericPayloadType>;
49
+ interface ImageRegistryConfig {
50
+ registryAuthType: RegistryAuthType;
51
+ secretId: string;
52
+ }
53
+ declare const ImageRegistryConfig: MessageFns<ImageRegistryConfig>;
40
54
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
41
55
  type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
42
56
  [K in keyof T]?: DeepPartial<T[K]>;
@@ -50,11 +64,64 @@ interface MessageFns<T> {
50
64
  fromPartial(object: DeepPartial<T>): T;
51
65
  }
52
66
 
67
+ /** Options for `Secret.fromName()`. */
68
+ type SecretFromNameOptions = {
69
+ environment?: string;
70
+ requiredKeys?: string[];
71
+ };
72
+ /** Secrets provide a dictionary of environment variables for images. */
73
+ declare class Secret {
74
+ readonly secretId: string;
75
+ readonly name?: string;
76
+ /** @ignore */
77
+ constructor(secretId: string, name?: string);
78
+ /** Reference a Secret by its name. */
79
+ static fromName(name: string, options?: SecretFromNameOptions): Promise<Secret>;
80
+ /** Create a Secret from a plain object of key-value pairs. */
81
+ static fromObject(entries: Record<string, string>, options?: {
82
+ environment?: string;
83
+ }): Promise<Secret>;
84
+ }
85
+
53
86
  /** A container image, used for starting sandboxes. */
54
87
  declare class Image {
55
- readonly imageId: string;
88
+ #private;
56
89
  /** @ignore */
57
- constructor(imageId: string);
90
+ constructor(imageId: string, tag: string, imageRegistryConfig?: ImageRegistryConfig);
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;
98
+ /**
99
+ * Creates an `Image` instance from a raw registry tag, optionally using a secret for authentication.
100
+ *
101
+ * @param tag - The registry tag for the image.
102
+ * @param secret - Optional. A `Secret` instance containing credentials for registry authentication.
103
+ */
104
+ static fromRegistry(tag: string, secret?: Secret): Image;
105
+ /**
106
+ * Creates an `Image` instance from a raw registry tag, optionally using a secret for authentication.
107
+ *
108
+ * @param tag - The registry tag for the image.
109
+ * @param secret - A `Secret` instance containing credentials for registry authentication.
110
+ */
111
+ static fromAwsEcr(tag: string, secret: Secret): Image;
112
+ /**
113
+ * Creates an `Image` instance from a raw registry tag, optionally using a secret for authentication.
114
+ *
115
+ * @param tag - The registry tag for the image.
116
+ * @param secret - A `Secret` instance containing credentials for registry authentication.
117
+ */
118
+ static fromGcpArtifactRegistry(tag: string, secret: Secret): Image;
119
+ /**
120
+ * Eagerly builds an `Image` on Modal.
121
+ *
122
+ * @param app - App to use to build image.
123
+ */
124
+ build(app: App): Promise<Image>;
58
125
  }
59
126
 
60
127
  /** File open modes supported by the filesystem API. */
@@ -124,20 +191,6 @@ interface ModalWriteStream<R = any> extends WritableStream<R> {
124
191
  writeBytes(bytes: Uint8Array): Promise<void>;
125
192
  }
126
193
 
127
- /** Options for `Secret.fromName()`. */
128
- type SecretFromNameOptions = {
129
- environment?: string;
130
- requiredKeys?: string[];
131
- };
132
- /** Secrets provide a dictionary of environment variables for images. */
133
- declare class Secret {
134
- readonly secretId: string;
135
- /** @ignore */
136
- constructor(secretId: string);
137
- /** Reference a Secret by its name. */
138
- static fromName(name: string, options?: SecretFromNameOptions): Promise<Secret>;
139
- }
140
-
141
194
  /**
142
195
  * Stdin is always present, but this option allow you to drop stdout or stderr
143
196
  * if you don't need them. The default is "pipe", matching Node.js behavior.
@@ -151,6 +204,15 @@ type StdioBehavior = "pipe" | "ignore";
151
204
  * means the data will be read as raw bytes (Uint8Array).
152
205
  */
153
206
  type StreamMode = "text" | "binary";
207
+ /** Options for `Sandbox.list()`. */
208
+ type SandboxListOptions = {
209
+ /** Filter sandboxes for a specific app. */
210
+ appId?: string;
211
+ /** Only return sandboxes that include all specified tags. */
212
+ tags?: Record<string, string>;
213
+ /** Override environment for the request; defaults to current profile. */
214
+ environment?: string;
215
+ };
154
216
  /** Options to configure a `Sandbox.exec()` operation. */
155
217
  type ExecOptions = {
156
218
  /** Specifies text or binary encoding for input and output streams. */
@@ -190,11 +252,24 @@ declare class Sandbox {
190
252
  stderr: ModalReadStream<string>;
191
253
  /** @ignore */
192
254
  constructor(sandboxId: string);
255
+ /** Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in `Sandbox.list`. */
256
+ setTags(tags: Record<string, string>): Promise<void>;
193
257
  /** Returns a running Sandbox object from an ID.
194
258
  *
195
259
  * @returns Sandbox with ID
196
260
  */
197
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>;
198
273
  /**
199
274
  * Open a file in the sandbox filesystem.
200
275
  * @param path - Path to the file to open
@@ -232,6 +307,11 @@ declare class Sandbox {
232
307
  * Returns `null` if the Sandbox is still running, else returns the exit code.
233
308
  */
234
309
  poll(): Promise<number | null>;
310
+ /**
311
+ * List all Sandboxes for the current Environment or App ID (if specified).
312
+ * If tags are specified, only Sandboxes that have at least those tags are returned.
313
+ */
314
+ static list(options?: SandboxListOptions): AsyncGenerator<Sandbox, void, unknown>;
235
315
  }
236
316
  declare class ContainerProcess<R extends string | Uint8Array = any> {
237
317
  #private;
@@ -244,6 +324,15 @@ declare class ContainerProcess<R extends string | Uint8Array = any> {
244
324
  wait(): Promise<number>;
245
325
  }
246
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
+
247
336
  /** Options for `Volume.fromName()`. */
248
337
  type VolumeFromNameOptions = {
249
338
  environment?: string;
@@ -251,10 +340,55 @@ type VolumeFromNameOptions = {
251
340
  };
252
341
  /** Volumes provide persistent storage that can be mounted in Modal functions. */
253
342
  declare class Volume {
343
+ #private;
254
344
  readonly volumeId: string;
345
+ readonly name?: string;
346
+ private _readOnly;
255
347
  /** @ignore */
256
- constructor(volumeId: string);
348
+ constructor(volumeId: string, name?: string, readOnly?: boolean, ephemeralHbManager?: EphemeralHeartbeatManager);
257
349
  static fromName(name: string, options?: VolumeFromNameOptions): Promise<Volume>;
350
+ /** Configure Volume to mount as read-only. */
351
+ readOnly(): Volume;
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;
360
+ }
361
+
362
+ /** Options for `Proxy.fromName()`. */
363
+ type ProxyFromNameOptions = {
364
+ environment?: string;
365
+ };
366
+ /** Proxy objects give your Modal containers a static outbound IP address. */
367
+ declare class Proxy {
368
+ readonly proxyId: string;
369
+ /** @ignore */
370
+ constructor(proxyId: string);
371
+ /** Reference a Proxy by its name. */
372
+ static fromName(name: string, options?: ProxyFromNameOptions): Promise<Proxy>;
373
+ }
374
+
375
+ /** Cloud bucket mounts provide access to cloud storage buckets within Modal functions. */
376
+ declare class CloudBucketMount {
377
+ readonly bucketName: string;
378
+ readonly secret?: Secret;
379
+ readonly readOnly: boolean;
380
+ readonly requesterPays: boolean;
381
+ readonly bucketEndpointUrl?: string;
382
+ readonly keyPrefix?: string;
383
+ readonly oidcAuthRoleArn?: string;
384
+ constructor(bucketName: string, options?: {
385
+ secret?: Secret;
386
+ readOnly?: boolean;
387
+ requesterPays?: boolean;
388
+ bucketEndpointUrl?: string;
389
+ keyPrefix?: string;
390
+ oidcAuthRoleArn?: string;
391
+ });
258
392
  }
259
393
 
260
394
  /** Options for functions that find deployed Modal objects. */
@@ -276,8 +410,12 @@ type SandboxCreateOptions = {
276
410
  cpu?: number;
277
411
  /** Reservation of memory in MiB. */
278
412
  memory?: number;
413
+ /** GPU reservation for the sandbox (e.g. "A100", "T4:2", "A100-80GB:4"). */
414
+ gpu?: string;
279
415
  /** Timeout of the sandbox container, defaults to 10 minutes. */
280
416
  timeout?: number;
417
+ /** Working directory of the sandbox. */
418
+ workdir?: string;
281
419
  /**
282
420
  * Sequence of program arguments for the main process.
283
421
  * Default behavior is to sleep indefinitely until timeout or termination.
@@ -287,23 +425,49 @@ type SandboxCreateOptions = {
287
425
  secrets?: Secret[];
288
426
  /** Mount points for Modal Volumes. */
289
427
  volumes?: Record<string, Volume>;
428
+ /** Mount points for cloud buckets. */
429
+ cloudBucketMounts?: Record<string, CloudBucketMount>;
290
430
  /** List of ports to tunnel into the sandbox. Encrypted ports are tunneled with TLS. */
291
431
  encryptedPorts?: number[];
292
432
  /** List of encrypted ports to tunnel into the sandbox, using HTTP/2. */
293
433
  h2Ports?: number[];
294
434
  /** List of ports to tunnel into the sandbox without encryption. */
295
435
  unencryptedPorts?: number[];
436
+ /** Whether to block all network access from the sandbox. */
437
+ blockNetwork?: boolean;
438
+ /** List of CIDRs the sandbox is allowed to access. If None, all CIDRs are allowed. Cannot be used with blockNetwork. */
439
+ cidrAllowlist?: string[];
440
+ /** Cloud provider to run the sandbox on. */
441
+ cloud?: string;
442
+ /** Region(s) to run the sandbox on. */
443
+ regions?: string[];
444
+ /** Enable verbose logging. */
445
+ verbose?: boolean;
446
+ /** Reference to a Modal Proxy to use in front of this Sandbox. */
447
+ proxy?: Proxy;
448
+ /** Optional name for the sandbox. Unique within an app. */
449
+ name?: string;
296
450
  };
297
451
  /** Represents a deployed Modal App. */
298
452
  declare class App {
299
453
  readonly appId: string;
454
+ readonly name?: string;
300
455
  /** @ignore */
301
- constructor(appId: string);
456
+ constructor(appId: string, name?: string);
302
457
  /** Lookup a deployed app by name, or create if it does not exist. */
303
458
  static lookup(name: string, options?: LookupOptions): Promise<App>;
304
459
  createSandbox(image: Image, options?: SandboxCreateOptions): Promise<Sandbox>;
460
+ /**
461
+ * @deprecated Use `Image.fromRegistry` instead.
462
+ */
305
463
  imageFromRegistry(tag: string, secret?: Secret): Promise<Image>;
464
+ /**
465
+ * @deprecated Use `Image.fromAwsEcr` instead.
466
+ */
306
467
  imageFromAwsEcr(tag: string, secret: Secret): Promise<Image>;
468
+ /**
469
+ * @deprecated Use `Image.fromGcpArtifactRegistry` instead.
470
+ */
307
471
  imageFromGcpArtifactRegistry(tag: string, secret: Secret): Promise<Image>;
308
472
  }
309
473
 
@@ -346,26 +510,91 @@ declare class FunctionCall {
346
510
  cancel(options?: FunctionCallCancelOptions): Promise<void>;
347
511
  }
348
512
 
513
+ /** Simple data structure storing stats for a running Function. */
514
+ interface FunctionStats {
515
+ backlog: number;
516
+ numTotalRunners: number;
517
+ }
518
+ /** Options for overriding a Function's autoscaler behavior. */
519
+ interface UpdateAutoscalerOptions {
520
+ minContainers?: number;
521
+ maxContainers?: number;
522
+ bufferContainers?: number;
523
+ scaledownWindow?: number;
524
+ }
349
525
  /** Represents a deployed Modal Function, which can be invoked remotely. */
350
526
  declare class Function_ {
351
527
  #private;
352
528
  readonly functionId: string;
353
529
  readonly methodName?: string;
354
530
  /** @ignore */
355
- constructor(functionId: string, methodName?: string, inputPlaneUrl?: string);
531
+ constructor(functionId: string, methodName?: string, inputPlaneUrl?: string, webUrl?: string);
356
532
  static lookup(appName: string, name: string, options?: LookupOptions): Promise<Function_>;
357
533
  remote(args?: any[], kwargs?: Record<string, any>): Promise<any>;
358
534
  spawn(args?: any[], kwargs?: Record<string, any>): Promise<FunctionCall>;
535
+ getCurrentStats(): Promise<FunctionStats>;
536
+ updateAutoscaler(options: UpdateAutoscalerOptions): Promise<void>;
537
+ /**
538
+ * URL of a Function running as a web endpoint.
539
+ * @returns The web URL if this function is a web endpoint, otherwise undefined
540
+ */
541
+ getWebUrl(): Promise<string | undefined>;
542
+ }
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
+ });
359
556
  }
360
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
+ };
361
584
  /** Represents a deployed Modal Cls. */
362
585
  declare class Cls {
363
586
  #private;
364
587
  /** @ignore */
365
- constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string);
588
+ constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string, options?: ServiceOptions);
366
589
  static lookup(appName: string, name: string, options?: LookupOptions): Promise<Cls>;
367
- /** Create a new instance of the Cls with parameters. */
590
+ /** Create a new instance of the Cls with parameters and/or runtime options. */
368
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;
369
598
  }
370
599
  /** Represents an instance of a deployed Modal Cls, optionally with parameters. */
371
600
  declare class ClsInstance {
@@ -390,6 +619,10 @@ declare class InternalFailure extends Error {
390
619
  declare class NotFoundError extends Error {
391
620
  constructor(message: string);
392
621
  }
622
+ /** A resource already exists. */
623
+ declare class AlreadyExistsError extends Error {
624
+ constructor(message: string);
625
+ }
393
626
  /** A request or other operation was invalid. */
394
627
  declare class InvalidError extends Error {
395
628
  constructor(message: string);
@@ -450,8 +683,9 @@ type QueueIterateOptions = {
450
683
  declare class Queue {
451
684
  #private;
452
685
  readonly queueId: string;
686
+ readonly name?: string;
453
687
  /** @ignore */
454
- constructor(queueId: string, ephemeral?: boolean);
688
+ constructor(queueId: string, name?: string, ephemeralHbManager?: EphemeralHeartbeatManager);
455
689
  /**
456
690
  * Create a nameless, temporary queue.
457
691
  * You will need to call `closeEphemeral()` to delete the queue.
@@ -507,4 +741,4 @@ declare class Queue {
507
741
  iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
508
742
  }
509
743
 
510
- export { App, type ClientOptions, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, SandboxFile, type SandboxFileMode, SandboxTimeoutError, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, Tunnel, 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 };