modal 0.10.2-dev.6 → 0.10.2-dev.8

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
@@ -42,6 +42,7 @@ __export(index_exports, {
42
42
  ConflictError: () => ConflictError,
43
43
  ContainerProcess: () => ContainerProcess2,
44
44
  ExecutionError: () => ExecutionError,
45
+ ExperimentalOutboundPolicy: () => ExperimentalOutboundPolicy,
45
46
  FunctionCall: () => FunctionCall,
46
47
  FunctionCallLogsManager: () => FunctionCallLogsManager,
47
48
  FunctionCallService: () => FunctionCallService,
@@ -55,7 +56,6 @@ __export(index_exports, {
55
56
  InvalidError: () => InvalidError,
56
57
  ModalClient: () => ModalClient,
57
58
  NotFoundError: () => NotFoundError,
58
- OutboundPolicy: () => OutboundPolicy2,
59
59
  Probe: () => Probe2,
60
60
  Proxy: () => Proxy3,
61
61
  ProxyService: () => ProxyService,
@@ -75,6 +75,7 @@ __export(index_exports, {
75
75
  SandboxFilesystemNotFoundError: () => SandboxFilesystemNotFoundError,
76
76
  SandboxFilesystemPathAlreadyExistsError: () => SandboxFilesystemPathAlreadyExistsError,
77
77
  SandboxFilesystemPermissionError: () => SandboxFilesystemPermissionError,
78
+ SandboxLogsManager: () => SandboxLogsManager,
78
79
  SandboxService: () => SandboxService,
79
80
  SandboxSnapshot: () => SandboxSnapshot,
80
81
  SandboxSnapshotService: () => SandboxSnapshotService,
@@ -5584,7 +5585,7 @@ var AppGetInfoResponse = {
5584
5585
  }
5585
5586
  };
5586
5587
  function createBaseAppGetInfoResponse_FunctionInfoSummary() {
5587
- return { gpuConfig: [], schedule: void 0, webFunction: false, requiresProxyAuth: void 0 };
5588
+ return { gpuConfig: [], schedule: void 0, webFunction: false, requiresProxyAuth: void 0, isSessioned: false };
5588
5589
  }
5589
5590
  var AppGetInfoResponse_FunctionInfoSummary = {
5590
5591
  encode(message, writer = new BinaryWriter()) {
@@ -5600,6 +5601,9 @@ var AppGetInfoResponse_FunctionInfoSummary = {
5600
5601
  if (message.requiresProxyAuth !== void 0) {
5601
5602
  writer.uint32(32).bool(message.requiresProxyAuth);
5602
5603
  }
5604
+ if (message.isSessioned !== false) {
5605
+ writer.uint32(40).bool(message.isSessioned);
5606
+ }
5603
5607
  return writer;
5604
5608
  },
5605
5609
  decode(input, length) {
@@ -5637,6 +5641,13 @@ var AppGetInfoResponse_FunctionInfoSummary = {
5637
5641
  message.requiresProxyAuth = reader.bool();
5638
5642
  continue;
5639
5643
  }
5644
+ case 5: {
5645
+ if (tag !== 40) {
5646
+ break;
5647
+ }
5648
+ message.isSessioned = reader.bool();
5649
+ continue;
5650
+ }
5640
5651
  }
5641
5652
  if ((tag & 7) === 4 || tag === 0) {
5642
5653
  break;
@@ -5650,7 +5661,8 @@ var AppGetInfoResponse_FunctionInfoSummary = {
5650
5661
  gpuConfig: globalThis.Array.isArray(object?.gpuConfig) ? object.gpuConfig.map((e) => GPUConfig.fromJSON(e)) : [],
5651
5662
  schedule: isSet5(object.schedule) ? Schedule.fromJSON(object.schedule) : void 0,
5652
5663
  webFunction: isSet5(object.webFunction) ? globalThis.Boolean(object.webFunction) : false,
5653
- requiresProxyAuth: isSet5(object.requiresProxyAuth) ? globalThis.Boolean(object.requiresProxyAuth) : void 0
5664
+ requiresProxyAuth: isSet5(object.requiresProxyAuth) ? globalThis.Boolean(object.requiresProxyAuth) : void 0,
5665
+ isSessioned: isSet5(object.isSessioned) ? globalThis.Boolean(object.isSessioned) : false
5654
5666
  };
5655
5667
  },
5656
5668
  toJSON(message) {
@@ -5667,6 +5679,9 @@ var AppGetInfoResponse_FunctionInfoSummary = {
5667
5679
  if (message.requiresProxyAuth !== void 0) {
5668
5680
  obj.requiresProxyAuth = message.requiresProxyAuth;
5669
5681
  }
5682
+ if (message.isSessioned !== false) {
5683
+ obj.isSessioned = message.isSessioned;
5684
+ }
5670
5685
  return obj;
5671
5686
  },
5672
5687
  create(base) {
@@ -5678,6 +5693,7 @@ var AppGetInfoResponse_FunctionInfoSummary = {
5678
5693
  message.schedule = object.schedule !== void 0 && object.schedule !== null ? Schedule.fromPartial(object.schedule) : void 0;
5679
5694
  message.webFunction = object.webFunction ?? false;
5680
5695
  message.requiresProxyAuth = object.requiresProxyAuth ?? void 0;
5696
+ message.isSessioned = object.isSessioned ?? false;
5681
5697
  return message;
5682
5698
  }
5683
5699
  };
@@ -48067,6 +48083,108 @@ var SecretDeleteRequest = {
48067
48083
  return message;
48068
48084
  }
48069
48085
  };
48086
+ function createBaseSecretGetInfoRequest() {
48087
+ return { secretId: "" };
48088
+ }
48089
+ var SecretGetInfoRequest = {
48090
+ encode(message, writer = new BinaryWriter()) {
48091
+ if (message.secretId !== "") {
48092
+ writer.uint32(10).string(message.secretId);
48093
+ }
48094
+ return writer;
48095
+ },
48096
+ decode(input, length) {
48097
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
48098
+ let end = length === void 0 ? reader.len : reader.pos + length;
48099
+ const message = createBaseSecretGetInfoRequest();
48100
+ while (reader.pos < end) {
48101
+ const tag = reader.uint32();
48102
+ switch (tag >>> 3) {
48103
+ case 1: {
48104
+ if (tag !== 10) {
48105
+ break;
48106
+ }
48107
+ message.secretId = reader.string();
48108
+ continue;
48109
+ }
48110
+ }
48111
+ if ((tag & 7) === 4 || tag === 0) {
48112
+ break;
48113
+ }
48114
+ reader.skip(tag & 7);
48115
+ }
48116
+ return message;
48117
+ },
48118
+ fromJSON(object) {
48119
+ return { secretId: isSet5(object.secretId) ? globalThis.String(object.secretId) : "" };
48120
+ },
48121
+ toJSON(message) {
48122
+ const obj = {};
48123
+ if (message.secretId !== "") {
48124
+ obj.secretId = message.secretId;
48125
+ }
48126
+ return obj;
48127
+ },
48128
+ create(base) {
48129
+ return SecretGetInfoRequest.fromPartial(base ?? {});
48130
+ },
48131
+ fromPartial(object) {
48132
+ const message = createBaseSecretGetInfoRequest();
48133
+ message.secretId = object.secretId ?? "";
48134
+ return message;
48135
+ }
48136
+ };
48137
+ function createBaseSecretGetInfoResponse() {
48138
+ return { metadata: void 0 };
48139
+ }
48140
+ var SecretGetInfoResponse = {
48141
+ encode(message, writer = new BinaryWriter()) {
48142
+ if (message.metadata !== void 0) {
48143
+ SecretMetadata.encode(message.metadata, writer.uint32(10).fork()).join();
48144
+ }
48145
+ return writer;
48146
+ },
48147
+ decode(input, length) {
48148
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
48149
+ let end = length === void 0 ? reader.len : reader.pos + length;
48150
+ const message = createBaseSecretGetInfoResponse();
48151
+ while (reader.pos < end) {
48152
+ const tag = reader.uint32();
48153
+ switch (tag >>> 3) {
48154
+ case 1: {
48155
+ if (tag !== 10) {
48156
+ break;
48157
+ }
48158
+ message.metadata = SecretMetadata.decode(reader, reader.uint32());
48159
+ continue;
48160
+ }
48161
+ }
48162
+ if ((tag & 7) === 4 || tag === 0) {
48163
+ break;
48164
+ }
48165
+ reader.skip(tag & 7);
48166
+ }
48167
+ return message;
48168
+ },
48169
+ fromJSON(object) {
48170
+ return { metadata: isSet5(object.metadata) ? SecretMetadata.fromJSON(object.metadata) : void 0 };
48171
+ },
48172
+ toJSON(message) {
48173
+ const obj = {};
48174
+ if (message.metadata !== void 0) {
48175
+ obj.metadata = SecretMetadata.toJSON(message.metadata);
48176
+ }
48177
+ return obj;
48178
+ },
48179
+ create(base) {
48180
+ return SecretGetInfoResponse.fromPartial(base ?? {});
48181
+ },
48182
+ fromPartial(object) {
48183
+ const message = createBaseSecretGetInfoResponse();
48184
+ message.metadata = object.metadata !== void 0 && object.metadata !== null ? SecretMetadata.fromPartial(object.metadata) : void 0;
48185
+ return message;
48186
+ }
48187
+ };
48070
48188
  function createBaseSecretGetOrCreateRequest() {
48071
48189
  return { deploymentName: "", environmentName: "", objectCreationType: 0, envDict: {}, appId: "", requiredKeys: [] };
48072
48190
  }
@@ -48613,7 +48731,7 @@ var SecretListResponse = {
48613
48731
  }
48614
48732
  };
48615
48733
  function createBaseSecretMetadata() {
48616
- return { name: "", creationInfo: void 0, keys: [] };
48734
+ return { name: "", creationInfo: void 0, keys: [], environmentName: "" };
48617
48735
  }
48618
48736
  var SecretMetadata = {
48619
48737
  encode(message, writer = new BinaryWriter()) {
@@ -48626,6 +48744,9 @@ var SecretMetadata = {
48626
48744
  for (const v of message.keys) {
48627
48745
  writer.uint32(26).string(v);
48628
48746
  }
48747
+ if (message.environmentName !== "") {
48748
+ writer.uint32(34).string(message.environmentName);
48749
+ }
48629
48750
  return writer;
48630
48751
  },
48631
48752
  decode(input, length) {
@@ -48656,6 +48777,13 @@ var SecretMetadata = {
48656
48777
  message.keys.push(reader.string());
48657
48778
  continue;
48658
48779
  }
48780
+ case 4: {
48781
+ if (tag !== 34) {
48782
+ break;
48783
+ }
48784
+ message.environmentName = reader.string();
48785
+ continue;
48786
+ }
48659
48787
  }
48660
48788
  if ((tag & 7) === 4 || tag === 0) {
48661
48789
  break;
@@ -48668,7 +48796,8 @@ var SecretMetadata = {
48668
48796
  return {
48669
48797
  name: isSet5(object.name) ? globalThis.String(object.name) : "",
48670
48798
  creationInfo: isSet5(object.creationInfo) ? CreationInfo.fromJSON(object.creationInfo) : void 0,
48671
- keys: globalThis.Array.isArray(object?.keys) ? object.keys.map((e) => globalThis.String(e)) : []
48799
+ keys: globalThis.Array.isArray(object?.keys) ? object.keys.map((e) => globalThis.String(e)) : [],
48800
+ environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : ""
48672
48801
  };
48673
48802
  },
48674
48803
  toJSON(message) {
@@ -48682,6 +48811,9 @@ var SecretMetadata = {
48682
48811
  if (message.keys?.length) {
48683
48812
  obj.keys = message.keys;
48684
48813
  }
48814
+ if (message.environmentName !== "") {
48815
+ obj.environmentName = message.environmentName;
48816
+ }
48685
48817
  return obj;
48686
48818
  },
48687
48819
  create(base) {
@@ -48692,6 +48824,7 @@ var SecretMetadata = {
48692
48824
  message.name = object.name ?? "";
48693
48825
  message.creationInfo = object.creationInfo !== void 0 && object.creationInfo !== null ? CreationInfo.fromPartial(object.creationInfo) : void 0;
48694
48826
  message.keys = object.keys?.map((e) => e) || [];
48827
+ message.environmentName = object.environmentName ?? "";
48695
48828
  return message;
48696
48829
  }
48697
48830
  };
@@ -58546,6 +58679,74 @@ var WebhookTokenListResponse = {
58546
58679
  return message;
58547
58680
  }
58548
58681
  };
58682
+ function createBaseWebhookTokenUpdateRequest() {
58683
+ return { tokenId: "", name: void 0 };
58684
+ }
58685
+ var WebhookTokenUpdateRequest = {
58686
+ encode(message, writer = new BinaryWriter()) {
58687
+ if (message.tokenId !== "") {
58688
+ writer.uint32(10).string(message.tokenId);
58689
+ }
58690
+ if (message.name !== void 0) {
58691
+ writer.uint32(18).string(message.name);
58692
+ }
58693
+ return writer;
58694
+ },
58695
+ decode(input, length) {
58696
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
58697
+ let end = length === void 0 ? reader.len : reader.pos + length;
58698
+ const message = createBaseWebhookTokenUpdateRequest();
58699
+ while (reader.pos < end) {
58700
+ const tag = reader.uint32();
58701
+ switch (tag >>> 3) {
58702
+ case 1: {
58703
+ if (tag !== 10) {
58704
+ break;
58705
+ }
58706
+ message.tokenId = reader.string();
58707
+ continue;
58708
+ }
58709
+ case 2: {
58710
+ if (tag !== 18) {
58711
+ break;
58712
+ }
58713
+ message.name = reader.string();
58714
+ continue;
58715
+ }
58716
+ }
58717
+ if ((tag & 7) === 4 || tag === 0) {
58718
+ break;
58719
+ }
58720
+ reader.skip(tag & 7);
58721
+ }
58722
+ return message;
58723
+ },
58724
+ fromJSON(object) {
58725
+ return {
58726
+ tokenId: isSet5(object.tokenId) ? globalThis.String(object.tokenId) : "",
58727
+ name: isSet5(object.name) ? globalThis.String(object.name) : void 0
58728
+ };
58729
+ },
58730
+ toJSON(message) {
58731
+ const obj = {};
58732
+ if (message.tokenId !== "") {
58733
+ obj.tokenId = message.tokenId;
58734
+ }
58735
+ if (message.name !== void 0) {
58736
+ obj.name = message.name;
58737
+ }
58738
+ return obj;
58739
+ },
58740
+ create(base) {
58741
+ return WebhookTokenUpdateRequest.fromPartial(base ?? {});
58742
+ },
58743
+ fromPartial(object) {
58744
+ const message = createBaseWebhookTokenUpdateRequest();
58745
+ message.tokenId = object.tokenId ?? "";
58746
+ message.name = object.name ?? void 0;
58747
+ return message;
58748
+ }
58749
+ };
58549
58750
  function createBaseWorkspaceBillingRatesRequest() {
58550
58751
  return {};
58551
58752
  }
@@ -62076,6 +62277,14 @@ var ModalClientDefinition = {
62076
62277
  responseStream: false,
62077
62278
  options: {}
62078
62279
  },
62280
+ secretGetInfo: {
62281
+ name: "SecretGetInfo",
62282
+ requestType: SecretGetInfoRequest,
62283
+ requestStream: false,
62284
+ responseType: SecretGetInfoResponse,
62285
+ responseStream: false,
62286
+ options: {}
62287
+ },
62079
62288
  secretGetOrCreate: {
62080
62289
  name: "SecretGetOrCreate",
62081
62290
  requestType: SecretGetOrCreateRequest,
@@ -62510,6 +62719,14 @@ var ModalClientDefinition = {
62510
62719
  responseStream: false,
62511
62720
  options: {}
62512
62721
  },
62722
+ webhookTokenUpdate: {
62723
+ name: "WebhookTokenUpdate",
62724
+ requestType: WebhookTokenUpdateRequest,
62725
+ requestStream: false,
62726
+ responseType: WebhookToken,
62727
+ responseStream: false,
62728
+ options: {}
62729
+ },
62513
62730
  /** Workspaces */
62514
62731
  workspaceBillingRates: {
62515
62732
  name: "WorkspaceBillingRates",
@@ -71226,6 +71443,7 @@ var SandboxSnapshotService = class {
71226
71443
  var SB_LOGS_INITIAL_DELAY_MS = 10;
71227
71444
  var SB_LOGS_DELAY_FACTOR = 2;
71228
71445
  var SB_LOGS_MAX_RETRIES = 10;
71446
+ var SB_LOGS_TASK_ID_TIMEOUT_SECONDS = 0.5;
71229
71447
  var TTL_NO_EXPIRY_SENTINEL = -1;
71230
71448
  var CUSTOMER_SUPPLIED_ENCRYPTION_KEY_MIN_LENGTH = 16;
71231
71449
  var CUSTOMER_SUPPLIED_ENCRYPTION_KEY_MAX_LENGTH = 512;
@@ -71275,6 +71493,19 @@ function getSandboxVersion(sandboxId) {
71275
71493
  }
71276
71494
  return "V2" /* V2 */;
71277
71495
  }
71496
+ function sandboxRuntimeToProto(runtime) {
71497
+ switch (runtime) {
71498
+ case void 0:
71499
+ return void 0;
71500
+ case "gvisor":
71501
+ case "vm":
71502
+ return runtime;
71503
+ default:
71504
+ throw new Error(
71505
+ `runtime must be "gvisor" or "vm", got ${JSON.stringify(runtime)}`
71506
+ );
71507
+ }
71508
+ }
71278
71509
  var Probe2 = class _Probe {
71279
71510
  #tcpPort;
71280
71511
  #execArgv;
@@ -71408,6 +71639,7 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
71408
71639
  if (params.workdir && !params.workdir.startsWith("/")) {
71409
71640
  throw new Error(`workdir must be an absolute path, got: ${params.workdir}`);
71410
71641
  }
71642
+ const runtime = sandboxRuntimeToProto(params.runtime);
71411
71643
  const volumeMounts = params.volumes ? Object.entries(params.volumes).map(
71412
71644
  ([mountPath, volume]) => volumeToMountProto(mountPath, volume)
71413
71645
  ) : [];
@@ -71459,16 +71691,16 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
71459
71691
  );
71460
71692
  }
71461
71693
  }
71462
- if (params.outboundPolicy !== void 0) {
71463
- params.outboundPolicy._validate();
71694
+ if (params.experimentalOutboundPolicy !== void 0) {
71695
+ params.experimentalOutboundPolicy._validate();
71464
71696
  if (params.blockNetwork) {
71465
71697
  throw new InvalidError(
71466
- "outboundPolicy cannot be used when blockNetwork is enabled"
71698
+ "experimentalOutboundPolicy cannot be used when blockNetwork is enabled"
71467
71699
  );
71468
71700
  }
71469
71701
  if (params.outboundDomainAllowlist && params.outboundDomainAllowlist.length > 0) {
71470
71702
  throw new InvalidError(
71471
- "outboundPolicy cannot be used with outboundDomainAllowlist"
71703
+ "experimentalOutboundPolicy cannot be used with outboundDomainAllowlist"
71472
71704
  );
71473
71705
  }
71474
71706
  }
@@ -71552,7 +71784,7 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
71552
71784
  idleTimeoutSecs: params.idleTimeoutMs != void 0 ? params.idleTimeoutMs / 1e3 : void 0,
71553
71785
  workdir: params.workdir ?? void 0,
71554
71786
  networkAccess,
71555
- outboundPolicy: params.outboundPolicy?._toProto(),
71787
+ outboundPolicy: params.experimentalOutboundPolicy?._toProto(),
71556
71788
  resources: Resources.create({
71557
71789
  milliCpu,
71558
71790
  milliCpuMax,
@@ -71576,7 +71808,8 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
71576
71808
  includeOidcIdentityToken: params.includeOidcIdentityToken ?? false,
71577
71809
  inboundCidrAllowlist: params.inboundCidrAllowlist ?? [],
71578
71810
  i6pnEnabled: params.i6pn ?? false,
71579
- enableSnapshot: params.experimentalEnableSnapshot ?? false
71811
+ enableSnapshot: params.experimentalEnableSnapshot ?? false,
71812
+ runtime
71580
71813
  }
71581
71814
  });
71582
71815
  }
@@ -71613,7 +71846,10 @@ var SandboxService = class {
71613
71846
  );
71614
71847
  await hydrateSandboxSecrets(
71615
71848
  this.#client,
71616
- [...mergedSecrets, ...params.outboundPolicy?._secrets() ?? []],
71849
+ [
71850
+ ...mergedSecrets,
71851
+ ...params.experimentalOutboundPolicy?._secrets() ?? []
71852
+ ],
71617
71853
  params.cloudBucketMounts
71618
71854
  );
71619
71855
  const mergedParams = {
@@ -71674,7 +71910,10 @@ var SandboxService = class {
71674
71910
  Object.assign(envDict, params.env ?? {});
71675
71911
  await hydrateSandboxSecrets(
71676
71912
  this.#client,
71677
- [...resolvableSecrets, ...params.outboundPolicy?._secrets() ?? []],
71913
+ [
71914
+ ...resolvableSecrets,
71915
+ ...params.experimentalOutboundPolicy?._secrets() ?? []
71916
+ ],
71678
71917
  params.cloudBucketMounts
71679
71918
  );
71680
71919
  const mergedParams = {
@@ -72083,6 +72322,7 @@ function buildTaskSnapshotDirectoryRequestProto(taskId, path2, snapshotId, ttlSe
72083
72322
  var Sandbox2 = class _Sandbox {
72084
72323
  #client;
72085
72324
  sandboxId;
72325
+ #appId;
72086
72326
  #stdin;
72087
72327
  #stdout;
72088
72328
  #stderr;
@@ -72129,6 +72369,25 @@ var Sandbox2 = class _Sandbox {
72129
72369
  }
72130
72370
  return this.#stderr;
72131
72371
  }
72372
+ /**
72373
+ * Access persisted entrypoint logs emitted by this Sandbox.
72374
+ *
72375
+ * Use {@link SandboxLogsManager#fetch fetch()} to read logs from a UTC time
72376
+ * range and {@link SandboxLogsManager#tail tail()} to read the most recent
72377
+ * logs.
72378
+ *
72379
+ * This is separate from {@link Sandbox#stdout stdout} and
72380
+ * {@link Sandbox#stderr stderr}, which expose the Sandbox's live output
72381
+ * streams.
72382
+ */
72383
+ get logs() {
72384
+ return new SandboxLogsManager(
72385
+ this.#client,
72386
+ this.sandboxId,
72387
+ () => this.#getAppId(),
72388
+ () => this.#resolveTaskIdForLogs()
72389
+ );
72390
+ }
72132
72391
  #outputStream(fileDescriptor) {
72133
72392
  if (this.#isV2) {
72134
72393
  this.#ensureAttached();
@@ -72361,8 +72620,11 @@ var Sandbox2 = class _Sandbox {
72361
72620
  }
72362
72621
  return this.#client.cpClient.sandboxWait(req);
72363
72622
  }
72364
- #sandboxGetTaskId(signal) {
72365
- const req = { sandboxId: this.sandboxId };
72623
+ #sandboxGetTaskId(signal, timeout) {
72624
+ const req = SandboxGetTaskIdRequest.create({
72625
+ sandboxId: this.sandboxId,
72626
+ timeout
72627
+ });
72366
72628
  if (this.#isV2) {
72367
72629
  return this.#client.cpClient.sandboxGetTaskIdV2(req, { signal });
72368
72630
  }
@@ -72392,6 +72654,42 @@ var Sandbox2 = class _Sandbox {
72392
72654
  }
72393
72655
  static #maxGetTaskIdAttempts = 600;
72394
72656
  // 5 minutes at 500ms intervals
72657
+ async #getAppId() {
72658
+ if (this.#appId !== void 0) {
72659
+ return this.#appId;
72660
+ }
72661
+ const resp = await this.#sandboxWait(0);
72662
+ const appId = resp.metadata?.appId;
72663
+ if (!appId) {
72664
+ throw new ExecutionError(
72665
+ "Sandbox app ID should have been set during hydration"
72666
+ );
72667
+ }
72668
+ this.#appId = appId;
72669
+ return appId;
72670
+ }
72671
+ async #resolveTaskIdForLogs() {
72672
+ if (this.#taskId !== void 0) {
72673
+ return this.#taskId;
72674
+ }
72675
+ let resp;
72676
+ try {
72677
+ resp = await this.#sandboxGetTaskId(
72678
+ void 0,
72679
+ SB_LOGS_TASK_ID_TIMEOUT_SECONDS
72680
+ );
72681
+ } catch (error) {
72682
+ if (error instanceof import_nice_grpc12.ClientError && error.code === import_nice_grpc12.Status.DEADLINE_EXCEEDED) {
72683
+ throw new ExecutionError("Sandbox task ID is not available yet.");
72684
+ }
72685
+ throw error;
72686
+ }
72687
+ if (!resp.taskId) {
72688
+ throw new ExecutionError("Sandbox task ID is not available.");
72689
+ }
72690
+ this.#taskId = resp.taskId;
72691
+ return this.#taskId;
72692
+ }
72395
72693
  async #getTaskId(signal) {
72396
72694
  if (this.#taskId !== void 0) {
72397
72695
  return this.#taskId;
@@ -72823,14 +73121,16 @@ var Sandbox2 = class _Sandbox {
72823
73121
  /**
72824
73122
  * Replace the outbound policy of a running Sandbox.
72825
73123
  *
73124
+ * EXPERIMENTAL: the API is subject to change.
73125
+ *
72826
73126
  * The new policy replaces all existing policy configuration on the
72827
73127
  * Sandbox; build a policy including any existing rules you want to keep.
72828
73128
  *
72829
- * Only Sandboxes created with an `outboundPolicy` can be updated this
73129
+ * Only Sandboxes created with an `experimentalOutboundPolicy` can be updated this
72830
73130
  * way; for Sandboxes created without one this fails, since header
72831
73131
  * replacement is only set up at creation time.
72832
73132
  */
72833
- async updateOutboundPolicy(outboundPolicy) {
73133
+ async experimentalUpdateOutboundPolicy(outboundPolicy) {
72834
73134
  this.#ensureAttached();
72835
73135
  outboundPolicy._validate();
72836
73136
  const [, [taskId, commandRouterClient]] = await Promise.all([
@@ -73400,7 +73700,7 @@ var AuthTokenManager = class {
73400
73700
  };
73401
73701
 
73402
73702
  // src/version.ts
73403
- var SDK_VERSION = "0.10.2-dev.6";
73703
+ var SDK_VERSION = "0.10.2-dev.8";
73404
73704
  function getSDKVersion() {
73405
73705
  return SDK_VERSION;
73406
73706
  }
@@ -74141,6 +74441,8 @@ function contextIds(batch, item, ObjectId) {
74141
74441
  item.inputId || batch.inputId,
74142
74442
  item.containerId || batch.taskId
74143
74443
  ].filter((id) => id);
74444
+ case "sb":
74445
+ return [item.containerId || batch.taskId].filter((id) => id);
74144
74446
  default:
74145
74447
  return [];
74146
74448
  }
@@ -74961,6 +75263,97 @@ var FunctionCallLogsManager = class extends LogsManager {
74961
75263
  );
74962
75264
  }
74963
75265
  };
75266
+ var SandboxLogsManager = class {
75267
+ /** @ignore */
75268
+ constructor(client, sandboxId, getAppId, getTaskId) {
75269
+ this.client = client;
75270
+ this.sandboxId = sandboxId;
75271
+ this.getAppId = getAppId;
75272
+ this.getTaskId = getTaskId;
75273
+ }
75274
+ /**
75275
+ * Fetch Sandbox entrypoint logs corresponding to a UTC time range and
75276
+ * optional filters.
75277
+ *
75278
+ * Entries are returned in chronological order.
75279
+ *
75280
+ * @returns An async iterable of {@link LogEntry} objects.
75281
+ *
75282
+ * @example
75283
+ * ```typescript
75284
+ * import { ModalClient } from "modal";
75285
+ *
75286
+ * const modal = new ModalClient();
75287
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
75288
+ *
75289
+ * for await (const entry of sandbox.logs.fetch({
75290
+ * since: new Date(Date.now() - 60 * 60 * 1_000),
75291
+ * source: "stdout",
75292
+ * })) {
75293
+ * process.stdout.write(entry.message);
75294
+ * }
75295
+ * ```
75296
+ */
75297
+ async *fetch(params) {
75298
+ const [appId, taskId] = await Promise.all([
75299
+ this.getAppId(),
75300
+ this.getTaskId()
75301
+ ]);
75302
+ if (!taskId) {
75303
+ throw new ExecutionError(
75304
+ "Cannot resolve Sandbox metadata needed for fetching logs. Wait for the Sandbox to be scheduled."
75305
+ );
75306
+ }
75307
+ yield* fetchLogs(
75308
+ this.client,
75309
+ {
75310
+ appId,
75311
+ objectId: this.sandboxId,
75312
+ taskId,
75313
+ source: sourceToFileDescriptor(params.source),
75314
+ searchText: params.searchText
75315
+ },
75316
+ params.since,
75317
+ params.until
75318
+ );
75319
+ }
75320
+ /**
75321
+ * Fetch the most recent Sandbox entrypoint logs.
75322
+ *
75323
+ * Entries are returned in chronological order.
75324
+ *
75325
+ * @returns An async iterable of {@link LogEntry} objects.
75326
+ *
75327
+ * @example
75328
+ * ```typescript
75329
+ * import { ModalClient } from "modal";
75330
+ *
75331
+ * const modal = new ModalClient();
75332
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
75333
+ *
75334
+ * for await (const entry of sandbox.logs.tail({ entries: 20 })) {
75335
+ * process.stdout.write(entry.message);
75336
+ * }
75337
+ * ```
75338
+ */
75339
+ async *tail(params = {}) {
75340
+ const [appId, taskId] = await Promise.all([
75341
+ this.getAppId(),
75342
+ this.getTaskId()
75343
+ ]);
75344
+ if (!taskId) {
75345
+ throw new ExecutionError(
75346
+ "Sandbox task ID cannot be empty when fetching logs. Wait for the Sandbox to be scheduled."
75347
+ );
75348
+ }
75349
+ yield* tailLogs(this.client, params.entries ?? 100, {
75350
+ appId,
75351
+ objectId: this.sandboxId,
75352
+ taskId,
75353
+ source: sourceToFileDescriptor(params.source)
75354
+ });
75355
+ }
75356
+ };
74964
75357
 
74965
75358
  // src/function_call.ts
74966
75359
  var FunctionCallService = class {
@@ -75758,7 +76151,7 @@ function templateReferencesKey(template) {
75758
76151
  }
75759
76152
  return false;
75760
76153
  }
75761
- var OutboundPolicy2 = class _OutboundPolicy {
76154
+ var ExperimentalOutboundPolicy = class _ExperimentalOutboundPolicy {
75762
76155
  /** @internal */
75763
76156
  _replacements;
75764
76157
  /** @internal */
@@ -75766,7 +76159,7 @@ var OutboundPolicy2 = class _OutboundPolicy {
75766
76159
  this._replacements = _replacements;
75767
76160
  }
75768
76161
  /**
75769
- * Return a new {@link OutboundPolicy} with an added header replacement.
76162
+ * Return a new {@link ExperimentalOutboundPolicy} with an added header replacement.
75770
76163
  *
75771
76164
  * @param params.domain Domain the replacements are scoped to. Supports `*.` wildcard
75772
76165
  * prefixes (matching the apex domain and subdomains) and a bare `"*"`.
@@ -75777,7 +76170,7 @@ var OutboundPolicy2 = class _OutboundPolicy {
75777
76170
  */
75778
76171
  withHeaderReplacement(params) {
75779
76172
  const { domain, headers, secret } = params;
75780
- return new _OutboundPolicy([
76173
+ return new _ExperimentalOutboundPolicy([
75781
76174
  ...this._replacements,
75782
76175
  { domain, headers: { ...headers }, secret }
75783
76176
  ]);
@@ -75865,6 +76258,7 @@ var OutboundPolicy2 = class _OutboundPolicy {
75865
76258
  ConflictError,
75866
76259
  ContainerProcess,
75867
76260
  ExecutionError,
76261
+ ExperimentalOutboundPolicy,
75868
76262
  FunctionCall,
75869
76263
  FunctionCallLogsManager,
75870
76264
  FunctionCallService,
@@ -75878,7 +76272,6 @@ var OutboundPolicy2 = class _OutboundPolicy {
75878
76272
  InvalidError,
75879
76273
  ModalClient,
75880
76274
  NotFoundError,
75881
- OutboundPolicy,
75882
76275
  Probe,
75883
76276
  Proxy,
75884
76277
  ProxyService,
@@ -75898,6 +76291,7 @@ var OutboundPolicy2 = class _OutboundPolicy {
75898
76291
  SandboxFilesystemNotFoundError,
75899
76292
  SandboxFilesystemPathAlreadyExistsError,
75900
76293
  SandboxFilesystemPermissionError,
76294
+ SandboxLogsManager,
75901
76295
  SandboxService,
75902
76296
  SandboxSnapshot,
75903
76297
  SandboxSnapshotService,