owlmem 0.9.19 → 0.9.20

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.
Files changed (2) hide show
  1. package/owlmem.mjs +34 -1
  2. package/package.json +1 -1
package/owlmem.mjs CHANGED
@@ -43,7 +43,7 @@ import { join, dirname, basename, relative, isAbsolute } from "node:path";
43
43
  import { fileURLToPath } from "node:url";
44
44
  import { spawn, spawnSync } from "node:child_process";
45
45
 
46
- export const VERSION = "0.9.19";
46
+ export const VERSION = "0.9.20";
47
47
  const BASE = (process.env.OWLMEM_URL || "https://owlmem.com").replace(/\/$/, "");
48
48
  const DIR = process.env.OWLMEM_HOME || join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "owlmem");
49
49
  const enc = new TextEncoder(), dec = new TextDecoder();
@@ -1728,6 +1728,32 @@ async function antigravityQuota(fetchImpl = fetch) {
1728
1728
  }
1729
1729
  return null;
1730
1730
  }
1731
+ // DeepSeek's balance (0.9.20): DSH pays per token, so its quota is the account balance, not a window.
1732
+ // Read it from DeepSeek's balance endpoint with the key DSH itself runs on: DEEPSEEK_API_KEY in this
1733
+ // process's environment (DSH's own documented variable). The key is only sent to api.deepseek.com and
1734
+ // never leaves this computer otherwise; OwlMem gets the amount and currency. No key, no answer, or a
1735
+ // shape we don't recognize: no balance this round, the same as the other quota readers.
1736
+ export function dshBalanceFrom(j) {
1737
+ const infos = Array.isArray(j?.balance_infos) ? j.balance_infos : [];
1738
+ const entries = infos.map((b) => ({ currency: b?.currency, balance: Number(b?.total_balance) }))
1739
+ .filter((e) => typeof e.currency === "string" && e.currency && Number.isFinite(e.balance));
1740
+ if (!entries.length) return null;
1741
+ return entries.find((e) => e.balance > 0) || entries[0];
1742
+ }
1743
+ // The auto-wake service doesn't inherit your shell's environment, so also read DSH's own config file
1744
+ // ~/.dsh/.env (where `dsh` keeps DEEPSEEK_API_KEY). Only that one line is read; the key stays in memory.
1745
+ export function dshKeyFrom(text) {
1746
+ const m = /^\s*(?:export\s+)?DEEPSEEK_API_KEY\s*=\s*["']?([^"'\s#]+)/m.exec(String(text || ""));
1747
+ return m ? m[1] : null;
1748
+ }
1749
+ async function dshBalance(fetchImpl = fetch, home = homedir()) {
1750
+ let key = process.env.DEEPSEEK_API_KEY;
1751
+ if (!key) { try { key = dshKeyFrom(readFileSync(join(home, ".dsh", ".env"), "utf8")); } catch {} }
1752
+ if (!key) return null;
1753
+ const r = await fetchImpl("https://api.deepseek.com/user/balance", { headers: { Authorization: "Bearer " + key, "User-Agent": "owlmem-cli/" + VERSION }, signal: AbortSignal.timeout(15000) });
1754
+ if (!r.ok) return null;
1755
+ return dshBalanceFrom(await r.json());
1756
+ }
1731
1757
  async function usageTick(cfg, api, log, dir = DIR) {
1732
1758
  const file = join(wakeDir(dir), "usage.json");
1733
1759
  let state = {}; try { state = JSON.parse(readFileSync(file, "utf8")); } catch {}
@@ -1740,6 +1766,13 @@ async function usageTick(cfg, api, log, dir = DIR) {
1740
1766
  if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
1741
1767
  }
1742
1768
  }
1769
+ if (cfg.clients?.dsh) { // no transcripts to count here either, only its DeepSeek balance
1770
+ const b = await dshBalance().catch(() => null);
1771
+ if (b) {
1772
+ const r = await api("usage", { days: {}, status: { dsh: { ...b, limit_at: Math.floor(Date.now() / 1000) } } });
1773
+ if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
1774
+ }
1775
+ }
1743
1776
  if (!clients.length) return;
1744
1777
  scanUsage(state, Object.fromEntries(Object.entries(usageRoots()).filter(([c]) => clients.includes(c))));
1745
1778
  try { writeFileSync(file + ".tmp", JSON.stringify(state)); renameSync(file + ".tmp", file); } catch (e) { log("usage: " + e.message); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owlmem",
3
- "version": "0.9.19",
3
+ "version": "0.9.20",
4
4
  "description": "OwlMem command line: connect your AI apps to OwlMem in one command (npx -y owlmem install), an end-to-end encrypted vault for your AI agents, and a local MCP server.",
5
5
  "type": "module",
6
6
  "bin": { "owlmem": "owlmem.mjs" },