- Reset master to upstream/main (16,697 commits) - Overlay 2,271 local-only files (skills, tools, workspace, configs, apps) - Restore IDENTITY.md and USER.md templates - Build verified, gateway running, Discord working Co-Authored-By: Claude Opus 4.6 <[email protected]>
46 lines
1.8 KiB
JavaScript
46 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { execSync } = require("child_process");
|
|
|
|
(async function () {
|
|
try {
|
|
const cwd = process.cwd();
|
|
const out = {
|
|
timestamp: new Date().toISOString(),
|
|
providers: {},
|
|
totals: { costUsd: 0, tokens: 0, requests: 0 },
|
|
};
|
|
const db = path.join(cwd, "data", "usage.db");
|
|
if (fs.existsSync(db)) {
|
|
try {
|
|
const cmd = `sqlite3 ${db} "SELECT IFNULL(SUM(totalTokens),0)||'|'||IFNULL(SUM(totalRequests),0)||'|'||IFNULL(SUM(totalCostUsd),0) FROM snapshots WHERE date >= date('now','-7 days');"`;
|
|
const cnt = execSync(cmd, { timeout: 15000 }).toString().trim();
|
|
const parts = cnt.split("|").map((s) => parseFloat(s) || 0);
|
|
out.totals.tokens = parts[0];
|
|
out.totals.requests = parts[1];
|
|
out.totals.costUsd = parts[2];
|
|
} catch (e) {
|
|
console.error("sqlite read failed", e.message);
|
|
}
|
|
}
|
|
const api = process.env.DASH_API || "http://127.0.0.1:3031/api/status/backfill";
|
|
try {
|
|
const tmp = path.join("/tmp", "poc-dashboard-payload.json");
|
|
fs.writeFileSync(tmp, JSON.stringify(out));
|
|
const curl = `/usr/bin/curl -sS -X POST -H 'Content-Type: application/json' --data-binary @${tmp} ${api} -m 15`;
|
|
const res = execSync(curl, { timeout: 20000 }).toString();
|
|
console.log("curl result:", res.substring(0, 800));
|
|
} catch (e) {
|
|
console.error("curl failed", e.message);
|
|
}
|
|
const outpath = path.join(cwd, "tools", "model-dashboard", "integrations", "poc-sample.json");
|
|
fs.mkdirSync(path.dirname(outpath), { recursive: true });
|
|
fs.writeFileSync(outpath, JSON.stringify(out, null, 2));
|
|
console.log("Wrote sample to", outpath);
|
|
} catch (err) {
|
|
console.error(err);
|
|
process.exit(2);
|
|
}
|
|
})();
|