run402 4.158.2 → 4.159.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "run402",
3
- "version": "4.158.2",
3
+ "version": "4.159.1",
4
4
  "description": "CLI for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/namespaces/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAwB3C,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EAQtB,WAAW,EACX,oBAAoB,EAEpB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EAOvB,sBAAsB,EACtB,oBAAoB,EAUpB,iBAAiB,EAGjB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,2BAA2B,EAC3B,uBAAuB,EACvB,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAGlB,YAAY,EAEb,MAAM,mBAAmB,CAAC;AA4H3B,qBAAa,MAAM;IACL,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAnC,YAA6B,MAAM,EAAE,MAAM,EAAI;IAE/C;;;;OAIG;IACG,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAiD7E;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,C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A;KAAE,GACxB,OAAO,CAAC,mBAAmB,CAAC,CAuB9B;IAED;;;;OAIG;IACG,gBAAgB,CACpB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,wBAAwB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAkClC;IAED;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA2B7E;IAED;;;;OAIG;IACG,gBAAgB,CACpB,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,sBAAsB,CAAC,CAmBjC;IAED;;;;OAIG;IACG,IAAI,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6BlE;IAED;;;;OAIG;IACG,OAAO,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAUxE;CACF;AA42DD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;iEAG6D;IAC7D,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;CACvC;AA8qFD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKrD"}
@@ -88,34 +88,6 @@ const STATIC_ACTIVATION_FAILURE_CODES = new Set([
88
88
  "FUNCTION_SCHEDULE_LIMIT_EXCEEDED",
89
89
  "TIER_LIMIT_EXCEEDED",
90
90
  ]);
91
- const STATIC_FUNCTION_LIMITS_BY_TIER = {
92
- prototype: {
93
- maxTimeoutSeconds: 10,
94
- maxRunTimeoutSeconds: 10,
95
- maxMemoryMb: 128,
96
- maxSsrMemoryMb: 128,
97
- maxScheduledFunctions: 1,
98
- minCronIntervalMinutes: 15,
99
- },
100
- hobby: {
101
- maxTimeoutSeconds: 30,
102
- maxRunTimeoutSeconds: 30,
103
- maxMemoryMb: 256,
104
- maxSsrMemoryMb: 256,
105
- maxScheduledFunctions: 3,
106
- minCronIntervalMinutes: 5,
107
- },
108
- team: {
109
- maxTimeoutSeconds: 60,
110
- // A run function (class "run"), which only function runs reach, may take five minutes.
111
- maxRunTimeoutSeconds: 300,
112
- maxMemoryMb: 512,
113
- // An SSR-class function (the Astro `ssr` function) may use one vCPU.
114
- maxSsrMemoryMb: 1769,
115
- maxScheduledFunctions: 10,
116
- minCronIntervalMinutes: 1,
117
- },
118
- };
119
91
  const MANIFEST_CONTENT_TYPE = "application/vnd.run402.deploy-manifest+json";
120
92
  const TERMINAL_STATUSES = ["ready", "failed"];
121
93
  const SUCCESS_STATUS = "ready";
@@ -1264,8 +1236,6 @@ async function planInternal(client, spec, idempotencyKey, opts = {}) {
1264
1236
  const { normalized, byteReaders } = await normalizeReleaseSpec(client, spec, {
1265
1237
  inlineMigrationSql: isCore,
1266
1238
  });
1267
- if (!isCore)
1268
- await preflightTierFunctionLimits(client, normalized, ciCredentials);
1269
1239
  const wireSpec = isCore ? releaseSpecToCoreSpec(normalized) : releaseSpecToWire(normalized);
1270
1240
  // The gateway expects { spec, manifest_ref?, idempotency_key? }. Cloud
1271
1241
  // receives the legacy snake_case apply wire shape; Core receives the
@@ -1350,398 +1320,6 @@ function requiredPlanToWire(plan) {
1350
1320
  wire.plan_fingerprint = plan.planFingerprint;
1351
1321
  return wire;
1352
1322
  }
1353
- async function preflightTierFunctionLimits(client, spec, ciCredentials) {
1354
- if (ciCredentials)
1355
- return;
1356
- if (!hasFunctionTierPreflightInputs(spec.functions))
1357
- return;
1358
- const limits = await readTierFunctionLimits(client, spec.project_id);
1359
- if (!limits)
1360
- return;
1361
- const entries = collectFunctionPreflightEntries(spec.functions);
1362
- for (const entry of entries) {
1363
- const timeout = entry.fn.config?.timeoutSeconds;
1364
- // A run function has its own timeout cap. With no class declared the
1365
- // function keeps its stored one, which only the gateway knows.
1366
- const timeoutLimit = entry.fn.class === "run"
1367
- ? limits.maxRunTimeoutSeconds ?? limits.maxTimeoutSeconds
1368
- : entry.fn.class === undefined
1369
- ? largerLimit(limits.maxTimeoutSeconds, limits.maxRunTimeoutSeconds)
1370
- : limits.maxTimeoutSeconds;
1371
- if (timeout !== undefined &&
1372
- timeoutLimit &&
1373
- timeout > timeoutLimit.value) {
1374
- throw tierLimitError(`Function ${entry.name} timeoutSeconds ${timeout} exceeds the ${limits.tier} tier maximum of ${timeoutLimit.value}.`, `${entry.fieldPrefix}.config.timeoutSeconds`, timeout, limits, timeoutLimit, {
1375
- tier_max: timeoutLimit.value,
1376
- max_function_timeout_seconds: timeoutLimit.value,
1377
- });
1378
- }
1379
- const memory = entry.fn.config?.memoryMb;
1380
- // An SSR-class function has its own cap. With no class declared the
1381
- // function keeps its stored one, which only the gateway knows.
1382
- const memoryLimit = entry.fn.class === "ssr"
1383
- ? limits.maxSsrMemoryMb ?? limits.maxMemoryMb
1384
- : entry.fn.class === undefined
1385
- ? largerLimit(limits.maxMemoryMb, limits.maxSsrMemoryMb)
1386
- : limits.maxMemoryMb;
1387
- if (memory !== undefined &&
1388
- memoryLimit &&
1389
- memory > memoryLimit.value) {
1390
- throw tierLimitError(`Function ${entry.name} memoryMb ${memory} exceeds the ${limits.tier} tier maximum of ${memoryLimit.value}.`, `${entry.fieldPrefix}.config.memoryMb`, memory, limits, memoryLimit, {
1391
- tier_max: memoryLimit.value,
1392
- max_function_memory_mb: memoryLimit.value,
1393
- });
1394
- }
1395
- for (const trigger of scheduleTriggersForFunction(entry.fn)) {
1396
- if (!limits.minCronIntervalMinutes)
1397
- continue;
1398
- const intervalMinutes = estimateCronMinimumIntervalMinutes(trigger.cron);
1399
- if (intervalMinutes !== null &&
1400
- intervalMinutes < limits.minCronIntervalMinutes.value) {
1401
- const triggerLabel = trigger.id ? `trigger ${trigger.id}` : "schedule trigger";
1402
- throw tierLimitError(`Function ${entry.name} ${triggerLabel} runs every ${intervalMinutes} minute(s), below the ${limits.tier} tier minimum interval of ${limits.minCronIntervalMinutes.value} minutes.`, `${entry.fieldPrefix}.${trigger.fieldSuffix}`, trigger.cron, limits, limits.minCronIntervalMinutes, {
1403
- interval_minutes: intervalMinutes,
1404
- min_interval_minutes: limits.minCronIntervalMinutes.value,
1405
- min_cron_interval_minutes: limits.minCronIntervalMinutes.value,
1406
- });
1407
- }
1408
- }
1409
- }
1410
- if (limits.maxScheduledFunctions) {
1411
- const lowerBound = countScheduledFunctionsInSetEntries(spec.functions);
1412
- if (lowerBound > limits.maxScheduledFunctions.value) {
1413
- throw scheduledCountTierLimitError(lowerBound, limits, limits.maxScheduledFunctions, "manifest");
1414
- }
1415
- const desired = await computeDesiredScheduledFunctionCount(client, spec);
1416
- if (desired && desired.count > limits.maxScheduledFunctions.value) {
1417
- throw scheduledCountTierLimitError(desired.count, limits, limits.maxScheduledFunctions, desired.source);
1418
- }
1419
- }
1420
- }
1421
- function largerLimit(a, b) {
1422
- if (!a)
1423
- return b;
1424
- if (!b)
1425
- return a;
1426
- return b.value > a.value ? b : a;
1427
- }
1428
- function hasFunctionTierPreflightInputs(functions) {
1429
- if (!functions)
1430
- return false;
1431
- return collectFunctionPreflightEntries(functions).some((entry) => (entry.fn.config?.timeoutSeconds !== undefined ||
1432
- entry.fn.config?.memoryMb !== undefined ||
1433
- scheduleTriggersForFunction(entry.fn).length > 0));
1434
- }
1435
- function collectFunctionPreflightEntries(functions) {
1436
- if (!functions)
1437
- return [];
1438
- const entries = [];
1439
- for (const [name, fn] of Object.entries(functions.replace ?? {})) {
1440
- entries.push({ name, fn, fieldPrefix: `functions.${name}` });
1441
- }
1442
- for (const [name, fn] of Object.entries(functions.patch?.set ?? {})) {
1443
- entries.push({ name, fn, fieldPrefix: `functions.${name}` });
1444
- }
1445
- return entries;
1446
- }
1447
- /**
1448
- * The function caps of the tier the deploy is judged by: the tier of the
1449
- * organization that owns the project. `/tiers/v1/status` describes the
1450
- * wallet's own organization, so its caps count only when the project's tier
1451
- * is the same; otherwise the static table for the project's tier applies.
1452
- * When the project cannot be read, the wallet's own tier is used.
1453
- */
1454
- async function readTierFunctionLimits(client, projectId) {
1455
- let status;
1456
- try {
1457
- status = await client.request("/tiers/v1/status", {
1458
- context: "checking tier status for deploy preflight",
1459
- });
1460
- }
1461
- catch {
1462
- return null;
1463
- }
1464
- const projectTier = await readProjectTier(client, projectId);
1465
- let walletTier;
1466
- if (projectTier && projectTier.toLowerCase() !== String(status.tier ?? "").toLowerCase()) {
1467
- walletTier = typeof status.tier === "string" ? status.tier : "";
1468
- status = { tier: projectTier };
1469
- }
1470
- if (typeof status.tier !== "string" || status.tier.length === 0) {
1471
- return null;
1472
- }
1473
- const tierKey = status.tier.toLowerCase();
1474
- const fallback = STATIC_FUNCTION_LIMITS_BY_TIER[tierKey];
1475
- const limits = { tier: status.tier };
1476
- if (walletTier !== undefined)
1477
- limits.walletTier = walletTier;
1478
- limits.maxTimeoutSeconds = tierStatusLimitOrFallback(status, [
1479
- "max_function_timeout_seconds",
1480
- "max_timeout_seconds",
1481
- "timeout_seconds_max",
1482
- "function_timeout_seconds_max",
1483
- ], fallback?.maxTimeoutSeconds);
1484
- limits.maxMemoryMb = tierStatusLimitOrFallback(status, [
1485
- "max_function_memory_mb",
1486
- "max_memory_mb",
1487
- "memory_mb_max",
1488
- "function_memory_mb_max",
1489
- ], fallback?.maxMemoryMb);
1490
- // tier status names no SSR memory cap or run timeout cap, so they come from the static table.
1491
- if (fallback)
1492
- limits.maxSsrMemoryMb = { value: fallback.maxSsrMemoryMb, source: "local_static_fallback" };
1493
- if (fallback)
1494
- limits.maxRunTimeoutSeconds = { value: fallback.maxRunTimeoutSeconds, source: "local_static_fallback" };
1495
- limits.maxScheduledFunctions = tierStatusLimitOrFallback(status, [
1496
- "max_scheduled_functions",
1497
- "scheduled_functions_limit",
1498
- "scheduled_function_limit",
1499
- "max_function_schedules",
1500
- ], fallback?.maxScheduledFunctions);
1501
- limits.minCronIntervalMinutes = tierStatusLimitOrFallback(status, [
1502
- "min_cron_interval_minutes",
1503
- "minimum_cron_interval_minutes",
1504
- "min_schedule_interval_minutes",
1505
- "min_scheduled_function_interval_minutes",
1506
- ], fallback?.minCronIntervalMinutes);
1507
- limits.currentScheduledFunctions = tierStatusLimit(status, [
1508
- "current_scheduled_functions",
1509
- "current_scheduled_function_count",
1510
- "scheduled_function_count",
1511
- "scheduled_functions",
1512
- ]);
1513
- return hasAnyTierFunctionLimit(limits) ? limits : null;
1514
- }
1515
- async function readProjectTier(client, projectId) {
1516
- try {
1517
- const project = await client.request(`/projects/v1/${encodeURIComponent(projectId)}`, {
1518
- method: "GET",
1519
- context: "checking the project's tier for deploy preflight",
1520
- });
1521
- return typeof project.tier === "string" && project.tier.length > 0 ? project.tier : null;
1522
- }
1523
- catch {
1524
- return null;
1525
- }
1526
- }
1527
- function tierStatusLimitOrFallback(status, keys, fallback) {
1528
- return tierStatusLimit(status, keys) ?? (fallback === undefined
1529
- ? undefined
1530
- : { value: fallback, source: "local_static_fallback" });
1531
- }
1532
- function tierStatusLimit(status, keys) {
1533
- const limits = objectField(status, "limits");
1534
- const containers = [
1535
- objectField(status, "function_limits"),
1536
- objectField(limits, "functions"),
1537
- objectField(limits, "function_limits"),
1538
- objectField(status, "pool_usage"),
1539
- status,
1540
- ];
1541
- for (const container of containers) {
1542
- if (!container || typeof container !== "object" || Array.isArray(container))
1543
- continue;
1544
- const obj = container;
1545
- for (const key of keys) {
1546
- const value = obj[key];
1547
- if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
1548
- return { value, source: "tier_status" };
1549
- }
1550
- }
1551
- }
1552
- return undefined;
1553
- }
1554
- function hasAnyTierFunctionLimit(limits) {
1555
- return Boolean(limits.maxTimeoutSeconds ||
1556
- limits.maxMemoryMb ||
1557
- limits.maxScheduledFunctions ||
1558
- limits.minCronIntervalMinutes ||
1559
- limits.currentScheduledFunctions);
1560
- }
1561
- async function computeDesiredScheduledFunctionCount(client, spec) {
1562
- const functions = spec.functions;
1563
- if (!functions)
1564
- return null;
1565
- const replaceScheduled = scheduledFunctionNames(functions.replace);
1566
- if (replaceScheduled) {
1567
- applyScheduledFunctionPatch(replaceScheduled, functions.patch);
1568
- return { count: replaceScheduled.size, source: "manifest" };
1569
- }
1570
- if (!functions.patch)
1571
- return null;
1572
- const activeScheduled = await readActiveScheduledFunctionNames(client, spec.project_id);
1573
- if (!activeScheduled)
1574
- return null;
1575
- applyScheduledFunctionPatch(activeScheduled, functions.patch);
1576
- return { count: activeScheduled.size, source: "active_release_inventory" };
1577
- }
1578
- function countScheduledFunctionsInSetEntries(functions) {
1579
- if (!functions)
1580
- return 0;
1581
- let count = 0;
1582
- for (const fn of Object.values(functions.replace ?? {})) {
1583
- count += scheduleTriggersForFunction(fn).length;
1584
- }
1585
- for (const fn of Object.values(functions.patch?.set ?? {})) {
1586
- count += scheduleTriggersForFunction(fn).length;
1587
- }
1588
- return count;
1589
- }
1590
- function scheduledFunctionNames(functions) {
1591
- if (!functions)
1592
- return null;
1593
- const scheduled = new Set();
1594
- for (const [name, fn] of Object.entries(functions)) {
1595
- if (scheduleTriggersForFunction(fn).length > 0)
1596
- scheduled.add(name);
1597
- }
1598
- return scheduled;
1599
- }
1600
- function applyScheduledFunctionPatch(scheduled, patch) {
1601
- for (const name of patch?.delete ?? []) {
1602
- scheduled.delete(name);
1603
- }
1604
- for (const [name, fn] of Object.entries(patch?.set ?? {})) {
1605
- if (scheduleTriggersForFunction(fn).length > 0)
1606
- scheduled.add(name);
1607
- }
1608
- }
1609
- async function readActiveScheduledFunctionNames(client, projectId) {
1610
- let inventory;
1611
- try {
1612
- inventory = await client.request(appendQuery("/apply/v1/releases/active", { site_limit: 1 }), {
1613
- headers: await apikeyHeaders(client, projectId),
1614
- context: "fetching active release inventory for deploy preflight",
1615
- });
1616
- }
1617
- catch {
1618
- return null;
1619
- }
1620
- const scheduled = new Set();
1621
- for (const fn of inventory.functions ?? []) {
1622
- if (scheduleTriggersForFunction(fn).length > 0)
1623
- scheduled.add(fn.name);
1624
- }
1625
- return scheduled;
1626
- }
1627
- function scheduleTriggersForFunction(fn) {
1628
- return (fn.triggers ?? [])
1629
- .map((trigger, index) => ({ trigger, index }))
1630
- .filter((entry) => entry.trigger.type === "schedule")
1631
- .map(({ trigger, index }) => ({
1632
- ...trigger,
1633
- fieldSuffix: `triggers[${index}].cron`,
1634
- }));
1635
- }
1636
- function scheduledCountTierLimitError(count, limits, limit, countSource) {
1637
- return tierLimitError(`Deploy would have ${count} scheduled function(s), exceeding the ${limits.tier} tier maximum of ${limit.value}.`, "functions.scheduled_count", count, limits, limit, {
1638
- tier_max: limit.value,
1639
- max_scheduled_functions: limit.value,
1640
- count_source: countSource,
1641
- });
1642
- }
1643
- function tierLimitError(message, field, value, limits, limit, extraDetails) {
1644
- const hint = limits.walletTier !== undefined
1645
- ? `The project's organization is on the ${limits.tier} tier (your wallet's own organization ${limits.walletTier ? `is on ${limits.walletTier}` : "has no tier"}), and a deploy is held to the limits of the organization that owns the project. Lower the function setting or upgrade that organization's tier.`
1646
- : limit.source === "local_static_fallback"
1647
- ? "Tier limits came from the SDK's static fallback because /tiers/v1/status did not expose function caps. Run `run402 tier status` to refresh, lower the function setting, upgrade the tier, or retry and let gateway validation decide if this seems stale."
1648
- : "Lower the function setting or upgrade the tier before deploying.";
1649
- const details = {
1650
- field,
1651
- value,
1652
- tier: limits.tier,
1653
- limit_source: limit.source,
1654
- ...extraDetails,
1655
- };
1656
- const body = {
1657
- code: "BAD_FIELD",
1658
- category: "deploy",
1659
- message,
1660
- retryable: false,
1661
- details,
1662
- hint,
1663
- };
1664
- return new Run402DeployError(message, {
1665
- code: "BAD_FIELD",
1666
- phase: "validate",
1667
- resource: field,
1668
- retryable: false,
1669
- body,
1670
- context: "validating deploy tier limits",
1671
- });
1672
- }
1673
- function estimateCronMinimumIntervalMinutes(expression) {
1674
- const parts = expression.trim().split(/\s+/);
1675
- if (parts.length !== 5)
1676
- return null;
1677
- const minutes = expandCronNumberField(parts[0], 0, 59);
1678
- const hours = expandCronNumberField(parts[1], 0, 23);
1679
- if (!minutes || !hours || minutes.length === 0 || hours.length === 0)
1680
- return null;
1681
- const occurrences = [];
1682
- for (const hour of hours) {
1683
- for (const minute of minutes) {
1684
- occurrences.push(hour * 60 + minute);
1685
- }
1686
- }
1687
- occurrences.sort((a, b) => a - b);
1688
- if (occurrences.length <= 1)
1689
- return 24 * 60;
1690
- let minGap = Number.POSITIVE_INFINITY;
1691
- for (let i = 1; i < occurrences.length; i += 1) {
1692
- minGap = Math.min(minGap, occurrences[i] - occurrences[i - 1]);
1693
- }
1694
- minGap = Math.min(minGap, 24 * 60 - occurrences[occurrences.length - 1] + occurrences[0]);
1695
- return Number.isFinite(minGap) ? minGap : null;
1696
- }
1697
- function expandCronNumberField(field, min, max) {
1698
- const values = new Set();
1699
- for (const part of field.split(",")) {
1700
- const expanded = expandCronNumberPart(part.trim(), min, max);
1701
- if (!expanded)
1702
- return null;
1703
- for (const value of expanded)
1704
- values.add(value);
1705
- }
1706
- return [...values].sort((a, b) => a - b);
1707
- }
1708
- function expandCronNumberPart(part, min, max) {
1709
- if (!part)
1710
- return null;
1711
- const [rangePart, stepPart] = part.split("/");
1712
- if (part.split("/").length > 2)
1713
- return null;
1714
- const step = stepPart === undefined ? 1 : Number(stepPart);
1715
- if (!Number.isSafeInteger(step) || step < 1)
1716
- return null;
1717
- let start;
1718
- let end;
1719
- if (rangePart === "*") {
1720
- start = min;
1721
- end = max;
1722
- }
1723
- else if (rangePart?.includes("-")) {
1724
- const [rawStart, rawEnd] = rangePart.split("-");
1725
- start = Number(rawStart);
1726
- end = Number(rawEnd);
1727
- }
1728
- else {
1729
- start = Number(rangePart);
1730
- end = stepPart === undefined ? start : max;
1731
- }
1732
- if (!Number.isSafeInteger(start) ||
1733
- !Number.isSafeInteger(end) ||
1734
- start < min ||
1735
- end > max ||
1736
- start > end) {
1737
- return null;
1738
- }
1739
- const values = [];
1740
- for (let value = start; value <= end; value += step) {
1741
- values.push(value);
1742
- }
1743
- return values;
1744
- }
1745
1323
  async function commitInternal(client, planId, idempotencyKey, project, requiredPlan, vault, operationId, noSnapshot) {
1746
1324
  const tries = { attempts: 0 };
1747
1325
  try {
@@ -4823,7 +4401,7 @@ function translateDeployError(err, phase, planId, operationId) {
4823
4401
  : null;
4824
4402
  const gw = body && typeof body === "object" ? extractGatewayError(body) : null;
4825
4403
  if (gw) {
4826
- return translateGatewayError(gw, phase, planId, operationId);
4404
+ return translateGatewayError(gw, phase, planId, operationId, err.status);
4827
4405
  }
4828
4406
  return new Run402DeployError(err.message, {
4829
4407
  code: "INTERNAL_ERROR",
@@ -4848,7 +4426,7 @@ function translateDeployError(err, phase, planId, operationId) {
4848
4426
  : null;
4849
4427
  const gw = body ? extractGatewayError(body) : null;
4850
4428
  if (gw) {
4851
- return translateGatewayError(gw, phase, planId, operationId);
4429
+ return translateGatewayError(gw, phase, planId, operationId, err.status);
4852
4430
  }
4853
4431
  return new Run402DeployError(err.message, {
4854
4432
  code: "PROJECT_HAS_PENDING_TRANSFER",
@@ -4864,6 +4442,14 @@ function translateDeployError(err, phase, planId, operationId) {
4864
4442
  if (isNoResponseError(err)) {
4865
4443
  return noResponseDeployError(err, phase, planId, operationId);
4866
4444
  }
4445
+ // The kernel throws every 401/403 as `Unauthorized`. One the deploy state
4446
+ // machine itself refused (a tier cap at plan, a CI route scope) names its
4447
+ // phase, so it stays a deploy error, with its fix, next actions and status;
4448
+ // an auth or lifecycle refusal names none and is re-thrown below.
4449
+ const refusal = deployRefusalOf(err);
4450
+ if (refusal) {
4451
+ return translateGatewayError(refusal, phase, planId, operationId, err.status);
4452
+ }
4867
4453
  // Re-throw other Run402Error subclasses (PaymentRequired, Unauthorized, etc.)
4868
4454
  // as-is — the consumer handles them at a different layer than
4869
4455
  // deploy-state-machine errors.
@@ -5030,6 +4616,21 @@ function extractGatewayError(body) {
5030
4616
  }
5031
4617
  return null;
5032
4618
  }
4619
+ /**
4620
+ * The gateway error of a 401/403 that a deploy phase refused, or null. The
4621
+ * check is structural (`kind`), so it holds across duplicate SDK copies.
4622
+ */
4623
+ function deployRefusalOf(err) {
4624
+ if (!isRun402Error(err) || err.kind !== "unauthorized")
4625
+ return null;
4626
+ const body = err.body && typeof err.body === "object" && !Array.isArray(err.body)
4627
+ ? err.body
4628
+ : null;
4629
+ if (!body)
4630
+ return null;
4631
+ const phase = stringField(body, "phase") ?? stringField(objectField(body, "details"), "phase");
4632
+ return phase ? extractGatewayError(body) : null;
4633
+ }
5033
4634
  function stringField(obj, key) {
5034
4635
  return obj && typeof obj === "object" && typeof obj[key] === "string"
5035
4636
  ? obj[key]
@@ -5050,7 +4651,9 @@ function arrayField(obj, key) {
5050
4651
  const value = obj && typeof obj === "object" ? obj[key] : undefined;
5051
4652
  return Array.isArray(value) ? value : undefined;
5052
4653
  }
5053
- function translateGatewayError(gw, phase, planId, operationId) {
4654
+ function translateGatewayError(gw, phase, planId, operationId,
4655
+ /** The HTTP status of the response that carried the error, when one did. */
4656
+ status) {
5054
4657
  if (!gw) {
5055
4658
  return new Run402DeployError("Deploy failed without a structured error", {
5056
4659
  code: "INTERNAL_ERROR",
@@ -5090,6 +4693,7 @@ function translateGatewayError(gw, phase, planId, operationId) {
5090
4693
  fix,
5091
4694
  logs,
5092
4695
  rolledBack: gw.rolled_back ?? booleanField(details, "rolled_back") ?? false,
4696
+ ...(status !== undefined && status !== null ? { status } : {}),
5093
4697
  body,
5094
4698
  context: phase,
5095
4699
  });