Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

fix(studio): refresh profile stats and mode-aware activity summary

Souravrajvi02c8a6e0db07b
diff --git a/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx b/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx
index 2addf335370..bc0c034800e 100644
--- a/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx
+++ b/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx
@@ -7,6 +7,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
import type { ProfileStatsDay } from "../../api/profile-stats";
import {
type ActivityMode,
+ activitySummaryForMode,
formatCompactNumber,
formatProfileCount,
heatLevel,
@@ -290,14 +291,9 @@ export function TokenActivityCard({ daily }: { daily: ProfileStatsDay[] }) {
),
[grid, shaded],
);
- const visibleTotal = useMemo(
- () =>
- grid.reduce(
- (sum, column) =>
- column.reduce((total, cell) => total + (cell.day?.tokens ?? 0), sum),
- 0,
- ),
- [grid],
+ const summaryTotal = useMemo(
+ () => activitySummaryForMode(grid, mode),
+ [grid, mode],
);
const dateFormatter = useMemo(
@@ -313,12 +309,12 @@ export function TokenActivityCard({ daily }: { daily: ProfileStatsDay[] }) {
return (
<StatsCard
title={t("settings.profile.stats.activityTitle")}
- description={t("settings.profile.stats.activityDescription", {
+ description={t(`settings.profile.stats.activityDescription.${mode}`, {
total: formatProfileCount(
- visibleTotal,
+ summaryTotal,
"token",
locale,
- formatCompactNumber(visibleTotal, locale),
+ formatCompactNumber(summaryTotal, locale),
),
weeks: formatProfileCount(grid.length, "week", locale),
})}
diff --git a/studio/frontend/src/features/profile/hooks/use-profile-stats.ts b/studio/frontend/src/features/profile/hooks/use-profile-stats.ts
index c14f8e81e19..35f8ae566ee 100644
--- a/studio/frontend/src/features/profile/hooks/use-profile-stats.ts
+++ b/studio/frontend/src/features/profile/hooks/use-profile-stats.ts
@@ -2,6 +2,8 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import { useCallback, useEffect, useRef, useState } from "react";
+import { subscribeResidentStatusRefresh } from "@/features/hub/lib/resident-status-refresh";
+import { useSettingsDialogStore } from "@/features/settings/stores/settings-dialog-store";
import { type ProfileStats, loadProfileStats } from "../api/profile-stats";
type ProfileStatsState = {
@@ -43,6 +45,18 @@ export function useProfileStats(): ProfileStatsState {
return () => abortRef.current?.abort();
}, [load]);
+ useEffect(() => subscribeResidentStatusRefresh(load), [load]);
+
+ const settingsOpen = useSettingsDialogStore((state) => state.open);
+ const sawSettingsOpenRef = useRef(settingsOpen);
+ useEffect(() => {
+ const wasOpen = sawSettingsOpenRef.current;
+ sawSettingsOpenRef.current = settingsOpen;
+ if (!wasOpen && settingsOpen) {
+ void load();
+ }
+ }, [settingsOpen, load]);
+
const reload = useCallback(() => {
void load();
}, [load]);
diff --git a/studio/frontend/src/features/profile/utils/stats-format.ts b/studio/frontend/src/features/profile/utils/stats-format.ts
index c15d623cff4..21999f69b46 100644
--- a/studio/frontend/src/features/profile/utils/stats-format.ts
+++ b/studio/frontend/src/features/profile/utils/stats-format.ts
@@ -336,6 +336,37 @@ export function windowBaseline(
return values[start - 1] ?? 0;
}
+export type ActivityGridCell = {
+ day: { tokens: number } | null;
+};
+
+export type ActivityGridColumn = ActivityGridCell[];
+
+/**
+ * Headline number for the activity card subtitle. Daily and cumulative sum
+ * tokens in the visible window; weekly reports the busiest week in that window.
+ */
+export function activitySummaryForMode(
+ grid: ActivityGridColumn[],
+ mode: ActivityMode,
+): number {
+ if (grid.length === 0) return 0;
+ if (mode === "weekly") {
+ return grid.reduce((peak, column) => {
+ let weekTokens = 0;
+ for (const cell of column) {
+ if (cell.day) weekTokens += cell.day.tokens;
+ }
+ return Math.max(peak, weekTokens);
+ }, 0);
+ }
+ return grid.reduce(
+ (sum, column) =>
+ column.reduce((total, cell) => total + (cell.day?.tokens ?? 0), sum),
+ 0,
+ );
+}
+
export function seriesForMode(
daily: Array<{ date: string; tokens: number }>,
mode: ActivityMode,
diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.ts
index 460687f6d98..91d9adfd82b 100644
--- a/studio/frontend/src/i18n/locales/ar.ts
+++ b/studio/frontend/src/i18n/locales/ar.ts
@@ -921,7 +921,11 @@ export const ar = {
currentStreak: "التتابع الحالي",
longestStreak: "أطول تتابع",
activityTitle: "نشاط التوكنات",
- activityDescription: "{total} خلال آخر {weeks}",
+ activityDescription: {
+ daily: "{total} خلال آخر {weeks}",
+ weekly: "أسبوع الذروة {total} · آخر {weeks}",
+ cumulative: "{total} متراكمة خلال آخر {weeks}",
+ },
mode: {
daily: "يومي",
weekly: "أسبوعي",
diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.ts
index e3f92c1cdfd..7428c35f04c 100644
--- a/studio/frontend/src/i18n/locales/de.ts
+++ b/studio/frontend/src/i18n/locales/de.ts
@@ -945,7 +945,11 @@ export const de = {
currentStreak: "Aktuelle Serie",
longestStreak: "Längste Serie",
activityTitle: "Token-Aktivität",
- activityDescription: "Zeitraum: {weeks} · {total}",
+ activityDescription: {
+ daily: "Zeitraum: {weeks} · {total}",
+ weekly: "Spitzenwoche {total} · letzte {weeks}",
+ cumulative: "{total} kumuliert in den letzten {weeks}",
+ },
mode: {
daily: "Täglich",
weekly: "Wöchentlich",
diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.ts
index 4f483933ff2..5d4046d0598 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -916,7 +916,11 @@ export const en = {
currentStreak: "Current streak",
longestStreak: "Longest streak",
activityTitle: "Token activity",
- activityDescription: "{total} over the last {weeks}",
+ activityDescription: {
+ daily: "{total} over the last {weeks}",
+ weekly: "Peak week {total} · last {weeks}",
+ cumulative: "{total} accumulated over the last {weeks}",
+ },
mode: {
daily: "Daily",
weekly: "Weekly",
diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.ts
index 0e78d199c7c..65e2e1e5ba2 100644
--- a/studio/frontend/src/i18n/locales/es.ts
+++ b/studio/frontend/src/i18n/locales/es.ts
@@ -940,7 +940,11 @@ export const es = {
currentStreak: "Racha actual",
longestStreak: "Racha más larga",
activityTitle: "Actividad de tokens",
- activityDescription: "Período: {weeks} · {total}",
+ activityDescription: {
+ daily: "Período: {weeks} · {total}",
+ weekly: "Semana pico {total} · últimas {weeks}",
+ cumulative: "{total} acumulados en las últimas {weeks}",
+ },
mode: {
daily: "Diaria",
weekly: "Semanal",
diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.ts
index 37ae82e4aba..d49f44e427b 100644
--- a/studio/frontend/src/i18n/locales/fr.ts
+++ b/studio/frontend/src/i18n/locales/fr.ts
@@ -944,7 +944,11 @@ export const fr = {
currentStreak: "Série en cours",
longestStreak: "Plus longue série",
activityTitle: "Activité en tokens",
- activityDescription: "{total} au cours des {weeks} dernières",
+ activityDescription: {
+ daily: "{total} au cours des {weeks} dernières",
+ weekly: "Semaine record {total} · {weeks} dernières",
+ cumulative: "{total} cumulés sur les {weeks} dernières",
+ },
mode: {
daily: "Quotidienne",
weekly: "Hebdomadaire",
diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.ts
index bdd95975c44..887cdc601b1 100644
--- a/studio/frontend/src/i18n/locales/hi.ts
+++ b/studio/frontend/src/i18n/locales/hi.ts
@@ -924,7 +924,11 @@ export const hi = {
currentStreak: "मौजूदा स्ट्रीक",
longestStreak: "सबसे लंबी स्ट्रीक",
activityTitle: "टोकन गतिविधि",
- activityDescription: "अवधि: {weeks} · {total}",
+ activityDescription: {
+ daily: "अवधि: {weeks} · {total}",
+ weekly: "सबसे व्यस्त सप्ताह {total} · पिछले {weeks}",
+ cumulative: "पिछले {weeks} में कुल {total}",
+ },
mode: {
daily: "दैनिक",
weekly: "साप्ताहिक",
diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.ts
index de9ce0c2844..d1cbd3ae3eb 100644
--- a/studio/frontend/src/i18n/locales/it.ts
+++ b/studio/frontend/src/i18n/locales/it.ts
@@ -909,7 +909,11 @@ export const it = {
currentStreak: "Serie attuale",
longestStreak: "Serie più lunga",
activityTitle: "Attività in token",
- activityDescription: "Periodo: {weeks} · {total}",
+ activityDescription: {
+ daily: "Periodo: {weeks} · {total}",
+ weekly: "Settimana di punta {total} · ultime {weeks}",
+ cumulative: "{total} accumulati nelle ultime {weeks}",
+ },
mode: {
daily: "Giornaliera",
weekly: "Settimanale",
diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.ts
index 164df0cacd2..8efb2169099 100644
--- a/studio/frontend/src/i18n/locales/ja.ts
+++ b/studio/frontend/src/i18n/locales/ja.ts
@@ -904,7 +904,11 @@ export const ja = {
currentStreak: "現在の連続日数",
longestStreak: "最長の連続日数",
activityTitle: "トークンの推移",
- activityDescription: "直近{weeks}で{total}",
+ activityDescription: {
+ daily: "直近{weeks}で{total}",
+ weekly: "ピーク週 {total} · 直近{weeks}",
+ cumulative: "直近{weeks}で累計{total}",
+ },
mode: {
daily: "日次",
weekly: "週次",
diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.ts
index 5794a314c7a..66f2a8d0b5b 100644
--- a/studio/frontend/src/i18n/locales/ko.ts
+++ b/studio/frontend/src/i18n/locales/ko.ts
@@ -917,7 +917,11 @@ export const ko = {
currentStreak: "현재 연속 기록",
longestStreak: "최장 연속 기록",
activityTitle: "토큰 활동",
- activityDescription: "최근 {weeks} 동안 {total}",
+ activityDescription: {
+ daily: "최근 {weeks} 동안 {total}",
+ weekly: "최고 주 {total} · 최근 {weeks}",
+ cumulative: "최근 {weeks} 동안 누적 {total}",
+ },
mode: {
daily: "일별",
weekly: "주별",
diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.ts
index 88a0120bc38..b3a29866f38 100644
--- a/studio/frontend/src/i18n/locales/pt-br.ts
+++ b/studio/frontend/src/i18n/locales/pt-br.ts
@@ -932,7 +932,11 @@ export const ptBR = {
currentStreak: "Sequência atual",
longestStreak: "Maior sequência",
activityTitle: "Atividade de tokens",
- activityDescription: "Período: {weeks} · {total}",
+ activityDescription: {
+ daily: "Período: {weeks} · {total}",
+ weekly: "Semana de pico {total} · últimas {weeks}",
+ cumulative: "{total} acumulados nas últimas {weeks}",
+ },
mode: {
daily: "Diária",
weekly: "Semanal",
diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.ts
index f6db42605d9..be94a074dcf 100644
--- a/studio/frontend/src/i18n/locales/ru.ts
+++ b/studio/frontend/src/i18n/locales/ru.ts
@@ -925,7 +925,11 @@ export const ru = {
currentStreak: "Текущая серия",
longestStreak: "Самая длинная серия",
activityTitle: "Активность по токенам",
- activityDescription: "Период: {weeks} · {total}",
+ activityDescription: {
+ daily: "Период: {weeks} · {total}",
+ weekly: "Пиковая неделя {total} · последние {weeks}",
+ cumulative: "{total} накоплено за последние {weeks}",
+ },
mode: {
daily: "По дням",
weekly: "По неделям",
diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.ts
index 70ee27c038f..3bf805e3f6c 100644
--- a/studio/frontend/src/i18n/locales/zh-CN.ts
+++ b/studio/frontend/src/i18n/locales/zh-CN.ts
@@ -899,7 +899,11 @@ export const zhCN = {
currentStreak: "当前连续天数",
longestStreak: "最长连续天数",
activityTitle: "Token 活跃度",
- activityDescription: "过去{weeks}共{total}",
+ activityDescription: {
+ daily: "过去{weeks}共{total}",
+ weekly: "峰值周 {total} · 最近{weeks}",
+ cumulative: "过去{weeks}累计{total}",
+ },
mode: {
daily: "按天",
weekly: "按周",
diff --git a/studio/frontend/tests/profile-stats-format.test.ts b/studio/frontend/tests/profile-stats-format.test.ts
index bf1bee50e0a..a66fc44a6bf 100644
--- a/studio/frontend/tests/profile-stats-format.test.ts
+++ b/studio/frontend/tests/profile-stats-format.test.ts
@@ -5,6 +5,7 @@ import assert from "node:assert/strict";
import test from "node:test";
import {
+ activitySummaryForMode,
formatCompactNumber,
formatDayCount,
formatDuration,
@@ -181,6 +182,34 @@ test("day keys parse as local dates, not UTC", () => {
assert.equal(parsed.getDate(), 9);
});
+test("activity summaries follow the selected chart mode", () => {
+ const grid = [
+ [
+ { day: { tokens: 10 } },
+ { day: { tokens: 20 } },
+ { day: null },
+ { day: null },
+ { day: null },
+ { day: null },
+ { day: null },
+ ],
+ [
+ { day: { tokens: 100 } },
+ { day: { tokens: 50 } },
+ { day: null },
+ { day: null },
+ { day: null },
+ { day: null },
+ { day: null },
+ ],
+ ];
+
+ assert.equal(activitySummaryForMode(grid, "daily"), 180);
+ assert.equal(activitySummaryForMode(grid, "cumulative"), 180);
+ assert.equal(activitySummaryForMode(grid, "weekly"), 150);
+ assert.equal(activitySummaryForMode([], "daily"), 0);
+});
+
test("series modes reshape the same daily data", () => {
// 2026-03-02 is a Monday, so this spans exactly two calendar weeks.
const daily = [