Download src/stores/metrics-store.ts from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/src/stores/metrics-store.ts
- Command line
-
hf download hf://SaylorTwift/openhands/src/stores/metrics-store.ts
-
curl -L -o metrics-store.ts https://huggingface.co/SaylorTwift/openhands/resolve/main/src/stores/metrics-store.ts
1.16 kB
| 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; | |