@tangle-network/agent-app 0.60.93 → 0.60.95

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.
@@ -42,7 +42,7 @@ import {
42
42
  flattenHistory,
43
43
  readSandboxBinaryBytes,
44
44
  statSandboxFileSize
45
- } from "../chunk-QJNMYG5H.js";
45
+ } from "../chunk-BOEWSEGC.js";
46
46
  import "../chunk-4LBCTFBP.js";
47
47
  import "../chunk-MCYJON3F.js";
48
48
  import "../chunk-LWSJK546.js";
@@ -741,6 +741,8 @@ function createWarmLeases(options) {
741
741
  const boxIdleMs = options.boxIdleMs ?? 30 * 6e4;
742
742
  const holdMs = options.holdMs ?? 10 * 6e4;
743
743
  const warmDeadlineMs = options.warmDeadlineMs ?? 2 * 6e4;
744
+ const absentCooldownMs = options.absentCooldownMs ?? 10 * 6e4;
745
+ const capacityCooldownMs = options.capacityCooldownMs ?? 5 * 6e4;
744
746
  const burstHoldMs = options.burstHoldMs ?? boxIdleMs;
745
747
  const dailyBudgetMs = options.dailyBudgetMs ?? 30 * 6e4;
746
748
  const budgeted = new Set(options.budgetedReasons ?? DEFAULT_BUDGETED);
@@ -761,8 +763,9 @@ function createWarmLeases(options) {
761
763
  }
762
764
  async function signal(key, reason) {
763
765
  const at = now();
766
+ const row = await store.read(key);
767
+ if (row && row.declinedUntil > at && !row.leaseId) return { outcome: "declined" };
764
768
  if (budgeted.has(reason)) {
765
- const row = await store.read(key);
766
769
  if (!row?.leaseId && spentToday(row, at) >= dailyBudgetMs) {
767
770
  emit({ type: "warm_declined", key, reason, why: "budget" });
768
771
  return { outcome: "declined" };
@@ -780,9 +783,10 @@ function createWarmLeases(options) {
780
783
  return { outcome: "failed" };
781
784
  }
782
785
  const warmAt = now();
783
- if (box === "absent") {
786
+ if (box === "absent" || box === "capacity") {
784
787
  await store.end(key, leaseId, utcDay(at), 0);
785
- emit({ type: "warm_declined", key, reason, why: "absent" });
788
+ await store.markDeclined(key, warmAt + (box === "absent" ? absentCooldownMs : capacityCooldownMs));
789
+ emit({ type: "warm_declined", key, reason, why: box });
786
790
  return { outcome: "declined", box };
787
791
  }
788
792
  await store.markWarm(key, leaseId, warmAt, box === "resumed");
@@ -879,8 +883,10 @@ var WARM_LEASE_TABLE_DDL = `CREATE TABLE IF NOT EXISTS ${DEFAULT_WARM_LEASE_TABL
879
883
  slots TEXT NOT NULL DEFAULT '',
880
884
  slots_at INTEGER NOT NULL DEFAULT 0,
881
885
  first_seen_at INTEGER NOT NULL DEFAULT 0,
882
- predicted_at INTEGER NOT NULL DEFAULT 0
886
+ predicted_at INTEGER NOT NULL DEFAULT 0,
887
+ declined_until INTEGER NOT NULL DEFAULT 0
883
888
  )`;
889
+ var WARM_LEASE_DECLINED_UNTIL_DDL = `ALTER TABLE ${DEFAULT_WARM_LEASE_TABLE} ADD COLUMN declined_until INTEGER NOT NULL DEFAULT 0`;
884
890
  var SAFE_IDENTIFIER2 = /^[A-Za-z_][A-Za-z0-9_]*$/;
885
891
  function parseSlots(text) {
886
892
  if (!text) return [];
@@ -909,7 +915,8 @@ function toRow(row) {
909
915
  slots: parseSlots(row.slots),
910
916
  slotsAt: row.slots_at,
911
917
  firstSeenAt: row.first_seen_at,
912
- predictedAt: row.predicted_at
918
+ predictedAt: row.predicted_at,
919
+ declinedUntil: row.declined_until ?? 0
913
920
  };
914
921
  }
915
922
  function createD1WarmLeaseStore(db, options = {}) {
@@ -930,7 +937,7 @@ RETURNING lease_id`;
930
937
  const markWarmSql = `UPDATE ${t} SET warm_at = ?3, resumed = ?4 WHERE key = ?1 AND lease_id = ?2`;
931
938
  const firstUseSql = `UPDATE ${t} SET used_at = ?2 WHERE key = ?1 AND lease_id IS NOT NULL AND used_at = 0 RETURNING key`;
932
939
  const turnSql = `INSERT INTO ${t} (key, last_turn_at, hold_until) VALUES (?1, ?2, ?3)
933
- ON CONFLICT(key) DO UPDATE SET last_turn_at = ?2, hold_until = MAX(${t}.hold_until, ?3)`;
940
+ ON CONFLICT(key) DO UPDATE SET last_turn_at = ?2, hold_until = MAX(${t}.hold_until, ?3), declined_until = 0`;
934
941
  const endSql = `UPDATE ${t} SET
935
942
  lease_id = NULL, reason = NULL, started_at = 0, warm_at = 0, used_at = 0, resumed = 0, ping_at = 0,
936
943
  day_warm_ms = CASE WHEN day = ?3 THEN day_warm_ms + ?4 WHEN day < ?3 THEN ?4 ELSE day_warm_ms END,
@@ -979,6 +986,9 @@ WHERE key = ?1 AND lease_id = ?2`;
979
986
  async markPinged(key, at) {
980
987
  await q(`UPDATE ${t} SET ping_at = ?2 WHERE key = ?1`, key, at).run();
981
988
  },
989
+ async markDeclined(key, until) {
990
+ await q(`UPDATE ${t} SET declined_until = ?2 WHERE key = ?1`, key, until).run();
991
+ },
982
992
  async markPredicted(key, at) {
983
993
  await q(`UPDATE ${t} SET predicted_at = ?2 WHERE key = ?1`, key, at).run();
984
994
  },
@@ -2878,6 +2888,7 @@ export {
2878
2888
  createWarmLeases,
2879
2889
  DEFAULT_WARM_LEASE_TABLE,
2880
2890
  WARM_LEASE_TABLE_DDL,
2891
+ WARM_LEASE_DECLINED_UNTIL_DDL,
2881
2892
  createD1WarmLeaseStore,
2882
2893
  resolveSandboxClientCredentials,
2883
2894
  PYPI_EGRESS_DOMAINS,
@@ -2932,4 +2943,4 @@ export {
2932
2943
  isTerminalPromptEvent,
2933
2944
  detectInteractiveQuestion
2934
2945
  };
2935
- //# sourceMappingURL=chunk-QJNMYG5H.js.map
2946
+ //# sourceMappingURL=chunk-BOEWSEGC.js.map