modal 0.10.0 → 0.10.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,4 +1,4 @@
1
- import { Client, Status, ClientMiddleware } from 'nice-grpc';
1
+ import { createChannel, Client, Status, ClientMiddleware } from 'nice-grpc';
2
2
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
3
3
 
4
4
  /**
@@ -86,6 +86,13 @@ declare enum AppStopSource {
86
86
  APP_STOP_SOURCE_WEB = 3,
87
87
  UNRECOGNIZED = -1
88
88
  }
89
+ /** CPU architecture an image is built for and must run on. */
90
+ declare enum Arch {
91
+ ARCH_UNSPECIFIED = 0,
92
+ ARCH_X86_64 = 1,
93
+ ARCH_AARCH64 = 2,
94
+ UNRECOGNIZED = -1
95
+ }
89
96
  declare enum CertificateStatus {
90
97
  CERTIFICATE_STATUS_PENDING = 0,
91
98
  CERTIFICATE_STATUS_ISSUED = 1,
@@ -184,6 +191,17 @@ declare enum EndpointStopSource {
184
191
  ENDPOINT_STOP_SOURCE_WEB = 2,
185
192
  UNRECOGNIZED = -1
186
193
  }
194
+ /**
195
+ * Partial-update signal for EnvironmentUpdateRequest. Omitted means no-op.
196
+ * INHERIT clears the environment override so the workspace default applies.
197
+ */
198
+ declare enum EnvironmentBlockUnauthenticatedResources {
199
+ ENVIRONMENT_BLOCK_UNAUTHENTICATED_RESOURCES_UNSPECIFIED = 0,
200
+ ENVIRONMENT_BLOCK_UNAUTHENTICATED_RESOURCES_INHERIT = 1,
201
+ ENVIRONMENT_BLOCK_UNAUTHENTICATED_RESOURCES_BLOCK = 2,
202
+ ENVIRONMENT_BLOCK_UNAUTHENTICATED_RESOURCES_ALLOW = 3,
203
+ UNRECOGNIZED = -1
204
+ }
187
205
  declare enum EnvironmentRole {
188
206
  ENVIRONMENT_ROLE_UNSPECIFIED = 0,
189
207
  ENVIRONMENT_ROLE_VIEWER = 1,
@@ -625,6 +643,14 @@ interface AppGetByDeploymentNameResponse {
625
643
  lifecycle: AppLifecycle | undefined;
626
644
  }
627
645
  declare const AppGetByDeploymentNameResponse: MessageFns$1<AppGetByDeploymentNameResponse>;
646
+ interface AppGetInfoRequest {
647
+ appId: string;
648
+ }
649
+ declare const AppGetInfoRequest: MessageFns$1<AppGetInfoRequest>;
650
+ interface AppGetInfoResponse {
651
+ info: AppHandleMetadata | undefined;
652
+ }
653
+ declare const AppGetInfoResponse: MessageFns$1<AppGetInfoResponse>;
628
654
  interface AppGetLayoutRequest {
629
655
  appId: string;
630
656
  }
@@ -679,6 +705,7 @@ interface AppGetOrCreateRequest {
679
705
  declare const AppGetOrCreateRequest: MessageFns$1<AppGetOrCreateRequest>;
680
706
  interface AppGetOrCreateResponse {
681
707
  appId: string;
708
+ handleMetadata: AppHandleMetadata | undefined;
682
709
  }
683
710
  declare const AppGetOrCreateResponse: MessageFns$1<AppGetOrCreateResponse>;
684
711
  interface AppGetTagsRequest {
@@ -691,6 +718,21 @@ interface AppGetTagsResponse {
691
718
  };
692
719
  }
693
720
  declare const AppGetTagsResponse: MessageFns$1<AppGetTagsResponse>;
721
+ interface AppHandleMetadata {
722
+ description: string;
723
+ appId: string;
724
+ environmentName: string;
725
+ lifecycle: AppLifecycle | undefined;
726
+ /** tag -> function id */
727
+ functions: {
728
+ [key: string]: string;
729
+ };
730
+ /** tag -> function id */
731
+ servers: {
732
+ [key: string]: string;
733
+ };
734
+ }
735
+ declare const AppHandleMetadata: MessageFns$1<AppHandleMetadata>;
694
736
  interface AppHeartbeatRequest {
695
737
  appId: string;
696
738
  }
@@ -1560,6 +1602,7 @@ interface EndpointListItem {
1560
1602
  provisioningStatus: EndpointProvisioningStatus;
1561
1603
  status: string;
1562
1604
  servingMode: EndpointServingMode;
1605
+ unauthenticated: boolean;
1563
1606
  }
1564
1607
  declare const EndpointListItem: MessageFns$1<EndpointListItem>;
1565
1608
  interface EndpointListRequest {
@@ -1718,6 +1761,7 @@ interface EnvironmentListItem {
1718
1761
  spendLimitReached: boolean;
1719
1762
  environmentType: EnvironmentType;
1720
1763
  defaultMemberRole?: EnvironmentRole | undefined;
1764
+ blockUnauthenticatedResources?: boolean | undefined;
1721
1765
  }
1722
1766
  declare const EnvironmentListItem: MessageFns$1<EnvironmentListItem>;
1723
1767
  interface EnvironmentListResponse {
@@ -1766,6 +1810,12 @@ interface EnvironmentSettings {
1766
1810
  webhookSuffix: string;
1767
1811
  maxConcurrentGpus?: number | undefined;
1768
1812
  maxConcurrentTasks?: number | undefined;
1813
+ /**
1814
+ * When true, new unauthenticated web functions, Servers, tunnels, and
1815
+ * Endpoints in this environment are rejected. Unset inherits the workspace
1816
+ * default.
1817
+ */
1818
+ blockUnauthenticatedResources?: boolean | undefined;
1769
1819
  }
1770
1820
  declare const EnvironmentSettings: MessageFns$1<EnvironmentSettings>;
1771
1821
  interface EnvironmentUpdateRequest {
@@ -1774,6 +1824,7 @@ interface EnvironmentUpdateRequest {
1774
1824
  webSuffix: string | undefined;
1775
1825
  maxConcurrentTasks?: number | undefined;
1776
1826
  maxConcurrentGpus?: number | undefined;
1827
+ blockUnauthenticatedResources?: EnvironmentBlockUnauthenticatedResources | undefined;
1777
1828
  }
1778
1829
  declare const EnvironmentUpdateRequest: MessageFns$1<EnvironmentUpdateRequest>;
1779
1830
  /** A file entry when listing files in a volume or network file system. */
@@ -2208,6 +2259,15 @@ interface FunctionFinishInputsRequest {
2208
2259
  numInputs: number;
2209
2260
  }
2210
2261
  declare const FunctionFinishInputsRequest: MessageFns$1<FunctionFinishInputsRequest>;
2262
+ interface FunctionGetByIdRequest {
2263
+ functionId: string;
2264
+ }
2265
+ declare const FunctionGetByIdRequest: MessageFns$1<FunctionGetByIdRequest>;
2266
+ interface FunctionGetByIdResponse {
2267
+ function: FunctionData | undefined;
2268
+ handleMetadata: FunctionHandleMetadata | undefined;
2269
+ }
2270
+ declare const FunctionGetByIdResponse: MessageFns$1<FunctionGetByIdResponse>;
2211
2271
  interface FunctionGetCallGraphRequest {
2212
2272
  functionCallId: string;
2213
2273
  }
@@ -2215,6 +2275,8 @@ declare const FunctionGetCallGraphRequest: MessageFns$1<FunctionGetCallGraphRequ
2215
2275
  interface FunctionGetCallGraphResponse {
2216
2276
  inputs: InputCallGraphInfo[];
2217
2277
  functionCalls: FunctionCallCallGraphInfo[];
2278
+ /** Set by the server when the graph has more nodes than it will return, so `inputs` is a prefix of the graph. */
2279
+ truncated: boolean;
2218
2280
  }
2219
2281
  declare const FunctionGetCallGraphResponse: MessageFns$1<FunctionGetCallGraphResponse>;
2220
2282
  interface FunctionGetCurrentStatsRequest {
@@ -2231,6 +2293,14 @@ interface FunctionGetDynamicConcurrencyResponse {
2231
2293
  concurrency: number;
2232
2294
  }
2233
2295
  declare const FunctionGetDynamicConcurrencyResponse: MessageFns$1<FunctionGetDynamicConcurrencyResponse>;
2296
+ interface FunctionGetFlashAuthTokenRequest {
2297
+ functionId: string;
2298
+ }
2299
+ declare const FunctionGetFlashAuthTokenRequest: MessageFns$1<FunctionGetFlashAuthTokenRequest>;
2300
+ interface FunctionGetFlashAuthTokenResponse {
2301
+ token: string;
2302
+ }
2303
+ declare const FunctionGetFlashAuthTokenResponse: MessageFns$1<FunctionGetFlashAuthTokenResponse>;
2234
2304
  interface FunctionGetInputsItem {
2235
2305
  inputId: string;
2236
2306
  input: FunctionInput | undefined;
@@ -2329,6 +2399,8 @@ interface FunctionGetTimeRangeStatsRequest {
2329
2399
  until: Date | undefined;
2330
2400
  /** Aggregate the root Function pool and its non-version-pinned variant pools. */
2331
2401
  rollup: boolean;
2402
+ /** Filter stats for a specific container */
2403
+ containerId?: string | undefined;
2332
2404
  }
2333
2405
  declare const FunctionGetTimeRangeStatsRequest: MessageFns$1<FunctionGetTimeRangeStatsRequest>;
2334
2406
  interface FunctionGetTimeRangeStatsResponse {
@@ -2336,32 +2408,34 @@ interface FunctionGetTimeRangeStatsResponse {
2336
2408
  since: Date | undefined;
2337
2409
  /** Exclusive. */
2338
2410
  until: Date | undefined;
2339
- /**
2340
- * Per-input latency distributions.
2341
- * Execution time derived from inputs that finish in the window
2342
- */
2343
- executionTimeSeconds: FunctionStatsPercentiles | undefined;
2344
- /**
2345
- * Purposely omitted for now since it can't be computed
2346
- * from the desired tables without caveats that are confusing
2347
- * to explain to users
2348
- */
2349
- queueTimeSeconds: FunctionStatsPercentiles | undefined;
2350
- endToEndLatencySeconds: FunctionStatsPercentiles | undefined;
2351
- /** Container startup is measured from enqueue to start. */
2352
- containerStartupTimeSeconds: FunctionStatsPercentiles | undefined;
2353
2411
  /** Counts of inputs that finish in the requested time range. */
2354
2412
  inputSuccessCount: number;
2355
2413
  inputFailureCount: number;
2356
2414
  inputTimeoutCount: number;
2415
+ /** Number of inputs assigned but not finished at the exclusive end of the time range. */
2416
+ inputRunningAtEndCount: number;
2357
2417
  /**
2358
- * Resource distributions are computed from normalized container heartbeat
2359
- * observations and expressed as fractions, where 1.0 represents 100% utilization.
2360
- * A missing message indicates that no observations were available.
2418
+ * Metrics include execution_time, end_to_end_latency, subject to change
2419
+ * as requirements evolve
2361
2420
  */
2362
- cpuUtilization: FunctionStatsPercentiles | undefined;
2363
- memoryUtilization: FunctionStatsPercentiles | undefined;
2364
- gpuUtilization: FunctionStatsPercentiles | undefined;
2421
+ inputPercentileStats: {
2422
+ [key: string]: StatsPercentileDistribution;
2423
+ };
2424
+ /**
2425
+ * Container lifecycle counts. Started and errored containers are counted when
2426
+ * the corresponding event occurs in the requested time range. Creating containers
2427
+ * were enqueued but had not started or finished at the exclusive end of the range.
2428
+ */
2429
+ containerStartedCount: number;
2430
+ containerErrorCount: number;
2431
+ containerCreatingAtEndCount: number;
2432
+ /**
2433
+ * Metrics include cpu_usage, memory_usage, gpu_utilization subject to change
2434
+ * as requirements evolve
2435
+ */
2436
+ containerPercentileStats: {
2437
+ [key: string]: StatsPercentileDistribution;
2438
+ };
2365
2439
  /**
2366
2440
  * Number of direct non-version-pinned variants included in the roll-up.
2367
2441
  * Zero when roll-up is disabled or the base Function has no variants.
@@ -2565,11 +2639,6 @@ interface FunctionStats$1 {
2565
2639
  inputHeadroom: number;
2566
2640
  }
2567
2641
  declare const FunctionStats$1: MessageFns$1<FunctionStats$1>;
2568
- interface FunctionStatsPercentiles {
2569
- p50: number;
2570
- p90: number;
2571
- }
2572
- declare const FunctionStatsPercentiles: MessageFns$1<FunctionStatsPercentiles>;
2573
2642
  interface FunctionUpdateSchedulingParamsRequest {
2574
2643
  functionId: string;
2575
2644
  warmPoolSizeOverride: number;
@@ -2653,6 +2722,11 @@ interface Image$1 {
2653
2722
  };
2654
2723
  /** Volume mount for RUN commands */
2655
2724
  volumeMounts: VolumeMount[];
2725
+ /**
2726
+ * CPU architecture the image is built for. Images with an unspecified
2727
+ * arch predate this field and are treated as x86_64.
2728
+ */
2729
+ arch: Arch;
2656
2730
  }
2657
2731
  declare const Image$1: MessageFns$1<Image$1>;
2658
2732
  interface ImageBuildChainGetRequest {
@@ -3096,6 +3170,35 @@ interface ObjectDependency {
3096
3170
  objectId: string;
3097
3171
  }
3098
3172
  declare const ObjectDependency: MessageFns$1<ObjectDependency>;
3173
+ /** Policy for outbound traffic from a sandbox. */
3174
+ interface OutboundPolicy {
3175
+ /** Replace headers in outbound HTTPS requests, potentially with secret values. */
3176
+ headerReplacements: OutboundPolicy_HeaderReplacement[];
3177
+ }
3178
+ declare const OutboundPolicy: MessageFns$1<OutboundPolicy>;
3179
+ interface OutboundPolicy_HeaderReplacement {
3180
+ /**
3181
+ * Domain that the header replacement is scoped to. Supports wildcards in
3182
+ * subdomain positions.
3183
+ */
3184
+ domain: string;
3185
+ /** Header name to replace. */
3186
+ headerName: string;
3187
+ /**
3188
+ * Header value to replace.
3189
+ *
3190
+ * Supports templating with keys in a given secret_id: a $-prefixed key
3191
+ * name in the secret will be replaced with the secret value. Literal $
3192
+ * characters can be represented by two dollars: `$$`.
3193
+ */
3194
+ headerValue: string;
3195
+ /**
3196
+ * Reference to a secret to use in the header_value template. Can be empty
3197
+ * if no secret value is used in header_value.
3198
+ */
3199
+ secretId: string;
3200
+ }
3201
+ declare const OutboundPolicy_HeaderReplacement: MessageFns$1<OutboundPolicy_HeaderReplacement>;
3099
3202
  interface PTYInfo {
3100
3203
  /** Soon deprecated */
3101
3204
  enabled: boolean;
@@ -3467,8 +3570,30 @@ interface Sandbox$1 {
3467
3570
  */
3468
3571
  inboundCidrAllowlist: string[];
3469
3572
  environmentVariables: StringMap | undefined;
3573
+ outboundPolicy?: OutboundPolicy | undefined;
3470
3574
  }
3471
3575
  declare const Sandbox$1: MessageFns$1<Sandbox$1>;
3576
+ interface SandboxContainerCreateV2Request {
3577
+ /** Sandbox the container joins; it runs inside that sandbox's task. */
3578
+ sandboxId: string;
3579
+ /** Logical container name, unique within the sandbox. */
3580
+ containerName: string;
3581
+ /**
3582
+ * Same definition type as SandboxCreateV2. Fields a container cannot honor
3583
+ * (resources, timeouts, scheduling constraints, ...) are rejected.
3584
+ */
3585
+ definition: Sandbox$1 | undefined;
3586
+ ephemeralSecrets: StringMap | undefined;
3587
+ cloudBucketMountCredentials: {
3588
+ [key: string]: StringMap;
3589
+ };
3590
+ }
3591
+ declare const SandboxContainerCreateV2Request: MessageFns$1<SandboxContainerCreateV2Request>;
3592
+ interface SandboxContainerCreateV2Response {
3593
+ containerId: string;
3594
+ containerName: string;
3595
+ }
3596
+ declare const SandboxContainerCreateV2Response: MessageFns$1<SandboxContainerCreateV2Response>;
3472
3597
  interface SandboxCreateConnectTokenRequest {
3473
3598
  sandboxId: string;
3474
3599
  userMetadata: string;
@@ -3988,6 +4113,18 @@ interface SharedVolumeRemoveFileRequest {
3988
4113
  recursive: boolean;
3989
4114
  }
3990
4115
  declare const SharedVolumeRemoveFileRequest: MessageFns$1<SharedVolumeRemoveFileRequest>;
4116
+ interface StatsPercentile {
4117
+ /** The percentile expressed in basis points: 5000 is p50 and 9990 is p99.9. */
4118
+ percentileBasisPoints: number;
4119
+ value: number;
4120
+ }
4121
+ declare const StatsPercentile: MessageFns$1<StatsPercentile>;
4122
+ interface StatsPercentileDistribution {
4123
+ /** Unit identifier such as "seconds", "cores", "gibibytes", or "fraction". */
4124
+ unit: string;
4125
+ percentiles: StatsPercentile[];
4126
+ }
4127
+ declare const StatsPercentileDistribution: MessageFns$1<StatsPercentileDistribution>;
3991
4128
  interface StringMap {
3992
4129
  contents: {
3993
4130
  [key: string]: string;
@@ -4295,6 +4432,11 @@ interface VolumeGetFile2Request {
4295
4432
  start: number;
4296
4433
  /** 0 is interpreted as 'read to end' */
4297
4434
  len: number;
4435
+ /**
4436
+ * The client extends each block body it downloads with zero bytes up to the
4437
+ * block's expected length, so responses may omit trailing zero bytes.
4438
+ */
4439
+ clientPadsBlocks: boolean;
4298
4440
  }
4299
4441
  declare const VolumeGetFile2Request: MessageFns$1<VolumeGetFile2Request>;
4300
4442
  interface VolumeGetFile2Response {
@@ -4746,6 +4888,14 @@ declare const ModalClientDefinition: {
4746
4888
  readonly responseStream: false;
4747
4889
  readonly options: {};
4748
4890
  };
4891
+ readonly appGetInfo: {
4892
+ readonly name: "AppGetInfo";
4893
+ readonly requestType: MessageFns$1<AppGetInfoRequest>;
4894
+ readonly requestStream: false;
4895
+ readonly responseType: MessageFns$1<AppGetInfoResponse>;
4896
+ readonly responseStream: false;
4897
+ readonly options: {};
4898
+ };
4749
4899
  readonly appGetLayout: {
4750
4900
  readonly name: "AppGetLayout";
4751
4901
  readonly requestType: MessageFns$1<AppGetLayoutRequest>;
@@ -5481,6 +5631,14 @@ declare const ModalClientDefinition: {
5481
5631
  readonly responseStream: false;
5482
5632
  readonly options: {};
5483
5633
  };
5634
+ readonly functionGetById: {
5635
+ readonly name: "FunctionGetById";
5636
+ readonly requestType: MessageFns$1<FunctionGetByIdRequest>;
5637
+ readonly requestStream: false;
5638
+ readonly responseType: MessageFns$1<FunctionGetByIdResponse>;
5639
+ readonly responseStream: false;
5640
+ readonly options: {};
5641
+ };
5484
5642
  readonly functionGetCallGraph: {
5485
5643
  readonly name: "FunctionGetCallGraph";
5486
5644
  readonly requestType: MessageFns$1<FunctionGetCallGraphRequest>;
@@ -5505,6 +5663,14 @@ declare const ModalClientDefinition: {
5505
5663
  readonly responseStream: false;
5506
5664
  readonly options: {};
5507
5665
  };
5666
+ readonly functionGetFlashAuthToken: {
5667
+ readonly name: "FunctionGetFlashAuthToken";
5668
+ readonly requestType: MessageFns$1<FunctionGetFlashAuthTokenRequest>;
5669
+ readonly requestStream: false;
5670
+ readonly responseType: MessageFns$1<FunctionGetFlashAuthTokenResponse>;
5671
+ readonly responseStream: false;
5672
+ readonly options: {};
5673
+ };
5508
5674
  /** For containers to request next call */
5509
5675
  readonly functionGetInputs: {
5510
5676
  readonly name: "FunctionGetInputs";
@@ -5867,6 +6033,14 @@ declare const ModalClientDefinition: {
5867
6033
  readonly options: {};
5868
6034
  };
5869
6035
  /** Sandboxes */
6036
+ readonly sandboxContainerCreateV2: {
6037
+ readonly name: "SandboxContainerCreateV2";
6038
+ readonly requestType: MessageFns$1<SandboxContainerCreateV2Request>;
6039
+ readonly requestStream: false;
6040
+ readonly responseType: MessageFns$1<SandboxContainerCreateV2Response>;
6041
+ readonly responseStream: false;
6042
+ readonly options: {};
6043
+ };
5870
6044
  readonly sandboxCreate: {
5871
6045
  readonly name: "SandboxCreate";
5872
6046
  readonly requestType: MessageFns$1<SandboxCreateRequest>;
@@ -7632,6 +7806,14 @@ declare enum TaskExecStdoutConfig {
7632
7806
  TASK_EXEC_STDOUT_CONFIG_PIPE = 1,
7633
7807
  UNRECOGNIZED = -1
7634
7808
  }
7809
+ interface SandboxStdinWriteV2Response {
7810
+ }
7811
+ declare const SandboxStdinWriteV2Response: MessageFns<SandboxStdinWriteV2Response>;
7812
+ interface SandboxStdioReadV2Response {
7813
+ data: Uint8Array;
7814
+ startingOffset: number;
7815
+ }
7816
+ declare const SandboxStdioReadV2Response: MessageFns<SandboxStdioReadV2Response>;
7635
7817
  interface SandboxWaitUntilReadyTcrResponse {
7636
7818
  readyAt: number;
7637
7819
  }
@@ -7918,11 +8100,26 @@ interface Profile {
7918
8100
  serverUrl: string;
7919
8101
  tokenId?: string;
7920
8102
  tokenSecret?: string;
8103
+ oauthRefreshToken?: string;
8104
+ oauthClientId?: string;
8105
+ oauthClientSecret?: string;
8106
+ oauthJwtKey?: string;
7921
8107
  environment?: string;
7922
8108
  imageBuilderVersion?: string;
7923
8109
  logLevel?: string;
7924
8110
  /** Parsed from MODAL_MAX_THROTTLE_WAIT. null means unlimited. */
7925
8111
  maxThrottleWaitSecs?: number;
8112
+ /**
8113
+ * How long a Sandbox connection may sit idle before the client gives it up.
8114
+ * The Sandbox stays usable: the next operation reconnects. Zero keeps
8115
+ * connections open until the client closes.
8116
+ */
8117
+ sandboxChannelIdleTimeoutMs: number;
8118
+ /**
8119
+ * Set by the MODAL_SANDBOX_V2 environment variable or the sandbox_v2
8120
+ * profile key in .modal.toml.
8121
+ */
8122
+ sandboxV2: boolean;
7926
8123
  }
7927
8124
 
7928
8125
  /**
@@ -7949,7 +8146,37 @@ interface StdinSource {
7949
8146
  /** @ignore */
7950
8147
  declare class TaskCommandRouterClientImpl {
7951
8148
  private stub;
8149
+ /**
8150
+ * The connection, absent while it is released. It is dialled again by the
8151
+ * next operation, so nothing may hold `stub` across one.
8152
+ */
7952
8153
  private channel;
8154
+ private dial;
8155
+ private factory;
8156
+ /**
8157
+ * How many operations are using the connection. A count rather than a flag
8158
+ * because operations overlap: only the last one out starts the idle clock.
8159
+ */
8160
+ private inFlight;
8161
+ private idle;
8162
+ /**
8163
+ * Bumped every time a connection is dialled. A stream opened on an earlier
8164
+ * one is stale: the connection under it has since been given up.
8165
+ */
8166
+ private generation;
8167
+ /**
8168
+ * Streams open right now, tracked so they can be ended on release.
8169
+ *
8170
+ * grpc-js does not cancel a call in flight when its channel is closed, and a
8171
+ * subchannel with a live call on it is never collected - so closing alone
8172
+ * leaves the socket up. Aborting the calls first is what actually frees it.
8173
+ */
8174
+ private liveStreams;
8175
+ /**
8176
+ * How long the client may go unused before its connection is given up. Zero
8177
+ * keeps it up until the client is closed. Overridable in tests.
8178
+ */
8179
+ idleTimeoutMs: number;
7953
8180
  private serverClient;
7954
8181
  private taskId;
7955
8182
  private sandboxId;
@@ -7960,14 +8187,36 @@ declare class TaskCommandRouterClientImpl {
7960
8187
  private jwtRefreshLock;
7961
8188
  private logger;
7962
8189
  private closed;
8190
+ private draining;
7963
8191
  /**
7964
8192
  * `access` is the router access returned by SandboxCreateV2, which lets a
7965
8193
  * freshly created sandbox connect without a round-trip. Pass undefined to look
7966
8194
  * it up — a re-attached sandbox, or the server could not mint a token.
7967
8195
  */
7968
8196
  static tryInit(serverClient: ModalGrpcClient, taskId: string, sandboxId: string, isV2: boolean, access: CommandRouterAccess | undefined, logger: Logger, profile: Profile): Promise<TaskCommandRouterClientImpl | null>;
7969
- private constructor();
8197
+ /**
8198
+ * Builds a client around an already-resolved connection. Public so a test can
8199
+ * construct one without the control-plane round trip `tryInit` makes; the
8200
+ * class is not exported from the package, so this is not API surface.
8201
+ */
8202
+ constructor(serverClient: ModalGrpcClient, taskId: string, sandboxId: string, isV2: boolean, serverUrl: string, jwt: string, dial: () => ReturnType<typeof createChannel>, logger: Logger, idleTimeoutMs: number);
8203
+ /**
8204
+ * Says the client is about to be used: holds off the idle timer, and dials
8205
+ * again if the connection was already given up. Returns the generation being
8206
+ * used; pair every call with endOp.
8207
+ */
8208
+ private beginOp;
8209
+ /** Says the caller is done. The last one out starts the clock. */
8210
+ private endOp;
8211
+ /**
8212
+ * Starts the countdown to giving the connection back. Call it with nothing
8213
+ * in flight.
8214
+ */
8215
+ private armIdleTimer;
8216
+ /** Refuse new operations and release resources after current operations finish. */
8217
+ closeWhenIdle(): void;
7970
8218
  close(): void;
8219
+ private callWithRetries;
7971
8220
  /** Run a unary RPC against the command router with the default retry policy. */
7972
8221
  private callUnary;
7973
8222
  execStart(request: TaskExecStartRequest): Promise<TaskExecStartResponse>;
@@ -7976,7 +8225,7 @@ declare class TaskCommandRouterClientImpl {
7976
8225
  containerList(request: TaskContainerListRequest): Promise<TaskContainerListResponse>;
7977
8226
  containerTerminate(request: TaskContainerTerminateRequest): Promise<void>;
7978
8227
  containerWait(request: TaskContainerWaitRequest): Promise<TaskContainerWaitResponse>;
7979
- execStdioRead(taskId: string, execId: string, fileDescriptor: FileDescriptor, deadline?: number | null): AsyncGenerator<TaskExecStdioReadResponse>;
8228
+ execStdioRead(taskId: string, execId: string, fileDescriptor: FileDescriptor, deadline?: number | null, signal?: AbortSignal): AsyncGenerator<TaskExecStdioReadResponse>;
7980
8229
  execStdinWrite(taskId: string, execId: string, offset: number, data: Uint8Array, eof: boolean): Promise<TaskExecStdinWriteResponse>;
7981
8230
  /**
7982
8231
  * Read the current stdin write status for an exec'd command.
@@ -8010,10 +8259,20 @@ declare class TaskCommandRouterClientImpl {
8010
8259
  * within this window, the call is cancelled and a TimeoutError is thrown.
8011
8260
  */
8012
8261
  reloadVolumes(request: TaskReloadVolumesRequest, options?: TimeoutOptions): Promise<void>;
8262
+ sandboxStdioReadV2(taskId: string, fileDescriptor: FileDescriptor, signal?: AbortSignal): AsyncGenerator<SandboxStdioReadV2Response>;
8263
+ sandboxStdinWriteV2(taskId: string, offset: number, data: Uint8Array, eof: boolean): Promise<SandboxStdinWriteV2Response>;
8013
8264
  sandboxWaitUntilReady(taskId: string, timeoutMs: number): Promise<SandboxWaitUntilReadyTcrResponse>;
8014
8265
  private refreshJwt;
8266
+ /** The caller holds an operation lease across authentication and all retries. */
8015
8267
  private callWithAuthRetry;
8016
- private streamStdio;
8268
+ /**
8269
+ * Yields the next chunk of stdio, opening or reopening the stream as it needs
8270
+ * to, and determining whether or not to retry a failed open or read. It waits
8271
+ * out the backoff itself.
8272
+ */
8273
+ private streamStdioWithRetries;
8274
+ private streamExecStdio;
8275
+ private streamSandboxStdio;
8017
8276
  }
8018
8277
 
8019
8278
  /** Type of a filesystem entry. */
@@ -8228,12 +8487,13 @@ declare class SandboxFilesystem {
8228
8487
  writeText(data: string, remotePath: string): Promise<void>;
8229
8488
  }
8230
8489
 
8231
- type SandboxSidecarCommandRouter = Pick<TaskCommandRouterClientImpl, "containerCreate" | "containerGet" | "containerList" | "containerTerminate" | "containerWait">;
8490
+ type SandboxSidecarCommandRouter = Pick<TaskCommandRouterClientImpl, "containerCreate" | "containerGet" | "containerList" | "containerTerminate" | "containerWait" | "mountDirectory" | "snapshotDirectory" | "unmountDirectory">;
8232
8491
  type SandboxSidecarAccess = {
8233
8492
  client: ModalClient;
8234
8493
  exec(command: string[], params: SandboxExecParams | undefined, containerId: string): Promise<ContainerProcess>;
8235
8494
  commandRouter(): Promise<[string, SandboxSidecarCommandRouter]>;
8236
8495
  reloadVolumes(containerId: string, params: SidecarReloadVolumesParams | undefined): Promise<void>;
8496
+ snapshotFilesystem(containerId: string, params: SidecarSnapshotFilesystemParams | undefined): Promise<Image>;
8237
8497
  };
8238
8498
  /** Options for {@link SidecarService#create SidecarService.create()}. */
8239
8499
  type SidecarCreateParams = {
@@ -8276,11 +8536,24 @@ type SidecarTerminateParams = {
8276
8536
  /** If true, wait for the sidecar container to terminate. */
8277
8537
  wait?: boolean;
8278
8538
  };
8539
+ /** Optional parameters for {@link SidecarContainer#snapshotFilesystem SidecarContainer.snapshotFilesystem()}. */
8540
+ type SidecarSnapshotFilesystemParams = {
8541
+ /** Overall budget for the snapshot call, in milliseconds. Defaults to 55000. */
8542
+ timeoutMs?: number;
8543
+ /** Lifetime of the resulting image in milliseconds. Defaults to 30 days. Pass `null` for no expiry. */
8544
+ ttlMs?: number | null;
8545
+ };
8279
8546
  /** Optional parameters for {@link SidecarContainer#reloadVolumes SidecarContainer.reloadVolumes()}. */
8280
8547
  type SidecarReloadVolumesParams = {
8281
8548
  /** Overall budget in milliseconds. Defaults to 55000. */
8282
8549
  timeoutMs?: number;
8283
8550
  };
8551
+ /** Optional parameters for {@link SidecarContainer#mountImage SidecarContainer.mountImage()}. */
8552
+ type SidecarMountImageParams = SandboxMountImageParams;
8553
+ /** Optional parameters for {@link SidecarContainer#unmountImage SidecarContainer.unmountImage()}. */
8554
+ type SidecarUnmountImageParams = Record<string, never>;
8555
+ /** Optional parameters for {@link SidecarContainer#snapshotDirectory SidecarContainer.snapshotDirectory()}. */
8556
+ type SidecarSnapshotDirectoryParams = SandboxSnapshotDirectoryParams;
8284
8557
  /**
8285
8558
  * Creates and manages sidecar containers inside a Sandbox.
8286
8559
  *
@@ -8334,6 +8607,8 @@ declare class SidecarContainer {
8334
8607
  terminate(params: {
8335
8608
  wait: true;
8336
8609
  }): Promise<number>;
8610
+ /** Snapshot this Sidecar container's filesystem into an Image. */
8611
+ snapshotFilesystem(params?: SidecarSnapshotFilesystemParams): Promise<Image>;
8337
8612
  /**
8338
8613
  * Reload all Volumes mounted in this sidecar container.
8339
8614
  *
@@ -8341,6 +8616,39 @@ declare class SidecarContainer {
8341
8616
  * (the reload may still complete in the background).
8342
8617
  */
8343
8618
  reloadVolumes(params?: SidecarReloadVolumesParams): Promise<void>;
8619
+ /**
8620
+ * Mount an {@link Image} at a path in this Sidecar container's filesystem.
8621
+ *
8622
+ * @param path - The path where the directory should be mounted
8623
+ * @param image - Optional {@link Image} to mount. If undefined, mounts an empty directory.
8624
+ * @param params - Optional parameters; see {@link SidecarMountImageParams}.
8625
+ */
8626
+ mountImage(path: string, image?: Image, params?: SidecarMountImageParams): Promise<void>;
8627
+ /**
8628
+ * Unmounts an {@link Image} previously mounted at a path in this Sidecar container's filesystem.
8629
+ *
8630
+ * @param path - The mount path to unmount
8631
+ */
8632
+ unmountImage(path: string, _params?: SidecarUnmountImageParams): Promise<void>;
8633
+ /**
8634
+ * Snapshots and creates a new {@link Image} from a directory in the running Sidecar container.
8635
+ *
8636
+ * The resulting Image is retained for `ttlMs` (default: 30 days),
8637
+ * as a hard cutoff measured from creation — usage does not extend
8638
+ * the lifetime. Pass `ttlMs: null` to retain indefinitely.
8639
+ *
8640
+ * The call has an overall `timeoutMs` budget (default: 55000). If it
8641
+ * elapses before a snapshot completes, the call is cancelled and an
8642
+ * error is thrown.
8643
+ *
8644
+ * The Image can be used anywhere an Image is accepted, including as a mount
8645
+ * or as the base filesystem for another container.
8646
+ *
8647
+ * @param path - The path of the directory to snapshot
8648
+ * @param params - Optional parameters; see {@link SidecarSnapshotDirectoryParams}.
8649
+ * @returns Promise that resolves to an {@link Image}
8650
+ */
8651
+ snapshotDirectory(path: string, params?: SidecarSnapshotDirectoryParams): Promise<Image>;
8344
8652
  }
8345
8653
 
8346
8654
  /**
@@ -8514,7 +8822,9 @@ type SandboxCreateParams = {
8514
8822
  name?: string;
8515
8823
  /** Tags to attach to the Sandbox. Filterable via {@link SandboxService#list client.sandboxes.list}. */
8516
8824
  tags?: Record<string, string>;
8517
- /** Optional experimental options. */
8825
+ /**
8826
+ * Optional experimental options. Values must be booleans or strings.
8827
+ */
8518
8828
  experimentalOptions?: Record<string, any>;
8519
8829
  /** If set, connections to this Sandbox will be subdomains of this domain rather than the default.
8520
8830
  * This requires prior manual setup by Modal and is only available for Enterprise customers.
@@ -8851,6 +9161,9 @@ declare class Sandbox {
8851
9161
  * Disconnect from the Sandbox, cleaning up local resources.
8852
9162
  * The Sandbox continues running on Modal's infrastructure.
8853
9163
  * After calling detach(), most operations on this Sandbox object will throw.
9164
+ *
9165
+ * This does not block on or interrupt ongoing reads or calls. Connection
9166
+ * resources are closed promptly once those operations finish.
8854
9167
  */
8855
9168
  detach(): void;
8856
9169
  wait(): Promise<number>;
@@ -8887,13 +9200,39 @@ declare class Sandbox {
8887
9200
  /**
8888
9201
  * Get the exit filesystem snapshot image.
8889
9202
  *
9203
+ * An exit snapshot captures the Sandbox filesystem when the Sandbox exits,
9204
+ * whether its entrypoint finishes gracefully, abruptly, or it is stopped with
9205
+ * {@link Sandbox#terminate}. The resulting {@link Image} can be passed to
9206
+ * {@link SandboxService#create client.sandboxes.create()} to start a new
9207
+ * Sandbox from the saved filesystem.
9208
+ *
9209
+ * Exit snapshots are opt-in: the Sandbox must have been created with
9210
+ * `experimentalOptions: { enable_exit_snapshot: true }`. Calling this on a
9211
+ * Sandbox created without that option throws an {@link InvalidError}.
9212
+ *
9213
+ * @example
9214
+ * ```ts
9215
+ * const sb = await modal.sandboxes.create(app, image, {
9216
+ * experimentalOptions: { enable_exit_snapshot: true },
9217
+ * });
9218
+ * // ... use the Sandbox ...
9219
+ * await sb.terminate();
9220
+ * const image = await sb.experimentalGetExitSnapshot();
9221
+ * const sb2 = await modal.sandboxes.create(app, image);
9222
+ * ```
9223
+ *
8890
9224
  * EXPERIMENTAL: the API is subject to change.
8891
9225
  *
8892
9226
  * @param params - Optional parameters; see SandboxExperimentalGetExitSnapshotParams.
8893
9227
  * @returns The exit snapshot Image.
9228
+ * @throws {InvalidError} If `timeoutMs` is negative, or if exit snapshots
9229
+ * were not enabled when the Sandbox was created.
8894
9230
  * @throws {TimeoutError} If `timeoutMs` elapses before the snapshot
8895
9231
  * reaches a terminal state. This includes `timeoutMs = 0` when the
8896
9232
  * snapshot is still pending.
9233
+ * @throws {SnapshotCreationError} Snapshot operation is done and failed.
9234
+ * Polling again will not produce an Image; filesystem state is gone.
9235
+ * @throws {NotFoundError} If the Sandbox does not exist.
8897
9236
  */
8898
9237
  experimentalGetExitSnapshot(params?: SandboxExperimentalGetExitSnapshotParams): Promise<Image>;
8899
9238
  /**
@@ -8999,6 +9338,14 @@ declare class ContainerProcess<R extends string | Uint8Array = any> {
8999
9338
  interface ModalClientParams {
9000
9339
  tokenId?: string;
9001
9340
  tokenSecret?: string;
9341
+ /** OAuth refresh token returned by Modal's token endpoint. */
9342
+ oauthRefreshToken?: string;
9343
+ /** Modal-issued OAuth client ID, with an `oc-` prefix. */
9344
+ oauthClientId?: string;
9345
+ /** Modal-issued OAuth client secret, with an `ov-` prefix. */
9346
+ oauthClientSecret?: string;
9347
+ /** Unencrypted RSA private key encoded as PEM, with literal or escaped newlines. */
9348
+ oauthJwtKey?: string;
9002
9349
  environment?: string;
9003
9350
  endpoint?: string;
9004
9351
  timeoutMs?: number;
@@ -9059,8 +9406,10 @@ declare class ModalClient {
9059
9406
  private authTokenManager;
9060
9407
  private customMiddleware;
9061
9408
  private environmentManager;
9409
+ private oauthJwtKey?;
9062
9410
  constructor(params?: ModalClientParams);
9063
9411
  environmentName(environment?: string): string;
9412
+ private validateProfileCredentials;
9064
9413
  /**
9065
9414
  * Returns the image builder version by querying the server where the local profile takes
9066
9415
  * precedence.
@@ -9207,7 +9556,7 @@ declare class SandboxFilesystemPermissionError extends SandboxFilesystemError {
9207
9556
  declare class SandboxTimeoutError extends Error {
9208
9557
  constructor(message?: string);
9209
9558
  }
9210
- /** No snapshot image will be produced for a Sandbox. */
9559
+ /** Snapshot operation is done and failed. Polling again will not produce an Image; filesystem state is gone. */
9211
9560
  declare class SnapshotCreationError extends Error {
9212
9561
  constructor(message: string);
9213
9562
  }
@@ -9218,4 +9567,4 @@ declare class ClientClosedError extends Error {
9218
9567
 
9219
9568
  declare function checkForRenamedParams(params: any, renames: Record<string, string>): void;
9220
9569
 
9221
- export { AlreadyExistsError, App, type AppFromNameParams, AppService, ClientClosedError, CloudBucketMount, CloudBucketMountService, Cls, type ClsFromNameParams, ClsInstance, ClsService, type ClsWithBatchingParams, type ClsWithConcurrencyParams, type ClsWithOptionsParams, ConflictError, ContainerProcess, ExecutionError, type FileInfo, type FileType, type FileWatchEvent, type FileWatchEventType, type FunctionAutoscalerSettings, FunctionCall, type FunctionCallCancelParams, type FunctionCallGetParams, type FunctionCallLogFetchParams, type FunctionCallLogStreamParams, type FunctionCallLogTailParams, FunctionCallLogsManager, FunctionCallService, type FunctionFromNameParams, type FunctionLogFetchParams, type FunctionLogStreamParams, type FunctionLogTailParams, FunctionLogsManager, FunctionService, type FunctionStats, FunctionTimeoutError, type FunctionUpdateAutoscalerParams, type FunctionWithBatchingParams, type FunctionWithConcurrencyParams, type FunctionWithOptionsParams, Function_, Image, type ImageDeleteParams, type ImageDockerfileCommandsParams, type ImageFromNameParams, type ImagePublishParams, ImageService, InternalFailure, InvalidError, type LogEntry, type FunctionLogFetchParams as LogFetchParams, type LogLevel, type LogSource, type Logger, ModalClient, type ModalClientParams, type ModalReadStream, type ModalWriteStream, NotFoundError, Probe, type ProbeParams, type Profile, Proxy, type ProxyFromNameParams, ProxyService, Queue, type QueueClearParams, type QueueDeleteParams, QueueEmptyError, type QueueEphemeralParams, type QueueFromNameParams, QueueFullError, type QueueGetParams, type QueueIterateParams, type QueueLenParams, type QueuePutParams, QueueService, RemoteError, Retries, Sandbox, type SandboxCreateConnectCredentials, type SandboxCreateConnectTokenParams, type SandboxCreateParams, type SandboxExecParams, type SandboxExperimentalFromNameParams, type SandboxExperimentalFromSnapshotParams, type SandboxExperimentalGetExitSnapshotParams, type SandboxExperimentalListParams, SandboxFilesystem, SandboxFilesystemDirectoryNotEmptyError, SandboxFilesystemError, SandboxFilesystemFileTooLargeError, SandboxFilesystemIsADirectoryError, SandboxFilesystemNotADirectoryError, SandboxFilesystemNotFoundError, SandboxFilesystemPathAlreadyExistsError, SandboxFilesystemPermissionError, type SandboxFromNameParams, type SandboxListParams, type SandboxMountImageParams, type SandboxReloadVolumesParams, SandboxService, SandboxSnapshot, type SandboxSnapshotDirectoryParams, type SandboxSnapshotFilesystemParams, SandboxSnapshotService, type SandboxTerminateParams, SandboxTimeoutError, type SandboxUpdateNetworkPolicyParams, Secret, type SecretDeleteParams, type SecretFromNameParams, type SecretFromObjectParams, SecretService, SidecarContainer, type SidecarCreateParams, type SidecarExecParams, type SidecarGetParams, type SidecarListParams, SidecarService, type SidecarTerminateParams, SnapshotCreationError, type StdioBehavior, type StreamMode, TimeoutError, Tunnel, Volume, type VolumeDeleteParams, type VolumeEphemeralParams, type VolumeFromNameParams, type VolumeMountOptionsParams, VolumeService, checkForRenamedParams };
9570
+ export { AlreadyExistsError, App, type AppFromNameParams, AppService, ClientClosedError, CloudBucketMount, CloudBucketMountService, Cls, type ClsFromNameParams, ClsInstance, ClsService, type ClsWithBatchingParams, type ClsWithConcurrencyParams, type ClsWithOptionsParams, ConflictError, ContainerProcess, ExecutionError, type FileInfo, type FileType, type FileWatchEvent, type FileWatchEventType, type FunctionAutoscalerSettings, FunctionCall, type FunctionCallCancelParams, type FunctionCallGetParams, type FunctionCallLogFetchParams, type FunctionCallLogStreamParams, type FunctionCallLogTailParams, FunctionCallLogsManager, FunctionCallService, type FunctionFromNameParams, type FunctionLogFetchParams, type FunctionLogStreamParams, type FunctionLogTailParams, FunctionLogsManager, FunctionService, type FunctionStats, FunctionTimeoutError, type FunctionUpdateAutoscalerParams, type FunctionWithBatchingParams, type FunctionWithConcurrencyParams, type FunctionWithOptionsParams, Function_, Image, type ImageDeleteParams, type ImageDockerfileCommandsParams, type ImageFromNameParams, type ImagePublishParams, ImageService, InternalFailure, InvalidError, type LogEntry, type FunctionLogFetchParams as LogFetchParams, type LogLevel, type LogSource, type Logger, ModalClient, type ModalClientParams, type ModalReadStream, type ModalWriteStream, NotFoundError, Probe, type ProbeParams, type Profile, Proxy, type ProxyFromNameParams, ProxyService, Queue, type QueueClearParams, type QueueDeleteParams, QueueEmptyError, type QueueEphemeralParams, type QueueFromNameParams, QueueFullError, type QueueGetParams, type QueueIterateParams, type QueueLenParams, type QueuePutParams, QueueService, RemoteError, Retries, Sandbox, type SandboxCreateConnectCredentials, type SandboxCreateConnectTokenParams, type SandboxCreateParams, type SandboxExecParams, type SandboxExperimentalFromNameParams, type SandboxExperimentalFromSnapshotParams, type SandboxExperimentalGetExitSnapshotParams, type SandboxExperimentalListParams, SandboxFilesystem, SandboxFilesystemDirectoryNotEmptyError, SandboxFilesystemError, SandboxFilesystemFileTooLargeError, SandboxFilesystemIsADirectoryError, SandboxFilesystemNotADirectoryError, SandboxFilesystemNotFoundError, SandboxFilesystemPathAlreadyExistsError, SandboxFilesystemPermissionError, type SandboxFromNameParams, type SandboxListParams, type SandboxMountImageParams, type SandboxReloadVolumesParams, SandboxService, SandboxSnapshot, type SandboxSnapshotDirectoryParams, type SandboxSnapshotFilesystemParams, SandboxSnapshotService, type SandboxTerminateParams, SandboxTimeoutError, type SandboxUpdateNetworkPolicyParams, Secret, type SecretDeleteParams, type SecretFromNameParams, type SecretFromObjectParams, SecretService, SidecarContainer, type SidecarCreateParams, type SidecarExecParams, type SidecarGetParams, type SidecarListParams, type SidecarMountImageParams, SidecarService, type SidecarSnapshotDirectoryParams, type SidecarSnapshotFilesystemParams, type SidecarTerminateParams, type SidecarUnmountImageParams, SnapshotCreationError, type StdioBehavior, type StreamMode, TimeoutError, Tunnel, Volume, type VolumeDeleteParams, type VolumeEphemeralParams, type VolumeFromNameParams, type VolumeMountOptionsParams, VolumeService, checkForRenamedParams };