modal 0.5.0-dev.6 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -43349,7 +43349,7 @@ function cborDecode(data) {
43349
43349
  }
43350
43350
 
43351
43351
  // src/invocation.ts
43352
- var outputsTimeout = 55 * 1e3;
43352
+ var outputsTimeoutMs = 55 * 1e3;
43353
43353
  var ControlPlaneInvocation = class _ControlPlaneInvocation {
43354
43354
  cpClient;
43355
43355
  functionCallId;
@@ -43385,19 +43385,18 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
43385
43385
  static fromFunctionCallId(client2, functionCallId) {
43386
43386
  return new _ControlPlaneInvocation(client2.cpClient, functionCallId);
43387
43387
  }
43388
- async awaitOutput(timeout) {
43388
+ async awaitOutput(timeoutMs) {
43389
43389
  return await pollFunctionOutput(
43390
43390
  this.cpClient,
43391
- (timeoutMillis) => this.#getOutput(timeoutMillis),
43392
- timeout
43391
+ (timeoutMs2) => this.#getOutput(timeoutMs2),
43392
+ timeoutMs
43393
43393
  );
43394
43394
  }
43395
- async #getOutput(timeoutMillis) {
43395
+ async #getOutput(timeoutMs) {
43396
43396
  const response = await this.cpClient.functionGetOutputs({
43397
43397
  functionCallId: this.functionCallId,
43398
43398
  maxValues: 1,
43399
- timeout: timeoutMillis / 1e3,
43400
- // Backend needs seconds
43399
+ timeout: timeoutMs / 1e3,
43401
43400
  lastEntryId: "0-0",
43402
43401
  clearOnSuccess: true,
43403
43402
  requestedAt: timeNowSeconds()
@@ -43451,18 +43450,18 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
43451
43450
  attemptStartResponse.attemptToken
43452
43451
  );
43453
43452
  }
43454
- async awaitOutput(timeout) {
43453
+ async awaitOutput(timeoutMs) {
43455
43454
  return await pollFunctionOutput(
43456
43455
  this.cpClient,
43457
- (timeoutMillis) => this.#getOutput(timeoutMillis),
43458
- timeout
43456
+ (timeoutMs2) => this.#getOutput(timeoutMs2),
43457
+ timeoutMs
43459
43458
  );
43460
43459
  }
43461
- async #getOutput(timeoutMillis) {
43460
+ async #getOutput(timeoutMs) {
43462
43461
  const response = await this.ipClient.attemptAwait({
43463
43462
  attemptToken: this.attemptToken,
43464
43463
  requestedAt: timeNowSeconds(),
43465
- timeoutSecs: timeoutMillis / 1e3
43464
+ timeoutSecs: timeoutMs / 1e3
43466
43465
  });
43467
43466
  return response.output;
43468
43467
  }
@@ -43478,24 +43477,24 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
43478
43477
  function timeNowSeconds() {
43479
43478
  return Date.now() / 1e3;
43480
43479
  }
43481
- async function pollFunctionOutput(cpClient, getOutput, timeout) {
43480
+ async function pollFunctionOutput(cpClient, getOutput, timeoutMs) {
43482
43481
  const startTime = Date.now();
43483
- let pollTimeout = outputsTimeout;
43484
- if (timeout !== void 0) {
43485
- pollTimeout = Math.min(timeout, outputsTimeout);
43482
+ let pollTimeoutMs = outputsTimeoutMs;
43483
+ if (timeoutMs !== void 0) {
43484
+ pollTimeoutMs = Math.min(timeoutMs, outputsTimeoutMs);
43486
43485
  }
43487
43486
  while (true) {
43488
- const output = await getOutput(pollTimeout);
43487
+ const output = await getOutput(pollTimeoutMs);
43489
43488
  if (output) {
43490
43489
  return await processResult(cpClient, output.result, output.dataFormat);
43491
43490
  }
43492
- if (timeout !== void 0) {
43493
- const remainingTime = timeout - (Date.now() - startTime);
43494
- if (remainingTime <= 0) {
43495
- const message = `Timeout exceeded: ${(timeout / 1e3).toFixed(1)}s`;
43491
+ if (timeoutMs !== void 0) {
43492
+ const remainingMs = timeoutMs - (Date.now() - startTime);
43493
+ if (remainingMs <= 0) {
43494
+ const message = `Timeout exceeded: ${timeoutMs}ms`;
43496
43495
  throw new FunctionTimeoutError(message);
43497
43496
  }
43498
- pollTimeout = Math.min(outputsTimeout, remainingTime);
43497
+ pollTimeoutMs = Math.min(outputsTimeoutMs, remainingMs);
43499
43498
  }
43500
43499
  }
43501
43500
  }
@@ -43550,6 +43549,18 @@ function deserializeDataFormat(data, dataFormat) {
43550
43549
  }
43551
43550
  }
43552
43551
 
43552
+ // src/validation.ts
43553
+ function checkForRenamedParams(params, renames) {
43554
+ if (!params) return;
43555
+ for (const [oldName, newName] of Object.entries(renames)) {
43556
+ if (oldName in params) {
43557
+ throw new Error(
43558
+ `Parameter '${oldName}' has been renamed to '${newName}'.`
43559
+ );
43560
+ }
43561
+ }
43562
+ }
43563
+
43553
43564
  // src/function_call.ts
43554
43565
  var FunctionCallService = class {
43555
43566
  #client;
@@ -43579,12 +43590,12 @@ var FunctionCall = class _FunctionCall {
43579
43590
  }
43580
43591
  /** Get the result of a FunctionCall, optionally waiting with a timeout. */
43581
43592
  async get(params = {}) {
43582
- const timeout = params.timeout;
43593
+ checkForRenamedParams(params, { timeout: "timeoutMs" });
43583
43594
  const invocation = ControlPlaneInvocation.fromFunctionCallId(
43584
43595
  this.#client || getDefaultClient(),
43585
43596
  this.functionCallId
43586
43597
  );
43587
- return invocation.awaitOutput(timeout);
43598
+ return invocation.awaitOutput(params.timeoutMs);
43588
43599
  }
43589
43600
  /** Cancel a running FunctionCall. */
43590
43601
  async cancel(params = {}) {
@@ -43704,7 +43715,7 @@ var Function_ = class {
43704
43715
  async getCurrentStats() {
43705
43716
  const resp = await this.#client.cpClient.functionGetCurrentStats(
43706
43717
  { functionId: this.functionId },
43707
- { timeout: 1e4 }
43718
+ { timeoutMs: 1e4 }
43708
43719
  );
43709
43720
  return {
43710
43721
  backlog: resp.backlog,
@@ -43713,6 +43724,7 @@ var Function_ = class {
43713
43724
  }
43714
43725
  // Overrides the current autoscaler behavior for this Function.
43715
43726
  async updateAutoscaler(params) {
43727
+ checkForRenamedParams(params, { scaledownWindow: "scaledownWindowMs" });
43716
43728
  await this.#client.cpClient.functionUpdateSchedulingParams({
43717
43729
  functionId: this.functionId,
43718
43730
  warmPoolSizeOverride: 0,
@@ -43721,7 +43733,7 @@ var Function_ = class {
43721
43733
  minContainers: params.minContainers,
43722
43734
  maxContainers: params.maxContainers,
43723
43735
  bufferContainers: params.bufferContainers,
43724
- scaledownWindow: params.scaledownWindow
43736
+ scaledownWindow: params.scaledownWindowMs !== void 0 ? Math.trunc(params.scaledownWindowMs / 1e3) : void 0
43725
43737
  }
43726
43738
  });
43727
43739
  }
@@ -44073,10 +44085,58 @@ function mergeServiceOptions(base, diff) {
44073
44085
  async function buildFunctionOptionsProto(options) {
44074
44086
  if (!options) return void 0;
44075
44087
  const o = options ?? {};
44088
+ checkForRenamedParams(o, {
44089
+ memory: "memoryMiB",
44090
+ memoryLimit: "memoryLimitMiB",
44091
+ scaledownWindow: "scaledownWindowMs",
44092
+ timeout: "timeoutMs"
44093
+ });
44076
44094
  const gpuConfig = parseGpuConfig(o.gpu);
44077
- const resources = o.cpu !== void 0 || o.memory !== void 0 || gpuConfig ? {
44078
- milliCpu: o.cpu !== void 0 ? Math.round(1e3 * o.cpu) : void 0,
44079
- memoryMb: o.memory,
44095
+ let milliCpu = void 0;
44096
+ let milliCpuMax = void 0;
44097
+ if (o.cpu === void 0 && o.cpuLimit !== void 0) {
44098
+ throw new Error("must also specify cpu when cpuLimit is specified");
44099
+ }
44100
+ if (o.cpu !== void 0) {
44101
+ if (o.cpu <= 0) {
44102
+ throw new Error(`cpu (${o.cpu}) must be a positive number`);
44103
+ }
44104
+ milliCpu = Math.trunc(1e3 * o.cpu);
44105
+ if (o.cpuLimit !== void 0) {
44106
+ if (o.cpuLimit < o.cpu) {
44107
+ throw new Error(
44108
+ `cpu (${o.cpu}) cannot be higher than cpuLimit (${o.cpuLimit})`
44109
+ );
44110
+ }
44111
+ milliCpuMax = Math.trunc(1e3 * o.cpuLimit);
44112
+ }
44113
+ }
44114
+ let memoryMb = void 0;
44115
+ let memoryMbMax = void 0;
44116
+ if (o.memoryMiB === void 0 && o.memoryLimitMiB !== void 0) {
44117
+ throw new Error(
44118
+ "must also specify memoryMiB when memoryLimitMiB is specified"
44119
+ );
44120
+ }
44121
+ if (o.memoryMiB !== void 0) {
44122
+ if (o.memoryMiB <= 0) {
44123
+ throw new Error(`memoryMiB (${o.memoryMiB}) must be a positive number`);
44124
+ }
44125
+ memoryMb = o.memoryMiB;
44126
+ if (o.memoryLimitMiB !== void 0) {
44127
+ if (o.memoryLimitMiB < o.memoryMiB) {
44128
+ throw new Error(
44129
+ `memoryMiB (${o.memoryMiB}) cannot be higher than memoryLimitMiB (${o.memoryLimitMiB})`
44130
+ );
44131
+ }
44132
+ memoryMbMax = o.memoryLimitMiB;
44133
+ }
44134
+ }
44135
+ const resources = milliCpu !== void 0 || milliCpuMax !== void 0 || memoryMb !== void 0 || memoryMbMax !== void 0 || gpuConfig ? {
44136
+ milliCpu,
44137
+ milliCpuMax,
44138
+ memoryMb,
44139
+ memoryMbMax,
44080
44140
  gpuConfig
44081
44141
  } : void 0;
44082
44142
  const secretIds = (o.secrets || []).map((s) => s.secretId);
@@ -44093,13 +44153,15 @@ async function buildFunctionOptionsProto(options) {
44093
44153
  initialDelayMs: parsedRetries.initialDelayMs,
44094
44154
  maxDelayMs: parsedRetries.maxDelayMs
44095
44155
  } : void 0;
44096
- if (o.scaledownWindow !== void 0 && o.scaledownWindow % 1e3 !== 0) {
44156
+ if (o.scaledownWindowMs !== void 0 && o.scaledownWindowMs % 1e3 !== 0) {
44097
44157
  throw new Error(
44098
- `scaledownWindow must be a multiple of 1000ms, got ${o.scaledownWindow}`
44158
+ `scaledownWindowMs must be a multiple of 1000ms, got ${o.scaledownWindowMs}`
44099
44159
  );
44100
44160
  }
44101
- if (o.timeout !== void 0 && o.timeout % 1e3 !== 0) {
44102
- throw new Error(`timeout must be a multiple of 1000ms, got ${o.timeout}`);
44161
+ if (o.timeoutMs !== void 0 && o.timeoutMs % 1e3 !== 0) {
44162
+ throw new Error(
44163
+ `timeoutMs must be a multiple of 1000ms, got ${o.timeoutMs}`
44164
+ );
44103
44165
  }
44104
44166
  const functionOptions = FunctionOptions.create({
44105
44167
  secretIds,
@@ -44110,8 +44172,8 @@ async function buildFunctionOptionsProto(options) {
44110
44172
  retryPolicy,
44111
44173
  concurrencyLimit: o.maxContainers,
44112
44174
  bufferContainers: o.bufferContainers,
44113
- taskIdleTimeoutSecs: o.scaledownWindow !== void 0 ? o.scaledownWindow / 1e3 : void 0,
44114
- timeoutSecs: o.timeout !== void 0 ? o.timeout / 1e3 : void 0,
44175
+ taskIdleTimeoutSecs: o.scaledownWindowMs !== void 0 ? o.scaledownWindowMs / 1e3 : void 0,
44176
+ timeoutSecs: o.timeoutMs !== void 0 ? o.timeoutMs / 1e3 : void 0,
44115
44177
  maxConcurrentInputs: o.maxConcurrentInputs,
44116
44178
  targetConcurrentInputs: o.targetConcurrentInputs,
44117
44179
  batchMaxSize: o.batchMaxSize,
@@ -44891,8 +44953,8 @@ var EphemeralHeartbeatManager = class {
44891
44953
  };
44892
44954
 
44893
44955
  // src/queue.ts
44894
- var queueInitialPutBackoff = 100;
44895
- var queueDefaultPartitionTtl = 24 * 3600 * 1e3;
44956
+ var queueInitialPutBackoffMs = 100;
44957
+ var queueDefaultPartitionTtlMs = 24 * 3600 * 1e3;
44896
44958
  var QueueService = class {
44897
44959
  #client;
44898
44960
  constructor(client2) {
@@ -44996,30 +45058,30 @@ var Queue = class _Queue {
44996
45058
  allPartitions: params.all
44997
45059
  });
44998
45060
  }
44999
- async #get(n, partition, timeout) {
45061
+ async #get(n, partition, timeoutMs) {
45000
45062
  const partitionKey = _Queue.#validatePartitionKey(partition);
45001
45063
  const startTime = Date.now();
45002
- let pollTimeout = 5e4;
45003
- if (timeout !== void 0) {
45004
- pollTimeout = Math.min(pollTimeout, timeout);
45064
+ let pollTimeoutMs = 5e4;
45065
+ if (timeoutMs !== void 0) {
45066
+ pollTimeoutMs = Math.min(pollTimeoutMs, timeoutMs);
45005
45067
  }
45006
45068
  while (true) {
45007
45069
  const response = await this.#client.cpClient.queueGet({
45008
45070
  queueId: this.queueId,
45009
45071
  partitionKey,
45010
- timeout: pollTimeout / 1e3,
45072
+ timeout: pollTimeoutMs / 1e3,
45011
45073
  nValues: n
45012
45074
  });
45013
45075
  if (response.values && response.values.length > 0) {
45014
45076
  return response.values.map((value) => loads(value));
45015
45077
  }
45016
- if (timeout !== void 0) {
45017
- const remaining = timeout - (Date.now() - startTime);
45018
- if (remaining <= 0) {
45019
- const message = `Queue ${this.queueId} did not return values within ${timeout}ms.`;
45078
+ if (timeoutMs !== void 0) {
45079
+ const remainingMs = timeoutMs - (Date.now() - startTime);
45080
+ if (remainingMs <= 0) {
45081
+ const message = `Queue ${this.queueId} did not return values within ${timeoutMs}ms.`;
45020
45082
  throw new QueueEmptyError(message);
45021
45083
  }
45022
- pollTimeout = Math.min(pollTimeout, remaining);
45084
+ pollTimeoutMs = Math.min(pollTimeoutMs, remainingMs);
45023
45085
  }
45024
45086
  }
45025
45087
  }
@@ -45027,35 +45089,37 @@ var Queue = class _Queue {
45027
45089
  * Remove and return the next object from the Queue.
45028
45090
  *
45029
45091
  * By default, this will wait until at least one item is present in the Queue.
45030
- * If `timeout` is set, raises `QueueEmptyError` if no items are available
45092
+ * If `timeoutMs` is set, raises `QueueEmptyError` if no items are available
45031
45093
  * within that timeout in milliseconds.
45032
45094
  */
45033
45095
  async get(params = {}) {
45034
- const values = await this.#get(1, params.partition, params.timeout);
45096
+ checkForRenamedParams(params, { timeout: "timeoutMs" });
45097
+ const values = await this.#get(1, params.partition, params.timeoutMs);
45035
45098
  return values[0];
45036
45099
  }
45037
45100
  /**
45038
45101
  * Remove and return up to `n` objects from the Queue.
45039
45102
  *
45040
45103
  * By default, this will wait until at least one item is present in the Queue.
45041
- * If `timeout` is set, raises `QueueEmptyError` if no items are available
45104
+ * If `timeoutMs` is set, raises `QueueEmptyError` if no items are available
45042
45105
  * within that timeout in milliseconds.
45043
45106
  */
45044
45107
  async getMany(n, params = {}) {
45045
- return await this.#get(n, params.partition, params.timeout);
45108
+ checkForRenamedParams(params, { timeout: "timeoutMs" });
45109
+ return await this.#get(n, params.partition, params.timeoutMs);
45046
45110
  }
45047
- async #put(values, timeout, partition, partitionTtl) {
45111
+ async #put(values, timeoutMs, partition, partitionTtlMs) {
45048
45112
  const valuesEncoded = values.map((v) => dumps(v));
45049
45113
  const partitionKey = _Queue.#validatePartitionKey(partition);
45050
- let delay = queueInitialPutBackoff;
45051
- const deadline = timeout ? Date.now() + timeout : void 0;
45114
+ let delay = queueInitialPutBackoffMs;
45115
+ const deadline = timeoutMs ? Date.now() + timeoutMs : void 0;
45052
45116
  while (true) {
45053
45117
  try {
45054
45118
  await this.#client.cpClient.queuePut({
45055
45119
  queueId: this.queueId,
45056
45120
  values: valuesEncoded,
45057
45121
  partitionKey,
45058
- partitionTtlSeconds: (partitionTtl || queueDefaultPartitionTtl) / 1e3
45122
+ partitionTtlSeconds: (partitionTtlMs || queueDefaultPartitionTtlMs) / 1e3
45059
45123
  });
45060
45124
  break;
45061
45125
  } catch (e) {
@@ -45078,25 +45142,38 @@ var Queue = class _Queue {
45078
45142
  * Add an item to the end of the Queue.
45079
45143
  *
45080
45144
  * If the Queue is full, this will retry with exponential backoff until the
45081
- * provided `timeout` is reached, or indefinitely if `timeout` is not set.
45145
+ * provided `timeoutMs` is reached, or indefinitely if `timeoutMs` is not set.
45082
45146
  * Raises {@link QueueFullError} if the Queue is still full after the timeout.
45083
45147
  */
45084
45148
  async put(v, params = {}) {
45085
- await this.#put([v], params.timeout, params.partition, params.partitionTtl);
45149
+ checkForRenamedParams(params, {
45150
+ timeout: "timeoutMs",
45151
+ partitionTtl: "partitionTtlMs"
45152
+ });
45153
+ await this.#put(
45154
+ [v],
45155
+ params.timeoutMs,
45156
+ params.partition,
45157
+ params.partitionTtlMs
45158
+ );
45086
45159
  }
45087
45160
  /**
45088
45161
  * Add several items to the end of the Queue.
45089
45162
  *
45090
45163
  * If the Queue is full, this will retry with exponential backoff until the
45091
- * provided `timeout` is reached, or indefinitely if `timeout` is not set.
45164
+ * provided `timeoutMs` is reached, or indefinitely if `timeoutMs` is not set.
45092
45165
  * Raises {@link QueueFullError} if the Queue is still full after the timeout.
45093
45166
  */
45094
45167
  async putMany(values, params = {}) {
45168
+ checkForRenamedParams(params, {
45169
+ timeout: "timeoutMs",
45170
+ partitionTtl: "partitionTtlMs"
45171
+ });
45095
45172
  await this.#put(
45096
45173
  values,
45097
- params.timeout,
45174
+ params.timeoutMs,
45098
45175
  params.partition,
45099
- params.partitionTtl
45176
+ params.partitionTtlMs
45100
45177
  );
45101
45178
  }
45102
45179
  /** Return the number of objects in the Queue. */
@@ -45115,20 +45192,21 @@ var Queue = class _Queue {
45115
45192
  }
45116
45193
  /** Iterate through items in a Queue without mutation. */
45117
45194
  async *iterate(params = {}) {
45118
- const { partition, itemPollTimeout = 0 } = params;
45195
+ checkForRenamedParams(params, { itemPollTimeout: "itemPollTimeoutMs" });
45196
+ const { partition, itemPollTimeoutMs = 0 } = params;
45119
45197
  let lastEntryId = void 0;
45120
45198
  const validatedPartitionKey = _Queue.#validatePartitionKey(partition);
45121
- let fetchDeadline = Date.now() + itemPollTimeout;
45122
- const maxPollDuration = 3e4;
45199
+ let fetchDeadline = Date.now() + itemPollTimeoutMs;
45200
+ const maxPollDurationMs = 3e4;
45123
45201
  while (true) {
45124
- const pollDuration = Math.max(
45202
+ const pollDurationMs = Math.max(
45125
45203
  0,
45126
- Math.min(maxPollDuration, fetchDeadline - Date.now())
45204
+ Math.min(maxPollDurationMs, fetchDeadline - Date.now())
45127
45205
  );
45128
45206
  const request = {
45129
45207
  queueId: this.queueId,
45130
45208
  partitionKey: validatedPartitionKey,
45131
- itemPollTimeout: pollDuration / 1e3,
45209
+ itemPollTimeout: pollDurationMs / 1e3,
45132
45210
  lastEntryId: lastEntryId || ""
45133
45211
  };
45134
45212
  const response = await this.#client.cpClient.queueNextItems(request);
@@ -45137,7 +45215,7 @@ var Queue = class _Queue {
45137
45215
  yield loads(item.value);
45138
45216
  lastEntryId = item.entryId;
45139
45217
  }
45140
- fetchDeadline = Date.now() + itemPollTimeout;
45218
+ fetchDeadline = Date.now() + itemPollTimeoutMs;
45141
45219
  } else if (Date.now() > fetchDeadline) {
45142
45220
  break;
45143
45221
  }
@@ -45424,15 +45502,21 @@ function cloudBucketMountToProto(mount, mountPath) {
45424
45502
 
45425
45503
  // src/sandbox.ts
45426
45504
  async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45505
+ checkForRenamedParams(params, {
45506
+ memory: "memoryMiB",
45507
+ memoryLimit: "memoryLimitMiB",
45508
+ timeout: "timeoutMs",
45509
+ idleTimeout: "idleTimeoutMs"
45510
+ });
45427
45511
  const gpuConfig = parseGpuConfig(params.gpu);
45428
- if (params.timeout && params.timeout % 1e3 !== 0) {
45512
+ if (params.timeoutMs && params.timeoutMs % 1e3 !== 0) {
45429
45513
  throw new Error(
45430
- `timeout must be a multiple of 1000ms, got ${params.timeout}`
45514
+ `timeoutMs must be a multiple of 1000ms, got ${params.timeoutMs}`
45431
45515
  );
45432
45516
  }
45433
- if (params.idleTimeout && params.idleTimeout % 1e3 !== 0) {
45517
+ if (params.idleTimeoutMs && params.idleTimeoutMs % 1e3 !== 0) {
45434
45518
  throw new Error(
45435
- `idleTimeout must be a multiple of 1000ms, got ${params.idleTimeout}`
45519
+ `idleTimeoutMs must be a multiple of 1000ms, got ${params.idleTimeoutMs}`
45436
45520
  );
45437
45521
  }
45438
45522
  if (params.workdir && !params.workdir.startsWith("/")) {
@@ -45503,20 +45587,63 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45503
45587
  if (params.pty) {
45504
45588
  ptyInfo = defaultSandboxPTYInfo();
45505
45589
  }
45590
+ let milliCpu = void 0;
45591
+ let milliCpuMax = void 0;
45592
+ if (params.cpu === void 0 && params.cpuLimit !== void 0) {
45593
+ throw new Error("must also specify cpu when cpuLimit is specified");
45594
+ }
45595
+ if (params.cpu !== void 0) {
45596
+ if (params.cpu <= 0) {
45597
+ throw new Error(`cpu (${params.cpu}) must be a positive number`);
45598
+ }
45599
+ milliCpu = Math.trunc(1e3 * params.cpu);
45600
+ if (params.cpuLimit !== void 0) {
45601
+ if (params.cpuLimit < params.cpu) {
45602
+ throw new Error(
45603
+ `cpu (${params.cpu}) cannot be higher than cpuLimit (${params.cpuLimit})`
45604
+ );
45605
+ }
45606
+ milliCpuMax = Math.trunc(1e3 * params.cpuLimit);
45607
+ }
45608
+ }
45609
+ let memoryMb = void 0;
45610
+ let memoryMbMax = void 0;
45611
+ if (params.memoryMiB === void 0 && params.memoryLimitMiB !== void 0) {
45612
+ throw new Error(
45613
+ "must also specify memoryMiB when memoryLimitMiB is specified"
45614
+ );
45615
+ }
45616
+ if (params.memoryMiB !== void 0) {
45617
+ if (params.memoryMiB <= 0) {
45618
+ throw new Error(
45619
+ `the memoryMiB request (${params.memoryMiB}) must be a positive number`
45620
+ );
45621
+ }
45622
+ memoryMb = params.memoryMiB;
45623
+ if (params.memoryLimitMiB !== void 0) {
45624
+ if (params.memoryLimitMiB < params.memoryMiB) {
45625
+ throw new Error(
45626
+ `the memoryMiB request (${params.memoryMiB}) cannot be higher than memoryLimitMiB (${params.memoryLimitMiB})`
45627
+ );
45628
+ }
45629
+ memoryMbMax = params.memoryLimitMiB;
45630
+ }
45631
+ }
45506
45632
  return SandboxCreateRequest.create({
45507
45633
  appId,
45508
45634
  definition: {
45509
45635
  // Sleep default is implicit in image builder version <=2024.10
45510
45636
  entrypointArgs: params.command ?? ["sleep", "48h"],
45511
45637
  imageId,
45512
- timeoutSecs: params.timeout != void 0 ? params.timeout / 1e3 : 600,
45513
- idleTimeoutSecs: params.idleTimeout != void 0 ? params.idleTimeout / 1e3 : void 0,
45638
+ timeoutSecs: params.timeoutMs != void 0 ? params.timeoutMs / 1e3 : 600,
45639
+ idleTimeoutSecs: params.idleTimeoutMs != void 0 ? params.idleTimeoutMs / 1e3 : void 0,
45514
45640
  workdir: params.workdir ?? void 0,
45515
45641
  networkAccess,
45516
45642
  resources: {
45517
- // https://modal.com/docs/guide/resources
45518
- milliCpu: Math.round(1e3 * (params.cpu ?? 0.125)),
45519
- memoryMb: params.memory ?? 128,
45643
+ milliCpu,
45644
+ milliCpuMax,
45645
+ memoryMb,
45646
+ memoryMbMax,
45520
45647
  gpuConfig
45521
45648
  },
45522
45649
  volumeMounts,
@@ -45691,6 +45818,7 @@ function defaultSandboxPTYInfo() {
45691
45818
  });
45692
45819
  }
45693
45820
  async function buildContainerExecRequestProto(taskId, command, params) {
45821
+ checkForRenamedParams(params, { timeout: "timeoutMs" });
45694
45822
  const secretIds = (params?.secrets || []).map((secret) => secret.secretId);
45695
45823
  let ptyInfo;
45696
45824
  if (params?.pty) {
@@ -45700,7 +45828,7 @@ async function buildContainerExecRequestProto(taskId, command, params) {
45700
45828
  taskId,
45701
45829
  command,
45702
45830
  workdir: params?.workdir,
45703
- timeoutSecs: params?.timeout ? params.timeout / 1e3 : 0,
45831
+ timeoutSecs: params?.timeoutMs ? params.timeoutMs / 1e3 : 0,
45704
45832
  secretIds,
45705
45833
  ptyInfo
45706
45834
  });
@@ -45868,14 +45996,13 @@ var Sandbox2 = class _Sandbox {
45868
45996
  *
45869
45997
  * @returns A dictionary of {@link Tunnel} objects which are keyed by the container port.
45870
45998
  */
45871
- async tunnels(timeout = 5e4) {
45999
+ async tunnels(timeoutMs = 5e4) {
45872
46000
  if (this.#tunnels) {
45873
46001
  return this.#tunnels;
45874
46002
  }
45875
46003
  const resp = await this.#client.cpClient.sandboxGetTunnels({
45876
46004
  sandboxId: this.sandboxId,
45877
- timeout: timeout / 1e3
45878
- // Convert to seconds
46005
+ timeout: timeoutMs / 1e3
45879
46006
  });
45880
46007
  if (resp.result?.status === 4 /* GENERIC_STATUS_TIMEOUT */) {
45881
46008
  throw new SandboxTimeoutError();
@@ -45896,13 +46023,13 @@ var Sandbox2 = class _Sandbox {
45896
46023
  *
45897
46024
  * Returns an {@link Image} object which can be used to spawn a new Sandbox with the same filesystem.
45898
46025
  *
45899
- * @param timeout - Timeout for the snapshot operation in milliseconds
46026
+ * @param timeoutMs - Timeout for the snapshot operation in milliseconds
45900
46027
  * @returns Promise that resolves to an {@link Image}
45901
46028
  */
45902
- async snapshotFilesystem(timeout = 55e3) {
46029
+ async snapshotFilesystem(timeoutMs = 55e3) {
45903
46030
  const resp = await this.#client.cpClient.sandboxSnapshotFs({
45904
46031
  sandboxId: this.sandboxId,
45905
- timeout: timeout / 1e3
46032
+ timeout: timeoutMs / 1e3
45906
46033
  });
45907
46034
  if (resp.result?.status !== 1 /* GENERIC_STATUS_SUCCESS */) {
45908
46035
  throw new Error(
@@ -46354,7 +46481,7 @@ var AuthTokenManager = class {
46354
46481
 
46355
46482
  // src/version.ts
46356
46483
  function getSDKVersion() {
46357
- return true ? "0.5.0-dev.6" : "0.0.0";
46484
+ return true ? "0.5.0" : "0.0.0";
46358
46485
  }
46359
46486
 
46360
46487
  // src/client.ts
@@ -46375,6 +46502,7 @@ var ModalClient = class {
46375
46502
  ipClients;
46376
46503
  authTokenManager = null;
46377
46504
  constructor(params) {
46505
+ checkForRenamedParams(params, { timeout: "timeoutMs" });
46378
46506
  const baseProfile = getProfile(process.env["MODAL_PROFILE"]);
46379
46507
  this.profile = {
46380
46508
  ...baseProfile,
@@ -46468,10 +46596,10 @@ var ModalClient = class {
46468
46596
  }
46469
46597
  };
46470
46598
  var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
46471
- if (!options.timeout || options.signal?.aborted) {
46599
+ if (!options.timeoutMs || options.signal?.aborted) {
46472
46600
  return yield* call.next(call.request, options);
46473
46601
  }
46474
- const { timeout, signal: origSignal, ...restOptions } = options;
46602
+ const { timeoutMs, signal: origSignal, ...restOptions } = options;
46475
46603
  const abortController = new AbortController();
46476
46604
  const abortListener = () => abortController.abort();
46477
46605
  origSignal?.addEventListener("abort", abortListener);
@@ -46479,7 +46607,7 @@ var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
46479
46607
  const timer = setTimeout(() => {
46480
46608
  timedOut = true;
46481
46609
  abortController.abort();
46482
- }, timeout);
46610
+ }, timeoutMs);
46483
46611
  try {
46484
46612
  return yield* call.next(call.request, {
46485
46613
  ...restOptions,
@@ -46492,7 +46620,7 @@ var timeoutMiddleware = async function* timeoutMiddleware2(call, options) {
46492
46620
  throw new ClientError9(
46493
46621
  call.method.path,
46494
46622
  Status9.DEADLINE_EXCEEDED,
46495
- `Timed out after ${timeout}ms`
46623
+ `Timed out after ${timeoutMs}ms`
46496
46624
  );
46497
46625
  }
46498
46626
  }
@@ -46718,6 +46846,7 @@ export {
46718
46846
  SecretService,
46719
46847
  Volume,
46720
46848
  VolumeService,
46849
+ checkForRenamedParams,
46721
46850
  close,
46722
46851
  initializeClient
46723
46852
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "modal",
3
- "version": "0.5.0-dev.6",
4
- "description": "Modal client library for JavaScript",
3
+ "version": "0.5.0",
4
+ "description": "Modal SDK for JavaScript/TypeScript",
5
5
  "license": "Apache-2.0",
6
- "homepage": "https://modal.com/docs",
6
+ "homepage": "https://modal.com/docs/guide/sdk-javascript-go",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/modal-labs/libmodal.git"