owlmem 0.9.19 → 0.9.21
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/owlmem.mjs +47 -5
- 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.
|
|
46
|
+
export const VERSION = "0.9.21";
|
|
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();
|
|
@@ -423,6 +423,16 @@ async function fetchItem(name, mode = "view") {
|
|
|
423
423
|
const it = await approved("GET", itemPath(name), undefined, "access", mode);
|
|
424
424
|
return open(raw, sp.space, name, it.nonce, it.ciphertext);
|
|
425
425
|
}
|
|
426
|
+
// 「名字:字段」:名字里也可能有冒号(11-14 起名称不限字符)。带冒号时先查条目清单(不用审批):整串就是一条的名字就整串取,
|
|
427
|
+
// 否则按最后一个冒号拆成「名字 + 字段」。不先去试拆出来的名字——那会用错的名字发审批请求(antigravity 审查 #1600)
|
|
428
|
+
async function fetchRef(ref, mode) {
|
|
429
|
+
ref = String(ref); const i = ref.lastIndexOf(":");
|
|
430
|
+
if (i > 0 && i < ref.length - 1) {
|
|
431
|
+
const r = await call("GET", "items"); if (r.status >= 400) throw new Fail(r.data.detail || r.data.error);
|
|
432
|
+
if (!(r.data.items || []).some((it) => it.name === ref)) return pick(await fetchItem(ref.slice(0, i), mode), ref.slice(i + 1));
|
|
433
|
+
}
|
|
434
|
+
return pick(await fetchItem(ref, mode));
|
|
435
|
+
}
|
|
426
436
|
function pick(body, field) {
|
|
427
437
|
if (!field) return body.type === "env" || body.type === "secret" ? String(body.value ?? "") : JSON.stringify(body, null, 2);
|
|
428
438
|
const v = body[field] ?? body.fields?.[field];
|
|
@@ -463,8 +473,7 @@ async function mcpCall(name, a) {
|
|
|
463
473
|
const env = { ...process.env }, secrets = [];
|
|
464
474
|
for (const [k, ref] of Object.entries(a.env || {})) {
|
|
465
475
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k)) throw new Fail("Bad variable name " + k);
|
|
466
|
-
const
|
|
467
|
-
const v = pick(await fetchItem(item, "run"), field); env[k] = v; if (v && v.length >= 4) secrets.push(v);
|
|
476
|
+
const v = await fetchRef(ref, "run"); env[k] = v; if (v && v.length >= 4) secrets.push(v);
|
|
468
477
|
}
|
|
469
478
|
const mask = (t) => secrets.sort((x, y) => y.length - x.length).reduce((acc, v) => acc.split(v).join("****"), t);
|
|
470
479
|
const out = await new Promise((res) => {
|
|
@@ -1728,6 +1737,32 @@ async function antigravityQuota(fetchImpl = fetch) {
|
|
|
1728
1737
|
}
|
|
1729
1738
|
return null;
|
|
1730
1739
|
}
|
|
1740
|
+
// DeepSeek's balance (0.9.20): DSH pays per token, so its quota is the account balance, not a window.
|
|
1741
|
+
// Read it from DeepSeek's balance endpoint with the key DSH itself runs on: DEEPSEEK_API_KEY in this
|
|
1742
|
+
// process's environment (DSH's own documented variable). The key is only sent to api.deepseek.com and
|
|
1743
|
+
// never leaves this computer otherwise; OwlMem gets the amount and currency. No key, no answer, or a
|
|
1744
|
+
// shape we don't recognize: no balance this round, the same as the other quota readers.
|
|
1745
|
+
export function dshBalanceFrom(j) {
|
|
1746
|
+
const infos = Array.isArray(j?.balance_infos) ? j.balance_infos : [];
|
|
1747
|
+
const entries = infos.map((b) => ({ currency: b?.currency, balance: Number(b?.total_balance) }))
|
|
1748
|
+
.filter((e) => typeof e.currency === "string" && e.currency && Number.isFinite(e.balance));
|
|
1749
|
+
if (!entries.length) return null;
|
|
1750
|
+
return entries.find((e) => e.balance > 0) || entries[0];
|
|
1751
|
+
}
|
|
1752
|
+
// The auto-wake service doesn't inherit your shell's environment, so also read DSH's own config file
|
|
1753
|
+
// ~/.dsh/.env (where `dsh` keeps DEEPSEEK_API_KEY). Only that one line is read; the key stays in memory.
|
|
1754
|
+
export function dshKeyFrom(text) {
|
|
1755
|
+
const m = /^\s*(?:export\s+)?DEEPSEEK_API_KEY\s*=\s*["']?([^"'\s#]+)/m.exec(String(text || ""));
|
|
1756
|
+
return m ? m[1] : null;
|
|
1757
|
+
}
|
|
1758
|
+
async function dshBalance(fetchImpl = fetch, home = homedir()) {
|
|
1759
|
+
let key = process.env.DEEPSEEK_API_KEY;
|
|
1760
|
+
if (!key) { try { key = dshKeyFrom(readFileSync(join(home, ".dsh", ".env"), "utf8")); } catch {} }
|
|
1761
|
+
if (!key) return null;
|
|
1762
|
+
const r = await fetchImpl("https://api.deepseek.com/user/balance", { headers: { Authorization: "Bearer " + key, "User-Agent": "owlmem-cli/" + VERSION }, signal: AbortSignal.timeout(15000) });
|
|
1763
|
+
if (!r.ok) return null;
|
|
1764
|
+
return dshBalanceFrom(await r.json());
|
|
1765
|
+
}
|
|
1731
1766
|
async function usageTick(cfg, api, log, dir = DIR) {
|
|
1732
1767
|
const file = join(wakeDir(dir), "usage.json");
|
|
1733
1768
|
let state = {}; try { state = JSON.parse(readFileSync(file, "utf8")); } catch {}
|
|
@@ -1740,6 +1775,13 @@ async function usageTick(cfg, api, log, dir = DIR) {
|
|
|
1740
1775
|
if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
1741
1776
|
}
|
|
1742
1777
|
}
|
|
1778
|
+
if (cfg.clients?.dsh) { // no transcripts to count here either, only its DeepSeek balance
|
|
1779
|
+
const b = await dshBalance().catch(() => null);
|
|
1780
|
+
if (b) {
|
|
1781
|
+
const r = await api("usage", { days: {}, status: { dsh: { ...b, limit_at: Math.floor(Date.now() / 1000) } } });
|
|
1782
|
+
if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1743
1785
|
if (!clients.length) return;
|
|
1744
1786
|
scanUsage(state, Object.fromEntries(Object.entries(usageRoots()).filter(([c]) => clients.includes(c))));
|
|
1745
1787
|
try { writeFileSync(file + ".tmp", JSON.stringify(state)); renameSync(file + ".tmp", file); } catch (e) { log("usage: " + e.message); }
|
|
@@ -1941,9 +1983,9 @@ export async function main(argv) {
|
|
|
1941
1983
|
const opts = argv.slice(1, dash), command = argv.slice(dash + 1), env = { ...process.env };
|
|
1942
1984
|
for (let i = 0; i < opts.length; i++) {
|
|
1943
1985
|
if (opts[i] !== "--env") throw new Fail("Unknown option " + opts[i]);
|
|
1944
|
-
const m = /^([A-Za-z_][A-Za-z0-9_]*)=(
|
|
1986
|
+
const m = /^([A-Za-z_][A-Za-z0-9_]*)=(.+)$/.exec(opts[++i] || "");
|
|
1945
1987
|
if (!m) throw new Fail("Use --env VAR=item or --env VAR=item:field");
|
|
1946
|
-
env[m[1]] =
|
|
1988
|
+
env[m[1]] = await fetchRef(m[2], "run");
|
|
1947
1989
|
}
|
|
1948
1990
|
const child = spawn(command[0], command.slice(1), { stdio: "inherit", env });
|
|
1949
1991
|
await new Promise((res) => child.on("exit", (code, sig) => { process.exitCode = sig ? 1 : code; res(); }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owlmem",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
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" },
|