modal 0.7.5 → 0.7.6

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
@@ -62,6 +62,15 @@ __export(index_exports, {
62
62
  Retries: () => Retries,
63
63
  Sandbox: () => Sandbox2,
64
64
  SandboxFile: () => SandboxFile,
65
+ SandboxFilesystem: () => SandboxFilesystem,
66
+ SandboxFilesystemDirectoryNotEmptyError: () => SandboxFilesystemDirectoryNotEmptyError,
67
+ SandboxFilesystemError: () => SandboxFilesystemError,
68
+ SandboxFilesystemFileTooLargeError: () => SandboxFilesystemFileTooLargeError,
69
+ SandboxFilesystemIsADirectoryError: () => SandboxFilesystemIsADirectoryError,
70
+ SandboxFilesystemNotADirectoryError: () => SandboxFilesystemNotADirectoryError,
71
+ SandboxFilesystemNotFoundError: () => SandboxFilesystemNotFoundError,
72
+ SandboxFilesystemPathAlreadyExistsError: () => SandboxFilesystemPathAlreadyExistsError,
73
+ SandboxFilesystemPermissionError: () => SandboxFilesystemPermissionError,
65
74
  SandboxService: () => SandboxService,
66
75
  SandboxTimeoutError: () => SandboxTimeoutError,
67
76
  Secret: () => Secret,
@@ -76,7 +85,7 @@ __export(index_exports, {
76
85
  module.exports = __toCommonJS(index_exports);
77
86
 
78
87
  // src/app.ts
79
- var import_nice_grpc12 = require("nice-grpc");
88
+ var import_nice_grpc14 = require("nice-grpc");
80
89
 
81
90
  // node_modules/@bufbuild/protobuf/dist/esm/wire/varint.js
82
91
  function varint64read() {
@@ -1954,6 +1963,36 @@ function endpointInputModalityToJSON(object) {
1954
1963
  return "UNRECOGNIZED";
1955
1964
  }
1956
1965
  }
1966
+ function endpointStopSourceFromJSON(object) {
1967
+ switch (object) {
1968
+ case 0:
1969
+ case "ENDPOINT_STOP_SOURCE_UNSPECIFIED":
1970
+ return 0 /* ENDPOINT_STOP_SOURCE_UNSPECIFIED */;
1971
+ case 1:
1972
+ case "ENDPOINT_STOP_SOURCE_CLI":
1973
+ return 1 /* ENDPOINT_STOP_SOURCE_CLI */;
1974
+ case 2:
1975
+ case "ENDPOINT_STOP_SOURCE_WEB":
1976
+ return 2 /* ENDPOINT_STOP_SOURCE_WEB */;
1977
+ case -1:
1978
+ case "UNRECOGNIZED":
1979
+ default:
1980
+ return -1 /* UNRECOGNIZED */;
1981
+ }
1982
+ }
1983
+ function endpointStopSourceToJSON(object) {
1984
+ switch (object) {
1985
+ case 0 /* ENDPOINT_STOP_SOURCE_UNSPECIFIED */:
1986
+ return "ENDPOINT_STOP_SOURCE_UNSPECIFIED";
1987
+ case 1 /* ENDPOINT_STOP_SOURCE_CLI */:
1988
+ return "ENDPOINT_STOP_SOURCE_CLI";
1989
+ case 2 /* ENDPOINT_STOP_SOURCE_WEB */:
1990
+ return "ENDPOINT_STOP_SOURCE_WEB";
1991
+ case -1 /* UNRECOGNIZED */:
1992
+ default:
1993
+ return "UNRECOGNIZED";
1994
+ }
1995
+ }
1957
1996
  function environmentRoleFromJSON(object) {
1958
1997
  switch (object) {
1959
1998
  case 0:
@@ -16156,6 +16195,338 @@ var EndpointHuggingFaceModelSource = {
16156
16195
  return message;
16157
16196
  }
16158
16197
  };
16198
+ function createBaseEndpointListItem() {
16199
+ return { endpointId: "", name: "", description: "", activeDeploymentId: "", updatedAt: 0, metadata: void 0 };
16200
+ }
16201
+ var EndpointListItem = {
16202
+ encode(message, writer = new BinaryWriter()) {
16203
+ if (message.endpointId !== "") {
16204
+ writer.uint32(10).string(message.endpointId);
16205
+ }
16206
+ if (message.name !== "") {
16207
+ writer.uint32(18).string(message.name);
16208
+ }
16209
+ if (message.description !== "") {
16210
+ writer.uint32(26).string(message.description);
16211
+ }
16212
+ if (message.activeDeploymentId !== "") {
16213
+ writer.uint32(34).string(message.activeDeploymentId);
16214
+ }
16215
+ if (message.updatedAt !== 0) {
16216
+ writer.uint32(41).double(message.updatedAt);
16217
+ }
16218
+ if (message.metadata !== void 0) {
16219
+ EndpointMetadata.encode(message.metadata, writer.uint32(50).fork()).join();
16220
+ }
16221
+ return writer;
16222
+ },
16223
+ decode(input, length) {
16224
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16225
+ let end = length === void 0 ? reader.len : reader.pos + length;
16226
+ const message = createBaseEndpointListItem();
16227
+ while (reader.pos < end) {
16228
+ const tag = reader.uint32();
16229
+ switch (tag >>> 3) {
16230
+ case 1: {
16231
+ if (tag !== 10) {
16232
+ break;
16233
+ }
16234
+ message.endpointId = reader.string();
16235
+ continue;
16236
+ }
16237
+ case 2: {
16238
+ if (tag !== 18) {
16239
+ break;
16240
+ }
16241
+ message.name = reader.string();
16242
+ continue;
16243
+ }
16244
+ case 3: {
16245
+ if (tag !== 26) {
16246
+ break;
16247
+ }
16248
+ message.description = reader.string();
16249
+ continue;
16250
+ }
16251
+ case 4: {
16252
+ if (tag !== 34) {
16253
+ break;
16254
+ }
16255
+ message.activeDeploymentId = reader.string();
16256
+ continue;
16257
+ }
16258
+ case 5: {
16259
+ if (tag !== 41) {
16260
+ break;
16261
+ }
16262
+ message.updatedAt = reader.double();
16263
+ continue;
16264
+ }
16265
+ case 6: {
16266
+ if (tag !== 50) {
16267
+ break;
16268
+ }
16269
+ message.metadata = EndpointMetadata.decode(reader, reader.uint32());
16270
+ continue;
16271
+ }
16272
+ }
16273
+ if ((tag & 7) === 4 || tag === 0) {
16274
+ break;
16275
+ }
16276
+ reader.skip(tag & 7);
16277
+ }
16278
+ return message;
16279
+ },
16280
+ fromJSON(object) {
16281
+ return {
16282
+ endpointId: isSet5(object.endpointId) ? globalThis.String(object.endpointId) : "",
16283
+ name: isSet5(object.name) ? globalThis.String(object.name) : "",
16284
+ description: isSet5(object.description) ? globalThis.String(object.description) : "",
16285
+ activeDeploymentId: isSet5(object.activeDeploymentId) ? globalThis.String(object.activeDeploymentId) : "",
16286
+ updatedAt: isSet5(object.updatedAt) ? globalThis.Number(object.updatedAt) : 0,
16287
+ metadata: isSet5(object.metadata) ? EndpointMetadata.fromJSON(object.metadata) : void 0
16288
+ };
16289
+ },
16290
+ toJSON(message) {
16291
+ const obj = {};
16292
+ if (message.endpointId !== "") {
16293
+ obj.endpointId = message.endpointId;
16294
+ }
16295
+ if (message.name !== "") {
16296
+ obj.name = message.name;
16297
+ }
16298
+ if (message.description !== "") {
16299
+ obj.description = message.description;
16300
+ }
16301
+ if (message.activeDeploymentId !== "") {
16302
+ obj.activeDeploymentId = message.activeDeploymentId;
16303
+ }
16304
+ if (message.updatedAt !== 0) {
16305
+ obj.updatedAt = message.updatedAt;
16306
+ }
16307
+ if (message.metadata !== void 0) {
16308
+ obj.metadata = EndpointMetadata.toJSON(message.metadata);
16309
+ }
16310
+ return obj;
16311
+ },
16312
+ create(base) {
16313
+ return EndpointListItem.fromPartial(base ?? {});
16314
+ },
16315
+ fromPartial(object) {
16316
+ const message = createBaseEndpointListItem();
16317
+ message.endpointId = object.endpointId ?? "";
16318
+ message.name = object.name ?? "";
16319
+ message.description = object.description ?? "";
16320
+ message.activeDeploymentId = object.activeDeploymentId ?? "";
16321
+ message.updatedAt = object.updatedAt ?? 0;
16322
+ message.metadata = object.metadata !== void 0 && object.metadata !== null ? EndpointMetadata.fromPartial(object.metadata) : void 0;
16323
+ return message;
16324
+ }
16325
+ };
16326
+ function createBaseEndpointListRequest() {
16327
+ return { environmentName: "", pagination: void 0 };
16328
+ }
16329
+ var EndpointListRequest = {
16330
+ encode(message, writer = new BinaryWriter()) {
16331
+ if (message.environmentName !== "") {
16332
+ writer.uint32(10).string(message.environmentName);
16333
+ }
16334
+ if (message.pagination !== void 0) {
16335
+ ListPagination.encode(message.pagination, writer.uint32(18).fork()).join();
16336
+ }
16337
+ return writer;
16338
+ },
16339
+ decode(input, length) {
16340
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16341
+ let end = length === void 0 ? reader.len : reader.pos + length;
16342
+ const message = createBaseEndpointListRequest();
16343
+ while (reader.pos < end) {
16344
+ const tag = reader.uint32();
16345
+ switch (tag >>> 3) {
16346
+ case 1: {
16347
+ if (tag !== 10) {
16348
+ break;
16349
+ }
16350
+ message.environmentName = reader.string();
16351
+ continue;
16352
+ }
16353
+ case 2: {
16354
+ if (tag !== 18) {
16355
+ break;
16356
+ }
16357
+ message.pagination = ListPagination.decode(reader, reader.uint32());
16358
+ continue;
16359
+ }
16360
+ }
16361
+ if ((tag & 7) === 4 || tag === 0) {
16362
+ break;
16363
+ }
16364
+ reader.skip(tag & 7);
16365
+ }
16366
+ return message;
16367
+ },
16368
+ fromJSON(object) {
16369
+ return {
16370
+ environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : "",
16371
+ pagination: isSet5(object.pagination) ? ListPagination.fromJSON(object.pagination) : void 0
16372
+ };
16373
+ },
16374
+ toJSON(message) {
16375
+ const obj = {};
16376
+ if (message.environmentName !== "") {
16377
+ obj.environmentName = message.environmentName;
16378
+ }
16379
+ if (message.pagination !== void 0) {
16380
+ obj.pagination = ListPagination.toJSON(message.pagination);
16381
+ }
16382
+ return obj;
16383
+ },
16384
+ create(base) {
16385
+ return EndpointListRequest.fromPartial(base ?? {});
16386
+ },
16387
+ fromPartial(object) {
16388
+ const message = createBaseEndpointListRequest();
16389
+ message.environmentName = object.environmentName ?? "";
16390
+ message.pagination = object.pagination !== void 0 && object.pagination !== null ? ListPagination.fromPartial(object.pagination) : void 0;
16391
+ return message;
16392
+ }
16393
+ };
16394
+ function createBaseEndpointListResponse() {
16395
+ return { items: [], environmentName: "" };
16396
+ }
16397
+ var EndpointListResponse = {
16398
+ encode(message, writer = new BinaryWriter()) {
16399
+ for (const v of message.items) {
16400
+ EndpointListItem.encode(v, writer.uint32(10).fork()).join();
16401
+ }
16402
+ if (message.environmentName !== "") {
16403
+ writer.uint32(18).string(message.environmentName);
16404
+ }
16405
+ return writer;
16406
+ },
16407
+ decode(input, length) {
16408
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16409
+ let end = length === void 0 ? reader.len : reader.pos + length;
16410
+ const message = createBaseEndpointListResponse();
16411
+ while (reader.pos < end) {
16412
+ const tag = reader.uint32();
16413
+ switch (tag >>> 3) {
16414
+ case 1: {
16415
+ if (tag !== 10) {
16416
+ break;
16417
+ }
16418
+ message.items.push(EndpointListItem.decode(reader, reader.uint32()));
16419
+ continue;
16420
+ }
16421
+ case 2: {
16422
+ if (tag !== 18) {
16423
+ break;
16424
+ }
16425
+ message.environmentName = reader.string();
16426
+ continue;
16427
+ }
16428
+ }
16429
+ if ((tag & 7) === 4 || tag === 0) {
16430
+ break;
16431
+ }
16432
+ reader.skip(tag & 7);
16433
+ }
16434
+ return message;
16435
+ },
16436
+ fromJSON(object) {
16437
+ return {
16438
+ items: globalThis.Array.isArray(object?.items) ? object.items.map((e) => EndpointListItem.fromJSON(e)) : [],
16439
+ environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : ""
16440
+ };
16441
+ },
16442
+ toJSON(message) {
16443
+ const obj = {};
16444
+ if (message.items?.length) {
16445
+ obj.items = message.items.map((e) => EndpointListItem.toJSON(e));
16446
+ }
16447
+ if (message.environmentName !== "") {
16448
+ obj.environmentName = message.environmentName;
16449
+ }
16450
+ return obj;
16451
+ },
16452
+ create(base) {
16453
+ return EndpointListResponse.fromPartial(base ?? {});
16454
+ },
16455
+ fromPartial(object) {
16456
+ const message = createBaseEndpointListResponse();
16457
+ message.items = object.items?.map((e) => EndpointListItem.fromPartial(e)) || [];
16458
+ message.environmentName = object.environmentName ?? "";
16459
+ return message;
16460
+ }
16461
+ };
16462
+ function createBaseEndpointMetadata() {
16463
+ return { name: "", creationInfo: void 0 };
16464
+ }
16465
+ var EndpointMetadata = {
16466
+ encode(message, writer = new BinaryWriter()) {
16467
+ if (message.name !== "") {
16468
+ writer.uint32(10).string(message.name);
16469
+ }
16470
+ if (message.creationInfo !== void 0) {
16471
+ CreationInfo.encode(message.creationInfo, writer.uint32(18).fork()).join();
16472
+ }
16473
+ return writer;
16474
+ },
16475
+ decode(input, length) {
16476
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16477
+ let end = length === void 0 ? reader.len : reader.pos + length;
16478
+ const message = createBaseEndpointMetadata();
16479
+ while (reader.pos < end) {
16480
+ const tag = reader.uint32();
16481
+ switch (tag >>> 3) {
16482
+ case 1: {
16483
+ if (tag !== 10) {
16484
+ break;
16485
+ }
16486
+ message.name = reader.string();
16487
+ continue;
16488
+ }
16489
+ case 2: {
16490
+ if (tag !== 18) {
16491
+ break;
16492
+ }
16493
+ message.creationInfo = CreationInfo.decode(reader, reader.uint32());
16494
+ continue;
16495
+ }
16496
+ }
16497
+ if ((tag & 7) === 4 || tag === 0) {
16498
+ break;
16499
+ }
16500
+ reader.skip(tag & 7);
16501
+ }
16502
+ return message;
16503
+ },
16504
+ fromJSON(object) {
16505
+ return {
16506
+ name: isSet5(object.name) ? globalThis.String(object.name) : "",
16507
+ creationInfo: isSet5(object.creationInfo) ? CreationInfo.fromJSON(object.creationInfo) : void 0
16508
+ };
16509
+ },
16510
+ toJSON(message) {
16511
+ const obj = {};
16512
+ if (message.name !== "") {
16513
+ obj.name = message.name;
16514
+ }
16515
+ if (message.creationInfo !== void 0) {
16516
+ obj.creationInfo = CreationInfo.toJSON(message.creationInfo);
16517
+ }
16518
+ return obj;
16519
+ },
16520
+ create(base) {
16521
+ return EndpointMetadata.fromPartial(base ?? {});
16522
+ },
16523
+ fromPartial(object) {
16524
+ const message = createBaseEndpointMetadata();
16525
+ message.name = object.name ?? "";
16526
+ message.creationInfo = object.creationInfo !== void 0 && object.creationInfo !== null ? CreationInfo.fromPartial(object.creationInfo) : void 0;
16527
+ return message;
16528
+ }
16529
+ };
16159
16530
  function createBaseEndpointModalVolumeModelSource() {
16160
16531
  return { volumeId: "", modelPath: "" };
16161
16532
  }
@@ -16292,6 +16663,111 @@ var EndpointModelSource = {
16292
16663
  return message;
16293
16664
  }
16294
16665
  };
16666
+ function createBaseEndpointStopRequest() {
16667
+ return { endpointId: "", source: 0 };
16668
+ }
16669
+ var EndpointStopRequest = {
16670
+ encode(message, writer = new BinaryWriter()) {
16671
+ if (message.endpointId !== "") {
16672
+ writer.uint32(10).string(message.endpointId);
16673
+ }
16674
+ if (message.source !== 0) {
16675
+ writer.uint32(16).int32(message.source);
16676
+ }
16677
+ return writer;
16678
+ },
16679
+ decode(input, length) {
16680
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16681
+ let end = length === void 0 ? reader.len : reader.pos + length;
16682
+ const message = createBaseEndpointStopRequest();
16683
+ while (reader.pos < end) {
16684
+ const tag = reader.uint32();
16685
+ switch (tag >>> 3) {
16686
+ case 1: {
16687
+ if (tag !== 10) {
16688
+ break;
16689
+ }
16690
+ message.endpointId = reader.string();
16691
+ continue;
16692
+ }
16693
+ case 2: {
16694
+ if (tag !== 16) {
16695
+ break;
16696
+ }
16697
+ message.source = reader.int32();
16698
+ continue;
16699
+ }
16700
+ }
16701
+ if ((tag & 7) === 4 || tag === 0) {
16702
+ break;
16703
+ }
16704
+ reader.skip(tag & 7);
16705
+ }
16706
+ return message;
16707
+ },
16708
+ fromJSON(object) {
16709
+ return {
16710
+ endpointId: isSet5(object.endpointId) ? globalThis.String(object.endpointId) : "",
16711
+ source: isSet5(object.source) ? endpointStopSourceFromJSON(object.source) : 0
16712
+ };
16713
+ },
16714
+ toJSON(message) {
16715
+ const obj = {};
16716
+ if (message.endpointId !== "") {
16717
+ obj.endpointId = message.endpointId;
16718
+ }
16719
+ if (message.source !== 0) {
16720
+ obj.source = endpointStopSourceToJSON(message.source);
16721
+ }
16722
+ return obj;
16723
+ },
16724
+ create(base) {
16725
+ return EndpointStopRequest.fromPartial(base ?? {});
16726
+ },
16727
+ fromPartial(object) {
16728
+ const message = createBaseEndpointStopRequest();
16729
+ message.endpointId = object.endpointId ?? "";
16730
+ message.source = object.source ?? 0;
16731
+ return message;
16732
+ }
16733
+ };
16734
+ function createBaseEndpointStopResponse() {
16735
+ return {};
16736
+ }
16737
+ var EndpointStopResponse = {
16738
+ encode(_, writer = new BinaryWriter()) {
16739
+ return writer;
16740
+ },
16741
+ decode(input, length) {
16742
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16743
+ let end = length === void 0 ? reader.len : reader.pos + length;
16744
+ const message = createBaseEndpointStopResponse();
16745
+ while (reader.pos < end) {
16746
+ const tag = reader.uint32();
16747
+ switch (tag >>> 3) {
16748
+ }
16749
+ if ((tag & 7) === 4 || tag === 0) {
16750
+ break;
16751
+ }
16752
+ reader.skip(tag & 7);
16753
+ }
16754
+ return message;
16755
+ },
16756
+ fromJSON(_) {
16757
+ return {};
16758
+ },
16759
+ toJSON(_) {
16760
+ const obj = {};
16761
+ return obj;
16762
+ },
16763
+ create(base) {
16764
+ return EndpointStopResponse.fromPartial(base ?? {});
16765
+ },
16766
+ fromPartial(_) {
16767
+ const message = createBaseEndpointStopResponse();
16768
+ return message;
16769
+ }
16770
+ };
16295
16771
  function createBaseEnvironmentCreateRequest() {
16296
16772
  return { name: "", isManaged: false };
16297
16773
  }
@@ -34619,7 +35095,8 @@ function createBaseSandbox() {
34619
35095
  customDomain: "",
34620
35096
  includeOidcIdentityToken: false,
34621
35097
  readinessProbe: void 0,
34622
- inboundCidrAllowlist: []
35098
+ inboundCidrAllowlist: [],
35099
+ environmentVariables: void 0
34623
35100
  };
34624
35101
  }
34625
35102
  var Sandbox = {
@@ -34735,6 +35212,9 @@ var Sandbox = {
34735
35212
  for (const v of message.inboundCidrAllowlist) {
34736
35213
  writer.uint32(314).string(v);
34737
35214
  }
35215
+ if (message.environmentVariables !== void 0) {
35216
+ StringMap.encode(message.environmentVariables, writer.uint32(322).fork()).join();
35217
+ }
34738
35218
  return writer;
34739
35219
  },
34740
35220
  decode(input, length) {
@@ -35006,6 +35486,13 @@ var Sandbox = {
35006
35486
  message.inboundCidrAllowlist.push(reader.string());
35007
35487
  continue;
35008
35488
  }
35489
+ case 40: {
35490
+ if (tag !== 322) {
35491
+ break;
35492
+ }
35493
+ message.environmentVariables = StringMap.decode(reader, reader.uint32());
35494
+ continue;
35495
+ }
35009
35496
  }
35010
35497
  if ((tag & 7) === 4 || tag === 0) {
35011
35498
  break;
@@ -35055,7 +35542,8 @@ var Sandbox = {
35055
35542
  customDomain: isSet5(object.customDomain) ? globalThis.String(object.customDomain) : "",
35056
35543
  includeOidcIdentityToken: isSet5(object.includeOidcIdentityToken) ? globalThis.Boolean(object.includeOidcIdentityToken) : false,
35057
35544
  readinessProbe: isSet5(object.readinessProbe) ? Probe.fromJSON(object.readinessProbe) : void 0,
35058
- inboundCidrAllowlist: globalThis.Array.isArray(object?.inboundCidrAllowlist) ? object.inboundCidrAllowlist.map((e) => globalThis.String(e)) : []
35545
+ inboundCidrAllowlist: globalThis.Array.isArray(object?.inboundCidrAllowlist) ? object.inboundCidrAllowlist.map((e) => globalThis.String(e)) : [],
35546
+ environmentVariables: isSet5(object.environmentVariables) ? StringMap.fromJSON(object.environmentVariables) : void 0
35059
35547
  };
35060
35548
  },
35061
35549
  toJSON(message) {
@@ -35177,6 +35665,9 @@ var Sandbox = {
35177
35665
  if (message.inboundCidrAllowlist?.length) {
35178
35666
  obj.inboundCidrAllowlist = message.inboundCidrAllowlist;
35179
35667
  }
35668
+ if (message.environmentVariables !== void 0) {
35669
+ obj.environmentVariables = StringMap.toJSON(message.environmentVariables);
35670
+ }
35180
35671
  return obj;
35181
35672
  },
35182
35673
  create(base) {
@@ -35229,6 +35720,7 @@ var Sandbox = {
35229
35720
  message.includeOidcIdentityToken = object.includeOidcIdentityToken ?? false;
35230
35721
  message.readinessProbe = object.readinessProbe !== void 0 && object.readinessProbe !== null ? Probe.fromPartial(object.readinessProbe) : void 0;
35231
35722
  message.inboundCidrAllowlist = object.inboundCidrAllowlist?.map((e) => e) || [];
35723
+ message.environmentVariables = object.environmentVariables !== void 0 && object.environmentVariables !== null ? StringMap.fromPartial(object.environmentVariables) : void 0;
35232
35724
  return message;
35233
35725
  }
35234
35726
  };
@@ -41075,6 +41567,144 @@ var SharedVolumeRemoveFileRequest = {
41075
41567
  return message;
41076
41568
  }
41077
41569
  };
41570
+ function createBaseStringMap() {
41571
+ return { contents: {} };
41572
+ }
41573
+ var StringMap = {
41574
+ encode(message, writer = new BinaryWriter()) {
41575
+ Object.entries(message.contents).forEach(([key, value]) => {
41576
+ StringMap_ContentsEntry.encode({ key, value }, writer.uint32(10).fork()).join();
41577
+ });
41578
+ return writer;
41579
+ },
41580
+ decode(input, length) {
41581
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
41582
+ let end = length === void 0 ? reader.len : reader.pos + length;
41583
+ const message = createBaseStringMap();
41584
+ while (reader.pos < end) {
41585
+ const tag = reader.uint32();
41586
+ switch (tag >>> 3) {
41587
+ case 1: {
41588
+ if (tag !== 10) {
41589
+ break;
41590
+ }
41591
+ const entry1 = StringMap_ContentsEntry.decode(reader, reader.uint32());
41592
+ if (entry1.value !== void 0) {
41593
+ message.contents[entry1.key] = entry1.value;
41594
+ }
41595
+ continue;
41596
+ }
41597
+ }
41598
+ if ((tag & 7) === 4 || tag === 0) {
41599
+ break;
41600
+ }
41601
+ reader.skip(tag & 7);
41602
+ }
41603
+ return message;
41604
+ },
41605
+ fromJSON(object) {
41606
+ return {
41607
+ contents: isObject2(object.contents) ? Object.entries(object.contents).reduce((acc, [key, value]) => {
41608
+ acc[key] = String(value);
41609
+ return acc;
41610
+ }, {}) : {}
41611
+ };
41612
+ },
41613
+ toJSON(message) {
41614
+ const obj = {};
41615
+ if (message.contents) {
41616
+ const entries = Object.entries(message.contents);
41617
+ if (entries.length > 0) {
41618
+ obj.contents = {};
41619
+ entries.forEach(([k, v]) => {
41620
+ obj.contents[k] = v;
41621
+ });
41622
+ }
41623
+ }
41624
+ return obj;
41625
+ },
41626
+ create(base) {
41627
+ return StringMap.fromPartial(base ?? {});
41628
+ },
41629
+ fromPartial(object) {
41630
+ const message = createBaseStringMap();
41631
+ message.contents = Object.entries(object.contents ?? {}).reduce((acc, [key, value]) => {
41632
+ if (value !== void 0) {
41633
+ acc[key] = globalThis.String(value);
41634
+ }
41635
+ return acc;
41636
+ }, {});
41637
+ return message;
41638
+ }
41639
+ };
41640
+ function createBaseStringMap_ContentsEntry() {
41641
+ return { key: "", value: "" };
41642
+ }
41643
+ var StringMap_ContentsEntry = {
41644
+ encode(message, writer = new BinaryWriter()) {
41645
+ if (message.key !== "") {
41646
+ writer.uint32(10).string(message.key);
41647
+ }
41648
+ if (message.value !== "") {
41649
+ writer.uint32(18).string(message.value);
41650
+ }
41651
+ return writer;
41652
+ },
41653
+ decode(input, length) {
41654
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
41655
+ let end = length === void 0 ? reader.len : reader.pos + length;
41656
+ const message = createBaseStringMap_ContentsEntry();
41657
+ while (reader.pos < end) {
41658
+ const tag = reader.uint32();
41659
+ switch (tag >>> 3) {
41660
+ case 1: {
41661
+ if (tag !== 10) {
41662
+ break;
41663
+ }
41664
+ message.key = reader.string();
41665
+ continue;
41666
+ }
41667
+ case 2: {
41668
+ if (tag !== 18) {
41669
+ break;
41670
+ }
41671
+ message.value = reader.string();
41672
+ continue;
41673
+ }
41674
+ }
41675
+ if ((tag & 7) === 4 || tag === 0) {
41676
+ break;
41677
+ }
41678
+ reader.skip(tag & 7);
41679
+ }
41680
+ return message;
41681
+ },
41682
+ fromJSON(object) {
41683
+ return {
41684
+ key: isSet5(object.key) ? globalThis.String(object.key) : "",
41685
+ value: isSet5(object.value) ? globalThis.String(object.value) : ""
41686
+ };
41687
+ },
41688
+ toJSON(message) {
41689
+ const obj = {};
41690
+ if (message.key !== "") {
41691
+ obj.key = message.key;
41692
+ }
41693
+ if (message.value !== "") {
41694
+ obj.value = message.value;
41695
+ }
41696
+ return obj;
41697
+ },
41698
+ create(base) {
41699
+ return StringMap_ContentsEntry.fromPartial(base ?? {});
41700
+ },
41701
+ fromPartial(object) {
41702
+ const message = createBaseStringMap_ContentsEntry();
41703
+ message.key = object.key ?? "";
41704
+ message.value = object.value ?? "";
41705
+ return message;
41706
+ }
41707
+ };
41078
41708
  function createBaseSystemErrorMessage() {
41079
41709
  return { errorCode: 0, errorMessage: "" };
41080
41710
  }
@@ -48157,6 +48787,22 @@ var ModalClientDefinition = {
48157
48787
  responseStream: false,
48158
48788
  options: {}
48159
48789
  },
48790
+ endpointList: {
48791
+ name: "EndpointList",
48792
+ requestType: EndpointListRequest,
48793
+ requestStream: false,
48794
+ responseType: EndpointListResponse,
48795
+ responseStream: false,
48796
+ options: {}
48797
+ },
48798
+ endpointStop: {
48799
+ name: "EndpointStop",
48800
+ requestType: EndpointStopRequest,
48801
+ requestStream: false,
48802
+ responseType: EndpointStopResponse,
48803
+ responseStream: false,
48804
+ options: {}
48805
+ },
48160
48806
  /** Environments */
48161
48807
  environmentCreate: {
48162
48808
  name: "EnvironmentCreate",
@@ -49348,7 +49994,7 @@ function isSet5(value) {
49348
49994
 
49349
49995
  // src/client.ts
49350
49996
  var import_uuid2 = require("uuid");
49351
- var import_nice_grpc11 = require("nice-grpc");
49997
+ var import_nice_grpc13 = require("nice-grpc");
49352
49998
 
49353
49999
  // src/cloud_bucket_mount.ts
49354
50000
  var CloudBucketMountService = class {
@@ -49434,7 +50080,7 @@ var CloudBucketMount2 = class {
49434
50080
  };
49435
50081
 
49436
50082
  // src/cls.ts
49437
- var import_nice_grpc3 = require("nice-grpc");
50083
+ var import_nice_grpc4 = require("nice-grpc");
49438
50084
 
49439
50085
  // src/errors.ts
49440
50086
  var TimeoutError = class extends Error {
@@ -49497,6 +50143,48 @@ var SandboxFilesystemError = class extends Error {
49497
50143
  this.name = "SandboxFilesystemError";
49498
50144
  }
49499
50145
  };
50146
+ var SandboxFilesystemDirectoryNotEmptyError = class extends SandboxFilesystemError {
50147
+ constructor(message) {
50148
+ super(message);
50149
+ this.name = "SandboxFilesystemDirectoryNotEmptyError";
50150
+ }
50151
+ };
50152
+ var SandboxFilesystemFileTooLargeError = class extends SandboxFilesystemError {
50153
+ constructor(message) {
50154
+ super(message);
50155
+ this.name = "SandboxFilesystemFileTooLargeError";
50156
+ }
50157
+ };
50158
+ var SandboxFilesystemIsADirectoryError = class extends SandboxFilesystemError {
50159
+ constructor(message) {
50160
+ super(message);
50161
+ this.name = "SandboxFilesystemIsADirectoryError";
50162
+ }
50163
+ };
50164
+ var SandboxFilesystemNotADirectoryError = class extends SandboxFilesystemError {
50165
+ constructor(message) {
50166
+ super(message);
50167
+ this.name = "SandboxFilesystemNotADirectoryError";
50168
+ }
50169
+ };
50170
+ var SandboxFilesystemNotFoundError = class extends SandboxFilesystemError {
50171
+ constructor(message) {
50172
+ super(message);
50173
+ this.name = "SandboxFilesystemNotFoundError";
50174
+ }
50175
+ };
50176
+ var SandboxFilesystemPathAlreadyExistsError = class extends SandboxFilesystemError {
50177
+ constructor(message) {
50178
+ super(message);
50179
+ this.name = "SandboxFilesystemPathAlreadyExistsError";
50180
+ }
50181
+ };
50182
+ var SandboxFilesystemPermissionError = class extends SandboxFilesystemError {
50183
+ constructor(message) {
50184
+ super(message);
50185
+ this.name = "SandboxFilesystemPermissionError";
50186
+ }
50187
+ };
49500
50188
  var SandboxTimeoutError = class extends Error {
49501
50189
  constructor(message = "Sandbox operation timed out") {
49502
50190
  super(message);
@@ -50207,6 +50895,207 @@ function parseRetries(retries) {
50207
50895
  );
50208
50896
  }
50209
50897
 
50898
+ // src/volume.ts
50899
+ var import_nice_grpc3 = require("nice-grpc");
50900
+
50901
+ // src/ephemeral.ts
50902
+ var ephemeralObjectHeartbeatSleep = 3e5;
50903
+ var EphemeralHeartbeatManager = class {
50904
+ heartbeatFn;
50905
+ abortController;
50906
+ constructor(heartbeatFn) {
50907
+ this.heartbeatFn = heartbeatFn;
50908
+ this.abortController = new AbortController();
50909
+ this.start();
50910
+ }
50911
+ start() {
50912
+ const signal = this.abortController.signal;
50913
+ (async () => {
50914
+ while (!signal.aborted) {
50915
+ await this.heartbeatFn();
50916
+ await Promise.race([
50917
+ new Promise((resolve) => {
50918
+ setTimeout(resolve, ephemeralObjectHeartbeatSleep).unref();
50919
+ }),
50920
+ new Promise((resolve) => {
50921
+ signal.addEventListener("abort", resolve, { once: true });
50922
+ })
50923
+ ]);
50924
+ }
50925
+ })();
50926
+ }
50927
+ stop() {
50928
+ this.abortController.abort();
50929
+ }
50930
+ };
50931
+
50932
+ // src/volume.ts
50933
+ var VolumeService = class {
50934
+ #client;
50935
+ constructor(client2) {
50936
+ this.#client = client2;
50937
+ }
50938
+ /**
50939
+ * Reference a {@link Volume} by its name.
50940
+ */
50941
+ async fromName(name, params) {
50942
+ try {
50943
+ const resp = await this.#client.cpClient.volumeGetOrCreate({
50944
+ deploymentName: name,
50945
+ environmentName: this.#client.environmentName(params?.environment),
50946
+ objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */
50947
+ });
50948
+ this.#client.logger.debug(
50949
+ "Retrieved Volume",
50950
+ "volume_id",
50951
+ resp.volumeId,
50952
+ "volume_name",
50953
+ name
50954
+ );
50955
+ return new Volume(resp.volumeId, name);
50956
+ } catch (err) {
50957
+ if (err instanceof import_nice_grpc3.ClientError && err.code === import_nice_grpc3.Status.NOT_FOUND)
50958
+ throw new NotFoundError(err.details);
50959
+ throw err;
50960
+ }
50961
+ }
50962
+ /**
50963
+ * Create a nameless, temporary {@link Volume}.
50964
+ * It persists until closeEphemeral() is called, or the process exits.
50965
+ */
50966
+ async ephemeral(params = {}) {
50967
+ const resp = await this.#client.cpClient.volumeGetOrCreate({
50968
+ objectCreationType: 5 /* OBJECT_CREATION_TYPE_EPHEMERAL */,
50969
+ environmentName: this.#client.environmentName(params.environment)
50970
+ });
50971
+ this.#client.logger.debug(
50972
+ "Created ephemeral Volume",
50973
+ "volume_id",
50974
+ resp.volumeId
50975
+ );
50976
+ const ephemeralHbManager = new EphemeralHeartbeatManager(
50977
+ () => this.#client.cpClient.volumeHeartbeat({ volumeId: resp.volumeId })
50978
+ );
50979
+ return new Volume(resp.volumeId, void 0, void 0, ephemeralHbManager);
50980
+ }
50981
+ /**
50982
+ * Delete a named {@link Volume}.
50983
+ *
50984
+ * Warning: Deletion is irreversible and will affect any Apps currently using the Volume.
50985
+ */
50986
+ async delete(name, params) {
50987
+ try {
50988
+ const volume = await this.fromName(name, {
50989
+ environment: params?.environment,
50990
+ createIfMissing: false
50991
+ });
50992
+ await this.#client.cpClient.volumeDelete({
50993
+ volumeId: volume.volumeId
50994
+ });
50995
+ this.#client.logger.debug(
50996
+ "Deleted Volume",
50997
+ "volume_name",
50998
+ name,
50999
+ "volume_id",
51000
+ volume.volumeId
51001
+ );
51002
+ } catch (err) {
51003
+ const isNotFound = err instanceof NotFoundError || err instanceof import_nice_grpc3.ClientError && err.code === import_nice_grpc3.Status.NOT_FOUND;
51004
+ if (isNotFound && params?.allowMissing) {
51005
+ return;
51006
+ }
51007
+ throw err;
51008
+ }
51009
+ }
51010
+ };
51011
+ var DEFAULT_MOUNT_OPTIONS = {
51012
+ readOnly: false,
51013
+ subPath: void 0
51014
+ };
51015
+ var Volume = class _Volume {
51016
+ volumeId;
51017
+ name;
51018
+ /**
51019
+ * @hidden
51020
+ * @internal
51021
+ */
51022
+ _mountOptions = DEFAULT_MOUNT_OPTIONS;
51023
+ #ephemeralHbManager;
51024
+ /** @ignore */
51025
+ constructor(volumeId, name, mountOptions, ephemeralHbManager) {
51026
+ this.volumeId = volumeId;
51027
+ this.name = name;
51028
+ if (mountOptions) {
51029
+ this._mountOptions = mountOptions;
51030
+ }
51031
+ this.#ephemeralHbManager = ephemeralHbManager;
51032
+ }
51033
+ /**
51034
+ * @deprecated Use {@link VolumeService#fromName client.volumes.fromName()} instead.
51035
+ */
51036
+ static async fromName(name, options) {
51037
+ return getDefaultClient().volumes.fromName(name, options);
51038
+ }
51039
+ /**
51040
+ * Configure Volume to mount as read-only.
51041
+ *
51042
+ * @deprecated Use {@link withMountOptions} with `{ readOnly: true }` instead.
51043
+ */
51044
+ readOnly() {
51045
+ return this.withMountOptions({ readOnly: true });
51046
+ }
51047
+ /**
51048
+ * Configure options used when mounting this Volume. Fields left undefined preserve their value
51049
+ * from any previous withMountOptions call on the same Volume (stacking).
51050
+ */
51051
+ withMountOptions(params = {}) {
51052
+ let subPath = this._mountOptions.subPath;
51053
+ if (params.subPath !== void 0) {
51054
+ subPath = params.subPath === "/" ? void 0 : params.subPath;
51055
+ }
51056
+ return new _Volume(
51057
+ this.volumeId,
51058
+ this.name,
51059
+ {
51060
+ readOnly: params.readOnly ?? this._mountOptions.readOnly,
51061
+ subPath
51062
+ },
51063
+ this.#ephemeralHbManager
51064
+ );
51065
+ }
51066
+ /**
51067
+ * @deprecated Inspect mount configuration at the call site that configured it instead.
51068
+ * Future versions of this SDK may remove direct mount-option accessors on Volume.
51069
+ */
51070
+ get isReadOnly() {
51071
+ return this._mountOptions.readOnly;
51072
+ }
51073
+ /**
51074
+ * @deprecated Use {@link VolumeService#ephemeral client.volumes.ephemeral()} instead.
51075
+ */
51076
+ static async ephemeral(options = {}) {
51077
+ return getDefaultClient().volumes.ephemeral(options);
51078
+ }
51079
+ /** Delete the ephemeral Volume. Only usable with emphemeral Volumes. */
51080
+ closeEphemeral() {
51081
+ if (this.#ephemeralHbManager) {
51082
+ this.#ephemeralHbManager.stop();
51083
+ } else {
51084
+ throw new InvalidError("Volume is not ephemeral.");
51085
+ }
51086
+ }
51087
+ };
51088
+ function volumeToMountProto(mountPath, volume) {
51089
+ const opts = volume._mountOptions ?? DEFAULT_MOUNT_OPTIONS;
51090
+ return {
51091
+ volumeId: volume.volumeId,
51092
+ mountPath,
51093
+ allowBackgroundCommits: true,
51094
+ readOnly: opts.readOnly,
51095
+ subPath: opts.subPath
51096
+ };
51097
+ }
51098
+
50210
51099
  // src/cls.ts
50211
51100
  var ClsService = class {
50212
51101
  #client;
@@ -50247,7 +51136,7 @@ var ClsService = class {
50247
51136
  void 0
50248
51137
  );
50249
51138
  } catch (err) {
50250
- if (err instanceof import_nice_grpc3.ClientError && err.code === import_nice_grpc3.Status.NOT_FOUND)
51139
+ if (err instanceof import_nice_grpc4.ClientError && err.code === import_nice_grpc4.Status.NOT_FOUND)
50251
51140
  throw new NotFoundError(`Class '${appName}/${name}' not found`);
50252
51141
  throw err;
50253
51142
  }
@@ -50426,12 +51315,9 @@ async function buildFunctionOptionsProto(options) {
50426
51315
  gpuConfig
50427
51316
  } : void 0;
50428
51317
  const secretIds = (o.secrets || []).map((s) => s.secretId);
50429
- const volumeMounts = o.volumes ? Object.entries(o.volumes).map(([mountPath, volume]) => ({
50430
- volumeId: volume.volumeId,
50431
- mountPath,
50432
- allowBackgroundCommits: true,
50433
- readOnly: volume.isReadOnly
50434
- })) : [];
51318
+ const volumeMounts = o.volumes ? Object.entries(o.volumes).map(
51319
+ ([mountPath, volume]) => volumeToMountProto(mountPath, volume)
51320
+ ) : [];
50435
51321
  const parsedRetries = parseRetries(o.retries);
50436
51322
  const retryPolicy = parsedRetries ? {
50437
51323
  retries: parsedRetries.maxRetries,
@@ -50528,8 +51414,8 @@ var ClsInstance = class {
50528
51414
  };
50529
51415
 
50530
51416
  // src/image.ts
50531
- var import_nice_grpc4 = require("nice-grpc");
50532
51417
  var import_nice_grpc5 = require("nice-grpc");
51418
+ var import_nice_grpc6 = require("nice-grpc");
50533
51419
  var ImageService = class {
50534
51420
  #client;
50535
51421
  constructor(client2) {
@@ -50545,9 +51431,9 @@ var ImageService = class {
50545
51431
  const resp = await this.#client.cpClient.imageFromId({ imageId });
50546
51432
  return new Image2(this.#client, resp.imageId, "");
50547
51433
  } catch (err) {
50548
- if (err instanceof import_nice_grpc4.ClientError && err.code === import_nice_grpc5.Status.NOT_FOUND)
51434
+ if (err instanceof import_nice_grpc5.ClientError && err.code === import_nice_grpc6.Status.NOT_FOUND)
50549
51435
  throw new NotFoundError(err.details);
50550
- if (err instanceof import_nice_grpc4.ClientError && err.code === import_nice_grpc5.Status.FAILED_PRECONDITION && err.details.includes("Could not find image with ID"))
51436
+ if (err instanceof import_nice_grpc5.ClientError && err.code === import_nice_grpc6.Status.FAILED_PRECONDITION && err.details.includes("Could not find image with ID"))
50551
51437
  throw new NotFoundError(err.details);
50552
51438
  throw err;
50553
51439
  }
@@ -50629,9 +51515,9 @@ var ImageService = class {
50629
51515
  try {
50630
51516
  await this.#client.cpClient.imageDelete({ imageId });
50631
51517
  } catch (err) {
50632
- if (err instanceof import_nice_grpc4.ClientError && err.code === import_nice_grpc5.Status.NOT_FOUND)
51518
+ if (err instanceof import_nice_grpc5.ClientError && err.code === import_nice_grpc6.Status.NOT_FOUND)
50633
51519
  throw new NotFoundError(err.details);
50634
- if (err instanceof import_nice_grpc4.ClientError && err.code === import_nice_grpc5.Status.FAILED_PRECONDITION && err.details.includes("Could not find image with ID"))
51520
+ if (err instanceof import_nice_grpc5.ClientError && err.code === import_nice_grpc6.Status.FAILED_PRECONDITION && err.details.includes("Could not find image with ID"))
50635
51521
  throw new NotFoundError(err.details);
50636
51522
  throw err;
50637
51523
  }
@@ -50819,7 +51705,7 @@ ${result.exception}`
50819
51705
  };
50820
51706
 
50821
51707
  // src/proxy.ts
50822
- var import_nice_grpc6 = require("nice-grpc");
51708
+ var import_nice_grpc7 = require("nice-grpc");
50823
51709
  var ProxyService = class {
50824
51710
  #client;
50825
51711
  constructor(client2) {
@@ -50845,7 +51731,7 @@ var ProxyService = class {
50845
51731
  }
50846
51732
  return new Proxy3(resp.proxy.proxyId);
50847
51733
  } catch (err) {
50848
- if (err instanceof import_nice_grpc6.ClientError && err.code === import_nice_grpc6.Status.NOT_FOUND)
51734
+ if (err instanceof import_nice_grpc7.ClientError && err.code === import_nice_grpc7.Status.NOT_FOUND)
50849
51735
  throw new NotFoundError(`Proxy '${name}' not found`);
50850
51736
  throw err;
50851
51737
  }
@@ -51221,40 +52107,7 @@ function loads(buf) {
51221
52107
  }
51222
52108
 
51223
52109
  // src/queue.ts
51224
- var import_nice_grpc7 = require("nice-grpc");
51225
-
51226
- // src/ephemeral.ts
51227
- var ephemeralObjectHeartbeatSleep = 3e5;
51228
- var EphemeralHeartbeatManager = class {
51229
- heartbeatFn;
51230
- abortController;
51231
- constructor(heartbeatFn) {
51232
- this.heartbeatFn = heartbeatFn;
51233
- this.abortController = new AbortController();
51234
- this.start();
51235
- }
51236
- start() {
51237
- const signal = this.abortController.signal;
51238
- (async () => {
51239
- while (!signal.aborted) {
51240
- await this.heartbeatFn();
51241
- await Promise.race([
51242
- new Promise((resolve) => {
51243
- setTimeout(resolve, ephemeralObjectHeartbeatSleep).unref();
51244
- }),
51245
- new Promise((resolve) => {
51246
- signal.addEventListener("abort", resolve, { once: true });
51247
- })
51248
- ]);
51249
- }
51250
- })();
51251
- }
51252
- stop() {
51253
- this.abortController.abort();
51254
- }
51255
- };
51256
-
51257
- // src/queue.ts
52110
+ var import_nice_grpc8 = require("nice-grpc");
51258
52111
  var queueInitialPutBackoffMs = 100;
51259
52112
  var queueDefaultPartitionTtlMs = 24 * 3600 * 1e3;
51260
52113
  var QueueService = class {
@@ -51300,7 +52153,7 @@ var QueueService = class {
51300
52153
  );
51301
52154
  return new Queue(this.#client, resp.queueId, name);
51302
52155
  } catch (err) {
51303
- if (err instanceof import_nice_grpc7.ClientError && err.code === import_nice_grpc7.Status.NOT_FOUND)
52156
+ if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.NOT_FOUND)
51304
52157
  throw new NotFoundError(err.details);
51305
52158
  throw err;
51306
52159
  }
@@ -51325,7 +52178,7 @@ var QueueService = class {
51325
52178
  queue.queueId
51326
52179
  );
51327
52180
  } catch (err) {
51328
- const isNotFound = err instanceof NotFoundError || err instanceof import_nice_grpc7.ClientError && err.code === import_nice_grpc7.Status.NOT_FOUND;
52181
+ const isNotFound = err instanceof NotFoundError || err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.NOT_FOUND;
51329
52182
  if (isNotFound && params.allowMissing) {
51330
52183
  return;
51331
52184
  }
@@ -51463,7 +52316,7 @@ var Queue = class _Queue {
51463
52316
  });
51464
52317
  break;
51465
52318
  } catch (e) {
51466
- if (e instanceof import_nice_grpc7.ClientError && e.code === import_nice_grpc7.Status.RESOURCE_EXHAUSTED) {
52319
+ if (e instanceof import_nice_grpc8.ClientError && e.code === import_nice_grpc8.Status.RESOURCE_EXHAUSTED) {
51467
52320
  delay = Math.min(delay * 2, 3e4);
51468
52321
  if (deadline !== void 0) {
51469
52322
  const remaining = deadline - Date.now();
@@ -51564,8 +52417,8 @@ var Queue = class _Queue {
51564
52417
  };
51565
52418
 
51566
52419
  // src/sandbox.ts
51567
- var import_nice_grpc9 = require("nice-grpc");
51568
- var import_promises2 = require("timers/promises");
52420
+ var import_nice_grpc12 = require("nice-grpc");
52421
+ var import_promises3 = require("timers/promises");
51569
52422
 
51570
52423
  // proto/modal_proto/task_command_router.ts
51571
52424
  function sandboxStdioFileDescriptorFromJSON(object) {
@@ -54726,7 +55579,7 @@ function isSet6(value) {
54726
55579
 
54727
55580
  // src/task_command_router_client.ts
54728
55581
  var import_promises = require("timers/promises");
54729
- var import_nice_grpc8 = require("nice-grpc");
55582
+ var import_nice_grpc9 = require("nice-grpc");
54730
55583
 
54731
55584
  // src/config.ts
54732
55585
  var import_node_console = require("console");
@@ -54795,7 +55648,7 @@ function getProfile(profileName) {
54795
55648
  }
54796
55649
 
54797
55650
  // src/task_command_router_client.ts
54798
- function parseJwtExpiration(jwtToken, logger) {
55651
+ function parseJwtExpiration(jwtToken, logger2) {
54799
55652
  try {
54800
55653
  const parts = jwtToken.split(".");
54801
55654
  if (parts.length !== 3) {
@@ -54812,7 +55665,7 @@ function parseJwtExpiration(jwtToken, logger) {
54812
55665
  return exp;
54813
55666
  }
54814
55667
  } catch (e) {
54815
- logger.warn("Failed to parse JWT expiration", "error", e);
55668
+ logger2.warn("Failed to parse JWT expiration", "error", e);
54816
55669
  }
54817
55670
  return null;
54818
55671
  }
@@ -54822,11 +55675,11 @@ async function callWithRetriesOnTransientErrors(func, baseDelayMs = 10, delayFac
54822
55675
  let delayMs = baseDelayMs;
54823
55676
  let numRetries = 0;
54824
55677
  const retryableStatusCodes = /* @__PURE__ */ new Set([
54825
- import_nice_grpc8.Status.DEADLINE_EXCEEDED,
54826
- import_nice_grpc8.Status.UNAVAILABLE,
54827
- import_nice_grpc8.Status.CANCELLED,
54828
- import_nice_grpc8.Status.INTERNAL,
54829
- import_nice_grpc8.Status.UNKNOWN
55678
+ import_nice_grpc9.Status.DEADLINE_EXCEEDED,
55679
+ import_nice_grpc9.Status.UNAVAILABLE,
55680
+ import_nice_grpc9.Status.CANCELLED,
55681
+ import_nice_grpc9.Status.INTERNAL,
55682
+ import_nice_grpc9.Status.UNKNOWN
54830
55683
  ]);
54831
55684
  const excluded = new Set(excludeStatusCodes);
54832
55685
  while (true) {
@@ -54836,10 +55689,10 @@ async function callWithRetriesOnTransientErrors(func, baseDelayMs = 10, delayFac
54836
55689
  try {
54837
55690
  return await func();
54838
55691
  } catch (err) {
54839
- if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.CANCELLED && isClosed?.()) {
55692
+ if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.CANCELLED && isClosed?.()) {
54840
55693
  throw new ClientClosedError();
54841
55694
  }
54842
- if (err instanceof import_nice_grpc8.ClientError && retryableStatusCodes.has(err.code) && !excluded.has(err.code) && (maxRetries === null || numRetries < maxRetries)) {
55695
+ if (err instanceof import_nice_grpc9.ClientError && retryableStatusCodes.has(err.code) && !excluded.has(err.code) && (maxRetries === null || numRetries < maxRetries)) {
54843
55696
  let sleepMs = delayMs;
54844
55697
  if (deadlineMs !== null) {
54845
55698
  sleepMs = Math.min(sleepMs, deadlineMs - Date.now());
@@ -54867,7 +55720,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
54867
55720
  jwtRefreshLock = Promise.resolve();
54868
55721
  logger;
54869
55722
  closed = false;
54870
- static async tryInit(serverClient, taskId, sandboxId, isV2, logger, profile) {
55723
+ static async tryInit(serverClient, taskId, sandboxId, isV2, logger2, profile) {
54871
55724
  let resp;
54872
55725
  try {
54873
55726
  resp = await getCommandRouterAccess(
@@ -54877,8 +55730,8 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
54877
55730
  isV2
54878
55731
  );
54879
55732
  } catch (err) {
54880
- if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.FAILED_PRECONDITION) {
54881
- logger.debug(
55733
+ if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.FAILED_PRECONDITION) {
55734
+ logger2.debug(
54882
55735
  "Command router access is not enabled for task",
54883
55736
  "task_id",
54884
55737
  taskId
@@ -54887,7 +55740,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
54887
55740
  }
54888
55741
  throw err;
54889
55742
  }
54890
- logger.debug(
55743
+ logger2.debug(
54891
55744
  "Using command router access for task",
54892
55745
  "task_id",
54893
55746
  taskId,
@@ -54911,18 +55764,18 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
54911
55764
  };
54912
55765
  let channel;
54913
55766
  if (isLocalhost(profile)) {
54914
- logger.warn(
55767
+ logger2.warn(
54915
55768
  "Using insecure TLS (skip certificate verification) for task command router"
54916
55769
  );
54917
- channel = (0, import_nice_grpc8.createChannel)(
55770
+ channel = (0, import_nice_grpc9.createChannel)(
54918
55771
  serverUrl,
54919
- import_nice_grpc8.ChannelCredentials.createInsecure(),
55772
+ import_nice_grpc9.ChannelCredentials.createInsecure(),
54920
55773
  channelConfig
54921
55774
  );
54922
55775
  } else {
54923
- channel = (0, import_nice_grpc8.createChannel)(
55776
+ channel = (0, import_nice_grpc9.createChannel)(
54924
55777
  serverUrl,
54925
- import_nice_grpc8.ChannelCredentials.createSsl(),
55778
+ import_nice_grpc9.ChannelCredentials.createSsl(),
54926
55779
  channelConfig
54927
55780
  );
54928
55781
  }
@@ -54934,28 +55787,28 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
54934
55787
  resp.url,
54935
55788
  resp.jwt,
54936
55789
  channel,
54937
- logger
55790
+ logger2
54938
55791
  );
54939
- logger.debug(
55792
+ logger2.debug(
54940
55793
  "Successfully initialized command router client",
54941
55794
  "task_id",
54942
55795
  taskId
54943
55796
  );
54944
55797
  return client2;
54945
55798
  }
54946
- constructor(serverClient, taskId, sandboxId, isV2, serverUrl, jwt, channel, logger) {
55799
+ constructor(serverClient, taskId, sandboxId, isV2, serverUrl, jwt, channel, logger2) {
54947
55800
  this.serverClient = serverClient;
54948
55801
  this.taskId = taskId;
54949
55802
  this.sandboxId = sandboxId;
54950
55803
  this.isV2 = isV2;
54951
55804
  this.serverUrl = serverUrl;
54952
55805
  this.jwt = jwt;
54953
- this.jwtExp = parseJwtExpiration(jwt, logger);
54954
- this.logger = logger;
55806
+ this.jwtExp = parseJwtExpiration(jwt, logger2);
55807
+ this.logger = logger2;
54955
55808
  this.channel = channel;
54956
55809
  const self = this;
54957
- const factory = (0, import_nice_grpc8.createClientFactory)().use(timeoutMiddleware).use(async function* authMiddleware(call, options) {
54958
- options.metadata ??= new import_nice_grpc8.Metadata();
55810
+ const factory = (0, import_nice_grpc9.createClientFactory)().use(timeoutMiddleware).use(async function* authMiddleware(call, options) {
55811
+ options.metadata ??= new import_nice_grpc9.Metadata();
54959
55812
  options.metadata.set("authorization", `Bearer ${self.jwt}`);
54960
55813
  return yield* call.next(call.request, options);
54961
55814
  });
@@ -55027,7 +55880,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
55027
55880
  () => this.closed
55028
55881
  );
55029
55882
  } catch (err) {
55030
- if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.DEADLINE_EXCEEDED) {
55883
+ if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.DEADLINE_EXCEEDED) {
55031
55884
  throw new Error(`Deadline exceeded while polling for exec ${execId}`);
55032
55885
  }
55033
55886
  throw err;
@@ -55056,7 +55909,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
55056
55909
  () => this.closed
55057
55910
  );
55058
55911
  } catch (err) {
55059
- if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.DEADLINE_EXCEEDED) {
55912
+ if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.DEADLINE_EXCEEDED) {
55060
55913
  throw new Error(`Deadline exceeded while waiting for exec ${execId}`);
55061
55914
  }
55062
55915
  throw err;
@@ -55098,7 +55951,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
55098
55951
  10,
55099
55952
  overallDeadlineMs,
55100
55953
  () => this.closed,
55101
- [import_nice_grpc8.Status.DEADLINE_EXCEEDED, import_nice_grpc8.Status.CANCELLED]
55954
+ [import_nice_grpc9.Status.DEADLINE_EXCEEDED, import_nice_grpc9.Status.CANCELLED]
55102
55955
  );
55103
55956
  } catch (err) {
55104
55957
  if (overallDeadlineMs !== null && Date.now() >= overallDeadlineMs) {
@@ -55156,7 +56009,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
55156
56009
  try {
55157
56010
  return await func();
55158
56011
  } catch (err) {
55159
- if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.UNAUTHENTICATED) {
56012
+ if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.UNAUTHENTICATED) {
55160
56013
  await this.refreshJwt();
55161
56014
  return await func();
55162
56015
  }
@@ -55170,11 +56023,11 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
55170
56023
  let numRetriesRemaining = 10;
55171
56024
  let didAuthRetry = false;
55172
56025
  const retryableStatusCodes = /* @__PURE__ */ new Set([
55173
- import_nice_grpc8.Status.DEADLINE_EXCEEDED,
55174
- import_nice_grpc8.Status.UNAVAILABLE,
55175
- import_nice_grpc8.Status.CANCELLED,
55176
- import_nice_grpc8.Status.INTERNAL,
55177
- import_nice_grpc8.Status.UNKNOWN
56026
+ import_nice_grpc9.Status.DEADLINE_EXCEEDED,
56027
+ import_nice_grpc9.Status.UNAVAILABLE,
56028
+ import_nice_grpc9.Status.CANCELLED,
56029
+ import_nice_grpc9.Status.INTERNAL,
56030
+ import_nice_grpc9.Status.UNKNOWN
55178
56031
  ]);
55179
56032
  while (true) {
55180
56033
  try {
@@ -55199,7 +56052,7 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
55199
56052
  }
55200
56053
  return;
55201
56054
  } catch (err) {
55202
- if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.UNAUTHENTICATED && !didAuthRetry) {
56055
+ if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.UNAUTHENTICATED && !didAuthRetry) {
55203
56056
  await this.refreshJwt();
55204
56057
  didAuthRetry = true;
55205
56058
  continue;
@@ -55207,10 +56060,10 @@ var TaskCommandRouterClientImpl = class _TaskCommandRouterClientImpl {
55207
56060
  throw err;
55208
56061
  }
55209
56062
  } catch (err) {
55210
- if (err instanceof import_nice_grpc8.ClientError && err.code === import_nice_grpc8.Status.CANCELLED && this.closed) {
56063
+ if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.CANCELLED && this.closed) {
55211
56064
  throw new ClientClosedError();
55212
56065
  }
55213
- if (err instanceof import_nice_grpc8.ClientError && retryableStatusCodes.has(err.code) && numRetriesRemaining > 0) {
56066
+ if (err instanceof import_nice_grpc9.ClientError && retryableStatusCodes.has(err.code) && numRetriesRemaining > 0) {
55214
56067
  if (deadline && deadline - Date.now() <= delayMs) {
55215
56068
  throw new Error(
55216
56069
  `Deadline exceeded while streaming stdio for exec ${execId}`
@@ -55354,6 +56207,760 @@ async function runFilesystemExec(cpClient, request) {
55354
56207
  return { chunks, response };
55355
56208
  }
55356
56209
 
56210
+ // src/sandbox_fs.ts
56211
+ var import_node_crypto2 = require("crypto");
56212
+ var import_node_fs2 = require("fs");
56213
+ var import_promises2 = require("fs/promises");
56214
+ var import_node_stream = require("stream");
56215
+ var import_node_path3 = require("path");
56216
+ var import_nice_grpc11 = require("nice-grpc");
56217
+
56218
+ // src/sandbox_fs_utils.ts
56219
+ var import_node_path2 = require("path");
56220
+ var import_nice_grpc10 = require("nice-grpc");
56221
+
56222
+ // src/logger.ts
56223
+ var LOG_LEVELS = {
56224
+ debug: 0,
56225
+ info: 1,
56226
+ warn: 2,
56227
+ error: 3
56228
+ };
56229
+ function parseLogLevel(level) {
56230
+ if (!level) {
56231
+ return "warn";
56232
+ }
56233
+ const normalized = level.toLowerCase();
56234
+ if (normalized === "debug" || normalized === "info" || normalized === "warn" || normalized === "warning" || normalized === "error") {
56235
+ return normalized === "warning" ? "warn" : normalized;
56236
+ }
56237
+ throw new Error(
56238
+ `Invalid log level value: "${level}" (must be debug, info, warn, or error)`
56239
+ );
56240
+ }
56241
+ var DefaultLogger = class {
56242
+ levelValue;
56243
+ constructor(level = "warn") {
56244
+ this.levelValue = LOG_LEVELS[level];
56245
+ }
56246
+ debug(message, ...args) {
56247
+ if (this.levelValue <= LOG_LEVELS.debug) {
56248
+ console.log(this.formatMessage("DEBUG", message, args));
56249
+ }
56250
+ }
56251
+ info(message, ...args) {
56252
+ if (this.levelValue <= LOG_LEVELS.info) {
56253
+ console.log(this.formatMessage("INFO", message, args));
56254
+ }
56255
+ }
56256
+ warn(message, ...args) {
56257
+ if (this.levelValue <= LOG_LEVELS.warn) {
56258
+ console.warn(this.formatMessage("WARN", message, args));
56259
+ }
56260
+ }
56261
+ error(message, ...args) {
56262
+ if (this.levelValue <= LOG_LEVELS.error) {
56263
+ console.error(this.formatMessage("ERROR", message, args));
56264
+ }
56265
+ }
56266
+ formatMessage(level, message, args) {
56267
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
56268
+ let formatted = `time=${timestamp} level=${level} msg="${message}"`;
56269
+ if (args.length > 0) {
56270
+ for (let i = 0; i < args.length; i += 2) {
56271
+ if (i + 1 < args.length) {
56272
+ const key = args[i];
56273
+ const value = args[i + 1];
56274
+ formatted += ` ${key}=${this.formatValue(value)}`;
56275
+ }
56276
+ }
56277
+ }
56278
+ return formatted;
56279
+ }
56280
+ formatValue(value) {
56281
+ if (typeof value === "string") {
56282
+ return value.includes(" ") ? `"${value}"` : value;
56283
+ }
56284
+ if (value instanceof Error) {
56285
+ return `"${value.message}"`;
56286
+ }
56287
+ if (Array.isArray(value)) {
56288
+ return `[${value.join(",")}]`;
56289
+ }
56290
+ return String(value);
56291
+ }
56292
+ };
56293
+ var FilteredLogger = class {
56294
+ constructor(logger2, level) {
56295
+ this.logger = logger2;
56296
+ this.levelValue = LOG_LEVELS[level];
56297
+ }
56298
+ levelValue;
56299
+ debug(message, ...args) {
56300
+ if (this.levelValue <= LOG_LEVELS.debug) {
56301
+ this.logger.debug(message, ...args);
56302
+ }
56303
+ }
56304
+ info(message, ...args) {
56305
+ if (this.levelValue <= LOG_LEVELS.info) {
56306
+ this.logger.info(message, ...args);
56307
+ }
56308
+ }
56309
+ warn(message, ...args) {
56310
+ if (this.levelValue <= LOG_LEVELS.warn) {
56311
+ this.logger.warn(message, ...args);
56312
+ }
56313
+ }
56314
+ error(message, ...args) {
56315
+ if (this.levelValue <= LOG_LEVELS.error) {
56316
+ this.logger.error(message, ...args);
56317
+ }
56318
+ }
56319
+ };
56320
+ function createLogger(logger2, logLevel = "") {
56321
+ const level = parseLogLevel(logLevel);
56322
+ if (logger2) {
56323
+ return new FilteredLogger(logger2, level);
56324
+ }
56325
+ return new DefaultLogger(level);
56326
+ }
56327
+ function newLogger(logLevel = "") {
56328
+ return createLogger(void 0, logLevel);
56329
+ }
56330
+
56331
+ // src/sandbox_fs_utils.ts
56332
+ var logger = newLogger();
56333
+ var SANDBOX_FS_TOOLS_PATH = "/__modal/.bin/modal-sandbox-fs-tools";
56334
+ function validateAbsoluteRemotePath(remotePath, operation) {
56335
+ if (!import_node_path2.posix.isAbsolute(remotePath)) {
56336
+ throw new InvalidError(
56337
+ `Sandbox.filesystem.${operation}() currently only supports absolute remotePath values`
56338
+ );
56339
+ }
56340
+ }
56341
+ function stderrToText(stderr) {
56342
+ if (typeof stderr === "string") return stderr.trim();
56343
+ return new TextDecoder("utf-8", { fatal: false }).decode(stderr).trim();
56344
+ }
56345
+ function tryParseErrorPayload(stderr) {
56346
+ const text = stderrToText(stderr);
56347
+ if (!text) return null;
56348
+ let payload;
56349
+ try {
56350
+ payload = JSON.parse(text);
56351
+ } catch {
56352
+ return null;
56353
+ }
56354
+ if (typeof payload !== "object" || payload === null) return null;
56355
+ const obj = payload;
56356
+ const errorKind = obj.error_kind;
56357
+ const message = obj.message;
56358
+ if (typeof errorKind !== "string") return null;
56359
+ if (typeof message !== "string" || !message.trim()) return null;
56360
+ const detailRaw = obj.detail;
56361
+ const detail = typeof detailRaw === "string" ? detailRaw : "";
56362
+ return { error_kind: errorKind, message, detail };
56363
+ }
56364
+ function raiseListFilesError(returnCode, stderr, remotePath) {
56365
+ const payload = tryParseErrorPayload(stderr);
56366
+ if (payload) {
56367
+ logger.debug(
56368
+ `sandbox-fs-tools listFiles error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
56369
+ );
56370
+ if (payload.error_kind === "NotFound")
56371
+ throw new SandboxFilesystemNotFoundError(
56372
+ `${payload.message}: ${remotePath}`
56373
+ );
56374
+ if (payload.error_kind === "IsFile" || payload.error_kind === "NotDirectory")
56375
+ throw new SandboxFilesystemNotADirectoryError(
56376
+ `${payload.message}: ${remotePath}`
56377
+ );
56378
+ if (payload.error_kind === "PermissionDenied")
56379
+ throw new SandboxFilesystemPermissionError(
56380
+ `${payload.message}: ${remotePath}`
56381
+ );
56382
+ throw new SandboxFilesystemError(payload.message);
56383
+ }
56384
+ const text = stderrToText(stderr);
56385
+ if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
56386
+ throw new SandboxFilesystemError(
56387
+ `Operation on '${remotePath}' failed with exit code ${returnCode}`
56388
+ );
56389
+ }
56390
+ function makeListFilesCommand(remotePath) {
56391
+ return JSON.stringify({ ListFiles: { path: remotePath } });
56392
+ }
56393
+ function raiseMakeDirectoryError(returnCode, stderr, remotePath) {
56394
+ const payload = tryParseErrorPayload(stderr);
56395
+ if (payload) {
56396
+ logger.debug(
56397
+ `sandbox-fs-tools makeDirectory error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
56398
+ );
56399
+ if (payload.error_kind === "NotFound")
56400
+ throw new SandboxFilesystemNotFoundError(
56401
+ `${payload.message}: ${remotePath}`
56402
+ );
56403
+ if (payload.error_kind === "PathAlreadyExists")
56404
+ throw new SandboxFilesystemPathAlreadyExistsError(
56405
+ `${payload.message}: ${remotePath}`
56406
+ );
56407
+ if (payload.error_kind === "NotDirectory")
56408
+ throw new SandboxFilesystemNotADirectoryError(
56409
+ `${payload.message}: ${remotePath}`
56410
+ );
56411
+ if (payload.error_kind === "PermissionDenied")
56412
+ throw new SandboxFilesystemPermissionError(
56413
+ `${payload.message}: ${remotePath}`
56414
+ );
56415
+ if (payload.error_kind === "NotSupported")
56416
+ throw new InvalidError(
56417
+ `${payload.message}: ${remotePath} - this operation is not supported for CloudBucketMounts`
56418
+ );
56419
+ throw new SandboxFilesystemError(payload.message);
56420
+ }
56421
+ const text = stderrToText(stderr);
56422
+ if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
56423
+ throw new SandboxFilesystemError(
56424
+ `Operation on '${remotePath}' failed with exit code ${returnCode}`
56425
+ );
56426
+ }
56427
+ function makeMakeDirectoryCommand(remotePath, createParents) {
56428
+ return JSON.stringify({
56429
+ MakeDirectory: { path: remotePath, parents: createParents }
56430
+ });
56431
+ }
56432
+ function raiseReadFileError(returnCode, stderr, remotePath) {
56433
+ const payload = tryParseErrorPayload(stderr);
56434
+ if (payload) {
56435
+ logger.debug(
56436
+ `sandbox-fs-tools read error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
56437
+ );
56438
+ if (payload.error_kind === "NotFound")
56439
+ throw new SandboxFilesystemNotFoundError(
56440
+ `${payload.message}: ${remotePath}`
56441
+ );
56442
+ if (payload.error_kind === "IsDirectory")
56443
+ throw new SandboxFilesystemIsADirectoryError(
56444
+ `${payload.message}: ${remotePath}`
56445
+ );
56446
+ if (payload.error_kind === "PermissionDenied")
56447
+ throw new SandboxFilesystemPermissionError(
56448
+ `${payload.message}: ${remotePath}`
56449
+ );
56450
+ if (payload.error_kind === "FileTooLarge")
56451
+ throw new SandboxFilesystemFileTooLargeError(
56452
+ `${payload.message}: ${remotePath}`
56453
+ );
56454
+ throw new SandboxFilesystemError(payload.message);
56455
+ }
56456
+ const text = stderrToText(stderr);
56457
+ if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
56458
+ throw new SandboxFilesystemError(
56459
+ `Operation on '${remotePath}' failed with exit code ${returnCode}`
56460
+ );
56461
+ }
56462
+ function makeReadFileCommand(remotePath) {
56463
+ return JSON.stringify({ ReadFile: { path: remotePath } });
56464
+ }
56465
+ function raiseRemoveError(returnCode, stderr, remotePath) {
56466
+ const payload = tryParseErrorPayload(stderr);
56467
+ if (payload) {
56468
+ logger.debug(
56469
+ `sandbox-fs-tools remove error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
56470
+ );
56471
+ if (payload.error_kind === "NotFound")
56472
+ throw new SandboxFilesystemNotFoundError(
56473
+ `${payload.message}: ${remotePath}`
56474
+ );
56475
+ if (payload.error_kind === "DirectoryNotEmpty")
56476
+ throw new SandboxFilesystemDirectoryNotEmptyError(
56477
+ `${payload.message}: ${remotePath}`
56478
+ );
56479
+ if (payload.error_kind === "NotSupported")
56480
+ throw new InvalidError(
56481
+ `${payload.message}: ${remotePath} - this operation is not supported for CloudBucketMounts`
56482
+ );
56483
+ if (payload.error_kind === "PermissionDenied")
56484
+ throw new SandboxFilesystemPermissionError(
56485
+ `${payload.message}: ${remotePath}`
56486
+ );
56487
+ throw new SandboxFilesystemError(payload.message);
56488
+ }
56489
+ const text = stderrToText(stderr);
56490
+ if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
56491
+ throw new SandboxFilesystemError(
56492
+ `Operation on '${remotePath}' failed with exit code ${returnCode}`
56493
+ );
56494
+ }
56495
+ function makeRemoveCommand(remotePath, recursive) {
56496
+ return JSON.stringify({ Remove: { path: remotePath, recursive } });
56497
+ }
56498
+ function raiseStatError(returnCode, stderr, remotePath) {
56499
+ const payload = tryParseErrorPayload(stderr);
56500
+ if (payload) {
56501
+ logger.debug(
56502
+ `sandbox-fs-tools stat error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
56503
+ );
56504
+ if (payload.error_kind === "NotFound")
56505
+ throw new SandboxFilesystemNotFoundError(
56506
+ `${payload.message}: ${remotePath}`
56507
+ );
56508
+ if (payload.error_kind === "NotDirectory")
56509
+ throw new SandboxFilesystemNotADirectoryError(
56510
+ `${payload.message}: ${remotePath}`
56511
+ );
56512
+ if (payload.error_kind === "PermissionDenied")
56513
+ throw new SandboxFilesystemPermissionError(
56514
+ `${payload.message}: ${remotePath}`
56515
+ );
56516
+ throw new SandboxFilesystemError(payload.message);
56517
+ }
56518
+ const text = stderrToText(stderr);
56519
+ if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
56520
+ throw new SandboxFilesystemError(
56521
+ `Operation on '${remotePath}' failed with exit code ${returnCode}`
56522
+ );
56523
+ }
56524
+ function makeStatCommand(remotePath) {
56525
+ return JSON.stringify({ Stat: { path: remotePath } });
56526
+ }
56527
+ function raiseWriteFileError(returnCode, stderr, remotePath) {
56528
+ const payload = tryParseErrorPayload(stderr);
56529
+ if (payload) {
56530
+ logger.debug(
56531
+ `sandbox-fs-tools write error: path=${remotePath}, error_kind=${payload.error_kind}, message=${payload.message}, detail=${payload.detail}`
56532
+ );
56533
+ if (payload.error_kind === "NotDirectory" || payload.error_kind === "AlreadyExists")
56534
+ throw new SandboxFilesystemNotADirectoryError(
56535
+ `${payload.message}: ${remotePath}`
56536
+ );
56537
+ if (payload.error_kind === "IsDirectory")
56538
+ throw new SandboxFilesystemIsADirectoryError(
56539
+ `${payload.message}: ${remotePath}`
56540
+ );
56541
+ if (payload.error_kind === "PermissionDenied")
56542
+ throw new SandboxFilesystemPermissionError(
56543
+ `${payload.message}: ${remotePath}`
56544
+ );
56545
+ throw new SandboxFilesystemError(payload.message);
56546
+ }
56547
+ const text = stderrToText(stderr);
56548
+ if (text) logger.debug(`Unstructured modal-sandbox-fs-tools stderr: ${text}`);
56549
+ throw new SandboxFilesystemError(
56550
+ `Operation on '${remotePath}' failed with exit code ${returnCode}`
56551
+ );
56552
+ }
56553
+ function makeWriteFileCommand(remotePath) {
56554
+ return JSON.stringify({ WriteFile: { path: remotePath } });
56555
+ }
56556
+ var SUPPORT_ERROR_CODE_RE = /Error code:\s*([A-Z0-9]{8})/;
56557
+ function extractSupportErrorCode(err) {
56558
+ const message = err instanceof Error ? err.message : String(err);
56559
+ const match = SUPPORT_ERROR_CODE_RE.exec(message);
56560
+ return match ? match[1] : null;
56561
+ }
56562
+ function describeError(err) {
56563
+ if (err instanceof Error) return `${err.name}: ${err.message}`;
56564
+ return String(err);
56565
+ }
56566
+ function isSandboxUnavailableError(err) {
56567
+ if (err instanceof NotFoundError) return true;
56568
+ if (err instanceof import_nice_grpc10.ClientError) {
56569
+ return err.code === import_nice_grpc10.Status.NOT_FOUND || err.code === import_nice_grpc10.Status.CANCELLED || err.code === import_nice_grpc10.Status.UNKNOWN || err.code === import_nice_grpc10.Status.DEADLINE_EXCEEDED || err.code === import_nice_grpc10.Status.UNAVAILABLE;
56570
+ }
56571
+ return false;
56572
+ }
56573
+ function translateExecSandboxUnavailableError(operation, remotePath, err) {
56574
+ logger.debug(
56575
+ `Sandbox filesystem control-plane error for operation=${operation}, path=${remotePath}: ${describeError(err)}`
56576
+ );
56577
+ return new NotFoundError(
56578
+ "The Sandbox is unavailable. This Sandbox may have already shut down."
56579
+ );
56580
+ }
56581
+ function translateExecUnexpectedError(operation, remotePath, err) {
56582
+ const code = extractSupportErrorCode(err);
56583
+ logger.debug(
56584
+ `Unexpected sandbox filesystem exec error for operation=${operation}, path=${remotePath}: ${describeError(err)}`
56585
+ );
56586
+ const supportSuffix = code ? `please contact support@modal.com (Error code: ${code})` : "please contact support@modal.com";
56587
+ return new SandboxFilesystemError(
56588
+ `An unexpected error occurred, ${supportSuffix}`
56589
+ );
56590
+ }
56591
+ async function translateExecErrors(operation, remotePath, fn) {
56592
+ try {
56593
+ return await fn();
56594
+ } catch (err) {
56595
+ if (isSandboxUnavailableError(err)) {
56596
+ throw translateExecSandboxUnavailableError(operation, remotePath, err);
56597
+ }
56598
+ if (err instanceof import_nice_grpc10.ClientError) {
56599
+ throw translateExecUnexpectedError(operation, remotePath, err);
56600
+ }
56601
+ throw err;
56602
+ }
56603
+ }
56604
+
56605
+ // src/sandbox_fs.ts
56606
+ function parseFileEntry(raw) {
56607
+ return {
56608
+ name: raw.name,
56609
+ path: raw.path,
56610
+ type: raw.type,
56611
+ size: raw.size,
56612
+ mode: raw.mode,
56613
+ permissions: raw.permissions,
56614
+ owner: raw.owner,
56615
+ group: raw.group,
56616
+ modifiedTime: raw.modified_time,
56617
+ symlinkTarget: raw.symlink_target ?? null
56618
+ };
56619
+ }
56620
+ var WRITE_CHUNK_SIZE = 4 * 1024 * 1024;
56621
+ function toUint8Array(data) {
56622
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
56623
+ if (data instanceof Uint8Array) return data;
56624
+ throw new TypeError(
56625
+ `Expected Uint8Array, ArrayBuffer, or Buffer, got ${typeof data}`
56626
+ );
56627
+ }
56628
+ var SandboxFilesystem = class {
56629
+ /** @ignore */
56630
+ constructor(sandbox) {
56631
+ this.sandbox = sandbox;
56632
+ }
56633
+ /**
56634
+ * Copy a local file into the Sandbox.
56635
+ *
56636
+ * `remotePath` must be an absolute path to a file in the Sandbox.
56637
+ * Parent directories are created if needed. The remote file is overwritten
56638
+ * if it already exists.
56639
+ *
56640
+ * @throws {SandboxFilesystemNotADirectoryError} a parent component of `remotePath` is not a directory.
56641
+ * @throws {SandboxFilesystemIsADirectoryError} `remotePath` points to a directory.
56642
+ * @throws {SandboxFilesystemPermissionError} write permission is denied in the Sandbox.
56643
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56644
+ * @throws {Error} `localPath` does not exist, is a directory, or cannot be read (`ENOENT`, `EISDIR`, `EACCES`).
56645
+ */
56646
+ async copyFromLocal(localPath, remotePath) {
56647
+ validateAbsoluteRemotePath(remotePath, "copyFromLocal");
56648
+ await translateExecErrors("copyFromLocal", remotePath, async () => {
56649
+ const process2 = await this.sandbox.exec(
56650
+ [SANDBOX_FS_TOOLS_PATH, makeWriteFileCommand(remotePath)],
56651
+ { mode: "binary" }
56652
+ );
56653
+ const writer = process2.stdin.getWriter();
56654
+ try {
56655
+ const fileStream = (0, import_node_fs2.createReadStream)(localPath);
56656
+ for await (const chunk of fileStream) {
56657
+ await writer.write(chunk);
56658
+ }
56659
+ await writer.close();
56660
+ } catch (err) {
56661
+ if (err instanceof import_nice_grpc11.ClientError && (err.code === import_nice_grpc11.Status.FAILED_PRECONDITION || err.code === import_nice_grpc11.Status.ABORTED)) {
56662
+ await process2.closeStdin();
56663
+ } else {
56664
+ await writer.abort(err).catch(() => {
56665
+ });
56666
+ throw err;
56667
+ }
56668
+ } finally {
56669
+ writer.releaseLock();
56670
+ }
56671
+ const returnCode = await process2.wait();
56672
+ if (returnCode !== 0) {
56673
+ const stderr = await process2.stderr.readBytes();
56674
+ raiseWriteFileError(returnCode, stderr, remotePath);
56675
+ }
56676
+ });
56677
+ }
56678
+ /**
56679
+ * Copy a file from the Sandbox to a local path.
56680
+ *
56681
+ * `remotePath` must be an absolute path to a file in the Sandbox.
56682
+ * Parent directories for `localPath` are created if needed. The local file
56683
+ * is overwritten if it already exists.
56684
+ *
56685
+ * @throws {SandboxFilesystemNotFoundError} the remote path does not exist.
56686
+ * @throws {SandboxFilesystemIsADirectoryError} the remote path points to a directory.
56687
+ * @throws {SandboxFilesystemFileTooLargeError} the file exceeds the read size limit.
56688
+ * @throws {SandboxFilesystemPermissionError} read permission is denied in the Sandbox.
56689
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56690
+ * @throws {Error} `localPath` points to a directory, or writing it is not permitted.
56691
+ */
56692
+ async copyToLocal(remotePath, localPath) {
56693
+ validateAbsoluteRemotePath(remotePath, "copyToLocal");
56694
+ const dir = (0, import_node_path3.dirname)(localPath);
56695
+ const createdDir = await (0, import_promises2.mkdir)(dir, { recursive: true });
56696
+ const tmpPath = `${dir}/.modal-sandbox-fs-tmp-${(0, import_node_crypto2.randomBytes)(8).toString("hex")}`;
56697
+ try {
56698
+ await translateExecErrors("copyToLocal", remotePath, async () => {
56699
+ const process2 = await this.sandbox.exec(
56700
+ [SANDBOX_FS_TOOLS_PATH, makeReadFileCommand(remotePath)],
56701
+ { mode: "binary" }
56702
+ );
56703
+ const returnCode = await process2.wait();
56704
+ if (returnCode !== 0) {
56705
+ const stderr = await process2.stderr.readBytes();
56706
+ raiseReadFileError(returnCode, stderr, remotePath);
56707
+ }
56708
+ await process2.stdout.pipeTo(import_node_stream.Writable.toWeb((0, import_node_fs2.createWriteStream)(tmpPath)));
56709
+ });
56710
+ await (0, import_promises2.rename)(tmpPath, localPath);
56711
+ } catch (err) {
56712
+ await (0, import_promises2.unlink)(tmpPath).catch(() => {
56713
+ });
56714
+ if (createdDir !== void 0) {
56715
+ await (0, import_promises2.rm)(createdDir, { recursive: true, force: true }).catch(() => {
56716
+ });
56717
+ }
56718
+ throw err;
56719
+ }
56720
+ }
56721
+ /**
56722
+ * List files and directories in a Sandbox directory.
56723
+ *
56724
+ * `remotePath` must be an absolute path to a directory in the Sandbox.
56725
+ * Returns an array of {@link FileInfo} objects sorted by name.
56726
+ *
56727
+ * @throws {SandboxFilesystemNotFoundError} the path does not exist.
56728
+ * @throws {SandboxFilesystemNotADirectoryError} the path is not a directory.
56729
+ * @throws {SandboxFilesystemPermissionError} read permission is denied.
56730
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56731
+ */
56732
+ async listFiles(remotePath) {
56733
+ validateAbsoluteRemotePath(remotePath, "listFiles");
56734
+ const json = await translateExecErrors(
56735
+ "listFiles",
56736
+ remotePath,
56737
+ async () => {
56738
+ const process2 = await this.sandbox.exec(
56739
+ [SANDBOX_FS_TOOLS_PATH, makeListFilesCommand(remotePath)],
56740
+ { mode: "text" }
56741
+ );
56742
+ const returnCode = await process2.wait();
56743
+ if (returnCode !== 0) {
56744
+ const stderr = await process2.stderr.readBytes();
56745
+ raiseListFilesError(returnCode, stderr, remotePath);
56746
+ }
56747
+ return process2.stdout.readText();
56748
+ }
56749
+ );
56750
+ return JSON.parse(json).map(parseFileEntry);
56751
+ }
56752
+ /**
56753
+ * Create a new directory in the Sandbox.
56754
+ *
56755
+ * `remotePath` must be an absolute path in the Sandbox.
56756
+ *
56757
+ * When `createParents` is `true` (the default), any missing parent
56758
+ * directories are created and the call is idempotent (succeeds if the
56759
+ * directory already exists). When `createParents` is `false`, the immediate
56760
+ * parent must already exist and the path must not already exist.
56761
+ *
56762
+ * @throws {SandboxFilesystemNotFoundError} the parent does not exist and `createParents` is `false`.
56763
+ * @throws {SandboxFilesystemPathAlreadyExistsError} the path already exists and `createParents` is `false`.
56764
+ * @throws {SandboxFilesystemNotADirectoryError} a path component is not a directory.
56765
+ * @throws {SandboxFilesystemPermissionError} creation is not permitted.
56766
+ * @throws {InvalidError} the operation is not supported by the mount.
56767
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56768
+ */
56769
+ async makeDirectory(remotePath, options) {
56770
+ validateAbsoluteRemotePath(remotePath, "makeDirectory");
56771
+ const createParents = options?.createParents ?? true;
56772
+ await translateExecErrors("makeDirectory", remotePath, async () => {
56773
+ const process2 = await this.sandbox.exec(
56774
+ [
56775
+ SANDBOX_FS_TOOLS_PATH,
56776
+ makeMakeDirectoryCommand(remotePath, createParents)
56777
+ ],
56778
+ { mode: "binary" }
56779
+ );
56780
+ const returnCode = await process2.wait();
56781
+ if (returnCode !== 0) {
56782
+ const stderr = await process2.stderr.readBytes();
56783
+ raiseMakeDirectoryError(returnCode, stderr, remotePath);
56784
+ }
56785
+ });
56786
+ }
56787
+ /**
56788
+ * Read a file from the Sandbox and return its contents as bytes.
56789
+ *
56790
+ * `remotePath` must be an absolute path to a file in the Sandbox.
56791
+ *
56792
+ * @throws {SandboxFilesystemNotFoundError} the path does not exist.
56793
+ * @throws {SandboxFilesystemIsADirectoryError} the path points to a directory.
56794
+ * @throws {SandboxFilesystemFileTooLargeError} the file exceeds the read size limit.
56795
+ * @throws {SandboxFilesystemPermissionError} read permission is denied.
56796
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56797
+ */
56798
+ async readBytes(remotePath) {
56799
+ validateAbsoluteRemotePath(remotePath, "readBytes");
56800
+ return translateExecErrors("readBytes", remotePath, async () => {
56801
+ const process2 = await this.sandbox.exec(
56802
+ [SANDBOX_FS_TOOLS_PATH, makeReadFileCommand(remotePath)],
56803
+ { mode: "binary" }
56804
+ );
56805
+ const returnCode = await process2.wait();
56806
+ if (returnCode !== 0) {
56807
+ const stderr = await process2.stderr.readBytes();
56808
+ raiseReadFileError(returnCode, stderr, remotePath);
56809
+ }
56810
+ return process2.stdout.readBytes();
56811
+ });
56812
+ }
56813
+ /**
56814
+ * Read a file from the Sandbox and return its contents as a UTF-8 string.
56815
+ *
56816
+ * `remotePath` must be an absolute path to a file in the Sandbox.
56817
+ *
56818
+ * @throws {SandboxFilesystemNotFoundError} the path does not exist.
56819
+ * @throws {SandboxFilesystemIsADirectoryError} the path points to a directory.
56820
+ * @throws {SandboxFilesystemFileTooLargeError} the file exceeds the read size limit.
56821
+ * @throws {SandboxFilesystemPermissionError} read permission is denied.
56822
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56823
+ */
56824
+ async readText(remotePath) {
56825
+ validateAbsoluteRemotePath(remotePath, "readText");
56826
+ return translateExecErrors("readText", remotePath, async () => {
56827
+ const process2 = await this.sandbox.exec(
56828
+ [SANDBOX_FS_TOOLS_PATH, makeReadFileCommand(remotePath)],
56829
+ { mode: "text" }
56830
+ );
56831
+ const returnCode = await process2.wait();
56832
+ if (returnCode !== 0) {
56833
+ const stderr = await process2.stderr.readBytes();
56834
+ raiseReadFileError(returnCode, stderr, remotePath);
56835
+ }
56836
+ return process2.stdout.readText();
56837
+ });
56838
+ }
56839
+ /**
56840
+ * Remove a file or directory in the Sandbox.
56841
+ *
56842
+ * `remotePath` must be an absolute path in the Sandbox. When `remotePath`
56843
+ * is a directory and `recursive` is `false` (the default), it is removed
56844
+ * only if empty. When `recursive` is `true`, the directory and all its
56845
+ * contents are removed. Recursive removal is not supported on all mounts —
56846
+ * `CloudBucketMount` does not support it.
56847
+ *
56848
+ * @throws {SandboxFilesystemNotFoundError} the path does not exist.
56849
+ * @throws {SandboxFilesystemDirectoryNotEmptyError} `recursive` is `false` and the directory is not empty.
56850
+ * @throws {SandboxFilesystemPermissionError} removal is not permitted.
56851
+ * @throws {InvalidError} the operation is not supported by the mount.
56852
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56853
+ */
56854
+ async remove(remotePath, options) {
56855
+ validateAbsoluteRemotePath(remotePath, "remove");
56856
+ const recursive = options?.recursive ?? false;
56857
+ await translateExecErrors("remove", remotePath, async () => {
56858
+ const process2 = await this.sandbox.exec(
56859
+ [SANDBOX_FS_TOOLS_PATH, makeRemoveCommand(remotePath, recursive)],
56860
+ { mode: "binary" }
56861
+ );
56862
+ const returnCode = await process2.wait();
56863
+ if (returnCode !== 0) {
56864
+ const stderr = await process2.stderr.readBytes();
56865
+ raiseRemoveError(returnCode, stderr, remotePath);
56866
+ }
56867
+ });
56868
+ }
56869
+ /**
56870
+ * Return metadata for a single file, directory, or symlink in the Sandbox.
56871
+ *
56872
+ * `remotePath` must be an absolute path in the Sandbox. If `remotePath` is
56873
+ * a symlink, the returned {@link FileInfo} describes the symlink itself, not
56874
+ * the target it points to.
56875
+ *
56876
+ * @throws {SandboxFilesystemNotFoundError} the path does not exist.
56877
+ * @throws {SandboxFilesystemNotADirectoryError} a non-leaf component of the path is not a directory.
56878
+ * @throws {SandboxFilesystemPermissionError} a path component is not searchable.
56879
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56880
+ */
56881
+ async stat(remotePath) {
56882
+ validateAbsoluteRemotePath(remotePath, "stat");
56883
+ const stdout = await translateExecErrors("stat", remotePath, async () => {
56884
+ const process2 = await this.sandbox.exec(
56885
+ [SANDBOX_FS_TOOLS_PATH, makeStatCommand(remotePath)],
56886
+ { mode: "text" }
56887
+ );
56888
+ const returnCode = await process2.wait();
56889
+ if (returnCode !== 0) {
56890
+ const stderr = await process2.stderr.readBytes();
56891
+ raiseStatError(returnCode, stderr, remotePath);
56892
+ }
56893
+ return await process2.stdout.readText();
56894
+ });
56895
+ return parseFileEntry(JSON.parse(stdout));
56896
+ }
56897
+ /**
56898
+ * Write binary content to a file in the Sandbox.
56899
+ *
56900
+ * `remotePath` must be an absolute path to a file in the Sandbox.
56901
+ * Parent directories are created if needed. The remote file is overwritten
56902
+ * if it already exists.
56903
+ *
56904
+ * @throws {TypeError} `data` is not a `Uint8Array`, `ArrayBuffer`, or `Buffer`.
56905
+ * @throws {SandboxFilesystemNotADirectoryError} a parent component of `remotePath` is not a directory.
56906
+ * @throws {SandboxFilesystemIsADirectoryError} `remotePath` points to a directory.
56907
+ * @throws {SandboxFilesystemPermissionError} write permission is denied.
56908
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56909
+ */
56910
+ async writeBytes(data, remotePath) {
56911
+ validateAbsoluteRemotePath(remotePath, "writeBytes");
56912
+ const bytes = toUint8Array(data);
56913
+ await translateExecErrors("writeBytes", remotePath, async () => {
56914
+ const process2 = await this.sandbox.exec(
56915
+ [SANDBOX_FS_TOOLS_PATH, makeWriteFileCommand(remotePath)],
56916
+ { mode: "binary" }
56917
+ );
56918
+ const writer = process2.stdin.getWriter();
56919
+ try {
56920
+ const end = Math.max(bytes.length, 1);
56921
+ for (let offset = 0; offset < end; offset += WRITE_CHUNK_SIZE) {
56922
+ await writer.write(bytes.subarray(offset, offset + WRITE_CHUNK_SIZE));
56923
+ }
56924
+ await writer.close();
56925
+ } catch (err) {
56926
+ if (err instanceof import_nice_grpc11.ClientError && (err.code === import_nice_grpc11.Status.FAILED_PRECONDITION || err.code === import_nice_grpc11.Status.ABORTED)) {
56927
+ await process2.closeStdin();
56928
+ } else {
56929
+ await writer.abort(err).catch(() => {
56930
+ });
56931
+ throw err;
56932
+ }
56933
+ } finally {
56934
+ writer.releaseLock();
56935
+ }
56936
+ const returnCode = await process2.wait();
56937
+ if (returnCode !== 0) {
56938
+ const stderr = await process2.stderr.readBytes();
56939
+ raiseWriteFileError(returnCode, stderr, remotePath);
56940
+ }
56941
+ });
56942
+ }
56943
+ /**
56944
+ * Write UTF-8 text to a file in the Sandbox.
56945
+ *
56946
+ * `remotePath` must be an absolute path to a file in the Sandbox.
56947
+ * Parent directories are created if needed. The remote file is overwritten
56948
+ * if it already exists.
56949
+ *
56950
+ * @throws {TypeError} `data` is not a string.
56951
+ * @throws {SandboxFilesystemNotADirectoryError} a parent component of `remotePath` is not a directory.
56952
+ * @throws {SandboxFilesystemIsADirectoryError} `remotePath` points to a directory.
56953
+ * @throws {SandboxFilesystemPermissionError} write permission is denied.
56954
+ * @throws {SandboxFilesystemError} the command fails for any other reason.
56955
+ */
56956
+ async writeText(data, remotePath) {
56957
+ validateAbsoluteRemotePath(remotePath, "writeText");
56958
+ if (typeof data !== "string")
56959
+ throw new TypeError(`writeText() expects a string, got ${typeof data}`);
56960
+ await this.writeBytes(new TextEncoder().encode(data), remotePath);
56961
+ }
56962
+ };
56963
+
55357
56964
  // src/streams.ts
55358
56965
  function toModalReadStream(stream) {
55359
56966
  return Object.assign(stream, readMixin);
@@ -55469,6 +57076,27 @@ var SB_LOGS_INITIAL_DELAY_MS = 10;
55469
57076
  var SB_LOGS_DELAY_FACTOR = 2;
55470
57077
  var SB_LOGS_MAX_RETRIES = 10;
55471
57078
  var TTL_NO_EXPIRY_SENTINEL = -1;
57079
+ var V1_SANDBOX_ID_ALPHABET = new Set(
57080
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
57081
+ );
57082
+ var ULID_ALPHABET = new Set("0123456789ABCDEFGHJKMNPQRSTVWXYZ");
57083
+ function isV1SandboxId(sandboxId) {
57084
+ const [prefix, suffix, ...extra] = sandboxId.split("-");
57085
+ return prefix === "sb" && extra.length === 0 && suffix !== void 0 && suffix.length === 22 && Array.from(suffix).every((ch) => V1_SANDBOX_ID_ALPHABET.has(ch));
57086
+ }
57087
+ function isV2SandboxId(sandboxId) {
57088
+ const [prefix, suffix, ...extra] = sandboxId.split("-");
57089
+ return prefix === "sb" && extra.length === 0 && suffix !== void 0 && suffix.length === 26 && "01234567".includes(suffix[0]) && Array.from(suffix).every((ch) => ULID_ALPHABET.has(ch));
57090
+ }
57091
+ function getSandboxVersion(sandboxId) {
57092
+ if (isV2SandboxId(sandboxId)) {
57093
+ return "V2" /* V2 */;
57094
+ }
57095
+ if (isV1SandboxId(sandboxId)) {
57096
+ return "V1" /* V1 */;
57097
+ }
57098
+ throw new InvalidError(`Invalid Sandbox ID: ${sandboxId}`);
57099
+ }
55472
57100
  var Probe2 = class _Probe {
55473
57101
  #tcpPort;
55474
57102
  #execArgv;
@@ -55570,12 +57198,9 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
55570
57198
  if (params.workdir && !params.workdir.startsWith("/")) {
55571
57199
  throw new Error(`workdir must be an absolute path, got: ${params.workdir}`);
55572
57200
  }
55573
- const volumeMounts = params.volumes ? Object.entries(params.volumes).map(([mountPath, volume]) => ({
55574
- volumeId: volume.volumeId,
55575
- mountPath,
55576
- allowBackgroundCommits: true,
55577
- readOnly: volume.isReadOnly
55578
- })) : [];
57201
+ const volumeMounts = params.volumes ? Object.entries(params.volumes).map(
57202
+ ([mountPath, volume]) => volumeToMountProto(mountPath, volume)
57203
+ ) : [];
55579
57204
  const cloudBucketMounts = params.cloudBucketMounts ? Object.entries(params.cloudBucketMounts).map(
55580
57205
  ([mountPath, mount]) => mount.toProto(mountPath)
55581
57206
  ) : [];
@@ -55812,7 +57437,7 @@ var SandboxService = class {
55812
57437
  try {
55813
57438
  createResp = await this.#client.cpClient.sandboxCreate(createReq);
55814
57439
  } catch (err) {
55815
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.ALREADY_EXISTS) {
57440
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.ALREADY_EXISTS) {
55816
57441
  throw new AlreadyExistsError(err.details || err.message);
55817
57442
  }
55818
57443
  throw err;
@@ -55826,6 +57451,20 @@ var SandboxService = class {
55826
57451
  }
55827
57452
  /**
55828
57453
  * Create a new {@link Sandbox} using the experimental V2 backend.
57454
+ *
57455
+ * Supported features include exec, encrypted tunnels, wait/poll/terminate,
57456
+ * CPU and memory configuration, and region placement.
57457
+ *
57458
+ * Features like tags, filesystem snapshots, memory snapshots, volumes, cloud
57459
+ * bucket mounts, GPUs, custom domains, OIDC identity tokens, proxies, and
57460
+ * readiness probes are not supported.
57461
+ *
57462
+ * V2 sandboxes created with this method are not currently returned by
57463
+ * {@link SandboxService#list client.sandboxes.list()} and cannot be looked up
57464
+ * with {@link SandboxService#fromName client.sandboxes.fromName()}. Store
57465
+ * {@link Sandbox#sandboxId sandbox.sandboxId} if you need to retrieve the
57466
+ * sandbox later, and use {@link SandboxService#fromId client.sandboxes.fromId()}
57467
+ * to reattach.
55829
57468
  */
55830
57469
  async experimentalCreate(app, image, params = {}) {
55831
57470
  await image.build(app);
@@ -55849,7 +57488,7 @@ var SandboxService = class {
55849
57488
  try {
55850
57489
  createResp = await this.#client.cpClient.sandboxCreateV2(createReq);
55851
57490
  } catch (err) {
55852
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.ALREADY_EXISTS) {
57491
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.ALREADY_EXISTS) {
55853
57492
  throw new AlreadyExistsError(err.details || err.message);
55854
57493
  }
55855
57494
  throw err;
@@ -55876,17 +57515,21 @@ var SandboxService = class {
55876
57515
  * @returns Sandbox with ID
55877
57516
  */
55878
57517
  async fromId(sandboxId) {
57518
+ const sandboxVersion = getSandboxVersion(sandboxId);
57519
+ const isV2 = sandboxVersion === "V2" /* V2 */;
57520
+ const req = { sandboxId, timeout: 0 };
55879
57521
  try {
55880
- await this.#client.cpClient.sandboxWait({
55881
- sandboxId,
55882
- timeout: 0
55883
- });
57522
+ if (isV2) {
57523
+ await this.#client.cpClient.sandboxWaitV2(req);
57524
+ } else {
57525
+ await this.#client.cpClient.sandboxWait(req);
57526
+ }
55884
57527
  } catch (err) {
55885
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.NOT_FOUND)
57528
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.NOT_FOUND)
55886
57529
  throw new NotFoundError(`Sandbox with id: '${sandboxId}' not found`);
55887
57530
  throw err;
55888
57531
  }
55889
- return new Sandbox2(this.#client, sandboxId);
57532
+ return new Sandbox2(this.#client, sandboxId, { isV2 });
55890
57533
  }
55891
57534
  /** Get a running {@link Sandbox} by name from a deployed {@link App}.
55892
57535
  *
@@ -55907,7 +57550,7 @@ var SandboxService = class {
55907
57550
  });
55908
57551
  return new Sandbox2(this.#client, resp.sandboxId);
55909
57552
  } catch (err) {
55910
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.NOT_FOUND)
57553
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.NOT_FOUND)
55911
57554
  throw new NotFoundError(
55912
57555
  `Sandbox with name '${name}' not found in App '${appName}'`
55913
57556
  );
@@ -55942,7 +57585,7 @@ var SandboxService = class {
55942
57585
  }
55943
57586
  beforeTimestamp = resp.sandboxes[resp.sandboxes.length - 1].createdAt;
55944
57587
  } catch (err) {
55945
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.INVALID_ARGUMENT) {
57588
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.INVALID_ARGUMENT) {
55946
57589
  throw new InvalidError(err.details || err.message);
55947
57590
  }
55948
57591
  throw err;
@@ -56062,6 +57705,7 @@ var Sandbox2 = class _Sandbox {
56062
57705
  #commandRouterClient;
56063
57706
  #commandRouterClientPromise;
56064
57707
  #attached = true;
57708
+ #filesystem;
56065
57709
  /** @ignore */
56066
57710
  constructor(client2, sandboxId, params = {}) {
56067
57711
  this.#client = client2;
@@ -56117,6 +57761,13 @@ var Sandbox2 = class _Sandbox {
56117
57761
  }
56118
57762
  return this.#stderr;
56119
57763
  }
57764
+ get filesystem() {
57765
+ this.#ensureAttached();
57766
+ if (!this.#filesystem) {
57767
+ this.#filesystem = new SandboxFilesystem(this);
57768
+ }
57769
+ return this.#filesystem;
57770
+ }
56120
57771
  /** Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in {@link SandboxService#list Sandbox.list}. */
56121
57772
  async setTags(tags) {
56122
57773
  this.#ensureAttached();
@@ -56132,7 +57783,7 @@ var Sandbox2 = class _Sandbox {
56132
57783
  tags: tagsList
56133
57784
  });
56134
57785
  } catch (err) {
56135
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.INVALID_ARGUMENT) {
57786
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.INVALID_ARGUMENT) {
56136
57787
  throw new InvalidError(err.details || err.message);
56137
57788
  }
56138
57789
  throw err;
@@ -56148,7 +57799,7 @@ var Sandbox2 = class _Sandbox {
56148
57799
  sandboxId: this.sandboxId
56149
57800
  });
56150
57801
  } catch (err) {
56151
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.INVALID_ARGUMENT) {
57802
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.INVALID_ARGUMENT) {
56152
57803
  throw new InvalidError(err.details || err.message);
56153
57804
  }
56154
57805
  throw err;
@@ -56175,6 +57826,10 @@ var Sandbox2 = class _Sandbox {
56175
57826
  }
56176
57827
  /**
56177
57828
  * Open a file in the Sandbox filesystem.
57829
+ *
57830
+ * @deprecated Use {@link SandboxFilesystem} methods: `sandbox.filesystem.readBytes()`,
57831
+ * `writeBytes()`, or `copyToLocal()` instead for improved reliability.
57832
+ *
56178
57833
  * @param path - Path to the file to open
56179
57834
  * @param mode - File open mode (r, w, a, r+, w+, a+)
56180
57835
  * @returns Promise that resolves to a {@link SandboxFile}
@@ -56285,7 +57940,7 @@ var Sandbox2 = class _Sandbox {
56285
57940
  this.#taskId = resp.taskId;
56286
57941
  return this.#taskId;
56287
57942
  }
56288
- await (0, import_promises2.setTimeout)(500);
57943
+ await (0, import_promises3.setTimeout)(500);
56289
57944
  }
56290
57945
  throw new Error(
56291
57946
  `Timed out waiting for task ID for Sandbox ${this.sandboxId}`
@@ -56416,7 +58071,7 @@ var Sandbox2 = class _Sandbox {
56416
58071
  return;
56417
58072
  }
56418
58073
  } catch (err) {
56419
- if (err instanceof import_nice_grpc9.ClientError && err.code === import_nice_grpc9.Status.DEADLINE_EXCEEDED)
58074
+ if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.DEADLINE_EXCEEDED)
56420
58075
  continue;
56421
58076
  throw err;
56422
58077
  }
@@ -56625,6 +58280,16 @@ var ContainerProcess = class {
56625
58280
  this.stderr = toModalReadStream(stderrStream);
56626
58281
  }
56627
58282
  }
58283
+ /**
58284
+ * @ignore
58285
+ * Send stdin EOF directly, bypassing the WritableStream state machine.
58286
+ *
58287
+ * Useful for when an stdin write has failed.
58288
+ */
58289
+ async closeStdin() {
58290
+ await this.#commandRouterClient.execStdinWrite(this.#taskId, this.#execId, 0, new Uint8Array(0), true).catch(() => {
58291
+ });
58292
+ }
56628
58293
  /** Wait for process completion and return the exit code. */
56629
58294
  async wait() {
56630
58295
  const resp = await this.#commandRouterClient.execWait(
@@ -56676,7 +58341,7 @@ async function* outputStreamSb(cpClient, sandboxId, fileDescriptor, signal) {
56676
58341
  }
56677
58342
  if (isRetryableGrpc(err) && retriesRemaining > 0) {
56678
58343
  try {
56679
- await (0, import_promises2.setTimeout)(delayMs, void 0, { signal });
58344
+ await (0, import_promises3.setTimeout)(delayMs, void 0, { signal });
56680
58345
  } catch {
56681
58346
  return;
56682
58347
  }
@@ -56750,127 +58415,6 @@ function encodeIfString(chunk) {
56750
58415
  return typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
56751
58416
  }
56752
58417
 
56753
- // src/volume.ts
56754
- var import_nice_grpc10 = require("nice-grpc");
56755
- var VolumeService = class {
56756
- #client;
56757
- constructor(client2) {
56758
- this.#client = client2;
56759
- }
56760
- /**
56761
- * Reference a {@link Volume} by its name.
56762
- */
56763
- async fromName(name, params) {
56764
- try {
56765
- const resp = await this.#client.cpClient.volumeGetOrCreate({
56766
- deploymentName: name,
56767
- environmentName: this.#client.environmentName(params?.environment),
56768
- objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */
56769
- });
56770
- this.#client.logger.debug(
56771
- "Retrieved Volume",
56772
- "volume_id",
56773
- resp.volumeId,
56774
- "volume_name",
56775
- name
56776
- );
56777
- return new Volume(resp.volumeId, name);
56778
- } catch (err) {
56779
- if (err instanceof import_nice_grpc10.ClientError && err.code === import_nice_grpc10.Status.NOT_FOUND)
56780
- throw new NotFoundError(err.details);
56781
- throw err;
56782
- }
56783
- }
56784
- /**
56785
- * Create a nameless, temporary {@link Volume}.
56786
- * It persists until closeEphemeral() is called, or the process exits.
56787
- */
56788
- async ephemeral(params = {}) {
56789
- const resp = await this.#client.cpClient.volumeGetOrCreate({
56790
- objectCreationType: 5 /* OBJECT_CREATION_TYPE_EPHEMERAL */,
56791
- environmentName: this.#client.environmentName(params.environment)
56792
- });
56793
- this.#client.logger.debug(
56794
- "Created ephemeral Volume",
56795
- "volume_id",
56796
- resp.volumeId
56797
- );
56798
- const ephemeralHbManager = new EphemeralHeartbeatManager(
56799
- () => this.#client.cpClient.volumeHeartbeat({ volumeId: resp.volumeId })
56800
- );
56801
- return new Volume(resp.volumeId, void 0, false, ephemeralHbManager);
56802
- }
56803
- /**
56804
- * Delete a named {@link Volume}.
56805
- *
56806
- * Warning: Deletion is irreversible and will affect any Apps currently using the Volume.
56807
- */
56808
- async delete(name, params) {
56809
- try {
56810
- const volume = await this.fromName(name, {
56811
- environment: params?.environment,
56812
- createIfMissing: false
56813
- });
56814
- await this.#client.cpClient.volumeDelete({
56815
- volumeId: volume.volumeId
56816
- });
56817
- this.#client.logger.debug(
56818
- "Deleted Volume",
56819
- "volume_name",
56820
- name,
56821
- "volume_id",
56822
- volume.volumeId
56823
- );
56824
- } catch (err) {
56825
- const isNotFound = err instanceof NotFoundError || err instanceof import_nice_grpc10.ClientError && err.code === import_nice_grpc10.Status.NOT_FOUND;
56826
- if (isNotFound && params?.allowMissing) {
56827
- return;
56828
- }
56829
- throw err;
56830
- }
56831
- }
56832
- };
56833
- var Volume = class _Volume {
56834
- volumeId;
56835
- name;
56836
- _readOnly = false;
56837
- #ephemeralHbManager;
56838
- /** @ignore */
56839
- constructor(volumeId, name, readOnly = false, ephemeralHbManager) {
56840
- this.volumeId = volumeId;
56841
- this.name = name;
56842
- this._readOnly = readOnly;
56843
- this.#ephemeralHbManager = ephemeralHbManager;
56844
- }
56845
- /**
56846
- * @deprecated Use {@link VolumeService#fromName client.volumes.fromName()} instead.
56847
- */
56848
- static async fromName(name, options) {
56849
- return getDefaultClient().volumes.fromName(name, options);
56850
- }
56851
- /** Configure Volume to mount as read-only. */
56852
- readOnly() {
56853
- return new _Volume(this.volumeId, this.name, true, this.#ephemeralHbManager);
56854
- }
56855
- get isReadOnly() {
56856
- return this._readOnly;
56857
- }
56858
- /**
56859
- * @deprecated Use {@link VolumeService#ephemeral client.volumes.ephemeral()} instead.
56860
- */
56861
- static async ephemeral(options = {}) {
56862
- return getDefaultClient().volumes.ephemeral(options);
56863
- }
56864
- /** Delete the ephemeral Volume. Only usable with emphemeral Volumes. */
56865
- closeEphemeral() {
56866
- if (this.#ephemeralHbManager) {
56867
- this.#ephemeralHbManager.stop();
56868
- } else {
56869
- throw new InvalidError("Volume is not ephemeral.");
56870
- }
56871
- }
56872
- };
56873
-
56874
58418
  // src/auth_token_manager.ts
56875
58419
  var REFRESH_WINDOW = 5 * 60;
56876
58420
  var DEFAULT_EXPIRY_OFFSET = 20 * 60;
@@ -56880,9 +58424,9 @@ var AuthTokenManager = class {
56880
58424
  currentToken = "";
56881
58425
  tokenExpiry = 0;
56882
58426
  refreshPromise = null;
56883
- constructor(client2, logger) {
58427
+ constructor(client2, logger2) {
56884
58428
  this.client = client2;
56885
- this.logger = logger;
58429
+ this.logger = logger2;
56886
58430
  }
56887
58431
  /**
56888
58432
  * Returns a valid auth token.
@@ -56990,113 +58534,7 @@ var AuthTokenManager = class {
56990
58534
 
56991
58535
  // src/version.ts
56992
58536
  function getSDKVersion() {
56993
- return true ? "0.7.5" : "0.0.0";
56994
- }
56995
-
56996
- // src/logger.ts
56997
- var LOG_LEVELS = {
56998
- debug: 0,
56999
- info: 1,
57000
- warn: 2,
57001
- error: 3
57002
- };
57003
- function parseLogLevel(level) {
57004
- if (!level) {
57005
- return "warn";
57006
- }
57007
- const normalized = level.toLowerCase();
57008
- if (normalized === "debug" || normalized === "info" || normalized === "warn" || normalized === "warning" || normalized === "error") {
57009
- return normalized === "warning" ? "warn" : normalized;
57010
- }
57011
- throw new Error(
57012
- `Invalid log level value: "${level}" (must be debug, info, warn, or error)`
57013
- );
57014
- }
57015
- var DefaultLogger = class {
57016
- levelValue;
57017
- constructor(level = "warn") {
57018
- this.levelValue = LOG_LEVELS[level];
57019
- }
57020
- debug(message, ...args) {
57021
- if (this.levelValue <= LOG_LEVELS.debug) {
57022
- console.log(this.formatMessage("DEBUG", message, args));
57023
- }
57024
- }
57025
- info(message, ...args) {
57026
- if (this.levelValue <= LOG_LEVELS.info) {
57027
- console.log(this.formatMessage("INFO", message, args));
57028
- }
57029
- }
57030
- warn(message, ...args) {
57031
- if (this.levelValue <= LOG_LEVELS.warn) {
57032
- console.warn(this.formatMessage("WARN", message, args));
57033
- }
57034
- }
57035
- error(message, ...args) {
57036
- if (this.levelValue <= LOG_LEVELS.error) {
57037
- console.error(this.formatMessage("ERROR", message, args));
57038
- }
57039
- }
57040
- formatMessage(level, message, args) {
57041
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
57042
- let formatted = `time=${timestamp} level=${level} msg="${message}"`;
57043
- if (args.length > 0) {
57044
- for (let i = 0; i < args.length; i += 2) {
57045
- if (i + 1 < args.length) {
57046
- const key = args[i];
57047
- const value = args[i + 1];
57048
- formatted += ` ${key}=${this.formatValue(value)}`;
57049
- }
57050
- }
57051
- }
57052
- return formatted;
57053
- }
57054
- formatValue(value) {
57055
- if (typeof value === "string") {
57056
- return value.includes(" ") ? `"${value}"` : value;
57057
- }
57058
- if (value instanceof Error) {
57059
- return `"${value.message}"`;
57060
- }
57061
- if (Array.isArray(value)) {
57062
- return `[${value.join(",")}]`;
57063
- }
57064
- return String(value);
57065
- }
57066
- };
57067
- var FilteredLogger = class {
57068
- constructor(logger, level) {
57069
- this.logger = logger;
57070
- this.levelValue = LOG_LEVELS[level];
57071
- }
57072
- levelValue;
57073
- debug(message, ...args) {
57074
- if (this.levelValue <= LOG_LEVELS.debug) {
57075
- this.logger.debug(message, ...args);
57076
- }
57077
- }
57078
- info(message, ...args) {
57079
- if (this.levelValue <= LOG_LEVELS.info) {
57080
- this.logger.info(message, ...args);
57081
- }
57082
- }
57083
- warn(message, ...args) {
57084
- if (this.levelValue <= LOG_LEVELS.warn) {
57085
- this.logger.warn(message, ...args);
57086
- }
57087
- }
57088
- error(message, ...args) {
57089
- if (this.levelValue <= LOG_LEVELS.error) {
57090
- this.logger.error(message, ...args);
57091
- }
57092
- }
57093
- };
57094
- function createLogger(logger, logLevel = "") {
57095
- const level = parseLogLevel(logLevel);
57096
- if (logger) {
57097
- return new FilteredLogger(logger, level);
57098
- }
57099
- return new DefaultLogger(level);
58537
+ return true ? "0.7.6" : "0.0.0";
57100
58538
  }
57101
58539
 
57102
58540
  // src/client.ts
@@ -57183,7 +58621,7 @@ var ModalClient2 = class {
57183
58621
  return getSDKVersion();
57184
58622
  }
57185
58623
  createClient(profile) {
57186
- const channel = (0, import_nice_grpc11.createChannel)(profile.serverUrl, void 0, {
58624
+ const channel = (0, import_nice_grpc13.createChannel)(profile.serverUrl, void 0, {
57187
58625
  "grpc.max_receive_message_length": 100 * 1024 * 1024,
57188
58626
  "grpc.max_send_message_length": 100 * 1024 * 1024,
57189
58627
  "grpc-node.flow_control_window": 64 * 1024 * 1024,
@@ -57191,7 +58629,7 @@ var ModalClient2 = class {
57191
58629
  "grpc.keepalive_timeout_ms": 1e4,
57192
58630
  "grpc.keepalive_permit_without_calls": 1
57193
58631
  });
57194
- let factory = (0, import_nice_grpc11.createClientFactory)().use(this.authMiddleware(profile)).use(this.retryMiddleware()).use(timeoutMiddleware);
58632
+ let factory = (0, import_nice_grpc13.createClientFactory)().use(this.authMiddleware(profile)).use(this.retryMiddleware()).use(timeoutMiddleware);
57195
58633
  for (const middleware of this.customMiddleware) {
57196
58634
  factory = factory.use(middleware);
57197
58635
  }
@@ -57199,7 +58637,7 @@ var ModalClient2 = class {
57199
58637
  }
57200
58638
  /** Middleware to retry transient errors and timeouts for unary requests. */
57201
58639
  retryMiddleware() {
57202
- const logger = this.logger;
58640
+ const logger2 = this.logger;
57203
58641
  const maxThrottleWaitSecs = this.profile.maxThrottleWaitSecs;
57204
58642
  return async function* retryMiddleware(call, options) {
57205
58643
  const {
@@ -57225,9 +58663,9 @@ var ModalClient2 = class {
57225
58663
  let delayMs = baseDelay;
57226
58664
  let throttleRetries = 0;
57227
58665
  let lastServerRetryWarnTime = 0;
57228
- logger.debug("Sending gRPC request", "method", call.method.path);
58666
+ logger2.debug("Sending gRPC request", "method", call.method.path);
57229
58667
  while (true) {
57230
- const metadata = new import_nice_grpc11.Metadata(restOptions.metadata ?? {});
58668
+ const metadata = new import_nice_grpc13.Metadata(restOptions.metadata ?? {});
57231
58669
  metadata.set("x-idempotency-key", idempotencyKey);
57232
58670
  metadata.set("x-retry-attempt", String(attempt));
57233
58671
  metadata.set("x-throttle-retry-attempt", String(throttleRetries));
@@ -57266,7 +58704,7 @@ var ModalClient2 = class {
57266
58704
  const serverDelaySecs = serverDelayMs / 1e3;
57267
58705
  const elapsedSecs = (Date.now() - startTime) / 1e3;
57268
58706
  if (maxThrottleWaitSecs && elapsedSecs + serverDelaySecs >= maxThrottleWaitSecs) {
57269
- logger.debug(
58707
+ logger2.debug(
57270
58708
  "Max throttle wait exceeded, not retrying",
57271
58709
  "method",
57272
58710
  call.method.path,
@@ -57281,7 +58719,7 @@ var ModalClient2 = class {
57281
58719
  );
57282
58720
  throw err;
57283
58721
  }
57284
- logger.debug(
58722
+ logger2.debug(
57285
58723
  "Server requested retry delay",
57286
58724
  "method",
57287
58725
  call.method.path,
@@ -57297,8 +58735,8 @@ var ModalClient2 = class {
57297
58735
  const now = Date.now();
57298
58736
  if (!lastServerRetryWarnTime || now - lastServerRetryWarnTime >= SERVER_RETRY_WARNING_INTERVAL_MS) {
57299
58737
  lastServerRetryWarnTime = now;
57300
- const clientError2 = err instanceof import_nice_grpc11.ClientError ? err : null;
57301
- logger.warn(
58738
+ const clientError2 = err instanceof import_nice_grpc13.ClientError ? err : null;
58739
+ logger2.warn(
57302
58740
  "Server requested retry delay. Retrying...",
57303
58741
  "status",
57304
58742
  clientError2?.code ?? "unknown",
@@ -57312,10 +58750,10 @@ var ModalClient2 = class {
57312
58750
  await sleep(serverDelayMs, signal);
57313
58751
  continue;
57314
58752
  }
57315
- const clientError = err instanceof import_nice_grpc11.ClientError ? err : null;
58753
+ const clientError = err instanceof import_nice_grpc13.ClientError ? err : null;
57316
58754
  if (!clientError || !retryableCodes.has(clientError.code) || attempt >= retries) {
57317
58755
  if (attempt === retries && attempt > 0) {
57318
- logger.debug(
58756
+ logger2.debug(
57319
58757
  "Final retry attempt failed",
57320
58758
  "error",
57321
58759
  err,
@@ -57332,7 +58770,7 @@ var ModalClient2 = class {
57332
58770
  throw err;
57333
58771
  }
57334
58772
  if (attempt > 0) {
57335
- logger.debug(
58773
+ logger2.debug(
57336
58774
  "Retryable failure",
57337
58775
  "error",
57338
58776
  err,
@@ -57370,7 +58808,7 @@ var ModalClient2 = class {
57370
58808
  );
57371
58809
  }
57372
58810
  const { tokenId, tokenSecret } = profile;
57373
- options.metadata ??= new import_nice_grpc11.Metadata();
58811
+ options.metadata ??= new import_nice_grpc13.Metadata();
57374
58812
  options.metadata.set(
57375
58813
  "x-modal-client-type",
57376
58814
  String(8 /* CLIENT_TYPE_LIBMODAL_JS */)
@@ -57415,20 +58853,20 @@ var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
57415
58853
  origSignal?.removeEventListener("abort", abortListener);
57416
58854
  clearTimeout(timer);
57417
58855
  if (timedOut) {
57418
- throw new import_nice_grpc11.ClientError(
58856
+ throw new import_nice_grpc13.ClientError(
57419
58857
  call.method.path,
57420
- import_nice_grpc11.Status.DEADLINE_EXCEEDED,
58858
+ import_nice_grpc13.Status.DEADLINE_EXCEEDED,
57421
58859
  `Timed out after ${timeoutMs}ms`
57422
58860
  );
57423
58861
  }
57424
58862
  }
57425
58863
  };
57426
58864
  var retryableGrpcStatusCodes = /* @__PURE__ */ new Set([
57427
- import_nice_grpc11.Status.DEADLINE_EXCEEDED,
57428
- import_nice_grpc11.Status.UNAVAILABLE,
57429
- import_nice_grpc11.Status.CANCELLED,
57430
- import_nice_grpc11.Status.INTERNAL,
57431
- import_nice_grpc11.Status.UNKNOWN
58865
+ import_nice_grpc13.Status.DEADLINE_EXCEEDED,
58866
+ import_nice_grpc13.Status.UNAVAILABLE,
58867
+ import_nice_grpc13.Status.CANCELLED,
58868
+ import_nice_grpc13.Status.INTERNAL,
58869
+ import_nice_grpc13.Status.UNKNOWN
57432
58870
  ]);
57433
58871
  var SERVER_RETRY_WARNING_INTERVAL_MS = 3e4;
57434
58872
  function getServerRetryPolicy(statusDetails) {
@@ -57445,7 +58883,7 @@ function getServerRetryPolicy(statusDetails) {
57445
58883
  return null;
57446
58884
  }
57447
58885
  function isRetryableGrpc(err) {
57448
- if (err instanceof import_nice_grpc11.ClientError) {
58886
+ if (err instanceof import_nice_grpc13.ClientError) {
57449
58887
  return retryableGrpcStatusCodes.has(err.code);
57450
58888
  }
57451
58889
  return false;
@@ -57514,7 +58952,7 @@ var AppService = class {
57514
58952
  );
57515
58953
  return new App2(resp.appId, name);
57516
58954
  } catch (err) {
57517
- if (err instanceof import_nice_grpc12.ClientError && err.code === import_nice_grpc12.Status.NOT_FOUND)
58955
+ if (err instanceof import_nice_grpc14.ClientError && err.code === import_nice_grpc14.Status.NOT_FOUND)
57518
58956
  throw new NotFoundError(`App '${name}' not found`);
57519
58957
  throw err;
57520
58958
  }
@@ -57615,6 +59053,15 @@ var App2 = class {
57615
59053
  Retries,
57616
59054
  Sandbox,
57617
59055
  SandboxFile,
59056
+ SandboxFilesystem,
59057
+ SandboxFilesystemDirectoryNotEmptyError,
59058
+ SandboxFilesystemError,
59059
+ SandboxFilesystemFileTooLargeError,
59060
+ SandboxFilesystemIsADirectoryError,
59061
+ SandboxFilesystemNotADirectoryError,
59062
+ SandboxFilesystemNotFoundError,
59063
+ SandboxFilesystemPathAlreadyExistsError,
59064
+ SandboxFilesystemPermissionError,
57618
59065
  SandboxService,
57619
59066
  SandboxTimeoutError,
57620
59067
  Secret,