owlmem 0.9.3 → 0.9.5
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 +60 -1
- package/package.json +1 -1
package/owlmem.mjs
CHANGED
|
@@ -41,7 +41,7 @@ import { join, dirname, basename, relative, isAbsolute } from "node:path";
|
|
|
41
41
|
import { fileURLToPath } from "node:url";
|
|
42
42
|
import { spawn, spawnSync } from "node:child_process";
|
|
43
43
|
|
|
44
|
-
export const VERSION = "0.9.
|
|
44
|
+
export const VERSION = "0.9.5";
|
|
45
45
|
const BASE = (process.env.OWLMEM_URL || "https://owlmem.com").replace(/\/$/, "");
|
|
46
46
|
const DIR = process.env.OWLMEM_HOME || join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "owlmem");
|
|
47
47
|
const enc = new TextEncoder(), dec = new TextDecoder();
|
|
@@ -1253,6 +1253,19 @@ export class Scheduler {
|
|
|
1253
1253
|
get size() { return this.running.size + this.queue.length; }
|
|
1254
1254
|
}
|
|
1255
1255
|
|
|
1256
|
+
// Check-ins for the AI (0.9.4, 站长 11-01「npm 方式、不消耗 token 上报」): while an AI this program started is still working
|
|
1257
|
+
// on a task, tell OwlMem every ALIVE_EVERY that its process is running. That counts as the task's heartbeat, so the AI
|
|
1258
|
+
// doesn't spend tokens reporting in itself. Only tasks whose process is running (the scheduler's running set); replies
|
|
1259
|
+
// (type note) have no heartbeat. When the process ends this stops by itself and report() says how it ended.
|
|
1260
|
+
export const ALIVE_EVERY = 60 * 1000;
|
|
1261
|
+
export async function aliveTick(sched, api, log = () => {}) {
|
|
1262
|
+
const ids = [...sched.running].filter((j) => j.task?.type !== "note" && j.id != null).map((j) => j.id);
|
|
1263
|
+
if (!ids.length) return [];
|
|
1264
|
+
const r = await api("alive", { ids });
|
|
1265
|
+
if (r.status !== 200 && r.status !== 404) log("check-in: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
1266
|
+
return ids;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1256
1269
|
// The long-poll loop. api(sub, body) → {status, data}. Returns "revoked" after cleaning up on a 401.
|
|
1257
1270
|
export async function wakeLoop(o) {
|
|
1258
1271
|
const { cfg, api, sched, log = () => {}, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), once = false, cleanup } = o;
|
|
@@ -1552,11 +1565,56 @@ async function claudeQuota(fetchImpl = fetch) {
|
|
|
1552
1565
|
const w = claudeWindows(await r.json());
|
|
1553
1566
|
return w.length ? w : null;
|
|
1554
1567
|
}
|
|
1568
|
+
// Antigravity's quota (0.9.5): its running app answers on 127.0.0.1 with each model's remaining share and reset time, the
|
|
1569
|
+
// numbers its own model picker shows. We find the app by its command line (agy --hub-port=… --csrf_token=…); the token
|
|
1570
|
+
// only goes to that local port. Models that reset together are one window; OwlMem gets percentages and times, no names.
|
|
1571
|
+
export function agyServers(psOut) {
|
|
1572
|
+
const out = [];
|
|
1573
|
+
for (const l of String(psOut || "").split("\n")) {
|
|
1574
|
+
if (!/(^|\/)agy$/.test(l.trim().split(/\s/)[0] || "")) continue;
|
|
1575
|
+
const port = /--hub-port[= ](\d{2,5})\b/.exec(l), tok = /--csrf_token[= ]([\w-]{8,})/.exec(l);
|
|
1576
|
+
if (port && tok) out.push({ port: Number(port[1]), token: tok[1] });
|
|
1577
|
+
}
|
|
1578
|
+
return out;
|
|
1579
|
+
}
|
|
1580
|
+
export function agyWindows(j) {
|
|
1581
|
+
const groups = {};
|
|
1582
|
+
for (const m of j?.userStatus?.cascadeModelConfigData?.clientModelConfigs || []) {
|
|
1583
|
+
const q = m?.quotaInfo, t = Date.parse(q?.resetTime);
|
|
1584
|
+
if (typeof q?.remainingFraction !== "number" || isNaN(t)) continue;
|
|
1585
|
+
const at = Math.floor(t / 1000), used = Math.round((1 - Math.max(0, Math.min(1, q.remainingFraction))) * 1000) / 10;
|
|
1586
|
+
groups[at] = Math.max(groups[at] ?? 0, used);
|
|
1587
|
+
}
|
|
1588
|
+
return Object.entries(groups).map(([at, used_percent]) => ({ minutes: null, used_percent, resets_at: Number(at) }))
|
|
1589
|
+
.sort((a, b) => b.used_percent - a.used_percent || a.resets_at - b.resets_at).slice(0, 4);
|
|
1590
|
+
}
|
|
1591
|
+
async function antigravityQuota(fetchImpl = fetch) {
|
|
1592
|
+
if (process.platform === "win32") return null;
|
|
1593
|
+
const ps = spawnSync("ps", ["-axww", "-o", "args="], { encoding: "utf8", timeout: 10000 });
|
|
1594
|
+
for (const s of agyServers(ps.stdout)) {
|
|
1595
|
+
try {
|
|
1596
|
+
const r = await fetchImpl("http://127.0.0.1:" + s.port + "/exa.language_server_pb.LanguageServerService/GetUserStatus",
|
|
1597
|
+
{ method: "POST", headers: { "Content-Type": "application/json", "Connect-Protocol-Version": "1", "X-Codeium-Csrf-Token": s.token },
|
|
1598
|
+
body: JSON.stringify({ metadata: { ideName: "antigravity" } }), signal: AbortSignal.timeout(10000) });
|
|
1599
|
+
if (!r.ok) continue;
|
|
1600
|
+
const w = agyWindows(await r.json());
|
|
1601
|
+
if (w.length) return w;
|
|
1602
|
+
} catch {}
|
|
1603
|
+
}
|
|
1604
|
+
return null;
|
|
1605
|
+
}
|
|
1555
1606
|
async function usageTick(cfg, api, log, dir = DIR) {
|
|
1556
1607
|
const file = join(wakeDir(dir), "usage.json");
|
|
1557
1608
|
let state = {}; try { state = JSON.parse(readFileSync(file, "utf8")); } catch {}
|
|
1558
1609
|
if (state.v !== 2) state = { v: 2 }; // 0.9.1 also reads quota state: read every file once more
|
|
1559
1610
|
const clients = Object.keys(cfg.clients || {}).filter((c) => c in usageRoots());
|
|
1611
|
+
if (cfg.clients?.antigravity) { // no transcripts to count here, only its quota, and only while the app is open
|
|
1612
|
+
const w = await antigravityQuota().catch(() => null);
|
|
1613
|
+
if (w) {
|
|
1614
|
+
const r = await api("usage", { days: {}, status: { antigravity: { windows: w, limit_at: Math.floor(Date.now() / 1000) } } });
|
|
1615
|
+
if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1560
1618
|
if (!clients.length) return;
|
|
1561
1619
|
scanUsage(state, Object.fromEntries(Object.entries(usageRoots()).filter(([c]) => clients.includes(c))));
|
|
1562
1620
|
try { writeFileSync(file + ".tmp", JSON.stringify(state)); renameSync(file + ".tmp", file); } catch (e) { log("usage: " + e.message); }
|
|
@@ -1586,6 +1644,7 @@ async function wakeRun() {
|
|
|
1586
1644
|
log("OwlMem auto-wake " + VERSION + " running on " + (cfg.machine || hostname()) + ".");
|
|
1587
1645
|
const usage = () => usageTick(cfg, api, log).catch((e) => log("usage: " + e.message));
|
|
1588
1646
|
setTimeout(usage, 30000).unref(); setInterval(usage, USAGE_EVERY).unref();
|
|
1647
|
+
setInterval(() => aliveTick(sched, api, log).catch((e) => log("check-in: " + e.message)), ALIVE_EVERY).unref();
|
|
1589
1648
|
const out = await wakeLoop({ cfg, api, sched, log, update: (v) => wakeUpdate(v, { log }),
|
|
1590
1649
|
cleanup: () => { try { wakeUninstall(autostartOpts(), wakeRunCmd, true); } catch (e) { log("cleanup: " + e.message); } } });
|
|
1591
1650
|
if (out === "revoked") process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owlmem",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
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" },
|