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.cjs CHANGED
@@ -31,7 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  AlreadyExistsError: () => AlreadyExistsError,
34
- App: () => App,
34
+ App: () => App2,
35
35
  CloudBucketMount: () => CloudBucketMount2,
36
36
  Cls: () => Cls,
37
37
  ClsInstance: () => ClsInstance,
@@ -24415,13 +24415,16 @@ var ListPagination = {
24415
24415
  }
24416
24416
  };
24417
24417
  function createBaseMapAwaitRequest() {
24418
- return { functionCallId: "", lastEntryId: "", requestedAt: 0, timeout: 0 };
24418
+ return { functionCallId: void 0, mapToken: void 0, lastEntryId: "", requestedAt: 0, timeout: 0 };
24419
24419
  }
24420
24420
  var MapAwaitRequest = {
24421
24421
  encode(message, writer = new BinaryWriter()) {
24422
- if (message.functionCallId !== "") {
24422
+ if (message.functionCallId !== void 0) {
24423
24423
  writer.uint32(10).string(message.functionCallId);
24424
24424
  }
24425
+ if (message.mapToken !== void 0) {
24426
+ writer.uint32(42).string(message.mapToken);
24427
+ }
24425
24428
  if (message.lastEntryId !== "") {
24426
24429
  writer.uint32(18).string(message.lastEntryId);
24427
24430
  }
@@ -24447,6 +24450,13 @@ var MapAwaitRequest = {
24447
24450
  message.functionCallId = reader.string();
24448
24451
  continue;
24449
24452
  }
24453
+ case 5: {
24454
+ if (tag !== 42) {
24455
+ break;
24456
+ }
24457
+ message.mapToken = reader.string();
24458
+ continue;
24459
+ }
24450
24460
  case 2: {
24451
24461
  if (tag !== 18) {
24452
24462
  break;
@@ -24478,7 +24488,8 @@ var MapAwaitRequest = {
24478
24488
  },
24479
24489
  fromJSON(object) {
24480
24490
  return {
24481
- functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : "",
24491
+ functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : void 0,
24492
+ mapToken: isSet3(object.mapToken) ? globalThis.String(object.mapToken) : void 0,
24482
24493
  lastEntryId: isSet3(object.lastEntryId) ? globalThis.String(object.lastEntryId) : "",
24483
24494
  requestedAt: isSet3(object.requestedAt) ? globalThis.Number(object.requestedAt) : 0,
24484
24495
  timeout: isSet3(object.timeout) ? globalThis.Number(object.timeout) : 0
@@ -24486,9 +24497,12 @@ var MapAwaitRequest = {
24486
24497
  },
24487
24498
  toJSON(message) {
24488
24499
  const obj = {};
24489
- if (message.functionCallId !== "") {
24500
+ if (message.functionCallId !== void 0) {
24490
24501
  obj.functionCallId = message.functionCallId;
24491
24502
  }
24503
+ if (message.mapToken !== void 0) {
24504
+ obj.mapToken = message.mapToken;
24505
+ }
24492
24506
  if (message.lastEntryId !== "") {
24493
24507
  obj.lastEntryId = message.lastEntryId;
24494
24508
  }
@@ -24505,7 +24519,8 @@ var MapAwaitRequest = {
24505
24519
  },
24506
24520
  fromPartial(object) {
24507
24521
  const message = createBaseMapAwaitRequest();
24508
- message.functionCallId = object.functionCallId ?? "";
24522
+ message.functionCallId = object.functionCallId ?? void 0;
24523
+ message.mapToken = object.mapToken ?? void 0;
24509
24524
  message.lastEntryId = object.lastEntryId ?? "";
24510
24525
  message.requestedAt = object.requestedAt ?? 0;
24511
24526
  message.timeout = object.timeout ?? 0;
@@ -24792,7 +24807,7 @@ var MapStartOrContinueItem = {
24792
24807
  }
24793
24808
  };
24794
24809
  function createBaseMapStartOrContinueRequest() {
24795
- return { functionId: "", parentInputId: "", functionCallId: void 0, items: [] };
24810
+ return { functionId: "", parentInputId: "", functionCallId: void 0, mapToken: void 0, items: [] };
24796
24811
  }
24797
24812
  var MapStartOrContinueRequest = {
24798
24813
  encode(message, writer = new BinaryWriter()) {
@@ -24805,6 +24820,9 @@ var MapStartOrContinueRequest = {
24805
24820
  if (message.functionCallId !== void 0) {
24806
24821
  writer.uint32(26).string(message.functionCallId);
24807
24822
  }
24823
+ if (message.mapToken !== void 0) {
24824
+ writer.uint32(42).string(message.mapToken);
24825
+ }
24808
24826
  for (const v of message.items) {
24809
24827
  MapStartOrContinueItem.encode(v, writer.uint32(34).fork()).join();
24810
24828
  }
@@ -24838,6 +24856,13 @@ var MapStartOrContinueRequest = {
24838
24856
  message.functionCallId = reader.string();
24839
24857
  continue;
24840
24858
  }
24859
+ case 5: {
24860
+ if (tag !== 42) {
24861
+ break;
24862
+ }
24863
+ message.mapToken = reader.string();
24864
+ continue;
24865
+ }
24841
24866
  case 4: {
24842
24867
  if (tag !== 34) {
24843
24868
  break;
@@ -24858,6 +24883,7 @@ var MapStartOrContinueRequest = {
24858
24883
  functionId: isSet3(object.functionId) ? globalThis.String(object.functionId) : "",
24859
24884
  parentInputId: isSet3(object.parentInputId) ? globalThis.String(object.parentInputId) : "",
24860
24885
  functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : void 0,
24886
+ mapToken: isSet3(object.mapToken) ? globalThis.String(object.mapToken) : void 0,
24861
24887
  items: globalThis.Array.isArray(object?.items) ? object.items.map((e) => MapStartOrContinueItem.fromJSON(e)) : []
24862
24888
  };
24863
24889
  },
@@ -24872,6 +24898,9 @@ var MapStartOrContinueRequest = {
24872
24898
  if (message.functionCallId !== void 0) {
24873
24899
  obj.functionCallId = message.functionCallId;
24874
24900
  }
24901
+ if (message.mapToken !== void 0) {
24902
+ obj.mapToken = message.mapToken;
24903
+ }
24875
24904
  if (message.items?.length) {
24876
24905
  obj.items = message.items.map((e) => MapStartOrContinueItem.toJSON(e));
24877
24906
  }
@@ -24885,15 +24914,26 @@ var MapStartOrContinueRequest = {
24885
24914
  message.functionId = object.functionId ?? "";
24886
24915
  message.parentInputId = object.parentInputId ?? "";
24887
24916
  message.functionCallId = object.functionCallId ?? void 0;
24917
+ message.mapToken = object.mapToken ?? void 0;
24888
24918
  message.items = object.items?.map((e) => MapStartOrContinueItem.fromPartial(e)) || [];
24889
24919
  return message;
24890
24920
  }
24891
24921
  };
24892
24922
  function createBaseMapStartOrContinueResponse() {
24893
- return { functionId: "", functionCallId: "", maxInputsOutstanding: 0, attemptTokens: [], retryPolicy: void 0 };
24923
+ return {
24924
+ mapToken: "",
24925
+ functionId: "",
24926
+ functionCallId: "",
24927
+ maxInputsOutstanding: 0,
24928
+ attemptTokens: [],
24929
+ retryPolicy: void 0
24930
+ };
24894
24931
  }
24895
24932
  var MapStartOrContinueResponse = {
24896
24933
  encode(message, writer = new BinaryWriter()) {
24934
+ if (message.mapToken !== "") {
24935
+ writer.uint32(50).string(message.mapToken);
24936
+ }
24897
24937
  if (message.functionId !== "") {
24898
24938
  writer.uint32(10).string(message.functionId);
24899
24939
  }
@@ -24918,6 +24958,13 @@ var MapStartOrContinueResponse = {
24918
24958
  while (reader.pos < end) {
24919
24959
  const tag = reader.uint32();
24920
24960
  switch (tag >>> 3) {
24961
+ case 6: {
24962
+ if (tag !== 50) {
24963
+ break;
24964
+ }
24965
+ message.mapToken = reader.string();
24966
+ continue;
24967
+ }
24921
24968
  case 1: {
24922
24969
  if (tag !== 10) {
24923
24970
  break;
@@ -24963,6 +25010,7 @@ var MapStartOrContinueResponse = {
24963
25010
  },
24964
25011
  fromJSON(object) {
24965
25012
  return {
25013
+ mapToken: isSet3(object.mapToken) ? globalThis.String(object.mapToken) : "",
24966
25014
  functionId: isSet3(object.functionId) ? globalThis.String(object.functionId) : "",
24967
25015
  functionCallId: isSet3(object.functionCallId) ? globalThis.String(object.functionCallId) : "",
24968
25016
  maxInputsOutstanding: isSet3(object.maxInputsOutstanding) ? globalThis.Number(object.maxInputsOutstanding) : 0,
@@ -24972,6 +25020,9 @@ var MapStartOrContinueResponse = {
24972
25020
  },
24973
25021
  toJSON(message) {
24974
25022
  const obj = {};
25023
+ if (message.mapToken !== "") {
25024
+ obj.mapToken = message.mapToken;
25025
+ }
24975
25026
  if (message.functionId !== "") {
24976
25027
  obj.functionId = message.functionId;
24977
25028
  }
@@ -24994,6 +25045,7 @@ var MapStartOrContinueResponse = {
24994
25045
  },
24995
25046
  fromPartial(object) {
24996
25047
  const message = createBaseMapStartOrContinueResponse();
25048
+ message.mapToken = object.mapToken ?? "";
24997
25049
  message.functionId = object.functionId ?? "";
24998
25050
  message.functionCallId = object.functionCallId ?? "";
24999
25051
  message.maxInputsOutstanding = object.maxInputsOutstanding ?? 0;
@@ -26689,7 +26741,16 @@ var ObjectDependency = {
26689
26741
  }
26690
26742
  };
26691
26743
  function createBasePTYInfo() {
26692
- return { enabled: false, winszRows: 0, winszCols: 0, envTerm: "", envColorterm: "", envTermProgram: "", ptyType: 0 };
26744
+ return {
26745
+ enabled: false,
26746
+ winszRows: 0,
26747
+ winszCols: 0,
26748
+ envTerm: "",
26749
+ envColorterm: "",
26750
+ envTermProgram: "",
26751
+ ptyType: 0,
26752
+ noTerminateOnIdleStdin: false
26753
+ };
26693
26754
  }
26694
26755
  var PTYInfo = {
26695
26756
  encode(message, writer = new BinaryWriter()) {
@@ -26714,6 +26775,9 @@ var PTYInfo = {
26714
26775
  if (message.ptyType !== 0) {
26715
26776
  writer.uint32(56).int32(message.ptyType);
26716
26777
  }
26778
+ if (message.noTerminateOnIdleStdin !== false) {
26779
+ writer.uint32(64).bool(message.noTerminateOnIdleStdin);
26780
+ }
26717
26781
  return writer;
26718
26782
  },
26719
26783
  decode(input, length) {
@@ -26772,6 +26836,13 @@ var PTYInfo = {
26772
26836
  message.ptyType = reader.int32();
26773
26837
  continue;
26774
26838
  }
26839
+ case 8: {
26840
+ if (tag !== 64) {
26841
+ break;
26842
+ }
26843
+ message.noTerminateOnIdleStdin = reader.bool();
26844
+ continue;
26845
+ }
26775
26846
  }
26776
26847
  if ((tag & 7) === 4 || tag === 0) {
26777
26848
  break;
@@ -26788,7 +26859,8 @@ var PTYInfo = {
26788
26859
  envTerm: isSet3(object.envTerm) ? globalThis.String(object.envTerm) : "",
26789
26860
  envColorterm: isSet3(object.envColorterm) ? globalThis.String(object.envColorterm) : "",
26790
26861
  envTermProgram: isSet3(object.envTermProgram) ? globalThis.String(object.envTermProgram) : "",
26791
- ptyType: isSet3(object.ptyType) ? pTYInfo_PTYTypeFromJSON(object.ptyType) : 0
26862
+ ptyType: isSet3(object.ptyType) ? pTYInfo_PTYTypeFromJSON(object.ptyType) : 0,
26863
+ noTerminateOnIdleStdin: isSet3(object.noTerminateOnIdleStdin) ? globalThis.Boolean(object.noTerminateOnIdleStdin) : false
26792
26864
  };
26793
26865
  },
26794
26866
  toJSON(message) {
@@ -26814,6 +26886,9 @@ var PTYInfo = {
26814
26886
  if (message.ptyType !== 0) {
26815
26887
  obj.ptyType = pTYInfo_PTYTypeToJSON(message.ptyType);
26816
26888
  }
26889
+ if (message.noTerminateOnIdleStdin !== false) {
26890
+ obj.noTerminateOnIdleStdin = message.noTerminateOnIdleStdin;
26891
+ }
26817
26892
  return obj;
26818
26893
  },
26819
26894
  create(base) {
@@ -26828,6 +26903,7 @@ var PTYInfo = {
26828
26903
  message.envColorterm = object.envColorterm ?? "";
26829
26904
  message.envTermProgram = object.envTermProgram ?? "";
26830
26905
  message.ptyType = object.ptyType ?? 0;
26906
+ message.noTerminateOnIdleStdin = object.noTerminateOnIdleStdin ?? false;
26831
26907
  return message;
26832
26908
  }
26833
26909
  };
@@ -30324,6 +30400,142 @@ var Sandbox_ExperimentalOptionsEntry = {
30324
30400
  return message;
30325
30401
  }
30326
30402
  };
30403
+ function createBaseSandboxCreateConnectTokenRequest() {
30404
+ return { sandboxId: "", metadata: "" };
30405
+ }
30406
+ var SandboxCreateConnectTokenRequest = {
30407
+ encode(message, writer = new BinaryWriter()) {
30408
+ if (message.sandboxId !== "") {
30409
+ writer.uint32(10).string(message.sandboxId);
30410
+ }
30411
+ if (message.metadata !== "") {
30412
+ writer.uint32(18).string(message.metadata);
30413
+ }
30414
+ return writer;
30415
+ },
30416
+ decode(input, length) {
30417
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
30418
+ let end = length === void 0 ? reader.len : reader.pos + length;
30419
+ const message = createBaseSandboxCreateConnectTokenRequest();
30420
+ while (reader.pos < end) {
30421
+ const tag = reader.uint32();
30422
+ switch (tag >>> 3) {
30423
+ case 1: {
30424
+ if (tag !== 10) {
30425
+ break;
30426
+ }
30427
+ message.sandboxId = reader.string();
30428
+ continue;
30429
+ }
30430
+ case 2: {
30431
+ if (tag !== 18) {
30432
+ break;
30433
+ }
30434
+ message.metadata = reader.string();
30435
+ continue;
30436
+ }
30437
+ }
30438
+ if ((tag & 7) === 4 || tag === 0) {
30439
+ break;
30440
+ }
30441
+ reader.skip(tag & 7);
30442
+ }
30443
+ return message;
30444
+ },
30445
+ fromJSON(object) {
30446
+ return {
30447
+ sandboxId: isSet3(object.sandboxId) ? globalThis.String(object.sandboxId) : "",
30448
+ metadata: isSet3(object.metadata) ? globalThis.String(object.metadata) : ""
30449
+ };
30450
+ },
30451
+ toJSON(message) {
30452
+ const obj = {};
30453
+ if (message.sandboxId !== "") {
30454
+ obj.sandboxId = message.sandboxId;
30455
+ }
30456
+ if (message.metadata !== "") {
30457
+ obj.metadata = message.metadata;
30458
+ }
30459
+ return obj;
30460
+ },
30461
+ create(base) {
30462
+ return SandboxCreateConnectTokenRequest.fromPartial(base ?? {});
30463
+ },
30464
+ fromPartial(object) {
30465
+ const message = createBaseSandboxCreateConnectTokenRequest();
30466
+ message.sandboxId = object.sandboxId ?? "";
30467
+ message.metadata = object.metadata ?? "";
30468
+ return message;
30469
+ }
30470
+ };
30471
+ function createBaseSandboxCreateConnectTokenResponse() {
30472
+ return { url: "", token: "" };
30473
+ }
30474
+ var SandboxCreateConnectTokenResponse = {
30475
+ encode(message, writer = new BinaryWriter()) {
30476
+ if (message.url !== "") {
30477
+ writer.uint32(10).string(message.url);
30478
+ }
30479
+ if (message.token !== "") {
30480
+ writer.uint32(18).string(message.token);
30481
+ }
30482
+ return writer;
30483
+ },
30484
+ decode(input, length) {
30485
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
30486
+ let end = length === void 0 ? reader.len : reader.pos + length;
30487
+ const message = createBaseSandboxCreateConnectTokenResponse();
30488
+ while (reader.pos < end) {
30489
+ const tag = reader.uint32();
30490
+ switch (tag >>> 3) {
30491
+ case 1: {
30492
+ if (tag !== 10) {
30493
+ break;
30494
+ }
30495
+ message.url = reader.string();
30496
+ continue;
30497
+ }
30498
+ case 2: {
30499
+ if (tag !== 18) {
30500
+ break;
30501
+ }
30502
+ message.token = reader.string();
30503
+ continue;
30504
+ }
30505
+ }
30506
+ if ((tag & 7) === 4 || tag === 0) {
30507
+ break;
30508
+ }
30509
+ reader.skip(tag & 7);
30510
+ }
30511
+ return message;
30512
+ },
30513
+ fromJSON(object) {
30514
+ return {
30515
+ url: isSet3(object.url) ? globalThis.String(object.url) : "",
30516
+ token: isSet3(object.token) ? globalThis.String(object.token) : ""
30517
+ };
30518
+ },
30519
+ toJSON(message) {
30520
+ const obj = {};
30521
+ if (message.url !== "") {
30522
+ obj.url = message.url;
30523
+ }
30524
+ if (message.token !== "") {
30525
+ obj.token = message.token;
30526
+ }
30527
+ return obj;
30528
+ },
30529
+ create(base) {
30530
+ return SandboxCreateConnectTokenResponse.fromPartial(base ?? {});
30531
+ },
30532
+ fromPartial(object) {
30533
+ const message = createBaseSandboxCreateConnectTokenResponse();
30534
+ message.url = object.url ?? "";
30535
+ message.token = object.token ?? "";
30536
+ return message;
30537
+ }
30538
+ };
30327
30539
  function createBaseSandboxCreateRequest() {
30328
30540
  return { appId: "", definition: void 0, environmentName: "" };
30329
30541
  }
@@ -40927,6 +41139,14 @@ var ModalClientDefinition = {
40927
41139
  responseStream: false,
40928
41140
  options: {}
40929
41141
  },
41142
+ sandboxCreateConnectToken: {
41143
+ name: "SandboxCreateConnectToken",
41144
+ requestType: SandboxCreateConnectTokenRequest,
41145
+ requestStream: false,
41146
+ responseType: SandboxCreateConnectTokenResponse,
41147
+ responseStream: false,
41148
+ options: {}
41149
+ },
40930
41150
  sandboxGetFromName: {
40931
41151
  name: "SandboxGetFromName",
40932
41152
  requestType: SandboxGetFromNameRequest,
@@ -41772,11 +41992,20 @@ var Image2 = class _Image {
41772
41992
  #imageId;
41773
41993
  #tag;
41774
41994
  #imageRegistryConfig;
41995
+ #layers;
41775
41996
  /** @ignore */
41776
- constructor(imageId, tag, imageRegistryConfig) {
41997
+ constructor(imageId, tag, imageRegistryConfig, layers) {
41777
41998
  this.#imageId = imageId;
41778
41999
  this.#tag = tag;
41779
42000
  this.#imageRegistryConfig = imageRegistryConfig;
42001
+ this.#layers = layers || [
42002
+ {
42003
+ commands: [],
42004
+ secrets: void 0,
42005
+ gpuConfig: void 0,
42006
+ forceBuild: false
42007
+ }
42008
+ ];
41780
42009
  }
41781
42010
  get imageId() {
41782
42011
  return this.#imageId;
@@ -41861,6 +42090,42 @@ var Image2 = class _Image {
41861
42090
  }
41862
42091
  return new _Image("", tag, imageRegistryConfig);
41863
42092
  }
42093
+ static validateDockerfileCommands(commands) {
42094
+ for (const command of commands) {
42095
+ const trimmed = command.trim().toUpperCase();
42096
+ if (trimmed.startsWith("COPY ") && !trimmed.startsWith("COPY --FROM=")) {
42097
+ throw new InvalidError(
42098
+ "COPY commands that copy from local context are not yet supported."
42099
+ );
42100
+ }
42101
+ }
42102
+ }
42103
+ /**
42104
+ * Extend an image with arbitrary Dockerfile-like commands.
42105
+ *
42106
+ * Each call creates a new Image layer that will be built sequentially.
42107
+ * The provided options apply only to this layer.
42108
+ *
42109
+ * @param commands - Array of Dockerfile commands as strings
42110
+ * @param options - Optional configuration for this layer's build
42111
+ * @returns A new Image instance
42112
+ */
42113
+ dockerfileCommands(commands, options) {
42114
+ if (commands.length === 0) {
42115
+ return this;
42116
+ }
42117
+ _Image.validateDockerfileCommands(commands);
42118
+ const newLayer = {
42119
+ commands: [...commands],
42120
+ secrets: options?.secrets,
42121
+ gpuConfig: options?.gpu ? parseGpuConfig(options.gpu) : void 0,
42122
+ forceBuild: options?.forceBuild
42123
+ };
42124
+ return new _Image("", this.#tag, this.#imageRegistryConfig, [
42125
+ ...this.#layers,
42126
+ newLayer
42127
+ ]);
42128
+ }
41864
42129
  /**
41865
42130
  * Eagerly builds an Image on Modal.
41866
42131
  *
@@ -41870,58 +42135,75 @@ var Image2 = class _Image {
41870
42135
  if (this.imageId !== "") {
41871
42136
  return this;
41872
42137
  }
41873
- const resp = await client.imageGetOrCreate({
41874
- appId: app.appId,
41875
- image: {
41876
- dockerfileCommands: [`FROM ${this.#tag}`],
41877
- imageRegistryConfig: this.#imageRegistryConfig
41878
- },
41879
- builderVersion: imageBuilderVersion()
41880
- });
41881
- let result;
41882
- let metadata = void 0;
41883
- if (resp.result?.status) {
41884
- result = resp.result;
41885
- metadata = resp.metadata;
41886
- } else {
41887
- let lastEntryId = "";
41888
- let resultJoined = void 0;
41889
- while (!resultJoined) {
41890
- for await (const item of client.imageJoinStreaming({
41891
- imageId: resp.imageId,
41892
- timeout: 55,
41893
- lastEntryId
41894
- })) {
41895
- if (item.entryId) lastEntryId = item.entryId;
41896
- if (item.result?.status) {
41897
- resultJoined = item.result;
41898
- metadata = item.metadata;
41899
- break;
42138
+ let baseImageId;
42139
+ for (let i = 0; i < this.#layers.length; i++) {
42140
+ const layer = this.#layers[i];
42141
+ const secretIds = layer.secrets?.map((secret) => secret.secretId) || [];
42142
+ const gpuConfig = layer.gpuConfig;
42143
+ let dockerfileCommands;
42144
+ let baseImages;
42145
+ if (i === 0) {
42146
+ dockerfileCommands = [`FROM ${this.#tag}`, ...layer.commands];
42147
+ baseImages = [];
42148
+ } else {
42149
+ dockerfileCommands = ["FROM base", ...layer.commands];
42150
+ baseImages = [{ dockerTag: "base", imageId: baseImageId }];
42151
+ }
42152
+ const resp = await client.imageGetOrCreate({
42153
+ appId: app.appId,
42154
+ image: Image.create({
42155
+ dockerfileCommands,
42156
+ imageRegistryConfig: this.#imageRegistryConfig,
42157
+ secretIds,
42158
+ gpuConfig,
42159
+ contextFiles: [],
42160
+ baseImages
42161
+ }),
42162
+ builderVersion: imageBuilderVersion(),
42163
+ forceBuild: layer.forceBuild || false
42164
+ });
42165
+ let result;
42166
+ if (resp.result?.status) {
42167
+ result = resp.result;
42168
+ } else {
42169
+ let lastEntryId = "";
42170
+ let resultJoined = void 0;
42171
+ while (!resultJoined) {
42172
+ for await (const item of client.imageJoinStreaming({
42173
+ imageId: resp.imageId,
42174
+ timeout: 55,
42175
+ lastEntryId
42176
+ })) {
42177
+ if (item.entryId) lastEntryId = item.entryId;
42178
+ if (item.result?.status) {
42179
+ resultJoined = item.result;
42180
+ break;
42181
+ }
41900
42182
  }
41901
42183
  }
42184
+ result = resultJoined;
41902
42185
  }
41903
- result = resultJoined;
41904
- }
41905
- void metadata;
41906
- if (result.status === 2 /* GENERIC_STATUS_FAILURE */) {
41907
- throw new Error(
41908
- `Image build for ${resp.imageId} failed with the exception:
42186
+ if (result.status === 2 /* GENERIC_STATUS_FAILURE */) {
42187
+ throw new Error(
42188
+ `Image build for ${resp.imageId} failed with the exception:
41909
42189
  ${result.exception}`
41910
- );
41911
- } else if (result.status === 3 /* GENERIC_STATUS_TERMINATED */) {
41912
- throw new Error(
41913
- `Image build for ${resp.imageId} terminated due to external shut-down. Please try again.`
41914
- );
41915
- } else if (result.status === 4 /* GENERIC_STATUS_TIMEOUT */) {
41916
- throw new Error(
41917
- `Image build for ${resp.imageId} timed out. Please try again with a larger timeout parameter.`
41918
- );
41919
- } else if (result.status !== 1 /* GENERIC_STATUS_SUCCESS */) {
41920
- throw new Error(
41921
- `Image build for ${resp.imageId} failed with unknown status: ${result.status}`
41922
- );
42190
+ );
42191
+ } else if (result.status === 3 /* GENERIC_STATUS_TERMINATED */) {
42192
+ throw new Error(
42193
+ `Image build for ${resp.imageId} terminated due to external shut-down. Please try again.`
42194
+ );
42195
+ } else if (result.status === 4 /* GENERIC_STATUS_TIMEOUT */) {
42196
+ throw new Error(
42197
+ `Image build for ${resp.imageId} timed out. Please try again with a larger timeout parameter.`
42198
+ );
42199
+ } else if (result.status !== 1 /* GENERIC_STATUS_SUCCESS */) {
42200
+ throw new Error(
42201
+ `Image build for ${resp.imageId} failed with unknown status: ${result.status}`
42202
+ );
42203
+ }
42204
+ baseImageId = resp.imageId;
41923
42205
  }
41924
- this.#imageId = resp.imageId;
42206
+ this.#imageId = baseImageId;
41925
42207
  return this;
41926
42208
  }
41927
42209
  /** Delete an Image by ID. Warning: This removes an *entire Image*, and cannot be undone. */
@@ -42175,6 +42457,33 @@ var Tunnel = class {
42175
42457
  return [this.unencryptedHost, this.unencryptedPort];
42176
42458
  }
42177
42459
  };
42460
+ function defaultSandboxPTYInfo() {
42461
+ return PTYInfo.create({
42462
+ enabled: true,
42463
+ winszRows: 24,
42464
+ winszCols: 80,
42465
+ envTerm: "xterm-256color",
42466
+ envColorterm: "truecolor",
42467
+ envTermProgram: "",
42468
+ ptyType: 2 /* PTY_TYPE_SHELL */,
42469
+ noTerminateOnIdleStdin: true
42470
+ });
42471
+ }
42472
+ function containerExecRequestProto(taskId, command, options) {
42473
+ const secretIds = options?.secrets ? options.secrets.map((secret) => secret.secretId) : [];
42474
+ let ptyInfo;
42475
+ if (options?.pty) {
42476
+ ptyInfo = defaultSandboxPTYInfo();
42477
+ }
42478
+ return ContainerExecRequest.create({
42479
+ taskId,
42480
+ command,
42481
+ workdir: options?.workdir,
42482
+ timeoutSecs: options?.timeout ? options.timeout / 1e3 : 0,
42483
+ secretIds,
42484
+ ptyInfo
42485
+ });
42486
+ }
42178
42487
  var Sandbox2 = class _Sandbox {
42179
42488
  sandboxId;
42180
42489
  stdin;
@@ -42279,14 +42588,8 @@ var Sandbox2 = class _Sandbox {
42279
42588
  }
42280
42589
  async exec(command, options) {
42281
42590
  const taskId = await this.#getTaskId();
42282
- const secretIds = options?.secrets ? options.secrets.map((secret) => secret.secretId) : [];
42283
- const resp = await client.containerExec({
42284
- taskId,
42285
- command,
42286
- workdir: options?.workdir,
42287
- timeoutSecs: options?.timeout ? options.timeout / 1e3 : 0,
42288
- secretIds
42289
- });
42591
+ const req = containerExecRequestProto(taskId, command, options);
42592
+ const resp = await client.containerExec(req);
42290
42593
  return new ContainerProcess(resp.execId, options);
42291
42594
  }
42292
42595
  async #getTaskId() {
@@ -42673,7 +42976,118 @@ function parseGpuConfig(gpu) {
42673
42976
  gpuType: gpuType.toUpperCase()
42674
42977
  };
42675
42978
  }
42676
- var App = class _App {
42979
+ function sandboxCreateRequestProto(appId, imageId, options = {}) {
42980
+ const gpuConfig = parseGpuConfig(options.gpu);
42981
+ if (options.timeout && options.timeout % 1e3 !== 0) {
42982
+ throw new Error(
42983
+ `timeout must be a multiple of 1000ms, got ${options.timeout}`
42984
+ );
42985
+ }
42986
+ if (options.idleTimeout && options.idleTimeout % 1e3 !== 0) {
42987
+ throw new Error(
42988
+ `idleTimeout must be a multiple of 1000ms, got ${options.idleTimeout}`
42989
+ );
42990
+ }
42991
+ if (options.workdir && !options.workdir.startsWith("/")) {
42992
+ throw new Error(
42993
+ `workdir must be an absolute path, got: ${options.workdir}`
42994
+ );
42995
+ }
42996
+ const volumeMounts = options.volumes ? Object.entries(options.volumes).map(([mountPath, volume]) => ({
42997
+ volumeId: volume.volumeId,
42998
+ mountPath,
42999
+ allowBackgroundCommits: true,
43000
+ readOnly: volume.isReadOnly
43001
+ })) : [];
43002
+ const cloudBucketMounts = options.cloudBucketMounts ? Object.entries(options.cloudBucketMounts).map(
43003
+ ([mountPath, mount]) => cloudBucketMountToProto(mount, mountPath)
43004
+ ) : [];
43005
+ const openPorts = [];
43006
+ if (options.encryptedPorts) {
43007
+ openPorts.push(
43008
+ ...options.encryptedPorts.map((port) => ({
43009
+ port,
43010
+ unencrypted: false
43011
+ }))
43012
+ );
43013
+ }
43014
+ if (options.h2Ports) {
43015
+ openPorts.push(
43016
+ ...options.h2Ports.map((port) => ({
43017
+ port,
43018
+ unencrypted: false,
43019
+ tunnelType: 1 /* TUNNEL_TYPE_H2 */
43020
+ }))
43021
+ );
43022
+ }
43023
+ if (options.unencryptedPorts) {
43024
+ openPorts.push(
43025
+ ...options.unencryptedPorts.map((port) => ({
43026
+ port,
43027
+ unencrypted: true
43028
+ }))
43029
+ );
43030
+ }
43031
+ const secretIds = options.secrets ? options.secrets.map((secret) => secret.secretId) : [];
43032
+ let networkAccess;
43033
+ if (options.blockNetwork) {
43034
+ if (options.cidrAllowlist) {
43035
+ throw new Error(
43036
+ "cidrAllowlist cannot be used when blockNetwork is enabled"
43037
+ );
43038
+ }
43039
+ networkAccess = {
43040
+ networkAccessType: 2 /* BLOCKED */,
43041
+ allowedCidrs: []
43042
+ };
43043
+ } else if (options.cidrAllowlist) {
43044
+ networkAccess = {
43045
+ networkAccessType: 3 /* ALLOWLIST */,
43046
+ allowedCidrs: options.cidrAllowlist
43047
+ };
43048
+ } else {
43049
+ networkAccess = {
43050
+ networkAccessType: 1 /* OPEN */,
43051
+ allowedCidrs: []
43052
+ };
43053
+ }
43054
+ const schedulerPlacement = SchedulerPlacement.create({
43055
+ regions: options.regions ?? []
43056
+ });
43057
+ let ptyInfo;
43058
+ if (options.pty) {
43059
+ ptyInfo = defaultSandboxPTYInfo();
43060
+ }
43061
+ return SandboxCreateRequest.create({
43062
+ appId,
43063
+ definition: {
43064
+ // Sleep default is implicit in image builder version <=2024.10
43065
+ entrypointArgs: options.command ?? ["sleep", "48h"],
43066
+ imageId,
43067
+ timeoutSecs: options.timeout != void 0 ? options.timeout / 1e3 : 600,
43068
+ idleTimeoutSecs: options.idleTimeout != void 0 ? options.idleTimeout / 1e3 : void 0,
43069
+ workdir: options.workdir ?? void 0,
43070
+ networkAccess,
43071
+ resources: {
43072
+ // https://modal.com/docs/guide/resources
43073
+ milliCpu: Math.round(1e3 * (options.cpu ?? 0.125)),
43074
+ memoryMb: options.memory ?? 128,
43075
+ gpuConfig
43076
+ },
43077
+ volumeMounts,
43078
+ cloudBucketMounts,
43079
+ ptyInfo,
43080
+ secretIds,
43081
+ openPorts: openPorts.length > 0 ? { ports: openPorts } : void 0,
43082
+ cloudProviderStr: options.cloud ?? "",
43083
+ schedulerPlacement,
43084
+ verbose: options.verbose ?? false,
43085
+ proxyId: options.proxy?.proxyId,
43086
+ name: options.name
43087
+ }
43088
+ });
43089
+ }
43090
+ var App2 = class _App {
42677
43091
  appId;
42678
43092
  name;
42679
43093
  /** @ignore */
@@ -42697,113 +43111,15 @@ var App = class _App {
42697
43111
  }
42698
43112
  }
42699
43113
  async createSandbox(image, options = {}) {
42700
- const gpuConfig = parseGpuConfig(options.gpu);
42701
- if (options.timeout && options.timeout % 1e3 !== 0) {
42702
- throw new Error(
42703
- `timeout must be a multiple of 1000ms, got ${options.timeout}`
42704
- );
42705
- }
42706
- if (options.idleTimeout && options.idleTimeout % 1e3 !== 0) {
42707
- throw new Error(
42708
- `idleTimeout must be a multiple of 1000ms, got ${options.idleTimeout}`
42709
- );
42710
- }
42711
43114
  await image.build(this);
42712
- if (options.workdir && !options.workdir.startsWith("/")) {
42713
- throw new Error(
42714
- `workdir must be an absolute path, got: ${options.workdir}`
42715
- );
42716
- }
42717
- const volumeMounts = options.volumes ? Object.entries(options.volumes).map(([mountPath, volume]) => ({
42718
- volumeId: volume.volumeId,
42719
- mountPath,
42720
- allowBackgroundCommits: true,
42721
- readOnly: volume.isReadOnly
42722
- })) : [];
42723
- const cloudBucketMounts = options.cloudBucketMounts ? Object.entries(options.cloudBucketMounts).map(
42724
- ([mountPath, mount]) => cloudBucketMountToProto(mount, mountPath)
42725
- ) : [];
42726
- const openPorts = [];
42727
- if (options.encryptedPorts) {
42728
- openPorts.push(
42729
- ...options.encryptedPorts.map((port) => ({
42730
- port,
42731
- unencrypted: false
42732
- }))
42733
- );
42734
- }
42735
- if (options.h2Ports) {
42736
- openPorts.push(
42737
- ...options.h2Ports.map((port) => ({
42738
- port,
42739
- unencrypted: false,
42740
- tunnelType: 1 /* TUNNEL_TYPE_H2 */
42741
- }))
42742
- );
42743
- }
42744
- if (options.unencryptedPorts) {
42745
- openPorts.push(
42746
- ...options.unencryptedPorts.map((port) => ({
42747
- port,
42748
- unencrypted: true
42749
- }))
42750
- );
42751
- }
42752
- const secretIds = options.secrets ? options.secrets.map((secret) => secret.secretId) : [];
42753
- let networkAccess;
42754
- if (options.blockNetwork) {
42755
- if (options.cidrAllowlist) {
42756
- throw new Error(
42757
- "cidrAllowlist cannot be used when blockNetwork is enabled"
42758
- );
42759
- }
42760
- networkAccess = {
42761
- networkAccessType: 2 /* BLOCKED */,
42762
- allowedCidrs: []
42763
- };
42764
- } else if (options.cidrAllowlist) {
42765
- networkAccess = {
42766
- networkAccessType: 3 /* ALLOWLIST */,
42767
- allowedCidrs: options.cidrAllowlist
42768
- };
42769
- } else {
42770
- networkAccess = {
42771
- networkAccessType: 1 /* OPEN */,
42772
- allowedCidrs: []
42773
- };
42774
- }
42775
- const schedulerPlacement = SchedulerPlacement.create({
42776
- regions: options.regions ?? []
42777
- });
43115
+ const createReq = sandboxCreateRequestProto(
43116
+ this.appId,
43117
+ image.imageId,
43118
+ options
43119
+ );
42778
43120
  let createResp;
42779
43121
  try {
42780
- createResp = await client.sandboxCreate({
42781
- appId: this.appId,
42782
- definition: {
42783
- // Sleep default is implicit in image builder version <=2024.10
42784
- entrypointArgs: options.command ?? ["sleep", "48h"],
42785
- imageId: image.imageId,
42786
- timeoutSecs: options.timeout != void 0 ? options.timeout / 1e3 : 600,
42787
- idleTimeoutSecs: options.idleTimeout != void 0 ? options.idleTimeout / 1e3 : void 0,
42788
- workdir: options.workdir ?? void 0,
42789
- networkAccess,
42790
- resources: {
42791
- // https://modal.com/docs/guide/resources
42792
- milliCpu: Math.round(1e3 * (options.cpu ?? 0.125)),
42793
- memoryMb: options.memory ?? 128,
42794
- gpuConfig
42795
- },
42796
- volumeMounts,
42797
- cloudBucketMounts,
42798
- secretIds,
42799
- openPorts: openPorts.length > 0 ? { ports: openPorts } : void 0,
42800
- cloudProviderStr: options.cloud ?? "",
42801
- schedulerPlacement,
42802
- verbose: options.verbose ?? false,
42803
- proxyId: options.proxy?.proxyId,
42804
- name: options.name
42805
- }
42806
- });
43122
+ createResp = await client.sandboxCreate(createReq);
42807
43123
  } catch (err) {
42808
43124
  if (err instanceof import_nice_grpc6.ClientError && err.code === import_nice_grpc6.Status.ALREADY_EXISTS) {
42809
43125
  throw new AlreadyExistsError(err.details || err.message);