auto-model-router 0.4.11 → 0.4.12

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.
@@ -7,14 +7,14 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "auto-model-router: a local cost/complexity-aware model router for Oh My Pi, backed by OpenRouter",
10
- "version": "0.4.11",
10
+ "version": "0.4.12",
11
11
  "pluginRoot": "."
12
12
  },
13
13
  "plugins": [
14
14
  {
15
15
  "name": "auto-model-router",
16
16
  "description": "Local cost/complexity-aware model router for Oh My Pi, backed by OpenRouter. Runs in-process, routes per turn by price and task complexity, with budget caps, mid-stream escalation, and cache-aware hysteresis.",
17
- "version": "0.4.11",
17
+ "version": "0.4.12",
18
18
  "author": {
19
19
  "name": "drewappling",
20
20
  "email": "drewappling@gmail.com"
package/README.md CHANGED
@@ -706,7 +706,8 @@ escalation signal, error. Three views aggregate it, all from the same
706
706
  transcript. Falls back to reading the ledger directly if the router is
707
707
  unreachable.
708
708
  - `auto-model-router report --days 7 [--harness <id>] [--json]` on the terminal.
709
- - `GET /v1/router/report?days=7&harness=<id>` for dashboards.
709
+ - `GET /v1/router/report?days=7&harness=<id>` for dashboards (`harness` may be
710
+ a comma-separated set of ids, for a group).
710
711
  - `GET /v1/router/summary?harness=<id>` — the daily summary as JSON (`auto=1`
711
712
  applies the once-a-day gate and returns `due: false` when nothing is due).
712
713
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-model-router",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "private": false,
5
5
  "description": "Local cost/complexity-aware model router for Oh My Pi, backed by OpenRouter",
6
6
  "type": "module",
@@ -187,9 +187,20 @@ function toRow(r: RawRow, windowSpend: number): ReportRow {
187
187
  };
188
188
  }
189
189
 
190
+ /** A harness filter: one id, or several comma-separated (a team's members); empty ⇒ everything. */
191
+ export function harnessFilter(harnessId: string, param = "$harness"): { sql: string[]; bind: Record<string, string> } {
192
+ const ids = harnessId.split(",").map((s) => s.trim()).filter((s) => s !== "");
193
+ if (ids.length === 0) return { sql: [], bind: {} };
194
+ if (ids.length === 1) return { sql: [`harness_id = ${param}`], bind: { [param]: ids[0]! } };
195
+ const bind: Record<string, string> = {};
196
+ ids.forEach((id, i) => (bind[`${param}${i}`] = id));
197
+ return { sql: [`harness_id IN (${ids.map((_, i) => `${param}${i}`).join(", ")})`], bind };
198
+ }
199
+
190
200
  /**
191
201
  * Builds the report for the last `windowDays`. `harnessId` narrows to one
192
- * harness (the `X-Omp-Harness` header); empty means everything.
202
+ * harness (the `X-Omp-Harness` header) or a comma-separated set of them (a
203
+ * team edition group); empty means everything.
193
204
  */
194
205
  export function buildUsageReport(
195
206
  db: Database,
@@ -200,12 +211,9 @@ export function buildUsageReport(
200
211
  const sinceMs = nowMs - windowDays * 86_400_000;
201
212
  const harnessId = opts.harnessId ?? "";
202
213
  const untilMs = opts.untilMs;
203
- const where = [
204
- "created_at_ms >= $since",
205
- ...(untilMs === undefined ? [] : ["created_at_ms < $until"]),
206
- ...(harnessId === "" ? [] : ["harness_id = $harness"]),
207
- ].join(" AND ");
208
- const bind = { $since: sinceMs, ...(untilMs === undefined ? {} : { $until: untilMs }), ...(harnessId === "" ? {} : { $harness: harnessId }) };
214
+ const hf = harnessFilter(harnessId);
215
+ const where = ["created_at_ms >= $since", ...(untilMs === undefined ? [] : ["created_at_ms < $until"]), ...hf.sql].join(" AND ");
216
+ const bind = { $since: sinceMs, ...(untilMs === undefined ? {} : { $until: untilMs }), ...hf.bind };
209
217
 
210
218
  const t = db
211
219
  .query(
@@ -13,7 +13,7 @@
13
13
 
14
14
  import type { Database } from "bun:sqlite";
15
15
  import { TIER_ORDER } from "../router/types.ts";
16
- import { buildUsageReport, type BaselinePrice, type BaselineRow, type UsageReport } from "./report.ts";
16
+ import { buildUsageReport, harnessFilter, type BaselinePrice, type BaselineRow, type UsageReport } from "./report.ts";
17
17
  import type { SoftFailureSpike } from "./types.ts";
18
18
 
19
19
  /** One 24-hour window's headline numbers. */
@@ -89,8 +89,9 @@ function windowOf(r: UsageReport): SummaryWindow {
89
89
 
90
90
  /** Counts tier moves up and down between consecutive kept turns of each conversation since `sinceMs`. */
91
91
  export function countTierChanges(db: Database, sinceMs: number, harnessId: string): { up: number; down: number } {
92
- const where = harnessId === "" ? "created_at_ms >= $since" : "created_at_ms >= $since AND harness_id = $harness";
93
- const bind = harnessId === "" ? { $since: sinceMs } : { $since: sinceMs, $harness: harnessId };
92
+ const hf = harnessFilter(harnessId);
93
+ const where = ["created_at_ms >= $since", ...hf.sql].join(" AND ");
94
+ const bind = { $since: sinceMs, ...hf.bind };
94
95
  const seq = db
95
96
  .query(`SELECT conversation_key AS ck, tier FROM ledger WHERE ${where} AND wasted = 0 AND requested_model <> 'digest' ORDER BY conversation_key, created_at_ms`)
96
97
  .all(bind) as { ck: string; tier: string }[];
@@ -155,7 +156,7 @@ function delta(current: number, previous: number): string {
155
156
 
156
157
  /** Renders the summary as a few plain lines for the transcript. */
157
158
  export function renderDailySummary(s: DailySummary): string {
158
- const scope = s.harnessId === "" ? "all harnesses" : `harness ${s.harnessId}`;
159
+ const scope = s.harnessId === "" ? "all harnesses" : s.harnessId.includes(",") ? `${s.harnessId.split(",").length} harnesses` : `harness ${s.harnessId}`;
159
160
  const out: string[] = [`auto-model-router daily summary — last 24h (${scope})`];
160
161
  const c = s.current;
161
162
  if (c.dispatches === 0) {
@@ -156,6 +156,20 @@ describe("buildUsageReport", () => {
156
156
  db.close();
157
157
  });
158
158
 
159
+ test("a comma-separated harness list reports the union (a team group)", () => {
160
+ const { db, ledger } = seeded();
161
+ try {
162
+ ledger.record(entry({ harnessId: "u_a", reportedUsd: 1 }));
163
+ ledger.record(entry({ harnessId: "u_b", reportedUsd: 2 }));
164
+ ledger.record(entry({ harnessId: "u_c", reportedUsd: 4 }));
165
+ expect(buildUsageReport(db, { windowDays: 1, nowMs: NOW, harnessId: "u_a,u_b" }).totals.spendUsd).toBeCloseTo(3, 6);
166
+ expect(buildUsageReport(db, { windowDays: 1, nowMs: NOW, harnessId: " u_c , u_a " }).totals.spendUsd).toBeCloseTo(5, 6);
167
+ expect(buildUsageReport(db, { windowDays: 1, nowMs: NOW, harnessId: "u_b" }).totals.spendUsd).toBeCloseTo(2, 6);
168
+ } finally {
169
+ db.close();
170
+ }
171
+ });
172
+
159
173
  test("prompt anatomy averages the recorded byte shares", () => {
160
174
  const { db, ledger } = seeded();
161
175
  const feat = (tool: number, older: number, stale: number) => ({ toolSchemaBytes: 1000, anatomy: { messages: 30, systemBytes: 1000, userBytes: 500, assistantBytes: 500, toolBytes: tool, olderHalfBytes: older, staleToolBytes: stale } });