dsh-pulse-overview 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +376 -2
- package/README_EN.md +289 -0
- package/assets/icon-180.png +0 -0
- package/assets/icon.svg +14 -0
- package/client/index.mjs +1675 -0
- package/cordis.patch.yml +3 -0
- package/index.mjs +427 -0
- package/lib/activity.mjs +234 -0
- package/lib/books.mjs +215 -0
- package/lib/config.mjs +93 -0
- package/lib/overview.mjs +311 -0
- package/lib/sessions.mjs +150 -0
- package/lib/token-index.mjs +669 -0
- package/lib/zstd-frames.mjs +98 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +70 -4
- package/scripts/check-npm-token.mjs +69 -0
- package/scripts/lib/skip-report.mjs +46 -0
- package/scripts/render-preview.py +355 -0
- package/scripts/verify-activity.mjs +439 -0
- package/scripts/verify-books.mjs +245 -0
- package/scripts/verify-client.mjs +569 -0
- package/scripts/verify-config.mjs +214 -0
- package/scripts/verify-host.mjs +372 -0
- package/scripts/verify-overview.mjs +395 -0
- package/scripts/verify-placement.mjs +436 -0
- package/scripts/verify-render.mjs +726 -0
- package/scripts/verify-token-index.mjs +559 -0
package/client/index.mjs
ADDED
|
@@ -0,0 +1,1675 @@
|
|
|
1
|
+
// client/index.mjs — dsh-pulse Web UI 插件
|
|
2
|
+
//
|
|
3
|
+
// 两个界面位置:
|
|
4
|
+
// 1. 会话欢迎页(空态)的「探索未至之境」标题下方,渲染「最近一年」的
|
|
5
|
+
// 53 × 7 方块热力图,可在「会话 / Token」两个指标间切换;
|
|
6
|
+
// 2. settings.section —— 设置页的「活跃度」分组,一个开关 + 默认指标选择。
|
|
7
|
+
//
|
|
8
|
+
// 纯 JS + React jsx-runtime 手写(不依赖 JSX 构建),与 dsh-soul 保持同一套写法:
|
|
9
|
+
// - 宿主用 React 17+ 的 jsx-runtime,children 必须在 props 里,不能当第三个参数;
|
|
10
|
+
// - 文案走 ctx.locale.register 的 8 份词典,槽位声明 locale 后由渲染器注入 t;
|
|
11
|
+
// - 组件拿到的是**位置参数**形式的 sessionId(scope:'session' 的 inject 契约),
|
|
12
|
+
// 不是 props 对象 —— 这里不需要会话 id,但 inject 签名不能按对象写。
|
|
13
|
+
//
|
|
14
|
+
// 开关关闭时**注销槽位**而不是隐藏:宿主按注册项生成 DOM,组件 return null 只会留下
|
|
15
|
+
// 一个仍被挂载、仍会发请求的空壳(更糟:热力图组件自己的 useEffect 照样会去拉数据)。
|
|
16
|
+
//
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// 视觉:为什么长这样
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// 宿主的 chrome 是**无色相**的:面板、卡片、边框、文字全部取自
|
|
21
|
+
// --dsw-alias-bg-* / border-* / label-* 这套灰阶,彩色只出现在表达状态的少数位置
|
|
22
|
+
// (dsh-tokenledger 的源码注释写得很直白:DSH's chrome is achromatic and the
|
|
23
|
+
// panel keeps it that way)。所以这里:
|
|
24
|
+
//
|
|
25
|
+
// - 卡片本体:--dsw-specific-input-major 底色 + --dsw-elevation-stroke 描边
|
|
26
|
+
// + --dsw-elevation-soft 投影 + --dsw-radius-panel 圆角 —— 与下方输入框
|
|
27
|
+
// (InputBar 的 .card)**完全同一套 token**,两者并排看不出是两套设计;
|
|
28
|
+
// - 0 档格子:--dsw-alias-bg-skeleton(宿主自己的骨架屏灰);
|
|
29
|
+
// - 1–4 档:DeepSeek 蓝(--dsw-static-deepseek-*)的透明度阶梯。
|
|
30
|
+
// 数据是这张卡里唯一该有颜色的东西,用品牌蓝而不是 Qoder 的绿,是为了让
|
|
31
|
+
// 「这是 DeepSeek Harness 的数据」成立。
|
|
32
|
+
//
|
|
33
|
+
// 之前那版用 --dsw-alias-state-success-primary(绿)做四档,绿色在宿主里是
|
|
34
|
+
// 「成功状态」的语义,一张 371 格的绿网格会让整个首页看起来在报成功事件;
|
|
35
|
+
// 换成品牌蓝之后,语义与观感都对齐了。
|
|
36
|
+
|
|
37
|
+
window.__ModuleLoader__.load({
|
|
38
|
+
id: 'dsh-pulse-overview',
|
|
39
|
+
factory: (require) => {
|
|
40
|
+
const module = { exports: {} }
|
|
41
|
+
const exports = module.exports
|
|
42
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
43
|
+
|
|
44
|
+
// jsx-runtime:官方 client bundle 使用 jsx/jsxs/Fragment。
|
|
45
|
+
// 用一个小包装 e() 让 children 写法保持直观,同时符合 jsx-runtime 约定。
|
|
46
|
+
const { jsx: h, jsxs: hs } = require('react/jsx-runtime')
|
|
47
|
+
const React = require('react')
|
|
48
|
+
|
|
49
|
+
// react-dom 的 createPortal:把热力图挂到标题下方。
|
|
50
|
+
//
|
|
51
|
+
// require 失败不能让插件崩:降级为「留在 conversation.hero.options 那一行」,
|
|
52
|
+
// 位置不理想但功能完整(见组件末尾的回退分支)。
|
|
53
|
+
let createPortal = null
|
|
54
|
+
try {
|
|
55
|
+
const reactDom = require('react-dom')
|
|
56
|
+
if (reactDom && typeof reactDom.createPortal === 'function') createPortal = reactDom.createPortal
|
|
57
|
+
} catch {
|
|
58
|
+
createPortal = null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const e = (type, props, ...children) => {
|
|
62
|
+
const p = props || {}
|
|
63
|
+
if (children.length === 0) return h(type, p)
|
|
64
|
+
if (children.length === 1) return h(type, { ...p, children: children[0] })
|
|
65
|
+
return hs(type, { ...p, children })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const NS = 'pulse'
|
|
69
|
+
const VERSION = '0.3.0'
|
|
70
|
+
// 与服务端默认值一致。改这里之前先想清楚:服务端也按 53 周聚合,传别的数字
|
|
71
|
+
// 只是换窗口长度,不是换布局。
|
|
72
|
+
const WEEKS = 53
|
|
73
|
+
|
|
74
|
+
const METRIC_SESSIONS = 'sessions'
|
|
75
|
+
const METRIC_TOKENS = 'tokens'
|
|
76
|
+
|
|
77
|
+
// 活动概览的时间范围选项(与 lib/overview.mjs 的 RANGE_VALUES 一致)。
|
|
78
|
+
// 0 是「全部」的哨兵值 —— 总 Token / 最长连续 / 活跃天数天然是全时段概念。
|
|
79
|
+
const OVERVIEW_RANGES = [0, 365, 30, 7]
|
|
80
|
+
const OVERVIEW_RANGE_DEFAULT = 0
|
|
81
|
+
|
|
82
|
+
// -------------------------------------------------------------------------
|
|
83
|
+
// 样式
|
|
84
|
+
// -------------------------------------------------------------------------
|
|
85
|
+
//
|
|
86
|
+
// 全部取主题 token,明暗主题自动适配;没有一个字面颜色值。
|
|
87
|
+
// 尺寸跟宿主对齐:卡片圆角用 --dsw-radius-panel(28px,与输入框一致)、
|
|
88
|
+
// 描边用 elevation 的 0.5px 发丝线、字阶用 13/12/11 三档。
|
|
89
|
+
const STYLE_ID = 'dsh-pulse-overview-style'
|
|
90
|
+
const CSS = `
|
|
91
|
+
.pulse-hero{position:relative;display:flex;justify-content:center;width:100%;max-width:100%;font:inherit;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary)}
|
|
92
|
+
.pulse-panel{box-sizing:border-box;display:flex;flex-direction:column;gap:10px;width:100%;max-width:100%;padding:14px 16px 12px;border-radius:var(--dsw-radius-lg);background:var(--dsw-specific-input-major,var(--dsw-alias-bg-layer-1));--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);box-shadow:var(--dsw-elevation-stroke),var(--dsw-shadow-lv1);overflow:hidden;transition:box-shadow var(--ds-transition-duration,ease)}
|
|
93
|
+
.pulse-panel:hover{box-shadow:var(--dsw-elevation-stroke),var(--dsw-shadow-lv2)}
|
|
94
|
+
.pulse-head{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:20px}
|
|
95
|
+
.pulse-head-main{display:flex;align-items:center;gap:8px;min-width:0}
|
|
96
|
+
.pulse-title{font-size:13px;line-height:20px;font-weight:500;color:var(--dsw-alias-label-primary);white-space:nowrap}
|
|
97
|
+
.pulse-head-right{display:flex;align-items:center;gap:10px;flex:none}
|
|
98
|
+
.pulse-total{font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary);white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
99
|
+
|
|
100
|
+
/* 指标切换:宿主的 segmented 观感 —— 一条极浅的轨道,选中项用面板底色浮起。
|
|
101
|
+
不用边框、不用阴影,靠底色差与字重区分,这是宿主 toggle 组件的做法。 */
|
|
102
|
+
.pulse-switch{display:inline-flex;align-items:center;gap:2px;padding:2px;border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-interactive-bg-hover)}
|
|
103
|
+
.pulse-switch-btn{appearance:none;-webkit-appearance:none;box-sizing:border-box;margin:0;padding:0 8px;height:20px;border:0;border-radius:var(--dsw-radius-xs);background:transparent;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;line-height:20px;font-weight:400;cursor:pointer;white-space:nowrap;transition:color var(--ds-transition-duration-fast,100ms) ease,background-color var(--ds-transition-duration-fast,100ms) ease}
|
|
104
|
+
.pulse-switch-btn:hover{color:var(--dsw-alias-label-secondary)}
|
|
105
|
+
.pulse-switch-btn[data-on="1"]{background:var(--dsw-specific-input-major,var(--dsw-alias-bg-layer-1));color:var(--dsw-alias-label-primary);font-weight:500;box-shadow:var(--dsw-shadow-lv1)}
|
|
106
|
+
.pulse-switch-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
107
|
+
|
|
108
|
+
/* 网格:列数按周数动态生成(gridTemplateColumns 由组件写行内样式)。
|
|
109
|
+
格子用 aspect-ratio 保持正方形,间距 3px —— 与 Qoder / GitHub 的密度一致,
|
|
110
|
+
再密就分不清相邻格子,再疏 371 格会撑出卡片。 */
|
|
111
|
+
.pulse-grid{display:grid;grid-auto-flow:column;grid-template-rows:repeat(7,minmax(0,1fr));gap:3px;width:100%}
|
|
112
|
+
.pulse-cell{display:block;width:100%;aspect-ratio:1;border-radius:2px;background:var(--dsw-alias-bg-skeleton);transition:transform var(--ds-transition-duration-fast,100ms) ease,outline-color var(--ds-transition-duration-fast,100ms) ease;outline:1px solid transparent;outline-offset:1px}
|
|
113
|
+
.pulse-cell:hover{position:relative;z-index:1;transform:scale(1.28);outline-color:var(--dsw-alias-label-caption)}
|
|
114
|
+
|
|
115
|
+
/* 四档强度:DeepSeek 蓝的透明度阶梯。
|
|
116
|
+
0 档是骨架灰(上面 .pulse-cell 的基础背景);1–4 档递进到实心品牌蓝。
|
|
117
|
+
用 color-mix 而不是写死 rgba,是为了让明暗主题各自取自己的蓝(暗色下
|
|
118
|
+
--dsw-static-deepseek-400 更亮),不必维护两套值。 */
|
|
119
|
+
.pulse-cell[data-level="1"]{background:color-mix(in srgb, var(--dsw-static-deepseek-500) 26%, transparent)}
|
|
120
|
+
.pulse-cell[data-level="2"]{background:color-mix(in srgb, var(--dsw-static-deepseek-500) 48%, transparent)}
|
|
121
|
+
.pulse-cell[data-level="3"]{background:color-mix(in srgb, var(--dsw-static-deepseek-500) 72%, transparent)}
|
|
122
|
+
.pulse-cell[data-level="4"]{background:var(--dsw-static-deepseek-500)}
|
|
123
|
+
.pulse-cell[data-future="1"]{opacity:0;pointer-events:none}
|
|
124
|
+
.pulse-skeleton .pulse-cell{opacity:.5}
|
|
125
|
+
|
|
126
|
+
/* 月份标签贴在网格下方,10px 灰字。列宽由 grid 自动分配,与格子列对齐。 */
|
|
127
|
+
.pulse-months{display:grid;gap:0 3px;height:12px;font-size:10px;line-height:12px;color:var(--dsw-alias-label-caption)}
|
|
128
|
+
.pulse-months span{white-space:nowrap}
|
|
129
|
+
|
|
130
|
+
/* 图例:少 ▢▢▣▣▣ 多。放在头部右侧,与总数同一行,不额外占高度。 */
|
|
131
|
+
.pulse-legend{display:flex;align-items:center;gap:3px;font-size:10px;line-height:16px;color:var(--dsw-alias-label-caption);white-space:nowrap}
|
|
132
|
+
.pulse-legend .pulse-cell{width:8px;height:8px;aspect-ratio:auto;flex:none;pointer-events:none;outline:0}
|
|
133
|
+
|
|
134
|
+
.pulse-note{display:flex;align-items:center;justify-content:center;flex:1;min-height:118px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);text-align:center}
|
|
135
|
+
.pulse-error{display:flex;align-items:center;justify-content:center;flex:1;min-height:118px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
|
|
136
|
+
|
|
137
|
+
/* 索引进度:token 视图第一次打开时数据还在补,这里给一行极轻的提示,
|
|
138
|
+
不阻塞网格显示(已有部分照常画出来)。 */
|
|
139
|
+
.pulse-progress{display:flex;align-items:center;gap:6px;font-size:10px;line-height:14px;color:var(--dsw-alias-label-caption);white-space:nowrap}
|
|
140
|
+
.pulse-progress-bar{position:relative;width:56px;height:2px;border-radius:1px;background:var(--dsw-alias-bg-skeleton);overflow:hidden}
|
|
141
|
+
.pulse-progress-fill{position:absolute;inset:0 auto 0 0;border-radius:1px;background:var(--dsw-static-deepseek-500);transition:width var(--ds-transition-duration,200ms) ease}
|
|
142
|
+
|
|
143
|
+
/* 浮层:hover 时显示日期 + 数值。
|
|
144
|
+
用 absolute 定位在卡片内部(不 portal 到 body):固定在 body 上的浮层会被某些
|
|
145
|
+
布局当成可滚动区域,hover 时冒出滚动条。 */
|
|
146
|
+
.pulse-tip{position:absolute;z-index:5;box-sizing:border-box;display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start;gap:10px;min-width:170px;max-width:280px;padding:8px 10px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-overlay,var(--dsw-specific-menu));box-shadow:var(--dsw-shadow-lv2);color:var(--dsw-alias-label-primary);font-size:12px;line-height:16px;pointer-events:none;transform:translate(-50%,-100%);margin-top:-8px}
|
|
147
|
+
.pulse-tip[data-below="1"]{transform:translate(-50%,0);margin-top:8px}
|
|
148
|
+
.pulse-tip-title{font-weight:500;font-variant-numeric:tabular-nums}
|
|
149
|
+
.pulse-tip-sub{margin-top:2px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary)}
|
|
150
|
+
.pulse-tip-value{font-family:var(--ds-font-family-code,Consolas,Menlo,monospace);font-size:12px;line-height:16px;font-weight:500;color:var(--dsw-alias-label-primary);white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
151
|
+
|
|
152
|
+
/* ---- 活动概览(overview)----
|
|
153
|
+
指标栅格:2 行 × 4 列(窄卡片自动降到 2 列)。底色不是纯色块,而是
|
|
154
|
+
「比卡片深一层」的 alias-bg-layer-2,这是宿主嵌套面板的层次做法;
|
|
155
|
+
选中/强调只用品牌蓝的 12% 底 + 蓝字(连续天数在续期时点亮)。 */
|
|
156
|
+
.pulse-ov-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px}
|
|
157
|
+
@media (max-width:720px){.pulse-ov-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
|
158
|
+
/* 说明行:12px 次级灰,与指标格之间留 8px —— 它交代「窗口与样本量」,
|
|
159
|
+
是读下面那张表的前提,所以放在表上方而不是塞进表头。 */
|
|
160
|
+
.pulse-ov-caption{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}
|
|
161
|
+
.pulse-ov-cell{box-sizing:border-box;display:flex;flex-direction:column;align-items:center;gap:3px;padding:12px 6px 10px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-skeleton));min-width:0}
|
|
162
|
+
.pulse-ov-label{font-size:11px;line-height:14px;color:var(--dsw-alias-label-tertiary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
|
|
163
|
+
.pulse-ov-value{font-size:17px;line-height:22px;font-weight:600;color:var(--dsw-alias-label-primary);white-space:nowrap;font-variant-numeric:tabular-nums;max-width:100%;overflow:hidden;text-overflow:ellipsis}
|
|
164
|
+
.pulse-ov-value[data-accent="1"]{color:var(--dsw-static-deepseek-500)}
|
|
165
|
+
/* 模型名是变长文本(实测 provider/model 最长 29 字符),17px 在 1/4 宽的格子里
|
|
166
|
+
只能显示十来个字符。降到 13px 并允许省略:宁可截断也要让前缀可读 ——
|
|
167
|
+
完整名字走 title,hover 能看到。 */
|
|
168
|
+
.pulse-ov-value[data-compact="1"]{font-size:13px;line-height:22px;font-weight:600;letter-spacing:-.1px}
|
|
169
|
+
.pulse-ov-unit{font-size:11px;line-height:14px;font-weight:400;color:var(--dsw-alias-label-secondary)}
|
|
170
|
+
.pulse-ov-sub{font-size:10px;line-height:13px;color:var(--dsw-alias-label-caption);white-space:nowrap;max-width:100%;overflow:hidden;text-overflow:ellipsis}
|
|
171
|
+
|
|
172
|
+
/* 24 小时火花线:24 根圆角小柱,0 点在最左;柱体用品牌蓝的透明度阶梯,
|
|
173
|
+
与热力图同一套色语 —— 数据是卡里唯一有颜色的东西。 */
|
|
174
|
+
.pulse-ov-spark{display:flex;align-items:flex-end;gap:2px;height:26px;padding:0 2px}
|
|
175
|
+
.pulse-ov-spark-bar{flex:1 1 0;min-width:1px;border-radius:1px 1px 0 0;background:color-mix(in srgb, var(--dsw-static-deepseek-500) 22%, transparent);min-height:1px}
|
|
176
|
+
.pulse-ov-spark-bar[data-peak="1"]{background:var(--dsw-static-deepseek-500)}
|
|
177
|
+
.pulse-ov-spark-meta{display:flex;justify-content:space-between;font-size:10px;line-height:13px;color:var(--dsw-alias-label-caption)}
|
|
178
|
+
|
|
179
|
+
/* 概览卡与热力图卡都挂在 _body 里:补一个 10px 的卡间距(与卡内 gap 一致);
|
|
180
|
+
单独开启任何一张时相邻选择器不命中,不会多出空隙。 */
|
|
181
|
+
.pulse-panel + .pulse-panel{margin-top:10px}
|
|
182
|
+
|
|
183
|
+
/* 页脚「上下文当量」:一行 11px 的浅灰小字,居中 —— 与热力图底部的月份条
|
|
184
|
+
保持同等的克制。 */
|
|
185
|
+
.pulse-ov-footnote{margin-top:2px;text-align:center;font-size:11px;line-height:16px;color:var(--dsw-alias-label-caption)}
|
|
186
|
+
|
|
187
|
+
/* ---- 设置页 ---- */
|
|
188
|
+
.pulse-section{display:flex;flex-direction:column;gap:10px;margin:24px 0}
|
|
189
|
+
.pulse-section-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px}
|
|
190
|
+
.pulse-section-title{font-size:15px;line-height:24px;font-weight:600;color:var(--dsw-alias-label-primary)}
|
|
191
|
+
.pulse-version{font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary)}
|
|
192
|
+
.pulse-card{display:flex;flex-direction:column;gap:12px;padding:14px 16px;border:.5px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-xl);background:var(--dsw-alias-settings-card-fill)}
|
|
193
|
+
.pulse-switch-row{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}
|
|
194
|
+
.pulse-switch-text{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
195
|
+
.pulse-switch-label{font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary)}
|
|
196
|
+
.pulse-switch-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
|
|
197
|
+
.pulse-toggle{display:inline-flex;flex:none;align-items:center;cursor:pointer}
|
|
198
|
+
.pulse-toggle input[type="checkbox"]{appearance:none;-webkit-appearance:none;box-sizing:border-box;flex:none;width:36px;height:20px;margin:0;border:.5px solid var(--dsw-alias-border-l2);border-radius:999px;background:color-mix(in srgb, var(--dsw-alias-label-secondary) 22%, transparent);position:relative;cursor:pointer;transition:background-color var(--ds-transition-duration-fast,100ms) ease,border-color var(--ds-transition-duration-fast,100ms) ease}
|
|
199
|
+
.pulse-toggle input[type="checkbox"]::after{content:"";position:absolute;top:1.5px;left:1.5px;box-sizing:border-box;width:16px;height:16px;border:.5px solid var(--dsw-alias-border-l2);border-radius:50%;background:var(--dsw-alias-label-primary);transition:transform var(--ds-transition-duration-fast,100ms) ease}
|
|
200
|
+
.pulse-toggle input[type="checkbox"]:checked{background:var(--dsw-static-deepseek-500);border-color:var(--dsw-static-deepseek-500)}
|
|
201
|
+
.pulse-toggle input[type="checkbox"]:checked::after{transform:translateX(16px);border-color:transparent}
|
|
202
|
+
.pulse-toggle input[type="checkbox"]:disabled{opacity:.5;cursor:default}
|
|
203
|
+
.pulse-metric-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding-top:10px;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
204
|
+
.pulse-metric-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
|
|
205
|
+
@media (prefers-reduced-motion:reduce){.pulse-cell,.pulse-panel,.pulse-switch-btn,.pulse-progress-fill,.pulse-ov-spark-bar{transition:none}}
|
|
206
|
+
`.trim()
|
|
207
|
+
|
|
208
|
+
// 样式只插一次。宿主有 document 才插 —— 纯 Node 的校验脚本里没有 document,
|
|
209
|
+
// apply 必须能在那种环境下跑完(否则 verify-client 就没法测槽位注册了)。
|
|
210
|
+
function injectStyles() {
|
|
211
|
+
if (typeof document === 'undefined' || !document || !document.head) return
|
|
212
|
+
try {
|
|
213
|
+
if (typeof document.getElementById === 'function' && document.getElementById(STYLE_ID)) return
|
|
214
|
+
const el = document.createElement('style')
|
|
215
|
+
el.id = STYLE_ID
|
|
216
|
+
el.textContent = CSS
|
|
217
|
+
document.head.appendChild(el)
|
|
218
|
+
} catch {
|
|
219
|
+
// 样式注入失败只影响外观,不该让整个客户端装配失败。
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// -------------------------------------------------------------------------
|
|
224
|
+
// 词典(8 份,键集必须完全一致 —— 由 scripts/verify-client.mjs 钉住)
|
|
225
|
+
// -------------------------------------------------------------------------
|
|
226
|
+
//
|
|
227
|
+
// 占位符必须逐字保留 `{date}` `{count}` `{tokens}`:fmt() 用字符串替换,
|
|
228
|
+
// 键名写错不会报错,只会让用户看到 `{tokens} tokens` 这样的原文。
|
|
229
|
+
|
|
230
|
+
const zh = {
|
|
231
|
+
'nav.label': '活跃度',
|
|
232
|
+
'section.title': '会话活跃度热力图',
|
|
233
|
+
'switch.label': '显示会话热力图',
|
|
234
|
+
'switch.hint': '在会话欢迎页显示最近一年每天的活跃度。关闭后不再注册界面、不发请求,也不扫描本地会话目录。',
|
|
235
|
+
'metric.label': '默认指标',
|
|
236
|
+
'metric.hint': '热力图默认显示哪个指标。Token 用量需要读取会话日志,首次切换时会后台建立索引。',
|
|
237
|
+
'metric.sessions': '会话',
|
|
238
|
+
'metric.tokens': 'Token',
|
|
239
|
+
'chart.title': '活跃度',
|
|
240
|
+
'chart.total.sessions': '{count} 个会话',
|
|
241
|
+
'chart.total.tokens': '{tokens} Token',
|
|
242
|
+
'chart.empty.sessions': '还没有会话记录',
|
|
243
|
+
'chart.empty.tokens': '还没有 Token 用量记录',
|
|
244
|
+
'chart.loading': '正在统计…',
|
|
245
|
+
'chart.error': '热力图加载失败',
|
|
246
|
+
'chart.indexing': '正在建立索引 {done}/{total}',
|
|
247
|
+
'chart.partial': 'Token 数据仍在补齐',
|
|
248
|
+
'cell.sessions': '{count} 个会话',
|
|
249
|
+
'cell.tokens': '{tokens} Token',
|
|
250
|
+
'legend.less': '少',
|
|
251
|
+
'legend.more': '多',
|
|
252
|
+
'overview.title': '活动概览',
|
|
253
|
+
'overview.stat.sessions': '会话数',
|
|
254
|
+
'overview.stat.messages': '消息数',
|
|
255
|
+
'overview.stat.tokens': '总 Token',
|
|
256
|
+
'overview.stat.activeDays': '活跃天数',
|
|
257
|
+
'overview.stat.currentStreak': '当前连续',
|
|
258
|
+
'overview.stat.longestStreak': '最长连续',
|
|
259
|
+
'overview.stat.peakHour': '活跃时段',
|
|
260
|
+
'overview.stat.topModel': '常用模型',
|
|
261
|
+
'overview.range.days': '{days} 天',
|
|
262
|
+
'overview.range.all': '全部',
|
|
263
|
+
'overview.caption.all': '全部 {sessions} 次会话',
|
|
264
|
+
'overview.span': '共 {days} 天',
|
|
265
|
+
'overview.caption': '最近 {days} 天 · {sessions} 次会话',
|
|
266
|
+
'overview.loading': '正在统计…',
|
|
267
|
+
'overview.error': '概览加载失败',
|
|
268
|
+
'overview.empty': '还没有活动记录',
|
|
269
|
+
'overview.streak.day': '天',
|
|
270
|
+
'overview.books': '≈ {count} 部{name}',
|
|
271
|
+
'overview.books.under': '不到 1 部{name}',
|
|
272
|
+
'overview.books.beyond': '超过 {count} 部{name}的体量',
|
|
273
|
+
'overview.books.title': '按新内容 {fresh} token 折算(不含重复读取的上下文)。含重复口径为 {total} token。',
|
|
274
|
+
'overview.spark.caption': '24 小时活跃分布(消息数)',
|
|
275
|
+
'overview.switch.label': '显示活动概览',
|
|
276
|
+
'overview.switch.hint': '在会话欢迎页显示会话数、消息数、Token 用量、连续天数等活动概览。关闭后不再注册界面、不发请求,也不扫描本地会话目录。',
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const en = {
|
|
280
|
+
'nav.label': 'Activity',
|
|
281
|
+
'section.title': 'Session activity heat map',
|
|
282
|
+
'switch.label': 'Show the session heat map',
|
|
283
|
+
'switch.hint': 'Shows how active each day was over the past year on the New Session screen. When off, the widget is not registered, no requests are sent, and the local session folder is not scanned.',
|
|
284
|
+
'metric.label': 'Default metric',
|
|
285
|
+
'metric.hint': 'Which metric the heat map shows first. Token usage reads session logs, so the first switch builds an index in the background.',
|
|
286
|
+
'metric.sessions': 'Sessions',
|
|
287
|
+
'metric.tokens': 'Tokens',
|
|
288
|
+
'chart.title': 'Activity',
|
|
289
|
+
'chart.total.sessions': '{count} sessions',
|
|
290
|
+
'chart.total.tokens': '{tokens} tokens',
|
|
291
|
+
'chart.empty.sessions': 'No sessions yet',
|
|
292
|
+
'chart.empty.tokens': 'No token usage yet',
|
|
293
|
+
'chart.loading': 'Counting…',
|
|
294
|
+
'chart.error': 'Could not load the heat map',
|
|
295
|
+
'chart.indexing': 'Building index {done}/{total}',
|
|
296
|
+
'chart.partial': 'Token data still filling in',
|
|
297
|
+
'cell.sessions': '{count} sessions',
|
|
298
|
+
'cell.tokens': '{tokens} tokens',
|
|
299
|
+
'legend.less': 'Less',
|
|
300
|
+
'legend.more': 'More',
|
|
301
|
+
'overview.title': 'Activity overview',
|
|
302
|
+
'overview.stat.sessions': 'Sessions',
|
|
303
|
+
'overview.stat.messages': 'Messages',
|
|
304
|
+
'overview.stat.tokens': 'Total tokens',
|
|
305
|
+
'overview.stat.activeDays': 'Active days',
|
|
306
|
+
'overview.stat.currentStreak': 'Current streak',
|
|
307
|
+
'overview.stat.longestStreak': 'Longest streak',
|
|
308
|
+
'overview.stat.peakHour': 'Peak hours',
|
|
309
|
+
'overview.stat.topModel': 'Top model',
|
|
310
|
+
'overview.range.days': '{days} days',
|
|
311
|
+
'overview.range.all': 'All',
|
|
312
|
+
'overview.caption.all': 'All {sessions} sessions',
|
|
313
|
+
'overview.span': '{days} days total',
|
|
314
|
+
'overview.caption': 'Last {days} days · {sessions} sessions',
|
|
315
|
+
'overview.loading': 'Counting…',
|
|
316
|
+
'overview.error': 'Could not load the overview',
|
|
317
|
+
'overview.empty': 'No activity yet',
|
|
318
|
+
'overview.streak.day': 'd',
|
|
319
|
+
'overview.books': '≈ {count} × {name}',
|
|
320
|
+
'overview.books.under': 'Less than one {name}',
|
|
321
|
+
'overview.books.beyond': 'More than {count} × {name}',
|
|
322
|
+
'overview.books.title': 'Based on {fresh} tokens of new content (repeated context reads excluded). Including repeats: {total} tokens.',
|
|
323
|
+
'overview.spark.caption': '24-hour activity (messages)',
|
|
324
|
+
'overview.switch.label': 'Show the activity overview',
|
|
325
|
+
'overview.switch.hint': 'Shows sessions, messages, token usage, streaks and more on the New Session screen. When off, the widget is not registered, no requests are sent, and the local session folder is not scanned.',
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const ru = {
|
|
329
|
+
'nav.label': 'Активность',
|
|
330
|
+
'section.title': 'Тепловая карта активности сессий',
|
|
331
|
+
'switch.label': 'Показывать тепловую карту сессий',
|
|
332
|
+
'switch.hint': 'На экране новой сессии показывает, насколько активным был каждый день за последний год. Если выключено, виджет не регистрируется, запросы не отправляются и локальный каталог сессий не сканируется.',
|
|
333
|
+
'metric.label': 'Показатель по умолчанию',
|
|
334
|
+
'metric.hint': 'Какой показатель карта показывает первой. Расход токенов читает журналы сессий, поэтому при первом переключении индекс строится в фоне.',
|
|
335
|
+
'metric.sessions': 'Сессии',
|
|
336
|
+
'metric.tokens': 'Токены',
|
|
337
|
+
'chart.title': 'Активность',
|
|
338
|
+
'chart.total.sessions': 'Сессий: {count}',
|
|
339
|
+
'chart.total.tokens': '{tokens} токенов',
|
|
340
|
+
'chart.empty.sessions': 'Сессий пока нет',
|
|
341
|
+
'chart.empty.tokens': 'Расхода токенов пока нет',
|
|
342
|
+
'chart.loading': 'Подсчёт…',
|
|
343
|
+
'chart.error': 'Не удалось загрузить тепловую карту',
|
|
344
|
+
'chart.indexing': 'Построение индекса {done}/{total}',
|
|
345
|
+
'chart.partial': 'Данные о токенах ещё пополняются',
|
|
346
|
+
'cell.sessions': 'Сессий: {count}',
|
|
347
|
+
'cell.tokens': 'Токенов: {tokens}',
|
|
348
|
+
'legend.less': 'Меньше',
|
|
349
|
+
'legend.more': 'Больше',
|
|
350
|
+
'overview.title': 'Обзор активности',
|
|
351
|
+
'overview.stat.sessions': 'Сессии',
|
|
352
|
+
'overview.stat.messages': 'Сообщения',
|
|
353
|
+
'overview.stat.tokens': 'Всего токенов',
|
|
354
|
+
'overview.stat.activeDays': 'Активные дни',
|
|
355
|
+
'overview.stat.currentStreak': 'Текущая серия',
|
|
356
|
+
'overview.stat.longestStreak': 'Лучшая серия',
|
|
357
|
+
'overview.stat.peakHour': 'Час пик',
|
|
358
|
+
'overview.stat.topModel': 'Частая модель',
|
|
359
|
+
'overview.range.days': '{days} дн.',
|
|
360
|
+
'overview.range.all': 'Всё время',
|
|
361
|
+
'overview.caption.all': 'Всего сессий: {sessions}',
|
|
362
|
+
'overview.span': 'всего {days} дн.',
|
|
363
|
+
'overview.caption': 'Последние {days} дн. · сессий: {sessions}',
|
|
364
|
+
'overview.loading': 'Подсчёт…',
|
|
365
|
+
'overview.error': 'Не удалось загрузить обзор',
|
|
366
|
+
'overview.empty': 'Активности пока нет',
|
|
367
|
+
'overview.streak.day': 'д',
|
|
368
|
+
'overview.books': '≈ {count} × {name}',
|
|
369
|
+
'overview.books.under': 'Меньше одного {name}',
|
|
370
|
+
'overview.books.beyond': 'Больше {count} × {name}',
|
|
371
|
+
'overview.books.title': 'По {fresh} токенам нового содержимого (без повторных чтений контекста). С повторами: {total}.',
|
|
372
|
+
'overview.spark.caption': 'Активность за 24 часа (сообщения)',
|
|
373
|
+
'overview.switch.label': 'Показывать обзор активности',
|
|
374
|
+
'overview.switch.hint': 'Показывает сессии, сообщения, расход токенов, серии и другое на экране новой сессии. Если выключено, виджет не регистрируется, запросы не отправляются и локальный каталог сессий не сканируется.',
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const ja = {
|
|
378
|
+
'nav.label': 'アクティビティ',
|
|
379
|
+
'section.title': 'セッションのアクティビティヒートマップ',
|
|
380
|
+
'switch.label': 'セッションのヒートマップを表示',
|
|
381
|
+
'switch.hint': '新しいセッションの画面に、過去1年で各日がどれだけ活発だったかを表示します。オフにするとウィジェットは登録されず、リクエストも送信されず、ローカルのセッションフォルダーも走査しません。',
|
|
382
|
+
'metric.label': '既定の指標',
|
|
383
|
+
'metric.hint': 'ヒートマップが最初に表示する指標です。トークン使用量はセッションログを読むため、初回の切り替え時にバックグラウンドで索引を構築します。',
|
|
384
|
+
'metric.sessions': 'セッション',
|
|
385
|
+
'metric.tokens': 'トークン',
|
|
386
|
+
'chart.title': 'アクティビティ',
|
|
387
|
+
'chart.total.sessions': 'セッション {count} 件',
|
|
388
|
+
'chart.total.tokens': '{tokens} トークン',
|
|
389
|
+
'chart.empty.sessions': 'まだセッションがありません',
|
|
390
|
+
'chart.empty.tokens': 'トークン使用量はまだありません',
|
|
391
|
+
'chart.loading': '集計中…',
|
|
392
|
+
'chart.error': 'ヒートマップを読み込めませんでした',
|
|
393
|
+
'chart.indexing': '索引を作成中 {done}/{total}',
|
|
394
|
+
'chart.partial': 'トークンデータを補完中です',
|
|
395
|
+
'cell.sessions': 'セッション {count} 件',
|
|
396
|
+
'cell.tokens': 'トークン {tokens}',
|
|
397
|
+
'legend.less': '少なめ',
|
|
398
|
+
'legend.more': '多め',
|
|
399
|
+
'overview.title': 'アクティビティ概要',
|
|
400
|
+
'overview.stat.sessions': 'セッション数',
|
|
401
|
+
'overview.stat.messages': 'メッセージ数',
|
|
402
|
+
'overview.stat.tokens': '合計トークン',
|
|
403
|
+
'overview.stat.activeDays': 'アクティブ日数',
|
|
404
|
+
'overview.stat.currentStreak': '現在の連続',
|
|
405
|
+
'overview.stat.longestStreak': '最長の連続',
|
|
406
|
+
'overview.stat.peakHour': 'ピーク時間帯',
|
|
407
|
+
'overview.stat.topModel': 'よく使うモデル',
|
|
408
|
+
'overview.range.days': '{days} 日',
|
|
409
|
+
'overview.range.all': '全期間',
|
|
410
|
+
'overview.caption.all': '全期間 {sessions} 件のセッション',
|
|
411
|
+
'overview.span': '計 {days} 日',
|
|
412
|
+
'overview.caption': '直近 {days} 日 · セッション {sessions} 件',
|
|
413
|
+
'overview.loading': '集計中…',
|
|
414
|
+
'overview.error': '概要を読み込めませんでした',
|
|
415
|
+
'overview.empty': 'アクティビティはまだありません',
|
|
416
|
+
'overview.streak.day': '日',
|
|
417
|
+
'overview.books': '≈ {count} 冊の{name}',
|
|
418
|
+
'overview.books.under': '{name} 1 冊未満',
|
|
419
|
+
'overview.books.beyond': '{count} 冊の{name}を超える量',
|
|
420
|
+
'overview.books.title': '新しい内容 {fresh} トークン換算(コンテキストの再読み込みを除く)。再読み込み込みでは {total} トークン。',
|
|
421
|
+
'overview.spark.caption': '24時間のアクティビティ(メッセージ数)',
|
|
422
|
+
'overview.switch.label': 'アクティビティ概要を表示',
|
|
423
|
+
'overview.switch.hint': '新しいセッションの画面にセッション数・メッセージ数・トークン使用量・連続日数などを表示します。オフにするとウィジェットは登録されず、リクエストも送信されず、ローカルのセッションフォルダーも走査しません。',
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const es = {
|
|
427
|
+
'nav.label': 'Actividad',
|
|
428
|
+
'section.title': 'Mapa de actividad de sesiones',
|
|
429
|
+
'switch.label': 'Mostrar el mapa de sesiones',
|
|
430
|
+
'switch.hint': 'Muestra cuán activo fue cada día durante el último año en la pantalla de sesión nueva. Si se desactiva, el widget no se registra, no se envían solicitudes y no se explora la carpeta local de sesiones.',
|
|
431
|
+
'metric.label': 'Métrica predeterminada',
|
|
432
|
+
'metric.hint': 'Qué métrica muestra primero el mapa. El uso de tokens lee los registros de sesión, así que el primer cambio crea un índice en segundo plano.',
|
|
433
|
+
'metric.sessions': 'Sesiones',
|
|
434
|
+
'metric.tokens': 'Tokens',
|
|
435
|
+
'chart.title': 'Actividad',
|
|
436
|
+
'chart.total.sessions': '{count} sesiones',
|
|
437
|
+
'chart.total.tokens': '{tokens} tokens',
|
|
438
|
+
'chart.empty.sessions': 'Todavía no hay sesiones',
|
|
439
|
+
'chart.empty.tokens': 'Todavía no hay uso de tokens',
|
|
440
|
+
'chart.loading': 'Contando…',
|
|
441
|
+
'chart.error': 'No se pudo cargar el mapa',
|
|
442
|
+
'chart.indexing': 'Creando índice {done}/{total}',
|
|
443
|
+
'chart.partial': 'Los datos de tokens aún se están completando',
|
|
444
|
+
'cell.sessions': '{count} sesiones',
|
|
445
|
+
'cell.tokens': '{tokens} tokens',
|
|
446
|
+
'legend.less': 'Menos',
|
|
447
|
+
'legend.more': 'Más',
|
|
448
|
+
'overview.title': 'Resumen de actividad',
|
|
449
|
+
'overview.stat.sessions': 'Sesiones',
|
|
450
|
+
'overview.stat.messages': 'Mensajes',
|
|
451
|
+
'overview.stat.tokens': 'Tokens totales',
|
|
452
|
+
'overview.stat.activeDays': 'Días activos',
|
|
453
|
+
'overview.stat.currentStreak': 'Racha actual',
|
|
454
|
+
'overview.stat.longestStreak': 'Racha más larga',
|
|
455
|
+
'overview.stat.peakHour': 'Hora punta',
|
|
456
|
+
'overview.stat.topModel': 'Modelo habitual',
|
|
457
|
+
'overview.range.days': '{days} días',
|
|
458
|
+
'overview.range.all': 'Todo',
|
|
459
|
+
'overview.caption.all': '{sessions} sesiones en total',
|
|
460
|
+
'overview.span': '{days} días en total',
|
|
461
|
+
'overview.caption': 'Últimos {days} días · {sessions} sesiones',
|
|
462
|
+
'overview.loading': 'Contando…',
|
|
463
|
+
'overview.error': 'No se pudo cargar el resumen',
|
|
464
|
+
'overview.empty': 'Todavía no hay actividad',
|
|
465
|
+
'overview.streak.day': 'd',
|
|
466
|
+
'overview.books': '≈ {count} × {name}',
|
|
467
|
+
'overview.books.under': 'Menos de un {name}',
|
|
468
|
+
'overview.books.beyond': 'Más de {count} × {name}',
|
|
469
|
+
'overview.books.title': 'Según {fresh} tokens de contenido nuevo (sin relecturas de contexto). Incluyendo repeticiones: {total} tokens.',
|
|
470
|
+
'overview.spark.caption': 'Actividad de 24 horas (mensajes)',
|
|
471
|
+
'overview.switch.label': 'Mostrar el resumen de actividad',
|
|
472
|
+
'overview.switch.hint': 'Muestra sesiones, mensajes, uso de tokens, rachas y más en la pantalla de sesión nueva. Si se desactiva, el widget no se registra, no se envían solicitudes y no se explora la carpeta local de sesiones.',
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const fr = {
|
|
476
|
+
'nav.label': 'Activité',
|
|
477
|
+
'section.title': 'Carte d’activité des sessions',
|
|
478
|
+
'switch.label': 'Afficher la carte des sessions',
|
|
479
|
+
'switch.hint': 'Affiche l’activité de chaque jour sur la dernière année, sur l’écran de nouvelle session. Désactivé, le widget n’est pas enregistré, aucune requête n’est envoyée et le dossier local des sessions n’est pas analysé.',
|
|
480
|
+
'metric.label': 'Indicateur par défaut',
|
|
481
|
+
'metric.hint': 'L’indicateur affiché en premier par la carte. L’usage des jetons lit les journaux de session : le premier basculement construit un index en arrière-plan.',
|
|
482
|
+
'metric.sessions': 'Sessions',
|
|
483
|
+
'metric.tokens': 'Jetons',
|
|
484
|
+
'chart.title': 'Activité',
|
|
485
|
+
'chart.total.sessions': '{count} sessions',
|
|
486
|
+
'chart.total.tokens': '{tokens} jetons',
|
|
487
|
+
'chart.empty.sessions': 'Aucune session pour l’instant',
|
|
488
|
+
'chart.empty.tokens': 'Aucun usage de jetons pour l’instant',
|
|
489
|
+
'chart.loading': 'Comptage…',
|
|
490
|
+
'chart.error': 'Impossible de charger la carte',
|
|
491
|
+
'chart.indexing': 'Création de l’index {done}/{total}',
|
|
492
|
+
'chart.partial': 'Les données de jetons se complètent encore',
|
|
493
|
+
'cell.sessions': '{count} sessions',
|
|
494
|
+
'cell.tokens': '{tokens} jetons',
|
|
495
|
+
'legend.less': 'Moins',
|
|
496
|
+
'legend.more': 'Plus',
|
|
497
|
+
'overview.title': 'Aperçu d’activité',
|
|
498
|
+
'overview.stat.sessions': 'Sessions',
|
|
499
|
+
'overview.stat.messages': 'Messages',
|
|
500
|
+
'overview.stat.tokens': 'Total de jetons',
|
|
501
|
+
'overview.stat.activeDays': 'Jours actifs',
|
|
502
|
+
'overview.stat.currentStreak': 'Série actuelle',
|
|
503
|
+
'overview.stat.longestStreak': 'Série la plus longue',
|
|
504
|
+
'overview.stat.peakHour': 'Heure de pointe',
|
|
505
|
+
'overview.stat.topModel': 'Modèle habituel',
|
|
506
|
+
'overview.range.days': '{days} jours',
|
|
507
|
+
'overview.range.all': 'Tout',
|
|
508
|
+
'overview.caption.all': '{sessions} sessions au total',
|
|
509
|
+
'overview.span': '{days} jours au total',
|
|
510
|
+
'overview.caption': 'Derniers {days} jours · {sessions} sessions',
|
|
511
|
+
'overview.loading': 'Comptage…',
|
|
512
|
+
'overview.error': 'Impossible de charger l’aperçu',
|
|
513
|
+
'overview.empty': 'Aucune activité pour l’instant',
|
|
514
|
+
'overview.streak.day': 'j',
|
|
515
|
+
'overview.books': '≈ {count} × {name}',
|
|
516
|
+
'overview.books.under': 'Moins d’un {name}',
|
|
517
|
+
'overview.books.beyond': 'Plus de {count} × {name}',
|
|
518
|
+
'overview.books.title': 'D’après {fresh} jetons de contenu nouveau (relectures de contexte exclues). Relances comprises : {total} jetons.',
|
|
519
|
+
'overview.spark.caption': 'Activité sur 24 heures (messages)',
|
|
520
|
+
'overview.switch.label': 'Afficher l’aperçu d’activité',
|
|
521
|
+
'overview.switch.hint': 'Affiche sessions, messages, usage de jetons, séries et plus sur l’écran de nouvelle session. Désactivé, le widget n’est pas enregistré, aucune requête n’est envoyée et le dossier local des sessions n’est pas analysé.',
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const de = {
|
|
525
|
+
'nav.label': 'Aktivität',
|
|
526
|
+
'section.title': 'Aktivitäts-Heatmap der Sitzungen',
|
|
527
|
+
'switch.label': 'Sitzungs-Heatmap anzeigen',
|
|
528
|
+
'switch.hint': 'Zeigt auf dem Bildschirm für neue Sitzungen, wie aktiv jeder Tag des letzten Jahres war. Wenn deaktiviert, wird das Widget nicht registriert, es werden keine Anfragen gesendet und der lokale Sitzungsordner wird nicht durchsucht.',
|
|
529
|
+
'metric.label': 'Standardmetrik',
|
|
530
|
+
'metric.hint': 'Welche Metrik die Heatmap zuerst zeigt. Die Token-Nutzung liest Sitzungsprotokolle, daher wird beim ersten Wechsel ein Index im Hintergrund aufgebaut.',
|
|
531
|
+
'metric.sessions': 'Sitzungen',
|
|
532
|
+
'metric.tokens': 'Token',
|
|
533
|
+
'chart.title': 'Aktivität',
|
|
534
|
+
'chart.total.sessions': '{count} Sitzungen',
|
|
535
|
+
'chart.total.tokens': '{tokens} Token',
|
|
536
|
+
'chart.empty.sessions': 'Noch keine Sitzungen',
|
|
537
|
+
'chart.empty.tokens': 'Noch keine Token-Nutzung',
|
|
538
|
+
'chart.loading': 'Wird gezählt…',
|
|
539
|
+
'chart.error': 'Heatmap konnte nicht geladen werden',
|
|
540
|
+
'chart.indexing': 'Index wird erstellt {done}/{total}',
|
|
541
|
+
'chart.partial': 'Token-Daten werden noch ergänzt',
|
|
542
|
+
'cell.sessions': '{count} Sitzungen',
|
|
543
|
+
'cell.tokens': '{tokens} Token',
|
|
544
|
+
'legend.less': 'Weniger',
|
|
545
|
+
'legend.more': 'Mehr',
|
|
546
|
+
'overview.title': 'Aktivitätsübersicht',
|
|
547
|
+
'overview.stat.sessions': 'Sitzungen',
|
|
548
|
+
'overview.stat.messages': 'Nachrichten',
|
|
549
|
+
'overview.stat.tokens': 'Token gesamt',
|
|
550
|
+
'overview.stat.activeDays': 'Aktive Tage',
|
|
551
|
+
'overview.stat.currentStreak': 'Aktuelle Serie',
|
|
552
|
+
'overview.stat.longestStreak': 'Längste Serie',
|
|
553
|
+
'overview.stat.peakHour': 'Stoßzeit',
|
|
554
|
+
'overview.stat.topModel': 'Häufigstes Modell',
|
|
555
|
+
'overview.range.days': '{days} Tage',
|
|
556
|
+
'overview.range.all': 'Gesamt',
|
|
557
|
+
'overview.caption.all': 'Insgesamt {sessions} Sitzungen',
|
|
558
|
+
'overview.span': '{days} Tage gesamt',
|
|
559
|
+
'overview.caption': 'Letzte {days} Tage · {sessions} Sitzungen',
|
|
560
|
+
'overview.loading': 'Wird gezählt…',
|
|
561
|
+
'overview.error': 'Übersicht konnte nicht geladen werden',
|
|
562
|
+
'overview.empty': 'Noch keine Aktivität',
|
|
563
|
+
'overview.streak.day': 'T',
|
|
564
|
+
'overview.books': '≈ {count} × {name}',
|
|
565
|
+
'overview.books.under': 'Weniger als ein {name}',
|
|
566
|
+
'overview.books.beyond': 'Mehr als {count} × {name}',
|
|
567
|
+
'overview.books.title': 'Nach {fresh} Token neuen Inhalts (ohne wiederholtes Lesen des Kontexts). Mit Wiederholungen: {total} Token.',
|
|
568
|
+
'overview.spark.caption': '24-Stunden-Aktivität (Nachrichten)',
|
|
569
|
+
'overview.switch.label': 'Aktivitätsübersicht anzeigen',
|
|
570
|
+
'overview.switch.hint': 'Zeigt auf dem Bildschirm für neue Sitzungen Sitzungen, Nachrichten, Token-Nutzung, Serien und mehr. Wenn deaktiviert, wird das Widget nicht registriert, es werden keine Anfragen gesendet und der lokale Sitzungsordner wird nicht durchsucht.',
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const pt = {
|
|
574
|
+
'nav.label': 'Atividade',
|
|
575
|
+
'section.title': 'Mapa de atividade das sessões',
|
|
576
|
+
'switch.label': 'Mostrar o mapa de sessões',
|
|
577
|
+
'switch.hint': 'Mostra quão ativo foi cada dia no último ano, na tela de nova sessão. Quando desativado, o widget não é registrado, nenhuma requisição é enviada e a pasta local de sessões não é verificada.',
|
|
578
|
+
'metric.label': 'Métrica padrão',
|
|
579
|
+
'metric.hint': 'Qual métrica o mapa mostra primeiro. O uso de tokens lê os registros de sessão, então a primeira troca cria um índice em segundo plano.',
|
|
580
|
+
'metric.sessions': 'Sessões',
|
|
581
|
+
'metric.tokens': 'Tokens',
|
|
582
|
+
'chart.title': 'Atividade',
|
|
583
|
+
'chart.total.sessions': '{count} sessões',
|
|
584
|
+
'chart.total.tokens': '{tokens} tokens',
|
|
585
|
+
'chart.empty.sessions': 'Ainda não há sessões',
|
|
586
|
+
'chart.empty.tokens': 'Ainda não há uso de tokens',
|
|
587
|
+
'chart.loading': 'Contando…',
|
|
588
|
+
'chart.error': 'Não foi possível carregar o mapa',
|
|
589
|
+
'chart.indexing': 'Criando índice {done}/{total}',
|
|
590
|
+
'chart.partial': 'Os dados de tokens ainda estão sendo completados',
|
|
591
|
+
'cell.sessions': '{count} sessões',
|
|
592
|
+
'cell.tokens': '{tokens} tokens',
|
|
593
|
+
'legend.less': 'Menos',
|
|
594
|
+
'legend.more': 'Mais',
|
|
595
|
+
'overview.title': 'Resumo de atividade',
|
|
596
|
+
'overview.stat.sessions': 'Sessões',
|
|
597
|
+
'overview.stat.messages': 'Mensagens',
|
|
598
|
+
'overview.stat.tokens': 'Total de tokens',
|
|
599
|
+
'overview.stat.activeDays': 'Dias ativos',
|
|
600
|
+
'overview.stat.currentStreak': 'Sequência atual',
|
|
601
|
+
'overview.stat.longestStreak': 'Sequência mais longa',
|
|
602
|
+
'overview.stat.peakHour': 'Horário de pico',
|
|
603
|
+
'overview.stat.topModel': 'Modelo frequente',
|
|
604
|
+
'overview.range.days': '{days} dias',
|
|
605
|
+
'overview.range.all': 'Tudo',
|
|
606
|
+
'overview.caption.all': '{sessions} sessões no total',
|
|
607
|
+
'overview.span': '{days} dias no total',
|
|
608
|
+
'overview.caption': 'Últimos {days} dias · {sessions} sessões',
|
|
609
|
+
'overview.loading': 'Contando…',
|
|
610
|
+
'overview.error': 'Não foi possível carregar o resumo',
|
|
611
|
+
'overview.empty': 'Ainda não há atividade',
|
|
612
|
+
'overview.streak.day': 'd',
|
|
613
|
+
'overview.books': '≈ {count} × {name}',
|
|
614
|
+
'overview.books.under': 'Menos de um {name}',
|
|
615
|
+
'overview.books.beyond': 'Mais de {count} × {name}',
|
|
616
|
+
'overview.books.title': 'Com base em {fresh} tokens de conteúdo novo (releituras de contexto excluídas). Incluindo repetições: {total} tokens.',
|
|
617
|
+
'overview.spark.caption': 'Atividade em 24 horas (mensagens)',
|
|
618
|
+
'overview.switch.label': 'Mostrar o resumo de atividade',
|
|
619
|
+
'overview.switch.hint': 'Mostra sessões, mensagens, uso de tokens, sequências e mais na tela de nova sessão. Quando desativado, o widget não é registrado, nenhuma requisição é enviada e a pasta local de sessões não é verificada.',
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const DICTS = { zh, en, ru, ja, es, fr, de, pt }
|
|
623
|
+
|
|
624
|
+
// 渲染器未注入 t 时的回退(组件可独立渲染 / 测试)。
|
|
625
|
+
function fmt(text, params) {
|
|
626
|
+
let out = String(text)
|
|
627
|
+
if (params) {
|
|
628
|
+
for (const [key, value] of Object.entries(params)) {
|
|
629
|
+
out = out.split(`{${key}}`).join(String(value))
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return out
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
const FALLBACK_T = (key, params) => fmt(zh[key] !== undefined ? zh[key] : key, params)
|
|
636
|
+
|
|
637
|
+
// 数字缩写:热力图的头部空间有限,1.4B 比 1400000000 可读得多。
|
|
638
|
+
// 用 Intl.NumberFormat 的 compact 记法,语言取宿主的 <html lang>。
|
|
639
|
+
function formatCount(value, locale, options) {
|
|
640
|
+
const n = typeof value === 'number' && Number.isFinite(value) ? value : 0
|
|
641
|
+
try {
|
|
642
|
+
return new Intl.NumberFormat(locale, options).format(n)
|
|
643
|
+
} catch {
|
|
644
|
+
return String(n)
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// -------------------------------------------------------------------------
|
|
649
|
+
// 控制器:配置的单一数据源
|
|
650
|
+
// -------------------------------------------------------------------------
|
|
651
|
+
//
|
|
652
|
+
// 为什么需要一个 store 而不是在各组件里各拉一次:热力图槽位是否注册、设置页的
|
|
653
|
+
// 开关状态、开/关后的即时生效,三处必须读同一份值。否则会出现「设置页显示关了、
|
|
654
|
+
// 首页还在画」这种自相矛盾的状态。
|
|
655
|
+
function createController() {
|
|
656
|
+
let snapshot = {
|
|
657
|
+
ready: false,
|
|
658
|
+
heatmapEnabled: true,
|
|
659
|
+
overviewEnabled: true,
|
|
660
|
+
metric: METRIC_SESSIONS,
|
|
661
|
+
configError: null,
|
|
662
|
+
error: null
|
|
663
|
+
}
|
|
664
|
+
const listeners = new Set()
|
|
665
|
+
|
|
666
|
+
const emit = () => {
|
|
667
|
+
for (const listener of listeners) {
|
|
668
|
+
try {
|
|
669
|
+
listener(snapshot)
|
|
670
|
+
} catch {
|
|
671
|
+
// 一个订阅者抛错不该阻断其他订阅者(拖垮的会是整个首页)。
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const store = {
|
|
677
|
+
getSnapshot: () => snapshot,
|
|
678
|
+
subscribe(listener) {
|
|
679
|
+
listeners.add(listener)
|
|
680
|
+
return () => listeners.delete(listener)
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const apply = (config) => {
|
|
685
|
+
snapshot = {
|
|
686
|
+
ready: true,
|
|
687
|
+
heatmapEnabled: config && config.heatmapEnabled === false ? false : true,
|
|
688
|
+
overviewEnabled: config && config.overviewEnabled === false ? false : true,
|
|
689
|
+
metric: config && config.metric === METRIC_TOKENS ? METRIC_TOKENS : METRIC_SESSIONS,
|
|
690
|
+
configError: snapshot.configError,
|
|
691
|
+
error: null
|
|
692
|
+
}
|
|
693
|
+
emit()
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
async function refresh() {
|
|
697
|
+
if (typeof fetch !== 'function') return snapshot
|
|
698
|
+
try {
|
|
699
|
+
const res = await fetch('/api/pulse/config')
|
|
700
|
+
const data = await res.json()
|
|
701
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || 'bad payload')
|
|
702
|
+
snapshot = {
|
|
703
|
+
ready: true,
|
|
704
|
+
heatmapEnabled: data.config && data.config.heatmapEnabled === false ? false : true,
|
|
705
|
+
overviewEnabled: data.config && data.config.overviewEnabled === false ? false : true,
|
|
706
|
+
metric: data.config && data.config.metric === METRIC_TOKENS ? METRIC_TOKENS : METRIC_SESSIONS,
|
|
707
|
+
configError: data.configError || null,
|
|
708
|
+
error: null
|
|
709
|
+
}
|
|
710
|
+
emit()
|
|
711
|
+
} catch (err) {
|
|
712
|
+
// 读不到配置时保持当前状态(默认开启)。热力图数据端点自己也会按配置判断,
|
|
713
|
+
// 所以这里静默失败不会让开关「看起来有效、实际无效」。
|
|
714
|
+
snapshot = { ...snapshot, ready: true, error: String((err && err.message) || err) }
|
|
715
|
+
emit()
|
|
716
|
+
}
|
|
717
|
+
return snapshot
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
async function save(patch) {
|
|
721
|
+
if (typeof fetch !== 'function') throw new Error('fetch unavailable')
|
|
722
|
+
const res = await fetch('/api/pulse/config', {
|
|
723
|
+
method: 'POST',
|
|
724
|
+
headers: { 'content-type': 'application/json' },
|
|
725
|
+
body: JSON.stringify(patch)
|
|
726
|
+
})
|
|
727
|
+
const data = await res.json()
|
|
728
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || 'save failed')
|
|
729
|
+
apply(data.config)
|
|
730
|
+
return data.config
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
const setEnabled = (value) => save({ heatmapEnabled: value === true })
|
|
734
|
+
const setOverviewEnabled = (value) => save({ overviewEnabled: value === true })
|
|
735
|
+
const setMetric = (value) => save({ metric: value === METRIC_TOKENS ? METRIC_TOKENS : METRIC_SESSIONS })
|
|
736
|
+
|
|
737
|
+
return { store, refresh, setEnabled, setOverviewEnabled, setMetric }
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// -------------------------------------------------------------------------
|
|
741
|
+
// 挂载点:标题下方
|
|
742
|
+
// -------------------------------------------------------------------------
|
|
743
|
+
//
|
|
744
|
+
// 宿主**没有**「标题下方」的槽位。HeroShell 的真实结构(app.asar 内已核对):
|
|
745
|
+
//
|
|
746
|
+
// div._composerHero
|
|
747
|
+
// div._stack
|
|
748
|
+
// div._headline ← 鲸鱼 + 「探索未至之境」
|
|
749
|
+
// div._body ← 空容器;React 不管理它的子节点
|
|
750
|
+
// div._heroWorkspaceRow ← 工作区 chip … conversation.hero.options
|
|
751
|
+
//
|
|
752
|
+
// hero.options 只出现在最后一行(右对齐、和 chip 同级),热力图放那儿会被挤成
|
|
753
|
+
// 一小块。这里注册槽位只当「什么时候该显示」的开关,内容用 portal 放进 _body:
|
|
754
|
+
// React 不会去清理它的子节点,所以额外插入的元素不会被回收。
|
|
755
|
+
//
|
|
756
|
+
// 类名是 CSS Module 的哈希前缀 + 稳定后缀(如 `WOwLGG_headline`),所以按
|
|
757
|
+
// `[class*="_xxx"]` 匹配。宿主改结构时可能失配 —— 1.5 秒内找不到就退回行内渲染
|
|
758
|
+
// (留在 hero.options 那一行),功能不丢,只是位置回到旧样子。
|
|
759
|
+
|
|
760
|
+
const HOST_ATTR = 'data-dsh-pulse-hero'
|
|
761
|
+
const PORTAL_TIMEOUT_MS = 1500
|
|
762
|
+
|
|
763
|
+
function hasDom() {
|
|
764
|
+
return typeof document !== 'undefined' && document !== null &&
|
|
765
|
+
typeof document.querySelector === 'function' && typeof document.createElement === 'function'
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// 找到 hero 的标题与它下面的容器。
|
|
769
|
+
//
|
|
770
|
+
// 只认带 _titleGroup 的 _headline:宿主里还有别的 _headline(会话标题等),
|
|
771
|
+
// 插到它们下面会跑到完全无关的位置。
|
|
772
|
+
function findHeroMount() {
|
|
773
|
+
if (!hasDom()) return null
|
|
774
|
+
const scope = document.querySelector('[class*="_composerHero"]') || document
|
|
775
|
+
const headline = scope.querySelector('[class*="_headline"]')
|
|
776
|
+
if (!headline || typeof headline.querySelector !== 'function') return null
|
|
777
|
+
if (!headline.querySelector('[class*="_titleGroup"]')) return null
|
|
778
|
+
const stack = headline.parentElement
|
|
779
|
+
if (!stack) return null
|
|
780
|
+
|
|
781
|
+
// _body 是 headline 的兄弟,且必须是直接子节点(不能用后代选择器 ——
|
|
782
|
+
// 里面还嵌着别的模块,随便命中一个会把热力图塞进输入框里)。
|
|
783
|
+
let body = null
|
|
784
|
+
const children = stack.children
|
|
785
|
+
if (children && typeof children.length === 'number') {
|
|
786
|
+
for (let i = 0; i < children.length; i++) {
|
|
787
|
+
const child = children[i]
|
|
788
|
+
if (child === headline) continue
|
|
789
|
+
if (/_body$/.test(String(child && child.className ? child.className : ''))) {
|
|
790
|
+
body = child
|
|
791
|
+
break
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
return { headline, stack, body }
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// 返回 { host, gaveUp }:
|
|
799
|
+
// host —— 已经挂在标题下方的容器;为 null 时组件先不渲染内容
|
|
800
|
+
// gaveUp —— 找不到挂载点(宿主结构变了),退回行内渲染
|
|
801
|
+
//
|
|
802
|
+
// MutationObserver 只做一件事:hero 重挂载(换会话、切工作区)后把 host 接回去。
|
|
803
|
+
// 用 rAF 节流,避免每次输入都同步跑两遍选择器。
|
|
804
|
+
function useHeroPortal() {
|
|
805
|
+
const [host, setHost] = React.useState(null)
|
|
806
|
+
const [gaveUp, setGaveUp] = React.useState(false)
|
|
807
|
+
|
|
808
|
+
React.useEffect(() => {
|
|
809
|
+
if (!createPortal || !hasDom()) return undefined
|
|
810
|
+
|
|
811
|
+
let node = null
|
|
812
|
+
let frame = 0
|
|
813
|
+
let stopped = false
|
|
814
|
+
let observer = null
|
|
815
|
+
let sizeObserver = null
|
|
816
|
+
|
|
817
|
+
// 卡片的宽度要和下方输入框**完全一致**。
|
|
818
|
+
//
|
|
819
|
+
// 宿主给 hero 用的栅格比输入框窄(实测 748 vs 922),所以不能靠 100% 撑满;
|
|
820
|
+
// 直接量输入框卡片(data-composer-card)的宽度,写到 host 上,再靠
|
|
821
|
+
// align-self:center 居中 —— host 比 stack 宽时,两侧对称溢出到
|
|
822
|
+
// composerHero 的留白里,正好和输入框对齐。
|
|
823
|
+
const queryComposerCard = () => {
|
|
824
|
+
if (!hasDom() || typeof document.querySelector !== 'function') return null
|
|
825
|
+
return document.querySelector('[data-composer-seat] [data-composer-card]') ||
|
|
826
|
+
document.querySelector('[data-composer-card]')
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const syncWidth = () => {
|
|
830
|
+
if (!node || !node.style) return
|
|
831
|
+
const card = queryComposerCard()
|
|
832
|
+
if (!card || typeof card.getBoundingClientRect !== 'function') {
|
|
833
|
+
node.style.width = ''
|
|
834
|
+
node.style.alignSelf = ''
|
|
835
|
+
return
|
|
836
|
+
}
|
|
837
|
+
const width = Math.round(card.getBoundingClientRect().width)
|
|
838
|
+
if (!(width > 0)) return
|
|
839
|
+
node.style.width = `${width}px`
|
|
840
|
+
node.style.alignSelf = 'center'
|
|
841
|
+
|
|
842
|
+
if (!sizeObserver && typeof ResizeObserver === 'function') {
|
|
843
|
+
sizeObserver = new ResizeObserver(() => schedule())
|
|
844
|
+
sizeObserver.observe(card)
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
const attach = () => {
|
|
849
|
+
frame = 0
|
|
850
|
+
if (stopped) return
|
|
851
|
+
|
|
852
|
+
const mount = findHeroMount()
|
|
853
|
+
if (!mount) return
|
|
854
|
+
if (!node) {
|
|
855
|
+
node = document.createElement('div')
|
|
856
|
+
node.setAttribute(HOST_ATTR, '')
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
if (mount.body) {
|
|
860
|
+
if (node.parentElement !== mount.body) mount.body.appendChild(node)
|
|
861
|
+
} else if (node.parentElement !== mount.stack || node.previousElementSibling !== mount.headline) {
|
|
862
|
+
// 没有 _body 的版本:插在标题后面(会被 React 看到,但只是多一个兄弟节点,
|
|
863
|
+
// 不参与它的子节点对账;真出问题时还有 gaveUp 的回退)。
|
|
864
|
+
if (typeof mount.headline.insertAdjacentElement === 'function') {
|
|
865
|
+
mount.headline.insertAdjacentElement('afterend', node)
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if (node.parentElement !== null) {
|
|
870
|
+
syncWidth()
|
|
871
|
+
setHost((current) => (current === node ? current : node))
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
const schedule = () => {
|
|
876
|
+
if (frame !== 0 || stopped) return
|
|
877
|
+
frame = typeof requestAnimationFrame === 'function'
|
|
878
|
+
? requestAnimationFrame(attach)
|
|
879
|
+
: setTimeout(attach, 16)
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
attach()
|
|
883
|
+
const hasWindow = typeof window !== 'undefined' && window && typeof window.addEventListener === 'function'
|
|
884
|
+
if (hasWindow) window.addEventListener('resize', schedule)
|
|
885
|
+
|
|
886
|
+
try {
|
|
887
|
+
if (typeof MutationObserver === 'function') {
|
|
888
|
+
observer = new MutationObserver(schedule)
|
|
889
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
890
|
+
}
|
|
891
|
+
} catch {
|
|
892
|
+
observer = null
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
const timer = setTimeout(() => {
|
|
896
|
+
if (!stopped) setGaveUp(true)
|
|
897
|
+
}, PORTAL_TIMEOUT_MS)
|
|
898
|
+
|
|
899
|
+
return () => {
|
|
900
|
+
stopped = true
|
|
901
|
+
clearTimeout(timer)
|
|
902
|
+
if (hasWindow) window.removeEventListener('resize', schedule)
|
|
903
|
+
if (sizeObserver) sizeObserver.disconnect()
|
|
904
|
+
if (observer) observer.disconnect()
|
|
905
|
+
if (frame !== 0) {
|
|
906
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
907
|
+
else clearTimeout(frame)
|
|
908
|
+
}
|
|
909
|
+
if (node && node.parentElement) node.parentElement.removeChild(node)
|
|
910
|
+
// 不在 cleanup 里 setHost(null):此时组件正在卸载,再 setState 只会触发
|
|
911
|
+
// React 的「对已卸载组件更新」警告。
|
|
912
|
+
}
|
|
913
|
+
}, [])
|
|
914
|
+
|
|
915
|
+
return { host, gaveUp }
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// -------------------------------------------------------------------------
|
|
919
|
+
// 组件
|
|
920
|
+
// -------------------------------------------------------------------------
|
|
921
|
+
|
|
922
|
+
// 月份标签:取每个月第一次出现的那一列。
|
|
923
|
+
//
|
|
924
|
+
// 只按 ISO 字符串的前 7 位分组,不做日期运算;月份名交给 Intl,语言取宿主的
|
|
925
|
+
// <html lang>(宿主切换界面语言时会更新它)。
|
|
926
|
+
function uiLocale() {
|
|
927
|
+
if (typeof document !== 'undefined' && document && document.documentElement) {
|
|
928
|
+
const lang = document.documentElement.lang
|
|
929
|
+
if (typeof lang === 'string' && lang !== '') return lang
|
|
930
|
+
}
|
|
931
|
+
return 'en'
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function monthMarks(days) {
|
|
935
|
+
let formatter = null
|
|
936
|
+
try {
|
|
937
|
+
formatter = new Intl.DateTimeFormat(uiLocale(), { month: 'short' })
|
|
938
|
+
} catch {
|
|
939
|
+
formatter = null
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
const marks = []
|
|
943
|
+
let lastMonth = ''
|
|
944
|
+
let lastColumn = 0
|
|
945
|
+
for (let i = 0; i < days.length; i++) {
|
|
946
|
+
const date = String(days[i].date || '')
|
|
947
|
+
const month = date.slice(0, 7)
|
|
948
|
+
if (month === '' || month === lastMonth) continue
|
|
949
|
+
lastMonth = month
|
|
950
|
+
|
|
951
|
+
// 第一个月不完整(网格从月中开始)时不标:它的「1 号」不在网格里,
|
|
952
|
+
// 标了会和第二个月的标签挤在同一列(10px 字宽 ≈ 两列)。
|
|
953
|
+
if (i === 0 && !date.endsWith('-01')) continue
|
|
954
|
+
|
|
955
|
+
const column = Math.floor(i / 7) + 1
|
|
956
|
+
// 至少隔一列再标,避免 10px 的「11月」「12月」互相压住。
|
|
957
|
+
if (column <= lastColumn + 1) continue
|
|
958
|
+
lastColumn = column
|
|
959
|
+
|
|
960
|
+
let label = month.slice(5)
|
|
961
|
+
if (formatter) {
|
|
962
|
+
const [year, index] = month.split('-').map(Number)
|
|
963
|
+
try {
|
|
964
|
+
label = formatter.format(new Date(year, index - 1, 1))
|
|
965
|
+
} catch {
|
|
966
|
+
label = month.slice(5)
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
marks.push({ key: month, column, label })
|
|
970
|
+
}
|
|
971
|
+
return marks
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// 网格列数。53 列 × 7 行 = 一年。
|
|
975
|
+
function gridStyle(weeks) {
|
|
976
|
+
return { gridTemplateColumns: `repeat(${weeks}, minmax(0, 1fr))` }
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// 单个格子。hover 用卡片浮层,不用原生 title ——
|
|
980
|
+
// 原生 title 有延迟、样式跟系统走,和卡片完全不是一个质感。
|
|
981
|
+
function cellOf(day, today, metric, t, onEnter) {
|
|
982
|
+
const future = typeof today === 'string' && day.date > today
|
|
983
|
+
const level = metric === METRIC_TOKENS ? day.tokenLevel : day.level
|
|
984
|
+
const value = metric === METRIC_TOKENS ? day.tokens : day.count
|
|
985
|
+
const label = future
|
|
986
|
+
? undefined
|
|
987
|
+
: fmt(t(metric === METRIC_TOKENS ? 'cell.tokens' : 'cell.sessions'), {
|
|
988
|
+
date: day.date,
|
|
989
|
+
count: day.count,
|
|
990
|
+
tokens: formatCount(day.tokens, uiLocale(), { notation: 'compact', maximumFractionDigits: 1 })
|
|
991
|
+
})
|
|
992
|
+
return e('span', {
|
|
993
|
+
key: day.date,
|
|
994
|
+
role: 'img',
|
|
995
|
+
className: 'pulse-cell',
|
|
996
|
+
'data-level': String(level),
|
|
997
|
+
'data-future': future ? '1' : undefined,
|
|
998
|
+
'data-empty': future ? undefined : (value > 0 ? undefined : '1'),
|
|
999
|
+
'aria-label': label,
|
|
1000
|
+
onMouseEnter: future ? undefined : (event) => onEnter(event, day)
|
|
1001
|
+
})
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
function legendOf(t, metric) {
|
|
1005
|
+
const cells = [0, 1, 2, 3, 4].map((level) =>
|
|
1006
|
+
e('span', { key: `lvl-${level}`, className: 'pulse-cell', 'data-level': String(level) })
|
|
1007
|
+
)
|
|
1008
|
+
return e('div', { className: 'pulse-legend' },
|
|
1009
|
+
e('span', null, t('legend.less')),
|
|
1010
|
+
cells,
|
|
1011
|
+
e('span', null, t('legend.more'))
|
|
1012
|
+
)
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// 指标切换(会话 / Token)。
|
|
1016
|
+
//
|
|
1017
|
+
// 这是「单卡双指标」的入口:同一张网格换色标与刻度,位置完全不动,
|
|
1018
|
+
// 用户的视线不需要重新定位。
|
|
1019
|
+
function metricSwitchOf(t, active, onChange) {
|
|
1020
|
+
const options = [
|
|
1021
|
+
{ key: METRIC_SESSIONS, label: t('metric.sessions') },
|
|
1022
|
+
{ key: METRIC_TOKENS, label: t('metric.tokens') }
|
|
1023
|
+
]
|
|
1024
|
+
return e('div', { className: 'pulse-switch', role: 'tablist' },
|
|
1025
|
+
options.map((option) =>
|
|
1026
|
+
e('button', {
|
|
1027
|
+
key: option.key,
|
|
1028
|
+
type: 'button',
|
|
1029
|
+
role: 'tab',
|
|
1030
|
+
'data-on': option.key === active ? '1' : '0',
|
|
1031
|
+
'aria-selected': option.key === active ? 'true' : 'false',
|
|
1032
|
+
className: 'pulse-switch-btn',
|
|
1033
|
+
onClick: () => {
|
|
1034
|
+
if (option.key !== active) onChange(option.key)
|
|
1035
|
+
}
|
|
1036
|
+
}, option.label)))
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// 会话欢迎页的活动概览。
|
|
1040
|
+
//
|
|
1041
|
+
// 与热力图一样用 portal 挂进 HeroShell 标题下方的容器:两个组件各自创建
|
|
1042
|
+
// 自己的 host 节点,按注册顺序叠放(概览 order 15 < 热力图 20,挂载也更早,
|
|
1043
|
+
// 所以概览在上、热力图在下)。分两张卡还是合一张卡,取决于宿主 _body 的
|
|
1044
|
+
// 层叠 —— 这里保持「一个组件一个 host」的最简模型,间距由 CSS 的相邻
|
|
1045
|
+
// 兄弟选择器补出,任何一张卡单独开关都不会留下空洞。
|
|
1046
|
+
//
|
|
1047
|
+
// 指标栅格 2×4,与参考实现同序:会话数 / 消息数 / 总 Token / 活跃天数 /
|
|
1048
|
+
// 当前连续 / 最长连续 / 活跃时段 / 常用模型;右上角是时间范围切换。
|
|
1049
|
+
// DSH 特有的是页脚:24 小时消息火花线 + 总量的「上下文当量」换算 ——
|
|
1050
|
+
// token 数字没有直觉,换算成消息数之后「4.1M 是多大」第一次有了参照。
|
|
1051
|
+
function PulseOverview(props) {
|
|
1052
|
+
const t = typeof props.t === 'function' ? props.t : FALLBACK_T
|
|
1053
|
+
const { host, gaveUp } = useHeroPortal()
|
|
1054
|
+
const [state, setState] = React.useState({ status: 'loading', payload: null })
|
|
1055
|
+
const [range, setRange] = React.useState(OVERVIEW_RANGE_DEFAULT)
|
|
1056
|
+
|
|
1057
|
+
React.useEffect(() => {
|
|
1058
|
+
let alive = true
|
|
1059
|
+
const load = async () => {
|
|
1060
|
+
try {
|
|
1061
|
+
const res = await fetch(`/api/pulse/overview?range=${range}`)
|
|
1062
|
+
const data = await res.json()
|
|
1063
|
+
if (!alive) return
|
|
1064
|
+
if (!data || data.ok !== true) throw new Error('bad payload')
|
|
1065
|
+
if (data.enabled === false) {
|
|
1066
|
+
setState({ status: 'disabled', payload: null })
|
|
1067
|
+
return
|
|
1068
|
+
}
|
|
1069
|
+
setState({ status: 'ready', payload: data })
|
|
1070
|
+
} catch {
|
|
1071
|
+
if (alive) setState({ status: 'error', payload: null })
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
void load()
|
|
1075
|
+
return () => { alive = false }
|
|
1076
|
+
}, [range])
|
|
1077
|
+
|
|
1078
|
+
// token 索引在后台推进时每 3 秒追一次,齐了就停(与热力图同策略)。
|
|
1079
|
+
React.useEffect(() => {
|
|
1080
|
+
if (state.status !== 'ready') return undefined
|
|
1081
|
+
const index = state.payload && state.payload.index
|
|
1082
|
+
const pending = !index || index.partial === true || index.running === true
|
|
1083
|
+
if (!pending) return undefined
|
|
1084
|
+
|
|
1085
|
+
let alive = true
|
|
1086
|
+
const timer = setInterval(async () => {
|
|
1087
|
+
try {
|
|
1088
|
+
const res = await fetch(`/api/pulse/overview?range=${range}`)
|
|
1089
|
+
const data = await res.json()
|
|
1090
|
+
if (!alive || !data || data.ok !== true || data.enabled === false) return
|
|
1091
|
+
setState({ status: 'ready', payload: data })
|
|
1092
|
+
} catch {
|
|
1093
|
+
// 轮询失败静默重试:下一拍还会再来。
|
|
1094
|
+
}
|
|
1095
|
+
}, 3000)
|
|
1096
|
+
return () => {
|
|
1097
|
+
alive = false
|
|
1098
|
+
clearInterval(timer)
|
|
1099
|
+
}
|
|
1100
|
+
}, [state.status, state.payload, range])
|
|
1101
|
+
|
|
1102
|
+
const payload = state.payload
|
|
1103
|
+
const locale = uiLocale()
|
|
1104
|
+
const hasData = state.status === 'ready' &&
|
|
1105
|
+
((payload.sessions || 0) > 0 || (payload.messages || 0) > 0 || (payload.tokens || 0) > 0)
|
|
1106
|
+
|
|
1107
|
+
// 指标栅格。activeDays / streak 的单位走同一格(值 + 小单位并排),
|
|
1108
|
+
// 峰值时段与模型是文本值,直接作为 value。
|
|
1109
|
+
//
|
|
1110
|
+
// text 选项:变长文本(模型名)要降字号并给 title —— 实测 provider/model
|
|
1111
|
+
// 最长 29 字符,17px 在 1/4 宽的格子里只能显示十来个,宁可截断也要让前缀可读。
|
|
1112
|
+
const cell = (label, value, options = {}) => e('div', { className: 'pulse-ov-cell', key: label },
|
|
1113
|
+
e('span', { className: 'pulse-ov-label' }, label),
|
|
1114
|
+
value === null || value === undefined
|
|
1115
|
+
? e('span', { className: 'pulse-ov-value' }, '—')
|
|
1116
|
+
: (typeof value === 'string'
|
|
1117
|
+
? e('span', {
|
|
1118
|
+
className: 'pulse-ov-value',
|
|
1119
|
+
'data-accent': options.accent ? '1' : undefined,
|
|
1120
|
+
'data-compact': options.text ? '1' : undefined,
|
|
1121
|
+
title: options.title || (options.text ? value : undefined)
|
|
1122
|
+
}, value)
|
|
1123
|
+
: e('span', { className: 'pulse-ov-value', 'data-accent': options.accent ? '1' : undefined },
|
|
1124
|
+
String(value),
|
|
1125
|
+
options.unit ? e('span', { className: 'pulse-ov-unit' }, options.unit) : null)),
|
|
1126
|
+
options.sub ? e('span', { className: 'pulse-ov-sub' }, options.sub) : null)
|
|
1127
|
+
|
|
1128
|
+
// 常用模型的格子文本。
|
|
1129
|
+
//
|
|
1130
|
+
// 格宽只有卡片的 1/4(实测 900px 卡 ≈ 213px),而 'provider/model' 全名最长
|
|
1131
|
+
// 29 字符 —— 即使降到 13px 也放不下。所以格子里只显示 **模型段**(provider
|
|
1132
|
+
// 前缀对「我最常用哪个模型」是次要信息),完整名字放 title,hover 可见。
|
|
1133
|
+
// 模型段本身也可能很长('deepseek-v4.1-flash'),所以 CSS 仍保留省略号兜底。
|
|
1134
|
+
const shortModel = (label) => {
|
|
1135
|
+
if (typeof label !== 'string' || label === '') return null
|
|
1136
|
+
const slash = label.lastIndexOf('/')
|
|
1137
|
+
return slash >= 0 && slash < label.length - 1 ? label.slice(slash + 1) : label
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// 时间范围文案:0 是「全部」哨兵,其余是「N 天」。
|
|
1141
|
+
const fmtRange = (days) => (days === 0 ? t('overview.range.all') : fmt(t('overview.range.days'), { days }))
|
|
1142
|
+
|
|
1143
|
+
const rangeSwitch = e('div', { className: 'pulse-switch', role: 'tablist' },
|
|
1144
|
+
OVERVIEW_RANGES.map((days) =>
|
|
1145
|
+
e('button', {
|
|
1146
|
+
key: days,
|
|
1147
|
+
type: 'button',
|
|
1148
|
+
role: 'tab',
|
|
1149
|
+
'data-on': days === range ? '1' : '0',
|
|
1150
|
+
'aria-selected': days === range ? 'true' : 'false',
|
|
1151
|
+
className: 'pulse-switch-btn',
|
|
1152
|
+
onClick: () => {
|
|
1153
|
+
if (days !== range) setRange(days)
|
|
1154
|
+
}
|
|
1155
|
+
}, fmtRange(days))))
|
|
1156
|
+
|
|
1157
|
+
// 24 小时火花线。消息直方图(payload.hours)由服务端按日聚合好带下来;
|
|
1158
|
+
// 全零时画一条基线占位,不显示「没有数据」的字样 —— 那是给整个卡片的空态用的。
|
|
1159
|
+
const hours = state.status === 'ready' && Array.isArray(payload.hours) ? payload.hours : []
|
|
1160
|
+
const hourMax = hours.reduce((m, v) => (v > m ? v : m), 0)
|
|
1161
|
+
const peakHour = payload && payload.peakHour ? payload.peakHour : null
|
|
1162
|
+
const spark = e('div', { className: 'pulse-ov-spark-wrap' },
|
|
1163
|
+
e('div', { className: 'pulse-ov-spark', role: 'img', 'aria-label': t('overview.spark.caption') },
|
|
1164
|
+
hours.map((v, h) => e('span', {
|
|
1165
|
+
key: h,
|
|
1166
|
+
className: 'pulse-ov-spark-bar',
|
|
1167
|
+
'data-peak': peakHour === `${String(h).padStart(2, '0')}:00` ? '1' : undefined,
|
|
1168
|
+
style: v > 0 && hourMax > 0
|
|
1169
|
+
? { height: `${Math.max(12, Math.round((v / hourMax) * 100))}%` }
|
|
1170
|
+
: undefined
|
|
1171
|
+
}))),
|
|
1172
|
+
e('div', { className: 'pulse-ov-spark-meta' },
|
|
1173
|
+
e('span', null, '00:00'),
|
|
1174
|
+
e('span', null, peakHour || ''),
|
|
1175
|
+
e('span', null, '23:00')))
|
|
1176
|
+
|
|
1177
|
+
const head = e('div', { className: 'pulse-head' },
|
|
1178
|
+
e('div', { className: 'pulse-head-main' },
|
|
1179
|
+
e('span', { className: 'pulse-title' }, t('overview.title')),
|
|
1180
|
+
rangeSwitch),
|
|
1181
|
+
e('div', { className: 'pulse-head-right' },
|
|
1182
|
+
// 头部右侧只放「索引仍在补」这一种状态:范围已经由左侧切换器表达,
|
|
1183
|
+
// 再写一遍「183 天」是同一事实的第二个出口。
|
|
1184
|
+
state.status === 'ready' && payload.index && payload.index.partial
|
|
1185
|
+
? e('span', { className: 'pulse-total' }, t('chart.partial'))
|
|
1186
|
+
: null))
|
|
1187
|
+
|
|
1188
|
+
let body
|
|
1189
|
+
if (state.status === 'loading') {
|
|
1190
|
+
body = e('div', { className: 'pulse-note' }, t('overview.loading'))
|
|
1191
|
+
} else if (state.status === 'error') {
|
|
1192
|
+
body = e('div', { className: 'pulse-error' }, t('overview.error'))
|
|
1193
|
+
} else if (!hasData) {
|
|
1194
|
+
body = e('div', { className: 'pulse-note' }, t('overview.empty'))
|
|
1195
|
+
} else {
|
|
1196
|
+
const model = payload.topModels && payload.topModels[0]
|
|
1197
|
+
// 说明行与副标题都以**组件当前的 range** 为准,而不是 payload.range:
|
|
1198
|
+
// 切换范围后 payload 要等一次网络往返,用 payload.range 会让说明行在那一瞬
|
|
1199
|
+
// 仍写着上一档("全部 139 次会话" 配着选中的「30 天」,自相矛盾)。
|
|
1200
|
+
// 数字本身来自 payload,切换期间短暂显示旧数字是可接受的(下一条请求马上到)。
|
|
1201
|
+
const activeDaysSub = range === 0
|
|
1202
|
+
? (payload.spanDays > 0 ? fmt(t('overview.span'), { days: payload.spanDays }) : null)
|
|
1203
|
+
: fmtRange(range)
|
|
1204
|
+
body = [
|
|
1205
|
+
// 说明行:一句话交代「这张表统计的是哪个窗口的多少次会话」。
|
|
1206
|
+
e('div', { className: 'pulse-ov-caption', key: 'caption' },
|
|
1207
|
+
range === 0
|
|
1208
|
+
? fmt(t('overview.caption.all'), { sessions: payload.sessions })
|
|
1209
|
+
: fmt(t('overview.caption'), { days: range, sessions: payload.sessions })),
|
|
1210
|
+
e('div', { className: 'pulse-ov-grid', key: 'grid' },
|
|
1211
|
+
cell(t('overview.stat.sessions'), payload.sessions || 0),
|
|
1212
|
+
cell(t('overview.stat.messages'), payload.messages || 0),
|
|
1213
|
+
cell(t('overview.stat.tokens'), formatCount(payload.tokens || 0, locale, { notation: 'compact', maximumFractionDigits: 1 })),
|
|
1214
|
+
cell(t('overview.stat.activeDays'), payload.activeDays || 0, { sub: activeDaysSub }),
|
|
1215
|
+
cell(t('overview.stat.currentStreak'), payload.currentStreak || 0, { unit: t('overview.streak.day'), accent: (payload.currentStreak || 0) > 0 }),
|
|
1216
|
+
cell(t('overview.stat.longestStreak'), payload.longestStreak || 0, { unit: t('overview.streak.day') }),
|
|
1217
|
+
cell(t('overview.stat.peakHour'), payload.peakHour || null),
|
|
1218
|
+
cell(t('overview.stat.topModel'), model ? shortModel(model.model) : null, {
|
|
1219
|
+
text: true,
|
|
1220
|
+
title: model ? model.model : null,
|
|
1221
|
+
sub: model ? formatCount(model.tokens, locale, { notation: 'compact', maximumFractionDigits: 1 }) : null
|
|
1222
|
+
})),
|
|
1223
|
+
spark
|
|
1224
|
+
]
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// 页脚:把 token 换算成「多少部书」—— token 数字没有直觉,书有。
|
|
1228
|
+
//
|
|
1229
|
+
// 用「新内容」口径(payload.books 由服务端按 freshTokens 算好),而不是
|
|
1230
|
+
// 卡上「总 Token」那个数:后者 96% 可能是 cacheRead(同一段上下文被反复读),
|
|
1231
|
+
// 拿它比作「读了多少书」会严重虚高。两种口径的差异放进 title,
|
|
1232
|
+
// hover 就能看到完整解释 —— 主文案只留一句好读的。
|
|
1233
|
+
const books = payload && payload.books
|
|
1234
|
+
// 三档措辞:under(不到一本)/ beyond(超过「部」能表达的量级)/ 常规。
|
|
1235
|
+
// beyond 不是错误,是人类出版物的上限 —— 1000 亿 token ≈ 83 部《四库全书》,
|
|
1236
|
+
// 与其报一个失去量感的数字,不如换成「相当于一座图书馆的藏书」。
|
|
1237
|
+
const bookKey = books && books.under
|
|
1238
|
+
? 'overview.books.under'
|
|
1239
|
+
: books && books.beyond ? 'overview.books.beyond' : 'overview.books'
|
|
1240
|
+
const footnote = state.status === 'ready' && books
|
|
1241
|
+
? e('div', {
|
|
1242
|
+
className: 'pulse-ov-footnote',
|
|
1243
|
+
title: fmt(t('overview.books.title'), {
|
|
1244
|
+
fresh: formatCount(payload.freshTokens || 0, locale, { notation: 'compact', maximumFractionDigits: 2 }),
|
|
1245
|
+
total: formatCount(payload.tokens || 0, locale, { notation: 'compact', maximumFractionDigits: 2 })
|
|
1246
|
+
})
|
|
1247
|
+
}, fmt(t(bookKey), { count: books.count, name: books.name }))
|
|
1248
|
+
: null
|
|
1249
|
+
|
|
1250
|
+
const content = e('div', { className: 'pulse-hero' },
|
|
1251
|
+
e('div', { className: 'pulse-panel' }, head, body, footnote))
|
|
1252
|
+
|
|
1253
|
+
if (createPortal && host) return createPortal(content, host)
|
|
1254
|
+
if (createPortal && !host && !gaveUp) return null
|
|
1255
|
+
return content
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
// 会话欢迎页的热力图。
|
|
1259
|
+
//
|
|
1260
|
+
// 视觉参照宿主的 InputBar 卡片:与输入框同宽的圆角卡片、53 周 × 7 行、
|
|
1261
|
+
// 3px 间距、2px 圆角、月份标签贴在网格下方、hover 放大 + 浮层。
|
|
1262
|
+
function PulseHeatmap(props) {
|
|
1263
|
+
const t = typeof props.t === 'function' ? props.t : FALLBACK_T
|
|
1264
|
+
const controller = props.controller
|
|
1265
|
+
const { host, gaveUp } = useHeroPortal()
|
|
1266
|
+
const [state, setState] = React.useState({ status: 'loading', payload: null })
|
|
1267
|
+
const [tip, setTip] = React.useState(null)
|
|
1268
|
+
|
|
1269
|
+
// 默认指标来自配置;用户在本卡内切换只改本地状态(不落盘),
|
|
1270
|
+
// 因为「这次我想看 token」和「以后都默认 token」是两件事。
|
|
1271
|
+
const configMetric = controller && controller.store
|
|
1272
|
+
? controller.store.getSnapshot().metric
|
|
1273
|
+
: METRIC_SESSIONS
|
|
1274
|
+
const [metric, setMetric] = React.useState(configMetric === METRIC_TOKENS ? METRIC_TOKENS : METRIC_SESSIONS)
|
|
1275
|
+
|
|
1276
|
+
React.useEffect(() => {
|
|
1277
|
+
let alive = true
|
|
1278
|
+
const load = async () => {
|
|
1279
|
+
try {
|
|
1280
|
+
const res = await fetch(`/api/pulse/activity?weeks=${WEEKS}&metric=${metric}`)
|
|
1281
|
+
const data = await res.json()
|
|
1282
|
+
if (!alive) return
|
|
1283
|
+
if (!data || data.ok !== true) throw new Error('bad payload')
|
|
1284
|
+
setState({ status: 'ready', payload: data })
|
|
1285
|
+
} catch {
|
|
1286
|
+
if (alive) setState({ status: 'error', payload: null })
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
void load()
|
|
1290
|
+
// 卸载即取消:开关被关掉时槽位会被注销,这次请求的结果已经没有接收者了。
|
|
1291
|
+
return () => { alive = false }
|
|
1292
|
+
}, [metric])
|
|
1293
|
+
|
|
1294
|
+
// token 索引在后台推进:数据还没齐时每 3 秒追一次,齐了就停。
|
|
1295
|
+
// 轮询只发生在「用户正看着 token 视图且索引未就绪」这一种情况下。
|
|
1296
|
+
React.useEffect(() => {
|
|
1297
|
+
if (metric !== METRIC_TOKENS) return undefined
|
|
1298
|
+
const payload = state.payload
|
|
1299
|
+
const index = payload && payload.index
|
|
1300
|
+
const pending = !index || index.partial === true || index.running === true
|
|
1301
|
+
if (!pending) return undefined
|
|
1302
|
+
|
|
1303
|
+
let alive = true
|
|
1304
|
+
const timer = setInterval(async () => {
|
|
1305
|
+
try {
|
|
1306
|
+
const res = await fetch(`/api/pulse/activity?weeks=${WEEKS}&metric=${METRIC_TOKENS}`)
|
|
1307
|
+
const data = await res.json()
|
|
1308
|
+
if (!alive || !data || data.ok !== true) return
|
|
1309
|
+
setState({ status: 'ready', payload: data })
|
|
1310
|
+
} catch {
|
|
1311
|
+
// 轮询失败静默重试:下一拍还会再来。
|
|
1312
|
+
}
|
|
1313
|
+
}, 3000)
|
|
1314
|
+
return () => {
|
|
1315
|
+
alive = false
|
|
1316
|
+
clearInterval(timer)
|
|
1317
|
+
}
|
|
1318
|
+
}, [metric, state.payload])
|
|
1319
|
+
|
|
1320
|
+
const payload = state.payload
|
|
1321
|
+
const ready = state.status === 'ready'
|
|
1322
|
+
const isTokens = metric === METRIC_TOKENS
|
|
1323
|
+
const total = payload && typeof payload.total === 'number' ? payload.total : 0
|
|
1324
|
+
const tokenTotal = payload && typeof payload.tokenTotal === 'number' ? payload.tokenTotal : 0
|
|
1325
|
+
const index = payload && payload.index ? payload.index : null
|
|
1326
|
+
|
|
1327
|
+
const showTip = (event, day) => {
|
|
1328
|
+
const target = event && event.currentTarget
|
|
1329
|
+
if (!target || typeof target.getBoundingClientRect !== 'function') return
|
|
1330
|
+
|
|
1331
|
+
// 参照物是 host(data-dsh-pulse-hero),它的左上角与 .pulse-hero 重合。
|
|
1332
|
+
// 浮层用 absolute 定位在卡片内部,不 portal 到 body —— 固定在 body 上的
|
|
1333
|
+
// 浮层会被某些布局当成可滚动区域,hover 时冒出滚动条。
|
|
1334
|
+
const anchor = typeof target.closest === 'function'
|
|
1335
|
+
? target.closest('[data-dsh-pulse-hero]')
|
|
1336
|
+
: null
|
|
1337
|
+
if (!anchor || typeof anchor.getBoundingClientRect !== 'function') return
|
|
1338
|
+
|
|
1339
|
+
const rect = target.getBoundingClientRect()
|
|
1340
|
+
const base = anchor.getBoundingClientRect()
|
|
1341
|
+
if (!(base.width > 0)) return
|
|
1342
|
+
|
|
1343
|
+
const half = Math.min(140, base.width / 2)
|
|
1344
|
+
const x = Math.min(Math.max(rect.left - base.left + rect.width / 2, half), base.width - half)
|
|
1345
|
+
const y = rect.top - base.top
|
|
1346
|
+
const bottom = rect.bottom - base.top
|
|
1347
|
+
setTip({
|
|
1348
|
+
date: day.date,
|
|
1349
|
+
count: day.count,
|
|
1350
|
+
tokens: day.tokens,
|
|
1351
|
+
x,
|
|
1352
|
+
top: y,
|
|
1353
|
+
bottom,
|
|
1354
|
+
// 靠近卡片顶部时翻到格子下面,别盖住表头(表头 20px + 间隙 10px + 浮层高度)。
|
|
1355
|
+
below: y < 78
|
|
1356
|
+
})
|
|
1357
|
+
}
|
|
1358
|
+
const hideTip = () => setTip(null)
|
|
1359
|
+
|
|
1360
|
+
// 头部:标题 + 指标切换 | 总数 + 图例。
|
|
1361
|
+
// 指标切换紧跟在标题后面(而不是靠右),是因为它改变的是「这张图在说什么」,
|
|
1362
|
+
// 属于标题的一部分;靠右会和「总数 / 图例」混在一起,读起来像三个同级控件。
|
|
1363
|
+
const head = e('div', { className: 'pulse-head' },
|
|
1364
|
+
e('div', { className: 'pulse-head-main' },
|
|
1365
|
+
e('span', { className: 'pulse-title' }, t('chart.title')),
|
|
1366
|
+
metricSwitchOf(t, metric, setMetric)),
|
|
1367
|
+
e('div', { className: 'pulse-head-right' },
|
|
1368
|
+
ready
|
|
1369
|
+
? e('span', { className: 'pulse-total' },
|
|
1370
|
+
isTokens
|
|
1371
|
+
? formatCount(tokenTotal, uiLocale(), { notation: 'compact', maximumFractionDigits: 2 })
|
|
1372
|
+
: fmt(t('chart.total.sessions'), { count: total }))
|
|
1373
|
+
: e('span', { className: 'pulse-total' }, t('chart.loading')),
|
|
1374
|
+
ready && ((isTokens ? tokenTotal : total) > 0) ? legendOf(t, metric) : null))
|
|
1375
|
+
|
|
1376
|
+
let body
|
|
1377
|
+
if (state.status === 'loading') {
|
|
1378
|
+
// 骨架网格:保持卡片的形状,避免「加载中」一行字把卡片压扁。
|
|
1379
|
+
body = e('div', { className: 'pulse-grid pulse-skeleton', style: gridStyle(WEEKS) },
|
|
1380
|
+
Array.from({ length: WEEKS * 7 }, (_, index) =>
|
|
1381
|
+
e('span', { key: index, className: 'pulse-cell', 'data-level': '0' })))
|
|
1382
|
+
} else if (state.status === 'error') {
|
|
1383
|
+
body = e('div', { className: 'pulse-error' }, t('chart.error'))
|
|
1384
|
+
} else if ((isTokens ? tokenTotal : total) === 0) {
|
|
1385
|
+
// 没有任何数据:显示一句空态,而不是一张全灰的空网格 —— 后者看起来像加载失败。
|
|
1386
|
+
// token 视图在索引还没跑完时不能报「没有记录」,那是在说谎;这时显示进度。
|
|
1387
|
+
const indexing = isTokens && index && index.partial === true
|
|
1388
|
+
body = indexing
|
|
1389
|
+
? e('div', { className: 'pulse-note' }, t('chart.indexing').split('{done}').join(String(index.scanned || 0)).split('{total}').join(String(index.total || 0)))
|
|
1390
|
+
: e('div', { className: 'pulse-note' }, t(isTokens ? 'chart.empty.tokens' : 'chart.empty.sessions'))
|
|
1391
|
+
} else {
|
|
1392
|
+
const weeks = Math.max(1, Math.floor(payload.days.length / 7))
|
|
1393
|
+
body = [
|
|
1394
|
+
e('div', { className: 'pulse-grid', style: gridStyle(weeks) },
|
|
1395
|
+
payload.days.map((day) => cellOf(day, payload.today, metric, t, showTip))),
|
|
1396
|
+
e('div', { className: 'pulse-months', style: gridStyle(weeks) },
|
|
1397
|
+
monthMarks(payload.days).map((mark, index2, list) =>
|
|
1398
|
+
e('span', {
|
|
1399
|
+
key: mark.key,
|
|
1400
|
+
style: {
|
|
1401
|
+
gridColumnStart: mark.column,
|
|
1402
|
+
justifySelf: index2 === list.length - 1 ? 'end' : undefined
|
|
1403
|
+
}
|
|
1404
|
+
}, mark.label)))
|
|
1405
|
+
]
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// token 视图的数据可能还在补:给一行极轻的进度,而不是让用户以为数字就是全部。
|
|
1409
|
+
const progressNode = (() => {
|
|
1410
|
+
if (!isTokens || !ready || !index) return null
|
|
1411
|
+
const pending = index.partial === true || index.running === true
|
|
1412
|
+
if (!pending) return null
|
|
1413
|
+
const done = index.scanned || 0
|
|
1414
|
+
const totalFiles = index.total || 0
|
|
1415
|
+
const pct = totalFiles > 0 ? Math.min(100, Math.round((done / totalFiles) * 100)) : 0
|
|
1416
|
+
return e('div', { className: 'pulse-progress' },
|
|
1417
|
+
e('span', { className: 'pulse-progress-bar' },
|
|
1418
|
+
e('span', { className: 'pulse-progress-fill', style: { width: `${pct}%` } })),
|
|
1419
|
+
e('span', null, totalFiles > 0
|
|
1420
|
+
? fmt(t('chart.indexing'), { done, total: totalFiles })
|
|
1421
|
+
: t('chart.partial')))
|
|
1422
|
+
})()
|
|
1423
|
+
|
|
1424
|
+
const tipNode = tip
|
|
1425
|
+
? e('div', {
|
|
1426
|
+
className: 'pulse-tip',
|
|
1427
|
+
'data-below': tip.below ? '1' : '0',
|
|
1428
|
+
style: { left: `${tip.x}px`, top: `${tip.below ? tip.bottom : tip.top}px` }
|
|
1429
|
+
},
|
|
1430
|
+
e('div', null,
|
|
1431
|
+
e('div', { className: 'pulse-tip-title' }, tip.date),
|
|
1432
|
+
e('div', { className: 'pulse-tip-sub' },
|
|
1433
|
+
isTokens
|
|
1434
|
+
? fmt(t('cell.tokens'), { tokens: formatCount(tip.tokens, uiLocale(), { notation: 'compact', maximumFractionDigits: 2 }) })
|
|
1435
|
+
: fmt(t('cell.sessions'), { count: tip.count }))),
|
|
1436
|
+
e('div', { className: 'pulse-tip-value' },
|
|
1437
|
+
isTokens
|
|
1438
|
+
? formatCount(tip.tokens, uiLocale(), { notation: 'compact', maximumFractionDigits: 2 })
|
|
1439
|
+
: String(tip.count)))
|
|
1440
|
+
: null
|
|
1441
|
+
|
|
1442
|
+
const content = e('div', { className: 'pulse-hero' },
|
|
1443
|
+
e('div', { className: 'pulse-panel', onMouseLeave: hideTip }, head, body, progressNode),
|
|
1444
|
+
tipNode)
|
|
1445
|
+
|
|
1446
|
+
// 先等挂载点:这一瞬间返回 null,槽位包装器是空的(宿主对它用了 :empty{display:none}),
|
|
1447
|
+
// 不会在右对齐那一行闪一下再跳走。
|
|
1448
|
+
if (createPortal && host) return createPortal(content, host)
|
|
1449
|
+
if (createPortal && !host && !gaveUp) return null
|
|
1450
|
+
return content
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// 设置页:开关 + 默认指标。
|
|
1454
|
+
function PulseSettings(props) {
|
|
1455
|
+
const t = typeof props.t === 'function' ? props.t : FALLBACK_T
|
|
1456
|
+
const controller = props.controller
|
|
1457
|
+
const [snap, setSnap] = React.useState(() => controller.store.getSnapshot())
|
|
1458
|
+
const [saving, setSaving] = React.useState(false)
|
|
1459
|
+
// 请求在途时先用用户点的值渲染:开关是受控组件,只等 store 更新会让点击看起来没反应。
|
|
1460
|
+
// 保存失败时 saving 归位,checked 自动回落到 store 里的旧值 —— 开关弹回去本身就是提示。
|
|
1461
|
+
const [pending, setPending] = React.useState(null)
|
|
1462
|
+
const [pendingOverview, setPendingOverview] = React.useState(null)
|
|
1463
|
+
const [saveError, setSaveError] = React.useState(null)
|
|
1464
|
+
|
|
1465
|
+
React.useEffect(() => controller.store.subscribe(setSnap), [])
|
|
1466
|
+
|
|
1467
|
+
const commit = async (patch) => {
|
|
1468
|
+
setSaving(true)
|
|
1469
|
+
setSaveError(null)
|
|
1470
|
+
try {
|
|
1471
|
+
await patch()
|
|
1472
|
+
} catch (err) {
|
|
1473
|
+
setSaveError(String((err && err.message) || err))
|
|
1474
|
+
} finally {
|
|
1475
|
+
setSaving(false)
|
|
1476
|
+
setPending(null)
|
|
1477
|
+
setPendingOverview(null)
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
const onToggle = (event) => {
|
|
1482
|
+
const next = event.target.checked === true
|
|
1483
|
+
setPending(next)
|
|
1484
|
+
void commit(() => controller.setEnabled(next))
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
const onOverviewToggle = (event) => {
|
|
1488
|
+
const next = event.target.checked === true
|
|
1489
|
+
setPendingOverview(next)
|
|
1490
|
+
void commit(() => controller.setOverviewEnabled(next))
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
const onMetric = (value) => {
|
|
1494
|
+
setPending(value)
|
|
1495
|
+
void commit(() => controller.setMetric(value))
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
const checked = saving && typeof pending === 'boolean' ? pending : snap.heatmapEnabled !== false
|
|
1499
|
+
const overviewChecked = saving && typeof pendingOverview === 'boolean'
|
|
1500
|
+
? pendingOverview
|
|
1501
|
+
: snap.overviewEnabled !== false
|
|
1502
|
+
const activeMetric = saving && (pending === METRIC_TOKENS || pending === METRIC_SESSIONS)
|
|
1503
|
+
? pending
|
|
1504
|
+
: (snap.metric === METRIC_TOKENS ? METRIC_TOKENS : METRIC_SESSIONS)
|
|
1505
|
+
|
|
1506
|
+
return e('div', { className: 'pulse-section' },
|
|
1507
|
+
e('div', { className: 'pulse-section-head' },
|
|
1508
|
+
e('span', { className: 'pulse-section-title' }, t('section.title')),
|
|
1509
|
+
e('span', { className: 'pulse-version' }, `v${VERSION}`)),
|
|
1510
|
+
e('div', { className: 'pulse-card' },
|
|
1511
|
+
e('div', { className: 'pulse-switch-row' },
|
|
1512
|
+
e('div', { className: 'pulse-switch-text' },
|
|
1513
|
+
e('div', { className: 'pulse-switch-label' }, t('switch.label')),
|
|
1514
|
+
e('div', { className: 'pulse-switch-hint' }, t('switch.hint'))),
|
|
1515
|
+
e('label', { className: 'pulse-toggle' },
|
|
1516
|
+
e('input', {
|
|
1517
|
+
type: 'checkbox',
|
|
1518
|
+
checked,
|
|
1519
|
+
disabled: saving,
|
|
1520
|
+
onChange: onToggle
|
|
1521
|
+
}))),
|
|
1522
|
+
e('div', { className: 'pulse-switch-row' },
|
|
1523
|
+
e('div', { className: 'pulse-switch-text' },
|
|
1524
|
+
e('div', { className: 'pulse-switch-label' }, t('overview.switch.label')),
|
|
1525
|
+
e('div', { className: 'pulse-switch-hint' }, t('overview.switch.hint'))),
|
|
1526
|
+
e('label', { className: 'pulse-toggle' },
|
|
1527
|
+
e('input', {
|
|
1528
|
+
type: 'checkbox',
|
|
1529
|
+
checked: overviewChecked,
|
|
1530
|
+
disabled: saving,
|
|
1531
|
+
onChange: onOverviewToggle
|
|
1532
|
+
}))),
|
|
1533
|
+
e('div', { className: 'pulse-metric-row' },
|
|
1534
|
+
e('div', { className: 'pulse-switch-text' },
|
|
1535
|
+
e('div', { className: 'pulse-switch-label' }, t('metric.label')),
|
|
1536
|
+
e('div', { className: 'pulse-metric-hint' }, t('metric.hint'))),
|
|
1537
|
+
metricSwitchOf(t, activeMetric, onMetric)),
|
|
1538
|
+
saveError ? e('div', { className: 'pulse-error' }, saveError) : null)
|
|
1539
|
+
)
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// -------------------------------------------------------------------------
|
|
1543
|
+
// 装配
|
|
1544
|
+
// -------------------------------------------------------------------------
|
|
1545
|
+
|
|
1546
|
+
const inject = ['slots', 'locale']
|
|
1547
|
+
|
|
1548
|
+
function apply(ctx) {
|
|
1549
|
+
injectStyles()
|
|
1550
|
+
|
|
1551
|
+
// 词典:一门语言一次 register。
|
|
1552
|
+
// 宿主对同一 (ns, locale) 第二次 register 会抛错,且是「先校验后写入」;
|
|
1553
|
+
// 拆开之后一门语言撞车只丢那一门,其余照常。注册失败只该让文案回退,
|
|
1554
|
+
// 不该让整个客户端 apply 抛错。
|
|
1555
|
+
const registerDicts = (dicts) => {
|
|
1556
|
+
try {
|
|
1557
|
+
return ctx.locale.register(NS, dicts)
|
|
1558
|
+
} catch (error) {
|
|
1559
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
1560
|
+
console.warn('[dsh-pulse] locale.register 失败(界面文案回退为 key):', error)
|
|
1561
|
+
}
|
|
1562
|
+
return () => {}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
for (const [locale, dict] of Object.entries(DICTS)) {
|
|
1566
|
+
ctx.effect(
|
|
1567
|
+
() => registerDicts({ [locale]: dict }),
|
|
1568
|
+
`dsh-pulse: dictionaries (${locale})`
|
|
1569
|
+
)
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
const controller = createController()
|
|
1573
|
+
// 拉一次配置;槽位在快照 ready 之后才注册(见下面的 sync)。
|
|
1574
|
+
// 读不到配置时 refresh 会保持 heatmapEnabled 的默认值 true 并把 ready 置位 ——
|
|
1575
|
+
// 网络抖动不该让用户的热力图消失。
|
|
1576
|
+
void controller.refresh()
|
|
1577
|
+
|
|
1578
|
+
const navT = ctx.locale.bind(NS)
|
|
1579
|
+
|
|
1580
|
+
// —— 会话欢迎页的活动概览 ——
|
|
1581
|
+
//
|
|
1582
|
+
// 同一个槽位、order 15(排在人设标签 10 之后、热力图 20 之前)。
|
|
1583
|
+
// 开关语义与热力图一致:读不到配置时保持默认开启;关掉时真的注销。
|
|
1584
|
+
ctx.slots.inject('conversation.hero.options', () => {
|
|
1585
|
+
let overviewDispose = null
|
|
1586
|
+
let heatmapDispose = null
|
|
1587
|
+
|
|
1588
|
+
const syncOverview = () => {
|
|
1589
|
+
const snapshot = controller.store.getSnapshot()
|
|
1590
|
+
const on = snapshot.ready === true && snapshot.overviewEnabled !== false
|
|
1591
|
+
if (on && overviewDispose === null) {
|
|
1592
|
+
overviewDispose = ctx.slots.register({
|
|
1593
|
+
name: 'conversation.hero.options',
|
|
1594
|
+
id: 'pulse-overview',
|
|
1595
|
+
order: 15,
|
|
1596
|
+
locale: NS,
|
|
1597
|
+
inject: () => ({})
|
|
1598
|
+
}, PulseOverview)
|
|
1599
|
+
} else if (!on && overviewDispose !== null) {
|
|
1600
|
+
if (typeof overviewDispose === 'function') overviewDispose()
|
|
1601
|
+
overviewDispose = null
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
const syncHeatmap = () => {
|
|
1606
|
+
const snapshot = controller.store.getSnapshot()
|
|
1607
|
+
// 等配置到位再注册。
|
|
1608
|
+
//
|
|
1609
|
+
// 不能「先按默认开启注册、读到关闭再注销」:注销发生在一次网络往返之后,
|
|
1610
|
+
// 而宿主在这段时间里已经把组件挂上了 —— 组件自己的 useEffect 会先发一次
|
|
1611
|
+
// /api/pulse/activity。那正是开关关闭时最该避免的请求。
|
|
1612
|
+
// 代价只是开启状态下晚一个请求的时间出现(同一份配置请求)。
|
|
1613
|
+
const on = snapshot.ready === true && snapshot.heatmapEnabled !== false
|
|
1614
|
+
if (on && heatmapDispose === null) {
|
|
1615
|
+
heatmapDispose = ctx.slots.register({
|
|
1616
|
+
name: 'conversation.hero.options',
|
|
1617
|
+
id: 'pulse-heatmap',
|
|
1618
|
+
order: 20,
|
|
1619
|
+
locale: NS,
|
|
1620
|
+
inject: (sessionId) => ({
|
|
1621
|
+
hooks: {
|
|
1622
|
+
pulseController: controller.store
|
|
1623
|
+
},
|
|
1624
|
+
controller,
|
|
1625
|
+
sessionId: typeof sessionId === 'string' && sessionId !== '' ? sessionId : null
|
|
1626
|
+
})
|
|
1627
|
+
}, PulseHeatmap)
|
|
1628
|
+
} else if (!on && heatmapDispose !== null) {
|
|
1629
|
+
// 真的注销,不是让组件 return null:宿主按注册项生成 DOM,
|
|
1630
|
+
// 留着注册项等于留着一个会 fetch 的空壳。
|
|
1631
|
+
if (typeof heatmapDispose === 'function') heatmapDispose()
|
|
1632
|
+
heatmapDispose = null
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
syncOverview()
|
|
1637
|
+
syncHeatmap()
|
|
1638
|
+
const off = controller.store.subscribe(() => {
|
|
1639
|
+
syncOverview()
|
|
1640
|
+
syncHeatmap()
|
|
1641
|
+
})
|
|
1642
|
+
|
|
1643
|
+
return () => {
|
|
1644
|
+
off()
|
|
1645
|
+
if (overviewDispose !== null && typeof overviewDispose === 'function') overviewDispose()
|
|
1646
|
+
overviewDispose = null
|
|
1647
|
+
if (heatmapDispose !== null && typeof heatmapDispose === 'function') heatmapDispose()
|
|
1648
|
+
heatmapDispose = null
|
|
1649
|
+
}
|
|
1650
|
+
})
|
|
1651
|
+
|
|
1652
|
+
// —— 设置页 ——
|
|
1653
|
+
//
|
|
1654
|
+
// 与热力图**相反**:这个槽位永远注册。关掉开关后用户还得能回到这里打开,
|
|
1655
|
+
// 连它一起注销就成了一道死门。
|
|
1656
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
1657
|
+
name: 'settings.section',
|
|
1658
|
+
id: 'pulse-settings',
|
|
1659
|
+
order: 60,
|
|
1660
|
+
label: () => navT('nav.label'),
|
|
1661
|
+
locale: NS,
|
|
1662
|
+
inject: () => ({
|
|
1663
|
+
hooks: {
|
|
1664
|
+
pulseController: controller.store
|
|
1665
|
+
},
|
|
1666
|
+
controller
|
|
1667
|
+
})
|
|
1668
|
+
}, PulseSettings))
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
exports.apply = apply
|
|
1672
|
+
exports.inject = inject
|
|
1673
|
+
return module.exports
|
|
1674
|
+
}
|
|
1675
|
+
})
|