@kangyishuai/dsh-advisor 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -37
- package/README.zh-CN.md +44 -36
- package/lib/budget.js +10 -4
- package/lib/catalog.js +35 -8
- package/lib/client.js +276 -28
- package/lib/guard.js +22 -8
- package/lib/ledger.js +19 -4
- package/lib/money.js +74 -0
- package/lib/service.js +127 -15
- package/lib/settings.js +45 -4
- package/locale/en.json +22 -4
- package/locale/zh.json +22 -4
- package/package.json +1 -1
package/lib/money.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 币种与金额换算。
|
|
3
|
+
//
|
|
4
|
+
// 账本、预算池、guard 的内部单位始终是 **USD**;`currency`/`usdToCny` 只决定
|
|
5
|
+
// 「设置里的金额按什么币种填写/展示」以及「显示时怎么把 USD 折算回去」。
|
|
6
|
+
// 汇率是手动配置的,插件不联网取价。
|
|
7
|
+
|
|
8
|
+
/** 支持设置的币种。 */
|
|
9
|
+
export const CURRENCIES = Object.freeze(/** @type {const} */ (["USD", "CNY"]));
|
|
10
|
+
|
|
11
|
+
/** 默认汇率:1 USD = 7.2 CNY(只是初始值,请按实际汇率修改)。 */
|
|
12
|
+
export const DEFAULT_USD_TO_CNY = 7.2;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 规整币种:未知值按 USD。
|
|
16
|
+
* @param {unknown} value
|
|
17
|
+
* @returns {"USD"|"CNY"}
|
|
18
|
+
*/
|
|
19
|
+
export function normalizeCurrency(value) {
|
|
20
|
+
return value === "CNY" ? "CNY" : "USD";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 规整汇率:非有限/非正数回落到默认,夹在 0.1–100。
|
|
25
|
+
* @param {unknown} value
|
|
26
|
+
* @returns {number}
|
|
27
|
+
*/
|
|
28
|
+
export function normalizeRate(value) {
|
|
29
|
+
const n = Number(value);
|
|
30
|
+
if (!Number.isFinite(n) || n <= 0) return DEFAULT_USD_TO_CNY;
|
|
31
|
+
return Math.min(100, Math.max(0.1, n));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 设置币种金额 → USD。`rate` 是 1 USD 等于多少 CNY。
|
|
36
|
+
* @param {unknown} amount
|
|
37
|
+
* @param {unknown} currency
|
|
38
|
+
* @param {unknown} rate
|
|
39
|
+
* @returns {number}
|
|
40
|
+
*/
|
|
41
|
+
export function toUsd(amount, currency, rate) {
|
|
42
|
+
const n = Number(amount);
|
|
43
|
+
if (!Number.isFinite(n)) return 0;
|
|
44
|
+
if (normalizeCurrency(currency) === "USD") return n;
|
|
45
|
+
return n / normalizeRate(rate);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* USD → 设置币种金额。
|
|
50
|
+
* @param {unknown} amountUsd
|
|
51
|
+
* @param {unknown} currency
|
|
52
|
+
* @param {unknown} rate
|
|
53
|
+
* @returns {number}
|
|
54
|
+
*/
|
|
55
|
+
export function fromUsd(amountUsd, currency, rate) {
|
|
56
|
+
const n = Number(amountUsd);
|
|
57
|
+
if (!Number.isFinite(n)) return 0;
|
|
58
|
+
if (normalizeCurrency(currency) === "USD") return n;
|
|
59
|
+
return n * normalizeRate(rate);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 金额显示:USD 用 $,CNY 用 ¥。
|
|
64
|
+
* @param {unknown} amount
|
|
65
|
+
* @param {unknown} currency
|
|
66
|
+
* @param {number} [digits]
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
export function formatMoney(amount, currency, digits = 4) {
|
|
70
|
+
const n = Number(amount);
|
|
71
|
+
const value = Number.isFinite(n) ? n : 0;
|
|
72
|
+
const places = Number.isFinite(digits) ? Math.max(0, Math.min(8, Math.round(digits))) : 4;
|
|
73
|
+
return `${normalizeCurrency(currency) === "CNY" ? "¥" : "$"}${value.toFixed(places)}`;
|
|
74
|
+
}
|
package/lib/service.js
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
rememberFingerprint,
|
|
30
30
|
} from "./guard.js";
|
|
31
31
|
import { createLedger } from "./ledger.js";
|
|
32
|
+
import { formatMoney, fromUsd } from "./money.js";
|
|
32
33
|
import { parseAdvice, summarizeAdvice, TOOL_DESCRIPTION } from "./prompt.js";
|
|
33
34
|
import { pairingCheck, resolveRoute } from "./route.js";
|
|
34
35
|
import {
|
|
@@ -430,7 +431,15 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
430
431
|
turn_limit: `本回合已达上限(${budget.used}/${budget.limit})`,
|
|
431
432
|
session_limit: `本会话已达上限(${budget.used}/${budget.limit})`,
|
|
432
433
|
hour_limit: `本小时已达上限(${budget.used}/${budget.limit})`,
|
|
433
|
-
day_budget:
|
|
434
|
+
day_budget: `今日预算已用完(${formatMoney(
|
|
435
|
+
fromUsd(budget.used, settings.currency, settings.usdToCny),
|
|
436
|
+
settings.currency,
|
|
437
|
+
4,
|
|
438
|
+
)}/${formatMoney(
|
|
439
|
+
fromUsd(budget.limit, settings.currency, settings.usdToCny),
|
|
440
|
+
settings.currency,
|
|
441
|
+
2,
|
|
442
|
+
)})`,
|
|
434
443
|
};
|
|
435
444
|
const reason = reasons[budget.code] ?? "预算不足";
|
|
436
445
|
if (sessionId !== "") this.lastSkip.set(sessionId, reason);
|
|
@@ -454,7 +463,15 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
454
463
|
const reason =
|
|
455
464
|
poolCheck.code === "workspace_calls"
|
|
456
465
|
? `工作区今日调用已达上限(${poolCheck.used}/${poolCheck.limit})`
|
|
457
|
-
:
|
|
466
|
+
: `工作区今日预算已用完(${formatMoney(
|
|
467
|
+
fromUsd(poolCheck.used, settings.currency, settings.usdToCny),
|
|
468
|
+
settings.currency,
|
|
469
|
+
4,
|
|
470
|
+
)}/${formatMoney(
|
|
471
|
+
fromUsd(poolCheck.limit, settings.currency, settings.usdToCny),
|
|
472
|
+
settings.currency,
|
|
473
|
+
2,
|
|
474
|
+
)})`;
|
|
458
475
|
if (sessionId !== "") this.lastSkip.set(sessionId, reason);
|
|
459
476
|
this.counters.skipped += 1;
|
|
460
477
|
return {
|
|
@@ -495,6 +512,8 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
495
512
|
outputTokens: settings.maxTokens / 2,
|
|
496
513
|
priceInputPerMTok: price.input,
|
|
497
514
|
priceOutputPerMTok: price.output,
|
|
515
|
+
priceCacheReadPerMTok: price.cacheRead,
|
|
516
|
+
priceCacheWritePerMTok: price.cacheWrite,
|
|
498
517
|
});
|
|
499
518
|
|
|
500
519
|
const started = Date.now();
|
|
@@ -517,18 +536,56 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
517
536
|
this.inflight.delete(sessionId);
|
|
518
537
|
}
|
|
519
538
|
|
|
520
|
-
|
|
521
|
-
|
|
539
|
+
/** @param {any} usage @returns {number} */
|
|
540
|
+
const costOf = (usage) =>
|
|
541
|
+
call.ok && usage !== undefined
|
|
522
542
|
? estimateCostUsd({
|
|
523
|
-
inputTokens:
|
|
524
|
-
outputTokens:
|
|
543
|
+
inputTokens: usage.inputTokens,
|
|
544
|
+
outputTokens: usage.outputTokens,
|
|
545
|
+
cacheReadTokens: usage.cacheReadTokens,
|
|
546
|
+
cacheWriteTokens: usage.cacheWriteTokens,
|
|
525
547
|
priceInputPerMTok: price.input,
|
|
526
548
|
priceOutputPerMTok: price.output,
|
|
549
|
+
priceCacheReadPerMTok: price.cacheRead,
|
|
550
|
+
priceCacheWritePerMTok: price.cacheWrite,
|
|
527
551
|
})
|
|
528
552
|
: 0;
|
|
529
553
|
|
|
530
|
-
|
|
531
|
-
|
|
554
|
+
/**
|
|
555
|
+
* @param {any} usage
|
|
556
|
+
* @param {number} cost
|
|
557
|
+
* @param {number} ms
|
|
558
|
+
* @returns {string}
|
|
559
|
+
*/
|
|
560
|
+
const usageLineOf = (usage, cost, ms) => {
|
|
561
|
+
const parts = [
|
|
562
|
+
`${formatTokens(usage?.inputTokens ?? 0)} in`,
|
|
563
|
+
`${formatTokens(usage?.outputTokens ?? 0)} out`,
|
|
564
|
+
];
|
|
565
|
+
if ((usage?.cacheReadTokens ?? 0) > 0) {
|
|
566
|
+
parts.push(`${formatTokens(usage.cacheReadTokens)} cache read`);
|
|
567
|
+
}
|
|
568
|
+
if ((usage?.cacheWriteTokens ?? 0) > 0) {
|
|
569
|
+
parts.push(`${formatTokens(usage.cacheWriteTokens)} cache write`);
|
|
570
|
+
}
|
|
571
|
+
parts.push(formatMs(ms));
|
|
572
|
+
if (cost > 0) {
|
|
573
|
+
parts.push(
|
|
574
|
+
`≈${formatMoney(fromUsd(cost, settings.currency, settings.usdToCny), settings.currency, 4)}`,
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
if (
|
|
578
|
+
((usage?.cacheReadTokens ?? 0) > 0 || (usage?.cacheWriteTokens ?? 0) > 0) &&
|
|
579
|
+
price.cacheSource === "none"
|
|
580
|
+
) {
|
|
581
|
+
parts.push("缓存未计价");
|
|
582
|
+
}
|
|
583
|
+
return parts.join(" / ");
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
let costUsd = costOf(call.usage);
|
|
587
|
+
let usageLine = call.ok
|
|
588
|
+
? usageLineOf(call.usage, costUsd, call.ms)
|
|
532
589
|
: `${formatMs(Date.now() - started)}`;
|
|
533
590
|
|
|
534
591
|
const baseResult = {
|
|
@@ -563,6 +620,7 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
563
620
|
inputTokens: 0,
|
|
564
621
|
outputTokens: 0,
|
|
565
622
|
cacheReadTokens: 0,
|
|
623
|
+
cacheWriteTokens: 0,
|
|
566
624
|
costUsd: 0,
|
|
567
625
|
ms: Date.now() - started,
|
|
568
626
|
code: baseResult.code,
|
|
@@ -571,12 +629,17 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
571
629
|
}
|
|
572
630
|
|
|
573
631
|
const parsed = parseAdvice(call.text ?? "");
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
632
|
+
let usage = call.usage;
|
|
633
|
+
|
|
634
|
+
// 记一次调用(调用数与最终成本):两阶段取证的额外 usage 合并后再记,避免只记第一轮。
|
|
635
|
+
const charge = () => {
|
|
636
|
+
this.ledger.noteCall(sessionId, { turn, costUsd, at: Date.now() });
|
|
637
|
+
void this.pool.add({ calls: 1, costUsd });
|
|
638
|
+
this.counters.calls += 1;
|
|
639
|
+
};
|
|
578
640
|
|
|
579
641
|
if (!parsed.ok) {
|
|
642
|
+
charge();
|
|
580
643
|
const result = { ...baseResult, status: "unavailable", code: `advice_${parsed.reason}` };
|
|
581
644
|
this.counters.failures += 1;
|
|
582
645
|
this.lastResult = result;
|
|
@@ -591,6 +654,7 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
591
654
|
inputTokens: usage?.inputTokens ?? 0,
|
|
592
655
|
outputTokens: usage?.outputTokens ?? 0,
|
|
593
656
|
cacheReadTokens: usage?.cacheReadTokens ?? 0,
|
|
657
|
+
cacheWriteTokens: usage?.cacheWriteTokens ?? 0,
|
|
594
658
|
costUsd,
|
|
595
659
|
ms: Date.now() - started,
|
|
596
660
|
code: result.code,
|
|
@@ -633,6 +697,13 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
633
697
|
}
|
|
634
698
|
}
|
|
635
699
|
|
|
700
|
+
// 两阶段可能追加了 usage:用合并后的 token 重算成本/展示,再记这一次调用。
|
|
701
|
+
usage = call.usage;
|
|
702
|
+
costUsd = costOf(usage);
|
|
703
|
+
usageLine = usageLineOf(usage, costUsd, call.ms);
|
|
704
|
+
baseResult.usage = usageLine;
|
|
705
|
+
charge();
|
|
706
|
+
|
|
636
707
|
const hollow = advice.verdict === "reviewed" && isHollowAdvice(advice.advice);
|
|
637
708
|
|
|
638
709
|
// 证据锚点校验:顾问说「刚才那次失败/这个文件」时,回头核对它引用的东西是否真的存在。
|
|
@@ -704,6 +775,7 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
704
775
|
inputTokens: usage?.inputTokens ?? 0,
|
|
705
776
|
outputTokens: usage?.outputTokens ?? 0,
|
|
706
777
|
cacheReadTokens: usage?.cacheReadTokens ?? 0,
|
|
778
|
+
cacheWriteTokens: usage?.cacheWriteTokens ?? 0,
|
|
707
779
|
costUsd,
|
|
708
780
|
ms: Date.now() - started,
|
|
709
781
|
code: "session_cap",
|
|
@@ -791,6 +863,7 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
791
863
|
inputTokens: usage?.inputTokens ?? 0,
|
|
792
864
|
outputTokens: usage?.outputTokens ?? 0,
|
|
793
865
|
cacheReadTokens: usage?.cacheReadTokens ?? 0,
|
|
866
|
+
cacheWriteTokens: usage?.cacheWriteTokens ?? 0,
|
|
794
867
|
costUsd,
|
|
795
868
|
ms: Date.now() - started,
|
|
796
869
|
});
|
|
@@ -1113,7 +1186,32 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
1113
1186
|
`脱敏命中:${transcript.stats.redactions.length === 0 ? "无" : transcript.stats.redactions.join(" / ")}`,
|
|
1114
1187
|
`白名单:${allow.reason}`,
|
|
1115
1188
|
`跨 provider:${crossProvider ? `是(需确认${confirmed ? ",已确认" : ",尚未确认 → /advisor confirm"})` : "否"}`,
|
|
1116
|
-
|
|
1189
|
+
`币种:${settings.currency}${settings.currency === "CNY" ? `(1 USD = ${settings.usdToCny} CNY)` : ""}`,
|
|
1190
|
+
`单价:${
|
|
1191
|
+
price.source === "none"
|
|
1192
|
+
? "输入/输出未配置(只记 token)"
|
|
1193
|
+
: `输入 ${formatMoney(
|
|
1194
|
+
fromUsd(price.input, settings.currency, settings.usdToCny),
|
|
1195
|
+
settings.currency,
|
|
1196
|
+
2,
|
|
1197
|
+
)}/M · 输出 ${formatMoney(
|
|
1198
|
+
fromUsd(price.output, settings.currency, settings.usdToCny),
|
|
1199
|
+
settings.currency,
|
|
1200
|
+
2,
|
|
1201
|
+
)}/M(${price.source === "builtin" ? "内置参考价(USD 折算)" : "用户设置"})`
|
|
1202
|
+
};${
|
|
1203
|
+
price.cacheSource === "none"
|
|
1204
|
+
? "缓存读取/写入未配置(缓存 token 不计)"
|
|
1205
|
+
: `缓存读取 ${formatMoney(
|
|
1206
|
+
fromUsd(price.cacheRead, settings.currency, settings.usdToCny),
|
|
1207
|
+
settings.currency,
|
|
1208
|
+
2,
|
|
1209
|
+
)}/M · 缓存写入 ${formatMoney(
|
|
1210
|
+
fromUsd(price.cacheWrite, settings.currency, settings.usdToCny),
|
|
1211
|
+
settings.currency,
|
|
1212
|
+
2,
|
|
1213
|
+
)}/M`
|
|
1214
|
+
}`,
|
|
1117
1215
|
`工作区今日:${pool.calls} 次(上限 ${settings.workspaceMaxCallsPerDay || "∞"})`,
|
|
1118
1216
|
``,
|
|
1119
1217
|
`—— 正文前 400 字符 ——`,
|
|
@@ -1362,7 +1460,9 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
1362
1460
|
maxCallsPerTurn: settings.maxCallsPerTurn,
|
|
1363
1461
|
maxCallsPerSession: settings.maxCallsPerSession,
|
|
1364
1462
|
maxCallsPerHour: settings.maxCallsPerHour,
|
|
1365
|
-
|
|
1463
|
+
maxCostPerDay: settings.maxCostPerDay,
|
|
1464
|
+
currency: settings.currency,
|
|
1465
|
+
usdToCny: settings.usdToCny,
|
|
1366
1466
|
},
|
|
1367
1467
|
totals,
|
|
1368
1468
|
last: this.lastResult,
|
|
@@ -1695,7 +1795,19 @@ export class AdvisorService extends TypertRemoteService {
|
|
|
1695
1795
|
: {
|
|
1696
1796
|
id: "budget",
|
|
1697
1797
|
status: "warn",
|
|
1698
|
-
message: `预算受限:${budget.code}(${
|
|
1798
|
+
message: `预算受限:${budget.code}(${
|
|
1799
|
+
budget.code === "day_budget"
|
|
1800
|
+
? `${formatMoney(
|
|
1801
|
+
fromUsd(budget.used, settings.currency, settings.usdToCny),
|
|
1802
|
+
settings.currency,
|
|
1803
|
+
4,
|
|
1804
|
+
)}/${formatMoney(
|
|
1805
|
+
fromUsd(budget.limit, settings.currency, settings.usdToCny),
|
|
1806
|
+
settings.currency,
|
|
1807
|
+
2,
|
|
1808
|
+
)}`
|
|
1809
|
+
: `${budget.used}/${budget.limit}`
|
|
1810
|
+
})`,
|
|
1699
1811
|
},
|
|
1700
1812
|
);
|
|
1701
1813
|
}
|
package/lib/settings.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
|
|
8
|
+
import { fromUsd, normalizeCurrency } from "./money.js";
|
|
9
|
+
|
|
8
10
|
/** 设置文件名(位于数据根下)。 */
|
|
9
11
|
export const SETTINGS_FILE = "advisor.settings.json";
|
|
10
12
|
|
|
@@ -29,9 +31,13 @@ export const DEFAULT_SETTINGS = Object.freeze({
|
|
|
29
31
|
maxCallsPerTurn: 1,
|
|
30
32
|
maxCallsPerSession: 32,
|
|
31
33
|
maxCallsPerHour: 12,
|
|
32
|
-
|
|
34
|
+
currency: "USD",
|
|
35
|
+
usdToCny: 7.2,
|
|
36
|
+
maxCostPerDay: 0,
|
|
33
37
|
priceInputPerMTok: 0,
|
|
34
38
|
priceOutputPerMTok: 0,
|
|
39
|
+
priceCacheReadPerMTok: 0,
|
|
40
|
+
priceCacheWritePerMTok: 0,
|
|
35
41
|
privacyScope: "summary",
|
|
36
42
|
redact: true,
|
|
37
43
|
immuneTurns: 3,
|
|
@@ -42,7 +48,7 @@ export const DEFAULT_SETTINGS = Object.freeze({
|
|
|
42
48
|
confirmedHosts: Object.freeze([]),
|
|
43
49
|
pairingEnforcement: "warn",
|
|
44
50
|
workspaceMaxCallsPerDay: 200,
|
|
45
|
-
|
|
51
|
+
workspaceMaxCostPerDay: 0,
|
|
46
52
|
postAnswer: "off",
|
|
47
53
|
advisorTools: false,
|
|
48
54
|
tracePrompt: "preview",
|
|
@@ -68,12 +74,17 @@ const INT_LIMITS = Object.freeze({
|
|
|
68
74
|
* 金额不能走整数夹紧——0.5 会被取整成 1,0.15 会变成 0。
|
|
69
75
|
*/
|
|
70
76
|
const MONEY_LIMITS = Object.freeze({
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
maxCostPerDay: { min: 0, max: 10000, digits: 2 },
|
|
78
|
+
workspaceMaxCostPerDay: { min: 0, max: 10000, digits: 2 },
|
|
73
79
|
priceInputPerMTok: { min: 0, max: 1000, digits: 4 },
|
|
74
80
|
priceOutputPerMTok: { min: 0, max: 1000, digits: 4 },
|
|
81
|
+
priceCacheReadPerMTok: { min: 0, max: 1000, digits: 4 },
|
|
82
|
+
priceCacheWritePerMTok: { min: 0, max: 1000, digits: 4 },
|
|
75
83
|
});
|
|
76
84
|
|
|
85
|
+
/** 汇率区间:1 USD = 0.1–100 CNY,保留 4 位小数。 */
|
|
86
|
+
const RATE_LIMIT = Object.freeze({ min: 0.1, max: 100, digits: 4 });
|
|
87
|
+
|
|
77
88
|
/** 字符串字段的最大长度,防止有人在设置里塞进一整段提示词。 */
|
|
78
89
|
const MAX_STRING = 300;
|
|
79
90
|
|
|
@@ -180,6 +191,19 @@ export function normalizeSettings(raw) {
|
|
|
180
191
|
/** @type {any} */
|
|
181
192
|
const out = { ...DEFAULT_SETTINGS };
|
|
182
193
|
|
|
194
|
+
out.currency = normalizeCurrency(input.currency);
|
|
195
|
+
const rawRate = Number(input.usdToCny);
|
|
196
|
+
out.usdToCny =
|
|
197
|
+
Number.isFinite(rawRate) && rawRate > 0
|
|
198
|
+
? clampMoney(
|
|
199
|
+
rawRate,
|
|
200
|
+
DEFAULT_SETTINGS.usdToCny,
|
|
201
|
+
RATE_LIMIT.min,
|
|
202
|
+
RATE_LIMIT.max,
|
|
203
|
+
RATE_LIMIT.digits,
|
|
204
|
+
)
|
|
205
|
+
: DEFAULT_SETTINGS.usdToCny;
|
|
206
|
+
|
|
183
207
|
if (typeof input.mode === "string" && MODES.includes(input.mode)) out.mode = input.mode;
|
|
184
208
|
|
|
185
209
|
for (const key of ["provider", "model", "reasoningEffort"]) {
|
|
@@ -207,9 +231,26 @@ export function normalizeSettings(raw) {
|
|
|
207
231
|
out[key] = clampInt(input[key], DEFAULT_SETTINGS[key], min, max);
|
|
208
232
|
}
|
|
209
233
|
for (const key of /** @type {(keyof typeof MONEY_LIMITS)[]} */ (Object.keys(MONEY_LIMITS))) {
|
|
234
|
+
if (key === "maxCostPerDay" || key === "workspaceMaxCostPerDay") continue;
|
|
210
235
|
const spec = MONEY_LIMITS[key];
|
|
211
236
|
out[key] = clampMoney(input[key], DEFAULT_SETTINGS[key], spec.min, spec.max, spec.digits);
|
|
212
237
|
}
|
|
238
|
+
// 旧版 *Usd 键按 USD 迁移到当前币种;新键存在时优先。
|
|
239
|
+
/** @type {Array<[keyof typeof MONEY_LIMITS, string]>} */
|
|
240
|
+
const MIGRATE_MONEY = [
|
|
241
|
+
["maxCostPerDay", "maxCostPerDayUsd"],
|
|
242
|
+
["workspaceMaxCostPerDay", "workspaceMaxCostPerDayUsd"],
|
|
243
|
+
];
|
|
244
|
+
for (const [key, oldKey] of MIGRATE_MONEY) {
|
|
245
|
+
const spec = MONEY_LIMITS[key];
|
|
246
|
+
const raw =
|
|
247
|
+
input[key] !== undefined
|
|
248
|
+
? input[key]
|
|
249
|
+
: input[oldKey] === undefined
|
|
250
|
+
? undefined
|
|
251
|
+
: fromUsd(Number(input[oldKey]) || 0, out.currency, out.usdToCny);
|
|
252
|
+
out[key] = clampMoney(raw, DEFAULT_SETTINGS[key], spec.min, spec.max, spec.digits);
|
|
253
|
+
}
|
|
213
254
|
out.temperature = nullableNumber(input.temperature, 0, 2);
|
|
214
255
|
out.tiers = normalizeTiers(input.tiers);
|
|
215
256
|
out.allowedModels = normalizeStringList(input.allowedModels);
|
package/locale/en.json
CHANGED
|
@@ -73,9 +73,7 @@
|
|
|
73
73
|
"settings.budget.maxCallsPerTurn": "Calls per turn",
|
|
74
74
|
"settings.budget.maxCallsPerSession": "Calls per session",
|
|
75
75
|
"settings.budget.maxCallsPerHour": "Calls per hour",
|
|
76
|
-
"settings.budget.maxCostPerDayUsd": "Daily budget",
|
|
77
76
|
"settings.budget.workspaceMaxCallsPerDay": "Workspace calls per day",
|
|
78
|
-
"settings.budget.workspaceMaxCostPerDayUsd": "Workspace daily budget",
|
|
79
77
|
"settings.budget.priceInputPerMTok": "Input price",
|
|
80
78
|
"settings.budget.priceOutputPerMTok": "Output price",
|
|
81
79
|
"settings.budget.range": "default {default} · range {min}–{max}",
|
|
@@ -177,7 +175,7 @@
|
|
|
177
175
|
"settings.group.delivery": "Delivery & behavior",
|
|
178
176
|
"settings.group.more": "More",
|
|
179
177
|
"settings.group.status": "Status & diagnostics",
|
|
180
|
-
"settings.basic.budgetHint": "0 = unlimited; default 0, range 0–10000.
|
|
178
|
+
"settings.basic.budgetHint": "0 = unlimited; default 0, range 0–10000 in the selected currency. Switching currency converts at the rate; finer limits are under Advanced.",
|
|
181
179
|
"settings.budget.maxCostHint": "Maximum spend per day; 0 = unlimited. Only counted when prices are set.",
|
|
182
180
|
"settings.advanced.maxTokensHint": "Maximum output tokens per answer; higher costs more.",
|
|
183
181
|
"settings.advanced.maxInputCharsHint": "Maximum characters of conversation sent per call; excess in the middle is elided, head and tail kept.",
|
|
@@ -215,6 +213,26 @@
|
|
|
215
213
|
"tail.trace.previewHide": "Hide sent content",
|
|
216
214
|
"tail.trace.previewTruncated": "Sent (redacted; first/last 2,000 of {chars} chars)",
|
|
217
215
|
"tail.trace.previewFull": "Sent (redacted; {chars} chars)",
|
|
218
|
-
"tail.trace.previewNone": "No sent content saved for this record (older record, or disabled in Advanced)."
|
|
216
|
+
"tail.trace.previewNone": "No sent content saved for this record (older record, or disabled in Advanced).",
|
|
217
|
+
"settings.currency": "Currency",
|
|
218
|
+
"settings.currency.USD": "US dollars (USD)",
|
|
219
|
+
"settings.currency.CNY": "Chinese yuan (CNY)",
|
|
220
|
+
"settings.currencyHint": "Amounts and prices are entered in this currency; switching converts them at the configured rate so the real value stays the same.",
|
|
221
|
+
"settings.currency.converted": "Converted amounts at 1 USD = {rate} CNY (not saved yet).",
|
|
222
|
+
"settings.usdToCny": "CNY per USD",
|
|
223
|
+
"settings.usdToCnyHint": "1 USD = ? CNY; only used when the currency is CNY. The plugin never fetches rates; maintain it manually.",
|
|
224
|
+
"settings.unit.cny": "CNY",
|
|
225
|
+
"settings.unit.cnyPerMTok": "CNY / 1M tokens",
|
|
226
|
+
"settings.budget.maxCostPerDay": "Daily budget",
|
|
227
|
+
"settings.budget.workspaceMaxCostPerDay": "Workspace daily budget",
|
|
228
|
+
"settings.unit.cnyPerUsd": "CNY / USD",
|
|
229
|
+
"settings.budget.priceCacheReadPerMTok": "Cache-read price",
|
|
230
|
+
"settings.budget.priceCacheWritePerMTok": "Cache-write price",
|
|
231
|
+
"settings.budget.cachePriceHint": "Input-token price for cache reads/writes (selected currency per 1M tokens); 0 = cache tokens are not priced. The host exposes cache-read/write tokens only; there is no cache-output token.",
|
|
232
|
+
"settings.budget.cachePriceSource": "Cache prices",
|
|
233
|
+
"settings.budget.cachePriceSource.settings": "user settings",
|
|
234
|
+
"settings.budget.cachePriceSource.none": "unset (cache tokens not priced)",
|
|
235
|
+
"settings.status.cache": "Cache tokens: {read} read / {write} write",
|
|
236
|
+
"settings.status.cacheUnpriced": "The ledger has cache tokens, but cache prices are 0: that part is not priced."
|
|
219
237
|
}
|
|
220
238
|
}
|
package/locale/zh.json
CHANGED
|
@@ -73,9 +73,7 @@
|
|
|
73
73
|
"settings.budget.maxCallsPerTurn": "每回合调用上限",
|
|
74
74
|
"settings.budget.maxCallsPerSession": "每会话调用上限",
|
|
75
75
|
"settings.budget.maxCallsPerHour": "每小时调用上限",
|
|
76
|
-
"settings.budget.maxCostPerDayUsd": "每日预算",
|
|
77
76
|
"settings.budget.workspaceMaxCallsPerDay": "工作区每日调用上限",
|
|
78
|
-
"settings.budget.workspaceMaxCostPerDayUsd": "工作区每日预算",
|
|
79
77
|
"settings.budget.priceInputPerMTok": "输入单价",
|
|
80
78
|
"settings.budget.priceOutputPerMTok": "输出单价",
|
|
81
79
|
"settings.budget.range": "默认 {default} · 范围 {min}–{max}",
|
|
@@ -177,7 +175,7 @@
|
|
|
177
175
|
"settings.group.delivery": "投递与行为",
|
|
178
176
|
"settings.group.more": "更多",
|
|
179
177
|
"settings.group.status": "状态与诊断",
|
|
180
|
-
"settings.basic.budgetHint": "0 = 不限;默认 0,范围 0–10000
|
|
178
|
+
"settings.basic.budgetHint": "0 = 不限;默认 0,范围 0–10000(按当前币种)。切换币种会按汇率折算;更细的限额在高级设置里。",
|
|
181
179
|
"settings.budget.maxCostHint": "每天最多花多少钱;0 = 不限。只有填了单价才会计算金额。",
|
|
182
180
|
"settings.advanced.maxTokensHint": "单次回答最多生成多少 token;越大越贵。",
|
|
183
181
|
"settings.advanced.maxInputCharsHint": "一次最多发送多少字符的会话内容;超出会保留首尾、省略中间。",
|
|
@@ -215,6 +213,26 @@
|
|
|
215
213
|
"tail.trace.previewHide": "收起发送内容",
|
|
216
214
|
"tail.trace.previewTruncated": "实际发送(脱敏后,首尾各 2,000 字符;共 {chars} 字符)",
|
|
217
215
|
"tail.trace.previewFull": "实际发送(脱敏后,共 {chars} 字符)",
|
|
218
|
-
"tail.trace.previewNone": "这条记录没有保存发送内容(可能是旧记录,或已在高级设置里关闭记录)。"
|
|
216
|
+
"tail.trace.previewNone": "这条记录没有保存发送内容(可能是旧记录,或已在高级设置里关闭记录)。",
|
|
217
|
+
"settings.currency": "币种",
|
|
218
|
+
"settings.currency.USD": "美元(USD)",
|
|
219
|
+
"settings.currency.CNY": "人民币(CNY)",
|
|
220
|
+
"settings.currencyHint": "金额和单价按此币种填写;切换时会按汇率折算金额,保持真实价值不变。",
|
|
221
|
+
"settings.currency.converted": "已按 1 USD = {rate} CNY 折算金额(尚未保存)。",
|
|
222
|
+
"settings.usdToCny": "人民币汇率",
|
|
223
|
+
"settings.usdToCnyHint": "1 USD = ? CNY;只在币种为人民币时用于换算。插件不联网取汇率,请手动维护。",
|
|
224
|
+
"settings.unit.cny": "元",
|
|
225
|
+
"settings.unit.cnyPerMTok": "元 / 百万 token",
|
|
226
|
+
"settings.budget.maxCostPerDay": "每日预算",
|
|
227
|
+
"settings.budget.workspaceMaxCostPerDay": "工作区每日预算",
|
|
228
|
+
"settings.unit.cnyPerUsd": "元 / USD",
|
|
229
|
+
"settings.budget.priceCacheReadPerMTok": "缓存读取单价",
|
|
230
|
+
"settings.budget.priceCacheWritePerMTok": "缓存写入单价",
|
|
231
|
+
"settings.budget.cachePriceHint": "缓存读取/写入的输入 token 单价(按当前币种 / 百万 token);0 = 不计缓存部分。宿主只提供缓存读/写 token,没有缓存输出 token。",
|
|
232
|
+
"settings.budget.cachePriceSource": "缓存单价",
|
|
233
|
+
"settings.budget.cachePriceSource.settings": "用户设置",
|
|
234
|
+
"settings.budget.cachePriceSource.none": "未配置(缓存 token 不计)",
|
|
235
|
+
"settings.status.cache": "缓存 token:{read} read / {write} write",
|
|
236
|
+
"settings.status.cacheUnpriced": "账本里有缓存 token,但缓存单价为 0:缓存部分没有计价。"
|
|
219
237
|
}
|
|
220
238
|
}
|
package/package.json
CHANGED