dsh-cyrene-theme-change 0.9.0 → 0.10.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/lib/client.js +138 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -847,6 +847,30 @@ 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%);
|
|
864
|
+
}
|
|
865
|
+
@supports not (backdrop-filter:blur(1px)){
|
|
866
|
+
.cyre-card{background-image:none}
|
|
867
|
+
}
|
|
868
|
+
/* 深色皮肤下内高光要收敛,否则整块发白发灰。 */
|
|
869
|
+
body[data-dsh-cyrene][data-cyrene-skin="on"] .cyre-card{
|
|
870
|
+
box-shadow:
|
|
871
|
+
inset 0 1px 0 rgba(255,255,255,.14),
|
|
872
|
+
inset 0 -1px 0 rgba(255,255,255,.05),
|
|
873
|
+
0 6px 22px rgba(0,0,0,.28);
|
|
850
874
|
}
|
|
851
875
|
.cyre-card-head{
|
|
852
876
|
display:flex;align-items:center;gap:8px;
|
|
@@ -2355,6 +2379,14 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
2355
2379
|
'<button type="button" class="cyre-btn" data-role="open-worldbook">打开管理器</button>',
|
|
2356
2380
|
"</div>",
|
|
2357
2381
|
'<p class="cyre-hint">世界书是翁法罗斯的设定库(从官方 wiki 整理):常驻只占一行索引,模型要用 cyrene_worldbook_search 才会取正文。</p>',
|
|
2382
|
+
'<div class="cyre-card" data-role="usage-card">',
|
|
2383
|
+
'<div class="cyre-card-head"><span class="cyre-mark">✦</span><span>Token 用量</span></div>',
|
|
2384
|
+
'<div class="cyre-kv" data-role="usage-kv">读取中…</div>',
|
|
2385
|
+
'<div class="cyre-row">',
|
|
2386
|
+
'<button type="button" class="cyre-btn" data-role="usage-refresh">刷新</button>',
|
|
2387
|
+
'<span class="cyre-manager-status" data-role="usage-note"></span>',
|
|
2388
|
+
"</div>",
|
|
2389
|
+
"</div>",
|
|
2358
2390
|
'<div class="cyre-card" data-role="profile-card">',
|
|
2359
2391
|
'<div class="cyre-card-head"><span class="cyre-mark">✦</span><span>画像与关系</span></div>',
|
|
2360
2392
|
'<div class="cyre-kv" data-role="profile-kv"></div>',
|
|
@@ -2382,6 +2414,112 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
|
|
|
2382
2414
|
const stickersBox = pick("stickers");
|
|
2383
2415
|
const petBox = pick("pet");
|
|
2384
2416
|
const petEmotionLine = pick("pet-emotion");
|
|
2417
|
+
// ── Token 用量 ────────────────────────────────────────────────
|
|
2418
|
+
// 数据来自宿主自己的 /api/session/list(每个会话的 tokenUsage 投影),
|
|
2419
|
+
// 我们只做展示:三段 token、缓存命中率、按 DeepSeek 公开价估算的花费。
|
|
2420
|
+
// 价格(元/百万 token,2026-11):未缓存输入 1、缓存命中 0.02、输出 4(闲时)/8(峰值)。
|
|
2421
|
+
const usageKv = pick("usage-kv");
|
|
2422
|
+
const usageNote = pick("usage-note");
|
|
2423
|
+
const usageRefresh = pick("usage-refresh");
|
|
2424
|
+
const PRICE = { input: 1, cache: 0.02, output: 4, outputPeak: 8 };
|
|
2425
|
+
const fmt = (n) => {
|
|
2426
|
+
const v = Number(n ?? 0);
|
|
2427
|
+
if (v >= 1e6) return (v / 1e6).toFixed(2) + "M";
|
|
2428
|
+
if (v >= 1e3) return (v / 1e3).toFixed(1) + "k";
|
|
2429
|
+
return String(Math.round(v));
|
|
2430
|
+
};
|
|
2431
|
+
const money = (n) => "¥" + (n < 0.01 ? n.toFixed(4) : n.toFixed(2));
|
|
2432
|
+
const isPeak = () => {
|
|
2433
|
+
const now = new Date();
|
|
2434
|
+
const day = now.getDay();
|
|
2435
|
+
if (day === 0 || day === 6) return false;
|
|
2436
|
+
const hour = now.getHours();
|
|
2437
|
+
return (hour >= 9 && hour < 12) || (hour >= 14 && hour < 18);
|
|
2438
|
+
};
|
|
2439
|
+
async function readUsage() {
|
|
2440
|
+
if (typeof fetch !== "function") throw new Error("宿主没有 fetch");
|
|
2441
|
+
const response = await fetch(new URL("/api/session/list", document.baseURI).href, {
|
|
2442
|
+
method: "POST",
|
|
2443
|
+
headers: { "content-type": "application/json" },
|
|
2444
|
+
body: JSON.stringify({
|
|
2445
|
+
type: "client-request",
|
|
2446
|
+
rpcId: "cyrene-usage-" + String(Date.now()),
|
|
2447
|
+
method: "session/list",
|
|
2448
|
+
payload: { args: { _request: {} } },
|
|
2449
|
+
}),
|
|
2450
|
+
});
|
|
2451
|
+
const payload = await response.json().catch(() => null);
|
|
2452
|
+
const items = payload?.result?.value?.items ?? [];
|
|
2453
|
+
return items.map((item) => ({
|
|
2454
|
+
id: item.sessionId,
|
|
2455
|
+
usage: item?.projections?.values?.tokenUsage ?? null,
|
|
2456
|
+
}));
|
|
2457
|
+
}
|
|
2458
|
+
async function renderUsage() {
|
|
2459
|
+
if (usageKv === null) return;
|
|
2460
|
+
usageKv.textContent = "读取中…";
|
|
2461
|
+
if (usageNote !== null) usageNote.textContent = "";
|
|
2462
|
+
let rows = [];
|
|
2463
|
+
try {
|
|
2464
|
+
rows = await readUsage();
|
|
2465
|
+
} catch (error) {
|
|
2466
|
+
usageKv.textContent = "读取失败:" + (error?.message ?? String(error));
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2469
|
+
const sum = { unc: 0, cache: 0, out: 0 };
|
|
2470
|
+
for (const row of rows) {
|
|
2471
|
+
if (row.usage === null) continue;
|
|
2472
|
+
sum.unc += Number(row.usage.uncachedInputTokens ?? 0);
|
|
2473
|
+
sum.cache += Number(row.usage.cacheReadTokens ?? 0);
|
|
2474
|
+
sum.out += Number(row.usage.outputTokens ?? 0);
|
|
2475
|
+
}
|
|
2476
|
+
// 测试用的 DOM 桩不一定有 querySelector,取不到就当"没有当前会话",不影响总量展示。
|
|
2477
|
+
let currentId = "";
|
|
2478
|
+
try {
|
|
2479
|
+
const holder = typeof document.querySelector === "function"
|
|
2480
|
+
? document.querySelector("[data-conversation-session]")
|
|
2481
|
+
: null;
|
|
2482
|
+
currentId = holder === null ? "" : String(holder.getAttribute("data-conversation-session") ?? "");
|
|
2483
|
+
} catch {
|
|
2484
|
+
currentId = "";
|
|
2485
|
+
}
|
|
2486
|
+
const current = rows.find((row) => row.id === currentId && row.usage !== null);
|
|
2487
|
+
const one = (usage) => {
|
|
2488
|
+
const unc = Number(usage.uncachedInputTokens ?? 0);
|
|
2489
|
+
const cache = Number(usage.cacheReadTokens ?? 0);
|
|
2490
|
+
const out = Number(usage.outputTokens ?? 0);
|
|
2491
|
+
const total = unc + cache;
|
|
2492
|
+
const hit = total === 0 ? 0 : (cache / total) * 100;
|
|
2493
|
+
const peak = isPeak();
|
|
2494
|
+
const cost = (unc / 1e6) * PRICE.input + (cache / 1e6) * PRICE.cache
|
|
2495
|
+
+ (out / 1e6) * (peak ? PRICE.outputPeak : PRICE.output);
|
|
2496
|
+
return { unc, cache, out, hit, cost, peak };
|
|
2497
|
+
};
|
|
2498
|
+
const lines = [];
|
|
2499
|
+
if (current !== undefined) {
|
|
2500
|
+
const m = one(current.usage);
|
|
2501
|
+
lines.push("本次会话 输入 " + fmt(m.unc) + " · 缓存 " + fmt(m.cache) + " · 输出 " + fmt(m.out));
|
|
2502
|
+
lines.push("缓存命中 " + m.hit.toFixed(1) + "%");
|
|
2503
|
+
lines.push("估算花费 " + money(m.cost) + (m.peak ? "(峰值价)" : "(闲时价)"));
|
|
2504
|
+
lines.push("");
|
|
2505
|
+
}
|
|
2506
|
+
const all = one(sum);
|
|
2507
|
+
lines.push("全部会话 输入 " + fmt(all.unc) + " · 缓存 " + fmt(all.cache) + " · 输出 " + fmt(all.out));
|
|
2508
|
+
lines.push("缓存命中 " + all.hit.toFixed(1) + "%");
|
|
2509
|
+
lines.push("估算花费 " + money(all.cost) + "(" + rows.filter((r) => r.usage !== null).length + " 个会话)");
|
|
2510
|
+
usageKv.textContent = lines.join("\n");
|
|
2511
|
+
if (usageNote !== null) {
|
|
2512
|
+
usageNote.textContent = "按 DeepSeek 公开价估算,含缓存折扣";
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
if (usageRefresh !== null) {
|
|
2516
|
+
usageRefresh.addEventListener("click", () => { void renderUsage(); });
|
|
2517
|
+
}
|
|
2518
|
+
if (typeof fetch === "function") {
|
|
2519
|
+
void renderUsage();
|
|
2520
|
+
} else if (usageKv !== null) {
|
|
2521
|
+
usageKv.textContent = "这个宿主没有 fetch,读不到用量。";
|
|
2522
|
+
}
|
|
2385
2523
|
const stickerSummary = pick("sticker-summary");
|
|
2386
2524
|
const status = pick("status");
|
|
2387
2525
|
const bgNote = pick("bg-note");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cyrene-theme-change",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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",
|