modal 0.10.2-dev.6 → 0.10.2-dev.7

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
@@ -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,
@@ -48067,6 +48068,108 @@ var SecretDeleteRequest = {
48067
48068
  return message;
48068
48069
  }
48069
48070
  };
48071
+ function createBaseSecretGetInfoRequest() {
48072
+ return { secretId: "" };
48073
+ }
48074
+ var SecretGetInfoRequest = {
48075
+ encode(message, writer = new BinaryWriter()) {
48076
+ if (message.secretId !== "") {
48077
+ writer.uint32(10).string(message.secretId);
48078
+ }
48079
+ return writer;
48080
+ },
48081
+ decode(input, length) {
48082
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
48083
+ let end = length === void 0 ? reader.len : reader.pos + length;
48084
+ const message = createBaseSecretGetInfoRequest();
48085
+ while (reader.pos < end) {
48086
+ const tag = reader.uint32();
48087
+ switch (tag >>> 3) {
48088
+ case 1: {
48089
+ if (tag !== 10) {
48090
+ break;
48091
+ }
48092
+ message.secretId = reader.string();
48093
+ continue;
48094
+ }
48095
+ }
48096
+ if ((tag & 7) === 4 || tag === 0) {
48097
+ break;
48098
+ }
48099
+ reader.skip(tag & 7);
48100
+ }
48101
+ return message;
48102
+ },
48103
+ fromJSON(object) {
48104
+ return { secretId: isSet5(object.secretId) ? globalThis.String(object.secretId) : "" };
48105
+ },
48106
+ toJSON(message) {
48107
+ const obj = {};
48108
+ if (message.secretId !== "") {
48109
+ obj.secretId = message.secretId;
48110
+ }
48111
+ return obj;
48112
+ },
48113
+ create(base) {
48114
+ return SecretGetInfoRequest.fromPartial(base ?? {});
48115
+ },
48116
+ fromPartial(object) {
48117
+ const message = createBaseSecretGetInfoRequest();
48118
+ message.secretId = object.secretId ?? "";
48119
+ return message;
48120
+ }
48121
+ };
48122
+ function createBaseSecretGetInfoResponse() {
48123
+ return { metadata: void 0 };
48124
+ }
48125
+ var SecretGetInfoResponse = {
48126
+ encode(message, writer = new BinaryWriter()) {
48127
+ if (message.metadata !== void 0) {
48128
+ SecretMetadata.encode(message.metadata, writer.uint32(10).fork()).join();
48129
+ }
48130
+ return writer;
48131
+ },
48132
+ decode(input, length) {
48133
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
48134
+ let end = length === void 0 ? reader.len : reader.pos + length;
48135
+ const message = createBaseSecretGetInfoResponse();
48136
+ while (reader.pos < end) {
48137
+ const tag = reader.uint32();
48138
+ switch (tag >>> 3) {
48139
+ case 1: {
48140
+ if (tag !== 10) {
48141
+ break;
48142
+ }
48143
+ message.metadata = SecretMetadata.decode(reader, reader.uint32());
48144
+ continue;
48145
+ }
48146
+ }
48147
+ if ((tag & 7) === 4 || tag === 0) {
48148
+ break;
48149
+ }
48150
+ reader.skip(tag & 7);
48151
+ }
48152
+ return message;
48153
+ },
48154
+ fromJSON(object) {
48155
+ return { metadata: isSet5(object.metadata) ? SecretMetadata.fromJSON(object.metadata) : void 0 };
48156
+ },
48157
+ toJSON(message) {
48158
+ const obj = {};
48159
+ if (message.metadata !== void 0) {
48160
+ obj.metadata = SecretMetadata.toJSON(message.metadata);
48161
+ }
48162
+ return obj;
48163
+ },
48164
+ create(base) {
48165
+ return SecretGetInfoResponse.fromPartial(base ?? {});
48166
+ },
48167
+ fromPartial(object) {
48168
+ const message = createBaseSecretGetInfoResponse();
48169
+ message.metadata = object.metadata !== void 0 && object.metadata !== null ? SecretMetadata.fromPartial(object.metadata) : void 0;
48170
+ return message;
48171
+ }
48172
+ };
48070
48173
  function createBaseSecretGetOrCreateRequest() {
48071
48174
  return { deploymentName: "", environmentName: "", objectCreationType: 0, envDict: {}, appId: "", requiredKeys: [] };
48072
48175
  }
@@ -48613,7 +48716,7 @@ var SecretListResponse = {
48613
48716
  }
48614
48717
  };
48615
48718
  function createBaseSecretMetadata() {
48616
- return { name: "", creationInfo: void 0, keys: [] };
48719
+ return { name: "", creationInfo: void 0, keys: [], environmentName: "" };
48617
48720
  }
48618
48721
  var SecretMetadata = {
48619
48722
  encode(message, writer = new BinaryWriter()) {
@@ -48626,6 +48729,9 @@ var SecretMetadata = {
48626
48729
  for (const v of message.keys) {
48627
48730
  writer.uint32(26).string(v);
48628
48731
  }
48732
+ if (message.environmentName !== "") {
48733
+ writer.uint32(34).string(message.environmentName);
48734
+ }
48629
48735
  return writer;
48630
48736
  },
48631
48737
  decode(input, length) {
@@ -48656,6 +48762,13 @@ var SecretMetadata = {
48656
48762
  message.keys.push(reader.string());
48657
48763
  continue;
48658
48764
  }
48765
+ case 4: {
48766
+ if (tag !== 34) {
48767
+ break;
48768
+ }
48769
+ message.environmentName = reader.string();
48770
+ continue;
48771
+ }
48659
48772
  }
48660
48773
  if ((tag & 7) === 4 || tag === 0) {
48661
48774
  break;
@@ -48668,7 +48781,8 @@ var SecretMetadata = {
48668
48781
  return {
48669
48782
  name: isSet5(object.name) ? globalThis.String(object.name) : "",
48670
48783
  creationInfo: isSet5(object.creationInfo) ? CreationInfo.fromJSON(object.creationInfo) : void 0,
48671
- keys: globalThis.Array.isArray(object?.keys) ? object.keys.map((e) => globalThis.String(e)) : []
48784
+ keys: globalThis.Array.isArray(object?.keys) ? object.keys.map((e) => globalThis.String(e)) : [],
48785
+ environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : ""
48672
48786
  };
48673
48787
  },
48674
48788
  toJSON(message) {
@@ -48682,6 +48796,9 @@ var SecretMetadata = {
48682
48796
  if (message.keys?.length) {
48683
48797
  obj.keys = message.keys;
48684
48798
  }
48799
+ if (message.environmentName !== "") {
48800
+ obj.environmentName = message.environmentName;
48801
+ }
48685
48802
  return obj;
48686
48803
  },
48687
48804
  create(base) {
@@ -48692,6 +48809,7 @@ var SecretMetadata = {
48692
48809
  message.name = object.name ?? "";
48693
48810
  message.creationInfo = object.creationInfo !== void 0 && object.creationInfo !== null ? CreationInfo.fromPartial(object.creationInfo) : void 0;
48694
48811
  message.keys = object.keys?.map((e) => e) || [];
48812
+ message.environmentName = object.environmentName ?? "";
48695
48813
  return message;
48696
48814
  }
48697
48815
  };
@@ -62076,6 +62194,14 @@ var ModalClientDefinition = {
62076
62194
  responseStream: false,
62077
62195
  options: {}
62078
62196
  },
62197
+ secretGetInfo: {
62198
+ name: "SecretGetInfo",
62199
+ requestType: SecretGetInfoRequest,
62200
+ requestStream: false,
62201
+ responseType: SecretGetInfoResponse,
62202
+ responseStream: false,
62203
+ options: {}
62204
+ },
62079
62205
  secretGetOrCreate: {
62080
62206
  name: "SecretGetOrCreate",
62081
62207
  requestType: SecretGetOrCreateRequest,
@@ -71226,6 +71352,7 @@ var SandboxSnapshotService = class {
71226
71352
  var SB_LOGS_INITIAL_DELAY_MS = 10;
71227
71353
  var SB_LOGS_DELAY_FACTOR = 2;
71228
71354
  var SB_LOGS_MAX_RETRIES = 10;
71355
+ var SB_LOGS_TASK_ID_TIMEOUT_SECONDS = 0.5;
71229
71356
  var TTL_NO_EXPIRY_SENTINEL = -1;
71230
71357
  var CUSTOMER_SUPPLIED_ENCRYPTION_KEY_MIN_LENGTH = 16;
71231
71358
  var CUSTOMER_SUPPLIED_ENCRYPTION_KEY_MAX_LENGTH = 512;
@@ -72083,6 +72210,7 @@ function buildTaskSnapshotDirectoryRequestProto(taskId, path2, snapshotId, ttlSe
72083
72210
  var Sandbox2 = class _Sandbox {
72084
72211
  #client;
72085
72212
  sandboxId;
72213
+ #appId;
72086
72214
  #stdin;
72087
72215
  #stdout;
72088
72216
  #stderr;
@@ -72129,6 +72257,25 @@ var Sandbox2 = class _Sandbox {
72129
72257
  }
72130
72258
  return this.#stderr;
72131
72259
  }
72260
+ /**
72261
+ * Access persisted entrypoint logs emitted by this Sandbox.
72262
+ *
72263
+ * Use {@link SandboxLogsManager#fetch fetch()} to read logs from a UTC time
72264
+ * range and {@link SandboxLogsManager#tail tail()} to read the most recent
72265
+ * logs.
72266
+ *
72267
+ * This is separate from {@link Sandbox#stdout stdout} and
72268
+ * {@link Sandbox#stderr stderr}, which expose the Sandbox's live output
72269
+ * streams.
72270
+ */
72271
+ get logs() {
72272
+ return new SandboxLogsManager(
72273
+ this.#client,
72274
+ this.sandboxId,
72275
+ () => this.#getAppId(),
72276
+ () => this.#resolveTaskIdForLogs()
72277
+ );
72278
+ }
72132
72279
  #outputStream(fileDescriptor) {
72133
72280
  if (this.#isV2) {
72134
72281
  this.#ensureAttached();
@@ -72361,8 +72508,11 @@ var Sandbox2 = class _Sandbox {
72361
72508
  }
72362
72509
  return this.#client.cpClient.sandboxWait(req);
72363
72510
  }
72364
- #sandboxGetTaskId(signal) {
72365
- const req = { sandboxId: this.sandboxId };
72511
+ #sandboxGetTaskId(signal, timeout) {
72512
+ const req = SandboxGetTaskIdRequest.create({
72513
+ sandboxId: this.sandboxId,
72514
+ timeout
72515
+ });
72366
72516
  if (this.#isV2) {
72367
72517
  return this.#client.cpClient.sandboxGetTaskIdV2(req, { signal });
72368
72518
  }
@@ -72392,6 +72542,42 @@ var Sandbox2 = class _Sandbox {
72392
72542
  }
72393
72543
  static #maxGetTaskIdAttempts = 600;
72394
72544
  // 5 minutes at 500ms intervals
72545
+ async #getAppId() {
72546
+ if (this.#appId !== void 0) {
72547
+ return this.#appId;
72548
+ }
72549
+ const resp = await this.#sandboxWait(0);
72550
+ const appId = resp.metadata?.appId;
72551
+ if (!appId) {
72552
+ throw new ExecutionError(
72553
+ "Sandbox app ID should have been set during hydration"
72554
+ );
72555
+ }
72556
+ this.#appId = appId;
72557
+ return appId;
72558
+ }
72559
+ async #resolveTaskIdForLogs() {
72560
+ if (this.#taskId !== void 0) {
72561
+ return this.#taskId;
72562
+ }
72563
+ let resp;
72564
+ try {
72565
+ resp = await this.#sandboxGetTaskId(
72566
+ void 0,
72567
+ SB_LOGS_TASK_ID_TIMEOUT_SECONDS
72568
+ );
72569
+ } catch (error) {
72570
+ if (error instanceof import_nice_grpc12.ClientError && error.code === import_nice_grpc12.Status.DEADLINE_EXCEEDED) {
72571
+ throw new ExecutionError("Sandbox task ID is not available yet.");
72572
+ }
72573
+ throw error;
72574
+ }
72575
+ if (!resp.taskId) {
72576
+ throw new ExecutionError("Sandbox task ID is not available.");
72577
+ }
72578
+ this.#taskId = resp.taskId;
72579
+ return this.#taskId;
72580
+ }
72395
72581
  async #getTaskId(signal) {
72396
72582
  if (this.#taskId !== void 0) {
72397
72583
  return this.#taskId;
@@ -73400,7 +73586,7 @@ var AuthTokenManager = class {
73400
73586
  };
73401
73587
 
73402
73588
  // src/version.ts
73403
- var SDK_VERSION = "0.10.2-dev.6";
73589
+ var SDK_VERSION = "0.10.2-dev.7";
73404
73590
  function getSDKVersion() {
73405
73591
  return SDK_VERSION;
73406
73592
  }
@@ -74141,6 +74327,8 @@ function contextIds(batch, item, ObjectId) {
74141
74327
  item.inputId || batch.inputId,
74142
74328
  item.containerId || batch.taskId
74143
74329
  ].filter((id) => id);
74330
+ case "sb":
74331
+ return [item.containerId || batch.taskId].filter((id) => id);
74144
74332
  default:
74145
74333
  return [];
74146
74334
  }
@@ -74961,6 +75149,97 @@ var FunctionCallLogsManager = class extends LogsManager {
74961
75149
  );
74962
75150
  }
74963
75151
  };
75152
+ var SandboxLogsManager = class {
75153
+ /** @ignore */
75154
+ constructor(client, sandboxId, getAppId, getTaskId) {
75155
+ this.client = client;
75156
+ this.sandboxId = sandboxId;
75157
+ this.getAppId = getAppId;
75158
+ this.getTaskId = getTaskId;
75159
+ }
75160
+ /**
75161
+ * Fetch Sandbox entrypoint logs corresponding to a UTC time range and
75162
+ * optional filters.
75163
+ *
75164
+ * Entries are returned in chronological order.
75165
+ *
75166
+ * @returns An async iterable of {@link LogEntry} objects.
75167
+ *
75168
+ * @example
75169
+ * ```typescript
75170
+ * import { ModalClient } from "modal";
75171
+ *
75172
+ * const modal = new ModalClient();
75173
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
75174
+ *
75175
+ * for await (const entry of sandbox.logs.fetch({
75176
+ * since: new Date(Date.now() - 60 * 60 * 1_000),
75177
+ * source: "stdout",
75178
+ * })) {
75179
+ * process.stdout.write(entry.message);
75180
+ * }
75181
+ * ```
75182
+ */
75183
+ async *fetch(params) {
75184
+ const [appId, taskId] = await Promise.all([
75185
+ this.getAppId(),
75186
+ this.getTaskId()
75187
+ ]);
75188
+ if (!taskId) {
75189
+ throw new ExecutionError(
75190
+ "Cannot resolve Sandbox metadata needed for fetching logs. Wait for the Sandbox to be scheduled."
75191
+ );
75192
+ }
75193
+ yield* fetchLogs(
75194
+ this.client,
75195
+ {
75196
+ appId,
75197
+ objectId: this.sandboxId,
75198
+ taskId,
75199
+ source: sourceToFileDescriptor(params.source),
75200
+ searchText: params.searchText
75201
+ },
75202
+ params.since,
75203
+ params.until
75204
+ );
75205
+ }
75206
+ /**
75207
+ * Fetch the most recent Sandbox entrypoint logs.
75208
+ *
75209
+ * Entries are returned in chronological order.
75210
+ *
75211
+ * @returns An async iterable of {@link LogEntry} objects.
75212
+ *
75213
+ * @example
75214
+ * ```typescript
75215
+ * import { ModalClient } from "modal";
75216
+ *
75217
+ * const modal = new ModalClient();
75218
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
75219
+ *
75220
+ * for await (const entry of sandbox.logs.tail({ entries: 20 })) {
75221
+ * process.stdout.write(entry.message);
75222
+ * }
75223
+ * ```
75224
+ */
75225
+ async *tail(params = {}) {
75226
+ const [appId, taskId] = await Promise.all([
75227
+ this.getAppId(),
75228
+ this.getTaskId()
75229
+ ]);
75230
+ if (!taskId) {
75231
+ throw new ExecutionError(
75232
+ "Sandbox task ID cannot be empty when fetching logs. Wait for the Sandbox to be scheduled."
75233
+ );
75234
+ }
75235
+ yield* tailLogs(this.client, params.entries ?? 100, {
75236
+ appId,
75237
+ objectId: this.sandboxId,
75238
+ taskId,
75239
+ source: sourceToFileDescriptor(params.source)
75240
+ });
75241
+ }
75242
+ };
74964
75243
 
74965
75244
  // src/function_call.ts
74966
75245
  var FunctionCallService = class {
@@ -75898,6 +76177,7 @@ var OutboundPolicy2 = class _OutboundPolicy {
75898
76177
  SandboxFilesystemNotFoundError,
75899
76178
  SandboxFilesystemPathAlreadyExistsError,
75900
76179
  SandboxFilesystemPermissionError,
76180
+ SandboxLogsManager,
75901
76181
  SandboxService,
75902
76182
  SandboxSnapshot,
75903
76183
  SandboxSnapshotService,
package/dist/index.d.cts CHANGED
@@ -4097,6 +4097,14 @@ interface SecretDeleteRequest {
4097
4097
  secretId: string;
4098
4098
  }
4099
4099
  declare const SecretDeleteRequest: MessageFns$1<SecretDeleteRequest>;
4100
+ interface SecretGetInfoRequest {
4101
+ secretId: string;
4102
+ }
4103
+ declare const SecretGetInfoRequest: MessageFns$1<SecretGetInfoRequest>;
4104
+ interface SecretGetInfoResponse {
4105
+ metadata: SecretMetadata | undefined;
4106
+ }
4107
+ declare const SecretGetInfoResponse: MessageFns$1<SecretGetInfoResponse>;
4100
4108
  interface SecretGetOrCreateRequest {
4101
4109
  deploymentName: string;
4102
4110
  environmentName: string;
@@ -4140,6 +4148,7 @@ interface SecretMetadata {
4140
4148
  name: string;
4141
4149
  creationInfo: CreationInfo | undefined;
4142
4150
  keys: string[];
4151
+ environmentName: string;
4143
4152
  }
4144
4153
  declare const SecretMetadata: MessageFns$1<SecretMetadata>;
4145
4154
  interface SecretUpdateRequest {
@@ -6619,6 +6628,14 @@ declare const ModalClientDefinition: {
6619
6628
  readonly responseStream: false;
6620
6629
  readonly options: {};
6621
6630
  };
6631
+ readonly secretGetInfo: {
6632
+ readonly name: "SecretGetInfo";
6633
+ readonly requestType: MessageFns$1<SecretGetInfoRequest>;
6634
+ readonly requestStream: false;
6635
+ readonly responseType: MessageFns$1<SecretGetInfoResponse>;
6636
+ readonly responseStream: false;
6637
+ readonly options: {};
6638
+ };
6622
6639
  readonly secretGetOrCreate: {
6623
6640
  readonly name: "SecretGetOrCreate";
6624
6641
  readonly requestType: MessageFns$1<SecretGetOrCreateRequest>;
@@ -7319,6 +7336,8 @@ interface FunctionCallLogFetchParams {
7319
7336
  /** Filter by text contained in the log message. */
7320
7337
  searchText?: string;
7321
7338
  }
7339
+ type SandboxLogFetchParams = FunctionLogFetchParams;
7340
+ type SandboxLogTailParams = FunctionLogTailParams;
7322
7341
  interface FunctionLogs {
7323
7342
  fetch(params: FunctionLogFetchParams): AsyncIterable<LogEntry>;
7324
7343
  tail(params?: FunctionLogTailParams): AsyncIterable<LogEntry>;
@@ -7329,6 +7348,10 @@ interface FunctionCallLogs extends Omit<FunctionLogs, "fetch"> {
7329
7348
  tail(params?: FunctionCallLogTailParams): AsyncIterable<LogEntry>;
7330
7349
  stream(params?: FunctionCallLogStreamParams): AsyncIterable<LogEntry>;
7331
7350
  }
7351
+ interface SandboxLogs {
7352
+ fetch(params: SandboxLogFetchParams): AsyncIterable<LogEntry>;
7353
+ tail(params?: SandboxLogTailParams): AsyncIterable<LogEntry>;
7354
+ }
7332
7355
  interface LogQueryParams {
7333
7356
  client: ModalClient;
7334
7357
  objectId: string;
@@ -7481,6 +7504,59 @@ declare class FunctionCallLogsManager extends LogsManager implements FunctionCal
7481
7504
  */
7482
7505
  stream(params?: FunctionCallLogStreamParams): AsyncIterable<LogEntry>;
7483
7506
  }
7507
+ /** Namespace for Sandbox entrypoint log APIs. */
7508
+ declare class SandboxLogsManager implements SandboxLogs {
7509
+ private readonly client;
7510
+ private readonly sandboxId;
7511
+ private readonly getAppId;
7512
+ private readonly getTaskId;
7513
+ /** @ignore */
7514
+ constructor(client: ModalClient, sandboxId: string, getAppId: () => Promise<string>, getTaskId: () => Promise<string>);
7515
+ /**
7516
+ * Fetch Sandbox entrypoint logs corresponding to a UTC time range and
7517
+ * optional filters.
7518
+ *
7519
+ * Entries are returned in chronological order.
7520
+ *
7521
+ * @returns An async iterable of {@link LogEntry} objects.
7522
+ *
7523
+ * @example
7524
+ * ```typescript
7525
+ * import { ModalClient } from "modal";
7526
+ *
7527
+ * const modal = new ModalClient();
7528
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
7529
+ *
7530
+ * for await (const entry of sandbox.logs.fetch({
7531
+ * since: new Date(Date.now() - 60 * 60 * 1_000),
7532
+ * source: "stdout",
7533
+ * })) {
7534
+ * process.stdout.write(entry.message);
7535
+ * }
7536
+ * ```
7537
+ */
7538
+ fetch(params: SandboxLogFetchParams): AsyncIterable<LogEntry>;
7539
+ /**
7540
+ * Fetch the most recent Sandbox entrypoint logs.
7541
+ *
7542
+ * Entries are returned in chronological order.
7543
+ *
7544
+ * @returns An async iterable of {@link LogEntry} objects.
7545
+ *
7546
+ * @example
7547
+ * ```typescript
7548
+ * import { ModalClient } from "modal";
7549
+ *
7550
+ * const modal = new ModalClient();
7551
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
7552
+ *
7553
+ * for await (const entry of sandbox.logs.tail({ entries: 20 })) {
7554
+ * process.stdout.write(entry.message);
7555
+ * }
7556
+ * ```
7557
+ */
7558
+ tail(params?: SandboxLogTailParams): AsyncIterable<LogEntry>;
7559
+ }
7484
7560
 
7485
7561
  /**
7486
7562
  * Service for managing {@link FunctionCall}s.
@@ -9504,6 +9580,18 @@ declare class Sandbox {
9504
9580
  get stdin(): ModalWriteStream<string>;
9505
9581
  get stdout(): ModalReadStream<string>;
9506
9582
  get stderr(): ModalReadStream<string>;
9583
+ /**
9584
+ * Access persisted entrypoint logs emitted by this Sandbox.
9585
+ *
9586
+ * Use {@link SandboxLogsManager#fetch fetch()} to read logs from a UTC time
9587
+ * range and {@link SandboxLogsManager#tail tail()} to read the most recent
9588
+ * logs.
9589
+ *
9590
+ * This is separate from {@link Sandbox#stdout stdout} and
9591
+ * {@link Sandbox#stderr stderr}, which expose the Sandbox's live output
9592
+ * streams.
9593
+ */
9594
+ get logs(): SandboxLogsManager;
9507
9595
  get filesystem(): SandboxFilesystem;
9508
9596
  /**
9509
9597
  * Operations for managing sidecar containers that run alongside the
@@ -9972,4 +10060,4 @@ declare class ClientClosedError extends Error {
9972
10060
 
9973
10061
  declare function checkForRenamedParams(params: any, renames: Record<string, string>): void;
9974
10062
 
9975
- export { AlreadyExistsError, App, type AppFromNameParams, AppService, ClientClosedError, CloudBucketMount, CloudBucketMountService, Cls, type ClsFromNameParams, ClsInstance, ClsService, type ClsWithBatchingParams, type ClsWithConcurrencyParams, type ClsWithOptionsParams, ConflictError, ContainerProcess, ExecutionError, type FileInfo, type FileType, type FileWatchEvent, type FileWatchEventType, type FunctionAutoscalerSettings, FunctionCall, type FunctionCallCancelParams, type FunctionCallGetParams, type FunctionCallLogFetchParams, type FunctionCallLogStreamParams, type FunctionCallLogTailParams, FunctionCallLogsManager, FunctionCallService, type FunctionFromNameParams, type FunctionLogFetchParams, type FunctionLogStreamParams, type FunctionLogTailParams, FunctionLogsManager, FunctionService, type FunctionStats, FunctionTimeoutError, type FunctionUpdateAutoscalerParams, type FunctionWithBatchingParams, type FunctionWithConcurrencyParams, type FunctionWithOptionsParams, Function_, Image, type ImageDeleteParams, type ImageDockerfileCommandsParams, type ImageFromNameParams, type ImagePublishParams, ImageService, InternalFailure, InvalidError, type LogEntry, type FunctionLogFetchParams as LogFetchParams, type LogLevel, type LogSource, type Logger, ModalClient, type ModalClientParams, type ModalReadStream, type ModalWriteStream, NotFoundError, OutboundPolicy, Probe, type ProbeParams, type Profile, Proxy, type ProxyFromNameParams, ProxyService, Queue, type QueueClearParams, type QueueDeleteParams, QueueEmptyError, type QueueEphemeralParams, type QueueFromNameParams, QueueFullError, type QueueGetParams, type QueueIterateParams, type QueueLenParams, type QueuePutParams, QueueService, RemoteError, Retries, Sandbox, type SandboxCreateConnectCredentials, type SandboxCreateConnectTokenParams, type SandboxCreateParams, type SandboxExecParams, type SandboxExperimentalFromNameParams, type SandboxExperimentalFromSnapshotParams, type SandboxExperimentalGetExitSnapshotParams, type SandboxExperimentalListParams, SandboxFilesystem, SandboxFilesystemDirectoryNotEmptyError, SandboxFilesystemError, SandboxFilesystemFileTooLargeError, SandboxFilesystemIsADirectoryError, SandboxFilesystemNotADirectoryError, SandboxFilesystemNotFoundError, SandboxFilesystemPathAlreadyExistsError, SandboxFilesystemPermissionError, type SandboxFromNameParams, type SandboxListParams, type SandboxMountImageParams, type SandboxReloadVolumesParams, SandboxService, SandboxSnapshot, type SandboxSnapshotDirectoryParams, type SandboxSnapshotFilesystemParams, SandboxSnapshotService, type SandboxTerminateParams, SandboxTimeoutError, type SandboxUpdateNetworkPolicyParams, Secret, type SecretDeleteParams, type SecretFromNameParams, type SecretFromObjectParams, SecretService, SidecarContainer, type SidecarCreateParams, type SidecarExecParams, type SidecarGetParams, type SidecarListParams, type SidecarMountImageParams, SidecarService, type SidecarSnapshotDirectoryParams, type SidecarSnapshotFilesystemParams, type SidecarTerminateParams, type SidecarUnmountImageParams, SnapshotCreationError, type StdioBehavior, type StreamMode, TimeoutError, Tunnel, Volume, type VolumeDeleteParams, type VolumeEphemeralParams, type VolumeFromNameParams, type VolumeMountOptionsParams, VolumeService, checkForRenamedParams };
10063
+ export { AlreadyExistsError, App, type AppFromNameParams, AppService, ClientClosedError, CloudBucketMount, CloudBucketMountService, Cls, type ClsFromNameParams, ClsInstance, ClsService, type ClsWithBatchingParams, type ClsWithConcurrencyParams, type ClsWithOptionsParams, ConflictError, ContainerProcess, ExecutionError, type FileInfo, type FileType, type FileWatchEvent, type FileWatchEventType, type FunctionAutoscalerSettings, FunctionCall, type FunctionCallCancelParams, type FunctionCallGetParams, type FunctionCallLogFetchParams, type FunctionCallLogStreamParams, type FunctionCallLogTailParams, FunctionCallLogsManager, FunctionCallService, type FunctionFromNameParams, type FunctionLogFetchParams, type FunctionLogStreamParams, type FunctionLogTailParams, FunctionLogsManager, FunctionService, type FunctionStats, FunctionTimeoutError, type FunctionUpdateAutoscalerParams, type FunctionWithBatchingParams, type FunctionWithConcurrencyParams, type FunctionWithOptionsParams, Function_, Image, type ImageDeleteParams, type ImageDockerfileCommandsParams, type ImageFromNameParams, type ImagePublishParams, ImageService, InternalFailure, InvalidError, type LogEntry, type FunctionLogFetchParams as LogFetchParams, type LogLevel, type LogSource, type Logger, ModalClient, type ModalClientParams, type ModalReadStream, type ModalWriteStream, NotFoundError, OutboundPolicy, Probe, type ProbeParams, type Profile, Proxy, type ProxyFromNameParams, ProxyService, Queue, type QueueClearParams, type QueueDeleteParams, QueueEmptyError, type QueueEphemeralParams, type QueueFromNameParams, QueueFullError, type QueueGetParams, type QueueIterateParams, type QueueLenParams, type QueuePutParams, QueueService, RemoteError, Retries, Sandbox, type SandboxCreateConnectCredentials, type SandboxCreateConnectTokenParams, type SandboxCreateParams, type SandboxExecParams, type SandboxExperimentalFromNameParams, type SandboxExperimentalFromSnapshotParams, type SandboxExperimentalGetExitSnapshotParams, type SandboxExperimentalListParams, SandboxFilesystem, SandboxFilesystemDirectoryNotEmptyError, SandboxFilesystemError, SandboxFilesystemFileTooLargeError, SandboxFilesystemIsADirectoryError, SandboxFilesystemNotADirectoryError, SandboxFilesystemNotFoundError, SandboxFilesystemPathAlreadyExistsError, SandboxFilesystemPermissionError, type SandboxFromNameParams, type SandboxListParams, type SandboxLogFetchParams, type SandboxLogTailParams, SandboxLogsManager, type SandboxMountImageParams, type SandboxReloadVolumesParams, SandboxService, SandboxSnapshot, type SandboxSnapshotDirectoryParams, type SandboxSnapshotFilesystemParams, SandboxSnapshotService, type SandboxTerminateParams, SandboxTimeoutError, type SandboxUpdateNetworkPolicyParams, Secret, type SecretDeleteParams, type SecretFromNameParams, type SecretFromObjectParams, SecretService, SidecarContainer, type SidecarCreateParams, type SidecarExecParams, type SidecarGetParams, type SidecarListParams, type SidecarMountImageParams, SidecarService, type SidecarSnapshotDirectoryParams, type SidecarSnapshotFilesystemParams, type SidecarTerminateParams, type SidecarUnmountImageParams, SnapshotCreationError, type StdioBehavior, type StreamMode, TimeoutError, Tunnel, Volume, type VolumeDeleteParams, type VolumeEphemeralParams, type VolumeFromNameParams, type VolumeMountOptionsParams, VolumeService, checkForRenamedParams };
package/dist/index.d.ts CHANGED
@@ -4097,6 +4097,14 @@ interface SecretDeleteRequest {
4097
4097
  secretId: string;
4098
4098
  }
4099
4099
  declare const SecretDeleteRequest: MessageFns$1<SecretDeleteRequest>;
4100
+ interface SecretGetInfoRequest {
4101
+ secretId: string;
4102
+ }
4103
+ declare const SecretGetInfoRequest: MessageFns$1<SecretGetInfoRequest>;
4104
+ interface SecretGetInfoResponse {
4105
+ metadata: SecretMetadata | undefined;
4106
+ }
4107
+ declare const SecretGetInfoResponse: MessageFns$1<SecretGetInfoResponse>;
4100
4108
  interface SecretGetOrCreateRequest {
4101
4109
  deploymentName: string;
4102
4110
  environmentName: string;
@@ -4140,6 +4148,7 @@ interface SecretMetadata {
4140
4148
  name: string;
4141
4149
  creationInfo: CreationInfo | undefined;
4142
4150
  keys: string[];
4151
+ environmentName: string;
4143
4152
  }
4144
4153
  declare const SecretMetadata: MessageFns$1<SecretMetadata>;
4145
4154
  interface SecretUpdateRequest {
@@ -6619,6 +6628,14 @@ declare const ModalClientDefinition: {
6619
6628
  readonly responseStream: false;
6620
6629
  readonly options: {};
6621
6630
  };
6631
+ readonly secretGetInfo: {
6632
+ readonly name: "SecretGetInfo";
6633
+ readonly requestType: MessageFns$1<SecretGetInfoRequest>;
6634
+ readonly requestStream: false;
6635
+ readonly responseType: MessageFns$1<SecretGetInfoResponse>;
6636
+ readonly responseStream: false;
6637
+ readonly options: {};
6638
+ };
6622
6639
  readonly secretGetOrCreate: {
6623
6640
  readonly name: "SecretGetOrCreate";
6624
6641
  readonly requestType: MessageFns$1<SecretGetOrCreateRequest>;
@@ -7319,6 +7336,8 @@ interface FunctionCallLogFetchParams {
7319
7336
  /** Filter by text contained in the log message. */
7320
7337
  searchText?: string;
7321
7338
  }
7339
+ type SandboxLogFetchParams = FunctionLogFetchParams;
7340
+ type SandboxLogTailParams = FunctionLogTailParams;
7322
7341
  interface FunctionLogs {
7323
7342
  fetch(params: FunctionLogFetchParams): AsyncIterable<LogEntry>;
7324
7343
  tail(params?: FunctionLogTailParams): AsyncIterable<LogEntry>;
@@ -7329,6 +7348,10 @@ interface FunctionCallLogs extends Omit<FunctionLogs, "fetch"> {
7329
7348
  tail(params?: FunctionCallLogTailParams): AsyncIterable<LogEntry>;
7330
7349
  stream(params?: FunctionCallLogStreamParams): AsyncIterable<LogEntry>;
7331
7350
  }
7351
+ interface SandboxLogs {
7352
+ fetch(params: SandboxLogFetchParams): AsyncIterable<LogEntry>;
7353
+ tail(params?: SandboxLogTailParams): AsyncIterable<LogEntry>;
7354
+ }
7332
7355
  interface LogQueryParams {
7333
7356
  client: ModalClient;
7334
7357
  objectId: string;
@@ -7481,6 +7504,59 @@ declare class FunctionCallLogsManager extends LogsManager implements FunctionCal
7481
7504
  */
7482
7505
  stream(params?: FunctionCallLogStreamParams): AsyncIterable<LogEntry>;
7483
7506
  }
7507
+ /** Namespace for Sandbox entrypoint log APIs. */
7508
+ declare class SandboxLogsManager implements SandboxLogs {
7509
+ private readonly client;
7510
+ private readonly sandboxId;
7511
+ private readonly getAppId;
7512
+ private readonly getTaskId;
7513
+ /** @ignore */
7514
+ constructor(client: ModalClient, sandboxId: string, getAppId: () => Promise<string>, getTaskId: () => Promise<string>);
7515
+ /**
7516
+ * Fetch Sandbox entrypoint logs corresponding to a UTC time range and
7517
+ * optional filters.
7518
+ *
7519
+ * Entries are returned in chronological order.
7520
+ *
7521
+ * @returns An async iterable of {@link LogEntry} objects.
7522
+ *
7523
+ * @example
7524
+ * ```typescript
7525
+ * import { ModalClient } from "modal";
7526
+ *
7527
+ * const modal = new ModalClient();
7528
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
7529
+ *
7530
+ * for await (const entry of sandbox.logs.fetch({
7531
+ * since: new Date(Date.now() - 60 * 60 * 1_000),
7532
+ * source: "stdout",
7533
+ * })) {
7534
+ * process.stdout.write(entry.message);
7535
+ * }
7536
+ * ```
7537
+ */
7538
+ fetch(params: SandboxLogFetchParams): AsyncIterable<LogEntry>;
7539
+ /**
7540
+ * Fetch the most recent Sandbox entrypoint logs.
7541
+ *
7542
+ * Entries are returned in chronological order.
7543
+ *
7544
+ * @returns An async iterable of {@link LogEntry} objects.
7545
+ *
7546
+ * @example
7547
+ * ```typescript
7548
+ * import { ModalClient } from "modal";
7549
+ *
7550
+ * const modal = new ModalClient();
7551
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
7552
+ *
7553
+ * for await (const entry of sandbox.logs.tail({ entries: 20 })) {
7554
+ * process.stdout.write(entry.message);
7555
+ * }
7556
+ * ```
7557
+ */
7558
+ tail(params?: SandboxLogTailParams): AsyncIterable<LogEntry>;
7559
+ }
7484
7560
 
7485
7561
  /**
7486
7562
  * Service for managing {@link FunctionCall}s.
@@ -9504,6 +9580,18 @@ declare class Sandbox {
9504
9580
  get stdin(): ModalWriteStream<string>;
9505
9581
  get stdout(): ModalReadStream<string>;
9506
9582
  get stderr(): ModalReadStream<string>;
9583
+ /**
9584
+ * Access persisted entrypoint logs emitted by this Sandbox.
9585
+ *
9586
+ * Use {@link SandboxLogsManager#fetch fetch()} to read logs from a UTC time
9587
+ * range and {@link SandboxLogsManager#tail tail()} to read the most recent
9588
+ * logs.
9589
+ *
9590
+ * This is separate from {@link Sandbox#stdout stdout} and
9591
+ * {@link Sandbox#stderr stderr}, which expose the Sandbox's live output
9592
+ * streams.
9593
+ */
9594
+ get logs(): SandboxLogsManager;
9507
9595
  get filesystem(): SandboxFilesystem;
9508
9596
  /**
9509
9597
  * Operations for managing sidecar containers that run alongside the
@@ -9972,4 +10060,4 @@ declare class ClientClosedError extends Error {
9972
10060
 
9973
10061
  declare function checkForRenamedParams(params: any, renames: Record<string, string>): void;
9974
10062
 
9975
- export { AlreadyExistsError, App, type AppFromNameParams, AppService, ClientClosedError, CloudBucketMount, CloudBucketMountService, Cls, type ClsFromNameParams, ClsInstance, ClsService, type ClsWithBatchingParams, type ClsWithConcurrencyParams, type ClsWithOptionsParams, ConflictError, ContainerProcess, ExecutionError, type FileInfo, type FileType, type FileWatchEvent, type FileWatchEventType, type FunctionAutoscalerSettings, FunctionCall, type FunctionCallCancelParams, type FunctionCallGetParams, type FunctionCallLogFetchParams, type FunctionCallLogStreamParams, type FunctionCallLogTailParams, FunctionCallLogsManager, FunctionCallService, type FunctionFromNameParams, type FunctionLogFetchParams, type FunctionLogStreamParams, type FunctionLogTailParams, FunctionLogsManager, FunctionService, type FunctionStats, FunctionTimeoutError, type FunctionUpdateAutoscalerParams, type FunctionWithBatchingParams, type FunctionWithConcurrencyParams, type FunctionWithOptionsParams, Function_, Image, type ImageDeleteParams, type ImageDockerfileCommandsParams, type ImageFromNameParams, type ImagePublishParams, ImageService, InternalFailure, InvalidError, type LogEntry, type FunctionLogFetchParams as LogFetchParams, type LogLevel, type LogSource, type Logger, ModalClient, type ModalClientParams, type ModalReadStream, type ModalWriteStream, NotFoundError, OutboundPolicy, Probe, type ProbeParams, type Profile, Proxy, type ProxyFromNameParams, ProxyService, Queue, type QueueClearParams, type QueueDeleteParams, QueueEmptyError, type QueueEphemeralParams, type QueueFromNameParams, QueueFullError, type QueueGetParams, type QueueIterateParams, type QueueLenParams, type QueuePutParams, QueueService, RemoteError, Retries, Sandbox, type SandboxCreateConnectCredentials, type SandboxCreateConnectTokenParams, type SandboxCreateParams, type SandboxExecParams, type SandboxExperimentalFromNameParams, type SandboxExperimentalFromSnapshotParams, type SandboxExperimentalGetExitSnapshotParams, type SandboxExperimentalListParams, SandboxFilesystem, SandboxFilesystemDirectoryNotEmptyError, SandboxFilesystemError, SandboxFilesystemFileTooLargeError, SandboxFilesystemIsADirectoryError, SandboxFilesystemNotADirectoryError, SandboxFilesystemNotFoundError, SandboxFilesystemPathAlreadyExistsError, SandboxFilesystemPermissionError, type SandboxFromNameParams, type SandboxListParams, type SandboxMountImageParams, type SandboxReloadVolumesParams, SandboxService, SandboxSnapshot, type SandboxSnapshotDirectoryParams, type SandboxSnapshotFilesystemParams, SandboxSnapshotService, type SandboxTerminateParams, SandboxTimeoutError, type SandboxUpdateNetworkPolicyParams, Secret, type SecretDeleteParams, type SecretFromNameParams, type SecretFromObjectParams, SecretService, SidecarContainer, type SidecarCreateParams, type SidecarExecParams, type SidecarGetParams, type SidecarListParams, type SidecarMountImageParams, SidecarService, type SidecarSnapshotDirectoryParams, type SidecarSnapshotFilesystemParams, type SidecarTerminateParams, type SidecarUnmountImageParams, SnapshotCreationError, type StdioBehavior, type StreamMode, TimeoutError, Tunnel, Volume, type VolumeDeleteParams, type VolumeEphemeralParams, type VolumeFromNameParams, type VolumeMountOptionsParams, VolumeService, checkForRenamedParams };
10063
+ export { AlreadyExistsError, App, type AppFromNameParams, AppService, ClientClosedError, CloudBucketMount, CloudBucketMountService, Cls, type ClsFromNameParams, ClsInstance, ClsService, type ClsWithBatchingParams, type ClsWithConcurrencyParams, type ClsWithOptionsParams, ConflictError, ContainerProcess, ExecutionError, type FileInfo, type FileType, type FileWatchEvent, type FileWatchEventType, type FunctionAutoscalerSettings, FunctionCall, type FunctionCallCancelParams, type FunctionCallGetParams, type FunctionCallLogFetchParams, type FunctionCallLogStreamParams, type FunctionCallLogTailParams, FunctionCallLogsManager, FunctionCallService, type FunctionFromNameParams, type FunctionLogFetchParams, type FunctionLogStreamParams, type FunctionLogTailParams, FunctionLogsManager, FunctionService, type FunctionStats, FunctionTimeoutError, type FunctionUpdateAutoscalerParams, type FunctionWithBatchingParams, type FunctionWithConcurrencyParams, type FunctionWithOptionsParams, Function_, Image, type ImageDeleteParams, type ImageDockerfileCommandsParams, type ImageFromNameParams, type ImagePublishParams, ImageService, InternalFailure, InvalidError, type LogEntry, type FunctionLogFetchParams as LogFetchParams, type LogLevel, type LogSource, type Logger, ModalClient, type ModalClientParams, type ModalReadStream, type ModalWriteStream, NotFoundError, OutboundPolicy, Probe, type ProbeParams, type Profile, Proxy, type ProxyFromNameParams, ProxyService, Queue, type QueueClearParams, type QueueDeleteParams, QueueEmptyError, type QueueEphemeralParams, type QueueFromNameParams, QueueFullError, type QueueGetParams, type QueueIterateParams, type QueueLenParams, type QueuePutParams, QueueService, RemoteError, Retries, Sandbox, type SandboxCreateConnectCredentials, type SandboxCreateConnectTokenParams, type SandboxCreateParams, type SandboxExecParams, type SandboxExperimentalFromNameParams, type SandboxExperimentalFromSnapshotParams, type SandboxExperimentalGetExitSnapshotParams, type SandboxExperimentalListParams, SandboxFilesystem, SandboxFilesystemDirectoryNotEmptyError, SandboxFilesystemError, SandboxFilesystemFileTooLargeError, SandboxFilesystemIsADirectoryError, SandboxFilesystemNotADirectoryError, SandboxFilesystemNotFoundError, SandboxFilesystemPathAlreadyExistsError, SandboxFilesystemPermissionError, type SandboxFromNameParams, type SandboxListParams, type SandboxLogFetchParams, type SandboxLogTailParams, SandboxLogsManager, type SandboxMountImageParams, type SandboxReloadVolumesParams, SandboxService, SandboxSnapshot, type SandboxSnapshotDirectoryParams, type SandboxSnapshotFilesystemParams, SandboxSnapshotService, type SandboxTerminateParams, SandboxTimeoutError, type SandboxUpdateNetworkPolicyParams, Secret, type SecretDeleteParams, type SecretFromNameParams, type SecretFromObjectParams, SecretService, SidecarContainer, type SidecarCreateParams, type SidecarExecParams, type SidecarGetParams, type SidecarListParams, type SidecarMountImageParams, SidecarService, type SidecarSnapshotDirectoryParams, type SidecarSnapshotFilesystemParams, type SidecarTerminateParams, type SidecarUnmountImageParams, SnapshotCreationError, type StdioBehavior, type StreamMode, TimeoutError, Tunnel, Volume, type VolumeDeleteParams, type VolumeEphemeralParams, type VolumeFromNameParams, type VolumeMountOptionsParams, VolumeService, checkForRenamedParams };
package/dist/index.js CHANGED
@@ -47974,6 +47974,108 @@ var SecretDeleteRequest = {
47974
47974
  return message;
47975
47975
  }
47976
47976
  };
47977
+ function createBaseSecretGetInfoRequest() {
47978
+ return { secretId: "" };
47979
+ }
47980
+ var SecretGetInfoRequest = {
47981
+ encode(message, writer = new BinaryWriter()) {
47982
+ if (message.secretId !== "") {
47983
+ writer.uint32(10).string(message.secretId);
47984
+ }
47985
+ return writer;
47986
+ },
47987
+ decode(input, length) {
47988
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
47989
+ let end = length === void 0 ? reader.len : reader.pos + length;
47990
+ const message = createBaseSecretGetInfoRequest();
47991
+ while (reader.pos < end) {
47992
+ const tag = reader.uint32();
47993
+ switch (tag >>> 3) {
47994
+ case 1: {
47995
+ if (tag !== 10) {
47996
+ break;
47997
+ }
47998
+ message.secretId = reader.string();
47999
+ continue;
48000
+ }
48001
+ }
48002
+ if ((tag & 7) === 4 || tag === 0) {
48003
+ break;
48004
+ }
48005
+ reader.skip(tag & 7);
48006
+ }
48007
+ return message;
48008
+ },
48009
+ fromJSON(object) {
48010
+ return { secretId: isSet5(object.secretId) ? globalThis.String(object.secretId) : "" };
48011
+ },
48012
+ toJSON(message) {
48013
+ const obj = {};
48014
+ if (message.secretId !== "") {
48015
+ obj.secretId = message.secretId;
48016
+ }
48017
+ return obj;
48018
+ },
48019
+ create(base) {
48020
+ return SecretGetInfoRequest.fromPartial(base ?? {});
48021
+ },
48022
+ fromPartial(object) {
48023
+ const message = createBaseSecretGetInfoRequest();
48024
+ message.secretId = object.secretId ?? "";
48025
+ return message;
48026
+ }
48027
+ };
48028
+ function createBaseSecretGetInfoResponse() {
48029
+ return { metadata: void 0 };
48030
+ }
48031
+ var SecretGetInfoResponse = {
48032
+ encode(message, writer = new BinaryWriter()) {
48033
+ if (message.metadata !== void 0) {
48034
+ SecretMetadata.encode(message.metadata, writer.uint32(10).fork()).join();
48035
+ }
48036
+ return writer;
48037
+ },
48038
+ decode(input, length) {
48039
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
48040
+ let end = length === void 0 ? reader.len : reader.pos + length;
48041
+ const message = createBaseSecretGetInfoResponse();
48042
+ while (reader.pos < end) {
48043
+ const tag = reader.uint32();
48044
+ switch (tag >>> 3) {
48045
+ case 1: {
48046
+ if (tag !== 10) {
48047
+ break;
48048
+ }
48049
+ message.metadata = SecretMetadata.decode(reader, reader.uint32());
48050
+ continue;
48051
+ }
48052
+ }
48053
+ if ((tag & 7) === 4 || tag === 0) {
48054
+ break;
48055
+ }
48056
+ reader.skip(tag & 7);
48057
+ }
48058
+ return message;
48059
+ },
48060
+ fromJSON(object) {
48061
+ return { metadata: isSet5(object.metadata) ? SecretMetadata.fromJSON(object.metadata) : void 0 };
48062
+ },
48063
+ toJSON(message) {
48064
+ const obj = {};
48065
+ if (message.metadata !== void 0) {
48066
+ obj.metadata = SecretMetadata.toJSON(message.metadata);
48067
+ }
48068
+ return obj;
48069
+ },
48070
+ create(base) {
48071
+ return SecretGetInfoResponse.fromPartial(base ?? {});
48072
+ },
48073
+ fromPartial(object) {
48074
+ const message = createBaseSecretGetInfoResponse();
48075
+ message.metadata = object.metadata !== void 0 && object.metadata !== null ? SecretMetadata.fromPartial(object.metadata) : void 0;
48076
+ return message;
48077
+ }
48078
+ };
47977
48079
  function createBaseSecretGetOrCreateRequest() {
47978
48080
  return { deploymentName: "", environmentName: "", objectCreationType: 0, envDict: {}, appId: "", requiredKeys: [] };
47979
48081
  }
@@ -48520,7 +48622,7 @@ var SecretListResponse = {
48520
48622
  }
48521
48623
  };
48522
48624
  function createBaseSecretMetadata() {
48523
- return { name: "", creationInfo: void 0, keys: [] };
48625
+ return { name: "", creationInfo: void 0, keys: [], environmentName: "" };
48524
48626
  }
48525
48627
  var SecretMetadata = {
48526
48628
  encode(message, writer = new BinaryWriter()) {
@@ -48533,6 +48635,9 @@ var SecretMetadata = {
48533
48635
  for (const v of message.keys) {
48534
48636
  writer.uint32(26).string(v);
48535
48637
  }
48638
+ if (message.environmentName !== "") {
48639
+ writer.uint32(34).string(message.environmentName);
48640
+ }
48536
48641
  return writer;
48537
48642
  },
48538
48643
  decode(input, length) {
@@ -48563,6 +48668,13 @@ var SecretMetadata = {
48563
48668
  message.keys.push(reader.string());
48564
48669
  continue;
48565
48670
  }
48671
+ case 4: {
48672
+ if (tag !== 34) {
48673
+ break;
48674
+ }
48675
+ message.environmentName = reader.string();
48676
+ continue;
48677
+ }
48566
48678
  }
48567
48679
  if ((tag & 7) === 4 || tag === 0) {
48568
48680
  break;
@@ -48575,7 +48687,8 @@ var SecretMetadata = {
48575
48687
  return {
48576
48688
  name: isSet5(object.name) ? globalThis.String(object.name) : "",
48577
48689
  creationInfo: isSet5(object.creationInfo) ? CreationInfo.fromJSON(object.creationInfo) : void 0,
48578
- keys: globalThis.Array.isArray(object?.keys) ? object.keys.map((e) => globalThis.String(e)) : []
48690
+ keys: globalThis.Array.isArray(object?.keys) ? object.keys.map((e) => globalThis.String(e)) : [],
48691
+ environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : ""
48579
48692
  };
48580
48693
  },
48581
48694
  toJSON(message) {
@@ -48589,6 +48702,9 @@ var SecretMetadata = {
48589
48702
  if (message.keys?.length) {
48590
48703
  obj.keys = message.keys;
48591
48704
  }
48705
+ if (message.environmentName !== "") {
48706
+ obj.environmentName = message.environmentName;
48707
+ }
48592
48708
  return obj;
48593
48709
  },
48594
48710
  create(base) {
@@ -48599,6 +48715,7 @@ var SecretMetadata = {
48599
48715
  message.name = object.name ?? "";
48600
48716
  message.creationInfo = object.creationInfo !== void 0 && object.creationInfo !== null ? CreationInfo.fromPartial(object.creationInfo) : void 0;
48601
48717
  message.keys = object.keys?.map((e) => e) || [];
48718
+ message.environmentName = object.environmentName ?? "";
48602
48719
  return message;
48603
48720
  }
48604
48721
  };
@@ -61983,6 +62100,14 @@ var ModalClientDefinition = {
61983
62100
  responseStream: false,
61984
62101
  options: {}
61985
62102
  },
62103
+ secretGetInfo: {
62104
+ name: "SecretGetInfo",
62105
+ requestType: SecretGetInfoRequest,
62106
+ requestStream: false,
62107
+ responseType: SecretGetInfoResponse,
62108
+ responseStream: false,
62109
+ options: {}
62110
+ },
61986
62111
  secretGetOrCreate: {
61987
62112
  name: "SecretGetOrCreate",
61988
62113
  requestType: SecretGetOrCreateRequest,
@@ -71146,6 +71271,7 @@ var SandboxSnapshotService = class {
71146
71271
  var SB_LOGS_INITIAL_DELAY_MS = 10;
71147
71272
  var SB_LOGS_DELAY_FACTOR = 2;
71148
71273
  var SB_LOGS_MAX_RETRIES = 10;
71274
+ var SB_LOGS_TASK_ID_TIMEOUT_SECONDS = 0.5;
71149
71275
  var TTL_NO_EXPIRY_SENTINEL = -1;
71150
71276
  var CUSTOMER_SUPPLIED_ENCRYPTION_KEY_MIN_LENGTH = 16;
71151
71277
  var CUSTOMER_SUPPLIED_ENCRYPTION_KEY_MAX_LENGTH = 512;
@@ -72003,6 +72129,7 @@ function buildTaskSnapshotDirectoryRequestProto(taskId, path2, snapshotId, ttlSe
72003
72129
  var Sandbox2 = class _Sandbox {
72004
72130
  #client;
72005
72131
  sandboxId;
72132
+ #appId;
72006
72133
  #stdin;
72007
72134
  #stdout;
72008
72135
  #stderr;
@@ -72049,6 +72176,25 @@ var Sandbox2 = class _Sandbox {
72049
72176
  }
72050
72177
  return this.#stderr;
72051
72178
  }
72179
+ /**
72180
+ * Access persisted entrypoint logs emitted by this Sandbox.
72181
+ *
72182
+ * Use {@link SandboxLogsManager#fetch fetch()} to read logs from a UTC time
72183
+ * range and {@link SandboxLogsManager#tail tail()} to read the most recent
72184
+ * logs.
72185
+ *
72186
+ * This is separate from {@link Sandbox#stdout stdout} and
72187
+ * {@link Sandbox#stderr stderr}, which expose the Sandbox's live output
72188
+ * streams.
72189
+ */
72190
+ get logs() {
72191
+ return new SandboxLogsManager(
72192
+ this.#client,
72193
+ this.sandboxId,
72194
+ () => this.#getAppId(),
72195
+ () => this.#resolveTaskIdForLogs()
72196
+ );
72197
+ }
72052
72198
  #outputStream(fileDescriptor) {
72053
72199
  if (this.#isV2) {
72054
72200
  this.#ensureAttached();
@@ -72281,8 +72427,11 @@ var Sandbox2 = class _Sandbox {
72281
72427
  }
72282
72428
  return this.#client.cpClient.sandboxWait(req);
72283
72429
  }
72284
- #sandboxGetTaskId(signal) {
72285
- const req = { sandboxId: this.sandboxId };
72430
+ #sandboxGetTaskId(signal, timeout) {
72431
+ const req = SandboxGetTaskIdRequest.create({
72432
+ sandboxId: this.sandboxId,
72433
+ timeout
72434
+ });
72286
72435
  if (this.#isV2) {
72287
72436
  return this.#client.cpClient.sandboxGetTaskIdV2(req, { signal });
72288
72437
  }
@@ -72312,6 +72461,42 @@ var Sandbox2 = class _Sandbox {
72312
72461
  }
72313
72462
  static #maxGetTaskIdAttempts = 600;
72314
72463
  // 5 minutes at 500ms intervals
72464
+ async #getAppId() {
72465
+ if (this.#appId !== void 0) {
72466
+ return this.#appId;
72467
+ }
72468
+ const resp = await this.#sandboxWait(0);
72469
+ const appId = resp.metadata?.appId;
72470
+ if (!appId) {
72471
+ throw new ExecutionError(
72472
+ "Sandbox app ID should have been set during hydration"
72473
+ );
72474
+ }
72475
+ this.#appId = appId;
72476
+ return appId;
72477
+ }
72478
+ async #resolveTaskIdForLogs() {
72479
+ if (this.#taskId !== void 0) {
72480
+ return this.#taskId;
72481
+ }
72482
+ let resp;
72483
+ try {
72484
+ resp = await this.#sandboxGetTaskId(
72485
+ void 0,
72486
+ SB_LOGS_TASK_ID_TIMEOUT_SECONDS
72487
+ );
72488
+ } catch (error) {
72489
+ if (error instanceof ClientError11 && error.code === Status11.DEADLINE_EXCEEDED) {
72490
+ throw new ExecutionError("Sandbox task ID is not available yet.");
72491
+ }
72492
+ throw error;
72493
+ }
72494
+ if (!resp.taskId) {
72495
+ throw new ExecutionError("Sandbox task ID is not available.");
72496
+ }
72497
+ this.#taskId = resp.taskId;
72498
+ return this.#taskId;
72499
+ }
72315
72500
  async #getTaskId(signal) {
72316
72501
  if (this.#taskId !== void 0) {
72317
72502
  return this.#taskId;
@@ -73320,7 +73505,7 @@ var AuthTokenManager = class {
73320
73505
  };
73321
73506
 
73322
73507
  // src/version.ts
73323
- var SDK_VERSION = "0.10.2-dev.6";
73508
+ var SDK_VERSION = "0.10.2-dev.7";
73324
73509
  function getSDKVersion() {
73325
73510
  return SDK_VERSION;
73326
73511
  }
@@ -74066,6 +74251,8 @@ function contextIds(batch, item, ObjectId) {
74066
74251
  item.inputId || batch.inputId,
74067
74252
  item.containerId || batch.taskId
74068
74253
  ].filter((id) => id);
74254
+ case "sb":
74255
+ return [item.containerId || batch.taskId].filter((id) => id);
74069
74256
  default:
74070
74257
  return [];
74071
74258
  }
@@ -74886,6 +75073,97 @@ var FunctionCallLogsManager = class extends LogsManager {
74886
75073
  );
74887
75074
  }
74888
75075
  };
75076
+ var SandboxLogsManager = class {
75077
+ /** @ignore */
75078
+ constructor(client, sandboxId, getAppId, getTaskId) {
75079
+ this.client = client;
75080
+ this.sandboxId = sandboxId;
75081
+ this.getAppId = getAppId;
75082
+ this.getTaskId = getTaskId;
75083
+ }
75084
+ /**
75085
+ * Fetch Sandbox entrypoint logs corresponding to a UTC time range and
75086
+ * optional filters.
75087
+ *
75088
+ * Entries are returned in chronological order.
75089
+ *
75090
+ * @returns An async iterable of {@link LogEntry} objects.
75091
+ *
75092
+ * @example
75093
+ * ```typescript
75094
+ * import { ModalClient } from "modal";
75095
+ *
75096
+ * const modal = new ModalClient();
75097
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
75098
+ *
75099
+ * for await (const entry of sandbox.logs.fetch({
75100
+ * since: new Date(Date.now() - 60 * 60 * 1_000),
75101
+ * source: "stdout",
75102
+ * })) {
75103
+ * process.stdout.write(entry.message);
75104
+ * }
75105
+ * ```
75106
+ */
75107
+ async *fetch(params) {
75108
+ const [appId, taskId] = await Promise.all([
75109
+ this.getAppId(),
75110
+ this.getTaskId()
75111
+ ]);
75112
+ if (!taskId) {
75113
+ throw new ExecutionError(
75114
+ "Cannot resolve Sandbox metadata needed for fetching logs. Wait for the Sandbox to be scheduled."
75115
+ );
75116
+ }
75117
+ yield* fetchLogs(
75118
+ this.client,
75119
+ {
75120
+ appId,
75121
+ objectId: this.sandboxId,
75122
+ taskId,
75123
+ source: sourceToFileDescriptor(params.source),
75124
+ searchText: params.searchText
75125
+ },
75126
+ params.since,
75127
+ params.until
75128
+ );
75129
+ }
75130
+ /**
75131
+ * Fetch the most recent Sandbox entrypoint logs.
75132
+ *
75133
+ * Entries are returned in chronological order.
75134
+ *
75135
+ * @returns An async iterable of {@link LogEntry} objects.
75136
+ *
75137
+ * @example
75138
+ * ```typescript
75139
+ * import { ModalClient } from "modal";
75140
+ *
75141
+ * const modal = new ModalClient();
75142
+ * const sandbox = await modal.sandboxes.fromId("sb-...");
75143
+ *
75144
+ * for await (const entry of sandbox.logs.tail({ entries: 20 })) {
75145
+ * process.stdout.write(entry.message);
75146
+ * }
75147
+ * ```
75148
+ */
75149
+ async *tail(params = {}) {
75150
+ const [appId, taskId] = await Promise.all([
75151
+ this.getAppId(),
75152
+ this.getTaskId()
75153
+ ]);
75154
+ if (!taskId) {
75155
+ throw new ExecutionError(
75156
+ "Sandbox task ID cannot be empty when fetching logs. Wait for the Sandbox to be scheduled."
75157
+ );
75158
+ }
75159
+ yield* tailLogs(this.client, params.entries ?? 100, {
75160
+ appId,
75161
+ objectId: this.sandboxId,
75162
+ taskId,
75163
+ source: sourceToFileDescriptor(params.source)
75164
+ });
75165
+ }
75166
+ };
74889
75167
 
74890
75168
  // src/function_call.ts
74891
75169
  var FunctionCallService = class {
@@ -75822,6 +76100,7 @@ export {
75822
76100
  SandboxFilesystemNotFoundError,
75823
76101
  SandboxFilesystemPathAlreadyExistsError,
75824
76102
  SandboxFilesystemPermissionError,
76103
+ SandboxLogsManager,
75825
76104
  SandboxService,
75826
76105
  SandboxSnapshot,
75827
76106
  SandboxSnapshotService,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modal",
3
- "version": "0.10.2-dev.6",
3
+ "version": "0.10.2-dev.7",
4
4
  "description": "Modal SDK for JavaScript/TypeScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://modal.com/docs/guide/sdk-javascript-go",