File size: 1,156 Bytes
5f40163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { create } from "zustand";

export interface MetricsState {
  cost: number | null;
  max_budget_per_task: number | null;
  usage: {
    prompt_tokens: number;
    completion_tokens: number;
    cache_read_tokens: number;
    cache_write_tokens: number;
    context_window: number;
    per_turn_token: number;
  } | null;
}

export interface MetricsStore extends MetricsState {
  setMetrics: (metrics: MetricsState) => void;
  resetMetrics: () => void;
}

const EMPTY_METRICS: MetricsState = {
  cost: null,
  max_budget_per_task: null,
  usage: null,
};

const useMetricsStore = create<MetricsStore>((set) => ({
  ...EMPTY_METRICS,
  setMetrics: (metrics) => set(metrics),
  resetMetrics: () => set(EMPTY_METRICS),
}));

// Dev-only console handle for inspecting the live WS metrics while
// debugging the usage meter (window.__OH_METRICS_STORE__.getState()).
// Gated on import.meta.env.DEV so it never reaches production builds.
if (typeof window !== "undefined" && import.meta.env.DEV) {
  (
    window as unknown as { __OH_METRICS_STORE__?: typeof useMetricsStore }
  ).__OH_METRICS_STORE__ = useMetricsStore;
}

export default useMetricsStore;