dsh-cyrene-theme-change 0.9.0 → 0.11.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/NOTICE +7 -0
- package/README.md +22 -0
- package/lib/client.js +379 -0
- package/lib/index.js +218 -0
- package/package.json +1 -1
package/NOTICE
CHANGED
|
@@ -19,6 +19,13 @@ SPDX-License-Identifier: MIT
|
|
|
19
19
|
原项目的版权与功劳归原作者与直接上游;本仓库只对其新增部分负责。
|
|
20
20
|
上游 MIT,本项目同样以 MIT 发布,并按 MIT 要求保留上述版权声明。
|
|
21
21
|
|
|
22
|
+
参考与致谢
|
|
23
|
+
dsh-liquid-glass(Ultronen,MIT)
|
|
24
|
+
https://github.com/Ultronen/dsh-liquid-glass
|
|
25
|
+
参考点:用 ctx.theme.overrideTokens 做半透明而不是自写 --dsw-* 变量;
|
|
26
|
+
backdrop-filter 会创建 containing block、破坏弹窗浮层,因此不做全局面模糊。
|
|
27
|
+
本项目未复制其代码,仅采用其公开的结论与 API 用法。
|
|
28
|
+
|
|
22
29
|
本项目以 MIT 许可证发布,完整条款见同目录的 LICENSE 文件。
|
|
23
30
|
使用、修改、再分发与商用均被允许,只需保留本 NOTICE 与 LICENSE 中的版权声明。
|
|
24
31
|
注意:第三方素材(见三、四节)不因本许可证而改变归属。
|
package/README.md
CHANGED
|
@@ -26,6 +26,28 @@
|
|
|
26
26
|
>
|
|
27
27
|
> **Unofficial fan project.** Cyrene and all *Honkai: Star Rail* character art, names and assets are © miHoYo / HoYoverse, used here as non-commercial fan work. Not affiliated with or endorsed by miHoYo, HoYoverse or DeepSeek — see 「致谢」 below.
|
|
28
28
|
|
|
29
|
+
## 液态玻璃
|
|
30
|
+
|
|
31
|
+
三档,从省到贵:
|
|
32
|
+
|
|
33
|
+
| 档 | 做法 | 默认 |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| 关 | 普通毛玻璃(原有主题) | — |
|
|
36
|
+
| **透明** | `ctx.theme.overrideTokens` 把「面」的 token 换成半透明,背景图透上来 | ✅ 开启 |
|
|
37
|
+
| **折射** | 再叠一层 SVG `feTurbulence` + `feDisplacementMap` 做真实折射 | 关(开销大,在面板里开) |
|
|
38
|
+
|
|
39
|
+
两条从实测里换来的硬约束:
|
|
40
|
+
|
|
41
|
+
1. **不用 `backdrop-filter` 做全局面**。它会创建 containing block,把设置弹窗和浮层搞坏
|
|
42
|
+
(`dsh-liquid-glass` 也踩过这个坑并因此放弃;我们之前给 shell.overlay 加模糊,整窗糊掉)。
|
|
43
|
+
2. **折射层只挂在 `::before` 上,且只作用于本插件自己的 `.cyre-*` 元素**。
|
|
44
|
+
挂在元素本身会把文字一起扭曲;碰 `[data-slot]` 槽位会连累整个窗口。
|
|
45
|
+
|
|
46
|
+
折射档的操作开销来自 `feDisplacementMap` 的逐像素采样,手机上明显吃 GPU,所以默认关闭。
|
|
47
|
+
|
|
48
|
+
感谢 [`dsh-liquid-glass`](https://github.com/Ultronen/dsh-liquid-glass)(MIT)验证了
|
|
49
|
+
「只做透明度、不做 backdrop-filter」这条路线,以及 `overrideTokens` 的正确用法。
|
|
50
|
+
|
|
29
51
|
## 与上游的差异
|
|
30
52
|
|
|
31
53
|
上游 [`dsh-plugin-cyrene`](https://github.com/under-the-ocean/dsh-plugin-cyrene) 提供的是
|
package/lib/client.js
CHANGED
|
@@ -847,7 +847,119 @@ body[data-dsh-cyrene][data-ds-dark-theme]{
|
|
|
847
847
|
display:flex;flex-direction:column;gap:8px;margin-top:10px;
|
|
848
848
|
padding:10px 12px;border-radius:14px;
|
|
849
849
|
border:1px solid var(--cy-ui-line);background:var(--cy-ui-face2);
|
|
850
|
+
/* 液态玻璃:底色仍走主题变量,只是叠一层半透明渐变 + 内高光 + 外投影。
|
|
851
|
+
真正的"玻璃感"来自那两道 inset 高光(上沿亮、下沿收),不是模糊;
|
|
852
|
+
模糊只负责把背后的内容推开,给文字让出可读的底。 */
|
|
853
|
+
background-image:linear-gradient(135deg,
|
|
854
|
+
color-mix(in srgb, var(--cy-ui-face2) 78%, white 22%) 0%,
|
|
855
|
+
color-mix(in srgb, var(--cy-ui-face2) 92%, black 8%) 46%,
|
|
856
|
+
color-mix(in srgb, var(--cy-ui-face2) 84%, white 16%) 100%);
|
|
857
|
+
border-color:color-mix(in srgb, var(--cy-ui-line) 70%, white 30%);
|
|
858
|
+
box-shadow:
|
|
859
|
+
inset 0 1px 0 rgba(255,255,255,.55),
|
|
860
|
+
inset 0 -1px 0 rgba(255,255,255,.16),
|
|
861
|
+
0 6px 22px rgba(180,120,160,.10);
|
|
862
|
+
backdrop-filter:blur(18px) saturate(165%);
|
|
863
|
+
-webkit-backdrop-filter:blur(18px) saturate(165%);
|
|
850
864
|
}
|
|
865
|
+
@supports not (backdrop-filter:blur(1px)){
|
|
866
|
+
.cyre-card{background-image:none}
|
|
867
|
+
}
|
|
868
|
+
/* 深色皮肤下内高光要收敛,否则整块发白发灰。 */
|
|
869
|
+
/* ── 液态玻璃:只做透明度,不用 backdrop-filter ──────────────────
|
|
870
|
+
参考 dsh-liquid-glass 的实测结论:backdrop-filter 会创建 containing block,
|
|
871
|
+
把设置弹窗和浮层搞坏(他们踩过,我们之前给 shell.overlay 加模糊也糊过整窗)。
|
|
872
|
+
所以这里的"玻璃"靠两件事:
|
|
873
|
+
1. 把 DSH 的面色 token 换成半透明(JS 里用 ctx.theme.overrideTokens);
|
|
874
|
+
2. 结构层只加内高光和细白边,让边缘有"玻璃厚度",不加任何模糊。 */
|
|
875
|
+
body[data-dsh-cyrene][data-cyrene-skin="on"] [data-chat-flow] [class*="bubble"]{
|
|
876
|
+
box-shadow:
|
|
877
|
+
inset 0 1px 0 rgba(255,255,255,.55),
|
|
878
|
+
0 4px 16px rgba(176,120,156,.10);
|
|
879
|
+
border:1px solid rgba(255,255,255,.42);
|
|
880
|
+
}
|
|
881
|
+
body[data-dsh-cyrene][data-cyrene-skin="on"] [data-composer-card]{
|
|
882
|
+
box-shadow:
|
|
883
|
+
inset 0 1px 0 rgba(255,255,255,.8),
|
|
884
|
+
inset 0 -1px 0 rgba(255,255,255,.24),
|
|
885
|
+
0 8px 26px rgba(176,120,156,.13);
|
|
886
|
+
border:1px solid rgba(255,255,255,.55);
|
|
887
|
+
}
|
|
888
|
+
body[data-dsh-cyrene][data-cyrene-skin="on"] [data-code-block-content]{
|
|
889
|
+
box-shadow:
|
|
890
|
+
inset 0 1px 0 rgba(255,255,255,.16),
|
|
891
|
+
0 6px 20px rgba(20,10,20,.18);
|
|
892
|
+
border:1px solid rgba(255,255,255,.12);
|
|
893
|
+
}
|
|
894
|
+
/* ── 真·液态玻璃(可选,默认关) ──────────────────────────────────
|
|
895
|
+
做法:给本插件自己的每一块面加一个 ::before,让它只承载
|
|
896
|
+
的 backdrop-filter,再用 SVG 位移滤镜把「背后的像素」扭出折射起伏。
|
|
897
|
+
两条硬约束,都是踩出来的:
|
|
898
|
+
1. 滤镜挂在 ::before 上,不挂在元素本身 —— 否则文字会跟着扭;
|
|
899
|
+
2. 只作用于 .cyre-* 自己的界面,绝不碰 [data-slot] 槽位 ——
|
|
900
|
+
那会创建 containing block,把设置弹窗和浮层搞坏。
|
|
901
|
+
开销:feTurbulence + feDisplacementMap 是逐像素算的,手机上明显吃 GPU,
|
|
902
|
+
所以做成开关,默认 off。 */
|
|
903
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-card,
|
|
904
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-editor,
|
|
905
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-panel,
|
|
906
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-page{
|
|
907
|
+
position:relative;
|
|
908
|
+
isolation:isolate;
|
|
909
|
+
background-color:transparent;
|
|
910
|
+
}
|
|
911
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-card::before,
|
|
912
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-editor::before,
|
|
913
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-panel::before,
|
|
914
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-page::before{
|
|
915
|
+
content:"";
|
|
916
|
+
position:absolute;
|
|
917
|
+
inset:0;
|
|
918
|
+
border-radius:inherit;
|
|
919
|
+
z-index:-1;
|
|
920
|
+
background:linear-gradient(135deg,rgba(255,255,255,.34),rgba(255,255,255,.10) 52%,rgba(255,255,255,.28));
|
|
921
|
+
backdrop-filter:blur(10px) saturate(175%);
|
|
922
|
+
-webkit-backdrop-filter:blur(10px) saturate(175%);
|
|
923
|
+
filter:url(#cyrene-theme-change-liquid);
|
|
924
|
+
box-shadow:
|
|
925
|
+
inset 0 1px 0 rgba(255,255,255,.85),
|
|
926
|
+
inset 0 -1px 0 rgba(255,255,255,.30),
|
|
927
|
+
0 10px 30px rgba(176,120,156,.16);
|
|
928
|
+
}
|
|
929
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-card::before,
|
|
930
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-editor::before,
|
|
931
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-panel::before,
|
|
932
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-page::before{
|
|
933
|
+
background:linear-gradient(135deg,rgba(64,46,62,.42),rgba(38,30,42,.20) 52%,rgba(58,42,56,.36));
|
|
934
|
+
box-shadow:
|
|
935
|
+
inset 0 1px 0 rgba(255,255,255,.22),
|
|
936
|
+
inset 0 -1px 0 rgba(255,255,255,.06),
|
|
937
|
+
0 10px 30px rgba(0,0,0,.34);
|
|
938
|
+
}
|
|
939
|
+
@supports not ((backdrop-filter:blur(1px)) and (filter:url(#x))){
|
|
940
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-card::before,
|
|
941
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-editor::before,
|
|
942
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-panel::before,
|
|
943
|
+
body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-page::before{
|
|
944
|
+
filter:none;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
body[data-dsh-cyrene][data-cyrene-skin="on"] [data-slot="sidebar"]{
|
|
948
|
+
box-shadow:inset -1px 0 0 rgba(255,255,255,.45);
|
|
949
|
+
}
|
|
950
|
+
body[data-dsh-cyrene][data-cyrene-skin="on"][data-theme="dark"] [data-slot="sidebar"]{
|
|
951
|
+
box-shadow:inset -1px 0 0 rgba(255,255,255,.12);
|
|
952
|
+
}
|
|
953
|
+
body[data-dsh-cyrene][data-cyrene-skin="on"] .cyre-card{
|
|
954
|
+
box-shadow:
|
|
955
|
+
inset 0 1px 0 rgba(255,255,255,.14),
|
|
956
|
+
inset 0 -1px 0 rgba(255,255,255,.05),
|
|
957
|
+
0 6px 22px rgba(0,0,0,.28);
|
|
958
|
+
}
|
|
959
|
+
.cyre-ring{display:inline-flex;align-items:center;color:var(--cy-ui-accent,#e8699f);transition:color .2s ease}
|
|
960
|
+
.cyre-ring.warm{color:#e8a33d}
|
|
961
|
+
.cyre-ring.alert{color:#e0575b}
|
|
962
|
+
.cyre-ring-label{font-size:11.5px;color:var(--cy-ui-soft);font-variant-numeric:tabular-nums}
|
|
851
963
|
.cyre-card-head{
|
|
852
964
|
display:flex;align-items:center;gap:8px;
|
|
853
965
|
font-size:12.5px;font-weight:600;color:var(--cy-ui-text);
|
|
@@ -1179,6 +1291,10 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
1179
1291
|
persona: "", enabled: true, theme: true, stickers: true, rev: 0,
|
|
1180
1292
|
/** 桌宠(Live2D)开关;默认关,避免和 dsh-cyrene 的桌宠叠在一起。 */
|
|
1181
1293
|
pet: false,
|
|
1294
|
+
/** 液态玻璃不透明度(0.25–0.95)。 */
|
|
1295
|
+
glassAlpha: 0.55,
|
|
1296
|
+
/** 真·液态玻璃(SVG 位移折射):视觉最像,开销也最大,默认关。 */
|
|
1297
|
+
glassHeavy: false,
|
|
1182
1298
|
/** 聊天里贴图的最大边长(px):落到 body 上的 --cyre-sticker-size。 */
|
|
1183
1299
|
stickerSize: 96,
|
|
1184
1300
|
defaultPersona: "", statePath: "",
|
|
@@ -1264,6 +1380,8 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
1264
1380
|
if (typeof value.theme === "boolean") state.theme = value.theme;
|
|
1265
1381
|
if (typeof value.stickers === "boolean") state.stickers = value.stickers;
|
|
1266
1382
|
if (typeof value.pet === "boolean") state.pet = value.pet;
|
|
1383
|
+
if (Number.isFinite(value.glassAlpha)) state.glassAlpha = value.glassAlpha;
|
|
1384
|
+
if (typeof value.glassHeavy === "boolean") state.glassHeavy = value.glassHeavy;
|
|
1267
1385
|
if (Number.isFinite(value.stickerSize)) state.stickerSize = value.stickerSize;
|
|
1268
1386
|
if (value.hero !== null && typeof value.hero === "object") {
|
|
1269
1387
|
if (typeof value.hero.title === "string") state.heroTitle = value.hero.title;
|
|
@@ -1286,12 +1404,95 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
1286
1404
|
}
|
|
1287
1405
|
|
|
1288
1406
|
/** 主题开关落到 body 属性上;样式表只认 on。贴图大小与色纱浓度落到 CSS 变量上。 */
|
|
1407
|
+
// ── 液态玻璃:走宿主自己的 token 覆盖服务 ────────────────────────
|
|
1408
|
+
// 参考 dsh-liquid-glass 的做法:用 ctx.theme.overrideTokens(source, tokens)
|
|
1409
|
+
// 把「面」的 token 换成半透明,而不是自己写一堆 --dsw-* 变量去和主题打架。
|
|
1410
|
+
// token 必须给 { light, dark } 成对,否则切深色时会变得没法看。
|
|
1411
|
+
// 宿主没有这个服务(老版本)时静默跳过——CSS 那边还有一层兜底的高光。
|
|
1412
|
+
const GLASS_SOURCE = PACKAGE_ID + ": glass"
|
|
1413
|
+
const GLASS_TOKENS = [
|
|
1414
|
+
"--dsw-alias-bg-base",
|
|
1415
|
+
"--dsw-alias-bg-layer-1",
|
|
1416
|
+
"--dsw-alias-bg-layer-2",
|
|
1417
|
+
"--dsw-alias-bg-layer-3",
|
|
1418
|
+
"--dsw-alias-bg-overlay",
|
|
1419
|
+
"--dsw-specific-sidebar-fill",
|
|
1420
|
+
"--dsw-specific-bubble",
|
|
1421
|
+
"--dsw-specific-input-major",
|
|
1422
|
+
"--dsw-alias-markdown-code-block",
|
|
1423
|
+
"--dsw-alias-markdown-inline-code",
|
|
1424
|
+
]
|
|
1425
|
+
/**
|
|
1426
|
+
* 真·液态玻璃的滤镜定义:feTurbulence 造噪声 → 高斯柔化 → feDisplacementMap
|
|
1427
|
+
* 按噪声把「背后」的像素推开,于是边缘出现折射起伏。
|
|
1428
|
+
* 关键点:滤镜必须挂在 ::before 上(它只承载 backdrop-filter),不能挂在
|
|
1429
|
+
* 元素本身——否则文字会一起被扭(这是所有 liquid-glass 实现的共同注意点)。
|
|
1430
|
+
*/
|
|
1431
|
+
const LIQUID_ID = PACKAGE_ID + "-liquid"
|
|
1432
|
+
function ensureLiquidFilter() {
|
|
1433
|
+
if (typeof document.getElementById === "function" && document.getElementById(LIQUID_ID) !== null) return
|
|
1434
|
+
if (typeof document.createElement !== "function") return
|
|
1435
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
|
|
1436
|
+
svg.setAttribute("id", LIQUID_ID + "-holder")
|
|
1437
|
+
svg.setAttribute("width", "0")
|
|
1438
|
+
svg.setAttribute("height", "0")
|
|
1439
|
+
svg.setAttribute("aria-hidden", "true")
|
|
1440
|
+
svg.style.position = "absolute"
|
|
1441
|
+
svg.innerHTML = '<filter id="' + LIQUID_ID + '" x="0" y="0" width="100%" height="100%">'
|
|
1442
|
+
+ '<feTurbulence type="fractalNoise" baseFrequency="0.009 0.009" numOctaves="2" seed="7" result="noise"></feTurbulence>'
|
|
1443
|
+
+ '<feGaussianBlur in="noise" stdDeviation="1.6" result="soft"></feGaussianBlur>'
|
|
1444
|
+
+ '<feDisplacementMap in="SourceGraphic" in2="soft" scale="24"'
|
|
1445
|
+
+ ' xChannelSelector="R" yChannelSelector="G"></feDisplacementMap>'
|
|
1446
|
+
+ "</filter>"
|
|
1447
|
+
document.body.appendChild(svg)
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
const GLASS_LIGHT = "#ffffff"
|
|
1451
|
+
const GLASS_DARK = "#151517"
|
|
1452
|
+
let disposeGlass = null
|
|
1453
|
+
|
|
1454
|
+
function rgbaOf(hex, alpha) {
|
|
1455
|
+
const value = String(hex).replace("#", "")
|
|
1456
|
+
const n = Number.parseInt(value.length === 3
|
|
1457
|
+
? value.split("").map((c) => c + c).join("")
|
|
1458
|
+
: value, 16)
|
|
1459
|
+
const r = (n >> 16) & 255
|
|
1460
|
+
const g = (n >> 8) & 255
|
|
1461
|
+
const b = n & 255
|
|
1462
|
+
return "rgba(" + r + "," + g + "," + b + "," + alpha + ")"
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
function applyGlass() {
|
|
1466
|
+
if (disposeGlass !== null) {
|
|
1467
|
+
try { disposeGlass() } catch { /* 已随 fiber 回收 */ }
|
|
1468
|
+
disposeGlass = null
|
|
1469
|
+
}
|
|
1470
|
+
const theme = hostCtx === null ? null : hostCtx.theme
|
|
1471
|
+
if (theme === null || theme === undefined || typeof theme.overrideTokens !== "function") return
|
|
1472
|
+
if (state.theme !== true) return
|
|
1473
|
+
// 代码块要比其他面更实一点,否则深色代码看不清。
|
|
1474
|
+
const alpha = Number.isFinite(state.glassAlpha) ? Math.min(0.95, Math.max(0.25, state.glassAlpha)) : 0.55
|
|
1475
|
+
const tokens = {}
|
|
1476
|
+
for (const key of GLASS_TOKENS) {
|
|
1477
|
+
const a = key.indexOf("markdown") >= 0 ? Math.max(alpha, 0.7) : alpha
|
|
1478
|
+
tokens[key] = { light: rgbaOf(GLASS_LIGHT, a), dark: rgbaOf(GLASS_DARK, a) }
|
|
1479
|
+
}
|
|
1480
|
+
try {
|
|
1481
|
+
disposeGlass = theme.overrideTokens(GLASS_SOURCE, tokens)
|
|
1482
|
+
} catch (error) {
|
|
1483
|
+
log("warn", "液态玻璃 token 覆盖失败(宿主不认这组 key,已跳过)", error)
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1289
1487
|
function applySkin() {
|
|
1290
1488
|
if (!document.body) return;
|
|
1291
1489
|
document.body.setAttribute(SKIN_ATTR, state.theme ? "on" : "off");
|
|
1490
|
+
document.body.setAttribute("data-cyrene-glass", state.glassHeavy === true ? "heavy" : "off");
|
|
1491
|
+
if (state.theme === true && state.glassHeavy === true) ensureLiquidFilter();
|
|
1292
1492
|
const size = Number.isFinite(state.stickerSize) ? Math.round(state.stickerSize) : 96;
|
|
1293
1493
|
document.body.style.setProperty("--cyre-sticker-size", size + "px");
|
|
1294
1494
|
applyBackground();
|
|
1495
|
+
applyGlass();
|
|
1295
1496
|
}
|
|
1296
1497
|
|
|
1297
1498
|
/** 把设置页里点选的文件读成 data URL(FileReader 在渲染进程里是同步可用的)。 */
|
|
@@ -2321,6 +2522,8 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
2321
2522
|
'<label class="cyre-switch"><input type="checkbox" data-role="theme"><span>粉白毛玻璃主题</span></label>',
|
|
2322
2523
|
'<label class="cyre-switch"><input type="checkbox" data-role="stickers"><span>允许发表情包</span></label>',
|
|
2323
2524
|
'<label class="cyre-switch"><input type="checkbox" data-role="pet"><span>桌宠</span></label>',
|
|
2525
|
+
'<label class="cyre-switch"><input type="checkbox" data-role="glassHeavy"><span>液态玻璃 · 折射(开销大)</span></label>',
|
|
2526
|
+
'<label class="cyre-switch"><span>玻璃不透明度</span><input type="range" class="cyre-range" min="0.25" max="0.95" step="0.05" data-role="glassAlpha"><span data-role="glassAlphaVal">55%</span></label>',
|
|
2324
2527
|
'<span class="cyre-status" data-role="status"></span>',
|
|
2325
2528
|
"</div>",
|
|
2326
2529
|
'<p class="cyre-hint" data-role="pet-line">当前情绪:<span data-role="pet-emotion">平静</span>(只读,来自关系与情绪)</p>',
|
|
@@ -2355,6 +2558,19 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
2355
2558
|
'<button type="button" class="cyre-btn" data-role="open-worldbook">打开管理器</button>',
|
|
2356
2559
|
"</div>",
|
|
2357
2560
|
'<p class="cyre-hint">世界书是翁法罗斯的设定库(从官方 wiki 整理):常驻只占一行索引,模型要用 cyrene_worldbook_search 才会取正文。</p>',
|
|
2561
|
+
'<div class="cyre-card" data-role="usage-card">',
|
|
2562
|
+
'<div class="cyre-card-head"><span class="cyre-mark">✦</span><span>Token 用量</span></div>',
|
|
2563
|
+
'<div class="cyre-row" data-role="usage-head">',
|
|
2564
|
+
'<span class="cyre-ring" data-role="usage-ring" aria-hidden="true"></span>',
|
|
2565
|
+
'<span class="cyre-ring-label" data-role="usage-hit">—</span>',
|
|
2566
|
+
"</div>",
|
|
2567
|
+
'<div class="cyre-kv" data-role="usage-kv">读取中…</div>',
|
|
2568
|
+
'<div class="cyre-row">',
|
|
2569
|
+
'<button type="button" class="cyre-btn" data-role="usage-refresh">刷新</button>',
|
|
2570
|
+
'<button type="button" class="cyre-btn cyre-primary" data-role="usage-open">打开用量窗口</button>',
|
|
2571
|
+
'<span class="cyre-manager-status" data-role="usage-note"></span>',
|
|
2572
|
+
"</div>",
|
|
2573
|
+
"</div>",
|
|
2358
2574
|
'<div class="cyre-card" data-role="profile-card">',
|
|
2359
2575
|
'<div class="cyre-card-head"><span class="cyre-mark">✦</span><span>画像与关系</span></div>',
|
|
2360
2576
|
'<div class="cyre-kv" data-role="profile-kv"></div>',
|
|
@@ -2381,7 +2597,155 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
2381
2597
|
const themeBox = pick("theme");
|
|
2382
2598
|
const stickersBox = pick("stickers");
|
|
2383
2599
|
const petBox = pick("pet");
|
|
2600
|
+
const glassHeavyBox = pick("glassHeavy");
|
|
2601
|
+
const glassAlphaRange = pick("glassAlpha");
|
|
2602
|
+
const glassAlphaVal = pick("glassAlphaVal");
|
|
2384
2603
|
const petEmotionLine = pick("pet-emotion");
|
|
2604
|
+
// ── Token 用量 ────────────────────────────────────────────────
|
|
2605
|
+
// 数据来自宿主自己的 /api/session/list(每个会话的 tokenUsage 投影),
|
|
2606
|
+
// 我们只做展示:三段 token、缓存命中率、按 DeepSeek 公开价估算的花费。
|
|
2607
|
+
// 价格(元/百万 token,2026-11):未缓存输入 1、缓存命中 0.02、输出 4(闲时)/8(峰值)。
|
|
2608
|
+
const usageKv = pick("usage-kv");
|
|
2609
|
+
const usageNote = pick("usage-note");
|
|
2610
|
+
const usageRefresh = pick("usage-refresh");
|
|
2611
|
+
const usageRing = pick("usage-ring");
|
|
2612
|
+
const usageHit = pick("usage-hit");
|
|
2613
|
+
/**
|
|
2614
|
+
* 环形指标:和 Cyrene-Agent 的 ContextUsageRing 同一个视觉语言(20px 圆环、
|
|
2615
|
+
* 三档变色),但指标换成**缓存命中率**——DSH 不向插件暴露上下文窗口大小,
|
|
2616
|
+
* 拿不到"占满度";命中率是我们能算准的,而且对成本最直接。
|
|
2617
|
+
* 颜色语义反过来:命中率高是好事(主题色),低才暖/红。
|
|
2618
|
+
*/
|
|
2619
|
+
const RING_R = 8.5;
|
|
2620
|
+
const RING_C = 2 * Math.PI * RING_R;
|
|
2621
|
+
function paintRing(hit) {
|
|
2622
|
+
if (usageRing === null) return;
|
|
2623
|
+
const ratio = Math.max(0, Math.min(1, (Number(hit) || 0) / 100));
|
|
2624
|
+
const tier = hit >= 95 ? "" : hit >= 80 ? " warm" : " alert";
|
|
2625
|
+
usageRing.className = "cyre-ring" + tier;
|
|
2626
|
+
usageRing.innerHTML = '<svg viewBox="0 0 20 20" width="20" height="20">'
|
|
2627
|
+
+ '<circle cx="10" cy="10" r="' + RING_R + '" fill="none" stroke="currentColor"'
|
|
2628
|
+
+ ' stroke-opacity=".18" stroke-width="3"></circle>'
|
|
2629
|
+
+ '<circle cx="10" cy="10" r="' + RING_R + '" fill="none" stroke="currentColor"'
|
|
2630
|
+
+ ' stroke-width="3" stroke-linecap="round"'
|
|
2631
|
+
+ ' stroke-dasharray="' + RING_C.toFixed(2) + '"'
|
|
2632
|
+
+ ' stroke-dashoffset="' + (RING_C * (1 - ratio)).toFixed(2) + '"'
|
|
2633
|
+
+ ' transform="rotate(-90 10 10)"></circle></svg>';
|
|
2634
|
+
if (usageHit !== null) usageHit.textContent = (Number(hit) || 0).toFixed(1) + "% 命中";
|
|
2635
|
+
}
|
|
2636
|
+
const PRICE = { input: 1, cache: 0.02, output: 4, outputPeak: 8 };
|
|
2637
|
+
const fmt = (n) => {
|
|
2638
|
+
const v = Number(n ?? 0);
|
|
2639
|
+
if (v >= 1e6) return (v / 1e6).toFixed(2) + "M";
|
|
2640
|
+
if (v >= 1e3) return (v / 1e3).toFixed(1) + "k";
|
|
2641
|
+
return String(Math.round(v));
|
|
2642
|
+
};
|
|
2643
|
+
const money = (n) => "¥" + (n < 0.01 ? n.toFixed(4) : n.toFixed(2));
|
|
2644
|
+
const isPeak = () => {
|
|
2645
|
+
const now = new Date();
|
|
2646
|
+
const day = now.getDay();
|
|
2647
|
+
if (day === 0 || day === 6) return false;
|
|
2648
|
+
const hour = now.getHours();
|
|
2649
|
+
return (hour >= 9 && hour < 12) || (hour >= 14 && hour < 18);
|
|
2650
|
+
};
|
|
2651
|
+
async function readUsage() {
|
|
2652
|
+
if (typeof fetch !== "function") throw new Error("宿主没有 fetch");
|
|
2653
|
+
const response = await fetch(new URL("/api/session/list", document.baseURI).href, {
|
|
2654
|
+
method: "POST",
|
|
2655
|
+
headers: { "content-type": "application/json" },
|
|
2656
|
+
body: JSON.stringify({
|
|
2657
|
+
type: "client-request",
|
|
2658
|
+
rpcId: "cyrene-usage-" + String(Date.now()),
|
|
2659
|
+
method: "session/list",
|
|
2660
|
+
payload: { args: { _request: {} } },
|
|
2661
|
+
}),
|
|
2662
|
+
});
|
|
2663
|
+
const payload = await response.json().catch(() => null);
|
|
2664
|
+
const items = payload?.result?.value?.items ?? [];
|
|
2665
|
+
return items.map((item) => ({
|
|
2666
|
+
id: item.sessionId,
|
|
2667
|
+
usage: item?.projections?.values?.tokenUsage ?? null,
|
|
2668
|
+
}));
|
|
2669
|
+
}
|
|
2670
|
+
async function renderUsage() {
|
|
2671
|
+
if (usageKv === null) return;
|
|
2672
|
+
usageKv.textContent = "读取中…";
|
|
2673
|
+
if (usageNote !== null) usageNote.textContent = "";
|
|
2674
|
+
let rows = [];
|
|
2675
|
+
try {
|
|
2676
|
+
rows = await readUsage();
|
|
2677
|
+
} catch (error) {
|
|
2678
|
+
usageKv.textContent = "读取失败:" + (error?.message ?? String(error));
|
|
2679
|
+
return;
|
|
2680
|
+
}
|
|
2681
|
+
const sum = { unc: 0, cache: 0, out: 0 };
|
|
2682
|
+
for (const row of rows) {
|
|
2683
|
+
if (row.usage === null) continue;
|
|
2684
|
+
sum.unc += Number(row.usage.uncachedInputTokens ?? 0);
|
|
2685
|
+
sum.cache += Number(row.usage.cacheReadTokens ?? 0);
|
|
2686
|
+
sum.out += Number(row.usage.outputTokens ?? 0);
|
|
2687
|
+
}
|
|
2688
|
+
// 测试用的 DOM 桩不一定有 querySelector,取不到就当"没有当前会话",不影响总量展示。
|
|
2689
|
+
let currentId = "";
|
|
2690
|
+
try {
|
|
2691
|
+
const holder = typeof document.querySelector === "function"
|
|
2692
|
+
? document.querySelector("[data-conversation-session]")
|
|
2693
|
+
: null;
|
|
2694
|
+
currentId = holder === null ? "" : String(holder.getAttribute("data-conversation-session") ?? "");
|
|
2695
|
+
} catch {
|
|
2696
|
+
currentId = "";
|
|
2697
|
+
}
|
|
2698
|
+
const current = rows.find((row) => row.id === currentId && row.usage !== null);
|
|
2699
|
+
const one = (usage) => {
|
|
2700
|
+
const unc = Number(usage.uncachedInputTokens ?? 0);
|
|
2701
|
+
const cache = Number(usage.cacheReadTokens ?? 0);
|
|
2702
|
+
const out = Number(usage.outputTokens ?? 0);
|
|
2703
|
+
const total = unc + cache;
|
|
2704
|
+
const hit = total === 0 ? 0 : (cache / total) * 100;
|
|
2705
|
+
const peak = isPeak();
|
|
2706
|
+
const cost = (unc / 1e6) * PRICE.input + (cache / 1e6) * PRICE.cache
|
|
2707
|
+
+ (out / 1e6) * (peak ? PRICE.outputPeak : PRICE.output);
|
|
2708
|
+
return { unc, cache, out, hit, cost, peak };
|
|
2709
|
+
};
|
|
2710
|
+
const lines = [];
|
|
2711
|
+
if (current !== undefined) {
|
|
2712
|
+
const m = one(current.usage);
|
|
2713
|
+
lines.push("本次会话 输入 " + fmt(m.unc) + " · 缓存 " + fmt(m.cache) + " · 输出 " + fmt(m.out));
|
|
2714
|
+
lines.push("缓存命中 " + m.hit.toFixed(1) + "%");
|
|
2715
|
+
lines.push("估算花费 " + money(m.cost) + (m.peak ? "(峰值价)" : "(闲时价)"));
|
|
2716
|
+
lines.push("");
|
|
2717
|
+
}
|
|
2718
|
+
const all = one(sum);
|
|
2719
|
+
lines.push("全部会话 输入 " + fmt(all.unc) + " · 缓存 " + fmt(all.cache) + " · 输出 " + fmt(all.out));
|
|
2720
|
+
lines.push("缓存命中 " + all.hit.toFixed(1) + "%");
|
|
2721
|
+
lines.push("估算花费 " + money(all.cost) + "(" + rows.filter((r) => r.usage !== null).length + " 个会话)");
|
|
2722
|
+
usageKv.textContent = lines.join("\n");
|
|
2723
|
+
paintRing(all.hit);
|
|
2724
|
+
if (usageNote !== null) {
|
|
2725
|
+
usageNote.textContent = "按 DeepSeek 公开价估算,含缓存折扣";
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
if (usageRefresh !== null) {
|
|
2729
|
+
usageRefresh.addEventListener("click", () => { void renderUsage(); });
|
|
2730
|
+
}
|
|
2731
|
+
// 独立窗口:和 Cyrene-Agent 的用量查看器一样是单独一扇 GUI。
|
|
2732
|
+
// 液态玻璃也只有在那种自带背景的页面上才看得出来。
|
|
2733
|
+
const usageOpen = pick("usage-open");
|
|
2734
|
+
if (usageOpen !== null) {
|
|
2735
|
+
usageOpen.addEventListener("click", () => {
|
|
2736
|
+
try {
|
|
2737
|
+
window.open(new URL("cyrene/usage", document.baseURI).href, "cyrene-usage",
|
|
2738
|
+
"width=480,height=640,menubar=no,toolbar=no,location=no,status=no");
|
|
2739
|
+
} catch (error) {
|
|
2740
|
+
log("warn", "打开用量窗口失败", error);
|
|
2741
|
+
}
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
if (typeof fetch === "function") {
|
|
2745
|
+
void renderUsage();
|
|
2746
|
+
} else if (usageKv !== null) {
|
|
2747
|
+
usageKv.textContent = "这个宿主没有 fetch,读不到用量。";
|
|
2748
|
+
}
|
|
2385
2749
|
const stickerSummary = pick("sticker-summary");
|
|
2386
2750
|
const status = pick("status");
|
|
2387
2751
|
const bgNote = pick("bg-note");
|
|
@@ -2540,6 +2904,12 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
2540
2904
|
themeBox.checked = state.theme;
|
|
2541
2905
|
stickersBox.checked = state.stickers !== false;
|
|
2542
2906
|
petBox.checked = state.pet === true;
|
|
2907
|
+
if (glassHeavyBox !== null) glassHeavyBox.checked = state.glassHeavy === true;
|
|
2908
|
+
if (glassAlphaRange !== null) {
|
|
2909
|
+
const alpha = Number.isFinite(state.glassAlpha) ? state.glassAlpha : 0.55;
|
|
2910
|
+
glassAlphaRange.value = String(alpha);
|
|
2911
|
+
if (glassAlphaVal !== null) glassAlphaVal.textContent = Math.round(alpha * 100) + "%";
|
|
2912
|
+
}
|
|
2543
2913
|
// 只读行:显示关系管线算出来的主导情绪;桌宠关着也照样更新(方便先看再开)。
|
|
2544
2914
|
petEmotionLine.textContent = petEmotion.dimension === null
|
|
2545
2915
|
? "平静"
|
|
@@ -2597,6 +2967,15 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
2597
2967
|
});
|
|
2598
2968
|
petBox.addEventListener("change", () => {
|
|
2599
2969
|
void save({ pet: petBox.checked }).then(paint);
|
|
2970
|
+
if (glassHeavyBox !== null) glassHeavyBox.addEventListener("change", () => {
|
|
2971
|
+
void save({ glassHeavy: glassHeavyBox.checked }).then(paint);
|
|
2972
|
+
});
|
|
2973
|
+
if (glassAlphaRange !== null) glassAlphaRange.addEventListener("input", () => {
|
|
2974
|
+
if (glassAlphaVal !== null) glassAlphaVal.textContent = Math.round(Number(glassAlphaRange.value) * 100) + "%";
|
|
2975
|
+
});
|
|
2976
|
+
if (glassAlphaRange !== null) glassAlphaRange.addEventListener("change", () => {
|
|
2977
|
+
void save({ glassAlpha: Number(glassAlphaRange.value) }).then(paint);
|
|
2978
|
+
});
|
|
2600
2979
|
});
|
|
2601
2980
|
|
|
2602
2981
|
// 状态筛选只重画卡片,不发请求(筛选是纯本地的)。
|
package/lib/index.js
CHANGED
|
@@ -92,6 +92,193 @@ const PACKAGE_ID = 'dsh-cyrene-theme-change'
|
|
|
92
92
|
const SECTION_NAME = 'cyrene:persona'
|
|
93
93
|
/** fenced 路由前缀;客户端半请求 <base>/cyrene/state。 */
|
|
94
94
|
const ROUTE_PREFIX = '/cyrene'
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 「用量」独立窗口(GET /cyrene/usage)。
|
|
98
|
+
*
|
|
99
|
+
* 为什么单独一页而不是塞在设置面板里:
|
|
100
|
+
* 1. Cyrene-Agent 的用量查看器本身就是一扇独立 GUI;
|
|
101
|
+
* 2. 液态玻璃需要**背后有内容**才能看出来——设置面板背后是不透明底色,
|
|
102
|
+
* 玻璃只会变成一块磨砂色块。这一页自带渐变背景,玻璃才立得住。
|
|
103
|
+
*
|
|
104
|
+
* 数据:页面自己向宿主 /api/session/list 取(同源,带登录 cookie)。
|
|
105
|
+
* 价格:DeepSeek 公开价,未缓存输入 1 / 缓存命中 0.02 / 输出 4(闲时)8(峰值)元每百万。
|
|
106
|
+
*/
|
|
107
|
+
const USAGE_PAGE_HTML = `<!doctype html>
|
|
108
|
+
<html lang="zh-CN"><head><meta charset="utf-8">
|
|
109
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
110
|
+
<title>昔涟 · Token 用量</title>
|
|
111
|
+
<style>
|
|
112
|
+
:root{color-scheme:light dark}
|
|
113
|
+
*{box-sizing:border-box}
|
|
114
|
+
body{
|
|
115
|
+
margin:0;min-height:100vh;padding:18px;
|
|
116
|
+
font:13px/1.6 system-ui,-apple-system,"PingFang SC",sans-serif;
|
|
117
|
+
color:#3f2d3a;
|
|
118
|
+
background:
|
|
119
|
+
radial-gradient(1200px 600px at 12% -10%,#ffd9ec 0%,transparent 60%),
|
|
120
|
+
radial-gradient(900px 500px at 100% 0%,#d7e6ff 0%,transparent 55%),
|
|
121
|
+
radial-gradient(800px 700px at 50% 120%,#ffe9f3 0%,transparent 60%),
|
|
122
|
+
linear-gradient(160deg,#fdf7fb 0%,#f4f7ff 48%,#fff5f9 100%);
|
|
123
|
+
background-attachment:fixed;
|
|
124
|
+
}
|
|
125
|
+
.wrap{max-width:560px;margin:0 auto;display:flex;flex-direction:column;gap:14px}
|
|
126
|
+
.card{
|
|
127
|
+
position:relative;border-radius:20px;padding:16px 18px;
|
|
128
|
+
background:linear-gradient(135deg,rgba(255,255,255,.62),rgba(255,255,255,.28) 46%,rgba(255,255,255,.5));
|
|
129
|
+
border:1px solid rgba(255,255,255,.75);
|
|
130
|
+
box-shadow:
|
|
131
|
+
inset 0 1px 0 rgba(255,255,255,.95),
|
|
132
|
+
inset 0 -1px 0 rgba(255,255,255,.35),
|
|
133
|
+
0 10px 30px rgba(178,120,160,.16);
|
|
134
|
+
backdrop-filter:blur(22px) saturate(180%);
|
|
135
|
+
-webkit-backdrop-filter:blur(22px) saturate(180%);
|
|
136
|
+
}
|
|
137
|
+
.head{display:flex;align-items:center;gap:10px;font-weight:600;font-size:13.5px;letter-spacing:.3px}
|
|
138
|
+
.head .dot{color:#e8699f}
|
|
139
|
+
.hero{display:flex;align-items:center;gap:16px}
|
|
140
|
+
.ring{flex:0 0 auto;color:#e8699f}
|
|
141
|
+
.ring.warm{color:#e8a33d}.ring.alert{color:#e0575b}
|
|
142
|
+
.pct{font-size:30px;font-weight:700;line-height:1;font-variant-numeric:tabular-nums}
|
|
143
|
+
.sub{font-size:11.5px;opacity:.62;margin-top:4px}
|
|
144
|
+
.rows{display:flex;flex-direction:column;gap:6px;margin-top:10px}
|
|
145
|
+
.row{display:flex;justify-content:space-between;gap:12px;font-variant-numeric:tabular-nums}
|
|
146
|
+
.row span:first-child{opacity:.66}
|
|
147
|
+
.bar{height:6px;border-radius:999px;background:rgba(200,150,180,.22);overflow:hidden;display:flex;margin-top:10px}
|
|
148
|
+
.bar i{display:block;height:100%}
|
|
149
|
+
.legend{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:11.5px;opacity:.7}
|
|
150
|
+
.legend b{font-weight:600}
|
|
151
|
+
.hint{font-size:11.5px;opacity:.55;text-align:center}
|
|
152
|
+
@media (prefers-color-scheme:dark){
|
|
153
|
+
body{color:#f4e7ef;background:
|
|
154
|
+
radial-gradient(1200px 600px at 12% -10%,#4a2740 0%,transparent 60%),
|
|
155
|
+
radial-gradient(900px 500px at 100% 0%,#22324f 0%,transparent 55%),
|
|
156
|
+
linear-gradient(160deg,#211723 0%,#1a1f2b 50%,#241a24 100%)}
|
|
157
|
+
.card{background:linear-gradient(135deg,rgba(58,40,54,.66),rgba(40,32,46,.42) 46%,rgba(58,42,56,.58));
|
|
158
|
+
border-color:rgba(255,255,255,.16);
|
|
159
|
+
box-shadow:inset 0 1px 0 rgba(255,255,255,.18),inset 0 -1px 0 rgba(255,255,255,.05),0 10px 30px rgba(0,0,0,.42)}
|
|
160
|
+
.ring{color:#f19fc6}
|
|
161
|
+
}
|
|
162
|
+
</style></head>
|
|
163
|
+
<body><div class="wrap">
|
|
164
|
+
|
|
165
|
+
<div class="card">
|
|
166
|
+
<div class="head"><span class="dot">✦</span><span>缓存命中率</span></div>
|
|
167
|
+
<div class="hero">
|
|
168
|
+
<span class="ring" id="ring"></span>
|
|
169
|
+
<div>
|
|
170
|
+
<div class="pct" id="pct">—</div>
|
|
171
|
+
<div class="sub" id="hitsub">全部会话</div>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
<div class="bar" id="bar"><i id="barCache"></i><i id="barUnc"></i></div>
|
|
175
|
+
<div class="legend">
|
|
176
|
+
<span><b id="lgCache">0</b> 缓存读取</span>
|
|
177
|
+
<span><b id="lgUnc">0</b> 未缓存</span>
|
|
178
|
+
<span><b id="lgOut">0</b> 输出</span>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<div class="card">
|
|
183
|
+
<div class="head"><span class="dot">✦</span><span>估算花费</span></div>
|
|
184
|
+
<div class="rows">
|
|
185
|
+
<div class="row"><span>本次会话</span><b id="costCur">—</b></div>
|
|
186
|
+
<div class="row"><span>全部会话</span><b id="costAll">—</b></div>
|
|
187
|
+
<div class="row"><span>计价档</span><b id="tier">—</b></div>
|
|
188
|
+
</div>
|
|
189
|
+
<div class="sub" id="note">按 DeepSeek 公开价估算:未缓存 1 / 缓存 0.02 / 输出 4(闲时)8(峰值)元每百万 token</div>
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<div class="hint" id="stamp">读取中…</div>
|
|
193
|
+
</div>
|
|
194
|
+
<script>
|
|
195
|
+
(function () {
|
|
196
|
+
var PRICE = { input: 1, cache: 0.02, out: 4, outPeak: 8 };
|
|
197
|
+
var RING_R = 26, RING_C = 2 * Math.PI * RING_R;
|
|
198
|
+
|
|
199
|
+
function fmt(n) {
|
|
200
|
+
n = Number(n || 0);
|
|
201
|
+
if (n >= 1e6) return (n / 1e6).toFixed(2) + "M";
|
|
202
|
+
if (n >= 1e3) return (n / 1e3).toFixed(1) + "k";
|
|
203
|
+
return String(Math.round(n));
|
|
204
|
+
}
|
|
205
|
+
function money(n) { return "¥" + (n < 0.01 ? n.toFixed(4) : n.toFixed(2)); }
|
|
206
|
+
function peak() {
|
|
207
|
+
var d = new Date(), day = d.getDay(), h = d.getHours();
|
|
208
|
+
if (day === 0 || day === 6) return false;
|
|
209
|
+
return (h >= 9 && h < 12) || (h >= 14 && h < 18);
|
|
210
|
+
}
|
|
211
|
+
function paintRing(hit) {
|
|
212
|
+
var ratio = Math.max(0, Math.min(1, (Number(hit) || 0) / 100));
|
|
213
|
+
var el = document.getElementById("ring");
|
|
214
|
+
el.className = "ring" + (hit >= 95 ? "" : hit >= 80 ? " warm" : " alert");
|
|
215
|
+
el.innerHTML = '<svg width="76" height="76" viewBox="0 0 64 64">'
|
|
216
|
+
+ '<circle cx="32" cy="32" r="' + RING_R + '" fill="none" stroke="currentColor" stroke-opacity=".16" stroke-width="6"></circle>'
|
|
217
|
+
+ '<circle cx="32" cy="32" r="' + RING_R + '" fill="none" stroke="currentColor" stroke-width="6" stroke-linecap="round"'
|
|
218
|
+
+ ' stroke-dasharray="' + RING_C.toFixed(2) + '" stroke-dashoffset="' + (RING_C * (1 - ratio)).toFixed(2) + '"'
|
|
219
|
+
+ ' transform="rotate(-90 32 32)"></circle></svg>';
|
|
220
|
+
}
|
|
221
|
+
function rpc() {
|
|
222
|
+
return fetch("/api/session/list", {
|
|
223
|
+
method: "POST",
|
|
224
|
+
headers: { "content-type": "application/json" },
|
|
225
|
+
credentials: "same-origin",
|
|
226
|
+
body: JSON.stringify({
|
|
227
|
+
type: "client-request", rpcId: "usage-" + Date.now(),
|
|
228
|
+
method: "session/list", payload: { args: { _request: {} } }
|
|
229
|
+
})
|
|
230
|
+
}).then(function (r) { return r.json(); });
|
|
231
|
+
}
|
|
232
|
+
function sumOf(items) {
|
|
233
|
+
var s = { unc: 0, cache: 0, out: 0 };
|
|
234
|
+
items.forEach(function (it) {
|
|
235
|
+
var u = it && it.projections && it.projections.values && it.projections.values.tokenUsage;
|
|
236
|
+
if (!u) return;
|
|
237
|
+
s.unc += Number(u.uncachedInputTokens || 0);
|
|
238
|
+
s.cache += Number(u.cacheReadTokens || 0);
|
|
239
|
+
s.out += Number(u.outputTokens || 0);
|
|
240
|
+
});
|
|
241
|
+
return s;
|
|
242
|
+
}
|
|
243
|
+
function costOf(s) {
|
|
244
|
+
var p = peak();
|
|
245
|
+
return (s.unc / 1e6) * PRICE.input + (s.cache / 1e6) * PRICE.cache + (s.out / 1e6) * (p ? PRICE.outPeak : PRICE.out);
|
|
246
|
+
}
|
|
247
|
+
function refresh() {
|
|
248
|
+
rpc().then(function (payload) {
|
|
249
|
+
var items = (payload && payload.result && payload.result.value && payload.result.value.items) || [];
|
|
250
|
+
var all = sumOf(items);
|
|
251
|
+
var total = all.unc + all.cache;
|
|
252
|
+
var hit = total === 0 ? 0 : (all.cache / total) * 100;
|
|
253
|
+
paintRing(hit);
|
|
254
|
+
document.getElementById("pct").textContent = hit.toFixed(1) + "%";
|
|
255
|
+
document.getElementById("hitsub").textContent = items.length + " 个会话 · 未缓存 " + fmt(all.unc);
|
|
256
|
+
document.getElementById("lgCache").textContent = fmt(all.cache);
|
|
257
|
+
document.getElementById("lgUnc").textContent = fmt(all.unc);
|
|
258
|
+
document.getElementById("lgOut").textContent = fmt(all.out);
|
|
259
|
+
var bar = document.getElementById("bar");
|
|
260
|
+
bar.children[0].style.width = (total === 0 ? 0 : (all.cache / total) * 100) + "%";
|
|
261
|
+
bar.children[0].style.background = "linear-gradient(90deg,#f9a8d4,#e8699f)";
|
|
262
|
+
bar.children[1].style.width = (total === 0 ? 0 : (all.unc / total) * 100) + "%";
|
|
263
|
+
bar.children[1].style.background = "rgba(160,120,150,.35)";
|
|
264
|
+
document.getElementById("costAll").textContent = money(costOf(all));
|
|
265
|
+
var cur = document.getElementById("costCur");
|
|
266
|
+
var holder = window.opener && window.opener.document
|
|
267
|
+
? window.opener.document.querySelector("[data-conversation-session]") : null;
|
|
268
|
+
var sid = holder ? holder.getAttribute("data-conversation-session") : "";
|
|
269
|
+
var mine = items.filter(function (it) { return it.sessionId === sid; });
|
|
270
|
+
if (mine.length > 0) cur.textContent = money(costOf(sumOf(mine)));
|
|
271
|
+
else cur.textContent = "(切换回主窗口刷新)";
|
|
272
|
+
document.getElementById("tier").textContent = peak() ? "峰值(工作日 9-12 / 14-18)" : "闲时";
|
|
273
|
+
document.getElementById("stamp").textContent = "更新于 " + new Date().toLocaleTimeString() + " · 每 5 秒自动刷新";
|
|
274
|
+
}).catch(function (e) {
|
|
275
|
+
document.getElementById("stamp").textContent = "读取失败:" + e.message;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
refresh();
|
|
279
|
+
setInterval(refresh, 5000);
|
|
280
|
+
})();
|
|
281
|
+
</script></body></html>`
|
|
95
282
|
/** 请求体上限,防止一次误粘贴把提示词写爆。 */
|
|
96
283
|
const MAX_BODY_BYTES = 256 * 1024
|
|
97
284
|
|
|
@@ -261,6 +448,14 @@ const state = {
|
|
|
261
448
|
* 这是纯前端展示开关,关掉只卸 canvas,不影响记忆与关系。
|
|
262
449
|
*/
|
|
263
450
|
pet: false,
|
|
451
|
+
/**
|
|
452
|
+
* 液态玻璃的不透明度(0.25–0.95,数字越大越实)。
|
|
453
|
+
* 走宿主 ctx.theme.overrideTokens 把面色 token 换成 rgba,不做模糊——
|
|
454
|
+
* backdrop-filter 会创建 containing block,把设置弹窗和浮层搞坏。
|
|
455
|
+
*/
|
|
456
|
+
glassAlpha: 0.55,
|
|
457
|
+
/** 真·液态玻璃(SVG 位移折射)。开销大,默认关。 */
|
|
458
|
+
glassHeavy: false,
|
|
264
459
|
/** 聊天里贴图的最大边长(px):客户端半把它落到 CSS 变量上。 */
|
|
265
460
|
stickerSize: 96,
|
|
266
461
|
/**
|
|
@@ -546,6 +741,17 @@ function applyPatch(patch) {
|
|
|
546
741
|
state.pet = patch.pet
|
|
547
742
|
changed = true
|
|
548
743
|
}
|
|
744
|
+
if (typeof patch.glassHeavy === 'boolean' && patch.glassHeavy !== state.glassHeavy) {
|
|
745
|
+
state.glassHeavy = patch.glassHeavy
|
|
746
|
+
changed = true
|
|
747
|
+
}
|
|
748
|
+
if (Number.isFinite(patch.glassAlpha)) {
|
|
749
|
+
const alpha = Math.min(0.95, Math.max(0.25, Number(patch.glassAlpha)))
|
|
750
|
+
if (alpha !== state.glassAlpha) {
|
|
751
|
+
state.glassAlpha = alpha
|
|
752
|
+
changed = true
|
|
753
|
+
}
|
|
754
|
+
}
|
|
549
755
|
if (Number.isFinite(patch.stickerSize)) {
|
|
550
756
|
const size = clampStickerSize(patch.stickerSize)
|
|
551
757
|
if (size !== state.stickerSize) {
|
|
@@ -623,6 +829,8 @@ function persist(ctx) {
|
|
|
623
829
|
theme: state.theme,
|
|
624
830
|
stickers: state.stickers,
|
|
625
831
|
pet: state.pet,
|
|
832
|
+
glassAlpha: state.glassAlpha,
|
|
833
|
+
glassHeavy: state.glassHeavy,
|
|
626
834
|
stickerSize: state.stickerSize,
|
|
627
835
|
customStickers: state.customStickers.map((entry) => ({ ...entry })),
|
|
628
836
|
customBackgrounds: state.customBackgrounds.map((entry) => ({ ...entry })),
|
|
@@ -3043,6 +3251,16 @@ export function apply(ctx, config) {
|
|
|
3043
3251
|
const url = new URL(req.url ?? '/', 'http://localhost')
|
|
3044
3252
|
const route = url.pathname.slice(ROUTE_PREFIX.length) || '/'
|
|
3045
3253
|
try {
|
|
3254
|
+
if (route === '/usage' && req.method === 'GET') {
|
|
3255
|
+
// 独立的「用量」窗口:Cyrene-Agent 是单独一扇 GUI,这里也做成独立页,
|
|
3256
|
+
// 顺便解决液态玻璃在没有背景的面板里看不出来的问题(这页自带渐变背景)。
|
|
3257
|
+
res.writeHead(200, {
|
|
3258
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
3259
|
+
'Cache-Control': 'no-store',
|
|
3260
|
+
})
|
|
3261
|
+
res.end(USAGE_PAGE_HTML)
|
|
3262
|
+
return
|
|
3263
|
+
}
|
|
3046
3264
|
if (route === '/state' && req.method === 'GET') {
|
|
3047
3265
|
await Promise.all([ensureLoaded(ctx), ensureHero(ctx)])
|
|
3048
3266
|
sendJson(res, 200, { ok: true, value: publicState() })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cyrene-theme-change",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "昔涟(Cyrene)主题:粉白渐变毛玻璃 UI + 侧边栏可编辑的人格设定 + 表情包 / 背景图 / 世界书 + 认知记忆(L0/L1/L2 分层、成色衰减、语义召回、账本与健康行、压缩反思)与关系情绪 | A Cyrene (Honkai: Star Rail) theme for DeepSeek Harness",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|