@deeplake/hivemind 0.7.61 → 0.7.62

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.
@@ -23683,6 +23683,9 @@ function traceSql(msg) {
23683
23683
  log3(msg);
23684
23684
  }
23685
23685
  var _signalledBalanceExhausted = false;
23686
+ var _signalledLowBalance = false;
23687
+ var LOW_BALANCE_THRESHOLD_CENTS = 200;
23688
+ var BALANCE_HEADER = "X-Activeloop-Balance-Cents";
23686
23689
  function maybeSignalBalanceExhausted(status, bodyText) {
23687
23690
  if (status !== 402)
23688
23691
  return;
@@ -23703,6 +23706,35 @@ function maybeSignalBalanceExhausted(status, bodyText) {
23703
23706
  log3(`enqueue balance-exhausted failed: ${e instanceof Error ? e.message : String(e)}`);
23704
23707
  });
23705
23708
  }
23709
+ function signalLowBalanceFromHeader(resp) {
23710
+ if (_signalledLowBalance)
23711
+ return;
23712
+ const raw = resp.headers?.get?.(BALANCE_HEADER);
23713
+ if (!raw)
23714
+ return;
23715
+ if (!/^-?\d+$/.test(raw.trim()))
23716
+ return;
23717
+ const balance = Number(raw.trim());
23718
+ if (!Number.isFinite(balance))
23719
+ return;
23720
+ if (balance >= LOW_BALANCE_THRESHOLD_CENTS)
23721
+ return;
23722
+ if (balance <= 0)
23723
+ return;
23724
+ _signalledLowBalance = true;
23725
+ log3(`balance below threshold (${balance}\xA2) \u2014 enqueuing low-balance banner`);
23726
+ enqueueNotification({
23727
+ id: "low-balance-warning",
23728
+ severity: "warn",
23729
+ transient: true,
23730
+ title: "Your org's Hivemind balance is running low",
23731
+ body: `Only $${(balance / 100).toFixed(2)} of prepaid balance remains. Admins can top up at ${billingUrl()}; otherwise ask an org admin to top up before requests start failing.`,
23732
+ dedupKey: { reason: "low-balance" }
23733
+ }).catch((e) => {
23734
+ _signalledLowBalance = false;
23735
+ log3(`enqueue low-balance failed: ${e instanceof Error ? e.message : String(e)}`);
23736
+ });
23737
+ }
23706
23738
  function billingUrl() {
23707
23739
  try {
23708
23740
  const c = loadCredentials();
@@ -23828,6 +23860,7 @@ var DeeplakeApi = class {
23828
23860
  }
23829
23861
  throw lastError;
23830
23862
  }
23863
+ signalLowBalanceFromHeader(resp);
23831
23864
  if (resp.ok) {
23832
23865
  const raw = await resp.json();
23833
23866
  if (!raw?.rows || !raw?.columns)
@@ -23988,6 +24021,7 @@ var DeeplakeApi = class {
23988
24021
  ...deeplakeClientHeader()
23989
24022
  }
23990
24023
  });
24024
+ signalLowBalanceFromHeader(resp);
23991
24025
  if (resp.ok) {
23992
24026
  const data = await resp.json();
23993
24027
  return {
@@ -494,6 +494,9 @@ function traceSql(msg) {
494
494
  if (globalThis.__hivemind_tuning__.HIVEMIND_DEBUG === "1") log3(msg);
495
495
  }
496
496
  var _signalledBalanceExhausted = false;
497
+ var _signalledLowBalance = false;
498
+ var LOW_BALANCE_THRESHOLD_CENTS = 200;
499
+ var BALANCE_HEADER = "X-Activeloop-Balance-Cents";
497
500
  function maybeSignalBalanceExhausted(status, bodyText) {
498
501
  if (status !== 402) return;
499
502
  if (!bodyText.includes("balance_cents")) return;
@@ -511,6 +514,29 @@ function maybeSignalBalanceExhausted(status, bodyText) {
511
514
  log3(`enqueue balance-exhausted failed: ${e instanceof Error ? e.message : String(e)}`);
512
515
  });
513
516
  }
517
+ function signalLowBalanceFromHeader(resp) {
518
+ if (_signalledLowBalance) return;
519
+ const raw = resp.headers?.get?.(BALANCE_HEADER);
520
+ if (!raw) return;
521
+ if (!/^-?\d+$/.test(raw.trim())) return;
522
+ const balance = Number(raw.trim());
523
+ if (!Number.isFinite(balance)) return;
524
+ if (balance >= LOW_BALANCE_THRESHOLD_CENTS) return;
525
+ if (balance <= 0) return;
526
+ _signalledLowBalance = true;
527
+ log3(`balance below threshold (${balance}\xA2) \u2014 enqueuing low-balance banner`);
528
+ enqueueNotification({
529
+ id: "low-balance-warning",
530
+ severity: "warn",
531
+ transient: true,
532
+ title: "Your org's Hivemind balance is running low",
533
+ body: `Only $${(balance / 100).toFixed(2)} of prepaid balance remains. Admins can top up at ${billingUrl()}; otherwise ask an org admin to top up before requests start failing.`,
534
+ dedupKey: { reason: "low-balance" }
535
+ }).catch((e) => {
536
+ _signalledLowBalance = false;
537
+ log3(`enqueue low-balance failed: ${e instanceof Error ? e.message : String(e)}`);
538
+ });
539
+ }
514
540
  function billingUrl() {
515
541
  try {
516
542
  const c = loadCredentials();
@@ -636,6 +662,7 @@ var DeeplakeApi = class {
636
662
  }
637
663
  throw lastError;
638
664
  }
665
+ signalLowBalanceFromHeader(resp);
639
666
  if (resp.ok) {
640
667
  const raw = await resp.json();
641
668
  if (!raw?.rows || !raw?.columns) return [];
@@ -797,6 +824,7 @@ var DeeplakeApi = class {
797
824
  ...deeplakeClientHeader()
798
825
  }
799
826
  });
827
+ signalLowBalanceFromHeader(resp);
800
828
  if (resp.ok) {
801
829
  const data = await resp.json();
802
830
  return {
@@ -1795,7 +1823,7 @@ function extractLatestVersion(body) {
1795
1823
  return typeof v === "string" && v.length > 0 ? v : null;
1796
1824
  }
1797
1825
  function getInstalledVersion() {
1798
- return "0.7.61".length > 0 ? "0.7.61" : null;
1826
+ return "0.7.62".length > 0 ? "0.7.62" : null;
1799
1827
  }
1800
1828
  function isNewer(latest, current) {
1801
1829
  const parse = (v) => v.replace(/-.*$/, "").split(".").map(Number);
@@ -54,5 +54,5 @@
54
54
  }
55
55
  }
56
56
  },
57
- "version": "0.7.61"
57
+ "version": "0.7.62"
58
58
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hivemind",
3
- "version": "0.7.61",
3
+ "version": "0.7.62",
4
4
  "type": "module",
5
5
  "description": "Hivemind — cloud-backed persistent shared memory for AI agents, powered by DeepLake",
6
6
  "license": "Apache-2.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deeplake/hivemind",
3
- "version": "0.7.61",
3
+ "version": "0.7.62",
4
4
  "description": "Cloud-backed persistent shared memory for AI agents powered by Deeplake",
5
5
  "type": "module",
6
6
  "repository": {