modal 0.6.1 → 0.6.3

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.cjs CHANGED
@@ -45032,7 +45032,8 @@ var SecretService = class {
45032
45032
  secret.secretId
45033
45033
  );
45034
45034
  } catch (err) {
45035
- if (err instanceof NotFoundError && params?.allowMissing) {
45035
+ const isNotFound = err instanceof NotFoundError || err instanceof import_nice_grpc2.ClientError && err.code === import_nice_grpc2.Status.NOT_FOUND;
45036
+ if (isNotFound && params?.allowMissing) {
45036
45037
  return;
45037
45038
  }
45038
45039
  throw err;
@@ -46245,7 +46246,8 @@ var QueueService = class {
46245
46246
  queue.queueId
46246
46247
  );
46247
46248
  } catch (err) {
46248
- if (err instanceof NotFoundError && params.allowMissing) {
46249
+ const isNotFound = err instanceof NotFoundError || err instanceof import_nice_grpc7.ClientError && err.code === import_nice_grpc7.Status.NOT_FOUND;
46250
+ if (isNotFound && params.allowMissing) {
46249
46251
  return;
46250
46252
  }
46251
46253
  throw err;
@@ -46484,6 +46486,7 @@ var Queue = class _Queue {
46484
46486
 
46485
46487
  // src/sandbox.ts
46486
46488
  var import_nice_grpc8 = require("nice-grpc");
46489
+ var import_promises = require("timers/promises");
46487
46490
 
46488
46491
  // src/sandbox_filesystem.ts
46489
46492
  var SandboxFile = class {
@@ -46667,7 +46670,7 @@ var writeMixin = {
46667
46670
  }
46668
46671
  }
46669
46672
  };
46670
- function streamConsumingIter(iterable) {
46673
+ function streamConsumingIter(iterable, onCancel) {
46671
46674
  const iter = iterable[Symbol.asyncIterator]();
46672
46675
  return new ReadableStream(
46673
46676
  {
@@ -46681,7 +46684,13 @@ function streamConsumingIter(iterable) {
46681
46684
  }
46682
46685
  },
46683
46686
  async cancel() {
46684
- consumeIterator(iter);
46687
+ try {
46688
+ onCancel?.();
46689
+ } finally {
46690
+ if (typeof iter.return === "function") {
46691
+ await iter.return();
46692
+ }
46693
+ }
46685
46694
  }
46686
46695
  },
46687
46696
  new ByteLengthQueuingStrategy({
@@ -46690,14 +46699,11 @@ function streamConsumingIter(iterable) {
46690
46699
  })
46691
46700
  );
46692
46701
  }
46693
- async function consumeIterator(iter) {
46694
- while (true) {
46695
- const { done } = await iter.next();
46696
- if (done) break;
46697
- }
46698
- }
46699
46702
 
46700
46703
  // src/sandbox.ts
46704
+ var SB_LOGS_INITIAL_DELAY_MS = 10;
46705
+ var SB_LOGS_DELAY_FACTOR = 2;
46706
+ var SB_LOGS_MAX_RETRIES = 10;
46701
46707
  async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
46702
46708
  checkForRenamedParams(params, {
46703
46709
  memory: "memoryMiB",
@@ -47073,34 +47079,61 @@ async function buildContainerExecRequestProto(taskId, command, params) {
47073
47079
  var Sandbox2 = class _Sandbox {
47074
47080
  #client;
47075
47081
  sandboxId;
47076
- stdin;
47077
- stdout;
47078
- stderr;
47082
+ #stdin;
47083
+ #stdout;
47084
+ #stderr;
47085
+ #stdoutAbort;
47086
+ #stderrAbort;
47079
47087
  #taskId;
47080
47088
  #tunnels;
47081
47089
  /** @ignore */
47082
47090
  constructor(client2, sandboxId) {
47083
47091
  this.#client = client2;
47084
47092
  this.sandboxId = sandboxId;
47085
- this.stdin = toModalWriteStream(inputStreamSb(client2.cpClient, sandboxId));
47086
- this.stdout = toModalReadStream(
47087
- streamConsumingIter(
47093
+ }
47094
+ get stdin() {
47095
+ if (!this.#stdin) {
47096
+ this.#stdin = toModalWriteStream(
47097
+ inputStreamSb(this.#client.cpClient, this.sandboxId)
47098
+ );
47099
+ }
47100
+ return this.#stdin;
47101
+ }
47102
+ get stdout() {
47103
+ if (!this.#stdout) {
47104
+ this.#stdoutAbort = new AbortController();
47105
+ const bytesStream = streamConsumingIter(
47088
47106
  outputStreamSb(
47089
- client2.cpClient,
47090
- sandboxId,
47091
- 1 /* FILE_DESCRIPTOR_STDOUT */
47092
- )
47093
- ).pipeThrough(new TextDecoderStream())
47094
- );
47095
- this.stderr = toModalReadStream(
47096
- streamConsumingIter(
47107
+ this.#client.cpClient,
47108
+ this.sandboxId,
47109
+ 1 /* FILE_DESCRIPTOR_STDOUT */,
47110
+ this.#stdoutAbort.signal
47111
+ ),
47112
+ () => this.#stdoutAbort?.abort()
47113
+ );
47114
+ this.#stdout = toModalReadStream(
47115
+ bytesStream.pipeThrough(new TextDecoderStream())
47116
+ );
47117
+ }
47118
+ return this.#stdout;
47119
+ }
47120
+ get stderr() {
47121
+ if (!this.#stderr) {
47122
+ this.#stderrAbort = new AbortController();
47123
+ const bytesStream = streamConsumingIter(
47097
47124
  outputStreamSb(
47098
- client2.cpClient,
47099
- sandboxId,
47100
- 2 /* FILE_DESCRIPTOR_STDERR */
47101
- )
47102
- ).pipeThrough(new TextDecoderStream())
47103
- );
47125
+ this.#client.cpClient,
47126
+ this.sandboxId,
47127
+ 2 /* FILE_DESCRIPTOR_STDERR */,
47128
+ this.#stderrAbort.signal
47129
+ ),
47130
+ () => this.#stderrAbort?.abort()
47131
+ );
47132
+ this.#stderr = toModalReadStream(
47133
+ bytesStream.pipeThrough(new TextDecoderStream())
47134
+ );
47135
+ }
47136
+ return this.#stderr;
47104
47137
  }
47105
47138
  /** Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in {@link SandboxService#list Sandbox.list}. */
47106
47139
  async setTags(tags) {
@@ -47399,19 +47432,25 @@ var ContainerProcess = class {
47399
47432
  }
47400
47433
  }
47401
47434
  };
47402
- async function* outputStreamSb(cpClient, sandboxId, fileDescriptor) {
47435
+ async function* outputStreamSb(cpClient, sandboxId, fileDescriptor, signal) {
47403
47436
  let lastIndex = "0-0";
47404
47437
  let completed = false;
47405
- let retries = 10;
47438
+ let retriesRemaining = SB_LOGS_MAX_RETRIES;
47439
+ let delayMs = SB_LOGS_INITIAL_DELAY_MS;
47406
47440
  while (!completed) {
47407
47441
  try {
47408
- const outputIterator = cpClient.sandboxGetLogs({
47409
- sandboxId,
47410
- fileDescriptor,
47411
- timeout: 55,
47412
- lastEntryId: lastIndex
47413
- });
47442
+ const outputIterator = cpClient.sandboxGetLogs(
47443
+ {
47444
+ sandboxId,
47445
+ fileDescriptor,
47446
+ timeout: 55,
47447
+ lastEntryId: lastIndex
47448
+ },
47449
+ { signal }
47450
+ );
47414
47451
  for await (const batch of outputIterator) {
47452
+ delayMs = SB_LOGS_INITIAL_DELAY_MS;
47453
+ retriesRemaining = SB_LOGS_MAX_RETRIES;
47415
47454
  lastIndex = batch.entryId;
47416
47455
  yield* batch.items.map((item) => new TextEncoder().encode(item.data));
47417
47456
  if (batch.eof) {
@@ -47420,8 +47459,21 @@ async function* outputStreamSb(cpClient, sandboxId, fileDescriptor) {
47420
47459
  }
47421
47460
  }
47422
47461
  } catch (err) {
47423
- if (isRetryableGrpc(err) && retries > 0) retries--;
47424
- else throw err;
47462
+ if (signal?.aborted) {
47463
+ return;
47464
+ }
47465
+ if (isRetryableGrpc(err) && retriesRemaining > 0) {
47466
+ try {
47467
+ await (0, import_promises.setTimeout)(delayMs, void 0, { signal });
47468
+ } catch {
47469
+ return;
47470
+ }
47471
+ delayMs *= SB_LOGS_DELAY_FACTOR;
47472
+ retriesRemaining--;
47473
+ continue;
47474
+ } else {
47475
+ throw err;
47476
+ }
47425
47477
  }
47426
47478
  }
47427
47479
  }
@@ -47572,7 +47624,8 @@ var VolumeService = class {
47572
47624
  volume.volumeId
47573
47625
  );
47574
47626
  } catch (err) {
47575
- if (err instanceof NotFoundError && params?.allowMissing) {
47627
+ const isNotFound = err instanceof NotFoundError || err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.NOT_FOUND;
47628
+ if (isNotFound && params?.allowMissing) {
47576
47629
  return;
47577
47630
  }
47578
47631
  throw err;
@@ -47826,7 +47879,7 @@ var AuthTokenManager = class {
47826
47879
 
47827
47880
  // src/version.ts
47828
47881
  function getSDKVersion() {
47829
- return true ? "0.6.1" : "0.0.0";
47882
+ return true ? "0.6.3" : "0.0.0";
47830
47883
  }
47831
47884
 
47832
47885
  // src/logger.ts
@@ -48022,7 +48075,10 @@ var ModalClient2 = class {
48022
48075
  const channel = (0, import_nice_grpc10.createChannel)(profile.serverUrl, void 0, {
48023
48076
  "grpc.max_receive_message_length": 100 * 1024 * 1024,
48024
48077
  "grpc.max_send_message_length": 100 * 1024 * 1024,
48025
- "grpc-node.flow_control_window": 64 * 1024 * 1024
48078
+ "grpc-node.flow_control_window": 64 * 1024 * 1024,
48079
+ "grpc.keepalive_time_ms": 3e4,
48080
+ "grpc.keepalive_timeout_ms": 1e4,
48081
+ "grpc.keepalive_permit_without_calls": 1
48026
48082
  });
48027
48083
  let factory = (0, import_nice_grpc10.createClientFactory)().use(this.authMiddleware(profile)).use(this.retryMiddleware()).use(timeoutMiddleware);
48028
48084
  for (const middleware of this.customMiddleware) {
package/dist/index.d.cts CHANGED
@@ -5937,11 +5937,11 @@ declare class Tunnel {
5937
5937
  declare class Sandbox {
5938
5938
  #private;
5939
5939
  readonly sandboxId: string;
5940
- stdin: ModalWriteStream<string>;
5941
- stdout: ModalReadStream<string>;
5942
- stderr: ModalReadStream<string>;
5943
5940
  /** @ignore */
5944
5941
  constructor(client: ModalClient, sandboxId: string);
5942
+ get stdin(): ModalWriteStream<string>;
5943
+ get stdout(): ModalReadStream<string>;
5944
+ get stderr(): ModalReadStream<string>;
5945
5945
  /** Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in {@link SandboxService#list Sandbox.list}. */
5946
5946
  setTags(tags: Record<string, string>): Promise<void>;
5947
5947
  /** Get tags (key-value pairs) currently attached to this Sandbox from the server. */
package/dist/index.d.ts CHANGED
@@ -5937,11 +5937,11 @@ declare class Tunnel {
5937
5937
  declare class Sandbox {
5938
5938
  #private;
5939
5939
  readonly sandboxId: string;
5940
- stdin: ModalWriteStream<string>;
5941
- stdout: ModalReadStream<string>;
5942
- stderr: ModalReadStream<string>;
5943
5940
  /** @ignore */
5944
5941
  constructor(client: ModalClient, sandboxId: string);
5942
+ get stdin(): ModalWriteStream<string>;
5943
+ get stdout(): ModalReadStream<string>;
5944
+ get stderr(): ModalReadStream<string>;
5945
5945
  /** Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in {@link SandboxService#list Sandbox.list}. */
5946
5946
  setTags(tags: Record<string, string>): Promise<void>;
5947
5947
  /** Get tags (key-value pairs) currently attached to this Sandbox from the server. */
package/dist/index.js CHANGED
@@ -44964,7 +44964,8 @@ var SecretService = class {
44964
44964
  secret.secretId
44965
44965
  );
44966
44966
  } catch (err) {
44967
- if (err instanceof NotFoundError && params?.allowMissing) {
44967
+ const isNotFound = err instanceof NotFoundError || err instanceof ClientError2 && err.code === Status2.NOT_FOUND;
44968
+ if (isNotFound && params?.allowMissing) {
44968
44969
  return;
44969
44970
  }
44970
44971
  throw err;
@@ -46177,7 +46178,8 @@ var QueueService = class {
46177
46178
  queue.queueId
46178
46179
  );
46179
46180
  } catch (err) {
46180
- if (err instanceof NotFoundError && params.allowMissing) {
46181
+ const isNotFound = err instanceof NotFoundError || err instanceof ClientError6 && err.code === Status6.NOT_FOUND;
46182
+ if (isNotFound && params.allowMissing) {
46181
46183
  return;
46182
46184
  }
46183
46185
  throw err;
@@ -46416,6 +46418,7 @@ var Queue = class _Queue {
46416
46418
 
46417
46419
  // src/sandbox.ts
46418
46420
  import { ClientError as ClientError7, Status as Status7 } from "nice-grpc";
46421
+ import { setTimeout as setTimeout2 } from "timers/promises";
46419
46422
 
46420
46423
  // src/sandbox_filesystem.ts
46421
46424
  var SandboxFile = class {
@@ -46599,7 +46602,7 @@ var writeMixin = {
46599
46602
  }
46600
46603
  }
46601
46604
  };
46602
- function streamConsumingIter(iterable) {
46605
+ function streamConsumingIter(iterable, onCancel) {
46603
46606
  const iter = iterable[Symbol.asyncIterator]();
46604
46607
  return new ReadableStream(
46605
46608
  {
@@ -46613,7 +46616,13 @@ function streamConsumingIter(iterable) {
46613
46616
  }
46614
46617
  },
46615
46618
  async cancel() {
46616
- consumeIterator(iter);
46619
+ try {
46620
+ onCancel?.();
46621
+ } finally {
46622
+ if (typeof iter.return === "function") {
46623
+ await iter.return();
46624
+ }
46625
+ }
46617
46626
  }
46618
46627
  },
46619
46628
  new ByteLengthQueuingStrategy({
@@ -46622,14 +46631,11 @@ function streamConsumingIter(iterable) {
46622
46631
  })
46623
46632
  );
46624
46633
  }
46625
- async function consumeIterator(iter) {
46626
- while (true) {
46627
- const { done } = await iter.next();
46628
- if (done) break;
46629
- }
46630
- }
46631
46634
 
46632
46635
  // src/sandbox.ts
46636
+ var SB_LOGS_INITIAL_DELAY_MS = 10;
46637
+ var SB_LOGS_DELAY_FACTOR = 2;
46638
+ var SB_LOGS_MAX_RETRIES = 10;
46633
46639
  async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
46634
46640
  checkForRenamedParams(params, {
46635
46641
  memory: "memoryMiB",
@@ -47005,34 +47011,61 @@ async function buildContainerExecRequestProto(taskId, command, params) {
47005
47011
  var Sandbox2 = class _Sandbox {
47006
47012
  #client;
47007
47013
  sandboxId;
47008
- stdin;
47009
- stdout;
47010
- stderr;
47014
+ #stdin;
47015
+ #stdout;
47016
+ #stderr;
47017
+ #stdoutAbort;
47018
+ #stderrAbort;
47011
47019
  #taskId;
47012
47020
  #tunnels;
47013
47021
  /** @ignore */
47014
47022
  constructor(client2, sandboxId) {
47015
47023
  this.#client = client2;
47016
47024
  this.sandboxId = sandboxId;
47017
- this.stdin = toModalWriteStream(inputStreamSb(client2.cpClient, sandboxId));
47018
- this.stdout = toModalReadStream(
47019
- streamConsumingIter(
47025
+ }
47026
+ get stdin() {
47027
+ if (!this.#stdin) {
47028
+ this.#stdin = toModalWriteStream(
47029
+ inputStreamSb(this.#client.cpClient, this.sandboxId)
47030
+ );
47031
+ }
47032
+ return this.#stdin;
47033
+ }
47034
+ get stdout() {
47035
+ if (!this.#stdout) {
47036
+ this.#stdoutAbort = new AbortController();
47037
+ const bytesStream = streamConsumingIter(
47020
47038
  outputStreamSb(
47021
- client2.cpClient,
47022
- sandboxId,
47023
- 1 /* FILE_DESCRIPTOR_STDOUT */
47024
- )
47025
- ).pipeThrough(new TextDecoderStream())
47026
- );
47027
- this.stderr = toModalReadStream(
47028
- streamConsumingIter(
47039
+ this.#client.cpClient,
47040
+ this.sandboxId,
47041
+ 1 /* FILE_DESCRIPTOR_STDOUT */,
47042
+ this.#stdoutAbort.signal
47043
+ ),
47044
+ () => this.#stdoutAbort?.abort()
47045
+ );
47046
+ this.#stdout = toModalReadStream(
47047
+ bytesStream.pipeThrough(new TextDecoderStream())
47048
+ );
47049
+ }
47050
+ return this.#stdout;
47051
+ }
47052
+ get stderr() {
47053
+ if (!this.#stderr) {
47054
+ this.#stderrAbort = new AbortController();
47055
+ const bytesStream = streamConsumingIter(
47029
47056
  outputStreamSb(
47030
- client2.cpClient,
47031
- sandboxId,
47032
- 2 /* FILE_DESCRIPTOR_STDERR */
47033
- )
47034
- ).pipeThrough(new TextDecoderStream())
47035
- );
47057
+ this.#client.cpClient,
47058
+ this.sandboxId,
47059
+ 2 /* FILE_DESCRIPTOR_STDERR */,
47060
+ this.#stderrAbort.signal
47061
+ ),
47062
+ () => this.#stderrAbort?.abort()
47063
+ );
47064
+ this.#stderr = toModalReadStream(
47065
+ bytesStream.pipeThrough(new TextDecoderStream())
47066
+ );
47067
+ }
47068
+ return this.#stderr;
47036
47069
  }
47037
47070
  /** Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in {@link SandboxService#list Sandbox.list}. */
47038
47071
  async setTags(tags) {
@@ -47331,19 +47364,25 @@ var ContainerProcess = class {
47331
47364
  }
47332
47365
  }
47333
47366
  };
47334
- async function* outputStreamSb(cpClient, sandboxId, fileDescriptor) {
47367
+ async function* outputStreamSb(cpClient, sandboxId, fileDescriptor, signal) {
47335
47368
  let lastIndex = "0-0";
47336
47369
  let completed = false;
47337
- let retries = 10;
47370
+ let retriesRemaining = SB_LOGS_MAX_RETRIES;
47371
+ let delayMs = SB_LOGS_INITIAL_DELAY_MS;
47338
47372
  while (!completed) {
47339
47373
  try {
47340
- const outputIterator = cpClient.sandboxGetLogs({
47341
- sandboxId,
47342
- fileDescriptor,
47343
- timeout: 55,
47344
- lastEntryId: lastIndex
47345
- });
47374
+ const outputIterator = cpClient.sandboxGetLogs(
47375
+ {
47376
+ sandboxId,
47377
+ fileDescriptor,
47378
+ timeout: 55,
47379
+ lastEntryId: lastIndex
47380
+ },
47381
+ { signal }
47382
+ );
47346
47383
  for await (const batch of outputIterator) {
47384
+ delayMs = SB_LOGS_INITIAL_DELAY_MS;
47385
+ retriesRemaining = SB_LOGS_MAX_RETRIES;
47347
47386
  lastIndex = batch.entryId;
47348
47387
  yield* batch.items.map((item) => new TextEncoder().encode(item.data));
47349
47388
  if (batch.eof) {
@@ -47352,8 +47391,21 @@ async function* outputStreamSb(cpClient, sandboxId, fileDescriptor) {
47352
47391
  }
47353
47392
  }
47354
47393
  } catch (err) {
47355
- if (isRetryableGrpc(err) && retries > 0) retries--;
47356
- else throw err;
47394
+ if (signal?.aborted) {
47395
+ return;
47396
+ }
47397
+ if (isRetryableGrpc(err) && retriesRemaining > 0) {
47398
+ try {
47399
+ await setTimeout2(delayMs, void 0, { signal });
47400
+ } catch {
47401
+ return;
47402
+ }
47403
+ delayMs *= SB_LOGS_DELAY_FACTOR;
47404
+ retriesRemaining--;
47405
+ continue;
47406
+ } else {
47407
+ throw err;
47408
+ }
47357
47409
  }
47358
47410
  }
47359
47411
  }
@@ -47504,7 +47556,8 @@ var VolumeService = class {
47504
47556
  volume.volumeId
47505
47557
  );
47506
47558
  } catch (err) {
47507
- if (err instanceof NotFoundError && params?.allowMissing) {
47559
+ const isNotFound = err instanceof NotFoundError || err instanceof ClientError8 && err.code === Status8.NOT_FOUND;
47560
+ if (isNotFound && params?.allowMissing) {
47508
47561
  return;
47509
47562
  }
47510
47563
  throw err;
@@ -47758,7 +47811,7 @@ var AuthTokenManager = class {
47758
47811
 
47759
47812
  // src/version.ts
47760
47813
  function getSDKVersion() {
47761
- return true ? "0.6.1" : "0.0.0";
47814
+ return true ? "0.6.3" : "0.0.0";
47762
47815
  }
47763
47816
 
47764
47817
  // src/logger.ts
@@ -47954,7 +48007,10 @@ var ModalClient2 = class {
47954
48007
  const channel = createChannel(profile.serverUrl, void 0, {
47955
48008
  "grpc.max_receive_message_length": 100 * 1024 * 1024,
47956
48009
  "grpc.max_send_message_length": 100 * 1024 * 1024,
47957
- "grpc-node.flow_control_window": 64 * 1024 * 1024
48010
+ "grpc-node.flow_control_window": 64 * 1024 * 1024,
48011
+ "grpc.keepalive_time_ms": 3e4,
48012
+ "grpc.keepalive_timeout_ms": 1e4,
48013
+ "grpc.keepalive_permit_without_calls": 1
47958
48014
  });
47959
48015
  let factory = createClientFactory().use(this.authMiddleware(profile)).use(this.retryMiddleware()).use(timeoutMiddleware);
47960
48016
  for (const middleware of this.customMiddleware) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modal",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Modal SDK for JavaScript/TypeScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://modal.com/docs/guide/sdk-javascript-go",