Compare commits

..
4 Commits
Author SHA1 Message Date
KimiSwitch Dev 5864d661c1 ci(release): Release 文案改为自动读取 release-notes-<tag>.md
Release / Version consistency (push) Canceled after 0s
Release / Build (macos-latest) (push) Canceled after 0s
Release / Build (ubuntu-latest) (push) Canceled after 0s
Release / Build (windows-latest) (push) Canceled after 0s
Release / Attach macOS install script (push) Canceled after 0s
不再硬编码过期文案;缺失时回退到提交记录说明,保留下载与 macOS 安装说明模板
2026-09-09 14:06:30 +08:00
KimiSwitch Dev 34a9c4c2d9 chore(release): bump to v0.7.15 — 昨天选项卡 + 模型用量统计 + Go 套餐 x-opencode-session 自动补头 2026-09-09 13:51:58 +08:00
KimiSwitch Dev 4f0b0cae12 feat(providers): Go 套餐导出自动补 x-opencode-session 头 + models-dev 2026-09-09
- opencode Console Go 网关强制要求 x-opencode-session 请求头(缺失 400),
  config 导出时对 zen/go 端点供应商自动补 custom_headers(保留用户已有值),
  zen/v1 按量端点不受影响
- models-dev 快照 7583 模型 / 213 供应商;public/ 前端静态目录同步补齐(原 08-27)
2026-09-09 13:51:57 +08:00
KimiSwitch Dev 35fd2e7b0e feat(dashboard): 用量统计新增「昨天」范围 + 跨供应商「模型用量统计」选项卡
- 范围新增 yesterday:本地时区昨日 0 点 ~ 今日 0 点,range_end 引入上界过滤
- RangeStats 新增 modelsByName:按裸模型名聚合,同一模型跨供应商合并,
  子代理记录归入 __secondary__ 单独成行,按 Token 降序
- 趋势选项卡第 4 个 tab「模型用量统计」:新增 ModelTotalsChart 横向条形图,
  悬停显示请求数/Token/缓存命中/费用
- 概览卡网格扩展为 5 张;i18n 中英同步
- 顺带:pricing 测试基准从已下架的 moonshotai/kimi-k2.5 切换到 kimi-k3
2026-09-09 13:51:43 +08:00
16 changed files with 84591 additions and 79883 deletions

No files matched your search

+40 -30
View File
@@ -69,6 +69,45 @@ jobs:
libgtk-3-dev \
libayatana-appindicator3-dev
- name: Compose release body
id: notes
shell: bash
run: |
FILE="release-notes-${{ github.ref_name }}.md"
{
echo 'body<<RELEASE_BODY_EOF'
if [ -f "$FILE" ]; then
cat "$FILE"
else
echo "## ${{ github.ref_name }}"
echo
echo "见提交记录(未找到 $FILE)。"
fi
echo
cat <<'TAIL_EOF'
### Downloads by platform
- **Windows**: `.msi` installer
- **macOS**: `.dmg` + `.app`(未签名,仅 Apple Silicon / M 系列芯片)
- **Linux**: `.deb` / `.AppImage` / `.rpm`
### macOS 安装说明(无开发者账号签名,需一次手动绕过)
1. 下载 `Kimi.Switch_*.dmg`,双击挂载后把 `Kimi Switch.app` 拖入「应用程序」文件夹
2. 下载本 Release 附带的 `install-macos.sh`,在终端运行:
```bash
bash install-macos.sh
```
脚本会自动清除「下载隔离」属性并启动应用,之后可正常使用。
3. 手动替代方案:右键 `Kimi Switch.app` → 打开 → 弹窗中点「打开」(或 系统设置 → 隐私与安全性 → 仍要打开)
Full changelog: see commit history.
TAIL_EOF
echo 'RELEASE_BODY_EOF'
} >> "$GITHUB_OUTPUT"
- name: Build and upload release
uses: tauri-apps/tauri-action@v0
env:
@@ -76,36 +115,7 @@ jobs:
with:
tagName: ${{ github.ref_name }}
releaseName: ${{ github.ref_name }}
releaseBody: |
## ${{ github.ref_name }}
### 本次更新
- **模型数据同步(models.dev 2026-08-27)**:7343 个模型 / 203 个供应商
- **新增 GLM-5.3 / GLM-5.3-Flash 全线接入**:智谱官方、OpenRouter、Cloudflare、DeepInfra、HuggingFace、火山引擎等约 20 条渠道;GLM-5.3-Flash 定价 $0.075 / $0.25(输入/输出,每百万 token)
- 新增 coding plan 渠道:`zhipuai-coding-plan/glm-5.3`、`glm-5.3-highspeed`、`glm-5.3-flash`
- 新增 Qwen3.8 系列、火山引擎豆包 Seed 2.x 全系、DeepSeek-V4 GA 版、MiniMax-M2.7/M3 等共 74 个模型条目
- 价格更新 58 处、能力信息修正 56 处(详见 release-notes-v0.7.9.md)
### Downloads by platform
- **Windows**: `.msi` installer
- **macOS**: `.dmg` + `.app`(未签名,仅 Apple Silicon / M 系列芯片)
- **Linux**: `.deb` / `.AppImage` / `.rpm`
### macOS 安装说明(无开发者账号签名,需一次手动绕过)
1. 下载 `Kimi.Switch_*.dmg`,双击挂载后把 `Kimi Switch.app` 拖入「应用程序」文件夹
2. 下载本 Release 附带的 `install-macos.sh`,在终端运行:
```bash
bash install-macos.sh
```
脚本会自动清除「下载隔离」属性并启动应用,之后可正常使用。
3. 手动替代方案:右键 `Kimi Switch.app` → 打开 → 弹窗中点「打开」(或 系统设置 → 隐私与安全性 → 仍要打开)
Full changelog: see commit history.
releaseBody: ${{ steps.notes.outputs.body }}
prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') }}
overwrite: true
args: ${{ matrix.args }}
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "kimiswitch",
"private": true,
"version": "0.7.14",
"version": "0.7.15",
"type": "module",
"scripts": {
"dev": "vite",
+81007 -77499
View File
File diff suppressed because it is too large. Load diff
+16
View File
@@ -0,0 +1,16 @@
# KimiSwitch v0.7.15
## 新功能
- **用量统计新增「昨天」选项卡**:时间范围现为 今天 / 昨天 / 7 天 / 30 天 / 全部,「昨天」按本地时区严格统计昨日 0 点至今日 0 点(不渗入今天),顶部概览卡同步扩展为 5 张
- **新增「模型用量统计」趋势选项卡**:在「供应商模型用量趋势」之后,不按天、跨供应商按模型名汇总(同一模型经不同供应商合并为一行),横向条形图按 Token 降序,悬停显示请求数 / Token / 缓存命中 / 费用;子代理模型仍单独成行
## 修复
- **opencode Go 套餐子代理请求 400**:Go 网关(opencode.ai/zen/go)近期强制要求 `x-opencode-session` 请求头用于路由与提示词缓存,缺失即 400 拒绝。现在导出配置时,凡指向 Go 端点的供应商会自动补写 `custom_headers.x-opencode-session`(已有用户自定义值保留不覆盖);按量计费的 `zen/v1` 端点不受影响
- 定价测试基准条目更新:models.dev 上游下架 `moonshotai/kimi-k2.5` 官方条目,测试基准切换到 `moonshotai/kimi-k3`
## 数据
- models-dev 快照同步至 2026-09-09(7583 模型 / 213 供应商),并补齐 `public/` 前端静态目录(原停留在 08-27)
- 注意:k2.5 官方定价条目下架后,`kimi/k2.5` 费用估算暂解析到 302ai 转售价格(0.66 / 3.3),略高于原官方价
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "kimiswitch"
version = "0.7.14"
version = "0.7.15"
description = "Kimi Switch - model config manager"
authors = ["codingplan.site"]
edition = "2021"
+146 -21
View File
@@ -102,6 +102,9 @@ pub struct RangeStats {
pub totals: TotalsRow,
pub daily: Vec<DailyRow>,
pub models: Vec<ModelRow>,
/// Model totals keyed by bare model name (provider prefix stripped), so the
/// same model served by multiple providers merges into one row.
pub models_by_name: Vec<ModelRow>,
pub recent: Vec<RecentRow>,
pub recent_total: usize,
pub recent_limit: usize,
@@ -976,6 +979,7 @@ fn aggregate(records: &[UsageRecord], range: &str, now_ms: u64) -> RangeStats {
totals: TotalsRow::default(),
daily: vec![],
models: vec![],
models_by_name: vec![],
recent: vec![],
recent_total: 0,
recent_limit: 500,
@@ -985,6 +989,7 @@ fn aggregate(records: &[UsageRecord], range: &str, now_ms: u64) -> RangeStats {
let mut totals = TotalsRow::default();
let mut by_day: HashMap<String, (TotalsRow, HashMap<String, TotalsRow>, HashMap<String, HashMap<String, u64>>)> = HashMap::new();
let mut by_model: HashMap<String, (ModelRow, TotalsRow)> = HashMap::new();
let mut by_name: HashMap<String, (ModelRow, TotalsRow)> = HashMap::new();
for r in &filtered {
totals.add(r);
@@ -1017,6 +1022,28 @@ fn aggregate(records: &[UsageRecord], range: &str, now_ms: u64) -> RangeStats {
entry.1.add(r);
entry.0.cost_estimated = entry.0.cost_estimated || r.cost_estimated;
entry.0.is_secondary = entry.0.is_secondary || r.is_secondary;
// Provider-agnostic bucket: secondary (subagent) records keep the
// stable "__secondary__" marker; everything else keys on the bare
// model name so the same model across providers merges into one row.
let nk = if r.is_secondary { "__secondary__".to_string() } else { r.model_resolved.clone() };
let name_entry = by_name.entry(nk.clone()).or_insert_with(|| {
let m = ModelRow {
model: nk.clone(),
model_display: nk.clone(),
model_resolved: nk.clone(),
price_id: r.price_id.clone(),
cost_estimated: r.cost_estimated,
is_secondary: r.is_secondary,
requests: 0, input_other: 0, output: 0,
input_cache_read: 0, input_cache_creation: 0,
cost_usd: 0.0, total_tokens: 0, cache_hit_rate: 0.0,
};
(m, TotalsRow::default())
});
name_entry.1.add(r);
name_entry.0.cost_estimated = name_entry.0.cost_estimated || r.cost_estimated;
name_entry.0.is_secondary = name_entry.0.is_secondary || r.is_secondary;
}
let total_input = totals.input_other + totals.input_cache_read + totals.input_cache_creation;
@@ -1063,6 +1090,17 @@ fn aggregate(records: &[UsageRecord], range: &str, now_ms: u64) -> RangeStats {
}).collect();
models.sort_by(|a, b| b.total_tokens.cmp(&a.total_tokens));
let mut models_by_name: Vec<ModelRow> = by_name.into_iter().map(|(_, (mut m, t))| {
let ti = t.input_other + t.input_cache_read + t.input_cache_creation;
m.cache_hit_rate = if ti > 0 { t.input_cache_read as f64 / ti as f64 } else { 0.0 };
m.requests = t.requests;
m.input_other = t.input_other; m.output = t.output;
m.input_cache_read = t.input_cache_read; m.input_cache_creation = t.input_cache_creation;
m.cost_usd = t.cost_usd; m.total_tokens = t.total_tokens;
m
}).collect();
models_by_name.sort_by(|a, b| b.total_tokens.cmp(&a.total_tokens));
let recent_total = filtered.len();
let recent_limit = 500;
let recent: Vec<RecentRow> = filtered.iter().take(recent_limit).map(|r| RecentRow {
@@ -1081,6 +1119,7 @@ fn aggregate(records: &[UsageRecord], range: &str, now_ms: u64) -> RangeStats {
totals,
daily,
models,
models_by_name,
recent,
recent_total,
recent_limit,
@@ -1109,24 +1148,40 @@ impl TotalsRow {
fn filter_by_range<'a>(records: &'a [UsageRecord], range: &str, now_ms: u64) -> Vec<&'a UsageRecord> {
if range == "all" { return records.iter().collect(); }
let start = range_start(range, now_ms);
records.iter().filter(|r| r.time >= start).collect()
match range_end(range, now_ms) {
Some(end) => records.iter().filter(|r| r.time >= start && r.time < end).collect(),
None => records.iter().filter(|r| r.time >= start).collect(),
}
}
/// Upper bound (exclusive) for bounded ranges. Only "yesterday" has one —
/// it must not bleed into today.
fn range_end(range: &str, now_ms: u64) -> Option<u64> {
match range {
"yesterday" => Some(local_midnight_ms(now_ms, 0)),
_ => None,
}
}
/// LOCAL midnight `days_ago` days before today, in epoch ms. Not UTC midnight:
/// without local-midnight anchoring, users east of UTC see day boundaries at
/// the wrong hour (e.g. UTC+8 users get cutoff at local 08:00).
fn local_midnight_ms(now_ms: u64, days_ago: i64) -> u64 {
let now_utc = DateTime::from_timestamp((now_ms / 1000) as i64, 0).unwrap_or_default();
let now_local = now_utc.with_timezone(&Local);
let date = now_local.date_naive() - chrono::Duration::days(days_ago);
let day_start = date.and_hms_opt(0, 0, 0).unwrap_or_default();
Local
.from_local_datetime(&day_start)
.single()
.map(|dt| dt.timestamp() as u64 * 1000)
.unwrap_or_else(|| day_start.and_utc().timestamp() as u64 * 1000)
}
fn range_start(range: &str, now_ms: u64) -> u64 {
match range {
"today" => {
// LOCAL midnight today — not UTC midnight. Without this, users east of UTC see
// "today" begin at the wrong hour (e.g. UTC+8 users get cutoff at local 08:00).
let now_utc = DateTime::from_timestamp((now_ms / 1000) as i64, 0).unwrap_or_default();
let now_local = now_utc.with_timezone(&Local);
let today_date = now_local.date_naive();
let today_start = today_date.and_hms_opt(0, 0, 0).unwrap_or_default();
Local
.from_local_datetime(&today_start)
.single()
.map(|dt| dt.timestamp() as u64 * 1000)
.unwrap_or_else(|| today_start.and_utc().timestamp() as u64 * 1000)
}
"today" => local_midnight_ms(now_ms, 0),
"yesterday" => local_midnight_ms(now_ms, 1),
"7d" => now_ms - 7 * 24 * 3600 * 1000,
"30d" => now_ms - 30 * 24 * 3600 * 1000,
_ => now_ms - 30 * 24 * 3600 * 1000,
@@ -1836,7 +1891,7 @@ pub fn get_summary(home_override: Option<String>, range: Option<String>, refresh
let all_model_count = all_models.len();
let mut range_totals = HashMap::new();
for r_k in ["today", "7d", "30d", "all"] {
for r_k in ["today", "yesterday", "7d", "30d", "all"] {
let s = aggregate(&records, r_k, now_ms);
range_totals.insert(r_k.to_string(), s.totals);
}
@@ -1977,10 +2032,10 @@ mod pricing_tests {
let idx = models_dev_cost_index();
// The compiled-in snapshot must carry real models.dev prices.
assert!(idx.len() > 1000, "expected >1000 priced models, got {}", idx.len());
let kimi = idx.get("moonshotai/kimi-k2.5").copied().expect("kimi-k2.5 present");
assert_eq!(kimi.input, 0.6);
assert_eq!(kimi.output, 3.0);
assert_eq!(kimi.cache_read, 0.1);
let kimi = idx.get("moonshotai/kimi-k3").copied().expect("kimi-k3 present");
assert_eq!(kimi.input, 3.0);
assert_eq!(kimi.output, 15.0);
assert_eq!(kimi.cache_read, 0.3);
}
#[test]
@@ -1992,9 +2047,9 @@ mod pricing_tests {
assert_eq!(input, 0.6);
assert_eq!(output, 2.2);
let (id, _, _, _, est) = match_price("kimi/k2.5");
let (id, _, _, _, est) = match_price("kimi/k3");
assert!(!est);
assert_eq!(id, "moonshotai/kimi-k2.5");
assert_eq!(id, "moonshotai/kimi-k3");
}
#[test]
@@ -2307,3 +2362,73 @@ mod session_tests {
assert!(list_sessions_cmd(&home, "all", None).sessions.is_empty());
}
}
#[cfg(test)]
mod range_and_model_totals_tests {
use super::*;
fn rec(time: u64, model: &str, resolved: &str, secondary: bool) -> UsageRecord {
UsageRecord {
time,
model: model.to_string(),
input_other: 100,
output: 50,
input_cache_read: 50,
input_cache_creation: 0,
cost_usd: 0.01,
cost_estimated: false,
price_id: String::new(),
model_resolved: resolved.to_string(),
model_display: model.to_string(),
provider: None,
from_env: false,
is_secondary: secondary,
}
}
#[test]
fn yesterday_range_is_bounded_to_yesterday() {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH).unwrap().as_millis() as u64;
let today_start = local_midnight_ms(now, 0);
let yesterday_start = local_midnight_ms(now, 1);
assert!(yesterday_start < today_start, "yesterday midnight precedes today's");
assert_eq!(range_end("yesterday", now), Some(today_start));
assert_eq!(range_end("today", now), None);
assert_eq!(range_end("7d", now), None);
let records = vec![
rec(yesterday_start + 1, "a/m1", "m1", false), // yesterday → in
rec(today_start + 1, "a/m1", "m1", false), // today → out
rec(yesterday_start.saturating_sub(1), "a/m1", "m1", false), // before → out
];
let stats = aggregate(&records, "yesterday", now);
assert_eq!(stats.totals.requests, 1, "only yesterday's record counts");
}
#[test]
fn models_by_name_merges_providers_and_keeps_secondary() {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH).unwrap().as_millis() as u64;
let records = vec![
rec(now, "openai/gpt-x", "gpt-x", false),
rec(now, "azure/gpt-x", "gpt-x", false),
rec(now, "__secondary__", "__secondary__", true),
];
let stats = aggregate(&records, "all", now);
// by_model keeps provider-qualified rows separate
assert_eq!(stats.models.len(), 3);
// by_name merges the two gpt-x rows, subagent stays its own row
assert_eq!(stats.models_by_name.len(), 2);
let gptx = stats.models_by_name.iter().find(|m| m.model == "gpt-x").expect("merged gpt-x row");
assert_eq!(gptx.requests, 2);
assert_eq!(gptx.total_tokens, 2 * 200);
let sub = stats.models_by_name.iter().find(|m| m.model == "__secondary__").expect("secondary row");
assert!(sub.is_secondary);
// sorted by total_tokens desc — every record has equal tokens here, so
// just assert the set is complete and totals add up.
let total: u64 = stats.models_by_name.iter().map(|m| m.total_tokens).sum();
assert_eq!(total, 3 * 200);
}
}
+89
View File
@@ -236,6 +236,30 @@ pub fn kimi_code_to_config(value: &TomlValue) -> Config {
}
}
/// opencode Console Go (the "Go 套餐" gateway) rejects requests that lack an
/// `x-opencode-session` header (400: required for routing and prompt-cache
/// affinity). When exporting a provider pointing at the Go endpoint, ensure
/// the header exists; an existing user-set value is kept as-is.
fn ensure_opencode_go_session_header(provider: &Provider, pt: &mut Table) {
let is_go = provider
.base_url
.as_deref()
.map(|u| u.trim_end_matches('/').starts_with("https://opencode.ai/zen/go"))
.unwrap_or(false);
if !is_go {
return;
}
let mut headers = pt
.get("custom_headers")
.and_then(|v| v.as_table())
.cloned()
.unwrap_or_default();
headers
.entry("x-opencode-session".to_string())
.or_insert_with(|| TomlValue::String("kimi-switch".to_string()));
pt.insert("custom_headers".to_string(), TomlValue::Table(headers));
}
/// Export Kimi Switch's internal `Config` to a Kimi Code TOML config value.
///
/// If `existing` is provided, unknown top-level sections (e.g. `services`) are
@@ -316,6 +340,7 @@ pub fn config_to_kimi_code(config: &Config, existing: Option<&TomlValue>) -> Tom
pt.insert(k, v);
}
}
ensure_opencode_go_session_header(provider, &mut pt);
providers_table.insert(name.clone(), TomlValue::Table(pt));
}
root.insert("providers".to_string(), TomlValue::Table(providers_table));
@@ -591,6 +616,70 @@ api_key = ""
assert!(caps.iter().any(|v| v.as_str() == Some("thinking")));
}
#[test]
fn kimi_code_export_adds_opencode_go_session_header() {
let make_provider = |base_url: &str, raw_other: Value| Provider {
name: "p".to_string(),
provider_type: ProviderType::Openai,
base_url: Some(base_url.to_string()),
api_key: Some("sk-test".to_string()),
env: IndexMap::new(),
note: None,
official_url: None,
managed: false,
enabled: true,
active: false,
icon: None,
icon_color: None,
raw_other,
usage_kinds: None,
usage_config: None,
};
let export = |p: Provider| {
let mut providers = IndexMap::new();
providers.insert("p".to_string(), p);
let config = Config {
default_model: None,
providers,
models: IndexMap::new(),
raw_other: Value::Null,
imported_section_keys: Vec::new(),
};
let exported = config_to_kimi_code(&config, None);
let root = exported.as_table().unwrap().clone();
root.get("providers")
.and_then(|v| v.as_table())
.and_then(|t| t.get("p"))
.and_then(|v| v.as_table().cloned())
.unwrap()
};
// Go endpoint without headers → header injected.
let p = export(make_provider("https://opencode.ai/zen/go/v1", Value::Null));
let headers = p.get("custom_headers").unwrap().as_table().unwrap();
assert_eq!(
headers.get("x-opencode-session").and_then(|v| v.as_str()),
Some("kimi-switch")
);
// Existing user-set value is preserved, not overwritten.
let raw = serde_json::json!({
"custom_headers": { "x-opencode-session": "my-session" }
});
let p = export(make_provider("https://opencode.ai/zen/go/v1", raw));
let headers = p.get("custom_headers").unwrap().as_table().unwrap();
assert_eq!(
headers.get("x-opencode-session").and_then(|v| v.as_str()),
Some("my-session")
);
// PAYG zen endpoint and unrelated providers are left alone.
let p = export(make_provider("https://opencode.ai/zen/v1", Value::Null));
assert!(p.get("custom_headers").is_none());
let p = export(make_provider("https://api.deepseek.com/v1", Value::Null));
assert!(p.get("custom_headers").is_none());
}
#[test]
fn kimi_code_export_syncs_raw_other_top_level_sections() {
// Regression: UI-managed top-level sections ([thinking],
+1 -1
View File
@@ -1,6 +1,6 @@
{
"productName": "Kimi Switch",
"version": "0.7.14",
"version": "0.7.15",
"identifier": "com.kimiswitch.app",
"build": {
"beforeDevCommand": "npm run dev",
+25 -6
View File
@@ -8,10 +8,11 @@ import { fmtInt, fmtPct, fmtTime, fmtTokens } from "../../lib/dashboard-format";
import { DailyBars } from "./DailyBars";
import { DailyDetailModal } from "./DailyDetailModal";
import { Heatmap } from "./Heatmap";
import { ModelTotalsChart } from "./ModelTotalsChart";
import { TrendLineChart } from "./TrendLineChart";
import type { DailyRow, HeatmapCell } from "../../types/dashboard";
const RANGES: DashboardRange[] = ["today", "7d", "30d", "all"];
const RANGES: DashboardRange[] = ["today", "yesterday", "7d", "30d", "all"];
/** Per-request cache hit rate: cached tokens / total input tokens. */
function cacheHitOf(r: { inputOther: number; inputCacheRead: number }): number {
@@ -59,13 +60,14 @@ export function DashboardPage() {
const { range, changeRange, data, loading, error, refresh, loadStats } = useDashboard();
const [showAllModels, setShowAllModels] = useState(false);
const [recentPage, setRecentPage] = useState(1);
const [trendTab, setTrendTab] = useState<"daily" | "model" | "provider">("daily");
const [trendTab, setTrendTab] = useState<"daily" | "model" | "provider" | "totals">("daily");
const [heatmapSelected, setHeatmapSelected] = useState<DailyRow | null>(null);
const daily = data?.stats.daily ?? [];
const RANGE_LABELS: Record<DashboardRange, string> = {
today: t("rangeToday"),
yesterday: t("rangeYesterday"),
"7d": t("range7d"),
"30d": t("range30d"),
all: t("rangeAll"),
@@ -192,7 +194,7 @@ export function DashboardPage() {
</div>
{/* Range overview cards */}
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-5">
{RANGES.map((r) => {
const tot = rangeTotals[r];
if (!tot) return null;
@@ -272,13 +274,26 @@ export function DashboardPage() {
>
{t("tabProviderTrend")}
</button>
<button
type="button"
onClick={() => setTrendTab("totals")}
className={`px-3 py-2 -mb-px border-b-2 text-sm font-medium transition-colors ${
trendTab === "totals"
? "border-blue-500 text-content-primary"
: "border-transparent text-content-muted hover:text-content-primary"
}`}
>
{t("tabModelTotals")}
</button>
</div>
<span className="pb-2 text-xs text-content-muted">
{trendTab === "daily"
? t("trendLineSub", { n: trendDaily.length })
: daily.length > 30
? t("cardDailyTrendSubCapped", { n: daily.length })
: t("cardDailyTrendSub", { n: daily.length })}
: trendTab === "totals"
? t("cardModelUsageSub", { n: data.stats.modelsByName.length })
: daily.length > 30
? t("cardDailyTrendSubCapped", { n: daily.length })
: t("cardDailyTrendSub", { n: daily.length })}
</span>
</div>
{/* Active tab content */}
@@ -287,6 +302,10 @@ export function DashboardPage() {
<div className="flex-1 min-h-[240px]">
<TrendLineChart daily={trendDaily} />
</div>
) : trendTab === "totals" ? (
<div className="flex-1 min-h-[240px]">
<ModelTotalsChart rows={data.stats.modelsByName} />
</div>
) : (
<div className="flex-1 min-h-[240px]">
<DailyBars
@@ -0,0 +1,73 @@
import { useTranslation } from "../../i18n";
import { useCurrency } from "../../hooks/useCurrency";
import { fmtInt, fmtPct, fmtTokens } from "../../lib/dashboard-format";
import { modelColor } from "./DailyBars";
import type { ModelRow } from "../../types/dashboard";
interface ModelTotalsChartProps {
/** Provider-agnostic model totals, pre-sorted by totalTokens desc. */
rows: ModelRow[];
}
/** Horizontal ranked bars: one row per bare model name, providers merged. */
export function ModelTotalsChart({ rows }: ModelTotalsChartProps) {
const { t } = useTranslation();
const { money } = useCurrency();
if (!rows.length) {
return (
<div className="flex h-48 items-center justify-center text-sm text-content-muted">
{t("noData")}
</div>
);
}
const max = Math.max(...rows.map((m) => m.totalTokens || 0), 1);
return (
<div className="flex h-full flex-col gap-1 overflow-y-auto">
{rows.map((m, i) => {
const color = i < 10 ? modelColor(i) : "#6b7280";
const name = m.isSecondary ? t("subagentModel") : m.modelDisplay || m.model;
const tooltip = [
name,
`${t("kpiRequests")}: ${fmtInt(m.requests)}`,
`${t("totalTokens")}: ${fmtInt(m.totalTokens)}`,
`${t("colCacheHit")}: ${fmtPct(m.cacheHitRate)}`,
`${t("cost")}: ${money(m.costUsd)}`,
].join("\n");
return (
<div
key={m.model}
title={tooltip}
className="group flex items-center gap-2 rounded px-1 py-1 cursor-help hover:bg-hover"
>
<span
className="inline-block h-2.5 w-2.5 rounded-sm shrink-0"
style={{ backgroundColor: color }}
/>
<span className="w-40 shrink-0 truncate text-xs text-content-primary">
{name}
{m.costEstimated && (
<span className="ml-1 text-[10px] text-yellow-600">({t("estimate")})</span>
)}
</span>
<div className="flex h-4 flex-1 items-center overflow-hidden rounded-sm bg-hover-2/50">
<div
className="h-full rounded-sm transition-[width] group-hover:opacity-85"
style={{
width: `${Math.max(2, (m.totalTokens / max) * 100)}%`,
backgroundColor: color,
}}
/>
</div>
<span className="w-16 shrink-0 text-right text-xs text-content-muted">
{fmtTokens(m.totalTokens)}
</span>
</div>
);
})}
</div>
);
}
+2 -2
View File
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from "react";
import { invoke } from "@tauri-apps/api/core";
import type { SummaryResult } from "../types/dashboard";
export type DashboardRange = "today" | "7d" | "30d" | "all";
export type DashboardRange = "today" | "yesterday" | "7d" | "30d" | "all";
const RANGE_STORAGE_KEY = "kimi-switch-dashboard-range";
@@ -10,7 +10,7 @@ export function useDashboard() {
const [range, setRange] = useState<DashboardRange>(() => {
try {
const stored = localStorage.getItem(RANGE_STORAGE_KEY) as DashboardRange | null;
if (stored === "today" || stored === "7d" || stored === "30d" || stored === "all") {
if (stored === "today" || stored === "yesterday" || stored === "7d" || stored === "30d" || stored === "all") {
return stored;
}
} catch {
+2
View File
@@ -288,6 +288,7 @@ export const enTranslations: Record<TranslationKey, string> = {
// Dashboard — ranges / status
rangeToday: "Today",
rangeYesterday: "Yesterday",
range7d: "7d",
range30d: "30d",
rangeAll: "All",
@@ -309,6 +310,7 @@ export const enTranslations: Record<TranslationKey, string> = {
cardDailyTrendSubCapped: "Last 30 days · {n} days total",
tabModelTrend: "Model usage trend",
tabProviderTrend: "Provider–model usage trend",
tabModelTotals: "Model usage totals",
tabDailyTrend: "Daily usage trend",
providerUnknown: "Unknown provider",
cardDailyTrendSub: "{n} days",
+2
View File
@@ -283,6 +283,7 @@ export const zhTranslations = {
// Dashboard — ranges / status
rangeToday: "今天",
rangeYesterday: "昨天",
range7d: "7 天",
range30d: "30 天",
rangeAll: "全部",
@@ -304,6 +305,7 @@ export const zhTranslations = {
cardDailyTrendSubCapped: "近 30 天 · 共 {n} 天",
tabModelTrend: "模型用量趋势",
tabProviderTrend: "供应商模型用量趋势",
tabModelTotals: "模型用量统计",
tabDailyTrend: "每日用量趋势",
providerUnknown: "未知供应商",
cardDailyTrendSub: "共 {n} 天",
+1740 -1280
View File
File diff suppressed because it is too large. Load diff
+1444 -1042
View File
File diff suppressed because it is too large. Load diff
+2
View File
@@ -52,6 +52,8 @@ export interface RangeStats {
totals: TotalsRow;
daily: DailyRow[];
models: ModelRow[];
/** Model totals keyed by bare model name — the same model across providers merges into one row. */
modelsByName: ModelRow[];
recent: RecentRow[];
recentTotal: number;
recentLimit: number;