MCPcopy Create free account
hub / github.com/anus-dev/ANUS / SessionStatsProvider

Function SessionStatsProvider

packages/cli/src/ui/contexts/SessionContext.tsx:66–130  ·  view source on GitHub ↗
({
  children,
})

Source from the content-addressed store, hash-verified

64// --- Provider Component ---
65
66export const SessionStatsProvider: React.FC<{ children: React.ReactNode }> = ({
67 children,
68}) => {
69 const [stats, setStats] = useState<SessionStatsState>({
70 sessionId,
71 sessionStartTime: new Date(),
72 metrics: uiTelemetryService.getMetrics(),
73 lastPromptTokenCount: 0,
74 promptCount: 0,
75 });
76
77 useEffect(() => {
78 const handleUpdate = ({
79 metrics,
80 lastPromptTokenCount,
81 }: {
82 metrics: SessionMetrics;
83 lastPromptTokenCount: number;
84 }) => {
85 setStats((prevState) => ({
86 ...prevState,
87 metrics,
88 lastPromptTokenCount,
89 }));
90 };
91
92 uiTelemetryService.on('update', handleUpdate);
93 // Set initial state
94 handleUpdate({
95 metrics: uiTelemetryService.getMetrics(),
96 lastPromptTokenCount: uiTelemetryService.getLastPromptTokenCount(),
97 });
98
99 return () => {
100 uiTelemetryService.off('update', handleUpdate);
101 };
102 }, []);
103
104 const startNewPrompt = useCallback(() => {
105 setStats((prevState) => ({
106 ...prevState,
107 promptCount: prevState.promptCount + 1,
108 }));
109 }, []);
110
111 const getPromptCount = useCallback(
112 () => stats.promptCount,
113 [stats.promptCount],
114 );
115
116 const value = useMemo(
117 () => ({
118 stats,
119 startNewPrompt,
120 getPromptCount,
121 }),
122 [stats, startNewPrompt, getPromptCount],
123 );

Callers

nothing calls this directly

Calls 3

handleUpdateFunction · 0.85
getMetricsMethod · 0.80

Tested by

no test coverage detected