modal 0.3.21 → 0.3.23

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.js CHANGED
@@ -24355,13 +24355,16 @@ var ListPagination = {
24355
24355
  }
24356
24356
  };
24357
24357
  function createBaseMapAwaitRequest() {
24358
- return { functionCallId: "", lastEntryId: "", requestedAt: 0, timeout: 0 };
24358
+ return { functionCallId: void 0, mapToken: void 0, lastEntryId: "", requestedAt: 0, timeout: 0 };
24359
24359
  }
24360
24360
  var MapAwaitRequest = {
24361
24361
  encode(message, writer = new BinaryWriter()) {
24362
- if (message.functionCallId !== "") {
24362
+ if (message.functionCallId !== void 0) {
24363
24363
  writer.uint32(10).string(message.functionCallId);
24364
24364
  }
24365
+ if (message.mapToken !== void 0) {
24366
+ writer.uint32(42).string(message.mapToken);
24367
+ }
24365
24368
  if (message.lastEntryId !== "") {
24366
24369
  writer.uint32(18).string(message.lastEntryId);
24367
24370
  }
@@ -24387,6 +24390,13 @@ var MapAwaitRequest = {
24387
24390
  message.functionCallId = reader.string();
24388
24391
  continue;
24389
24392
  }
24393
+ case 5: {
24394
+ if (tag !== 42) {
24395
+ break;
24396
+ }
24397
+ message.mapToken = reader.string();
24398
+ continue;
24399
+ }
24390
24400
  case 2: {
24391
24401
  if (tag !== 18) {
24392
24402
  break;
@@ -24418,7 +24428,8 @@ var MapAwaitRequest = {
24418
24428
  },
24419
24429
  fromJSON(object) {
24420
24430
  return {
24421
- functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : "",
24431
+ functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : void 0,
24432
+ mapToken: isSet3(object.mapToken) ? globalThis.String(object.mapToken) : void 0,
24422
24433
  lastEntryId: isSet3(object.lastEntryId) ? globalThis.String(object.lastEntryId) : "",
24423
24434
  requestedAt: isSet3(object.requestedAt) ? globalThis.Number(object.requestedAt) : 0,
24424
24435
  timeout: isSet3(object.timeout) ? globalThis.Number(object.timeout) : 0
@@ -24426,9 +24437,12 @@ var MapAwaitRequest = {
24426
24437
  },
24427
24438
  toJSON(message) {
24428
24439
  const obj = {};
24429
- if (message.functionCallId !== "") {
24440
+ if (message.functionCallId !== void 0) {
24430
24441
  obj.functionCallId = message.functionCallId;
24431
24442
  }
24443
+ if (message.mapToken !== void 0) {
24444
+ obj.mapToken = message.mapToken;
24445
+ }
24432
24446
  if (message.lastEntryId !== "") {
24433
24447
  obj.lastEntryId = message.lastEntryId;
24434
24448
  }
@@ -24445,7 +24459,8 @@ var MapAwaitRequest = {
24445
24459
  },
24446
24460
  fromPartial(object) {
24447
24461
  const message = createBaseMapAwaitRequest();
24448
- message.functionCallId = object.functionCallId ?? "";
24462
+ message.functionCallId = object.functionCallId ?? void 0;
24463
+ message.mapToken = object.mapToken ?? void 0;
24449
24464
  message.lastEntryId = object.lastEntryId ?? "";
24450
24465
  message.requestedAt = object.requestedAt ?? 0;
24451
24466
  message.timeout = object.timeout ?? 0;
@@ -24732,7 +24747,7 @@ var MapStartOrContinueItem = {
24732
24747
  }
24733
24748
  };
24734
24749
  function createBaseMapStartOrContinueRequest() {
24735
- return { functionId: "", parentInputId: "", functionCallId: void 0, items: [] };
24750
+ return { functionId: "", parentInputId: "", functionCallId: void 0, mapToken: void 0, items: [] };
24736
24751
  }
24737
24752
  var MapStartOrContinueRequest = {
24738
24753
  encode(message, writer = new BinaryWriter()) {
@@ -24745,6 +24760,9 @@ var MapStartOrContinueRequest = {
24745
24760
  if (message.functionCallId !== void 0) {
24746
24761
  writer.uint32(26).string(message.functionCallId);
24747
24762
  }
24763
+ if (message.mapToken !== void 0) {
24764
+ writer.uint32(42).string(message.mapToken);
24765
+ }
24748
24766
  for (const v of message.items) {
24749
24767
  MapStartOrContinueItem.encode(v, writer.uint32(34).fork()).join();
24750
24768
  }
@@ -24778,6 +24796,13 @@ var MapStartOrContinueRequest = {
24778
24796
  message.functionCallId = reader.string();
24779
24797
  continue;
24780
24798
  }
24799
+ case 5: {
24800
+ if (tag !== 42) {
24801
+ break;
24802
+ }
24803
+ message.mapToken = reader.string();
24804
+ continue;
24805
+ }
24781
24806
  case 4: {
24782
24807
  if (tag !== 34) {
24783
24808
  break;
@@ -24798,6 +24823,7 @@ var MapStartOrContinueRequest = {
24798
24823
  functionId: isSet3(object.functionId) ? globalThis.String(object.functionId) : "",
24799
24824
  parentInputId: isSet3(object.parentInputId) ? globalThis.String(object.parentInputId) : "",
24800
24825
  functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : void 0,
24826
+ mapToken: isSet3(object.mapToken) ? globalThis.String(object.mapToken) : void 0,
24801
24827
  items: globalThis.Array.isArray(object?.items) ? object.items.map((e) => MapStartOrContinueItem.fromJSON(e)) : []
24802
24828
  };
24803
24829
  },
@@ -24812,6 +24838,9 @@ var MapStartOrContinueRequest = {
24812
24838
  if (message.functionCallId !== void 0) {
24813
24839
  obj.functionCallId = message.functionCallId;
24814
24840
  }
24841
+ if (message.mapToken !== void 0) {
24842
+ obj.mapToken = message.mapToken;
24843
+ }
24815
24844
  if (message.items?.length) {
24816
24845
  obj.items = message.items.map((e) => MapStartOrContinueItem.toJSON(e));
24817
24846
  }
@@ -24825,15 +24854,26 @@ var MapStartOrContinueRequest = {
24825
24854
  message.functionId = object.functionId ?? "";
24826
24855
  message.parentInputId = object.parentInputId ?? "";
24827
24856
  message.functionCallId = object.functionCallId ?? void 0;
24857
+ message.mapToken = object.mapToken ?? void 0;
24828
24858
  message.items = object.items?.map((e) => MapStartOrContinueItem.fromPartial(e)) || [];
24829
24859
  return message;
24830
24860
  }
24831
24861
  };
24832
24862
  function createBaseMapStartOrContinueResponse() {
24833
- return { functionId: "", functionCallId: "", maxInputsOutstanding: 0, attemptTokens: [], retryPolicy: void 0 };
24863
+ return {
24864
+ mapToken: "",
24865
+ functionId: "",
24866
+ functionCallId: "",
24867
+ maxInputsOutstanding: 0,
24868
+ attemptTokens: [],
24869
+ retryPolicy: void 0
24870
+ };
24834
24871
  }
24835
24872
  var MapStartOrContinueResponse = {
24836
24873
  encode(message, writer = new BinaryWriter()) {
24874
+ if (message.mapToken !== "") {
24875
+ writer.uint32(50).string(message.mapToken);
24876
+ }
24837
24877
  if (message.functionId !== "") {
24838
24878
  writer.uint32(10).string(message.functionId);
24839
24879
  }
@@ -24858,6 +24898,13 @@ var MapStartOrContinueResponse = {
24858
24898
  while (reader.pos < end) {
24859
24899
  const tag = reader.uint32();
24860
24900
  switch (tag >>> 3) {
24901
+ case 6: {
24902
+ if (tag !== 50) {
24903
+ break;
24904
+ }
24905
+ message.mapToken = reader.string();
24906
+ continue;
24907
+ }
24861
24908
  case 1: {
24862
24909
  if (tag !== 10) {
24863
24910
  break;
@@ -24903,6 +24950,7 @@ var MapStartOrContinueResponse = {
24903
24950
  },
24904
24951
  fromJSON(object) {
24905
24952
  return {
24953
+ mapToken: isSet3(object.mapToken) ? globalThis.String(object.mapToken) : "",
24906
24954
  functionId: isSet3(object.functionId) ? globalThis.String(object.functionId) : "",
24907
24955
  functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : "",
24908
24956
  maxInputsOutstanding: isSet3(object.maxInputsOutstanding) ? globalThis.Number(object.maxInputsOutstanding) : 0,
@@ -24912,6 +24960,9 @@ var MapStartOrContinueResponse = {
24912
24960
  },
24913
24961
  toJSON(message) {
24914
24962
  const obj = {};
24963
+ if (message.mapToken !== "") {
24964
+ obj.mapToken = message.mapToken;
24965
+ }
24915
24966
  if (message.functionId !== "") {
24916
24967
  obj.functionId = message.functionId;
24917
24968
  }
@@ -24934,6 +24985,7 @@ var MapStartOrContinueResponse = {
24934
24985
  },
24935
24986
  fromPartial(object) {
24936
24987
  const message = createBaseMapStartOrContinueResponse();
24988
+ message.mapToken = object.mapToken ?? "";
24937
24989
  message.functionId = object.functionId ?? "";
24938
24990
  message.functionCallId = object.functionCallId ?? "";
24939
24991
  message.maxInputsOutstanding = object.maxInputsOutstanding ?? 0;
@@ -26629,7 +26681,16 @@ var ObjectDependency = {
26629
26681
  }
26630
26682
  };
26631
26683
  function createBasePTYInfo() {
26632
- return { enabled: false, winszRows: 0, winszCols: 0, envTerm: "", envColorterm: "", envTermProgram: "", ptyType: 0 };
26684
+ return {
26685
+ enabled: false,
26686
+ winszRows: 0,
26687
+ winszCols: 0,
26688
+ envTerm: "",
26689
+ envColorterm: "",
26690
+ envTermProgram: "",
26691
+ ptyType: 0,
26692
+ noTerminateOnIdleStdin: false
26693
+ };
26633
26694
  }
26634
26695
  var PTYInfo = {
26635
26696
  encode(message, writer = new BinaryWriter()) {
@@ -26654,6 +26715,9 @@ var PTYInfo = {
26654
26715
  if (message.ptyType !== 0) {
26655
26716
  writer.uint32(56).int32(message.ptyType);
26656
26717
  }
26718
+ if (message.noTerminateOnIdleStdin !== false) {
26719
+ writer.uint32(64).bool(message.noTerminateOnIdleStdin);
26720
+ }
26657
26721
  return writer;
26658
26722
  },
26659
26723
  decode(input, length) {
@@ -26712,6 +26776,13 @@ var PTYInfo = {
26712
26776
  message.ptyType = reader.int32();
26713
26777
  continue;
26714
26778
  }
26779
+ case 8: {
26780
+ if (tag !== 64) {
26781
+ break;
26782
+ }
26783
+ message.noTerminateOnIdleStdin = reader.bool();
26784
+ continue;
26785
+ }
26715
26786
  }
26716
26787
  if ((tag & 7) === 4 || tag === 0) {
26717
26788
  break;
@@ -26728,7 +26799,8 @@ var PTYInfo = {
26728
26799
  envTerm: isSet3(object.envTerm) ? globalThis.String(object.envTerm) : "",
26729
26800
  envColorterm: isSet3(object.envColorterm) ? globalThis.String(object.envColorterm) : "",
26730
26801
  envTermProgram: isSet3(object.envTermProgram) ? globalThis.String(object.envTermProgram) : "",
26731
- ptyType: isSet3(object.ptyType) ? pTYInfo_PTYTypeFromJSON(object.ptyType) : 0
26802
+ ptyType: isSet3(object.ptyType) ? pTYInfo_PTYTypeFromJSON(object.ptyType) : 0,
26803
+ noTerminateOnIdleStdin: isSet3(object.noTerminateOnIdleStdin) ? globalThis.Boolean(object.noTerminateOnIdleStdin) : false
26732
26804
  };
26733
26805
  },
26734
26806
  toJSON(message) {
@@ -26754,6 +26826,9 @@ var PTYInfo = {
26754
26826
  if (message.ptyType !== 0) {
26755
26827
  obj.ptyType = pTYInfo_PTYTypeToJSON(message.ptyType);
26756
26828
  }
26829
+ if (message.noTerminateOnIdleStdin !== false) {
26830
+ obj.noTerminateOnIdleStdin = message.noTerminateOnIdleStdin;
26831
+ }
26757
26832
  return obj;
26758
26833
  },
26759
26834
  create(base) {
@@ -26768,6 +26843,7 @@ var PTYInfo = {
26768
26843
  message.envColorterm = object.envColorterm ?? "";
26769
26844
  message.envTermProgram = object.envTermProgram ?? "";
26770
26845
  message.ptyType = object.ptyType ?? 0;
26846
+ message.noTerminateOnIdleStdin = object.noTerminateOnIdleStdin ?? false;
26771
26847
  return message;
26772
26848
  }
26773
26849
  };
@@ -30264,6 +30340,142 @@ var Sandbox_ExperimentalOptionsEntry = {
30264
30340
  return message;
30265
30341
  }
30266
30342
  };
30343
+ function createBaseSandboxCreateConnectTokenRequest() {
30344
+ return { sandboxId: "", metadata: "" };
30345
+ }
30346
+ var SandboxCreateConnectTokenRequest = {
30347
+ encode(message, writer = new BinaryWriter()) {
30348
+ if (message.sandboxId !== "") {
30349
+ writer.uint32(10).string(message.sandboxId);
30350
+ }
30351
+ if (message.metadata !== "") {
30352
+ writer.uint32(18).string(message.metadata);
30353
+ }
30354
+ return writer;
30355
+ },
30356
+ decode(input, length) {
30357
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
30358
+ let end = length === void 0 ? reader.len : reader.pos + length;
30359
+ const message = createBaseSandboxCreateConnectTokenRequest();
30360
+ while (reader.pos < end) {
30361
+ const tag = reader.uint32();
30362
+ switch (tag >>> 3) {
30363
+ case 1: {
30364
+ if (tag !== 10) {
30365
+ break;
30366
+ }
30367
+ message.sandboxId = reader.string();
30368
+ continue;
30369
+ }
30370
+ case 2: {
30371
+ if (tag !== 18) {
30372
+ break;
30373
+ }
30374
+ message.metadata = reader.string();
30375
+ continue;
30376
+ }
30377
+ }
30378
+ if ((tag & 7) === 4 || tag === 0) {
30379
+ break;
30380
+ }
30381
+ reader.skip(tag & 7);
30382
+ }
30383
+ return message;
30384
+ },
30385
+ fromJSON(object) {
30386
+ return {
30387
+ sandboxId: isSet3(object.sandboxId) ? globalThis.String(object.sandboxId) : "",
30388
+ metadata: isSet3(object.metadata) ? globalThis.String(object.metadata) : ""
30389
+ };
30390
+ },
30391
+ toJSON(message) {
30392
+ const obj = {};
30393
+ if (message.sandboxId !== "") {
30394
+ obj.sandboxId = message.sandboxId;
30395
+ }
30396
+ if (message.metadata !== "") {
30397
+ obj.metadata = message.metadata;
30398
+ }
30399
+ return obj;
30400
+ },
30401
+ create(base) {
30402
+ return SandboxCreateConnectTokenRequest.fromPartial(base ?? {});
30403
+ },
30404
+ fromPartial(object) {
30405
+ const message = createBaseSandboxCreateConnectTokenRequest();
30406
+ message.sandboxId = object.sandboxId ?? "";
30407
+ message.metadata = object.metadata ?? "";
30408
+ return message;
30409
+ }
30410
+ };
30411
+ function createBaseSandboxCreateConnectTokenResponse() {
30412
+ return { url: "", token: "" };
30413
+ }
30414
+ var SandboxCreateConnectTokenResponse = {
30415
+ encode(message, writer = new BinaryWriter()) {
30416
+ if (message.url !== "") {
30417
+ writer.uint32(10).string(message.url);
30418
+ }
30419
+ if (message.token !== "") {
30420
+ writer.uint32(18).string(message.token);
30421
+ }
30422
+ return writer;
30423
+ },
30424
+ decode(input, length) {
30425
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
30426
+ let end = length === void 0 ? reader.len : reader.pos + length;
30427
+ const message = createBaseSandboxCreateConnectTokenResponse();
30428
+ while (reader.pos < end) {
30429
+ const tag = reader.uint32();
30430
+ switch (tag >>> 3) {
30431
+ case 1: {
30432
+ if (tag !== 10) {
30433
+ break;
30434
+ }
30435
+ message.url = reader.string();
30436
+ continue;
30437
+ }
30438
+ case 2: {
30439
+ if (tag !== 18) {
30440
+ break;
30441
+ }
30442
+ message.token = reader.string();
30443
+ continue;
30444
+ }
30445
+ }
30446
+ if ((tag & 7) === 4 || tag === 0) {
30447
+ break;
30448
+ }
30449
+ reader.skip(tag & 7);
30450
+ }
30451
+ return message;
30452
+ },
30453
+ fromJSON(object) {
30454
+ return {
30455
+ url: isSet3(object.url) ? globalThis.String(object.url) : "",
30456
+ token: isSet3(object.token) ? globalThis.String(object.token) : ""
30457
+ };
30458
+ },
30459
+ toJSON(message) {
30460
+ const obj = {};
30461
+ if (message.url !== "") {
30462
+ obj.url = message.url;
30463
+ }
30464
+ if (message.token !== "") {
30465
+ obj.token = message.token;
30466
+ }
30467
+ return obj;
30468
+ },
30469
+ create(base) {
30470
+ return SandboxCreateConnectTokenResponse.fromPartial(base ?? {});
30471
+ },
30472
+ fromPartial(object) {
30473
+ const message = createBaseSandboxCreateConnectTokenResponse();
30474
+ message.url = object.url ?? "";
30475
+ message.token = object.token ?? "";
30476
+ return message;
30477
+ }
30478
+ };
30267
30479
  function createBaseSandboxCreateRequest() {
30268
30480
  return { appId: "", definition: void 0, environmentName: "" };
30269
30481
  }
@@ -40867,6 +41079,14 @@ var ModalClientDefinition = {
40867
41079
  responseStream: false,
40868
41080
  options: {}
40869
41081
  },
41082
+ sandboxCreateConnectToken: {
41083
+ name: "SandboxCreateConnectToken",
41084
+ requestType: SandboxCreateConnectTokenRequest,
41085
+ requestStream: false,
41086
+ responseType: SandboxCreateConnectTokenResponse,
41087
+ responseStream: false,
41088
+ options: {}
41089
+ },
40870
41090
  sandboxGetFromName: {
40871
41091
  name: "SandboxGetFromName",
40872
41092
  requestType: SandboxGetFromNameRequest,
@@ -41718,11 +41938,20 @@ var Image2 = class _Image {
41718
41938
  #imageId;
41719
41939
  #tag;
41720
41940
  #imageRegistryConfig;
41941
+ #layers;
41721
41942
  /** @ignore */
41722
- constructor(imageId, tag, imageRegistryConfig) {
41943
+ constructor(imageId, tag, imageRegistryConfig, layers) {
41723
41944
  this.#imageId = imageId;
41724
41945
  this.#tag = tag;
41725
41946
  this.#imageRegistryConfig = imageRegistryConfig;
41947
+ this.#layers = layers || [
41948
+ {
41949
+ commands: [],
41950
+ secrets: void 0,
41951
+ gpuConfig: void 0,
41952
+ forceBuild: false
41953
+ }
41954
+ ];
41726
41955
  }
41727
41956
  get imageId() {
41728
41957
  return this.#imageId;
@@ -41807,6 +42036,42 @@ var Image2 = class _Image {
41807
42036
  }
41808
42037
  return new _Image("", tag, imageRegistryConfig);
41809
42038
  }
42039
+ static validateDockerfileCommands(commands) {
42040
+ for (const command of commands) {
42041
+ const trimmed = command.trim().toUpperCase();
42042
+ if (trimmed.startsWith("COPY ") && !trimmed.startsWith("COPY --FROM=")) {
42043
+ throw new InvalidError(
42044
+ "COPY commands that copy from local context are not yet supported."
42045
+ );
42046
+ }
42047
+ }
42048
+ }
42049
+ /**
42050
+ * Extend an image with arbitrary Dockerfile-like commands.
42051
+ *
42052
+ * Each call creates a new Image layer that will be built sequentially.
42053
+ * The provided options apply only to this layer.
42054
+ *
42055
+ * @param commands - Array of Dockerfile commands as strings
42056
+ * @param options - Optional configuration for this layer's build
42057
+ * @returns A new Image instance
42058
+ */
42059
+ dockerfileCommands(commands, options) {
42060
+ if (commands.length === 0) {
42061
+ return this;
42062
+ }
42063
+ _Image.validateDockerfileCommands(commands);
42064
+ const newLayer = {
42065
+ commands: [...commands],
42066
+ secrets: options?.secrets,
42067
+ gpuConfig: options?.gpu ? parseGpuConfig(options.gpu) : void 0,
42068
+ forceBuild: options?.forceBuild
42069
+ };
42070
+ return new _Image("", this.#tag, this.#imageRegistryConfig, [
42071
+ ...this.#layers,
42072
+ newLayer
42073
+ ]);
42074
+ }
41810
42075
  /**
41811
42076
  * Eagerly builds an Image on Modal.
41812
42077
  *
@@ -41816,58 +42081,75 @@ var Image2 = class _Image {
41816
42081
  if (this.imageId !== "") {
41817
42082
  return this;
41818
42083
  }
41819
- const resp = await client.imageGetOrCreate({
41820
- appId: app.appId,
41821
- image: {
41822
- dockerfileCommands: [`FROM ${this.#tag}`],
41823
- imageRegistryConfig: this.#imageRegistryConfig
41824
- },
41825
- builderVersion: imageBuilderVersion()
41826
- });
41827
- let result;
41828
- let metadata = void 0;
41829
- if (resp.result?.status) {
41830
- result = resp.result;
41831
- metadata = resp.metadata;
41832
- } else {
41833
- let lastEntryId = "";
41834
- let resultJoined = void 0;
41835
- while (!resultJoined) {
41836
- for await (const item of client.imageJoinStreaming({
41837
- imageId: resp.imageId,
41838
- timeout: 55,
41839
- lastEntryId
41840
- })) {
41841
- if (item.entryId) lastEntryId = item.entryId;
41842
- if (item.result?.status) {
41843
- resultJoined = item.result;
41844
- metadata = item.metadata;
41845
- break;
42084
+ let baseImageId;
42085
+ for (let i = 0; i < this.#layers.length; i++) {
42086
+ const layer = this.#layers[i];
42087
+ const secretIds = layer.secrets?.map((secret) => secret.secretId) || [];
42088
+ const gpuConfig = layer.gpuConfig;
42089
+ let dockerfileCommands;
42090
+ let baseImages;
42091
+ if (i === 0) {
42092
+ dockerfileCommands = [`FROM ${this.#tag}`, ...layer.commands];
42093
+ baseImages = [];
42094
+ } else {
42095
+ dockerfileCommands = ["FROM base", ...layer.commands];
42096
+ baseImages = [{ dockerTag: "base", imageId: baseImageId }];
42097
+ }
42098
+ const resp = await client.imageGetOrCreate({
42099
+ appId: app.appId,
42100
+ image: Image.create({
42101
+ dockerfileCommands,
42102
+ imageRegistryConfig: this.#imageRegistryConfig,
42103
+ secretIds,
42104
+ gpuConfig,
42105
+ contextFiles: [],
42106
+ baseImages
42107
+ }),
42108
+ builderVersion: imageBuilderVersion(),
42109
+ forceBuild: layer.forceBuild || false
42110
+ });
42111
+ let result;
42112
+ if (resp.result?.status) {
42113
+ result = resp.result;
42114
+ } else {
42115
+ let lastEntryId = "";
42116
+ let resultJoined = void 0;
42117
+ while (!resultJoined) {
42118
+ for await (const item of client.imageJoinStreaming({
42119
+ imageId: resp.imageId,
42120
+ timeout: 55,
42121
+ lastEntryId
42122
+ })) {
42123
+ if (item.entryId) lastEntryId = item.entryId;
42124
+ if (item.result?.status) {
42125
+ resultJoined = item.result;
42126
+ break;
42127
+ }
41846
42128
  }
41847
42129
  }
42130
+ result = resultJoined;
41848
42131
  }
41849
- result = resultJoined;
41850
- }
41851
- void metadata;
41852
- if (result.status === 2 /* GENERIC_STATUS_FAILURE */) {
41853
- throw new Error(
41854
- `Image build for ${resp.imageId} failed with the exception:
42132
+ if (result.status === 2 /* GENERIC_STATUS_FAILURE */) {
42133
+ throw new Error(
42134
+ `Image build for ${resp.imageId} failed with the exception:
41855
42135
  ${result.exception}`
41856
- );
41857
- } else if (result.status === 3 /* GENERIC_STATUS_TERMINATED */) {
41858
- throw new Error(
41859
- `Image build for ${resp.imageId} terminated due to external shut-down. Please try again.`
41860
- );
41861
- } else if (result.status === 4 /* GENERIC_STATUS_TIMEOUT */) {
41862
- throw new Error(
41863
- `Image build for ${resp.imageId} timed out. Please try again with a larger timeout parameter.`
41864
- );
41865
- } else if (result.status !== 1 /* GENERIC_STATUS_SUCCESS */) {
41866
- throw new Error(
41867
- `Image build for ${resp.imageId} failed with unknown status: ${result.status}`
41868
- );
42136
+ );
42137
+ } else if (result.status === 3 /* GENERIC_STATUS_TERMINATED */) {
42138
+ throw new Error(
42139
+ `Image build for ${resp.imageId} terminated due to external shut-down. Please try again.`
42140
+ );
42141
+ } else if (result.status === 4 /* GENERIC_STATUS_TIMEOUT */) {
42142
+ throw new Error(
42143
+ `Image build for ${resp.imageId} timed out. Please try again with a larger timeout parameter.`
42144
+ );
42145
+ } else if (result.status !== 1 /* GENERIC_STATUS_SUCCESS */) {
42146
+ throw new Error(
42147
+ `Image build for ${resp.imageId} failed with unknown status: ${result.status}`
42148
+ );
42149
+ }
42150
+ baseImageId = resp.imageId;
41869
42151
  }
41870
- this.#imageId = resp.imageId;
42152
+ this.#imageId = baseImageId;
41871
42153
  return this;
41872
42154
  }
41873
42155
  /** Delete an Image by ID. Warning: This removes an *entire Image*, and cannot be undone. */
@@ -42121,6 +42403,33 @@ var Tunnel = class {
42121
42403
  return [this.unencryptedHost, this.unencryptedPort];
42122
42404
  }
42123
42405
  };
42406
+ function defaultSandboxPTYInfo() {
42407
+ return PTYInfo.create({
42408
+ enabled: true,
42409
+ winszRows: 24,
42410
+ winszCols: 80,
42411
+ envTerm: "xterm-256color",
42412
+ envColorterm: "truecolor",
42413
+ envTermProgram: "",
42414
+ ptyType: 2 /* PTY_TYPE_SHELL */,
42415
+ noTerminateOnIdleStdin: true
42416
+ });
42417
+ }
42418
+ function containerExecRequestProto(taskId, command, options) {
42419
+ const secretIds = options?.secrets ? options.secrets.map((secret) => secret.secretId) : [];
42420
+ let ptyInfo;
42421
+ if (options?.pty) {
42422
+ ptyInfo = defaultSandboxPTYInfo();
42423
+ }
42424
+ return ContainerExecRequest.create({
42425
+ taskId,
42426
+ command,
42427
+ workdir: options?.workdir,
42428
+ timeoutSecs: options?.timeout ? options.timeout / 1e3 : 0,
42429
+ secretIds,
42430
+ ptyInfo
42431
+ });
42432
+ }
42124
42433
  var Sandbox2 = class _Sandbox {
42125
42434
  sandboxId;
42126
42435
  stdin;
@@ -42225,14 +42534,8 @@ var Sandbox2 = class _Sandbox {
42225
42534
  }
42226
42535
  async exec(command, options) {
42227
42536
  const taskId = await this.#getTaskId();
42228
- const secretIds = options?.secrets ? options.secrets.map((secret) => secret.secretId) : [];
42229
- const resp = await client.containerExec({
42230
- taskId,
42231
- command,
42232
- workdir: options?.workdir,
42233
- timeoutSecs: options?.timeout ? options.timeout / 1e3 : 0,
42234
- secretIds
42235
- });
42537
+ const req = containerExecRequestProto(taskId, command, options);
42538
+ const resp = await client.containerExec(req);
42236
42539
  return new ContainerProcess(resp.execId, options);
42237
42540
  }
42238
42541
  async #getTaskId() {
@@ -42619,7 +42922,118 @@ function parseGpuConfig(gpu) {
42619
42922
  gpuType: gpuType.toUpperCase()
42620
42923
  };
42621
42924
  }
42622
- var App = class _App {
42925
+ function sandboxCreateRequestProto(appId, imageId, options = {}) {
42926
+ const gpuConfig = parseGpuConfig(options.gpu);
42927
+ if (options.timeout && options.timeout % 1e3 !== 0) {
42928
+ throw new Error(
42929
+ `timeout must be a multiple of 1000ms, got ${options.timeout}`
42930
+ );
42931
+ }
42932
+ if (options.idleTimeout && options.idleTimeout % 1e3 !== 0) {
42933
+ throw new Error(
42934
+ `idleTimeout must be a multiple of 1000ms, got ${options.idleTimeout}`
42935
+ );
42936
+ }
42937
+ if (options.workdir && !options.workdir.startsWith("/")) {
42938
+ throw new Error(
42939
+ `workdir must be an absolute path, got: ${options.workdir}`
42940
+ );
42941
+ }
42942
+ const volumeMounts = options.volumes ? Object.entries(options.volumes).map(([mountPath, volume]) => ({
42943
+ volumeId: volume.volumeId,
42944
+ mountPath,
42945
+ allowBackgroundCommits: true,
42946
+ readOnly: volume.isReadOnly
42947
+ })) : [];
42948
+ const cloudBucketMounts = options.cloudBucketMounts ? Object.entries(options.cloudBucketMounts).map(
42949
+ ([mountPath, mount]) => cloudBucketMountToProto(mount, mountPath)
42950
+ ) : [];
42951
+ const openPorts = [];
42952
+ if (options.encryptedPorts) {
42953
+ openPorts.push(
42954
+ ...options.encryptedPorts.map((port) => ({
42955
+ port,
42956
+ unencrypted: false
42957
+ }))
42958
+ );
42959
+ }
42960
+ if (options.h2Ports) {
42961
+ openPorts.push(
42962
+ ...options.h2Ports.map((port) => ({
42963
+ port,
42964
+ unencrypted: false,
42965
+ tunnelType: 1 /* TUNNEL_TYPE_H2 */
42966
+ }))
42967
+ );
42968
+ }
42969
+ if (options.unencryptedPorts) {
42970
+ openPorts.push(
42971
+ ...options.unencryptedPorts.map((port) => ({
42972
+ port,
42973
+ unencrypted: true
42974
+ }))
42975
+ );
42976
+ }
42977
+ const secretIds = options.secrets ? options.secrets.map((secret) => secret.secretId) : [];
42978
+ let networkAccess;
42979
+ if (options.blockNetwork) {
42980
+ if (options.cidrAllowlist) {
42981
+ throw new Error(
42982
+ "cidrAllowlist cannot be used when blockNetwork is enabled"
42983
+ );
42984
+ }
42985
+ networkAccess = {
42986
+ networkAccessType: 2 /* BLOCKED */,
42987
+ allowedCidrs: []
42988
+ };
42989
+ } else if (options.cidrAllowlist) {
42990
+ networkAccess = {
42991
+ networkAccessType: 3 /* ALLOWLIST */,
42992
+ allowedCidrs: options.cidrAllowlist
42993
+ };
42994
+ } else {
42995
+ networkAccess = {
42996
+ networkAccessType: 1 /* OPEN */,
42997
+ allowedCidrs: []
42998
+ };
42999
+ }
43000
+ const schedulerPlacement = SchedulerPlacement.create({
43001
+ regions: options.regions ?? []
43002
+ });
43003
+ let ptyInfo;
43004
+ if (options.pty) {
43005
+ ptyInfo = defaultSandboxPTYInfo();
43006
+ }
43007
+ return SandboxCreateRequest.create({
43008
+ appId,
43009
+ definition: {
43010
+ // Sleep default is implicit in image builder version <=2024.10
43011
+ entrypointArgs: options.command ?? ["sleep", "48h"],
43012
+ imageId,
43013
+ timeoutSecs: options.timeout != void 0 ? options.timeout / 1e3 : 600,
43014
+ idleTimeoutSecs: options.idleTimeout != void 0 ? options.idleTimeout / 1e3 : void 0,
43015
+ workdir: options.workdir ?? void 0,
43016
+ networkAccess,
43017
+ resources: {
43018
+ // https://modal.com/docs/guide/resources
43019
+ milliCpu: Math.round(1e3 * (options.cpu ?? 0.125)),
43020
+ memoryMb: options.memory ?? 128,
43021
+ gpuConfig
43022
+ },
43023
+ volumeMounts,
43024
+ cloudBucketMounts,
43025
+ ptyInfo,
43026
+ secretIds,
43027
+ openPorts: openPorts.length > 0 ? { ports: openPorts } : void 0,
43028
+ cloudProviderStr: options.cloud ?? "",
43029
+ schedulerPlacement,
43030
+ verbose: options.verbose ?? false,
43031
+ proxyId: options.proxy?.proxyId,
43032
+ name: options.name
43033
+ }
43034
+ });
43035
+ }
43036
+ var App2 = class _App {
42623
43037
  appId;
42624
43038
  name;
42625
43039
  /** @ignore */
@@ -42643,113 +43057,15 @@ var App = class _App {
42643
43057
  }
42644
43058
  }
42645
43059
  async createSandbox(image, options = {}) {
42646
- const gpuConfig = parseGpuConfig(options.gpu);
42647
- if (options.timeout && options.timeout % 1e3 !== 0) {
42648
- throw new Error(
42649
- `timeout must be a multiple of 1000ms, got ${options.timeout}`
42650
- );
42651
- }
42652
- if (options.idleTimeout && options.idleTimeout % 1e3 !== 0) {
42653
- throw new Error(
42654
- `idleTimeout must be a multiple of 1000ms, got ${options.idleTimeout}`
42655
- );
42656
- }
42657
43060
  await image.build(this);
42658
- if (options.workdir && !options.workdir.startsWith("/")) {
42659
- throw new Error(
42660
- `workdir must be an absolute path, got: ${options.workdir}`
42661
- );
42662
- }
42663
- const volumeMounts = options.volumes ? Object.entries(options.volumes).map(([mountPath, volume]) => ({
42664
- volumeId: volume.volumeId,
42665
- mountPath,
42666
- allowBackgroundCommits: true,
42667
- readOnly: volume.isReadOnly
42668
- })) : [];
42669
- const cloudBucketMounts = options.cloudBucketMounts ? Object.entries(options.cloudBucketMounts).map(
42670
- ([mountPath, mount]) => cloudBucketMountToProto(mount, mountPath)
42671
- ) : [];
42672
- const openPorts = [];
42673
- if (options.encryptedPorts) {
42674
- openPorts.push(
42675
- ...options.encryptedPorts.map((port) => ({
42676
- port,
42677
- unencrypted: false
42678
- }))
42679
- );
42680
- }
42681
- if (options.h2Ports) {
42682
- openPorts.push(
42683
- ...options.h2Ports.map((port) => ({
42684
- port,
42685
- unencrypted: false,
42686
- tunnelType: 1 /* TUNNEL_TYPE_H2 */
42687
- }))
42688
- );
42689
- }
42690
- if (options.unencryptedPorts) {
42691
- openPorts.push(
42692
- ...options.unencryptedPorts.map((port) => ({
42693
- port,
42694
- unencrypted: true
42695
- }))
42696
- );
42697
- }
42698
- const secretIds = options.secrets ? options.secrets.map((secret) => secret.secretId) : [];
42699
- let networkAccess;
42700
- if (options.blockNetwork) {
42701
- if (options.cidrAllowlist) {
42702
- throw new Error(
42703
- "cidrAllowlist cannot be used when blockNetwork is enabled"
42704
- );
42705
- }
42706
- networkAccess = {
42707
- networkAccessType: 2 /* BLOCKED */,
42708
- allowedCidrs: []
42709
- };
42710
- } else if (options.cidrAllowlist) {
42711
- networkAccess = {
42712
- networkAccessType: 3 /* ALLOWLIST */,
42713
- allowedCidrs: options.cidrAllowlist
42714
- };
42715
- } else {
42716
- networkAccess = {
42717
- networkAccessType: 1 /* OPEN */,
42718
- allowedCidrs: []
42719
- };
42720
- }
42721
- const schedulerPlacement = SchedulerPlacement.create({
42722
- regions: options.regions ?? []
42723
- });
43061
+ const createReq = sandboxCreateRequestProto(
43062
+ this.appId,
43063
+ image.imageId,
43064
+ options
43065
+ );
42724
43066
  let createResp;
42725
43067
  try {
42726
- createResp = await client.sandboxCreate({
42727
- appId: this.appId,
42728
- definition: {
42729
- // Sleep default is implicit in image builder version <=2024.10
42730
- entrypointArgs: options.command ?? ["sleep", "48h"],
42731
- imageId: image.imageId,
42732
- timeoutSecs: options.timeout != void 0 ? options.timeout / 1e3 : 600,
42733
- idleTimeoutSecs: options.idleTimeout != void 0 ? options.idleTimeout / 1e3 : void 0,
42734
- workdir: options.workdir ?? void 0,
42735
- networkAccess,
42736
- resources: {
42737
- // https://modal.com/docs/guide/resources
42738
- milliCpu: Math.round(1e3 * (options.cpu ?? 0.125)),
42739
- memoryMb: options.memory ?? 128,
42740
- gpuConfig
42741
- },
42742
- volumeMounts,
42743
- cloudBucketMounts,
42744
- secretIds,
42745
- openPorts: openPorts.length > 0 ? { ports: openPorts } : void 0,
42746
- cloudProviderStr: options.cloud ?? "",
42747
- schedulerPlacement,
42748
- verbose: options.verbose ?? false,
42749
- proxyId: options.proxy?.proxyId,
42750
- name: options.name
42751
- }
42752
- });
43068
+ createResp = await client.sandboxCreate(createReq);
42753
43069
  } catch (err) {
42754
43070
  if (err instanceof ClientError5 && err.code === Status5.ALREADY_EXISTS) {
42755
43071
  throw new AlreadyExistsError(err.details || err.message);
@@ -44167,7 +44483,7 @@ var Proxy2 = class _Proxy {
44167
44483
  };
44168
44484
  export {
44169
44485
  AlreadyExistsError,
44170
- App,
44486
+ App2 as App,
44171
44487
  CloudBucketMount2 as CloudBucketMount,
44172
44488
  Cls,
44173
44489
  ClsInstance,