@sandblocks/cli 0.6.3 → 0.6.4

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/cli.js CHANGED
@@ -13387,7 +13387,7 @@ async function deployUnlocked(args, dependencies) {
13387
13387
  await deployDevelopmentUnlocked(context, loaded, preview);
13388
13388
  return;
13389
13389
  }
13390
- const deploymentTarget = await resolveDeploymentTarget(context, process.env.SANDBLOCKS_SANDBOX_TARGET_HOST ?? preview.targetHost);
13390
+ const deploymentTarget = await resolveDeploymentTarget(context, serviceMemoryReservation(preview.services), process.env.SANDBLOCKS_SANDBOX_TARGET_HOST ?? preview.targetHost);
13391
13391
  const targetHost = deploymentTarget.targetHost;
13392
13392
  context.state.deploymentHostId = deploymentTarget.hostId;
13393
13393
  context.state.deploymentWorkerId = deploymentTarget.workerId;
@@ -14003,15 +14003,22 @@ async function resolveDevelopmentTarget(context, fallback) {
14003
14003
  targetHost
14004
14004
  };
14005
14005
  }
14006
- async function resolveDeploymentTarget(context, fallback) {
14006
+ async function resolveDeploymentTarget(context, memoryReservationBytes, fallback) {
14007
14007
  const project = encodeURIComponent(context.state.projectId);
14008
- const workerBody = await request(context.apiUrl, context.apiKey, `/v1/projects/${project}/workers`);
14009
- const workers = Array.isArray(workerBody.workers) ? workerBody.workers : [];
14010
14008
  const requestedPool = process.env.SANDBLOCKS_DEPLOYMENT_WORKER_POOL?.trim() || process.env.SANDBLOCKS_RUNTIME_WORKER_POOL?.trim();
14011
- const eligible = workers.filter((worker2) => worker2?.status === "online" && Array.isArray(worker2.roles) && worker2.roles.includes("runtime"));
14012
- const worker = eligible.find((candidate) => typeof fallback === "string" && candidate?.configuration?.targetAddress === fallback.trim()) ?? eligible.find((candidate) => requestedPool && candidate.pool === requestedPool) ?? eligible[0];
14013
- if (!worker?.id)
14014
- throw new Error("no online deployment worker is available");
14009
+ const [workerBody, placementBody] = await Promise.all([
14010
+ request(context.apiUrl, context.apiKey, `/v1/projects/${project}/workers`),
14011
+ request(context.apiUrl, context.apiKey, `/v1/projects/${project}/placement/explain?kind=workspace.service.deploy&role=runtime&memoryReservationBytes=${memoryReservationBytes}${requestedPool ? `&pool=${encodeURIComponent(requestedPool)}` : ""}`)
14012
+ ]);
14013
+ const workers = Array.isArray(workerBody.workers) ? workerBody.workers : [];
14014
+ const candidates = Array.isArray(placementBody?.explanation?.candidates) ? placementBody.explanation.candidates : [];
14015
+ const eligibleWorkerIds = new Set(candidates.filter((candidate) => candidate?.eligible === true).map((candidate) => candidate.workerId));
14016
+ const eligible = workers.filter((worker2) => worker2?.status === "online" && Array.isArray(worker2.roles) && worker2.roles.includes("runtime") && eligibleWorkerIds.has(worker2.id));
14017
+ const worker = eligible.find((candidate) => typeof fallback === "string" && candidate?.configuration?.targetAddress === fallback.trim()) ?? eligible[0];
14018
+ if (!worker?.id) {
14019
+ const reasons = candidates.filter((candidate) => candidate?.workerId).map((candidate) => `${candidate.workerName ?? candidate.workerId}: ${(candidate.reasons ?? []).join(", ")}`).join("; ");
14020
+ throw new Error(`no eligible deployment worker is available${reasons ? ` (${reasons})` : ""}`);
14021
+ }
14015
14022
  let configuredTarget = worker?.configuration?.targetAddress;
14016
14023
  if (!configuredTarget && worker.hostId) {
14017
14024
  const legacyHosts = await request(context.apiUrl, context.apiKey, `/v1/projects/${project}/hosts`);
@@ -16649,4 +16656,4 @@ export {
16649
16656
  parse2 as parse
16650
16657
  };
16651
16658
 
16652
- //# debugId=1BF5DC414419B92F64756E2164756E21
16659
+ //# debugId=DEBD794B205F33E264756E2164756E21