@relayplane/proxy 1.9.27 → 1.9.29

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.
@@ -0,0 +1,23 @@
1
+ export interface CostRecord {
2
+ tenantId: string;
3
+ model: string;
4
+ costUsd: number;
5
+ requestCount: number;
6
+ timestamp: Date;
7
+ }
8
+ export interface CostQueryResult {
9
+ totalUsd: number;
10
+ byModel: Record<string, number>;
11
+ byDay: Record<string, number>;
12
+ requestCount: number;
13
+ }
14
+ export declare class CostLedger {
15
+ private records;
16
+ private ledgerPath;
17
+ constructor();
18
+ private load;
19
+ private save;
20
+ record(rec: CostRecord): void;
21
+ query(tenantId: string, range: '7d' | '30d' | 'all'): CostQueryResult;
22
+ }
23
+ //# sourceMappingURL=cost-ledger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-ledger.d.ts","sourceRoot":"","sources":["../src/cost-ledger.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;CACtB;AAUD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,UAAU,CAAS;;IAO3B,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,IAAI;IAIZ,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAK7B,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,eAAe;CA2BtE"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CostLedger = void 0;
37
+ const fs = __importStar(require("node:fs"));
38
+ const path = __importStar(require("node:path"));
39
+ const os = __importStar(require("node:os"));
40
+ function getLedgerPath() {
41
+ const home = process.env['RELAYPLANE_HOME_OVERRIDE'] ?? path.join(os.homedir(), '.relayplane');
42
+ fs.mkdirSync(home, { recursive: true });
43
+ return path.join(home, 'cost-ledger.json');
44
+ }
45
+ class CostLedger {
46
+ records;
47
+ ledgerPath;
48
+ constructor() {
49
+ this.ledgerPath = getLedgerPath();
50
+ this.records = this.load();
51
+ }
52
+ load() {
53
+ try {
54
+ const raw = fs.readFileSync(this.ledgerPath, 'utf8');
55
+ return JSON.parse(raw);
56
+ }
57
+ catch {
58
+ return [];
59
+ }
60
+ }
61
+ save() {
62
+ fs.writeFileSync(this.ledgerPath, JSON.stringify(this.records), 'utf8');
63
+ }
64
+ record(rec) {
65
+ this.records.push({ ...rec, timestamp: rec.timestamp.toISOString() });
66
+ this.save();
67
+ }
68
+ query(tenantId, range) {
69
+ const now = Date.now();
70
+ const cutoff = range === '7d' ? now - 7 * 24 * 60 * 60 * 1000 :
71
+ range === '30d' ? now - 30 * 24 * 60 * 60 * 1000 :
72
+ 0;
73
+ const filtered = this.records.filter(r => {
74
+ if (r.tenantId !== tenantId)
75
+ return false;
76
+ if (cutoff > 0 && new Date(r.timestamp).getTime() < cutoff)
77
+ return false;
78
+ return true;
79
+ });
80
+ const result = { totalUsd: 0, byModel: {}, byDay: {}, requestCount: 0 };
81
+ for (const r of filtered) {
82
+ result.totalUsd += r.costUsd;
83
+ result.requestCount += r.requestCount;
84
+ result.byModel[r.model] = (result.byModel[r.model] ?? 0) + r.costUsd;
85
+ const day = r.timestamp.slice(0, 10); // YYYY-MM-DD
86
+ result.byDay[day] = (result.byDay[day] ?? 0) + r.costUsd;
87
+ }
88
+ return result;
89
+ }
90
+ }
91
+ exports.CostLedger = CostLedger;
92
+ //# sourceMappingURL=cost-ledger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-ledger.js","sourceRoot":"","sources":["../src/cost-ledger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAClC,4CAA8B;AAmB9B,SAAS,aAAa;IACpB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EA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 td{padding:8px 12px;border-bottom:1px solid #111318}
2665
2665
  <table><thead><tr><th>Agent</th><th>Requests</th><th>Total Cost</th><th>Last Active</th><th></th></tr></thead><tbody id="agents"></tbody></table></div>
2666
2666
  <div class="section"><h2>Provider Status</h2><div class="prov" id="providers"></div></div>
2667
2667
  <div class="section collapsible collapsed"><h2>Learning</h2><div id="learning-panel" style="display:flex;flex-direction:column;gap:12px"><div id="learning-stats" style="display:flex;gap:12px;flex-wrap:wrap"></div><div id="learning-recent"></div></div></div>
2668
- <div class="section collapsible" id="sessions-section"><h2>Sessions <span id="sessionsLabel" style="font-size:.75rem;color:#64748b;font-weight:400">(last 7d)</span></h2>
2668
+ <div class="section collapsible collapsed" id="sessions-section"><h2>Sessions <span id="sessionsLabel" style="font-size:.75rem;color:#64748b;font-weight:400">(last 7d)</span></h2>
2669
2669
  <table><thead><tr><th>Session ID</th><th>Source</th><th>Started</th><th>Duration</th><th>Requests</th><th>Tokens In</th><th>Tokens Out</th><th>Cost</th><th>Models</th><th>Status</th></tr></thead><tbody id="sessions"></tbody></table>
2670
2670
  </div>
2671
2671
  <div class="section collapsible collapsed" id="token-pool-section"><h2>Token Pool</h2><div id="token-pool-panel"></div></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relayplane/proxy",
3
- "version": "1.9.27",
3
+ "version": "1.9.29",
4
4
  "description": "Open source cost intelligence proxy for AI agents. Cut LLM costs ~80% with smart model routing. Dashboard, policy engine, 11 providers. MIT licensed.",
5
5
  "homepage": "https://relayplane.com",
6
6
  "repository": {