@oh-my-pi/omp-stats 18.4.2 → 18.4.4

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.
@@ -3,7 +3,7 @@ export interface BarListItem {
3
3
  key: string;
4
4
  label: ReactNode;
5
5
  value: number;
6
- /** Formatted figure; defaults to `value.toLocaleString()`. */
6
+ /** Formatted figure; defaults to `formatInteger(value)`. */
7
7
  display?: string;
8
8
  color?: string;
9
9
  }
@@ -7,6 +7,11 @@ export { getGainDashboardStats } from "./gain-aggregator.js";
7
7
  export { formatStatsDashboardUrl, type StartServerOptions, startServer } from "./server.js";
8
8
  export type { GainDashboardStats, GainSource, GainSourceTotals, GainTimeSeriesPoint } from "./shared-types.js";
9
9
  export type { AggregatedStats, DashboardStats, FolderStats, MessageStats, ModelPerformancePoint, ModelStats, ModelTimeSeriesPoint, TimeSeriesPoint, ToolDashboardStats, ToolModelStats, ToolTimeSeriesPoint, ToolUsageStats, } from "./types.js";
10
+ /**
11
+ * Print the dashboard summary to the console. Shared by `omp stats --summary`
12
+ * and the standalone `omp-stats --sync`.
13
+ */
14
+ export declare function printStatsSummary(): Promise<void>;
10
15
  /** Parsed arguments for the standalone `omp-stats` entry point. */
11
16
  export interface StandaloneStatsArgs {
12
17
  port: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/omp-stats",
4
- "version": "18.4.2",
4
+ "version": "18.4.4",
5
5
  "description": "Local observability dashboard for omp AI usage statistics",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": {
@@ -42,9 +42,9 @@
42
42
  "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
43
43
  },
44
44
  "dependencies": {
45
- "@oh-my-pi/pi-ai": "18.4.2",
46
- "@oh-my-pi/pi-catalog": "18.4.2",
47
- "@oh-my-pi/pi-utils": "18.4.2",
45
+ "@oh-my-pi/pi-ai": "18.4.4",
46
+ "@oh-my-pi/pi-catalog": "18.4.4",
47
+ "@oh-my-pi/pi-utils": "18.4.4",
48
48
  "lucide-react": "^1.24.0",
49
49
  "react": "19.2.7",
50
50
  "react-dom": "19.2.7"
@@ -1,10 +1,11 @@
1
1
  import type { ReactNode } from "react";
2
+ import { formatInteger } from "../data/formatters";
2
3
 
3
4
  export interface BarListItem {
4
5
  key: string;
5
6
  label: ReactNode;
6
7
  value: number;
7
- /** Formatted figure; defaults to `value.toLocaleString()`. */
8
+ /** Formatted figure; defaults to `formatInteger(value)`. */
8
9
  display?: string;
9
10
  color?: string;
10
11
  }
@@ -30,7 +31,7 @@ export function BarList({ items, max, onSelect }: BarListProps) {
30
31
  style={{ width: `${pct}%`, background: item.color ?? "var(--chart-primary)" }}
31
32
  />
32
33
  <span className="bar-list-label">{item.label}</span>
33
- <span className="bar-list-value">{item.display ?? item.value.toLocaleString()}</span>
34
+ <span className="bar-list-value">{item.display ?? formatInteger(item.value)}</span>
34
35
  </>
35
36
  );
36
37
  return onSelect ? (
@@ -1,18 +1,25 @@
1
1
  import { format, formatDistanceToNow } from "@oh-my-pi/pi-utils/dates";
2
2
  import type { MessageStats } from "../types";
3
3
 
4
+ /**
5
+ * Every number on the dashboard uses one fixed locale. Labels, percents
6
+ * (`toFixed`), durations and dates are English, so following the browser
7
+ * locale mixed conventions (e.g. `1,4 Mr` beside `97.0%` on a tr-TR browser).
8
+ */
9
+ const NUMBER_LOCALE = "en-US";
10
+
4
11
  export function formatInteger(value: number): string {
5
- return value.toLocaleString();
12
+ return value.toLocaleString(NUMBER_LOCALE);
6
13
  }
7
14
 
8
15
  export function formatCompact(value: number): string {
9
- return value.toLocaleString(undefined, { notation: "compact" });
16
+ return value.toLocaleString(NUMBER_LOCALE, { notation: "compact" });
10
17
  }
11
18
 
12
19
  export function formatCost(value: number, digits?: number): string {
13
20
  if (value === 0) return "$0";
14
21
  const fractionDigits = digits !== undefined ? digits : value > 0 && value < 0.01 ? 4 : 2;
15
- return `$${value.toLocaleString(undefined, {
22
+ return `$${value.toLocaleString(NUMBER_LOCALE, {
16
23
  minimumFractionDigits: fractionDigits,
17
24
  maximumFractionDigits: fractionDigits,
18
25
  })}`;
@@ -8,7 +8,7 @@
8
8
  import { ChevronDown, ChevronRight } from "lucide-react";
9
9
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
10
10
  import { createPortal } from "react-dom";
11
- import { formatDurationMs } from "../data/formatters";
11
+ import { formatDurationMs, formatInteger } from "../data/formatters";
12
12
  import type { TraceMarker, TraceSpan, TraceSpanKind, TraceTrack } from "../types";
13
13
  import { buildTicks, formatOffset, type TraceScale } from "./time-scale";
14
14
  import { type TraceTheme, useTraceTheme } from "./trace-colors";
@@ -738,7 +738,7 @@ function renderTooltip(hover: HoverState, traceStart: number) {
738
738
  </div>
739
739
  {span.kind === "model" && (
740
740
  <div className="muted num">
741
- {span.tokens !== undefined && <>{span.tokens.toLocaleString()} tok</>}
741
+ {span.tokens !== undefined && <>{formatInteger(span.tokens)} tok</>}
742
742
  {span.cost !== undefined && <> · ${span.cost.toFixed(4)}</>}
743
743
  {span.ttft !== undefined && <> · TTFT {formatDurationMs(span.ttft)}</>}
744
744
  {span.isError && <> · error</>}
@@ -1,5 +1,6 @@
1
1
  import { ArrowDown, ArrowUp } from "lucide-react";
2
2
  import { Fragment, type ReactNode, useMemo, useState } from "react";
3
+ import { formatInteger } from "../data/formatters";
3
4
  import { EmptyState } from "./States";
4
5
 
5
6
  export interface Column<T> {
@@ -154,7 +155,7 @@ export function Table<T>({
154
155
  {limit !== undefined && sorted.length > limit && (
155
156
  <div className="table-more">
156
157
  <span className="micro">
157
- {visible.length.toLocaleString()} of {sorted.length.toLocaleString()}
158
+ {formatInteger(visible.length)} of {formatInteger(sorted.length)}
158
159
  </span>
159
160
  {sorted.length > shown && (
160
161
  <button
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
3
  import { parseArgs } from "node:util";
4
- import { formatDuration, formatNumber, formatPercent } from "@oh-my-pi/pi-utils";
4
+ import { formatDuration, formatNumber, formatPercent, normalizePremiumRequests } from "@oh-my-pi/pi-utils";
5
+ import chalk from "@oh-my-pi/pi-utils/chalk";
5
6
  import { getDashboardStats, getTotalMessageCount, syncAllSessions } from "./aggregator";
6
7
  import { closeDb } from "./db";
7
8
  import { refreshRollups } from "./rollup";
@@ -45,20 +46,17 @@ function formatCost(n: number, unpricedRequests = 0): string {
45
46
  return `$${n.toFixed(2)}`;
46
47
  }
47
48
 
48
- function normalizePremiumRequests(n: number): number {
49
- return Math.round((n + Number.EPSILON) * 100) / 100;
50
- }
51
-
52
49
  /**
53
- * Print stats summary to console.
50
+ * Print the dashboard summary to the console. Shared by `omp stats --summary`
51
+ * and the standalone `omp-stats --sync`.
54
52
  */
55
- async function printStats(): Promise<void> {
53
+ export async function printStatsSummary(): Promise<void> {
56
54
  const stats = await getDashboardStats();
57
55
  const { overall, byModel, byFolder } = stats;
58
56
 
59
- console.log("\n=== AI Usage Statistics ===\n");
57
+ console.log(chalk.bold("\n=== AI Usage Statistics ===\n"));
60
58
 
61
- console.log("Overall:");
59
+ console.log(chalk.bold("Overall:"));
62
60
  console.log(` Requests: ${formatNumber(overall.totalRequests)} (${formatNumber(overall.failedRequests)} errors)`);
63
61
  console.log(` Error Rate: ${formatPercent(overall.errorRate)}`);
64
62
  console.log(` Total Tokens: ${formatNumber(overall.totalInputTokens + overall.totalOutputTokens)}`);
@@ -75,7 +73,7 @@ async function printStats(): Promise<void> {
75
73
  }
76
74
 
77
75
  if (byModel.length > 0) {
78
- console.log("\nBy Model (API-equivalent estimates):");
76
+ console.log(chalk.bold("\nBy Model (API-equivalent estimates):"));
79
77
  for (const m of byModel.slice(0, 10)) {
80
78
  console.log(
81
79
  ` ${m.model}: ${formatNumber(m.totalRequests)} reqs, ${formatCost(m.totalCost, m.unpricedRequests)}, ${formatPercent(m.cacheRate)} cache rate, ${formatPercent(m.cacheSavings)} cache savings`,
@@ -84,7 +82,7 @@ async function printStats(): Promise<void> {
84
82
  }
85
83
 
86
84
  if (byFolder.length > 0) {
87
- console.log("\nBy Folder (API-equivalent estimates):");
85
+ console.log(chalk.bold("\nBy Folder (API-equivalent estimates):"));
88
86
  for (const f of byFolder.slice(0, 10)) {
89
87
  console.log(
90
88
  ` ${f.folder}: ${formatNumber(f.totalRequests)} reqs, ${formatCost(f.totalCost, f.unpricedRequests)}`,
@@ -199,7 +197,7 @@ Examples:
199
197
  if (values.json) {
200
198
  console.log(JSON.stringify(await getDashboardStats(), null, 2));
201
199
  } else {
202
- await printStats();
200
+ await printStatsSummary();
203
201
  }
204
202
  } catch (error) {
205
203
  console.error("Error:", error);