dsh-message-actions 0.2.1 → 0.2.2
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 +1933 -232
- package/lib/index.js +445 -55
- package/lib/shared.cjs +613 -26
- package/lib/store.cjs +13 -8
- package/package.json +1 -1
- package/LICENSE +0 -21
- package/README.cn.md +0 -250
- package/README.md +0 -250
package/lib/client.js
CHANGED
|
@@ -70,6 +70,9 @@ const ERROR_LABELS = {
|
|
|
70
70
|
INVALID_AMOUNT: '金额格式不合法',
|
|
71
71
|
READ_ONLY: '状态文件只读,未保存',
|
|
72
72
|
WRITE_FAILED: '写入状态文件失败',
|
|
73
|
+
ATTACHMENT_NOT_FOUND: '附件不存在或已失效',
|
|
74
|
+
ATTACHMENT_UNAVAILABLE: '附件服务不可用',
|
|
75
|
+
ATTACHMENT_READ_FAILED: '附件读取失败',
|
|
73
76
|
INTERNAL: '内部错误'
|
|
74
77
|
},
|
|
75
78
|
en: {
|
|
@@ -85,6 +88,9 @@ const ERROR_LABELS = {
|
|
|
85
88
|
INVALID_AMOUNT: 'Invalid amount',
|
|
86
89
|
READ_ONLY: 'State file is read-only; nothing saved',
|
|
87
90
|
WRITE_FAILED: 'Could not write the state file',
|
|
91
|
+
ATTACHMENT_NOT_FOUND: 'Attachment not found or no longer available',
|
|
92
|
+
ATTACHMENT_UNAVAILABLE: 'Attachment service is unavailable',
|
|
93
|
+
ATTACHMENT_READ_FAILED: 'Could not read the attachment',
|
|
88
94
|
INTERNAL: 'Internal error'
|
|
89
95
|
}
|
|
90
96
|
};
|
|
@@ -97,7 +103,8 @@ const ERROR_LABELS = {
|
|
|
97
103
|
* 折叠 OpenAI 风格 content(字符串或 block 数组)为纯文本。
|
|
98
104
|
* 只取用户可见的 text 块:reasoning(思维链)不属于回答正文,不能混进分享/导出。
|
|
99
105
|
*/
|
|
100
|
-
function contentText(content) {
|
|
106
|
+
function contentText(content, options) {
|
|
107
|
+
const placeholders = !options || options.attachments !== false;
|
|
101
108
|
if (typeof content === 'string') return content;
|
|
102
109
|
if (!Array.isArray(content)) return '';
|
|
103
110
|
const parts = [];
|
|
@@ -110,14 +117,56 @@ function contentText(content) {
|
|
|
110
117
|
if (block.type === 'text' && typeof block.text === 'string') {
|
|
111
118
|
parts.push(block.text);
|
|
112
119
|
} else if (block.type === 'image') {
|
|
113
|
-
parts.push('[图片]');
|
|
120
|
+
if (placeholders) parts.push('[图片]');
|
|
114
121
|
} else if (block.type === 'file') {
|
|
115
|
-
parts.push('[文件]');
|
|
122
|
+
if (placeholders) parts.push('[文件]');
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
return parts.join('');
|
|
119
126
|
}
|
|
120
127
|
|
|
128
|
+
/**
|
|
129
|
+
* 撤回回填用的正文:只拼接文本块,不插入 `[图片]` / `[文件]` 占位符。
|
|
130
|
+
* 附件由客户端另行恢复(见 `attachmentsOfEvent`);只有附件恢复不可用时,
|
|
131
|
+
* 占位符才有意义,因此这里不留占位符,避免与真实附件重复。
|
|
132
|
+
*/
|
|
133
|
+
function refillTextOf(event) {
|
|
134
|
+
if (!event || event.type !== 'user/message') return '';
|
|
135
|
+
const content = event.data && event.data.content;
|
|
136
|
+
return contentText(content, { attachments: false });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 提取用户消息里的附件描述(图片与文件),供客户端按 id 取回字节后恢复。
|
|
141
|
+
* 只读取 durable `attachment` 引用,不展开内容;同一 id 只保留一次。
|
|
142
|
+
* @returns {{ kind: 'image'|'file', attachmentId: string, name: string, mediaType: string, bytes?: number, width?: number, height?: number }[]}
|
|
143
|
+
*/
|
|
144
|
+
function attachmentsOfEvent(event) {
|
|
145
|
+
const content = event && event.type === 'user/message' && event.data && event.data.content;
|
|
146
|
+
if (!Array.isArray(content)) return [];
|
|
147
|
+
const list = [];
|
|
148
|
+
const seen = new Set();
|
|
149
|
+
for (const block of content) {
|
|
150
|
+
if (!block || block.type !== 'image' && block.type !== 'file') continue;
|
|
151
|
+
const ref = block.attachment;
|
|
152
|
+
if (!ref || typeof ref.attachmentId !== 'string' || ref.attachmentId.length === 0) continue;
|
|
153
|
+
if (seen.has(ref.attachmentId)) continue;
|
|
154
|
+
seen.add(ref.attachmentId);
|
|
155
|
+
list.push({
|
|
156
|
+
kind: block.type,
|
|
157
|
+
attachmentId: ref.attachmentId,
|
|
158
|
+
name: typeof ref.name === 'string' && ref.name.length > 0
|
|
159
|
+
? ref.name
|
|
160
|
+
: (block.type === 'image' ? 'image' : 'file'),
|
|
161
|
+
mediaType: typeof ref.mediaType === 'string' ? ref.mediaType : '',
|
|
162
|
+
bytes: Number.isSafeInteger(ref.bytes) ? ref.bytes : undefined,
|
|
163
|
+
width: Number.isSafeInteger(ref.width) ? ref.width : undefined,
|
|
164
|
+
height: Number.isSafeInteger(ref.height) ? ref.height : undefined
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return list;
|
|
168
|
+
}
|
|
169
|
+
|
|
121
170
|
/** 取一个事件的纯文本正文(按事件类型分发)。 */
|
|
122
171
|
function textOf(event) {
|
|
123
172
|
if (!event || typeof event !== 'object') return '';
|
|
@@ -525,7 +574,11 @@ function planAction(events, nodes, params) {
|
|
|
525
574
|
})();
|
|
526
575
|
// 撤回回填必须用被点的那条提问文本:轮次区间起点可能是运行时注入消息,
|
|
527
576
|
// 不能取 startSeq 的正文,否则会把注入上下文回填到输入框。
|
|
528
|
-
|
|
577
|
+
// 附件单独返回,客户端恢复成真实图片 / 文件;正文不再插入占位符。
|
|
578
|
+
if (plan.ok && action === 'recall') {
|
|
579
|
+
plan.refillText = refillTextOf(evt);
|
|
580
|
+
plan.attachments = attachmentsOfEvent(evt);
|
|
581
|
+
}
|
|
529
582
|
return plan;
|
|
530
583
|
}
|
|
531
584
|
|
|
@@ -583,7 +636,7 @@ function buildPlan(events, nodes, startSeq, endSeq, targetType, action, turn) {
|
|
|
583
636
|
via,
|
|
584
637
|
turn,
|
|
585
638
|
step,
|
|
586
|
-
refillText: action === 'recall' ?
|
|
639
|
+
refillText: action === 'recall' ? refillTextOf(events[startSeq]) : null
|
|
587
640
|
};
|
|
588
641
|
}
|
|
589
642
|
|
|
@@ -649,6 +702,25 @@ function goneTurnsOf(events, nodes, lookup) {
|
|
|
649
702
|
return turnIndex.filter((info) => !live.has(info.turn)).map((info) => info.turn);
|
|
650
703
|
}
|
|
651
704
|
|
|
705
|
+
/**
|
|
706
|
+
* 单条回答的估算成本:只针对该条 `assistant/message` 自己的 usage,
|
|
707
|
+
* 不复用同一轮其它步骤的数据,避免同轮多步骤重复计价。
|
|
708
|
+
* 本地 / 非 DeepSeek 路由返回 `{ micros: 0, billable: false }`;
|
|
709
|
+
* 无 usage 或无法判定路由时返回 undefined(界面不显示金额)。
|
|
710
|
+
* @returns {{ micros: number, billable: boolean } | undefined}
|
|
711
|
+
*/
|
|
712
|
+
function replyCostOf(event) {
|
|
713
|
+
if (!event || event.type !== 'assistant/message') return undefined;
|
|
714
|
+
const usage = stepUsageOf(event);
|
|
715
|
+
if (!usage) return undefined;
|
|
716
|
+
const data = event.data || {};
|
|
717
|
+
const route = routeOfUsage(data.usage) || routeOfMessage(data.message);
|
|
718
|
+
if (!route) return undefined;
|
|
719
|
+
if (!isBillableRoute(route.provider, route.model)) return { micros: 0, billable: false };
|
|
720
|
+
const at = Number.isFinite(event.time) ? event.time : Date.now();
|
|
721
|
+
return { micros: turnCost(usage, route.model, periodInfo(at).period), billable: true };
|
|
722
|
+
}
|
|
723
|
+
|
|
652
724
|
/**
|
|
653
725
|
* `/messages` 摘要快照:只返回预览、字数、用量与 callId,不返回正文。
|
|
654
726
|
* 分享图 / 导出需要全文时,走 `full=1&turns=a,b` 的按需接口(见 index.mjs)。
|
|
@@ -694,6 +766,7 @@ function messagesSummaryOf(events, nodes, lookup, options) {
|
|
|
694
766
|
(data.source === undefined || data.source === null || data.source.kind === undefined || data.source.kind === 'user');
|
|
695
767
|
const isText = isUserQuestion || event.type === 'assistant/message';
|
|
696
768
|
const text = isText ? textOf(event) : '';
|
|
769
|
+
const replyCost = event.type === 'assistant/message' ? replyCostOf(event) : undefined;
|
|
697
770
|
const summary = {
|
|
698
771
|
seq,
|
|
699
772
|
type: event.type,
|
|
@@ -705,6 +778,8 @@ function messagesSummaryOf(events, nodes, lookup, options) {
|
|
|
705
778
|
preview: isText ? previewText(text, previewLimit) : '',
|
|
706
779
|
words: isText ? wordCount(text) : 0,
|
|
707
780
|
usage: usageSummaryOf(event),
|
|
781
|
+
costMicros: replyCost ? replyCost.micros : null,
|
|
782
|
+
billable: replyCost ? replyCost.billable : null,
|
|
708
783
|
callId: toolCallIdOf(event)
|
|
709
784
|
};
|
|
710
785
|
const beyondCursor = since === null || seq > since;
|
|
@@ -1238,6 +1313,29 @@ function routingOfProvider(provider) {
|
|
|
1238
1313
|
return 'local';
|
|
1239
1314
|
}
|
|
1240
1315
|
|
|
1316
|
+
/** 模型名是否为 DeepSeek 官方模型(无 provider 时用于兜底判定)。 */
|
|
1317
|
+
function isDeepseekModel(model) {
|
|
1318
|
+
return typeof model === 'string' && /^deepseek/i.test(model.trim());
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* 该次用量是否计入 DeepSeek 费用(统计表「估算成本」/「预算使用」/「日用」)。
|
|
1323
|
+
*
|
|
1324
|
+
* - provider 已知:`deepseek-account` / `deepseek-*` 计费,其余(本地模型、第三方网关)不计费;
|
|
1325
|
+
* - provider 缺失:只有模型名明确是 `deepseek-*` 才计费,未知来源一律不计费(不臆测)。
|
|
1326
|
+
*
|
|
1327
|
+
* 本地 / 未知来源的 token 仍照常统计,只是成本记 0。
|
|
1328
|
+
* @param provider 路由 provider(如 `deepseek-account` / `ninfer-27b`)
|
|
1329
|
+
* @param model 模型名(如 `deepseek-flash`)
|
|
1330
|
+
* @returns {boolean}
|
|
1331
|
+
*/
|
|
1332
|
+
function isBillableRoute(provider, model) {
|
|
1333
|
+
const routing = routingOfProvider(provider);
|
|
1334
|
+
if (routing === 'local') return false;
|
|
1335
|
+
if (routing === 'account' || routing === 'api-key') return true;
|
|
1336
|
+
return isDeepseekModel(model);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1241
1339
|
/**
|
|
1242
1340
|
* 费用卡片样式枚举。数组顺序即设置页选项顺序:单行样式排在第一位。
|
|
1243
1341
|
* 内部存储值沿用 `compact` / `default`,与旧版本配置兼容。
|
|
@@ -1268,6 +1366,81 @@ function costSwitches(config) {
|
|
|
1268
1366
|
};
|
|
1269
1367
|
}
|
|
1270
1368
|
|
|
1369
|
+
/** 可选音色(Web Audio 现场合成,无音频文件)。 */
|
|
1370
|
+
const SOUND_TONES = ['double', 'bell', 'soft'];
|
|
1371
|
+
const DEFAULT_SOUND_TONE = 'double';
|
|
1372
|
+
|
|
1373
|
+
/** 音色归一化:未知值回落到默认双音('off' 由 completionSoundTone 单独处理)。 */
|
|
1374
|
+
function normalizeSoundTone(value) {
|
|
1375
|
+
return typeof value === 'string' && SOUND_TONES.indexOf(value) >= 0 ? value : DEFAULT_SOUND_TONE;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* 运行时音色。0.2.2 起不再有独立开关:
|
|
1380
|
+
* - `soundTone === 'off'` 即关闭;
|
|
1381
|
+
* - 旧配置只有 `sound: false`(没有音色)时,映射为「关闭」,保持旧行为;
|
|
1382
|
+
* - 旧配置 `sound: false` + 已有音色,同样显示「关闭」(旧开关优先)。
|
|
1383
|
+
*/
|
|
1384
|
+
function completionSoundTone(config) {
|
|
1385
|
+
const cfg = config || {};
|
|
1386
|
+
if (cfg.sound === false) return 'off';
|
|
1387
|
+
if (cfg.soundTone === 'off') return 'off';
|
|
1388
|
+
return normalizeSoundTone(cfg.soundTone);
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
/** 完成提示音是否开启:等价于音色不为「关闭」。 */
|
|
1392
|
+
function completionSoundEnabled(config) {
|
|
1393
|
+
return completionSoundTone(config) !== 'off';
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
/**
|
|
1397
|
+
* 设置页音色选项:3 个音色 + 「关闭」。
|
|
1398
|
+
* 选中「关闭」即关闭完成提示音;选中任一音色即开启并试听。
|
|
1399
|
+
* 供客户端渲染与离线断言共用。
|
|
1400
|
+
*/
|
|
1401
|
+
function soundToneOptions() {
|
|
1402
|
+
return SOUND_TONES.concat(['off']);
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// 音量:0–100 整数,默认 50(= 现有增益基准),步进 5 由滑杆约束。
|
|
1406
|
+
const DEFAULT_SOUND_VOLUME = 50;
|
|
1407
|
+
|
|
1408
|
+
/** 音量归一化:非法值回默认 50,其余夹到 0–100 的整数。 */
|
|
1409
|
+
function clampSoundVolume(value) {
|
|
1410
|
+
const num = typeof value === 'number' ? value : Number(value);
|
|
1411
|
+
if (!Number.isFinite(num)) return DEFAULT_SOUND_VOLUME;
|
|
1412
|
+
return Math.min(100, Math.max(0, Math.round(num)));
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* 音量倍数:50 为基准 1.0,0 为 0(静音),100 为 2.0。
|
|
1417
|
+
* 播放端用 `TONE_SPECS[音色].gain * soundGainScale(音量)`,避免 0 音量仍发声。
|
|
1418
|
+
*/
|
|
1419
|
+
function soundGainScale(volume) {
|
|
1420
|
+
return clampSoundVolume(volume) / 50;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
/**
|
|
1424
|
+
* 判断这一轮是否该播放完成提示音。
|
|
1425
|
+
* - 开关必须开启、本轮已结算(`settled !== false`)且拿到有效结算时间;
|
|
1426
|
+
* - `previousAt` 相同说明还是上一轮(重渲染 / 重复拉取),不重复响;
|
|
1427
|
+
* - `lastPlayedAt` 记录已响过的轮次,迟到回调不补响;
|
|
1428
|
+
* - 宿主仍忙(`busy === true`)时不响。
|
|
1429
|
+
* @param {{enabled?:boolean, busy?:boolean, settled?:boolean, previousAt?:number|null, at?:number|null, lastPlayedAt?:number|null}} options
|
|
1430
|
+
* @returns {boolean}
|
|
1431
|
+
*/
|
|
1432
|
+
function shouldPlayCompletionSound(options) {
|
|
1433
|
+
const opt = options || {};
|
|
1434
|
+
if (opt.enabled !== true) return false;
|
|
1435
|
+
if (opt.busy === true) return false;
|
|
1436
|
+
if (opt.settled === false) return false;
|
|
1437
|
+
const at = opt.at;
|
|
1438
|
+
if (!Number.isFinite(at) || at <= 0) return false;
|
|
1439
|
+
if (Number.isFinite(opt.previousAt) && opt.previousAt === at) return false;
|
|
1440
|
+
if (Number.isFinite(opt.lastPlayedAt) && opt.lastPlayedAt === at) return false;
|
|
1441
|
+
return true;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1271
1444
|
/**
|
|
1272
1445
|
* 聚合一轮(turn/start…turn/end)内各 step 的 usage。
|
|
1273
1446
|
* 每个 step 只取最后一个有效 assistant 结果(message 优先,其次 attempt),
|
|
@@ -1383,31 +1556,61 @@ function appendTurnEvent(buffer, event) {
|
|
|
1383
1556
|
}
|
|
1384
1557
|
|
|
1385
1558
|
// ---------------------------------------------------------------------------
|
|
1386
|
-
//
|
|
1559
|
+
// 费用统计:余额观测(账户口径)
|
|
1387
1560
|
// ---------------------------------------------------------------------------
|
|
1388
1561
|
|
|
1389
1562
|
/** 间隔超过 25 小时视为应用长时间未运行,不补记差额。 */
|
|
1390
1563
|
const MAX_OBSERVE_GAP_MS = 25 * 60 * 60 * 1000;
|
|
1391
1564
|
|
|
1392
|
-
/**
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1565
|
+
/**
|
|
1566
|
+
* 轮次结算累加当日用量(纯函数)。
|
|
1567
|
+
*
|
|
1568
|
+
* 口径:**以结算累加为主**——每轮 `turn/end` 落地时立即把估算金额(分)
|
|
1569
|
+
* 记入当日桶,并与「自上次余额观测以来已结算的金额」一起累计;
|
|
1570
|
+
* 余额观测随后只对差额做校正(见 observeBalance),避免重复计入。
|
|
1571
|
+
*
|
|
1572
|
+
* 幂等:同一 `key`(会话 + 轮次 + 结束时刻)只累加一次,重复推送不会二次计数。
|
|
1573
|
+
* 跨零点:按结算时刻(endedAt)的北京日期入桶。
|
|
1574
|
+
*
|
|
1575
|
+
* @param state 持久化状态(不修改入参)
|
|
1576
|
+
* @param params { micros, at, key }
|
|
1577
|
+
* @returns {{ state, applied, cents }}
|
|
1578
|
+
*/
|
|
1579
|
+
function settleSpend(state, params) {
|
|
1580
|
+
const s = state || {};
|
|
1581
|
+
const p = params || {};
|
|
1582
|
+
const micros = Number.isFinite(p.micros) ? p.micros : 0;
|
|
1583
|
+
const cents = micros > 0 ? Math.round(micros / 10000) : 0;
|
|
1584
|
+
const out = {
|
|
1585
|
+
dailySpendCents: Object.assign({}, s.dailySpendCents || {}),
|
|
1586
|
+
settledSpendTotalCents: Number.isFinite(s.settledSpendTotalCents) ? s.settledSpendTotalCents : 0,
|
|
1587
|
+
settledSinceObserveCents: Number.isFinite(s.settledSinceObserveCents) ? s.settledSinceObserveCents : 0,
|
|
1588
|
+
lastSettledKey: typeof s.lastSettledKey === 'string' ? s.lastSettledKey : ''
|
|
1589
|
+
};
|
|
1590
|
+
const key = typeof p.key === 'string' ? p.key : '';
|
|
1591
|
+
if (cents === 0) return { state: out, applied: false, cents: 0 };
|
|
1592
|
+
if (key !== '' && key === out.lastSettledKey) return { state: out, applied: false, cents: 0 };
|
|
1593
|
+
const at = Number.isFinite(p.at) ? p.at : Date.now();
|
|
1594
|
+
const day = beijingDateKey(at);
|
|
1595
|
+
out.dailySpendCents[day] = (out.dailySpendCents[day] || 0) + cents;
|
|
1596
|
+
out.settledSpendTotalCents += cents;
|
|
1597
|
+
out.settledSinceObserveCents += cents;
|
|
1598
|
+
if (key !== '') out.lastSettledKey = key;
|
|
1599
|
+
return { state: out, applied: true, cents };
|
|
1401
1600
|
}
|
|
1402
1601
|
|
|
1403
1602
|
/**
|
|
1404
1603
|
* 一次余额观测的记账(纯函数,返回新状态与本次记账原因)。
|
|
1405
1604
|
*
|
|
1406
1605
|
* - 下降 → 累计「已观测消费」,按北京时间日期计入「日用」;
|
|
1407
|
-
* - 上升 →
|
|
1606
|
+
* - 上升 → 只更新 lastBalance,不冲减消费(不再维护手工校正字段);
|
|
1408
1607
|
* - 跨日 / 间隔超 25h / 路由切换 → 只更新 lastBalance,跳过本次差额;
|
|
1409
1608
|
* - 非 account 路由 → 完全不记账。
|
|
1410
1609
|
*
|
|
1610
|
+
* 与轮次结算共用同一份「日用」:本轮已结算的金额先由 settleSpend 记入,
|
|
1611
|
+
* 观测到差额时只把 **超出已结算部分** 补进当日桶(`diff - settledSinceObserveCents`),
|
|
1612
|
+
* 不重复计入;估算高于实际(差额为负)时不做减法,保持「日用」为花费上限提示。
|
|
1613
|
+
*
|
|
1411
1614
|
* @param state 持久化状态(不修改入参)
|
|
1412
1615
|
* @param params { cents, routing, at }
|
|
1413
1616
|
* @returns {{ state, reason }}
|
|
@@ -1424,8 +1627,9 @@ function observeBalance(state, params) {
|
|
|
1424
1627
|
lastRouting: typeof s.lastRouting === 'string' ? s.lastRouting : null,
|
|
1425
1628
|
observedSpendTotalCents: Number.isFinite(s.observedSpendTotalCents) ? s.observedSpendTotalCents : 0,
|
|
1426
1629
|
dailySpendCents: Object.assign({}, s.dailySpendCents || {}),
|
|
1427
|
-
|
|
1428
|
-
|
|
1630
|
+
settledSpendTotalCents: Number.isFinite(s.settledSpendTotalCents) ? s.settledSpendTotalCents : 0,
|
|
1631
|
+
settledSinceObserveCents: Number.isFinite(s.settledSinceObserveCents) ? s.settledSinceObserveCents : 0,
|
|
1632
|
+
lastSettledKey: typeof s.lastSettledKey === 'string' ? s.lastSettledKey : ''
|
|
1429
1633
|
};
|
|
1430
1634
|
if (cents === null) return { state: out, reason: 'invalid' };
|
|
1431
1635
|
if (routing !== 'account') return { state: out, reason: 'not-account' };
|
|
@@ -1435,28 +1639,34 @@ function observeBalance(state, params) {
|
|
|
1435
1639
|
out.lastBalanceCents = cents;
|
|
1436
1640
|
out.lastBalanceAt = at;
|
|
1437
1641
|
out.lastRouting = routing;
|
|
1642
|
+
out.settledSinceObserveCents = 0;
|
|
1438
1643
|
return { state: out, reason: 'baseline' };
|
|
1439
1644
|
}
|
|
1440
1645
|
if (out.lastBalanceCents === null || out.lastBalanceAt === 0) {
|
|
1441
1646
|
out.lastBalanceCents = cents;
|
|
1442
1647
|
out.lastBalanceAt = at;
|
|
1443
1648
|
out.lastRouting = routing;
|
|
1649
|
+
out.settledSinceObserveCents = 0;
|
|
1444
1650
|
return { state: out, reason: 'first' };
|
|
1445
1651
|
}
|
|
1446
1652
|
if (out.lastRouting !== routing) {
|
|
1447
1653
|
out.lastBalanceCents = cents;
|
|
1448
1654
|
out.lastBalanceAt = at;
|
|
1449
1655
|
out.lastRouting = routing;
|
|
1656
|
+
out.settledSinceObserveCents = 0;
|
|
1450
1657
|
return { state: out, reason: 'routing-switch' };
|
|
1451
1658
|
}
|
|
1452
1659
|
if (beijingDateKey(out.lastBalanceAt) !== beijingDateKey(at)) {
|
|
1453
1660
|
out.lastBalanceCents = cents;
|
|
1454
1661
|
out.lastBalanceAt = at;
|
|
1662
|
+
// 跨日不补记差额;同时清空待核对结算,避免把昨天的金额算进今天的差值。
|
|
1663
|
+
out.settledSinceObserveCents = 0;
|
|
1455
1664
|
return { state: out, reason: 'cross-day' };
|
|
1456
1665
|
}
|
|
1457
1666
|
if (at - out.lastBalanceAt > MAX_OBSERVE_GAP_MS) {
|
|
1458
1667
|
out.lastBalanceCents = cents;
|
|
1459
1668
|
out.lastBalanceAt = at;
|
|
1669
|
+
out.settledSinceObserveCents = 0;
|
|
1460
1670
|
return { state: out, reason: 'too-long' };
|
|
1461
1671
|
}
|
|
1462
1672
|
|
|
@@ -1464,12 +1674,16 @@ function observeBalance(state, params) {
|
|
|
1464
1674
|
let reason = 'none';
|
|
1465
1675
|
if (diff > 0) {
|
|
1466
1676
|
out.observedSpendTotalCents += diff;
|
|
1467
|
-
|
|
1468
|
-
|
|
1677
|
+
// 已结算部分已计入「日用」,这里只补超出部分,避免同一轮被计两次。
|
|
1678
|
+
const extra = diff - out.settledSinceObserveCents;
|
|
1679
|
+
if (extra > 0) {
|
|
1680
|
+
const key = beijingDateKey(at);
|
|
1681
|
+
out.dailySpendCents[key] = (out.dailySpendCents[key] || 0) + extra;
|
|
1682
|
+
}
|
|
1683
|
+
out.settledSinceObserveCents = 0;
|
|
1469
1684
|
reason = 'spend';
|
|
1470
1685
|
} else if (diff < 0) {
|
|
1471
|
-
|
|
1472
|
-
out.pendingAdjustmentAt = at;
|
|
1686
|
+
// 余额上升(充值 / 退货):只更新基准,不冲减消费,也不做手工校正。
|
|
1473
1687
|
reason = 'adjust';
|
|
1474
1688
|
}
|
|
1475
1689
|
out.lastBalanceCents = cents;
|
|
@@ -1478,10 +1692,15 @@ function observeBalance(state, params) {
|
|
|
1478
1692
|
}
|
|
1479
1693
|
|
|
1480
1694
|
/** 元(数字或字符串)转分;非法返回 null。 */
|
|
1481
|
-
function yuanToCents(value) {
|
|
1695
|
+
function yuanToCents(value, mode) {
|
|
1696
|
+
const truncate = mode === 'truncate';
|
|
1482
1697
|
if (typeof value === 'number') {
|
|
1483
1698
|
if (!Number.isFinite(value)) return null;
|
|
1484
|
-
|
|
1699
|
+
// 数字先转十进制字符串再按分解析:避免 `5.99 * 100 = 598.999…` 的浮点误差把分差成 1。
|
|
1700
|
+
const asText = String(value);
|
|
1701
|
+
if (/^-?\d+(\.\d+)?$/.test(asText.trim())) return yuanToCents(asText, mode);
|
|
1702
|
+
// 科学计数法等无法逐位解析的极端值,退回浮点换算。
|
|
1703
|
+
return truncate && value >= 0 ? Math.floor(value * 100 + 1e-6) : Math.round(value * 100);
|
|
1485
1704
|
}
|
|
1486
1705
|
if (typeof value !== 'string') return null;
|
|
1487
1706
|
const raw = value.trim().replace(/,/g, '');
|
|
@@ -1492,7 +1711,9 @@ function yuanToCents(value) {
|
|
|
1492
1711
|
const whole = split[0];
|
|
1493
1712
|
const frac = split[1] || '';
|
|
1494
1713
|
let cents = Number(whole) * 100 + Number((frac + '00').slice(0, 2));
|
|
1495
|
-
|
|
1714
|
+
// 官方「账号与余额」对正金额截断至分:原始余额字符串可能带三位以上小数,
|
|
1715
|
+
// 这里必须同样截断,否则 5.999… 会进位成 6.00,比官方页面多一分。
|
|
1716
|
+
if (frac.length > 2 && !(truncate && !negative) && Number(frac.charAt(2)) >= 5) cents += 1;
|
|
1496
1717
|
return negative ? -cents : cents;
|
|
1497
1718
|
}
|
|
1498
1719
|
|
|
@@ -1566,6 +1787,17 @@ function formatCostMicros(micros) {
|
|
|
1566
1787
|
return formatYuanCents(Math.round(micros / 10000));
|
|
1567
1788
|
}
|
|
1568
1789
|
|
|
1790
|
+
/**
|
|
1791
|
+
* 微元 -> 单条回答金额展示(保留 4 位小数,避免每轮几厘钱被舍成 0):
|
|
1792
|
+
* 0 → `¥0.0000`;0 < x < ¥0.0001 → `<¥0.0001`;其余四舍五入到 4 位。
|
|
1793
|
+
*/
|
|
1794
|
+
function formatReplyCost(micros) {
|
|
1795
|
+
if (!Number.isFinite(micros)) return '';
|
|
1796
|
+
if (micros <= 0) return '¥0.0000';
|
|
1797
|
+
if (micros < 100) return '<¥0.0001';
|
|
1798
|
+
return '¥' + (micros / 1000000).toFixed(4);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1569
1801
|
/** 自动关闭时刻:秒数 0 / 非法返回 null(不自动关闭);上限 600 秒。 */
|
|
1570
1802
|
function autoCloseAt(firstSeenAt, seconds) {
|
|
1571
1803
|
const s = typeof seconds === 'string' ? Number(seconds) : seconds;
|
|
@@ -1579,6 +1811,329 @@ function easeOutCubic(t) {
|
|
|
1579
1811
|
return 1 - Math.pow(1 - x, 3);
|
|
1580
1812
|
}
|
|
1581
1813
|
|
|
1814
|
+
// ---------------------------------------------------------------------------
|
|
1815
|
+
// 会话统计:从真实会话日志折叠 token / 成本 / 时间线(宿主与测试共用)
|
|
1816
|
+
// ---------------------------------------------------------------------------
|
|
1817
|
+
|
|
1818
|
+
/** 时间线桶数:小时视图 48 个(客户端展示最近 24 个),日视图 30 个。 */
|
|
1819
|
+
const STATS_HOURLY_BUCKETS = 48;
|
|
1820
|
+
const STATS_DAILY_BUCKETS = 30;
|
|
1821
|
+
|
|
1822
|
+
/** 四类 token 的空桶。 */
|
|
1823
|
+
function emptyStatsTokens() {
|
|
1824
|
+
return { input: 0, cacheRead: 0, cacheWrite: 0, output: 0 };
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
/** 四类 token 合计。 */
|
|
1828
|
+
function statsTokenTotal(tokens) {
|
|
1829
|
+
const t = tokens || {};
|
|
1830
|
+
return tokenCount(t.input) + tokenCount(t.cacheRead) + tokenCount(t.cacheWrite) + tokenCount(t.output);
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
/**
|
|
1834
|
+
* 原始 usage → 四类 token 桶。缺 input/output 计数时返回 null(该条不计入)。
|
|
1835
|
+
* 与费用统计共用 `normalizeCostUsage`,保证同一份日志得到同一组数字。
|
|
1836
|
+
*/
|
|
1837
|
+
function statsUsageBuckets(usage) {
|
|
1838
|
+
const normalized = normalizeCostUsage(usage);
|
|
1839
|
+
if (!normalized) return null;
|
|
1840
|
+
return {
|
|
1841
|
+
input: normalized.inputTokens,
|
|
1842
|
+
cacheRead: normalized.cacheReadTokens,
|
|
1843
|
+
cacheWrite: normalized.cacheWriteTokens,
|
|
1844
|
+
output: normalized.outputTokens
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
/**
|
|
1849
|
+
* 单个时间点的估算成本(微元):按该点时刻的峰 / 谷价与当时模型价目计算,
|
|
1850
|
+
* 与费用卡片的「单次」共用 `turnCost`,因此两处口径一致。
|
|
1851
|
+
*/
|
|
1852
|
+
function statsPointCostMicros(point) {
|
|
1853
|
+
if (!point) return 0;
|
|
1854
|
+
// 本地 / 未知来源的 token 照常统计,但成本记 0(不套用 DeepSeek 价目)。
|
|
1855
|
+
if (point.billable === false) return 0;
|
|
1856
|
+
const at = Number.isFinite(point.t) ? point.t : Date.now();
|
|
1857
|
+
const period = periodInfo(at).period;
|
|
1858
|
+
const usage = {
|
|
1859
|
+
inputTokens: tokenCount(point.input),
|
|
1860
|
+
cacheReadTokens: tokenCount(point.cacheRead),
|
|
1861
|
+
cacheWriteTokens: tokenCount(point.cacheWrite),
|
|
1862
|
+
outputTokens: tokenCount(point.output),
|
|
1863
|
+
reasoningTokens: 0
|
|
1864
|
+
};
|
|
1865
|
+
return turnCost(usage, point.model, period);
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
/** 取目录的最后一段,作为无标题会话的兜底名称。 */
|
|
1869
|
+
function baseNameOfPath(value) {
|
|
1870
|
+
if (typeof value !== 'string' || value.length === 0) return '';
|
|
1871
|
+
const parts = value.split(/[\\/]/).filter(Boolean);
|
|
1872
|
+
return parts.length === 0 ? '' : parts[parts.length - 1];
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
/**
|
|
1876
|
+
* 折叠一条会话日志:四类 token 汇总、时间线点(含计价时刻的模型)、
|
|
1877
|
+
* 标题 / 首个问题 / 模型与最后活跃时间。与宿主的 `tokenUsage` 投影口径一致:
|
|
1878
|
+
* 每个 assistant/message 的 usage 只取一次。
|
|
1879
|
+
* @param events 会话事件数组(读取日志得到的原始事件)
|
|
1880
|
+
*/
|
|
1881
|
+
function foldSessionStats(events) {
|
|
1882
|
+
const list = Array.isArray(events) ? events : [];
|
|
1883
|
+
const tokens = emptyStatsTokens();
|
|
1884
|
+
const points = [];
|
|
1885
|
+
let title = '';
|
|
1886
|
+
let firstPrompt = '';
|
|
1887
|
+
let model = '';
|
|
1888
|
+
let provider = '';
|
|
1889
|
+
let currentModel = '';
|
|
1890
|
+
let lastActiveAt = 0;
|
|
1891
|
+
let turns = 0;
|
|
1892
|
+
let steps = 0;
|
|
1893
|
+
let messages = 0;
|
|
1894
|
+
|
|
1895
|
+
for (const event of list) {
|
|
1896
|
+
if (!event || typeof event.type !== 'string') continue;
|
|
1897
|
+
const time = Number.isFinite(event.time) ? event.time : 0;
|
|
1898
|
+
if (time > lastActiveAt) lastActiveAt = time;
|
|
1899
|
+
const data = event.data || {};
|
|
1900
|
+
|
|
1901
|
+
if (event.type === 'assistant/message') {
|
|
1902
|
+
messages += 1;
|
|
1903
|
+
if (Number.isSafeInteger(data.turn) && data.turn > turns) turns = data.turn;
|
|
1904
|
+
const route = routeOfMessage(data.message) || routeOfUsage(data.usage);
|
|
1905
|
+
if (route) {
|
|
1906
|
+
provider = route.provider;
|
|
1907
|
+
if (route.model) currentModel = route.model;
|
|
1908
|
+
}
|
|
1909
|
+
const buckets = statsUsageBuckets(data.usage);
|
|
1910
|
+
if (buckets) {
|
|
1911
|
+
const pointModel = currentModel || model;
|
|
1912
|
+
const point = {
|
|
1913
|
+
t: time,
|
|
1914
|
+
input: buckets.input,
|
|
1915
|
+
cacheRead: buckets.cacheRead,
|
|
1916
|
+
cacheWrite: buckets.cacheWrite,
|
|
1917
|
+
output: buckets.output,
|
|
1918
|
+
model: pointModel,
|
|
1919
|
+
// 只对 DeepSeek 官方路由计价;本地模型仍统计 token,但成本为 0。
|
|
1920
|
+
billable: isBillableRoute(provider, pointModel)
|
|
1921
|
+
};
|
|
1922
|
+
tokens.input += point.input;
|
|
1923
|
+
tokens.cacheRead += point.cacheRead;
|
|
1924
|
+
tokens.cacheWrite += point.cacheWrite;
|
|
1925
|
+
tokens.output += point.output;
|
|
1926
|
+
points.push(point);
|
|
1927
|
+
}
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
if (event.type === 'step/end') {
|
|
1932
|
+
steps += 1;
|
|
1933
|
+
continue;
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
if (event.type === 'session/title') {
|
|
1937
|
+
if (typeof data.title === 'string' && data.title.trim()) title = data.title.trim();
|
|
1938
|
+
continue;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
if (event.type === 'request/header') {
|
|
1942
|
+
const config = data.header && data.header.config;
|
|
1943
|
+
if (config && typeof config === 'object') {
|
|
1944
|
+
if (typeof config.model === 'string' && config.model) {
|
|
1945
|
+
model = config.model;
|
|
1946
|
+
currentModel = config.model;
|
|
1947
|
+
}
|
|
1948
|
+
if (typeof config.provider === 'string' && config.provider) provider = config.provider;
|
|
1949
|
+
}
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
if (event.type === 'user/message' && !firstPrompt) {
|
|
1954
|
+
// 会话日志两种历史形状都兼容:data.message.content 或 data.content。
|
|
1955
|
+
const message = data.message && typeof data.message === 'object' ? data.message : data;
|
|
1956
|
+
const text = contentText(message.content).replace(/\s+/g, ' ').trim();
|
|
1957
|
+
if (text) firstPrompt = text.length > 80 ? text.slice(0, 80) + '…' : text;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
return { tokens, points, title, firstPrompt, model, provider, lastActiveAt, turns, steps, messages };
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
/** 本地时间的小时起点。 */
|
|
1965
|
+
function statsFloorHour(ts) {
|
|
1966
|
+
const date = new Date(ts);
|
|
1967
|
+
date.setMinutes(0, 0, 0);
|
|
1968
|
+
return date.getTime();
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
/** 本地时间的日起点。 */
|
|
1972
|
+
function statsFloorDay(ts) {
|
|
1973
|
+
const date = new Date(ts);
|
|
1974
|
+
date.setHours(0, 0, 0, 0);
|
|
1975
|
+
return date.getTime();
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
/** 以 `now` 为终点、向过去生成连续桶起点(旧 → 新)。 */
|
|
1979
|
+
function statsBucketStarts(now, count, unit) {
|
|
1980
|
+
const total = Number.isSafeInteger(count) && count > 0 ? count : 1;
|
|
1981
|
+
const starts = [];
|
|
1982
|
+
const cursor = new Date(unit === 'hour' ? statsFloorHour(now) : statsFloorDay(now));
|
|
1983
|
+
for (let index = 0; index < total; index += 1) {
|
|
1984
|
+
starts.push(cursor.getTime());
|
|
1985
|
+
if (unit === 'hour') cursor.setHours(cursor.getHours() - 1);
|
|
1986
|
+
else cursor.setDate(cursor.getDate() - 1);
|
|
1987
|
+
}
|
|
1988
|
+
return starts.reverse();
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
/** 把时间点聚合成桶(含 token 合计与成本合计,微元)。 */
|
|
1992
|
+
function statsAggregate(points, starts, unit) {
|
|
1993
|
+
const list = starts || [];
|
|
1994
|
+
const buckets = list.map((t) => ({
|
|
1995
|
+
t,
|
|
1996
|
+
...emptyStatsTokens(),
|
|
1997
|
+
tokens: 0,
|
|
1998
|
+
billableTokens: 0,
|
|
1999
|
+
localTokens: 0,
|
|
2000
|
+
costMicros: 0
|
|
2001
|
+
}));
|
|
2002
|
+
const positionOf = new Map();
|
|
2003
|
+
buckets.forEach((bucket, index) => positionOf.set(bucket.t, index));
|
|
2004
|
+
for (const point of points || []) {
|
|
2005
|
+
if (!point || !Number.isFinite(point.t)) continue;
|
|
2006
|
+
const start = unit === 'hour' ? statsFloorHour(point.t) : statsFloorDay(point.t);
|
|
2007
|
+
const position = positionOf.get(start);
|
|
2008
|
+
if (position === undefined) continue;
|
|
2009
|
+
const bucket = buckets[position];
|
|
2010
|
+
bucket.input += tokenCount(point.input);
|
|
2011
|
+
bucket.cacheRead += tokenCount(point.cacheRead);
|
|
2012
|
+
bucket.cacheWrite += tokenCount(point.cacheWrite);
|
|
2013
|
+
bucket.output += tokenCount(point.output);
|
|
2014
|
+
const pointTokens = tokenCount(point.input) + tokenCount(point.cacheRead) +
|
|
2015
|
+
tokenCount(point.cacheWrite) + tokenCount(point.output);
|
|
2016
|
+
bucket.tokens += pointTokens;
|
|
2017
|
+
if (point.billable === false) bucket.localTokens += pointTokens;
|
|
2018
|
+
else bucket.billableTokens += pointTokens;
|
|
2019
|
+
bucket.costMicros += statsPointCostMicros(point);
|
|
2020
|
+
}
|
|
2021
|
+
return buckets;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
/** 小时 / 日两条时间线(宿主一次性算好,客户端只切换显示)。 */
|
|
2025
|
+
function statsTimeline(points, now) {
|
|
2026
|
+
const at = Number.isFinite(now) ? now : Date.now();
|
|
2027
|
+
return {
|
|
2028
|
+
hourly: statsAggregate(points, statsBucketStarts(at, STATS_HOURLY_BUCKETS, 'hour'), 'hour'),
|
|
2029
|
+
daily: statsAggregate(points, statsBucketStarts(at, STATS_DAILY_BUCKETS, 'day'), 'day')
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
/** 会话行(供表格与汇总;纯函数便于离线断言)。 */
|
|
2034
|
+
function statsSessionRow(header, fold, options) {
|
|
2035
|
+
const h = header && typeof header === 'object' ? header : {};
|
|
2036
|
+
const f = fold && typeof fold === 'object' ? fold : {};
|
|
2037
|
+
const opt = options || {};
|
|
2038
|
+
const source = f.tokens && typeof f.tokens === 'object' ? f.tokens : emptyStatsTokens();
|
|
2039
|
+
const tokens = {
|
|
2040
|
+
input: tokenCount(source.input),
|
|
2041
|
+
cacheRead: tokenCount(source.cacheRead),
|
|
2042
|
+
cacheWrite: tokenCount(source.cacheWrite),
|
|
2043
|
+
output: tokenCount(source.output)
|
|
2044
|
+
};
|
|
2045
|
+
const total = statsTokenTotal(tokens);
|
|
2046
|
+
let costMicros = 0;
|
|
2047
|
+
let billableTokens = 0;
|
|
2048
|
+
let localTokens = 0;
|
|
2049
|
+
for (const point of Array.isArray(f.points) ? f.points : []) {
|
|
2050
|
+
if (!point) continue;
|
|
2051
|
+
const pointTokens = tokenCount(point.input) + tokenCount(point.cacheRead) +
|
|
2052
|
+
tokenCount(point.cacheWrite) + tokenCount(point.output);
|
|
2053
|
+
if (point.billable === false) localTokens += pointTokens;
|
|
2054
|
+
else billableTokens += pointTokens;
|
|
2055
|
+
costMicros += statsPointCostMicros(point);
|
|
2056
|
+
}
|
|
2057
|
+
const id = typeof h.id === 'string' ? h.id : '';
|
|
2058
|
+
return {
|
|
2059
|
+
id,
|
|
2060
|
+
title: f.title || f.firstPrompt || baseNameOfPath(h.cwd) || id,
|
|
2061
|
+
cwd: typeof h.cwd === 'string' ? h.cwd : '',
|
|
2062
|
+
createdAt: Number.isFinite(h.createdAt) ? h.createdAt : 0,
|
|
2063
|
+
lastActiveAt: Number.isFinite(f.lastActiveAt) ? f.lastActiveAt : 0,
|
|
2064
|
+
model: f.model || '',
|
|
2065
|
+
provider: f.provider || '',
|
|
2066
|
+
turns: Number.isSafeInteger(f.turns) ? f.turns : 0,
|
|
2067
|
+
steps: Number.isSafeInteger(f.steps) ? f.steps : 0,
|
|
2068
|
+
messages: Number.isSafeInteger(f.messages) ? f.messages : 0,
|
|
2069
|
+
tokens: { ...tokens, total },
|
|
2070
|
+
billableTokens,
|
|
2071
|
+
localTokens,
|
|
2072
|
+
/** 该会话是否有任何 DeepSeek 计费用量(用于会话表「本地 · 不计费」展示)。 */
|
|
2073
|
+
billable: billableTokens > 0,
|
|
2074
|
+
costMicros,
|
|
2075
|
+
running: opt.running === true,
|
|
2076
|
+
live: opt.live === true,
|
|
2077
|
+
subagent: h.origin === 'subagent'
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
/** 汇总多行:四类 token、成本、会话数、运行中数量与轮 / step / 消息数。 */
|
|
2082
|
+
function statsSummary(rows) {
|
|
2083
|
+
const list = Array.isArray(rows) ? rows : [];
|
|
2084
|
+
const tokens = emptyStatsTokens();
|
|
2085
|
+
let costMicros = 0;
|
|
2086
|
+
let billableTokens = 0;
|
|
2087
|
+
let localTokens = 0;
|
|
2088
|
+
let running = 0;
|
|
2089
|
+
let turns = 0;
|
|
2090
|
+
let steps = 0;
|
|
2091
|
+
let messages = 0;
|
|
2092
|
+
for (const row of list) {
|
|
2093
|
+
if (!row) continue;
|
|
2094
|
+
const source = row.tokens || {};
|
|
2095
|
+
tokens.input += tokenCount(source.input);
|
|
2096
|
+
tokens.cacheRead += tokenCount(source.cacheRead);
|
|
2097
|
+
tokens.cacheWrite += tokenCount(source.cacheWrite);
|
|
2098
|
+
tokens.output += tokenCount(source.output);
|
|
2099
|
+
costMicros += Number.isFinite(row.costMicros) ? Math.max(0, Math.round(row.costMicros)) : 0;
|
|
2100
|
+
billableTokens += Number.isFinite(row.billableTokens) ? Math.max(0, row.billableTokens) : 0;
|
|
2101
|
+
localTokens += Number.isFinite(row.localTokens) ? Math.max(0, row.localTokens) : 0;
|
|
2102
|
+
turns += Number.isSafeInteger(row.turns) ? row.turns : 0;
|
|
2103
|
+
steps += Number.isSafeInteger(row.steps) ? row.steps : 0;
|
|
2104
|
+
messages += Number.isSafeInteger(row.messages) ? row.messages : 0;
|
|
2105
|
+
if (row.running === true) running += 1;
|
|
2106
|
+
}
|
|
2107
|
+
return {
|
|
2108
|
+
tokens: { ...tokens, total: statsTokenTotal(tokens) },
|
|
2109
|
+
billableTokens,
|
|
2110
|
+
localTokens,
|
|
2111
|
+
costMicros,
|
|
2112
|
+
sessions: list.length,
|
|
2113
|
+
running,
|
|
2114
|
+
turns,
|
|
2115
|
+
steps,
|
|
2116
|
+
messages
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
/**
|
|
2121
|
+
* 预算视图:金额为分(人民币,与费用卡片币种一致)。
|
|
2122
|
+
* budgetCents 为 0 视为未设预算(enabled=false,比例不显示)。
|
|
2123
|
+
*/
|
|
2124
|
+
function statsBudget(spentMicros, budgetCents) {
|
|
2125
|
+
const amountCents = Number.isFinite(budgetCents) && budgetCents > 0 ? Math.round(budgetCents) : 0;
|
|
2126
|
+
const spentCents = Number.isFinite(spentMicros) ? Math.max(0, Math.round(spentMicros / 10000)) : 0;
|
|
2127
|
+
const enabled = amountCents > 0;
|
|
2128
|
+
return {
|
|
2129
|
+
amountCents,
|
|
2130
|
+
spentCents,
|
|
2131
|
+
remainingCents: enabled ? Math.max(0, amountCents - spentCents) : 0,
|
|
2132
|
+
ratio: enabled ? spentCents / amountCents : 0,
|
|
2133
|
+
enabled
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
|
|
1582
2137
|
// ---------------------------------------------------------------------------
|
|
1583
2138
|
// 工具函数
|
|
1584
2139
|
// ---------------------------------------------------------------------------
|
|
@@ -1689,6 +2244,8 @@ const CSS = `
|
|
|
1689
2244
|
[data-dma-rail="1"]{display:none!important}
|
|
1690
2245
|
.dma-overlay{position:fixed;inset:0;z-index:2147483000;background:var(--dsw-alias-bg-mask-1,rgba(0,0,0,.45));display:flex;align-items:center;justify-content:center}
|
|
1691
2246
|
.dma-panel{width:min(680px,calc(100vw - 48px));max-height:80vh;display:flex;flex-direction:column;background:var(--dsw-alias-bg-layer-1,#ffffff);border:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.1));border-radius:var(--dsw-radius-panel,12px);box-shadow:var(--dsw-elevation-panel,0 18px 48px rgba(0,0,0,.18));overflow:hidden;color:var(--dsw-alias-label-primary,#1f2329)}
|
|
2247
|
+
.dma-confirm{width:min(420px,calc(100vw - 48px))}
|
|
2248
|
+
@media (max-width:480px){.dma-confirm{width:calc(100vw - 32px)}.dma-panel-foot{gap:8px}.dma-panel-foot .dma-btn{padding:0 12px}}
|
|
1692
2249
|
.dma-panel-head{padding:16px 20px;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.1));font-size:16px;font-weight:600}
|
|
1693
2250
|
.dma-panel-body{overflow:auto;padding:12px 16px}
|
|
1694
2251
|
.dma-round{display:flex;gap:12px;align-items:flex-start;padding:10px 8px;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08));border-radius:8px}
|
|
@@ -1722,6 +2279,8 @@ module.exports = {
|
|
|
1722
2279
|
TOMBSTONE_TEXT,
|
|
1723
2280
|
ERROR_LABELS,
|
|
1724
2281
|
contentText,
|
|
2282
|
+
refillTextOf,
|
|
2283
|
+
attachmentsOfEvent,
|
|
1725
2284
|
textOf,
|
|
1726
2285
|
messageRoleOf,
|
|
1727
2286
|
messageIdOf,
|
|
@@ -1790,7 +2349,19 @@ module.exports = {
|
|
|
1790
2349
|
routeOfMessage,
|
|
1791
2350
|
routeOfUsage,
|
|
1792
2351
|
routingOfProvider,
|
|
2352
|
+
isDeepseekModel,
|
|
2353
|
+
isBillableRoute,
|
|
1793
2354
|
costSwitches,
|
|
2355
|
+
completionSoundEnabled,
|
|
2356
|
+
SOUND_TONES,
|
|
2357
|
+
DEFAULT_SOUND_TONE,
|
|
2358
|
+
normalizeSoundTone,
|
|
2359
|
+
completionSoundTone,
|
|
2360
|
+
soundToneOptions,
|
|
2361
|
+
DEFAULT_SOUND_VOLUME,
|
|
2362
|
+
clampSoundVolume,
|
|
2363
|
+
soundGainScale,
|
|
2364
|
+
shouldPlayCompletionSound,
|
|
1794
2365
|
COST_LAYOUTS,
|
|
1795
2366
|
DEFAULT_COST_LAYOUT,
|
|
1796
2367
|
normalizeCostLayout,
|
|
@@ -1799,24 +2370,40 @@ module.exports = {
|
|
|
1799
2370
|
deriveTurnUsage,
|
|
1800
2371
|
createTurnBuffer,
|
|
1801
2372
|
appendTurnEvent,
|
|
1802
|
-
correctedBalanceCents,
|
|
1803
2373
|
observeBalance,
|
|
2374
|
+
settleSpend,
|
|
1804
2375
|
yuanToCents,
|
|
1805
2376
|
validateCorrectionAmount,
|
|
1806
2377
|
pruneDailySpend,
|
|
1807
2378
|
formatCents,
|
|
1808
2379
|
formatYuanCents,
|
|
1809
2380
|
formatCostMicros,
|
|
2381
|
+
formatReplyCost,
|
|
1810
2382
|
autoCloseAt,
|
|
1811
2383
|
easeOutCubic,
|
|
2384
|
+
STATS_HOURLY_BUCKETS,
|
|
2385
|
+
STATS_DAILY_BUCKETS,
|
|
2386
|
+
emptyStatsTokens,
|
|
2387
|
+
statsTokenTotal,
|
|
2388
|
+
statsUsageBuckets,
|
|
2389
|
+
statsPointCostMicros,
|
|
2390
|
+
foldSessionStats,
|
|
2391
|
+
statsFloorHour,
|
|
2392
|
+
statsFloorDay,
|
|
2393
|
+
statsBucketStarts,
|
|
2394
|
+
statsAggregate,
|
|
2395
|
+
statsTimeline,
|
|
2396
|
+
statsSessionRow,
|
|
2397
|
+
statsSummary,
|
|
2398
|
+
statsBudget,
|
|
1812
2399
|
ICONS,
|
|
1813
2400
|
CSS
|
|
1814
2401
|
};
|
|
1815
2402
|
return module.exports;
|
|
1816
2403
|
})();
|
|
1817
|
-
const BUILD = "2026-11-
|
|
2404
|
+
const BUILD = "2026-11-06T20:01:34.544Z";
|
|
1818
2405
|
// 构建时由 build.mjs 用 package.json 的 version 替换,避免设置页显示旧版本。
|
|
1819
|
-
const VERSION = "0.2.
|
|
2406
|
+
const VERSION = "0.2.2";
|
|
1820
2407
|
|
|
1821
2408
|
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
1822
2409
|
console.info("[dsh-message-actions] build", BUILD);
|
|
@@ -1834,6 +2421,14 @@ return module.exports;
|
|
|
1834
2421
|
findToolRowByCallId,
|
|
1835
2422
|
resolveKeyAction,
|
|
1836
2423
|
mergeMessageSummary,
|
|
2424
|
+
completionSoundEnabled,
|
|
2425
|
+
normalizeSoundTone,
|
|
2426
|
+
completionSoundTone,
|
|
2427
|
+
soundToneOptions,
|
|
2428
|
+
DEFAULT_SOUND_VOLUME,
|
|
2429
|
+
clampSoundVolume,
|
|
2430
|
+
soundGainScale,
|
|
2431
|
+
shouldPlayCompletionSound,
|
|
1837
2432
|
formatTokens,
|
|
1838
2433
|
railTurnOfAttributes,
|
|
1839
2434
|
createScheduler,
|
|
@@ -1841,6 +2436,7 @@ return module.exports;
|
|
|
1841
2436
|
formatCents,
|
|
1842
2437
|
formatYuanCents,
|
|
1843
2438
|
formatCostMicros,
|
|
2439
|
+
formatReplyCost,
|
|
1844
2440
|
periodInfo,
|
|
1845
2441
|
periodChangeText,
|
|
1846
2442
|
autoCloseAt,
|
|
@@ -1928,11 +2524,20 @@ const zh = {
|
|
|
1928
2524
|
'settings.confirmDesc': '撤回/删除前弹出确认框;关闭后直接执行',
|
|
1929
2525
|
'settings.stats': '回答统计',
|
|
1930
2526
|
'settings.statsDesc': '答行显示本次回答的 tokens 与字数',
|
|
2527
|
+
'settings.soundTone': '提示音音色',
|
|
2528
|
+
'settings.soundToneDesc': '选中即开启并试听;选「关闭」即关闭完成提示音',
|
|
2529
|
+
'settings.soundTone.double': '默认双音',
|
|
2530
|
+
'settings.soundTone.bell': '短铃',
|
|
2531
|
+
'settings.soundTone.soft': '轻提示',
|
|
2532
|
+
'settings.soundTone.off': '关闭',
|
|
2533
|
+
'settings.soundVolume': '音量',
|
|
2534
|
+
'settings.soundVolumeDesc': '作用于全部音色:0% 静音,50% 为标准音量,100% 为两倍',
|
|
1931
2535
|
'settings.soon': '即将推出',
|
|
1932
2536
|
'settings.saveFailed': '无法保存设置',
|
|
1933
2537
|
'cost.tab.actions': '消息操作',
|
|
1934
2538
|
'cost.tab.billing': '费用统计',
|
|
1935
2539
|
'cost.balance': '余额',
|
|
2540
|
+
'cost.bonusHint': '赠金 {bonus}',
|
|
1936
2541
|
'cost.daily': '日用',
|
|
1937
2542
|
'cost.perTurn': '单次',
|
|
1938
2543
|
'cost.peak': '高峰价',
|
|
@@ -1940,8 +2545,6 @@ const zh = {
|
|
|
1940
2545
|
'cost.title': '费用统计卡片',
|
|
1941
2546
|
'cost.refresh': '刷新余额',
|
|
1942
2547
|
'cost.refreshing': '正在刷新余额',
|
|
1943
|
-
'cost.pending': '待核对',
|
|
1944
|
-
'cost.pendingTitle': '余额有增加,请到 设置 → 消息费用 → 费用统计 → 余额校正 核对',
|
|
1945
2548
|
'cost.signedOut': '未登录',
|
|
1946
2549
|
'cost.apiKey': 'API key',
|
|
1947
2550
|
'cost.unavailable': '不可用',
|
|
@@ -1962,18 +2565,79 @@ const zh = {
|
|
|
1962
2565
|
'cost.settings.layoutDesc': '单行样式去背景、所有数字排成一行;多行样式带背景卡片与峰谷文字行',
|
|
1963
2566
|
'cost.layout.default': '多行样式',
|
|
1964
2567
|
'cost.layout.compact': '单行样式',
|
|
1965
|
-
'cost.
|
|
1966
|
-
'cost.
|
|
1967
|
-
'cost.
|
|
1968
|
-
'cost.
|
|
1969
|
-
'
|
|
1970
|
-
'
|
|
1971
|
-
'
|
|
1972
|
-
'
|
|
1973
|
-
'
|
|
1974
|
-
'
|
|
1975
|
-
'
|
|
1976
|
-
'
|
|
2568
|
+
'cost.balanceNote': '余额直接读取 DeepSeek 账户的充值余额(按官方规则截断至分,不含赠金;赠金另以悬停提示)。「日用」按账户余额实际下降观测,「单次」按官方价目换算,两者口径不同,不要求逐轮对齐。',
|
|
2569
|
+
'cost.settings.statsTable': '统计表',
|
|
2570
|
+
'cost.settings.statsTableDesc': '查看 Token 用量、消耗时间线与各会话成本',
|
|
2571
|
+
'cost.settings.statsTableButton': '打开统计表',
|
|
2572
|
+
'stats.entry': '统计表',
|
|
2573
|
+
'stats.entryTitle': '统计表',
|
|
2574
|
+
'stats.panelTitle': '统计表',
|
|
2575
|
+
'stats.intro': '数据来自本机真实会话日志;估算成本与费用卡片使用同一价目与峰谷规则。仅 DeepSeek 官方模型计费,本地模型只统计 token。',
|
|
2576
|
+
'stats.refresh': '刷新',
|
|
2577
|
+
'stats.close': '关闭',
|
|
2578
|
+
'stats.loading': '正在读取会话日志…',
|
|
2579
|
+
'stats.error': '读取失败',
|
|
2580
|
+
'stats.stale': '沿用上次数据',
|
|
2581
|
+
'stats.unavailable': '宿主没有提供会话查询服务,暂时无法统计',
|
|
2582
|
+
'stats.totalTokens': '总 Token 消耗',
|
|
2583
|
+
'stats.sessions': '会话数量',
|
|
2584
|
+
'stats.estCost': '估算成本',
|
|
2585
|
+
'stats.budget': '预算使用',
|
|
2586
|
+
'stats.cacheShare': '缓存命中',
|
|
2587
|
+
'stats.runningNow': '运行中',
|
|
2588
|
+
'stats.priceHint': '仅 DeepSeek 计费 · 官方价目',
|
|
2589
|
+
'stats.budgetOff': '未设预算',
|
|
2590
|
+
'stats.budgetLeft': '剩余',
|
|
2591
|
+
'stats.overBudget': '已超预算',
|
|
2592
|
+
'stats.of': ' / ',
|
|
2593
|
+
'stats.timeline': 'Token 消耗时间线',
|
|
2594
|
+
'stats.range24': '近 24 小时',
|
|
2595
|
+
'stats.range30': '近 30 天',
|
|
2596
|
+
'stats.input': '输入',
|
|
2597
|
+
'stats.cacheRead': '缓存命中',
|
|
2598
|
+
'stats.cacheWrite': '缓存写入',
|
|
2599
|
+
'stats.output': '输出',
|
|
2600
|
+
'stats.peak': '峰值',
|
|
2601
|
+
'stats.total': '合计',
|
|
2602
|
+
'stats.sessionsSection': '各会话用量',
|
|
2603
|
+
'stats.colSession': '会话',
|
|
2604
|
+
'stats.colTokens': 'Tokens',
|
|
2605
|
+
'stats.colCost': '成本',
|
|
2606
|
+
'stats.colUpdated': '更新时间',
|
|
2607
|
+
'stats.empty': '还没有可统计的会话',
|
|
2608
|
+
'stats.truncated': '仅显示用量最多的 100 个会话',
|
|
2609
|
+
'stats.ledger': '对照:费用卡片 日用 {daily} · 累计观测 {observed}',
|
|
2610
|
+
'stats.budgetEdit': '预算',
|
|
2611
|
+
'stats.budgetUnit': '元',
|
|
2612
|
+
'stats.budgetSave': '保存',
|
|
2613
|
+
'stats.budgetSaving': '保存中…',
|
|
2614
|
+
'stats.budgetHint': '按全部会话估算成本;填 0 隐藏占比',
|
|
2615
|
+
'stats.budgetNote': '预算只用于计算「预算使用」占比与剩余额度,用来提示本期花了多少;不参与计费,也不影响余额与单次换算。默认 ¥5,填 0 只显示估算成本。',
|
|
2616
|
+
'stats.budgetUsed': '已用',
|
|
2617
|
+
'stats.budgetCancel': '取消',
|
|
2618
|
+
'stats.moneyBudget': '预算',
|
|
2619
|
+
'stats.moneyBalanceSub': '充值余额',
|
|
2620
|
+
'stats.moneyDailySub': '今日累计',
|
|
2621
|
+
'stats.moneyTurnSub': '最近一轮',
|
|
2622
|
+
'stats.moneyEdit': '修改预算',
|
|
2623
|
+
'stats.budgetOffSub': '仅提示花费,不计费',
|
|
2624
|
+
'stats.budgetInvalid': '预算金额不合法:最多两位小数、≥ 0',
|
|
2625
|
+
'stats.budgetFailed': '保存失败,请稍后再试',
|
|
2626
|
+
'stats.localCost': '本地',
|
|
2627
|
+
'stats.replyCostTitle': '本条回答估算 {cost};同一轮的合计见侧边栏「单次」',
|
|
2628
|
+
'stats.localTag': '本地 · 不计费',
|
|
2629
|
+
'stats.billingLegend': '计费口径',
|
|
2630
|
+
'stats.billingDeepseek': 'DeepSeek 计费',
|
|
2631
|
+
'stats.billingLocal': '本地 · 不计费',
|
|
2632
|
+
'stats.billingNote': '仅 DeepSeek 官方模型计费;本地模型只统计 token,不计入估算成本、预算使用与日用。',
|
|
2633
|
+
'stats.running': '运行中',
|
|
2634
|
+
'stats.subagent': '子会话',
|
|
2635
|
+
'stats.noModel': '未知模型',
|
|
2636
|
+
'stats.live': '实时',
|
|
2637
|
+
'stats.now': '刚刚',
|
|
2638
|
+
'stats.minutesAgo': '{n} 分钟前',
|
|
2639
|
+
'stats.hoursAgo': '{n} 小时前',
|
|
2640
|
+
'stats.daysAgo': '{n} 天前'
|
|
1977
2641
|
};
|
|
1978
2642
|
|
|
1979
2643
|
const en = {
|
|
@@ -2023,11 +2687,20 @@ const en = {
|
|
|
2023
2687
|
'settings.confirmDesc': 'Ask before recall/delete; when off, actions run immediately',
|
|
2024
2688
|
'settings.stats': 'Reply statistics',
|
|
2025
2689
|
'settings.statsDesc': 'Show tokens and character count on reply rows',
|
|
2690
|
+
'settings.soundTone': 'Sound tone',
|
|
2691
|
+
'settings.soundToneDesc': 'Picking a tone turns it on and previews it; "Off" turns the completion sound off',
|
|
2692
|
+
'settings.soundTone.double': 'Default double',
|
|
2693
|
+
'settings.soundTone.bell': 'Bell',
|
|
2694
|
+
'settings.soundTone.soft': 'Soft',
|
|
2695
|
+
'settings.soundTone.off': 'Off',
|
|
2696
|
+
'settings.soundVolume': 'Volume',
|
|
2697
|
+
'settings.soundVolumeDesc': 'Applies to all tones: 0% mutes, 50% is normal, 100% is double',
|
|
2026
2698
|
'settings.soon': 'Coming soon',
|
|
2027
2699
|
'settings.saveFailed': 'Could not save the setting',
|
|
2028
2700
|
'cost.tab.actions': 'Message Actions',
|
|
2029
2701
|
'cost.tab.billing': 'Cost Statistics',
|
|
2030
2702
|
'cost.balance': 'Bal',
|
|
2703
|
+
'cost.bonusHint': 'Bonus {bonus}',
|
|
2031
2704
|
'cost.daily': 'Today',
|
|
2032
2705
|
'cost.perTurn': 'Turn',
|
|
2033
2706
|
'cost.peak': 'Peak',
|
|
@@ -2035,8 +2708,6 @@ const en = {
|
|
|
2035
2708
|
'cost.title': 'Cost statistics card',
|
|
2036
2709
|
'cost.refresh': 'Refresh balance',
|
|
2037
2710
|
'cost.refreshing': 'Refreshing balance',
|
|
2038
|
-
'cost.pending': 'Check',
|
|
2039
|
-
'cost.pendingTitle': 'Balance increased. Review it in Settings → Messages & Cost → Cost Statistics → Balance correction.',
|
|
2040
2711
|
'cost.signedOut': 'Signed out',
|
|
2041
2712
|
'cost.apiKey': 'API key',
|
|
2042
2713
|
'cost.unavailable': 'Unavailable',
|
|
@@ -2057,18 +2728,79 @@ const en = {
|
|
|
2057
2728
|
'cost.settings.layoutDesc': 'Single-line drops the background and keeps all numbers on one row; multi-line keeps the card and the pricing-period line',
|
|
2058
2729
|
'cost.layout.default': 'Multi-line',
|
|
2059
2730
|
'cost.layout.compact': 'Single-line',
|
|
2060
|
-
'cost.
|
|
2061
|
-
'cost.
|
|
2062
|
-
'cost.
|
|
2063
|
-
'cost.
|
|
2064
|
-
'
|
|
2065
|
-
'
|
|
2066
|
-
'
|
|
2067
|
-
'
|
|
2068
|
-
'
|
|
2069
|
-
'
|
|
2070
|
-
'
|
|
2071
|
-
'
|
|
2731
|
+
'cost.balanceNote': 'Balance is read directly from the DeepSeek account recharge balance (truncated to the cent like the official page, excluding bonus credits, which are shown separately on hover). "Today" is observed from the actual balance drop; "Turn" is converted from official list prices — different bases, so they need not match turn by turn.',
|
|
2732
|
+
'cost.settings.statsTable': 'Stats table',
|
|
2733
|
+
'cost.settings.statsTableDesc': 'Token usage, usage timeline and per-session cost',
|
|
2734
|
+
'cost.settings.statsTableButton': 'Open stats table',
|
|
2735
|
+
'stats.entry': 'Statistics',
|
|
2736
|
+
'stats.entryTitle': 'Statistics',
|
|
2737
|
+
'stats.panelTitle': 'Statistics',
|
|
2738
|
+
'stats.intro': 'Built from real local session logs; estimates share the same prices and peak/off-peak rules as the cost card. Only official DeepSeek models are billed; local models count tokens only.',
|
|
2739
|
+
'stats.refresh': 'Refresh',
|
|
2740
|
+
'stats.close': 'Close',
|
|
2741
|
+
'stats.loading': 'Reading session logs…',
|
|
2742
|
+
'stats.error': 'Could not load',
|
|
2743
|
+
'stats.stale': 'Showing stale data',
|
|
2744
|
+
'stats.unavailable': 'The host does not expose a session query service',
|
|
2745
|
+
'stats.totalTokens': 'Total tokens',
|
|
2746
|
+
'stats.sessions': 'Sessions',
|
|
2747
|
+
'stats.estCost': 'Estimated cost',
|
|
2748
|
+
'stats.budget': 'Budget used',
|
|
2749
|
+
'stats.cacheShare': 'Cache hit',
|
|
2750
|
+
'stats.runningNow': 'Running',
|
|
2751
|
+
'stats.priceHint': 'DeepSeek only · list prices',
|
|
2752
|
+
'stats.budgetOff': 'No budget',
|
|
2753
|
+
'stats.budgetLeft': 'Remaining',
|
|
2754
|
+
'stats.overBudget': 'Over budget',
|
|
2755
|
+
'stats.of': ' of ',
|
|
2756
|
+
'stats.timeline': 'Token usage timeline',
|
|
2757
|
+
'stats.range24': 'Last 24 hours',
|
|
2758
|
+
'stats.range30': 'Last 30 days',
|
|
2759
|
+
'stats.input': 'Input',
|
|
2760
|
+
'stats.cacheRead': 'Cache hit',
|
|
2761
|
+
'stats.cacheWrite': 'Cache write',
|
|
2762
|
+
'stats.output': 'Output',
|
|
2763
|
+
'stats.peak': 'Peak',
|
|
2764
|
+
'stats.total': 'Total',
|
|
2765
|
+
'stats.sessionsSection': 'Usage by session',
|
|
2766
|
+
'stats.colSession': 'Session',
|
|
2767
|
+
'stats.colTokens': 'Tokens',
|
|
2768
|
+
'stats.colCost': 'Cost',
|
|
2769
|
+
'stats.colUpdated': 'Updated',
|
|
2770
|
+
'stats.empty': 'No sessions to summarize yet',
|
|
2771
|
+
'stats.truncated': 'Showing the 100 sessions with the most usage',
|
|
2772
|
+
'stats.ledger': 'Cross-check: card today {daily} · observed total {observed}',
|
|
2773
|
+
'stats.budgetEdit': 'Budget',
|
|
2774
|
+
'stats.budgetUnit': 'CNY',
|
|
2775
|
+
'stats.budgetSave': 'Save',
|
|
2776
|
+
'stats.budgetSaving': 'Saving…',
|
|
2777
|
+
'stats.budgetHint': 'All sessions; 0 hides the ratio',
|
|
2778
|
+
'stats.budgetNote': 'The budget only computes the "budget used" ratio and remaining allowance as a spending hint. It never bills you and does not affect the balance or per-turn figures. Default ¥5; 0 shows only the estimated cost.',
|
|
2779
|
+
'stats.budgetUsed': 'used',
|
|
2780
|
+
'stats.budgetCancel': 'Cancel',
|
|
2781
|
+
'stats.moneyBudget': 'Budget',
|
|
2782
|
+
'stats.moneyBalanceSub': 'Recharge balance',
|
|
2783
|
+
'stats.moneyDailySub': 'Since midnight',
|
|
2784
|
+
'stats.moneyTurnSub': 'Latest turn',
|
|
2785
|
+
'stats.moneyEdit': 'Edit budget',
|
|
2786
|
+
'stats.budgetOffSub': 'Hint only, never billed',
|
|
2787
|
+
'stats.budgetInvalid': 'Invalid budget: at most two decimals, ≥ 0',
|
|
2788
|
+
'stats.budgetFailed': 'Could not save; try again later',
|
|
2789
|
+
'stats.localCost': 'Local',
|
|
2790
|
+
'stats.replyCostTitle': 'Estimated cost of this reply: {cost}; the turn total is shown as Last turn in the sidebar.',
|
|
2791
|
+
'stats.localTag': 'Local · unbilled',
|
|
2792
|
+
'stats.billingLegend': 'Billing scope',
|
|
2793
|
+
'stats.billingDeepseek': 'DeepSeek billed',
|
|
2794
|
+
'stats.billingLocal': 'Local · unbilled',
|
|
2795
|
+
'stats.billingNote': 'Only official DeepSeek models are billed; local models count tokens but are excluded from estimated cost, budget usage and daily spend.',
|
|
2796
|
+
'stats.running': 'Running',
|
|
2797
|
+
'stats.subagent': 'Subagent',
|
|
2798
|
+
'stats.noModel': 'Unknown model',
|
|
2799
|
+
'stats.live': 'Live',
|
|
2800
|
+
'stats.now': 'just now',
|
|
2801
|
+
'stats.minutesAgo': '{n} min ago',
|
|
2802
|
+
'stats.hoursAgo': '{n} h ago',
|
|
2803
|
+
'stats.daysAgo': '{n} d ago'
|
|
2072
2804
|
};
|
|
2073
2805
|
|
|
2074
2806
|
module.exports = { meta, zh, en };
|
|
@@ -2282,6 +3014,167 @@ return module.exports;
|
|
|
2282
3014
|
return snap.value.usageStats !== false;
|
|
2283
3015
|
}
|
|
2284
3016
|
|
|
3017
|
+
let lastTurnAtApplied = null;
|
|
3018
|
+
let lastPlayedTurnAt = null;
|
|
3019
|
+
let audioCtx = null;
|
|
3020
|
+
let audioUnlockBound = false;
|
|
3021
|
+
|
|
3022
|
+
/** 提示音开关(默认 true);设置快照未就绪时按开启处理。 */
|
|
3023
|
+
function soundEnabledNow() {
|
|
3024
|
+
if (!costForm || typeof costForm.getSnapshot !== "function") return true;
|
|
3025
|
+
const snap = costForm.getSnapshot();
|
|
3026
|
+
if (!snap || snap.status !== "ready" || typeof snap.value !== "object" || !snap.value) return true;
|
|
3027
|
+
return completionSoundEnabled(snap.value);
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
/** 当前音色(关闭时返回 'off');设置快照未就绪时按默认双音。 */
|
|
3031
|
+
function soundToneNow() {
|
|
3032
|
+
if (!costForm || typeof costForm.getSnapshot !== "function") return "double";
|
|
3033
|
+
const snap = costForm.getSnapshot();
|
|
3034
|
+
if (!snap || snap.status !== "ready" || typeof snap.value !== "object" || !snap.value) return "double";
|
|
3035
|
+
return completionSoundTone(snap.value);
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
/** 当前音量(0–100,默认 50);设置快照未就绪时按默认值。 */
|
|
3039
|
+
function soundVolumeNow() {
|
|
3040
|
+
if (!costForm || typeof costForm.getSnapshot !== "function") return DEFAULT_SOUND_VOLUME;
|
|
3041
|
+
const snap = costForm.getSnapshot();
|
|
3042
|
+
if (!snap || snap.status !== "ready" || typeof snap.value !== "object" || !snap.value) {
|
|
3043
|
+
return DEFAULT_SOUND_VOLUME;
|
|
3044
|
+
}
|
|
3045
|
+
return clampSoundVolume(snap.value.soundVolume);
|
|
3046
|
+
}
|
|
3047
|
+
|
|
3048
|
+
/**
|
|
3049
|
+
* 创建 / 唤醒 AudioContext。浏览器要求一次用户手势后才能发声:
|
|
3050
|
+
* 模块加载时注册一次全局首次点击/按键监听,提前解锁,避免任务完成时才 resume 而错过。
|
|
3051
|
+
*/
|
|
3052
|
+
function ensureAudio() {
|
|
3053
|
+
try {
|
|
3054
|
+
const Ctor = typeof window !== "undefined" ? window.AudioContext || window.webkitAudioContext : null;
|
|
3055
|
+
if (!Ctor) return null;
|
|
3056
|
+
if (!audioCtx) audioCtx = new Ctor();
|
|
3057
|
+
if (audioCtx.state !== "running" && typeof audioCtx.resume === "function") {
|
|
3058
|
+
audioCtx.resume().catch(() => {});
|
|
3059
|
+
}
|
|
3060
|
+
return audioCtx;
|
|
3061
|
+
} catch {
|
|
3062
|
+
return null;
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
function unlockAudio() {
|
|
3067
|
+
ensureAudio();
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
function installAudioUnlock() {
|
|
3071
|
+
if (audioUnlockBound) return;
|
|
3072
|
+
if (typeof window === "undefined" || typeof window.addEventListener !== "function") return;
|
|
3073
|
+
audioUnlockBound = true;
|
|
3074
|
+
window.addEventListener("pointerdown", unlockAudio, { passive: true, capture: true });
|
|
3075
|
+
window.addEventListener("keydown", unlockAudio, { passive: true, capture: true });
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
// 插件加载即挂载首次交互解锁:用户点任何按钮/发消息后再播放就不会被策略拦截。
|
|
3079
|
+
installAudioUnlock();
|
|
3080
|
+
|
|
3081
|
+
/**
|
|
3082
|
+
* 音色参数:按「双音 / 短铃 / 轻提示」给出频率与包络。
|
|
3083
|
+
* `gain` 是音量 50% 时的基准(0.12–0.18),实际峰值 = gain × soundGainScale(音量)。
|
|
3084
|
+
*/
|
|
3085
|
+
const TONE_SPECS = {
|
|
3086
|
+
double: { gain: 0.18, notes: [{ freq: 880, at: 0, dur: 0.16, type: "sine" }, { freq: 660, at: 0.15, dur: 0.2, type: "sine" }] },
|
|
3087
|
+
bell: { gain: 0.16, notes: [{ freq: 1046, at: 0, dur: 0.1, type: "triangle" }, { freq: 784, at: 0.11, dur: 0.16, type: "triangle" }] },
|
|
3088
|
+
soft: { gain: 0.12, notes: [{ freq: 523, at: 0, dur: 0.24, type: "sine" }] }
|
|
3089
|
+
};
|
|
3090
|
+
|
|
3091
|
+
function emitTone(ctx, tone, volume) {
|
|
3092
|
+
const spec = TONE_SPECS[normalizeSoundTone(tone)];
|
|
3093
|
+
if (!spec) return false;
|
|
3094
|
+
const scale = soundGainScale(volume);
|
|
3095
|
+
// 0% 音量直接不发声,避免出现「静音档仍在响」。
|
|
3096
|
+
if (!(scale > 0)) return false;
|
|
3097
|
+
const now = ctx.currentTime;
|
|
3098
|
+
const body = Math.max(...spec.notes.map((note) => note.at + note.dur));
|
|
3099
|
+
const peak = Math.max(0.0001, spec.gain * scale);
|
|
3100
|
+
const gain = ctx.createGain();
|
|
3101
|
+
gain.gain.setValueAtTime(0.0001, now);
|
|
3102
|
+
gain.gain.exponentialRampToValueAtTime(peak, now + 0.03);
|
|
3103
|
+
gain.gain.exponentialRampToValueAtTime(0.0001, now + body);
|
|
3104
|
+
gain.connect(ctx.destination);
|
|
3105
|
+
for (const note of spec.notes) {
|
|
3106
|
+
const osc = ctx.createOscillator();
|
|
3107
|
+
osc.type = note.type;
|
|
3108
|
+
osc.frequency.setValueAtTime(note.freq, now + note.at);
|
|
3109
|
+
osc.connect(gain);
|
|
3110
|
+
osc.start(now + note.at);
|
|
3111
|
+
osc.stop(now + note.at + note.dur);
|
|
3112
|
+
}
|
|
3113
|
+
return true;
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
/**
|
|
3117
|
+
* 播放完成提示音。挂起时 resume 后静默重试一次(不弹 toast):
|
|
3118
|
+
* 用户已交互过就一定能听到;仍被策略拦截则安静放弃。
|
|
3119
|
+
* @param tone 指定音色(试听用);省略时读设置快照。
|
|
3120
|
+
* @param volume 指定音量(试听用);省略时读设置快照。
|
|
3121
|
+
*/
|
|
3122
|
+
function playCompletionSound(tone, volume) {
|
|
3123
|
+
const id = typeof tone === "string" ? tone : soundToneNow();
|
|
3124
|
+
if (id === "off") return false;
|
|
3125
|
+
const vol = Number.isFinite(volume) ? clampSoundVolume(volume) : soundVolumeNow();
|
|
3126
|
+
if (!(soundGainScale(vol) > 0)) return false;
|
|
3127
|
+
const ctx = ensureAudio();
|
|
3128
|
+
if (!ctx) return false;
|
|
3129
|
+
if (ctx.state !== "running") {
|
|
3130
|
+
const retry = () => {
|
|
3131
|
+
try {
|
|
3132
|
+
if (ctx.state === "running") emitTone(ctx, id, vol);
|
|
3133
|
+
} catch {
|
|
3134
|
+
/* 静默放弃 */
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3137
|
+
if (typeof ctx.resume === "function") ctx.resume().then(retry).catch(() => {});
|
|
3138
|
+
return false;
|
|
3139
|
+
}
|
|
3140
|
+
try {
|
|
3141
|
+
return emitTone(ctx, id, vol);
|
|
3142
|
+
} catch {
|
|
3143
|
+
return false;
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
function perTurnNow() {
|
|
3148
|
+
if (!costForm || typeof costForm.getSnapshot !== "function") return true;
|
|
3149
|
+
const snap = costForm.getSnapshot();
|
|
3150
|
+
if (!snap || snap.status !== "ready" || typeof snap.value !== "object" || !snap.value) return true;
|
|
3151
|
+
return snap.value.costPerTurn !== false;
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
/** 单次费用写明的那一刻判定提示音:同一状态更新里出数字、响一次。 */
|
|
3155
|
+
function maybeCompletionSound(value) {
|
|
3156
|
+
const turn = value && value.lastTurn ? value.lastTurn : null;
|
|
3157
|
+
const at = turn && Number.isFinite(turn.at) ? turn.at : null;
|
|
3158
|
+
if (at === null) return;
|
|
3159
|
+
const previousAt = lastTurnAtApplied;
|
|
3160
|
+
lastTurnAtApplied = at;
|
|
3161
|
+
if (previousAt === null) return; // 首次快照只记基线,刷新页面不补响
|
|
3162
|
+
if (!shouldPlayCompletionSound({
|
|
3163
|
+
enabled: costEnabledNow() && soundEnabledNow(),
|
|
3164
|
+
settled: true,
|
|
3165
|
+
previousAt,
|
|
3166
|
+
at,
|
|
3167
|
+
lastPlayedAt: lastPlayedTurnAt
|
|
3168
|
+
})) return;
|
|
3169
|
+
lastPlayedTurnAt = at;
|
|
3170
|
+
playCompletionSound();
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3173
|
+
function applyCostState(value) {
|
|
3174
|
+
patchCostState({ status: "ready", value, fetchedAt: Date.now(), error: "" });
|
|
3175
|
+
maybeCompletionSound(value);
|
|
3176
|
+
}
|
|
3177
|
+
|
|
2285
3178
|
async function fetchCostState(force) {
|
|
2286
3179
|
try {
|
|
2287
3180
|
const { status, data } = await getJson(
|
|
@@ -2289,7 +3182,7 @@ return module.exports;
|
|
|
2289
3182
|
force ? "refresh=1" : undefined
|
|
2290
3183
|
);
|
|
2291
3184
|
if (status === 200 && data && data.ok && data.value) {
|
|
2292
|
-
|
|
3185
|
+
applyCostState(data.value);
|
|
2293
3186
|
return data.value;
|
|
2294
3187
|
}
|
|
2295
3188
|
patchCostState({ status: "error", error: "request" });
|
|
@@ -2305,6 +3198,39 @@ return module.exports;
|
|
|
2305
3198
|
}
|
|
2306
3199
|
}
|
|
2307
3200
|
|
|
3201
|
+
// 结算推送:带 wait=<已知 lastTurn.at> 的长轮询,宿主结算后立即返回。
|
|
3202
|
+
let costWaitTimer = null;
|
|
3203
|
+
let costWaitActive = false;
|
|
3204
|
+
|
|
3205
|
+
function costWaitStep() {
|
|
3206
|
+
costWaitTimer = null;
|
|
3207
|
+
if (!costPolling || !costWaitActive) return;
|
|
3208
|
+
if (typeof document !== "undefined" && document.hidden) {
|
|
3209
|
+
costWaitTimer = setTimeout(costWaitStep, 1500);
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
if (!costEnabledNow() || !perTurnNow()) {
|
|
3213
|
+
costWaitTimer = setTimeout(costWaitStep, 1500);
|
|
3214
|
+
return;
|
|
3215
|
+
}
|
|
3216
|
+
const wait = lastTurnAtApplied === null ? 0 : lastTurnAtApplied;
|
|
3217
|
+
getJson("/dsh-message-actions/cost/state", "wait=" + wait)
|
|
3218
|
+
.then(({ status, data }) => {
|
|
3219
|
+
if (!costPolling || !costWaitActive) return;
|
|
3220
|
+
if (status === 200 && data && data.ok && data.value) applyCostState(data.value);
|
|
3221
|
+
costWaitTimer = setTimeout(costWaitStep, 0);
|
|
3222
|
+
})
|
|
3223
|
+
.catch(() => {
|
|
3224
|
+
costWaitTimer = setTimeout(costWaitStep, 2000);
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
function startCostWaitLoop() {
|
|
3229
|
+
if (costWaitActive) return;
|
|
3230
|
+
costWaitActive = true;
|
|
3231
|
+
costWaitStep();
|
|
3232
|
+
}
|
|
3233
|
+
|
|
2308
3234
|
function startCostPolling(form) {
|
|
2309
3235
|
costForm = form;
|
|
2310
3236
|
if (costPolling) return;
|
|
@@ -2316,6 +3242,7 @@ return module.exports;
|
|
|
2316
3242
|
};
|
|
2317
3243
|
tick();
|
|
2318
3244
|
costPollTimer = setInterval(tick, COST_POLL_MS);
|
|
3245
|
+
startCostWaitLoop();
|
|
2319
3246
|
if (typeof document !== "undefined" && !costVisibilityBound) {
|
|
2320
3247
|
costVisibilityBound = true;
|
|
2321
3248
|
document.addEventListener("visibilitychange", onCostVisibility);
|
|
@@ -2324,6 +3251,11 @@ return module.exports;
|
|
|
2324
3251
|
|
|
2325
3252
|
function stopCostPolling() {
|
|
2326
3253
|
costPolling = false;
|
|
3254
|
+
costWaitActive = false;
|
|
3255
|
+
if (costWaitTimer !== null) {
|
|
3256
|
+
clearTimeout(costWaitTimer);
|
|
3257
|
+
costWaitTimer = null;
|
|
3258
|
+
}
|
|
2327
3259
|
if (costPollTimer !== null) {
|
|
2328
3260
|
clearInterval(costPollTimer);
|
|
2329
3261
|
costPollTimer = null;
|
|
@@ -2556,8 +3488,10 @@ return module.exports;
|
|
|
2556
3488
|
// 工具行删除只遮蔽该工具节点,不影响同轮其它内容。
|
|
2557
3489
|
applyHiddenTool(this.sessionId, opts.nodeKey);
|
|
2558
3490
|
}
|
|
2559
|
-
if (action === "recall"
|
|
2560
|
-
refillComposer(this.sessionId, value.refillText);
|
|
3491
|
+
if (action === "recall") {
|
|
3492
|
+
if (value.refillText) refillComposer(this.sessionId, value.refillText);
|
|
3493
|
+
// 图片 / 文件:按附件 id 取回字节,交给官方输入框的 drop 通道恢复成真实附件。
|
|
3494
|
+
restoreRecallAttachments(this.sessionId, value.attachments).catch(() => {});
|
|
2561
3495
|
}
|
|
2562
3496
|
// 刷新消息快照(拿到最新 goneTurns),再重放导航隐藏。
|
|
2563
3497
|
await this.fetchMessages(true).catch(() => {});
|
|
@@ -2627,6 +3561,49 @@ return module.exports;
|
|
|
2627
3561
|
}
|
|
2628
3562
|
}
|
|
2629
3563
|
|
|
3564
|
+
// 附件回读路由:撤回后按 id 取回字节(image 为宿主归一化后的图片)。
|
|
3565
|
+
const ATTACHMENT_PATH = "/dsh-message-actions/attachment";
|
|
3566
|
+
|
|
3567
|
+
/**
|
|
3568
|
+
* 撤回后恢复图片 / 文件附件。
|
|
3569
|
+
* 取回字节 -> 构造 File -> 在 document 上派发 drop 事件,
|
|
3570
|
+
* 交给官方输入框的 `onAddFiles`(createDrafts + addFiles)恢复成真实附件。
|
|
3571
|
+
* 无附件、环境不支持 DataTransfer 或全部取回失败时静默跳过。
|
|
3572
|
+
*/
|
|
3573
|
+
async function restoreRecallAttachments(sessionId, attachments) {
|
|
3574
|
+
if (!Array.isArray(attachments) || attachments.length === 0) return;
|
|
3575
|
+
if (typeof document === "undefined" || typeof DataTransfer !== "function") return;
|
|
3576
|
+
const files = [];
|
|
3577
|
+
for (const meta of attachments) {
|
|
3578
|
+
if (!meta || typeof meta.attachmentId !== "string") continue;
|
|
3579
|
+
try {
|
|
3580
|
+
const query =
|
|
3581
|
+
"sessionId=" + encodeURIComponent(sessionId) +
|
|
3582
|
+
"&attachmentId=" + encodeURIComponent(meta.attachmentId);
|
|
3583
|
+
const res = await fetchWithTimeout(apiUrl(ATTACHMENT_PATH, query), { cache: "no-store" });
|
|
3584
|
+
if (!res.ok) continue;
|
|
3585
|
+
const blob = await res.blob();
|
|
3586
|
+
const name = typeof meta.name === "string" && meta.name.length > 0
|
|
3587
|
+
? meta.name
|
|
3588
|
+
: (meta.kind === "image" ? "image.png" : "attachment");
|
|
3589
|
+
files.push(new File([blob], name, { type: meta.mediaType || blob.type || "" }));
|
|
3590
|
+
} catch {
|
|
3591
|
+
/* 单个附件失败不影响其它附件 */
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
if (files.length === 0) return;
|
|
3595
|
+
const transfer = new DataTransfer();
|
|
3596
|
+
for (const file of files) transfer.items.add(file);
|
|
3597
|
+
let event;
|
|
3598
|
+
try {
|
|
3599
|
+
event = new DragEvent("drop", { bubbles: true, cancelable: true, dataTransfer: transfer });
|
|
3600
|
+
} catch {
|
|
3601
|
+
event = new Event("drop", { bubbles: true, cancelable: true });
|
|
3602
|
+
Object.defineProperty(event, "dataTransfer", { value: transfer });
|
|
3603
|
+
}
|
|
3604
|
+
document.dispatchEvent(event);
|
|
3605
|
+
}
|
|
3606
|
+
|
|
2630
3607
|
// -------------------------------------------------------------------------
|
|
2631
3608
|
// 问行按钮 DOM 注入
|
|
2632
3609
|
// -------------------------------------------------------------------------
|
|
@@ -3188,14 +4165,22 @@ return module.exports;
|
|
|
3188
4165
|
if (config && config.stats === false) return null;
|
|
3189
4166
|
if (!row || words === 0) return null;
|
|
3190
4167
|
|
|
4168
|
+
// 单条回答金额:只认该条自己的 usage(服务端已算好 costMicros),
|
|
4169
|
+
// 中间步骤没有 usage 时不拿同轮其它回答的金额兜底,避免重复计价。
|
|
4170
|
+
const replyCost = row && Number.isFinite(row.costMicros)
|
|
4171
|
+
? (row.billable === false ? tt("stats.localCost") : formatReplyCost(row.costMicros))
|
|
4172
|
+
: null;
|
|
4173
|
+
|
|
3191
4174
|
const label = [
|
|
3192
4175
|
tokens == null ? null : formatTokens(tokens) + " tok",
|
|
3193
|
-
words + " " + tt("stats.unit")
|
|
4176
|
+
words + " " + tt("stats.unit"),
|
|
4177
|
+
replyCost
|
|
3194
4178
|
].filter(Boolean).join(" \u00b7 ");
|
|
3195
4179
|
|
|
3196
4180
|
return e("span", {
|
|
3197
4181
|
className: "dma-stats",
|
|
3198
|
-
title: tt("stats.title", { tokens: tokens == null ? "?" : tokens, words })
|
|
4182
|
+
title: tt("stats.title", { tokens: tokens == null ? "?" : tokens, words }) +
|
|
4183
|
+
(replyCost ? " \u00b7 " + tt("stats.replyCostTitle", { cost: replyCost }) : "")
|
|
3199
4184
|
}, label);
|
|
3200
4185
|
}
|
|
3201
4186
|
|
|
@@ -3405,7 +4390,598 @@ return module.exports;
|
|
|
3405
4390
|
);
|
|
3406
4391
|
}
|
|
3407
4392
|
|
|
4393
|
+
// -------------------------------------------------------------------------
|
|
4394
|
+
// 会话统计浮层:body 级挂载,会话页与设置页都能打开
|
|
4395
|
+
// -------------------------------------------------------------------------
|
|
4396
|
+
|
|
4397
|
+
const STATS_ROUTE = "/dsh-message-actions/stats";
|
|
4398
|
+
const STATS_BUDGET_ROUTE = "/dsh-message-actions/stats/budget";
|
|
4399
|
+
const STATS_POLL_MS = 10000;
|
|
4400
|
+
|
|
4401
|
+
const STATS_ICON = '<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">' +
|
|
4402
|
+
'<path d="M3 13V9M6.7 13V6M10.4 13V8.5M14 13V3" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg>';
|
|
4403
|
+
const REFRESH_ICON = '<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">' +
|
|
4404
|
+
'<path d="M13 8a5 5 0 1 1-1.6-3.7M13 2.6V5.4h-2.8" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
4405
|
+
|
|
4406
|
+
let statsHost = null;
|
|
4407
|
+
let statsOpener = null;
|
|
4408
|
+
const statsStore = createStore({ open: false, seq: 0 });
|
|
4409
|
+
|
|
4410
|
+
function openStatsPanel(opener) {
|
|
4411
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
4412
|
+
if (!ReactDOMClient || typeof ReactDOMClient.createRoot !== "function") return;
|
|
4413
|
+
statsOpener = opener || (document.activeElement instanceof HTMLElement ? document.activeElement : null);
|
|
4414
|
+
if (!statsHost) {
|
|
4415
|
+
statsHost = document.createElement("div");
|
|
4416
|
+
statsHost.className = "dma-stats-root";
|
|
4417
|
+
document.body.appendChild(statsHost);
|
|
4418
|
+
ReactDOMClient.createRoot(statsHost).render(e(StatsOverlay));
|
|
4419
|
+
}
|
|
4420
|
+
const snapshot = statsStore.getSnapshot();
|
|
4421
|
+
statsStore.set({ open: true, seq: snapshot.seq + 1 });
|
|
4422
|
+
}
|
|
4423
|
+
|
|
4424
|
+
function closeStatsPanel() {
|
|
4425
|
+
const snapshot = statsStore.getSnapshot();
|
|
4426
|
+
if (!snapshot.open) return;
|
|
4427
|
+
statsStore.set({ open: false, seq: snapshot.seq + 1 });
|
|
4428
|
+
const opener = statsOpener;
|
|
4429
|
+
statsOpener = null;
|
|
4430
|
+
if (opener && typeof opener.focus === "function" && opener.isConnected) {
|
|
4431
|
+
try {
|
|
4432
|
+
opener.focus({ preventScroll: true });
|
|
4433
|
+
} catch {
|
|
4434
|
+
/* ignore */
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
|
|
4439
|
+
function StatsOverlay() {
|
|
4440
|
+
const snapshot = React.useSyncExternalStore(statsStore.subscribe, statsStore.getSnapshot, statsStore.getSnapshot);
|
|
4441
|
+
if (!snapshot.open) return null;
|
|
4442
|
+
return e(StatsPanel, { key: snapshot.seq, onClose: closeStatsPanel });
|
|
4443
|
+
}
|
|
4444
|
+
|
|
4445
|
+
function statsPct(value) {
|
|
4446
|
+
const n = Number.isFinite(value) ? Math.max(0, Math.min(100, value)) : 0;
|
|
4447
|
+
return (Math.round(n * 10) / 10) + "%";
|
|
4448
|
+
}
|
|
4449
|
+
|
|
4450
|
+
/** 比例文本不封顶(超预算时仍显示真实百分比)。 */
|
|
4451
|
+
function statsRatioText(value) {
|
|
4452
|
+
const n = Number.isFinite(value) ? Math.max(0, value) : 0;
|
|
4453
|
+
return (Math.round(n * 10) / 10) + "%";
|
|
4454
|
+
}
|
|
4455
|
+
|
|
4456
|
+
function statsShare(part, total) {
|
|
4457
|
+
if (!Number.isFinite(part) || !Number.isFinite(total) || total <= 0) return 0;
|
|
4458
|
+
return (part / total) * 100;
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
function statsClock(ts) {
|
|
4462
|
+
const date = new Date(ts);
|
|
4463
|
+
const pad = (n) => (n < 10 ? "0" + n : String(n));
|
|
4464
|
+
return pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + pad(date.getHours()) + ":" + pad(date.getMinutes());
|
|
4465
|
+
}
|
|
4466
|
+
|
|
4467
|
+
function statsRelative(ts, tt) {
|
|
4468
|
+
if (!Number.isFinite(ts) || ts <= 0) return "—";
|
|
4469
|
+
const diff = Math.max(0, Date.now() - ts);
|
|
4470
|
+
if (diff < 60 * 1000) return tt("stats.now");
|
|
4471
|
+
if (diff < 60 * 60 * 1000) return tt("stats.minutesAgo", { n: Math.floor(diff / 60000) });
|
|
4472
|
+
if (diff < 24 * 60 * 60 * 1000) return tt("stats.hoursAgo", { n: Math.floor(diff / 3600000) });
|
|
4473
|
+
return tt("stats.daysAgo", { n: Math.floor(diff / 86400000) });
|
|
4474
|
+
}
|
|
4475
|
+
|
|
4476
|
+
function StatsLegend({ t: tt }) {
|
|
4477
|
+
const rows = [
|
|
4478
|
+
["input", "dma-stats-seg-input"],
|
|
4479
|
+
["cacheRead", "dma-stats-seg-cacheRead"],
|
|
4480
|
+
["cacheWrite", "dma-stats-seg-cacheWrite"],
|
|
4481
|
+
["output", "dma-stats-seg-output"]
|
|
4482
|
+
];
|
|
4483
|
+
return e("div", { className: "dma-stats-legend" },
|
|
4484
|
+
rows.map(([key, cls]) => e("span", { key },
|
|
4485
|
+
e("i", { className: "dma-stats-swatch " + cls }),
|
|
4486
|
+
tt("stats." + key))
|
|
4487
|
+
)
|
|
4488
|
+
);
|
|
4489
|
+
}
|
|
4490
|
+
|
|
4491
|
+
function StatsStack({ bucket, max, className }) {
|
|
4492
|
+
const total = Number.isFinite(bucket.tokens) ? bucket.tokens : 0;
|
|
4493
|
+
const height = max > 0 ? statsShare(total, max) : 0;
|
|
4494
|
+
// 计费口径细条:DeepSeek 计费(深蓝)/ 本地 · 不计费(中性灰)。
|
|
4495
|
+
// 四色分类已占用蓝色系,因此不重上分类色,而是另加一条独立细条与独立图例。
|
|
4496
|
+
const billableTokens = Number.isFinite(bucket.billableTokens) ? bucket.billableTokens : total;
|
|
4497
|
+
const localTokens = Number.isFinite(bucket.localTokens) ? bucket.localTokens : 0;
|
|
4498
|
+
const segments = [
|
|
4499
|
+
["input", "dma-stats-seg-input"],
|
|
4500
|
+
["cacheRead", "dma-stats-seg-cacheRead"],
|
|
4501
|
+
["cacheWrite", "dma-stats-seg-cacheWrite"],
|
|
4502
|
+
["output", "dma-stats-seg-output"]
|
|
4503
|
+
];
|
|
4504
|
+
return e("div", { className: "dma-stats-col" },
|
|
4505
|
+
e("div", {
|
|
4506
|
+
className: "dma-stats-stack" + (className ? " " + className : ""),
|
|
4507
|
+
style: { height: statsPct(height) }
|
|
4508
|
+
},
|
|
4509
|
+
segments.map(([key, cls]) => {
|
|
4510
|
+
const part = Number.isFinite(bucket[key]) ? bucket[key] : 0;
|
|
4511
|
+
if (part <= 0 || total <= 0) return null;
|
|
4512
|
+
return e("i", {
|
|
4513
|
+
key,
|
|
4514
|
+
className: "dma-stats-seg " + cls,
|
|
4515
|
+
style: { height: statsPct(statsShare(part, total)) }
|
|
4516
|
+
});
|
|
4517
|
+
})
|
|
4518
|
+
),
|
|
4519
|
+
total > 0
|
|
4520
|
+
? e("div", { className: "dma-stats-billing-bar" },
|
|
4521
|
+
billableTokens > 0
|
|
4522
|
+
? e("i", { className: "dma-stats-billing-deepseek", style: { width: statsPct(statsShare(billableTokens, total)) } })
|
|
4523
|
+
: null,
|
|
4524
|
+
localTokens > 0
|
|
4525
|
+
? e("i", { className: "dma-stats-billing-local", style: { width: statsPct(statsShare(localTokens, total)) } })
|
|
4526
|
+
: null
|
|
4527
|
+
)
|
|
4528
|
+
: null
|
|
4529
|
+
);
|
|
4530
|
+
}
|
|
4531
|
+
|
|
4532
|
+
function StatsTimeline({ t: tt, series, range, onRange }) {
|
|
4533
|
+
const buckets = range === "hour" ? (series.hourly || []).slice(-24) : (series.daily || []);
|
|
4534
|
+
let max = 0;
|
|
4535
|
+
let billableTotal = 0;
|
|
4536
|
+
let localTotal = 0;
|
|
4537
|
+
for (const bucket of buckets) {
|
|
4538
|
+
if (bucket.tokens > max) max = bucket.tokens;
|
|
4539
|
+
billableTotal += Number.isFinite(bucket.billableTokens) ? bucket.billableTokens : bucket.tokens;
|
|
4540
|
+
localTotal += Number.isFinite(bucket.localTokens) ? bucket.localTokens : 0;
|
|
4541
|
+
}
|
|
4542
|
+
const first = buckets.length > 0 ? buckets[0].t : 0;
|
|
4543
|
+
const last = buckets.length > 0 ? buckets[buckets.length - 1].t : 0;
|
|
4544
|
+
return e("div", { className: "dma-stats-section" },
|
|
4545
|
+
e("div", { className: "dma-stats-section-head" },
|
|
4546
|
+
e("h4", { className: "dma-stats-section-title" }, tt("stats.timeline")),
|
|
4547
|
+
e("div", { className: "dma-stats-range", role: "group", "aria-label": tt("stats.timeline") },
|
|
4548
|
+
e("button", {
|
|
4549
|
+
type: "button",
|
|
4550
|
+
"aria-pressed": range === "hour" ? "true" : "false",
|
|
4551
|
+
onClick: () => onRange("hour")
|
|
4552
|
+
}, tt("stats.range24")),
|
|
4553
|
+
e("button", {
|
|
4554
|
+
type: "button",
|
|
4555
|
+
"aria-pressed": range === "day" ? "true" : "false",
|
|
4556
|
+
onClick: () => onRange("day")
|
|
4557
|
+
}, tt("stats.range30"))
|
|
4558
|
+
)
|
|
4559
|
+
),
|
|
4560
|
+
e("div", { className: "dma-stats-chart-card" },
|
|
4561
|
+
e("div", { className: "dma-stats-chart-meta" },
|
|
4562
|
+
e("span", {}, statsClock(first) + " → " + statsClock(last)),
|
|
4563
|
+
e("span", {}, tt("stats.peak") + " " + formatTokens(max))
|
|
4564
|
+
),
|
|
4565
|
+
e("div", {
|
|
4566
|
+
className: "dma-stats-chart",
|
|
4567
|
+
role: "img",
|
|
4568
|
+
"aria-label": tt("stats.timeline") + ": " + tt("stats.total") + " " + formatTokens(
|
|
4569
|
+
buckets.reduce((sum, bucket) => sum + (Number.isFinite(bucket.tokens) ? bucket.tokens : 0), 0)
|
|
4570
|
+
)
|
|
4571
|
+
},
|
|
4572
|
+
buckets.map((bucket, index) => e("div", {
|
|
4573
|
+
key: bucket.t,
|
|
4574
|
+
title: statsClock(bucket.t) + " · " + formatTokens(bucket.tokens) + " · " + formatCostMicros(bucket.costMicros)
|
|
4575
|
+
+ (Number.isFinite(bucket.localTokens) && bucket.localTokens > 0
|
|
4576
|
+
? " · " + tt("stats.billingLocal") + " " + formatTokens(bucket.localTokens)
|
|
4577
|
+
: "")
|
|
4578
|
+
}, e(StatsStack, { bucket, max })))
|
|
4579
|
+
),
|
|
4580
|
+
e("div", { className: "dma-stats-axis" },
|
|
4581
|
+
[0, Math.floor(buckets.length / 3), Math.floor((buckets.length * 2) / 3), Math.max(0, buckets.length - 1)]
|
|
4582
|
+
.map((position, index) => e("span", { key: index },
|
|
4583
|
+
buckets[position] ? statsClock(buckets[position].t).slice(0, 5) : ""))
|
|
4584
|
+
),
|
|
4585
|
+
e("div", { className: "dma-stats-legend-row" },
|
|
4586
|
+
e(StatsLegend, { t: tt }),
|
|
4587
|
+
e("div", { className: "dma-stats-legend dma-stats-legend-billing" },
|
|
4588
|
+
e("span", {},
|
|
4589
|
+
e("i", { className: "dma-stats-swatch dma-stats-billing-deepseek" }),
|
|
4590
|
+
tt("stats.billingDeepseek") + " " + formatTokens(billableTotal)),
|
|
4591
|
+
e("span", {},
|
|
4592
|
+
e("i", { className: "dma-stats-swatch dma-stats-billing-local" }),
|
|
4593
|
+
tt("stats.billingLocal") + " " + formatTokens(localTotal))
|
|
4594
|
+
)
|
|
4595
|
+
)
|
|
4596
|
+
)
|
|
4597
|
+
);
|
|
4598
|
+
}
|
|
4599
|
+
|
|
4600
|
+
function StatsSessionRows({ t: tt, rows, truncated, total }) {
|
|
4601
|
+
return e("div", { className: "dma-stats-section" },
|
|
4602
|
+
e("div", { className: "dma-stats-section-head" },
|
|
4603
|
+
e("h4", { className: "dma-stats-section-title" }, tt("stats.sessionsSection")),
|
|
4604
|
+
e("span", { className: "dma-stats-note" }, truncated ? tt("stats.truncated") : total + " / " + total)
|
|
4605
|
+
),
|
|
4606
|
+
e("div", { className: "dma-stats-rows" },
|
|
4607
|
+
e("div", { className: "dma-stats-row dma-stats-row-head", "aria-hidden": "true" },
|
|
4608
|
+
e("span", {}, tt("stats.colSession")),
|
|
4609
|
+
e("span", { className: "dma-stats-cell-right" }, tt("stats.colTokens")),
|
|
4610
|
+
e("span", { className: "dma-stats-cell-right" }, tt("stats.colCost")),
|
|
4611
|
+
e("span", { className: "dma-stats-cell-right" }, tt("stats.colUpdated"))
|
|
4612
|
+
),
|
|
4613
|
+
rows.length === 0
|
|
4614
|
+
? e("div", { className: "dma-stats-empty" }, tt("stats.empty"))
|
|
4615
|
+
: rows.map((row) => {
|
|
4616
|
+
// 只有本地用量时成本显示「本地」而不是 ¥0.00,避免误读为「花了 0 元」。
|
|
4617
|
+
const localOnly = Number.isFinite(row.localTokens) && row.localTokens > 0 &&
|
|
4618
|
+
!(Number.isFinite(row.billableTokens) && row.billableTokens > 0);
|
|
4619
|
+
return e("div", { key: row.id, className: "dma-stats-row" },
|
|
4620
|
+
e("div", { className: "dma-stats-cell" },
|
|
4621
|
+
e("div", { className: "dma-stats-row-title" },
|
|
4622
|
+
e("b", { title: row.title }, row.title),
|
|
4623
|
+
localOnly ? e("span", { className: "dma-stats-pill dma-stats-pill-local" }, tt("stats.localTag")) : null,
|
|
4624
|
+
row.running ? e("span", { className: "dma-stats-pill dma-stats-pill-running" }, tt("stats.running")) : null,
|
|
4625
|
+
row.subagent ? e("span", { className: "dma-stats-pill" }, tt("stats.subagent")) : null
|
|
4626
|
+
),
|
|
4627
|
+
e("div", { className: "dma-stats-meta" },
|
|
4628
|
+
(row.model || tt("stats.noModel")) + " · " + row.turns + " turns · " + row.messages + " msgs"),
|
|
4629
|
+
e("div", { className: "dma-stats-mini" },
|
|
4630
|
+
e("i", { className: "dma-stats-seg-input", style: { width: statsPct(statsShare(row.tokens.input, row.tokens.total || 1)) } }),
|
|
4631
|
+
e("i", { className: "dma-stats-seg-cacheRead", style: { width: statsPct(statsShare(row.tokens.cacheRead, row.tokens.total || 1)) } }),
|
|
4632
|
+
e("i", { className: "dma-stats-seg-cacheWrite", style: { width: statsPct(statsShare(row.tokens.cacheWrite, row.tokens.total || 1)) } }),
|
|
4633
|
+
e("i", { className: "dma-stats-seg-output", style: { width: statsPct(statsShare(row.tokens.output, row.tokens.total || 1)) } })
|
|
4634
|
+
)
|
|
4635
|
+
),
|
|
4636
|
+
e("span", { className: "dma-stats-cell dma-stats-cell-right" }, formatTokens(row.tokens.total)),
|
|
4637
|
+
e("span", {
|
|
4638
|
+
className: "dma-stats-cell dma-stats-cell-right",
|
|
4639
|
+
title: localOnly ? tt("stats.billingNote") : undefined
|
|
4640
|
+
}, localOnly ? tt("stats.localCost") : formatCostMicros(row.costMicros)),
|
|
4641
|
+
e("span", { className: "dma-stats-cell dma-stats-cell-right dma-stats-meta" },
|
|
4642
|
+
statsRelative(row.lastActiveAt, tt))
|
|
4643
|
+
);
|
|
4644
|
+
})
|
|
4645
|
+
)
|
|
4646
|
+
);
|
|
4647
|
+
}
|
|
4648
|
+
|
|
4649
|
+
function StatsPanel({ onClose }) {
|
|
4650
|
+
const tt = t;
|
|
4651
|
+
const [state, setState] = React.useState({ status: "loading", data: null, error: "" });
|
|
4652
|
+
const [range, setRange] = React.useState("hour");
|
|
4653
|
+
const [budgetText, setBudgetText] = React.useState("");
|
|
4654
|
+
const [budgetEditing, setBudgetEditing] = React.useState(false);
|
|
4655
|
+
const [budgetBusy, setBudgetBusy] = React.useState(false);
|
|
4656
|
+
const [budgetError, setBudgetError] = React.useState("");
|
|
4657
|
+
const alive = React.useRef(true);
|
|
4658
|
+
const budgetInit = React.useRef(false);
|
|
4659
|
+
|
|
4660
|
+
const load = React.useCallback(async () => {
|
|
4661
|
+
try {
|
|
4662
|
+
const res = await getJson(STATS_ROUTE);
|
|
4663
|
+
if (!alive.current) return;
|
|
4664
|
+
if (res.status === 200 && res.data && res.data.ok) {
|
|
4665
|
+
setState({ status: "ready", data: res.data.value, error: "" });
|
|
4666
|
+
return;
|
|
4667
|
+
}
|
|
4668
|
+
const message = res.data && res.data.error && res.data.error.message
|
|
4669
|
+
? String(res.data.error.message)
|
|
4670
|
+
: tt("stats.error");
|
|
4671
|
+
setState((prev) => ({ status: prev.data ? "stale" : "error", data: prev.data, error: message }));
|
|
4672
|
+
} catch (err) {
|
|
4673
|
+
if (!alive.current) return;
|
|
4674
|
+
setState((prev) => ({
|
|
4675
|
+
status: prev.data ? "stale" : "error",
|
|
4676
|
+
data: prev.data,
|
|
4677
|
+
error: err instanceof Error ? err.message : tt("stats.error")
|
|
4678
|
+
}));
|
|
4679
|
+
}
|
|
4680
|
+
}, [tt]);
|
|
4681
|
+
|
|
4682
|
+
React.useEffect(() => {
|
|
4683
|
+
alive.current = true;
|
|
4684
|
+
load();
|
|
4685
|
+
const timer = setInterval(() => {
|
|
4686
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
4687
|
+
load();
|
|
4688
|
+
}, STATS_POLL_MS);
|
|
4689
|
+
const onVisibility = () => {
|
|
4690
|
+
if (typeof document !== "undefined" && document.visibilityState === "visible") load();
|
|
4691
|
+
};
|
|
4692
|
+
if (typeof document !== "undefined") document.addEventListener("visibilitychange", onVisibility);
|
|
4693
|
+
return () => {
|
|
4694
|
+
alive.current = false;
|
|
4695
|
+
clearInterval(timer);
|
|
4696
|
+
if (typeof document !== "undefined") document.removeEventListener("visibilitychange", onVisibility);
|
|
4697
|
+
};
|
|
4698
|
+
}, [load]);
|
|
4699
|
+
|
|
4700
|
+
React.useEffect(() => {
|
|
4701
|
+
const data = state.data;
|
|
4702
|
+
if (budgetInit.current || !data || !data.budget) return;
|
|
4703
|
+
budgetInit.current = true;
|
|
4704
|
+
setBudgetText(formatCents(data.budget.amountCents));
|
|
4705
|
+
}, [state.data]);
|
|
4706
|
+
|
|
4707
|
+
useOverlayKeys({ active: true, primaryEnabled: false, busy: budgetBusy, onDismiss: onClose, onPrimary: () => {} });
|
|
4708
|
+
|
|
4709
|
+
const data = state.data;
|
|
4710
|
+
const loading = state.status === "loading";
|
|
4711
|
+
const totals = data ? data.totals : null;
|
|
4712
|
+
const budget = data ? data.budget : null;
|
|
4713
|
+
const ledger = data ? data.ledger : null;
|
|
4714
|
+
const ratio = budget && budget.enabled ? budget.ratio * 100 : 0;
|
|
4715
|
+
const over = budget && budget.enabled && budget.remainingCents === 0 && budget.spentCents > 0;
|
|
4716
|
+
const cacheShare = totals && totals.tokens.total > 0
|
|
4717
|
+
? statsShare(totals.tokens.cacheRead, totals.tokens.total)
|
|
4718
|
+
: 0;
|
|
4719
|
+
const kpi = [
|
|
4720
|
+
{
|
|
4721
|
+
label: tt("stats.totalTokens"),
|
|
4722
|
+
value: totals ? formatTokens(totals.tokens.total) : "—",
|
|
4723
|
+
sub: totals ? tt("stats.cacheShare") + " " + statsPct(cacheShare) : ""
|
|
4724
|
+
},
|
|
4725
|
+
{
|
|
4726
|
+
label: tt("stats.sessions"),
|
|
4727
|
+
value: totals ? String(totals.sessions) : "—",
|
|
4728
|
+
sub: totals ? tt("stats.runningNow") + " " + totals.running : ""
|
|
4729
|
+
},
|
|
4730
|
+
{
|
|
4731
|
+
label: tt("stats.estCost"),
|
|
4732
|
+
value: totals ? formatCostMicros(totals.costMicros) : "—",
|
|
4733
|
+
sub: tt("stats.priceHint")
|
|
4734
|
+
}
|
|
4735
|
+
];
|
|
4736
|
+
const statsCard = (item) => e("div", { key: item.label, className: "dma-stats-card" },
|
|
4737
|
+
e("span", { className: "dma-stats-card-label" }, item.label),
|
|
4738
|
+
e("span", { className: "dma-stats-card-value", title: item.value }, item.value),
|
|
4739
|
+
e("span", { className: "dma-stats-card-sub" }, item.sub)
|
|
4740
|
+
);
|
|
4741
|
+
|
|
4742
|
+
async function saveBudget() {
|
|
4743
|
+
if (budgetBusy) return;
|
|
4744
|
+
const check = validateCorrectionAmount(budgetText);
|
|
4745
|
+
if (!check.ok) {
|
|
4746
|
+
setBudgetError(tt("stats.budgetInvalid"));
|
|
4747
|
+
return;
|
|
4748
|
+
}
|
|
4749
|
+
setBudgetBusy(true);
|
|
4750
|
+
setBudgetError("");
|
|
4751
|
+
try {
|
|
4752
|
+
const res = await postJson(STATS_BUDGET_ROUTE, { budgetYuan: String(budgetText).trim() });
|
|
4753
|
+
if (res.status === 200 && res.data && res.data.ok) {
|
|
4754
|
+
setBudgetText(formatCents(res.data.value.budgetCents));
|
|
4755
|
+
if (alive.current) setBudgetEditing(false);
|
|
4756
|
+
await load();
|
|
4757
|
+
} else {
|
|
4758
|
+
setBudgetError(tt("stats.budgetFailed"));
|
|
4759
|
+
}
|
|
4760
|
+
} catch {
|
|
4761
|
+
setBudgetError(tt("stats.budgetFailed"));
|
|
4762
|
+
} finally {
|
|
4763
|
+
if (alive.current) setBudgetBusy(false);
|
|
4764
|
+
}
|
|
4765
|
+
}
|
|
4766
|
+
|
|
4767
|
+
/** 取消就地编辑:丢掉未保存的输入,恢复为当前预算金额。 */
|
|
4768
|
+
function cancelBudget() {
|
|
4769
|
+
setBudgetEditing(false);
|
|
4770
|
+
setBudgetError("");
|
|
4771
|
+
if (data && data.budget) setBudgetText(formatCents(data.budget.amountCents));
|
|
4772
|
+
}
|
|
4773
|
+
|
|
4774
|
+
const openBudgetEdit = () => {
|
|
4775
|
+
setBudgetError("");
|
|
4776
|
+
setBudgetEditing(true);
|
|
4777
|
+
};
|
|
4778
|
+
|
|
4779
|
+
const budgetProgress = budget && budget.enabled
|
|
4780
|
+
? e("div", { className: "dma-stats-progress", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.min(100, Math.round(ratio)) },
|
|
4781
|
+
e("i", { style: { width: statsPct(ratio) } }))
|
|
4782
|
+
: null;
|
|
4783
|
+
|
|
4784
|
+
// 第一行第三张:预算卡(金额 + 剩余/已用 + 进度条);「修改预算」小按钮与金额同一行,
|
|
4785
|
+
// 点金额仍可直接编辑(隐藏路径保留)。
|
|
4786
|
+
const budgetCardNode = e("div", { className: "dma-stats-card dma-stats-money-card" },
|
|
4787
|
+
e("span", { className: "dma-stats-card-label" }, tt("stats.moneyBudget")),
|
|
4788
|
+
budgetEditing
|
|
4789
|
+
? e("div", { className: "dma-stats-money-edit-row" },
|
|
4790
|
+
e("span", { className: "dma-stats-money-input" },
|
|
4791
|
+
"¥",
|
|
4792
|
+
e("input", {
|
|
4793
|
+
id: "dma-stats-budget-input",
|
|
4794
|
+
type: "text",
|
|
4795
|
+
inputMode: "decimal",
|
|
4796
|
+
value: budgetText,
|
|
4797
|
+
disabled: budgetBusy,
|
|
4798
|
+
autoFocus: true,
|
|
4799
|
+
"aria-label": tt("stats.budgetEdit"),
|
|
4800
|
+
onChange: (ev) => {
|
|
4801
|
+
setBudgetText(ev.target.value);
|
|
4802
|
+
if (budgetError) setBudgetError("");
|
|
4803
|
+
},
|
|
4804
|
+
onKeyDown: (ev) => {
|
|
4805
|
+
if (ev.key === "Enter") saveBudget();
|
|
4806
|
+
else if (ev.key === "Escape") {
|
|
4807
|
+
ev.stopPropagation();
|
|
4808
|
+
cancelBudget();
|
|
4809
|
+
}
|
|
4810
|
+
}
|
|
4811
|
+
}),
|
|
4812
|
+
tt("stats.budgetUnit")
|
|
4813
|
+
),
|
|
4814
|
+
e("button", {
|
|
4815
|
+
type: "button",
|
|
4816
|
+
className: "dma-stats-money-mini",
|
|
4817
|
+
disabled: budgetBusy,
|
|
4818
|
+
onClick: saveBudget
|
|
4819
|
+
}, budgetBusy ? tt("stats.budgetSaving") : tt("stats.budgetSave")),
|
|
4820
|
+
e("button", {
|
|
4821
|
+
type: "button",
|
|
4822
|
+
className: "dma-stats-money-cancel",
|
|
4823
|
+
disabled: budgetBusy,
|
|
4824
|
+
onClick: cancelBudget
|
|
4825
|
+
}, tt("stats.budgetCancel"))
|
|
4826
|
+
)
|
|
4827
|
+
: e("div", { className: "dma-stats-money-value-row" },
|
|
4828
|
+
e("button", {
|
|
4829
|
+
type: "button",
|
|
4830
|
+
className: "dma-stats-card-value dma-stats-money-edit",
|
|
4831
|
+
title: tt("stats.moneyEdit"),
|
|
4832
|
+
"aria-label": tt("stats.moneyEdit"),
|
|
4833
|
+
onClick: openBudgetEdit
|
|
4834
|
+
}, budget ? formatYuanCents(budget.amountCents) : "—"),
|
|
4835
|
+
e("button", {
|
|
4836
|
+
type: "button",
|
|
4837
|
+
className: "dma-stats-money-mini",
|
|
4838
|
+
title: tt("stats.moneyEdit"),
|
|
4839
|
+
"aria-label": tt("stats.moneyEdit"),
|
|
4840
|
+
onClick: openBudgetEdit
|
|
4841
|
+
}, tt("stats.moneyEdit"))
|
|
4842
|
+
),
|
|
4843
|
+
e("span", { className: "dma-stats-card-sub" },
|
|
4844
|
+
budget && budget.enabled
|
|
4845
|
+
? (over
|
|
4846
|
+
? tt("stats.overBudget")
|
|
4847
|
+
: tt("stats.budgetLeft") + " " + formatYuanCents(budget.remainingCents) + " · "
|
|
4848
|
+
+ tt("stats.budgetUsed") + " " + statsPct(ratio))
|
|
4849
|
+
: tt("stats.budgetOffSub")),
|
|
4850
|
+
budgetEditing
|
|
4851
|
+
? e("span", { className: "dma-stats-money-hint" }, budgetError || tt("stats.budgetHint"))
|
|
4852
|
+
: null,
|
|
4853
|
+
budgetProgress
|
|
4854
|
+
);
|
|
4855
|
+
|
|
4856
|
+
// 第一行第四张:预算使用(比例 + 剩余 / 额度 + 进度条)。
|
|
4857
|
+
const budgetUsageCardNode = e("div", { className: "dma-stats-card" },
|
|
4858
|
+
e("span", { className: "dma-stats-card-label" }, tt("stats.budget")),
|
|
4859
|
+
e("span", { className: "dma-stats-card-value", title: budget && budget.enabled ? statsRatioText(ratio) : tt("stats.budgetOff") },
|
|
4860
|
+
budget && budget.enabled ? statsRatioText(ratio) : tt("stats.budgetOff")),
|
|
4861
|
+
e("span", { className: "dma-stats-card-sub" },
|
|
4862
|
+
budget && budget.enabled
|
|
4863
|
+
? (over
|
|
4864
|
+
? tt("stats.overBudget") + " · " + formatYuanCents(budget.amountCents)
|
|
4865
|
+
: tt("stats.budgetLeft") + " " + formatYuanCents(budget.remainingCents) + tt("stats.of") + formatYuanCents(budget.amountCents))
|
|
4866
|
+
: tt("stats.budgetOffSub")),
|
|
4867
|
+
budgetProgress
|
|
4868
|
+
);
|
|
4869
|
+
|
|
4870
|
+
return e("div", {
|
|
4871
|
+
className: "dma-overlay",
|
|
4872
|
+
onClick: (ev) => {
|
|
4873
|
+
if (ev.target === ev.currentTarget) onClose();
|
|
4874
|
+
}
|
|
4875
|
+
},
|
|
4876
|
+
e("div", {
|
|
4877
|
+
className: "dma-panel dma-stats-panel",
|
|
4878
|
+
role: "dialog",
|
|
4879
|
+
"aria-modal": "true",
|
|
4880
|
+
"aria-label": tt("stats.panelTitle")
|
|
4881
|
+
},
|
|
4882
|
+
e("div", { className: "dma-panel-head dma-stats-head" },
|
|
4883
|
+
e("span", { className: "dma-stats-title" }, tt("stats.panelTitle")),
|
|
4884
|
+
e("span", { className: "dma-stats-live" },
|
|
4885
|
+
e("i", { className: "dma-stats-dot" }),
|
|
4886
|
+
state.status === "ready" ? tt("stats.live") : state.status === "stale" ? tt("stats.stale") : tt("stats.loading")),
|
|
4887
|
+
e("button", {
|
|
4888
|
+
type: "button",
|
|
4889
|
+
className: "dma-stats-icon",
|
|
4890
|
+
title: tt("stats.refresh"),
|
|
4891
|
+
"aria-label": tt("stats.refresh"),
|
|
4892
|
+
disabled: loading || budgetBusy,
|
|
4893
|
+
onClick: () => load()
|
|
4894
|
+
}, e("span", { className: "dma-stats-ico", dangerouslySetInnerHTML: { __html: REFRESH_ICON } })),
|
|
4895
|
+
e("button", {
|
|
4896
|
+
type: "button",
|
|
4897
|
+
autoFocus: true,
|
|
4898
|
+
className: "dma-stats-icon",
|
|
4899
|
+
title: tt("stats.close"),
|
|
4900
|
+
"aria-label": tt("stats.close"),
|
|
4901
|
+
onClick: onClose
|
|
4902
|
+
}, "×")
|
|
4903
|
+
),
|
|
4904
|
+
e("div", { className: "dma-panel-body dma-stats-body" },
|
|
4905
|
+
e("p", { className: "dma-stats-intro" }, tt("stats.intro")),
|
|
4906
|
+
state.status === "error"
|
|
4907
|
+
? e("p", { className: "dma-stats-error" }, tt("stats.error") + ":" + state.error)
|
|
4908
|
+
: null,
|
|
4909
|
+
state.status === "stale"
|
|
4910
|
+
? e("p", { className: "dma-stats-error" }, tt("stats.stale") + ":" + state.error)
|
|
4911
|
+
: null,
|
|
4912
|
+
!loading && data && data.available === false
|
|
4913
|
+
? e("p", { className: "dma-stats-error" }, tt("stats.unavailable"))
|
|
4914
|
+
: null,
|
|
4915
|
+
loading
|
|
4916
|
+
? e("p", { className: "dma-stats-empty" }, tt("stats.loading"))
|
|
4917
|
+
: e("div", { className: "dma-stats-kpis" },
|
|
4918
|
+
kpi.slice(0, 2).map(statsCard),
|
|
4919
|
+
// 第一行:总 Token → 会话数量 → 预算 → 预算使用。
|
|
4920
|
+
budgetCardNode,
|
|
4921
|
+
budgetUsageCardNode
|
|
4922
|
+
),
|
|
4923
|
+
!loading && data
|
|
4924
|
+
? e("div", { className: "dma-stats-kpis dma-stats-money" },
|
|
4925
|
+
// 第二行:余额 → 日用 → 单次 → 估算成本。
|
|
4926
|
+
ledger
|
|
4927
|
+
? e("div", { className: "dma-stats-card" },
|
|
4928
|
+
e("span", { className: "dma-stats-card-label" }, tt("cost.balance")),
|
|
4929
|
+
e("span", { className: "dma-stats-card-value" },
|
|
4930
|
+
Number.isFinite(ledger.balanceCents) ? formatYuanCents(ledger.balanceCents) : "—"),
|
|
4931
|
+
e("span", { className: "dma-stats-card-sub" },
|
|
4932
|
+
ledger.bonusCents > 0
|
|
4933
|
+
? tt("cost.bonusHint", { bonus: formatYuanCents(ledger.bonusCents) })
|
|
4934
|
+
: tt("stats.moneyBalanceSub"))
|
|
4935
|
+
)
|
|
4936
|
+
: null,
|
|
4937
|
+
ledger
|
|
4938
|
+
? e("div", { className: "dma-stats-card" },
|
|
4939
|
+
e("span", { className: "dma-stats-card-label" }, tt("cost.daily")),
|
|
4940
|
+
e("span", { className: "dma-stats-card-value" }, formatYuanCents(ledger.dailyCents || 0)),
|
|
4941
|
+
e("span", { className: "dma-stats-card-sub" }, tt("stats.moneyDailySub"))
|
|
4942
|
+
)
|
|
4943
|
+
: null,
|
|
4944
|
+
ledger
|
|
4945
|
+
? e("div", { className: "dma-stats-card" },
|
|
4946
|
+
e("span", { className: "dma-stats-card-label" }, tt("cost.perTurn")),
|
|
4947
|
+
e("span", { className: "dma-stats-card-value" },
|
|
4948
|
+
Number.isFinite(ledger.lastTurnMicros) ? formatCostMicros(ledger.lastTurnMicros) : "—"),
|
|
4949
|
+
e("span", { className: "dma-stats-card-sub" }, tt("stats.moneyTurnSub"))
|
|
4950
|
+
)
|
|
4951
|
+
: null,
|
|
4952
|
+
statsCard(kpi[2])
|
|
4953
|
+
)
|
|
4954
|
+
: null,
|
|
4955
|
+
!loading && data
|
|
4956
|
+
? e("p", { className: "dma-stats-note" }, tt("stats.budgetNote"))
|
|
4957
|
+
: null,
|
|
4958
|
+
!loading && data
|
|
4959
|
+
? e("p", { className: "dma-stats-note" }, tt("stats.billingNote"))
|
|
4960
|
+
: null,
|
|
4961
|
+
!loading && data
|
|
4962
|
+
? e(StatsTimeline, { t: tt, series: data.series, range, onRange: setRange })
|
|
4963
|
+
: null,
|
|
4964
|
+
!loading && data
|
|
4965
|
+
? e(StatsSessionRows, {
|
|
4966
|
+
t: tt,
|
|
4967
|
+
rows: data.sessions || [],
|
|
4968
|
+
truncated: data.truncated === true,
|
|
4969
|
+
total: data.sessionsTotal || 0
|
|
4970
|
+
})
|
|
4971
|
+
: null,
|
|
4972
|
+
!loading && data && data.ledger
|
|
4973
|
+
? e("p", { className: "dma-stats-note" }, tt("stats.ledger", {
|
|
4974
|
+
daily: formatYuanCents(data.ledger.dailyCents || 0),
|
|
4975
|
+
observed: formatYuanCents(data.ledger.observedSpendCents || 0)
|
|
4976
|
+
}))
|
|
4977
|
+
: null
|
|
4978
|
+
)
|
|
4979
|
+
)
|
|
4980
|
+
);
|
|
4981
|
+
}
|
|
4982
|
+
|
|
3408
4983
|
// 设置页(settings.section 槽位)
|
|
4984
|
+
// 「完成提示音」不再有独立开关行:音色选「关闭」即关闭(见 SoundToneRow)。
|
|
3409
4985
|
const SETTING_FIELDS = [
|
|
3410
4986
|
["recall", "settings.recall", "settings.recallDesc"],
|
|
3411
4987
|
["share", "settings.share", "settings.shareDesc"],
|
|
@@ -3499,6 +5075,112 @@ return module.exports;
|
|
|
3499
5075
|
);
|
|
3500
5076
|
}
|
|
3501
5077
|
|
|
5078
|
+
function SoundToneRow({ t: tt, value, onPick }) {
|
|
5079
|
+
const current = completionSoundTone(value || {});
|
|
5080
|
+
return e("div", { className: "dma-setting-row" },
|
|
5081
|
+
e("div", { className: "dma-setting-text" },
|
|
5082
|
+
e("div", { className: "dma-setting-label" }, tt("settings.soundTone")),
|
|
5083
|
+
e("div", { className: "dma-setting-desc" }, tt("settings.soundToneDesc"))
|
|
5084
|
+
),
|
|
5085
|
+
e("div", { className: "dma-seg", role: "group", "aria-label": tt("settings.soundTone") },
|
|
5086
|
+
soundToneOptions().map((id) => e("button", {
|
|
5087
|
+
key: id,
|
|
5088
|
+
type: "button",
|
|
5089
|
+
className: "dma-seg-btn",
|
|
5090
|
+
"aria-pressed": current === id ? "true" : "false",
|
|
5091
|
+
onClick: () => onPick(id)
|
|
5092
|
+
}, tt("settings.soundTone." + id)))
|
|
5093
|
+
)
|
|
5094
|
+
);
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5097
|
+
function VolumeRow({ t: tt, value, disabled, onCommit }) {
|
|
5098
|
+
const committed = clampSoundVolume(value);
|
|
5099
|
+
const [draft, setDraft] = React.useState(committed);
|
|
5100
|
+
const draftRef = React.useRef(committed);
|
|
5101
|
+
const committedRef = React.useRef(committed);
|
|
5102
|
+
const dragging = React.useRef(false);
|
|
5103
|
+
const timer = React.useRef(null);
|
|
5104
|
+
const inputRef = React.useRef(null);
|
|
5105
|
+
const commitRef = React.useRef(() => {});
|
|
5106
|
+
|
|
5107
|
+
// 外部配置变化时才回写本地值;拖动中或防抖未落盘时不覆盖,保证数字跟手。
|
|
5108
|
+
React.useEffect(() => {
|
|
5109
|
+
committedRef.current = committed;
|
|
5110
|
+
if (!dragging.current && !timer.current) {
|
|
5111
|
+
draftRef.current = committed;
|
|
5112
|
+
setDraft(committed);
|
|
5113
|
+
}
|
|
5114
|
+
}, [committed]);
|
|
5115
|
+
|
|
5116
|
+
React.useEffect(() => () => {
|
|
5117
|
+
if (timer.current) clearTimeout(timer.current);
|
|
5118
|
+
}, []);
|
|
5119
|
+
|
|
5120
|
+
// 拖动过程只更新本地显示,不写宿主配置、不重拉设置快照。
|
|
5121
|
+
const update = (raw) => {
|
|
5122
|
+
const next = clampSoundVolume(raw);
|
|
5123
|
+
draftRef.current = next;
|
|
5124
|
+
setDraft(next);
|
|
5125
|
+
};
|
|
5126
|
+
|
|
5127
|
+
// 松手 / 键盘抬起 / 失焦合并成一次提交:120ms 防抖后写入并试听一次。
|
|
5128
|
+
const commit = () => {
|
|
5129
|
+
dragging.current = false;
|
|
5130
|
+
if (timer.current) clearTimeout(timer.current);
|
|
5131
|
+
timer.current = setTimeout(() => {
|
|
5132
|
+
timer.current = null;
|
|
5133
|
+
const next = draftRef.current;
|
|
5134
|
+
if (next === committedRef.current) return;
|
|
5135
|
+
committedRef.current = next;
|
|
5136
|
+
onCommit(next);
|
|
5137
|
+
}, 120);
|
|
5138
|
+
};
|
|
5139
|
+
commitRef.current = commit;
|
|
5140
|
+
|
|
5141
|
+
// 原生 change 在拖动结束时才触发(React 的 onChange 实际是 input 事件),
|
|
5142
|
+
// 兜住指针在滑杆外松开、或浏览器不做隐式指针捕获的情况。
|
|
5143
|
+
React.useEffect(() => {
|
|
5144
|
+
const el = inputRef.current;
|
|
5145
|
+
if (!el || typeof el.addEventListener !== "function") return undefined;
|
|
5146
|
+
const onChangeEnd = () => commitRef.current();
|
|
5147
|
+
el.addEventListener("change", onChangeEnd);
|
|
5148
|
+
return () => el.removeEventListener("change", onChangeEnd);
|
|
5149
|
+
}, []);
|
|
5150
|
+
|
|
5151
|
+
return e("div", { className: "dma-setting-row" },
|
|
5152
|
+
e("div", { className: "dma-setting-text" },
|
|
5153
|
+
e("div", { className: "dma-setting-label" }, tt("settings.soundVolume")),
|
|
5154
|
+
e("div", { className: "dma-setting-desc" }, tt("settings.soundVolumeDesc"))
|
|
5155
|
+
),
|
|
5156
|
+
e("div", { className: "dma-volume" },
|
|
5157
|
+
e("input", {
|
|
5158
|
+
ref: inputRef,
|
|
5159
|
+
type: "range",
|
|
5160
|
+
className: "dma-volume-range",
|
|
5161
|
+
min: 0,
|
|
5162
|
+
max: 100,
|
|
5163
|
+
step: 5,
|
|
5164
|
+
value: draft,
|
|
5165
|
+
disabled: !!disabled,
|
|
5166
|
+
"aria-label": tt("settings.soundVolume"),
|
|
5167
|
+
onChange: (ev) => {
|
|
5168
|
+
dragging.current = true;
|
|
5169
|
+
update(ev.target.value);
|
|
5170
|
+
},
|
|
5171
|
+
onPointerDown: () => {
|
|
5172
|
+
dragging.current = true;
|
|
5173
|
+
},
|
|
5174
|
+
onPointerUp: commit,
|
|
5175
|
+
onPointerCancel: commit,
|
|
5176
|
+
onKeyUp: commit,
|
|
5177
|
+
onBlur: commit
|
|
5178
|
+
}),
|
|
5179
|
+
e("span", { className: "dma-volume-value" }, draft + "%")
|
|
5180
|
+
)
|
|
5181
|
+
);
|
|
5182
|
+
}
|
|
5183
|
+
|
|
3502
5184
|
function BillingTab({ t: tt, form, value, save }) {
|
|
3503
5185
|
const enabled = value ? value.usageStats !== false : true;
|
|
3504
5186
|
const onToggle = (key, on) => () => save(key, !on);
|
|
@@ -3540,127 +5222,18 @@ return module.exports;
|
|
|
3540
5222
|
disabled: !enabled,
|
|
3541
5223
|
onToggle: enabled ? onToggle("costPeakValley", value ? value.costPeakValley !== false : true) : null
|
|
3542
5224
|
}),
|
|
3543
|
-
e(
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
return Number.isFinite(cents) ? formatCents(cents) : "0.00";
|
|
3549
|
-
}
|
|
3550
|
-
|
|
3551
|
-
function CorrectionForm({ t: tt }) {
|
|
3552
|
-
const snap = React.useSyncExternalStore(
|
|
3553
|
-
costStore.subscribe,
|
|
3554
|
-
costStore.getSnapshot,
|
|
3555
|
-
costStore.getSnapshot
|
|
3556
|
-
);
|
|
3557
|
-
const value = snap && snap.status === "ready" ? snap.value : null;
|
|
3558
|
-
const [credit, setCredit] = React.useState("0.00");
|
|
3559
|
-
const [debit, setDebit] = React.useState("0.00");
|
|
3560
|
-
const [busy, setBusy] = React.useState(false);
|
|
3561
|
-
const [error, setError] = React.useState("");
|
|
3562
|
-
const initialized = React.useRef(false);
|
|
3563
|
-
|
|
3564
|
-
React.useEffect(() => {
|
|
3565
|
-
if (!value || initialized.current) return;
|
|
3566
|
-
initialized.current = true;
|
|
3567
|
-
setCredit(centsToInput(value.account.creditCents));
|
|
3568
|
-
setDebit(centsToInput(value.account.debitCents));
|
|
3569
|
-
}, [value]);
|
|
3570
|
-
|
|
3571
|
-
const creditCheck = validateCorrectionAmount(credit === "" ? 0 : credit);
|
|
3572
|
-
const debitCheck = validateCorrectionAmount(debit === "" ? 0 : debit);
|
|
3573
|
-
const invalid = !creditCheck.ok || !debitCheck.ok;
|
|
3574
|
-
|
|
3575
|
-
const account = value ? value.account : null;
|
|
3576
|
-
const baseline = account && Number.isFinite(account.baselineCents) ? account.baselineCents : null;
|
|
3577
|
-
const observed = account && Number.isFinite(account.observedSpendCents) ? account.observedSpendCents : 0;
|
|
3578
|
-
const previewCents = baseline === null
|
|
3579
|
-
? null
|
|
3580
|
-
: baseline - observed + (creditCheck.ok ? creditCheck.cents : 0) - (debitCheck.ok ? debitCheck.cents : 0);
|
|
3581
|
-
|
|
3582
|
-
async function submit() {
|
|
3583
|
-
if (invalid || busy) return;
|
|
3584
|
-
setBusy(true);
|
|
3585
|
-
setError("");
|
|
3586
|
-
let res;
|
|
3587
|
-
try {
|
|
3588
|
-
res = await postJson("/dsh-message-actions/cost/correction", {
|
|
3589
|
-
creditYuan: credit,
|
|
3590
|
-
debitYuan: debit
|
|
3591
|
-
});
|
|
3592
|
-
} catch {
|
|
3593
|
-
// 网络中断 / 宿主超时:给出可理解的反馈,不留未捕获 rejection。
|
|
3594
|
-
setError(tt("cost.correction.failed"));
|
|
3595
|
-
setBusy(false);
|
|
3596
|
-
return;
|
|
3597
|
-
}
|
|
3598
|
-
if (res.status === 200 && res.data && res.data.ok && res.data.value) {
|
|
3599
|
-
patchCostState({ status: "ready", value: res.data.value, fetchedAt: Date.now(), error: "" });
|
|
3600
|
-
setCredit(centsToInput(res.data.value.account.creditCents));
|
|
3601
|
-
setDebit(centsToInput(res.data.value.account.debitCents));
|
|
3602
|
-
} else {
|
|
3603
|
-
const code = res.data && res.data.error ? res.data.error.code : undefined;
|
|
3604
|
-
setError(tt(code === "INVALID_AMOUNT" ? "cost.correction.invalid" : "cost.correction.failed"));
|
|
3605
|
-
}
|
|
3606
|
-
setBusy(false);
|
|
3607
|
-
}
|
|
3608
|
-
|
|
3609
|
-
return e("div", { className: "dma-correction" },
|
|
3610
|
-
e("div", { className: "dma-correction-title" }, tt("cost.correction.title")),
|
|
3611
|
-
e("div", { className: "dma-correction-row" },
|
|
3612
|
-
e("label", { className: "dma-correction-label" }, tt("cost.correction.credit")),
|
|
3613
|
-
e("span", { className: "dma-correction-input" },
|
|
3614
|
-
e("span", { className: "dma-correction-yuan" }, tt("cost.correction.yuan")),
|
|
3615
|
-
e("input", {
|
|
3616
|
-
type: "text",
|
|
3617
|
-
inputMode: "decimal",
|
|
3618
|
-
value: credit,
|
|
3619
|
-
disabled: busy,
|
|
3620
|
-
"aria-invalid": invalid ? "true" : "false",
|
|
3621
|
-
onChange: (ev) => setCredit(ev.target.value)
|
|
3622
|
-
})
|
|
3623
|
-
)
|
|
3624
|
-
),
|
|
3625
|
-
e("div", { className: "dma-correction-row" },
|
|
3626
|
-
e("label", { className: "dma-correction-label" }, tt("cost.correction.debit")),
|
|
3627
|
-
e("span", { className: "dma-correction-input" },
|
|
3628
|
-
e("span", { className: "dma-correction-yuan" }, tt("cost.correction.yuan")),
|
|
3629
|
-
e("input", {
|
|
3630
|
-
type: "text",
|
|
3631
|
-
inputMode: "decimal",
|
|
3632
|
-
value: debit,
|
|
3633
|
-
disabled: busy,
|
|
3634
|
-
"aria-invalid": invalid ? "true" : "false",
|
|
3635
|
-
onChange: (ev) => setDebit(ev.target.value)
|
|
3636
|
-
})
|
|
3637
|
-
)
|
|
3638
|
-
),
|
|
3639
|
-
e("div", { className: "dma-correction-row dma-correction-preview" },
|
|
3640
|
-
e("label", { className: "dma-correction-label" }, tt("cost.correction.preview")),
|
|
3641
|
-
e("span", {
|
|
3642
|
-
className: "dma-correction-value" + (previewCents !== null && previewCents < 0 ? " dma-correction-negative" : "")
|
|
3643
|
-
}, previewCents === null ? "—" : formatYuanCents(previewCents))
|
|
3644
|
-
),
|
|
3645
|
-
e("div", { className: "dma-correction-row" },
|
|
3646
|
-
e("label", { className: "dma-correction-label" }, tt("cost.correction.pending")),
|
|
3647
|
-
e("span", { className: "dma-correction-value" },
|
|
3648
|
-
formatYuanCents(value && Number.isFinite(value.pendingAdjustmentCents) ? value.pendingAdjustmentCents : 0))
|
|
3649
|
-
),
|
|
3650
|
-
invalid ? e("div", { className: "dma-setting-error" }, tt("cost.correction.invalid")) : null,
|
|
3651
|
-
previewCents !== null && previewCents < 0
|
|
3652
|
-
? e("div", { className: "dma-correction-warn" }, tt("cost.correction.negative"))
|
|
3653
|
-
: null,
|
|
3654
|
-
error ? e("div", { className: "dma-setting-error" }, error) : null,
|
|
3655
|
-
e("p", { className: "dma-cost-note" }, tt("cost.note")),
|
|
3656
|
-
e("div", { className: "dma-correction-actions" },
|
|
5225
|
+
e("div", { className: "dma-setting-row" },
|
|
5226
|
+
e("div", { className: "dma-setting-text" },
|
|
5227
|
+
e("div", { className: "dma-setting-label" }, tt("cost.settings.statsTable")),
|
|
5228
|
+
e("div", { className: "dma-setting-desc" }, tt("cost.settings.statsTableDesc"))
|
|
5229
|
+
),
|
|
3657
5230
|
e("button", {
|
|
3658
5231
|
type: "button",
|
|
3659
|
-
className: "dma-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
)
|
|
5232
|
+
className: "dma-setting-primary dma-setting-btn",
|
|
5233
|
+
onClick: (ev) => openStatsPanel(ev.currentTarget)
|
|
5234
|
+
}, tt("cost.settings.statsTableButton"))
|
|
5235
|
+
),
|
|
5236
|
+
e("p", { className: "dma-cost-note" }, tt("cost.balanceNote"))
|
|
3664
5237
|
);
|
|
3665
5238
|
}
|
|
3666
5239
|
|
|
@@ -3721,8 +5294,8 @@ return module.exports;
|
|
|
3721
5294
|
),
|
|
3722
5295
|
tab === "actions"
|
|
3723
5296
|
? e("div", { className: "dma-settings-panel" },
|
|
3724
|
-
SETTING_FIELDS.map(([key, labelKey, descKey]) => {
|
|
3725
|
-
const on = value ? value[key] === true :
|
|
5297
|
+
SETTING_FIELDS.map(([key, labelKey, descKey, defaultOn]) => {
|
|
5298
|
+
const on = value ? (defaultOn ? value[key] !== false : value[key] === true) : defaultOn === true;
|
|
3726
5299
|
return e(SettingRow, {
|
|
3727
5300
|
key,
|
|
3728
5301
|
t: tt,
|
|
@@ -3732,6 +5305,28 @@ return module.exports;
|
|
|
3732
5305
|
onToggle: () => save(key, !on)
|
|
3733
5306
|
});
|
|
3734
5307
|
}),
|
|
5308
|
+
// 音色 + 音量:没有独立开关行,「关闭」音色即关闭完成提示音。
|
|
5309
|
+
e(SoundToneRow, {
|
|
5310
|
+
key: "soundTone",
|
|
5311
|
+
t: tt,
|
|
5312
|
+
value: value || {},
|
|
5313
|
+
onPick: (id) => {
|
|
5314
|
+
save("soundTone", id);
|
|
5315
|
+
if (id === "off") return; // 选「关闭」即关闭,不再试听
|
|
5316
|
+
// 旧配置可能还留着 sound=false:选任一音色时同步打开。
|
|
5317
|
+
if (value && value.sound === false) save("sound", true);
|
|
5318
|
+
playCompletionSound(id);
|
|
5319
|
+
}
|
|
5320
|
+
}),
|
|
5321
|
+
e(VolumeRow, {
|
|
5322
|
+
key: "soundVolume",
|
|
5323
|
+
t: tt,
|
|
5324
|
+
value: value ? value.soundVolume : DEFAULT_SOUND_VOLUME,
|
|
5325
|
+
onCommit: (volume) => {
|
|
5326
|
+
save("soundVolume", volume);
|
|
5327
|
+
playCompletionSound(undefined, volume);
|
|
5328
|
+
}
|
|
5329
|
+
}),
|
|
3735
5330
|
// 第一个标签页底部:只读版本号,不抢设置项视觉焦点。
|
|
3736
5331
|
e("div", { className: "dma-settings-version" }, "v" + VERSION)
|
|
3737
5332
|
)
|
|
@@ -3798,9 +5393,17 @@ return module.exports;
|
|
|
3798
5393
|
const status = value ? value.status : "stale";
|
|
3799
5394
|
const lastTurn = value && value.lastTurn ? value.lastTurn : null;
|
|
3800
5395
|
|
|
3801
|
-
|
|
3802
|
-
|
|
5396
|
+
// 余额口径:直接展示官方「充值余额」(不含赠金;赠金在提示里单列),
|
|
5397
|
+
// 全部按分计,不做元级四舍五入。缺充值字段时才退回总额。
|
|
5398
|
+
const rechargeCents = balance && Number.isFinite(balance.rechargeCents) ? balance.rechargeCents : null;
|
|
5399
|
+
const bonusCents = balance && Number.isFinite(balance.bonusCents) ? balance.bonusCents : null;
|
|
5400
|
+
const totalCents = balance && Number.isFinite(balance.totalCents) ? balance.totalCents : null;
|
|
5401
|
+
const balanceCents = balance && balance.updatedAt > 0
|
|
5402
|
+
? (rechargeCents !== null ? rechargeCents : totalCents)
|
|
3803
5403
|
: null;
|
|
5404
|
+
const bonusTitle = bonusCents !== null && bonusCents > 0
|
|
5405
|
+
? " · " + tt("cost.bonusHint", { bonus: formatYuanCents(bonusCents) })
|
|
5406
|
+
: "";
|
|
3804
5407
|
const dailyCents = balanceCents !== null && value && Number.isFinite(value.dailyCents)
|
|
3805
5408
|
? value.dailyCents
|
|
3806
5409
|
: null;
|
|
@@ -3847,7 +5450,7 @@ return module.exports;
|
|
|
3847
5450
|
|
|
3848
5451
|
if (!wide) {
|
|
3849
5452
|
const title = balanceCents !== null
|
|
3850
|
-
? tt("cost.railTitle", { balance: formatYuanCents(balanceCents) })
|
|
5453
|
+
? tt("cost.railTitle", { balance: formatYuanCents(balanceCents) }) + bonusTitle
|
|
3851
5454
|
: tt("cost.balance");
|
|
3852
5455
|
return e("div", { className: "dma-cost-item" },
|
|
3853
5456
|
e("button", {
|
|
@@ -3891,7 +5494,6 @@ return module.exports;
|
|
|
3891
5494
|
: formatCostMicros(Math.round(turnShown));
|
|
3892
5495
|
|
|
3893
5496
|
const stale = status === "stale" && balanceCents !== null;
|
|
3894
|
-
const pending = value && Number.isFinite(value.pendingAdjustmentCents) && value.pendingAdjustmentCents > 0;
|
|
3895
5497
|
const staleTitle = balance && balance.updatedAt > 0
|
|
3896
5498
|
? tt("cost.staleTitle", { time: new Date(balance.updatedAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
|
|
3897
5499
|
: "";
|
|
@@ -3908,30 +5510,38 @@ return module.exports;
|
|
|
3908
5510
|
if (compact) {
|
|
3909
5511
|
return e("div", { className: "dma-cost-item" },
|
|
3910
5512
|
e("div", { className: "dma-cost-card dma-cost-plain" },
|
|
3911
|
-
e("
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
e("span", { className: "dma-cost-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
e("span", { className: "dma-cost-
|
|
3926
|
-
|
|
5513
|
+
e("div", { className: "dma-cost-plain-wrap" },
|
|
5514
|
+
e("button", {
|
|
5515
|
+
type: "button",
|
|
5516
|
+
className: "dma-cost-plain-row",
|
|
5517
|
+
onClick: refresh,
|
|
5518
|
+
title: (stale ? staleTitle : tt("cost.refresh")) + bonusTitle,
|
|
5519
|
+
"aria-label": tt("cost.refresh"),
|
|
5520
|
+
"aria-busy": refreshing ? "true" : "false"
|
|
5521
|
+
},
|
|
5522
|
+
showPeak ? periodIcon : null,
|
|
5523
|
+
e("span", { className: "dma-cost-col" },
|
|
5524
|
+
e("span", { className: "dma-cost-label" }, tt("cost.balance")),
|
|
5525
|
+
e("span", { className: "dma-cost-value" }, balanceText)
|
|
5526
|
+
),
|
|
5527
|
+
e("span", { className: "dma-cost-col" },
|
|
5528
|
+
e("span", { className: "dma-cost-label" }, tt("cost.daily")),
|
|
5529
|
+
e("span", { className: "dma-cost-value" }, dailyText)
|
|
5530
|
+
),
|
|
5531
|
+
showTurn && !turnHidden
|
|
5532
|
+
? e("span", { className: "dma-cost-col" },
|
|
5533
|
+
e("span", { className: "dma-cost-label", title: tt("cost.settings.perTurnDesc") }, tt("cost.perTurn")),
|
|
5534
|
+
e("span", { className: "dma-cost-value" }, turnText)
|
|
5535
|
+
)
|
|
5536
|
+
: null
|
|
3927
5537
|
),
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
)
|
|
3933
|
-
:
|
|
3934
|
-
|
|
5538
|
+
e("button", {
|
|
5539
|
+
type: "button",
|
|
5540
|
+
className: "dma-stats-entry",
|
|
5541
|
+
title: tt("stats.entryTitle"),
|
|
5542
|
+
"aria-label": tt("stats.entryTitle"),
|
|
5543
|
+
onClick: (ev) => openStatsPanel(ev.currentTarget)
|
|
5544
|
+
}, e("span", { className: "dma-ico", dangerouslySetInnerHTML: { __html: STATS_ICON } }))
|
|
3935
5545
|
)
|
|
3936
5546
|
)
|
|
3937
5547
|
);
|
|
@@ -3944,13 +5554,12 @@ return module.exports;
|
|
|
3944
5554
|
type: "button",
|
|
3945
5555
|
className: "dma-cost-col dma-cost-balance" + (refreshing ? " dma-cost-busy" : ""),
|
|
3946
5556
|
onClick: refresh,
|
|
3947
|
-
title: stale ? staleTitle : tt("cost.refresh"),
|
|
5557
|
+
title: (stale ? staleTitle : tt("cost.refresh")) + bonusTitle,
|
|
3948
5558
|
"aria-label": tt("cost.refresh"),
|
|
3949
5559
|
"aria-busy": refreshing ? "true" : "false"
|
|
3950
5560
|
},
|
|
3951
5561
|
e("span", { className: "dma-cost-label" },
|
|
3952
5562
|
tt("cost.balance"),
|
|
3953
|
-
pending ? e("span", { className: "dma-cost-badge", title: tt("cost.pendingTitle") }, tt("cost.pending")) : null,
|
|
3954
5563
|
refreshing ? e("span", { className: "dma-cost-spinner" }) : null,
|
|
3955
5564
|
stale ? e("span", { className: "dma-cost-stale", title: staleTitle }) : null
|
|
3956
5565
|
),
|
|
@@ -3974,7 +5583,14 @@ return module.exports;
|
|
|
3974
5583
|
}, "×")
|
|
3975
5584
|
: null
|
|
3976
5585
|
)
|
|
3977
|
-
: null
|
|
5586
|
+
: null,
|
|
5587
|
+
e("button", {
|
|
5588
|
+
type: "button",
|
|
5589
|
+
className: "dma-stats-entry",
|
|
5590
|
+
title: tt("stats.entryTitle"),
|
|
5591
|
+
"aria-label": tt("stats.entryTitle"),
|
|
5592
|
+
onClick: (ev) => openStatsPanel(ev.currentTarget)
|
|
5593
|
+
}, e("span", { className: "dma-ico", dangerouslySetInnerHTML: { __html: STATS_ICON } }))
|
|
3978
5594
|
),
|
|
3979
5595
|
showPeak
|
|
3980
5596
|
? e("div", {
|
|
@@ -3996,17 +5612,17 @@ return module.exports;
|
|
|
3996
5612
|
const EXTRA_CSS = `
|
|
3997
5613
|
.dma-settings{max-width:680px;display:flex;flex-direction:column;gap:2px}
|
|
3998
5614
|
.dma-settings-panel{display:flex;flex-direction:column;gap:2px}
|
|
3999
|
-
.dma-settings-version{margin-top:
|
|
4000
|
-
.dma-setting-row{display:flex;align-items:flex-start;justify-content:space-between;gap:20px;padding:
|
|
5615
|
+
.dma-settings-version{margin-top:10px;padding-top:8px;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary,#8a919e);text-align:right;user-select:text}
|
|
5616
|
+
.dma-setting-row{display:flex;align-items:flex-start;justify-content:space-between;gap:20px;padding:10px 4px;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08))}
|
|
4001
5617
|
.dma-setting-text{min-width:0}
|
|
4002
5618
|
.dma-setting-label{font-size:14px;line-height:1.5;color:var(--dsw-alias-label-primary,#1f2329)}
|
|
4003
|
-
.dma-setting-desc{margin-top:
|
|
5619
|
+
.dma-setting-desc{margin-top:2px;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
4004
5620
|
.dma-switch{flex:none;position:relative;width:36px;height:20px;margin-top:2px;border:0;border-radius:999px;padding:0;background:var(--dsw-alias-border-l3,#c9ced6);cursor:pointer;transition:background 120ms ease}
|
|
4005
5621
|
.dma-switch[aria-checked="true"]{background:var(--dsw-alias-state-business-primary,#4c8dff)}
|
|
4006
5622
|
.dma-switch:disabled{opacity:.45;cursor:default}
|
|
4007
5623
|
.dma-switch-thumb{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-switch-thumb,#fff);box-shadow:0 1px 2px rgba(0,0,0,.18);transition:transform 120ms ease}
|
|
4008
5624
|
.dma-switch[aria-checked="true"] .dma-switch-thumb{transform:translateX(16px)}
|
|
4009
|
-
.dma-setting-error{margin-top:
|
|
5625
|
+
.dma-setting-error{margin-top:8px;font-size:12px;color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
4010
5626
|
.dma-ico{display:inline-flex}
|
|
4011
5627
|
.dma-empty{color:var(--dsw-alias-label-tertiary,#8a919e);font-size:13px;margin:12px 0}
|
|
4012
5628
|
.dma-tabs{display:inline-flex;gap:4px;align-self:flex-start;margin:2px 0 10px;padding:3px;border-radius:9px;background:var(--dsw-alias-bg-layer-2,#f2f3f5)}
|
|
@@ -4019,21 +5635,13 @@ return module.exports;
|
|
|
4019
5635
|
.dma-seg-btn{border:0;border-radius:6px;padding:4px 10px;background:transparent;color:var(--dsw-alias-label-secondary,#5b6472);font-size:12px;line-height:1.4;cursor:pointer}
|
|
4020
5636
|
.dma-seg-btn[aria-pressed="true"]{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#1f2329);font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.08)}
|
|
4021
5637
|
.dma-seg-btn:disabled{opacity:.45;cursor:default}
|
|
4022
|
-
.dma-
|
|
4023
|
-
.dma-
|
|
4024
|
-
.dma-
|
|
4025
|
-
.dma-
|
|
4026
|
-
.dma-correction-input{display:inline-flex;align-items:center;gap:4px;padding:4px 8px;border:.5px solid var(--dsw-alias-border-l3,#c9ced6);border-radius:7px;background:var(--dsw-alias-bg-layer-1,#fff)}
|
|
4027
|
-
.dma-correction-input input{width:110px;border:0;outline:0;background:transparent;color:var(--dsw-alias-label-primary,#1f2329);font:inherit;font-variant-numeric:tabular-nums;text-align:right}
|
|
4028
|
-
.dma-correction-input input[aria-invalid="true"]{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
4029
|
-
.dma-correction-yuan{color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
4030
|
-
.dma-correction-value{color:var(--dsw-alias-label-primary,#1f2329);font-variant-numeric:tabular-nums}
|
|
4031
|
-
.dma-correction-negative{color:var(--dsw-alias-state-error-primary,#e5484d);font-weight:600}
|
|
4032
|
-
.dma-correction-warn{margin-top:4px;font-size:12px;color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
5638
|
+
.dma-volume{flex:none;display:inline-flex;align-items:center;gap:8px;margin-top:2px}
|
|
5639
|
+
.dma-volume-range{width:132px;accent-color:var(--dsw-alias-state-business-primary,#4c8dff)}
|
|
5640
|
+
.dma-volume-range:disabled{opacity:.45}
|
|
5641
|
+
.dma-volume-value{min-width:38px;font-size:12px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary,#5b6472);text-align:right}
|
|
4033
5642
|
.dma-cost-note{margin:10px 0 0;font-size:11px;line-height:1.6;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
4034
|
-
.dma-
|
|
4035
|
-
.dma-
|
|
4036
|
-
.dma-correction-save:disabled{background:var(--dsw-alias-bg-layer-2,#f2f3f5);color:var(--dsw-alias-label-dimmed,#a0a6b0);cursor:default}
|
|
5643
|
+
.dma-setting-primary{height:32px;padding:0 16px;border:0;border-radius:8px;background:var(--dsw-alias-button-primary-fill,#4c8dff);color:#fff;font-size:13px;cursor:pointer}
|
|
5644
|
+
.dma-setting-primary:disabled{background:var(--dsw-alias-bg-layer-2,#f2f3f5);color:var(--dsw-alias-label-dimmed,#a0a6b0);cursor:default}
|
|
4037
5645
|
.dma-cost-item{flex:1 1 auto;min-width:0}
|
|
4038
5646
|
.dma-cost-card{display:flex;flex-direction:column;gap:3px;min-width:0;padding:5px 8px;border:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08));border-radius:8px;background:var(--dsw-alias-bg-layer-2,#f2f3f5);color:var(--dsw-alias-label-primary,#1f2329)}
|
|
4039
5647
|
.dma-cost-cols{display:flex;align-items:baseline;justify-content:space-between;gap:6px;min-width:0}
|
|
@@ -4043,7 +5651,6 @@ return module.exports;
|
|
|
4043
5651
|
.dma-cost-balance:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
4044
5652
|
.dma-cost-label{display:flex;align-items:center;gap:2px;overflow:hidden;font-size:11px;line-height:1.2;white-space:nowrap;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
4045
5653
|
.dma-cost-value{overflow:hidden;font-size:14px;font-weight:600;line-height:1.25;white-space:nowrap;text-overflow:ellipsis;font-variant-numeric:tabular-nums}
|
|
4046
|
-
.dma-cost-badge{flex:none;padding:0 4px;border-radius:7px;background:rgba(245,154,46,.16);color:#b56a00;font-size:10.5px;font-weight:500;line-height:15px}
|
|
4047
5654
|
.dma-cost-spinner{flex:none;width:9px;height:9px;border:1.5px solid rgba(0,0,0,.15);border-top-color:var(--dsw-alias-state-business-primary,#4c8dff);border-radius:50%;animation:dma-spin .8s linear infinite}
|
|
4048
5655
|
.dma-cost-stale{flex:none;width:4px;height:4px;border-radius:50%;background:var(--dsw-alias-label-dimmed,#a0a6b0)}
|
|
4049
5656
|
.dma-cost-hide{margin-left:1px;border:0;padding:0 1px;background:transparent;color:var(--dsw-alias-label-tertiary,#8a919e);font-size:11px;line-height:1;cursor:pointer}
|
|
@@ -4058,7 +5665,6 @@ return module.exports;
|
|
|
4058
5665
|
.dma-cost-plain-row:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
4059
5666
|
.dma-cost-plain .dma-cost-col{flex:0 1 auto;overflow:hidden}
|
|
4060
5667
|
.dma-cost-plain .dma-cost-value{font-size:13.5px}
|
|
4061
|
-
.dma-cost-plain .dma-cost-badge{margin-left:auto}
|
|
4062
5668
|
.dma-cost-local{flex-direction:row;align-items:center;justify-content:center;gap:5px;padding:6px 8px}
|
|
4063
5669
|
.dma-cost-local.dma-cost-plain{justify-content:flex-start;gap:6px;padding:2px 2px}
|
|
4064
5670
|
.dma-cost-local-text{overflow:hidden;font-size:12px;line-height:1.3;white-space:nowrap;text-overflow:ellipsis;color:var(--dsw-alias-label-secondary,#5b6472)}
|
|
@@ -4066,6 +5672,101 @@ return module.exports;
|
|
|
4066
5672
|
.dma-cost-rail:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.05))}
|
|
4067
5673
|
.dma-cost-rail:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
4068
5674
|
.dma-cost-rail svg{width:16px;height:16px}
|
|
5675
|
+
.dma-cost-plain-wrap{display:flex;align-items:center;gap:2px;width:100%;min-width:0}
|
|
5676
|
+
.dma-cost-plain-wrap .dma-cost-plain-row{flex:1 1 auto;min-width:0}
|
|
5677
|
+
.dma-cost-cols>.dma-stats-entry{align-self:center}
|
|
5678
|
+
.dma-stats-entry{flex:none;display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-tertiary,#8a919e);cursor:pointer;transition:background 120ms ease,color 120ms ease}
|
|
5679
|
+
.dma-stats-entry:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.05));color:var(--dsw-alias-label-primary,#1f2329)}
|
|
5680
|
+
.dma-stats-entry:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
5681
|
+
.dma-stats-entry svg{display:block;width:15px;height:15px}
|
|
5682
|
+
.dma-stats-panel{width:min(920px,calc(100vw - 48px));max-height:86vh}
|
|
5683
|
+
.dma-stats-head{display:flex;align-items:center;gap:6px}
|
|
5684
|
+
.dma-stats-title{margin-right:auto;font-size:16px;font-weight:600;color:var(--dsw-alias-label-primary,#1f2329)}
|
|
5685
|
+
.dma-stats-live{display:inline-flex;align-items:center;gap:5px;font-size:11px;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5686
|
+
.dma-stats-dot{display:inline-block;width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-state-success-primary,#22a06b)}
|
|
5687
|
+
.dma-stats-icon{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-secondary,#5b6472);font-size:16px;line-height:1;cursor:pointer}
|
|
5688
|
+
.dma-stats-icon:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.05))}
|
|
5689
|
+
.dma-stats-icon:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
5690
|
+
.dma-stats-icon:disabled{opacity:.45;cursor:default}
|
|
5691
|
+
.dma-stats-ico svg{display:block;width:16px;height:16px}
|
|
5692
|
+
.dma-stats-body{display:flex;flex-direction:column;gap:14px;padding:14px 18px}
|
|
5693
|
+
.dma-stats-intro{margin:0;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5694
|
+
.dma-stats-kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:10px}
|
|
5695
|
+
.dma-stats-card{display:flex;flex-direction:column;gap:4px;min-width:0;padding:10px 12px;border:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08));border-radius:9px;background:var(--dsw-alias-bg-layer-2,#f2f3f5)}
|
|
5696
|
+
.dma-stats-card-label{font-size:11px;line-height:1.4;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5697
|
+
.dma-stats-card-value{overflow:hidden;font-size:20px;font-weight:600;line-height:1.25;white-space:nowrap;text-overflow:ellipsis;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary,#1f2329)}
|
|
5698
|
+
.dma-stats-card-sub{overflow:hidden;font-size:11px;line-height:1.45;white-space:nowrap;text-overflow:ellipsis;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5699
|
+
.dma-stats-progress{height:5px;margin-top:2px;border-radius:3px;background:var(--dsw-alias-bg-layer-1,#fff);overflow:hidden}
|
|
5700
|
+
.dma-stats-progress i{display:block;height:100%;border-radius:3px;background:var(--dsw-alias-state-business-primary,#4c8dff);transition:width 240ms ease}
|
|
5701
|
+
.dma-stats-section{display:flex;flex-direction:column;gap:8px;min-width:0}
|
|
5702
|
+
.dma-stats-section-head{display:flex;align-items:center;justify-content:space-between;gap:10px}
|
|
5703
|
+
.dma-stats-section-title{margin:0;font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary,#1f2329)}
|
|
5704
|
+
.dma-stats-note{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5705
|
+
.dma-stats-range{display:inline-flex;gap:2px;padding:2px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,#f2f3f5)}
|
|
5706
|
+
.dma-stats-range button{border:0;border-radius:6px;padding:4px 10px;background:transparent;color:var(--dsw-alias-label-secondary,#5b6472);font-size:12px;line-height:1.4;cursor:pointer}
|
|
5707
|
+
.dma-stats-range button[aria-pressed="true"]{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#1f2329);font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.08)}
|
|
5708
|
+
.dma-stats-range button:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
5709
|
+
.dma-stats-chart-card{display:flex;flex-direction:column;gap:8px;padding:10px 12px;border:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08));border-radius:9px;background:var(--dsw-alias-bg-layer-2,#f2f3f5)}
|
|
5710
|
+
.dma-stats-chart-meta{display:flex;justify-content:space-between;gap:10px;font-size:11px;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5711
|
+
.dma-stats-chart{display:flex;align-items:flex-end;gap:2px;height:150px;min-width:0}
|
|
5712
|
+
.dma-stats-chart>div{flex:1 1 0;display:flex;align-items:flex-end;justify-content:center;min-width:0;height:100%}
|
|
5713
|
+
.dma-stats-col{position:relative;flex:1 1 0;display:flex;align-items:flex-end;justify-content:center;min-width:0;height:100%}
|
|
5714
|
+
.dma-stats-billing-bar{position:absolute;left:50%;bottom:0;transform:translateX(-50%);display:flex;width:100%;max-width:26px;height:3px;border-radius:2px;overflow:hidden;background:var(--dsw-alias-bg-layer-1,#fff)}
|
|
5715
|
+
.dma-stats-billing-bar i{display:block;height:100%}
|
|
5716
|
+
.dma-stats-billing-deepseek{background:#2f6bd8}
|
|
5717
|
+
.dma-stats-billing-local{background:#a8aeb8}
|
|
5718
|
+
.dma-stats-stack{display:flex;flex-direction:column-reverse;width:100%;max-width:26px;border-radius:3px 3px 0 0;overflow:hidden}
|
|
5719
|
+
.dma-stats-seg{display:block;width:100%}
|
|
5720
|
+
.dma-stats-seg-input{background:var(--dsw-alias-brand-primary,#4c8dff)}
|
|
5721
|
+
.dma-stats-seg-cacheRead{background:var(--dsw-alias-brand-primary,#4c8dff);opacity:.5}
|
|
5722
|
+
.dma-stats-seg-cacheWrite{background:var(--dsw-alias-brand-primary,#4c8dff);opacity:.26}
|
|
5723
|
+
.dma-stats-seg-output{background:var(--dsw-alias-state-success-primary,#22a06b)}
|
|
5724
|
+
.dma-stats-axis{display:grid;grid-template-columns:repeat(4,1fr);gap:2px;font-size:10px;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5725
|
+
.dma-stats-axis span{overflow:hidden;white-space:nowrap;text-align:center}
|
|
5726
|
+
.dma-stats-legend{display:flex;flex-wrap:wrap;gap:12px;font-size:11px;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5727
|
+
.dma-stats-legend span{display:inline-flex;align-items:center;gap:4px}
|
|
5728
|
+
.dma-stats-legend-row{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:6px 12px;min-width:0}
|
|
5729
|
+
.dma-stats-legend-billing{flex:none;margin-left:auto}
|
|
5730
|
+
.dma-stats-swatch{display:inline-block;width:9px;height:9px;border-radius:2px}
|
|
5731
|
+
.dma-stats-rows{display:flex;flex-direction:column;border:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08));border-radius:9px;overflow:hidden}
|
|
5732
|
+
.dma-stats-row{display:grid;grid-template-columns:minmax(0,1fr) 96px 84px 84px;gap:8px;align-items:center;padding:8px 12px;font-size:12px;border-top:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08))}
|
|
5733
|
+
.dma-stats-row:first-child{border-top:0}
|
|
5734
|
+
.dma-stats-row-head{font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary,#8a919e);background:var(--dsw-alias-bg-layer-2,#f2f3f5)}
|
|
5735
|
+
.dma-stats-cell{min-width:0;overflow:hidden}
|
|
5736
|
+
.dma-stats-cell-right{text-align:right;font-variant-numeric:tabular-nums}
|
|
5737
|
+
.dma-stats-row-title{display:flex;align-items:center;gap:5px;min-width:0}
|
|
5738
|
+
.dma-stats-row-title b{overflow:hidden;font-weight:600;white-space:nowrap;text-overflow:ellipsis;color:var(--dsw-alias-label-primary,#1f2329)}
|
|
5739
|
+
.dma-stats-pill{flex:none;padding:0 5px;border-radius:7px;background:rgba(76,141,255,.14);color:#2f6bd8;font-size:10px;font-weight:500;line-height:15px}
|
|
5740
|
+
.dma-stats-pill-running{background:rgba(34,160,107,.15);color:#137a4e}
|
|
5741
|
+
.dma-stats-pill-local{background:rgba(0,0,0,.06);color:#6b7280}
|
|
5742
|
+
.dma-stats-meta{overflow:hidden;font-size:10.5px;line-height:1.45;white-space:nowrap;text-overflow:ellipsis;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5743
|
+
.dma-stats-mini{display:flex;height:4px;margin-top:4px;border-radius:2px;overflow:hidden;background:var(--dsw-alias-bg-layer-1,#fff)}
|
|
5744
|
+
.dma-stats-mini i{display:block;height:100%}
|
|
5745
|
+
.dma-stats-mini .dma-stats-seg-cacheRead{opacity:.5}
|
|
5746
|
+
.dma-stats-mini .dma-stats-seg-output{background:var(--dsw-alias-state-success-primary,#22a06b)}
|
|
5747
|
+
.dma-stats-empty{margin:6px 0;font-size:12px;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5748
|
+
.dma-stats-money-edit{padding:0;border:0;background:transparent;font:inherit;font-size:20px;font-weight:600;line-height:1.25;text-align:left;color:inherit;border-radius:4px;cursor:pointer;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-variant-numeric:tabular-nums}
|
|
5749
|
+
.dma-stats-money-edit:hover{color:var(--dsw-alias-state-business-primary,#4c8dff)}
|
|
5750
|
+
.dma-stats-money-edit:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
5751
|
+
.dma-stats-money-edit-row{display:flex;flex-wrap:nowrap;align-items:center;gap:7px;min-width:0;min-height:24px}
|
|
5752
|
+
.dma-stats-money-edit-row>*{flex:none;min-width:0}
|
|
5753
|
+
.dma-stats-money-card{container-type:inline-size}
|
|
5754
|
+
.dma-stats-money-input{display:inline-flex;flex:0 1 92px;align-items:center;gap:3px;box-sizing:border-box;width:92px;min-width:64px;padding:2px 6px;border:.5px solid var(--dsw-alias-border-l3,#c9ced6);border-radius:6px;background:var(--dsw-alias-bg-layer-1,#fff);font-size:13px;color:var(--dsw-alias-label-tertiary,#8a919e);overflow:hidden}
|
|
5755
|
+
.dma-stats-money-input input{flex:1 1 auto;width:0;min-width:0;border:0;outline:0;background:transparent;color:var(--dsw-alias-label-primary,#1f2329);font:inherit;font-size:13px;font-variant-numeric:tabular-nums;text-align:right}
|
|
5756
|
+
.dma-stats-money-mini{flex:none;height:25px;padding:0 9px;border:0;border-radius:6px;background:var(--dsw-alias-button-primary-fill,#4c8dff);color:#fff;font-size:11.5px;font-weight:500;line-height:1;cursor:pointer;white-space:nowrap}
|
|
5757
|
+
.dma-stats-money-mini:hover{filter:brightness(.95)}
|
|
5758
|
+
.dma-stats-money-mini:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4c8dff);outline-offset:2px}
|
|
5759
|
+
.dma-stats-money-mini:disabled{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-dimmed,#a0a6b0);cursor:default;filter:none}
|
|
5760
|
+
.dma-stats-money-cancel{flex:none;height:25px;padding:0 7px;border:.5px solid var(--dsw-alias-border-l3,#c9ced6);border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary,#5b6472);font-size:11px;cursor:pointer;white-space:nowrap}
|
|
5761
|
+
.dma-stats-money-cancel:hover{color:var(--dsw-alias-label-primary,#1f2329);border-color:var(--dsw-alias-border-l2,rgba(0,0,0,.16))}
|
|
5762
|
+
.dma-stats-money-cancel:disabled{opacity:.45;cursor:default}
|
|
5763
|
+
@container (max-width:181px){.dma-stats-money-edit-row{gap:4px}.dma-stats-money-mini{padding:0 5px}.dma-stats-money-cancel{padding:0 4px}}
|
|
5764
|
+
.dma-stats-money-hint{overflow:hidden;font-size:10px;line-height:1.3;white-space:nowrap;text-overflow:ellipsis;color:var(--dsw-alias-label-tertiary,#8a919e)}
|
|
5765
|
+
.dma-stats-money-value-row{display:flex;align-items:center;gap:8px;min-width:0;min-height:24px}
|
|
5766
|
+
.dma-stats-money-value-row .dma-stats-money-edit{flex:1 1 auto;min-width:0}
|
|
5767
|
+
.dma-stats-money-value-row .dma-stats-money-mini{flex:none;white-space:nowrap}
|
|
5768
|
+
.dma-stats-error{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
5769
|
+
.dma-setting-btn{flex:none;margin-top:2px;align-self:flex-start}
|
|
4069
5770
|
@keyframes dma-spin{to{transform:rotate(360deg)}}
|
|
4070
5771
|
`;
|
|
4071
5772
|
|