@kangyishuai/dsh-advisor 0.3.0 → 0.4.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 CHANGED
@@ -55,46 +55,50 @@ Settings live in one JSON file, `<DSH_HOME>/advisor.settings.json` (`DSH_HOME` d
55
55
 
56
56
  **Settings UI.** Settings → General → Advisor. With the default `off`, the card shows only the mode, a one-line status and “Configure advisor”. Expanding or enabling it reveals:
57
57
 
58
- - **Basics**: mode, provider, model, reasoning effort, daily budget, send scope, redaction.
59
- - **Advanced** (folded by default): call limits, workspace limits, prices, output/input caps, advice-item cap, allowlist, auto-review, file reading, shadow dedupe, sent-content recording. The heading shows “Defaults” or “N changed”.
58
+ - **Basics**: mode, currency, provider, model, reasoning effort, daily budget, send scope, redaction.
59
+ - **Advanced** (folded by default): call limits, workspace limits, CNY-per-USD rate, prices, output/input caps, advice-item cap, allowlist, auto-review, file reading, shadow dedupe, sent-content recording. The heading shows “Defaults” or “N changed”.
60
60
  - **Status & diagnostics** (folded by default): calls/tokens/cost, last result/skip reason, send preview, diagnostics, settings and ledger paths.
61
61
 
62
62
  The “?” next to an advanced field expands an inline help block (click or activate with the keyboard) with the description, default/range and technical key; hover is only a supplement. Click **Save** to apply changes to the next consultation.
63
63
 
64
64
  Money fields accept decimals: budgets up to 2, unit prices up to 4.
65
65
 
66
- | Key | UI label | Default | Range / values | Meaning |
67
- | --------------------------- | ------------------------------ | ----------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
68
- | `mode` | Mode | `"off"` | off / shadow / advisory | Whether the plugin may consult at all. Off by default; opt in explicitly. |
69
- | `provider` | Provider | `""` | route name from Settings → Models, ≤300 chars | Advisor route. Empty means never call. |
70
- | `model` | Model | `""` | model id under that route, ≤300 chars | Advisor model. Empty means never call. |
71
- | `reasoningEffort` | Reasoning effort | `""` | a supported effort id, `""` = model default | An unsupported value is retried once without an effort. |
72
- | `maxTokens` | Output limit | `4096` | 256–32000 | Maximum output tokens per consultation. |
73
- | `temperature` | Randomness | `null` | 0–2, `null` = not sent | Empty lets the model decide. |
74
- | `maxCallsPerTurn` | Calls per turn | `1` | 0–8, 0 = unlimited | Maximum consultations per turn. |
75
- | `maxCallsPerSession` | Calls per session | `32` | 0–1000, 0 = unlimited | Maximum consultations per session. |
76
- | `maxCallsPerHour` | Calls per hour | `12` | 0–500, 0 = unlimited | Sliding one-hour window. |
77
- | `maxCostPerDayUsd` | Daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Daily spend ceiling in USD; only counted when prices are set. |
78
- | `priceInputPerMTok` | Input price | `0` | 0–1000; up to 4 decimals | Advisor input price, USD per 1M tokens; 0 = do not price. |
79
- | `priceOutputPerMTok` | Output price | `0` | 0–1000; up to 4 decimals | Output price, USD per 1M tokens. |
80
- | `privacyScope` | Send scope | `"summary"` | off / summary / full | How much conversation content is sent — see Cost & privacy. |
81
- | `redact` | Redact before sending | `true` | boolean | Best-effort masking of common key formats; not a guarantee. |
82
- | `immuneTurns` | JSON only: Immune turns | `3` | 0–20 | Turns to stay quiet after a delivery; used by shadow delivery. |
83
- | `dedupe` | Dedupe in shadow mode | `true` | boolean | In shadow mode, the same advice is recorded once; the tool path does not block on it. |
84
- | `sessionCap` | Advice items per session | `24` | 0–200 | Max advice items shown per session; once reached only blockers get through. |
85
- | `tiers` | JSON only: Tiers | `{}` | `"provider/model"` → number | Capability ranks for the pairing check; without an entry the pairing is unverified. |
86
- | `allowedModels` | Model allowlist | `[]` | string array | Empty = no limit; accepts provider/model or a bare model id. |
87
- | `confirmedHosts` | JSON/button: Confirmed hosts | `[]` | string array | Cross-provider confirmation list; the settings-card button writes it. |
88
- | `pairingEnforcement` | JSON only: Pairing enforcement | `"warn"` | warn / block | When the advisor tier is lower: warn allows and warns; block refuses. |
89
- | `workspaceMaxCallsPerDay` | Workspace calls per day | `200` | 0–100000, 0 = unlimited | Workspace-wide, shared across sessions, resets on the local day. |
90
- | `workspaceMaxCostPerDayUsd` | Workspace daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Workspace-wide daily spend ceiling. |
91
- | `postAnswer` | Auto-review after each turn | `"off"` | off / card | In advisory mode, runs once after each answer; records only, never inserts. |
92
- | `advisorTools` | Let the advisor read files | `false` | boolean | Lets it read working-directory files (up to 5, read-only); costs one extra call. |
93
- | `tracePrompt` | Keep sent content | `"preview"` | `preview` / `off` | Stores the first/last 2,000 chars of the text actually sent (after redaction) in the session record; `off` stores metadata only. |
94
- | `timeoutMs` | JSON only: Timeout | `90000` | 5000–600000 | Per-consultation timeout; `/advisor cancel` aborts sooner. |
95
- | `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept. |
96
-
97
- > **Note on `sessionCap`, `dedupe`, `immuneTurns`:** `sessionCap` is enforced — after that many delivered items in one session only `blocker` advice is still returned. `dedupe` and `immuneTurns` are persisted and used by the shadow path, but the tool path does not suppress a consultation because of them (you asked for it explicitly). The ceilings that stop _calls_ altogether are `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDayUsd`.
66
+ | Key | UI label | Default | Range / values | Meaning |
67
+ | ------------------------- | ------------------------------ | ----------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
68
+ | `mode` | Mode | `"off"` | off / shadow / advisory | Whether the plugin may consult at all. Off by default; opt in explicitly. |
69
+ | `provider` | Provider | `""` | route name from Settings → Models, ≤300 chars | Advisor route. Empty means never call. |
70
+ | `model` | Model | `""` | model id under that route, ≤300 chars | Advisor model. Empty means never call. |
71
+ | `reasoningEffort` | Reasoning effort | `""` | a supported effort id, `""` = model default | An unsupported value is retried once without an effort. |
72
+ | `maxTokens` | Output limit | `4096` | 256–32000 | Maximum output tokens per consultation. |
73
+ | `temperature` | Randomness | `null` | 0–2, `null` = not sent | Empty lets the model decide. |
74
+ | `maxCallsPerTurn` | Calls per turn | `1` | 0–8, 0 = unlimited | Maximum consultations per turn. |
75
+ | `maxCallsPerSession` | Calls per session | `32` | 0–1000, 0 = unlimited | Maximum consultations per session. |
76
+ | `maxCallsPerHour` | Calls per hour | `12` | 0–500, 0 = unlimited | Sliding one-hour window. |
77
+ | `currency` | Currency | `"USD"` | USD / CNY | Amounts and prices are entered in this currency; the ledger/pool stay in USD internally. |
78
+ | `usdToCny` | CNY per USD | `7.2` | 0.1–100 | 1 USD = ? CNY; used only for CNY conversion; manual, never fetched. |
79
+ | `maxCostPerDay` | Daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Daily spend ceiling in the selected currency; only counted when prices are set. |
80
+ | `priceInputPerMTok` | Input price | `0` | 0–1000; up to 4 decimals | Advisor input price in the selected currency per 1M tokens; 0 = do not price. |
81
+ | `priceOutputPerMTok` | Output price | `0` | 0–1000; up to 4 decimals | Output price in the selected currency per 1M tokens. |
82
+ | `privacyScope` | Send scope | `"summary"` | off / summary / full | How much conversation content is sent — see Cost & privacy. |
83
+ | `redact` | Redact before sending | `true` | boolean | Best-effort masking of common key formats; not a guarantee. |
84
+ | `immuneTurns` | JSON only: Immune turns | `3` | 0–20 | Turns to stay quiet after a delivery; used by shadow delivery. |
85
+ | `dedupe` | Dedupe in shadow mode | `true` | boolean | In shadow mode, the same advice is recorded once; the tool path does not block on it. |
86
+ | `sessionCap` | Advice items per session | `24` | 0–200 | Max advice items shown per session; once reached only blockers get through. |
87
+ | `tiers` | JSON only: Tiers | `{}` | `"provider/model"` → number | Capability ranks for the pairing check; without an entry the pairing is unverified. |
88
+ | `allowedModels` | Model allowlist | `[]` | string array | Empty = no limit; accepts provider/model or a bare model id. |
89
+ | `confirmedHosts` | JSON/button: Confirmed hosts | `[]` | string array | Cross-provider confirmation list; the settings-card button writes it. |
90
+ | `pairingEnforcement` | JSON only: Pairing enforcement | `"warn"` | warn / block | When the advisor tier is lower: warn allows and warns; block refuses. |
91
+ | `workspaceMaxCallsPerDay` | Workspace calls per day | `200` | 0–100000, 0 = unlimited | Workspace-wide, shared across sessions, resets on the local day. |
92
+ | `workspaceMaxCostPerDay` | Workspace daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Workspace-wide daily ceiling in the selected currency. |
93
+ | `postAnswer` | Auto-review after each turn | `"off"` | off / card | In advisory mode, runs once after each answer; records only, never inserts. |
94
+ | `advisorTools` | Let the advisor read files | `false` | boolean | Lets it read working-directory files (up to 5, read-only); costs one extra call. |
95
+ | `tracePrompt` | Keep sent content | `"preview"` | `preview` / `off` | Stores the first/last 2,000 chars of the text actually sent (after redaction) in the session record; `off` stores metadata only. |
96
+ | `timeoutMs` | JSON only: Timeout | `90000` | 5000–600000 | Per-consultation timeout; `/advisor cancel` aborts sooner. |
97
+ | `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept. |
98
+
99
+ **Currency and ledger.** Amounts and prices in settings are entered in `currency` (USD/CNY); `usdToCny` is a manual rate. The ledger and workspace pool always store USD: limits/prices are converted to USD at call time and displayed back in the selected currency. Switching currency converts the form amounts at the rate before saving; old `maxCostPerDayUsd` / `workspaceMaxCostPerDayUsd` keys migrate as USD to the new keys. A rate change affects future conversion/display, not the historical ledger.
100
+
101
+ > **Note on `sessionCap`, `dedupe`, `immuneTurns`:** `sessionCap` is enforced — after that many delivered items in one session only `blocker` advice is still returned. `dedupe` and `immuneTurns` are persisted and used by the shadow path, but the tool path does not suppress a consultation because of them (you asked for it explicitly). The ceilings that stop _calls_ altogether are `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDay`.
98
102
 
99
103
  Example (placeholder route and model names — use the ones the picker shows you):
100
104
 
@@ -110,7 +114,7 @@ Example (placeholder route and model names — use the ones the picker shows you
110
114
 
111
115
  **Two-pass evidence (opt-in).** With `advisorTools: true` the advisor may answer with `needs: [{kind:"file", ref:"path"}]`. The plugin reads those files **inside the session working directory only** (≤5 files, ≤64 KiB each, `../` and symlink escapes rejected), then calls the advisor once more with the quoted evidence so it can revise. This is the "advisor can check the facts" mode; it costs one extra model call. A rejected or unreadable path is reported back as unavailable evidence instead of failing the consultation.
112
116
 
113
- **Workspace budget.** Besides the per-session ceilings, a shared pool (`<DSH_HOME>/advisor/budget.json`) counts calls and estimated cost per local day across sessions (`workspaceMaxCallsPerDay`, `workspaceMaxCostPerDayUsd`).
117
+ **Workspace budget.** Besides the per-session ceilings, a shared pool (`<DSH_HOME>/advisor/budget.json`) counts calls and estimated cost per local day across sessions (`workspaceMaxCallsPerDay`, `workspaceMaxCostPerDay`).
114
118
 
115
119
  **Evidence anchors.** Each advice item may cite `{kind, ref}` anchors (a tool-call id, a message id, a file path). The plugin checks every ref against the session and marks the item unverified when nothing matches; if **none** of the cited anchors exist, the severity is downgraded one step and the advice says so. This is how a hallucinated "that failing command" gets caught.
116
120
 
@@ -144,7 +148,7 @@ This is the section to read before turning it on.
144
148
 
145
149
  - **Every consultation is an extra model call**, billed by the advisor route against that provider's quota. The main model's own usage is unaffected.
146
150
  - **Token accounting is ours.** DSH records usage only for the main loop's assistant messages, so the plugin writes its own ledger: `<DSH_HOME>/advisor/usage.jsonl`, one JSON object per consultation (time, session id, trigger `tool` / `shadow` / `manual`, provider, model, effort, verdict, severity, input/output/cache tokens, estimated cost, duration, error code). The file is append-only, rolls over to `usage.jsonl.1` at 2 MiB, and totals are restored from its tail on startup.
147
- - **Money needs your prices.** DSH's model metadata has no price field. Set `priceInputPerMTok` and `priceOutputPerMTok`; with zeros the ledger records tokens only and no dollar amount is shown. The plugin never guesses prices.
151
+ - **Money needs your prices.** DSH's model metadata has no price field. Set `priceInputPerMTok` and `priceOutputPerMTok` in the selected `currency`; with zeros the ledger records tokens only and no money amount is shown. The ledger stores the USD equivalent; built-in reference prices are USD and are converted for CNY display. The plugin never guesses prices.
148
152
  - **The daily budget counts spend already recorded**, so the one consultation that crosses the ceiling still completes and is charged.
149
153
  - **Conversation content leaves the machine when the advisor route is external.** The transcript — with tool calls and results, bounded by `privacyScope` and `maxInputChars` — is sent to whatever base URL that route points at. If that is another vendor, your conversation leaves this machine. Only a route pointing at a local gateway keeps it local. The plugin sends nothing else: no telemetry, no analytics, no network access besides the consultation itself.
150
154
  - **`privacyScope` decides how much is sent.** `summary` (default): each text block up to 2,000 characters, tool arguments up to 300, tool results up to 700. `off`: user and assistant text only, up to 1,200 characters, with no tool traffic at all. `full`: text up to 4,000, tool arguments up to 1,200, tool results up to 3,500. The rendered transcript is then capped at `maxInputChars` (60,000 by default): the first 30% and the tail are kept and the middle is replaced by an elision marker.
package/README.zh-CN.md CHANGED
@@ -55,46 +55,50 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
55
55
 
56
56
  **设置页。** 设置 → 通用 → 顾问。默认 `off` 时卡片只显示模式、一句状态和「配置顾问」;展开或启用后才显示:
57
57
 
58
- - **基础**:模式、服务商、模型、思考档、每日预算、发送范围、发送前脱敏。
59
- - **高级**(默认折叠):调用限额、工作区限额、单价、输出/输入上限、建议条数、白名单、答后复查、读文件核实、影子去重、记录发送内容;折叠标题会标出「默认值」或「N 项已修改」。
58
+ - **基础**:模式、币种、服务商、模型、思考档、每日预算、发送范围、发送前脱敏。
59
+ - **高级**(默认折叠):调用限额、工作区限额、人民币汇率、单价、输出/输入上限、建议条数、白名单、答后复查、读文件核实、影子去重、记录发送内容;折叠标题会标出「默认值」或「N 项已修改」。
60
60
  - **状态与诊断**(默认折叠):累计调用/token/金额、最近结果/跳过原因、发送预览、诊断、设置文件与账本路径。
61
61
 
62
62
  高级字段旁的「?」点开或用键盘激活会显示说明、默认值与范围、技术名;悬停只是补充。改完点「保存」才对下一次徵询生效。
63
63
 
64
64
  金额字段支持小数:预算最多 2 位,单价最多 4 位。
65
65
 
66
- | 键 | 设置页名称 | 默认 | 范围 / 取值 | 说明 |
67
- | --------------------------- | ----------------------------- | ----------- | ------------------------------------ | ----------------------------------------------------------------------------- |
68
- | `mode` | 模式 | `"off"` | off / shadow / advisory | 是否允许徵询。默认关闭,显式开启才生效。 |
69
- | `provider` | 服务商 | `""` | 设置 → 模型里的路由名,≤300 字符 | 顾问路由。留空 = 永不调用。 |
70
- | `model` | 模型 | `""` | 该路由下的模型 id,≤300 字符 | 顾问模型。留空 = 永不调用。 |
71
- | `reasoningEffort` | 思考档 | `""` | 模型支持的思考档 id,`""` = 模型默认 | 填了不支持的值会去掉思考档重试一次。 |
72
- | `maxTokens` | 输出上限 | `4096` | 256–32000 | 单次徵询最多生成多少 token。 |
73
- | `temperature` | 随机性 | `null` | 0–2,`null` = 不传 | 留空由模型决定。 |
74
- | `maxCallsPerTurn` | 每回合调用上限 | `1` | 0–8,0 = 不限 | 每回合最多徵询几次。 |
75
- | `maxCallsPerSession` | 每会话调用上限 | `32` | 0–1000,0 = 不限 | 每个会话最多徵询几次。 |
76
- | `maxCallsPerHour` | 每小时调用上限 | `12` | 0–500,0 = 不限 | 滚动一小时内。 |
77
- | `maxCostPerDayUsd` | 每日预算 | `0` | 0–10000,0 = 不限;最多 2 位小数 | 每天最多花多少美元;只有填了单价才计算金额。 |
78
- | `priceInputPerMTok` | 输入单价 | `0` | 0–1000;最多 4 位小数 | 顾问模型输入价,美元 / 百万 token;0 = 不算钱。 |
79
- | `priceOutputPerMTok` | 输出单价 | `0` | 0–1000;最多 4 位小数 | 输出价,美元 / 百万 token。 |
80
- | `privacyScope` | 发送范围 | `"summary"` | off / summary / full | 发多少会话内容,见「成本与隐私」。 |
81
- | `redact` | 发送前脱敏 | `true` | 布尔 | 尽量遮掉常见密钥格式;不能保证全部遮住。 |
82
- | `immuneTurns` | 仅 JSON:免疫回合 | `3` | 0–20 | 投递后保持安静的回合数;只用于 shadow 投递。 |
83
- | `dedupe` | 影子模式去重 | `true` | 布尔 | 影子模式下相同建议只记一次;工具路径不据此拦截。 |
84
- | `sessionCap` | 建议条数上限 | `24` | 0–200 | 单会话最多展示几条建议;到顶后只有 blocker 继续。 |
85
- | `tiers` | 仅 JSON:能力档位 | `{}` | `"provider/model"` → 数字 | 配对校验用的档位;没有条目时结论是「未校验」。 |
86
- | `allowedModels` | 模型白名单 | `[]` | 字符串数组 | 留空 = 不限制;可写 provider/model 或裸 model id。 |
87
- | `confirmedHosts` | 仅 JSON/按钮:已确认 provider | `[]` | 字符串数组 | 跨 provider 发送的确认名单;设置卡里的按钮会写入。 |
88
- | `pairingEnforcement` | 仅 JSON:配对校验 | `"warn"` | warn / block | 顾问档位低于主模型时:warn 放行并告警,block 拒绝。 |
89
- | `workspaceMaxCallsPerDay` | 工作区每日调用上限 | `200` | 0–100000,0 = 不限 | 工作区级,跨会话累计,按本地日重置。 |
90
- | `workspaceMaxCostPerDayUsd` | 工作区每日预算 | `0` | 0–10000,0 = 不限;最多 2 位小数 | 工作区级每日金额上限。 |
91
- | `postAnswer` | 回合结束后自动复查 | `"off"` | off / card | advisory 模式下每轮回答后自动复查一次;只记录,不插回对话。 |
92
- | `advisorTools` | 允许顾问读文件核实 | `false` | 布尔 | 允许顾问读工作目录内的文件(≤5 个、只读);多一次调用。 |
93
- | `tracePrompt` | 记录发送内容 | `"preview"` | `preview` / `off` | 在会话记录里保留实际发送文本的首尾各 2,000 字符(脱敏后);`off` 只记元数据。 |
94
- | `timeoutMs` | 仅 JSON:超时 | `90000` | 5000–600000 | 单次徵询超时;`/advisor cancel` 可以更早中止。 |
95
- | `maxInputChars` | 输入上限 | `60000` | 4000–400000 | 会话文本总预算;超出保留首尾、省略中间。 |
96
-
97
- > **关于 `sessionCap`、`dedupe`、`immuneTurns`:** `sessionCap` 会生效——单会话投递到上限后,只有 `blocker` 级建议还会返回。`dedupe` 与 `immuneTurns` 会被保存并用于 shadow 路径,但工具路径不会因为它们跳过徵询(是模型显式要求的)。真正会拦住**调用本身**的是 `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDayUsd`。
66
+ | 键 | 设置页名称 | 默认 | 范围 / 取值 | 说明 |
67
+ | ------------------------- | ----------------------------- | ----------- | ------------------------------------ | ----------------------------------------------------------------------------- |
68
+ | `mode` | 模式 | `"off"` | off / shadow / advisory | 是否允许徵询。默认关闭,显式开启才生效。 |
69
+ | `provider` | 服务商 | `""` | 设置 → 模型里的路由名,≤300 字符 | 顾问路由。留空 = 永不调用。 |
70
+ | `model` | 模型 | `""` | 该路由下的模型 id,≤300 字符 | 顾问模型。留空 = 永不调用。 |
71
+ | `reasoningEffort` | 思考档 | `""` | 模型支持的思考档 id,`""` = 模型默认 | 填了不支持的值会去掉思考档重试一次。 |
72
+ | `maxTokens` | 输出上限 | `4096` | 256–32000 | 单次徵询最多生成多少 token。 |
73
+ | `temperature` | 随机性 | `null` | 0–2,`null` = 不传 | 留空由模型决定。 |
74
+ | `maxCallsPerTurn` | 每回合调用上限 | `1` | 0–8,0 = 不限 | 每回合最多徵询几次。 |
75
+ | `maxCallsPerSession` | 每会话调用上限 | `32` | 0–1000,0 = 不限 | 每个会话最多徵询几次。 |
76
+ | `maxCallsPerHour` | 每小时调用上限 | `12` | 0–500,0 = 不限 | 滚动一小时内。 |
77
+ | `currency` | 币种 | `"USD"` | USD / CNY | 金额和单价按此币种填写;账本/预算池内部仍记 USD。 |
78
+ | `usdToCny` | 人民币汇率 | `7.2` | 0.1–100 | 1 USD = ? CNY;只在人民币时用于换算;手动维护,不联网。 |
79
+ | `maxCostPerDay` | 每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 每天最多花多少(按 `currency`);只有填了单价才计算金额。 |
80
+ | `priceInputPerMTok` | 输入单价 | `0` | 0–1000;最多 4 位小数 | 顾问模型输入价,按 `currency` / 百万 token;0 = 不算钱。 |
81
+ | `priceOutputPerMTok` | 输出单价 | `0` | 0–1000;最多 4 位小数 | 输出价,按 `currency` / 百万 token。 |
82
+ | `privacyScope` | 发送范围 | `"summary"` | off / summary / full | 发多少会话内容,见「成本与隐私」。 |
83
+ | `redact` | 发送前脱敏 | `true` | 布尔 | 尽量遮掉常见密钥格式;不能保证全部遮住。 |
84
+ | `immuneTurns` | 仅 JSON:免疫回合 | `3` | 0–20 | 投递后保持安静的回合数;只用于 shadow 投递。 |
85
+ | `dedupe` | 影子模式去重 | `true` | 布尔 | 影子模式下相同建议只记一次;工具路径不据此拦截。 |
86
+ | `sessionCap` | 建议条数上限 | `24` | 0–200 | 单会话最多展示几条建议;到顶后只有 blocker 继续。 |
87
+ | `tiers` | 仅 JSON:能力档位 | `{}` | `"provider/model"` → 数字 | 配对校验用的档位;没有条目时结论是「未校验」。 |
88
+ | `allowedModels` | 模型白名单 | `[]` | 字符串数组 | 留空 = 不限制;可写 provider/model 或裸 model id。 |
89
+ | `confirmedHosts` | 仅 JSON/按钮:已确认 provider | `[]` | 字符串数组 | 跨 provider 发送的确认名单;设置卡里的按钮会写入。 |
90
+ | `pairingEnforcement` | 仅 JSON:配对校验 | `"warn"` | warn / block | 顾问档位低于主模型时:warn 放行并告警,block 拒绝。 |
91
+ | `workspaceMaxCallsPerDay` | 工作区每日调用上限 | `200` | 0–100000,0 = 不限 | 工作区级,跨会话累计,按本地日重置。 |
92
+ | `workspaceMaxCostPerDay` | 工作区每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 工作区级每日金额上限(按 `currency`)。 |
93
+ | `postAnswer` | 回合结束后自动复查 | `"off"` | off / card | advisory 模式下每轮回答后自动复查一次;只记录,不插回对话。 |
94
+ | `advisorTools` | 允许顾问读文件核实 | `false` | 布尔 | 允许顾问读工作目录内的文件(≤5 个、只读);多一次调用。 |
95
+ | `tracePrompt` | 记录发送内容 | `"preview"` | `preview` / `off` | 在会话记录里保留实际发送文本的首尾各 2,000 字符(脱敏后);`off` 只记元数据。 |
96
+ | `timeoutMs` | 仅 JSON:超时 | `90000` | 5000–600000 | 单次徵询超时;`/advisor cancel` 可以更早中止。 |
97
+ | `maxInputChars` | 输入上限 | `60000` | 4000–400000 | 会话文本总预算;超出保留首尾、省略中间。 |
98
+
99
+ **币种与账本。** 设置里的金额和单价按 `currency` 填写(USD/CNY),`usdToCny` 是手动汇率。账本与工作区预算池内部始终记 USD:调用时把设置金额换算成 USD,展示时再换回当前币种。切换币种会按汇率折算当前表单金额,保存前不会落盘;旧版 `maxCostPerDayUsd` / `workspaceMaxCostPerDayUsd` 键会按 USD 自动迁移到新键。汇率变化只影响之后的换算和展示,不会重写历史账本。
100
+
101
+ > **关于 `sessionCap`、`dedupe`、`immuneTurns`:** `sessionCap` 会生效——单会话投递到上限后,只有 `blocker` 级建议还会返回。`dedupe` 与 `immuneTurns` 会被保存并用于 shadow 路径,但工具路径不会因为它们跳过徵询(是模型显式要求的)。真正会拦住**调用本身**的是 `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDay`。
98
102
 
99
103
  示例(路由名和模型名是占位,请用选择器里看到的真实值):
100
104
 
@@ -134,7 +138,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
134
138
 
135
139
  - **每次徵询都是一次额外的模型调用**,按顾问路由计费,走那家 provider 的额度。主模型自身的 usage 不受影响。
136
140
  - **token 由插件自己记账。** DSH 只为主动环里的 assistant 消息记 usage,所以插件单写一份账本:`<DSH_HOME>/advisor/usage.jsonl`,一次徵询一行 JSON(时间、会话 id、触发方式 `tool` / `shadow` / `manual`、provider、model、思考档、结论、严重度、输入 / 输出 / 缓存 token、估算金额、耗时、错误码)。文件只追加,超过 2 MiB 滚动到 `usage.jsonl.1`,启动时从文件尾部恢复累计数。
137
- - **算钱需要你填单价。** DSH 的模型元数据没有价格字段。填 `priceInputPerMTok` 和 `priceOutputPerMTok`;都留 0 时账本只记 token,界面不显示金额。插件从不猜价格。
141
+ - **算钱需要你填单价。** DSH 的模型元数据没有价格字段。按 `currency` 填 `priceInputPerMTok` 和 `priceOutputPerMTok`;都留 0 时账本只记 token,界面不显示金额。账本内部记 USD 等价,内置参考价是 USD,人民币展示时折算。插件从不猜价格。
138
142
  - **每日预算统计的是已经记下的花费**,所以跨过上限的那一次徵询仍会完成并计费。
139
143
  - **顾问路由在外部时,会话内容会离开本机。** 渲染后的会话文本(含工具调用与结果,受 `privacyScope` 和 `maxInputChars` 限制)会发到该路由指向的 baseURL。如果那是另一家厂商,你的对话就离开了这台机器;只有指向本地网关的路由才留在本机。除此之外插件什么都不发:没有遥测,没有统计,除了徵询本身不访问网络。
140
144
  - **`privacyScope` 决定发多少。** `summary`(默认):每个文本块最多 2,000 字符,工具参数最多 300,工具结果最多 700。`off`:只发用户与助手的文本(最多 1,200 字符),完全不发工具往来。`full`:文本最多 4,000,工具参数最多 1,200,工具结果最多 3,500。渲染完再按 `maxInputChars`(默认 60,000)封顶:保留前 30% 和结尾,中间替换成省略标记。
package/lib/budget.js CHANGED
@@ -6,6 +6,8 @@
6
6
  import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
7
7
  import { join } from "node:path";
8
8
 
9
+ import { toUsd } from "./money.js";
10
+
9
11
  /** 预算池文件名(位于数据根下的 advisor/ 目录)。 */
10
12
  export const BUDGET_FILE = "budget.json";
11
13
 
@@ -40,7 +42,7 @@ export function normalizePool(raw, today) {
40
42
  /**
41
43
  * 池子是否还能容纳一次调用。
42
44
  * @param {{ calls: number, costUsd: number }} pool
43
- * @param {{ workspaceMaxCallsPerDay: number, workspaceMaxCostPerDayUsd: number }} settings
45
+ * @param {{ workspaceMaxCallsPerDay: number, workspaceMaxCostPerDay: number, currency?: string, usdToCny?: number }} settings
44
46
  * @param {number} [estimatedCostUsd]
45
47
  * @returns {{ ok: true } | { ok: false, code: "workspace_calls"|"workspace_budget", used: number, limit: number }}
46
48
  */
@@ -49,9 +51,13 @@ export function checkPool(pool, settings, estimatedCostUsd = 0) {
49
51
  if (maxCalls > 0 && pool.calls >= maxCalls) {
50
52
  return { ok: false, code: "workspace_calls", used: pool.calls, limit: maxCalls };
51
53
  }
52
- const maxCost = Number(settings?.workspaceMaxCostPerDayUsd ?? 0) || 0;
53
- if (maxCost > 0 && pool.costUsd + estimatedCostUsd >= maxCost) {
54
- return { ok: false, code: "workspace_budget", used: pool.costUsd, limit: maxCost };
54
+ const maxCostUsd = toUsd(
55
+ settings?.workspaceMaxCostPerDay,
56
+ settings?.currency,
57
+ settings?.usdToCny,
58
+ );
59
+ if (maxCostUsd > 0 && pool.costUsd + estimatedCostUsd >= maxCostUsd) {
60
+ return { ok: false, code: "workspace_budget", used: pool.costUsd, limit: maxCostUsd };
55
61
  }
56
62
  return { ok: true };
57
63
  }
package/lib/catalog.js CHANGED
@@ -9,6 +9,8 @@
9
9
  //
10
10
  // 纯数据 + 纯函数,不 import 宿主包。
11
11
 
12
+ import { toUsd } from "./money.js";
13
+
12
14
  /**
13
15
  * 能力档位(越大越强)。同一族按代际与规格排序;跨族只保证「明显更强/更弱」的关系。
14
16
  * 键是模型 id 的小写匹配片段,按**从长到短**匹配,避免 `deepseek-v4` 抢走 `deepseek-v4.1-flash`。
@@ -112,13 +114,22 @@ export function effectiveRank(tiers, route) {
112
114
 
113
115
  /**
114
116
  * 有效单价:用户声明 > 内置;都没有返回 `{ input: 0, output: 0 }`(= 不算钱)。
115
- * @param {{ priceInputPerMTok: number, priceOutputPerMTok: number }} settings
117
+ * @param {{ priceInputPerMTok: number, priceOutputPerMTok: number, currency?: string, usdToCny?: number }} settings
116
118
  * @param {string} modelId
117
119
  * @returns {{ input: number, output: number, source: "settings"|"builtin"|"none" }}
118
120
  */
119
121
  export function effectivePrice(settings, modelId) {
120
- const input = Number(settings?.priceInputPerMTok ?? 0) || 0;
121
- const output = Number(settings?.priceOutputPerMTok ?? 0) || 0;
122
+ // 设置里的单价按 settings.currency 填写;内部估算统一换算成 USD。
123
+ const input = toUsd(
124
+ Number(settings?.priceInputPerMTok ?? 0) || 0,
125
+ settings?.currency,
126
+ settings?.usdToCny,
127
+ );
128
+ const output = toUsd(
129
+ Number(settings?.priceOutputPerMTok ?? 0) || 0,
130
+ settings?.currency,
131
+ settings?.usdToCny,
132
+ );
122
133
  if (input > 0 || output > 0) return { input, output, source: "settings" };
123
134
  const builtin = builtinPrice(modelId);
124
135
  if (builtin !== undefined) return { ...builtin, source: "builtin" };
package/lib/client.js CHANGED
@@ -108,7 +108,6 @@ window.__ModuleLoader__.load({
108
108
  "settings.budget.maxCallsPerTurn": "每回合最多调用",
109
109
  "settings.budget.maxCallsPerSession": "每会话最多调用",
110
110
  "settings.budget.maxCallsPerHour": "每小时最多调用",
111
- "settings.budget.maxCostPerDayUsd": "每日预算(USD)",
112
111
  "settings.budget.priceInputPerMTok": "输入单价(USD / 百万 token)",
113
112
  "settings.budget.priceOutputPerMTok": "输出单价(USD / 百万 token)",
114
113
  "settings.budget.range": "默认 {default} · 范围 {min}–{max}",
@@ -247,7 +246,6 @@ window.__ModuleLoader__.load({
247
246
  "settings.budget.maxCallsPerTurn": "Max calls per turn",
248
247
  "settings.budget.maxCallsPerSession": "Max calls per session",
249
248
  "settings.budget.maxCallsPerHour": "Max calls per hour",
250
- "settings.budget.maxCostPerDayUsd": "Daily budget (USD)",
251
249
  "settings.budget.priceInputPerMTok": "Input price (USD / 1M tokens)",
252
250
  "settings.budget.priceOutputPerMTok": "Output price (USD / 1M tokens)",
253
251
  "settings.budget.range": "default {default} · range {min}–{max}",
@@ -603,7 +601,9 @@ window.__ModuleLoader__.load({
603
601
  maxCallsPerTurn: 1,
604
602
  maxCallsPerSession: 32,
605
603
  maxCallsPerHour: 12,
606
- maxCostPerDayUsd: 0,
604
+ currency: "USD",
605
+ usdToCny: 7.2,
606
+ maxCostPerDay: 0,
607
607
  priceInputPerMTok: 0,
608
608
  priceOutputPerMTok: 0,
609
609
  privacyScope: "summary",
@@ -612,7 +612,7 @@ window.__ModuleLoader__.load({
612
612
  sessionCap: 24,
613
613
  allowedModels: [],
614
614
  workspaceMaxCallsPerDay: 200,
615
- workspaceMaxCostPerDayUsd: 0,
615
+ workspaceMaxCostPerDay: 0,
616
616
  postAnswer: "off",
617
617
  advisorTools: false,
618
618
  tracePrompt: "preview",
@@ -625,21 +625,23 @@ window.__ModuleLoader__.load({
625
625
  maxCallsPerTurn: [0, 8],
626
626
  maxCallsPerSession: [0, 1000],
627
627
  maxCallsPerHour: [0, 500],
628
- maxCostPerDayUsd: [0, 10000],
628
+ maxCostPerDay: [0, 10000],
629
629
  priceInputPerMTok: [0, 1000],
630
630
  priceOutputPerMTok: [0, 1000],
631
631
  workspaceMaxCallsPerDay: [0, 100000],
632
- workspaceMaxCostPerDayUsd: [0, 10000],
632
+ workspaceMaxCostPerDay: [0, 10000],
633
+ usdToCny: [0.1, 100],
633
634
  sessionCap: [0, 200],
634
635
  maxInputChars: [4000, 400000],
635
636
  };
636
637
 
637
638
  /** 金额字段的小数位;与 settings.js 的 MONEY_LIMITS 一致。 @type {Record<string, number>} */
638
639
  let SETTINGS_MONEY_FIELDS = {
639
- maxCostPerDayUsd: 2,
640
- workspaceMaxCostPerDayUsd: 2,
640
+ maxCostPerDay: 2,
641
+ workspaceMaxCostPerDay: 2,
641
642
  priceInputPerMTok: 4,
642
643
  priceOutputPerMTok: 4,
644
+ usdToCny: 4,
643
645
  };
644
646
 
645
647
  /** 所有整数输入字段(temperature 单独处理:可为空、可小数)。 */
@@ -653,9 +655,10 @@ window.__ModuleLoader__.load({
653
655
  "maxCallsPerSession",
654
656
  "maxCallsPerHour",
655
657
  "workspaceMaxCallsPerDay",
656
- "workspaceMaxCostPerDayUsd",
658
+ "workspaceMaxCostPerDay",
657
659
  "priceInputPerMTok",
658
660
  "priceOutputPerMTok",
661
+ "usdToCny",
659
662
  "maxTokens",
660
663
  "temperature",
661
664
  "maxInputChars",
@@ -672,9 +675,9 @@ window.__ModuleLoader__.load({
672
675
  "maxCallsPerTurn",
673
676
  "maxCallsPerSession",
674
677
  "maxCallsPerHour",
675
- "maxCostPerDayUsd",
678
+ "maxCostPerDay",
676
679
  "workspaceMaxCallsPerDay",
677
- "workspaceMaxCostPerDayUsd",
680
+ "workspaceMaxCostPerDay",
678
681
  ];
679
682
 
680
683
  /** 模式与发送范围的白名单,与 settings.js 一致。 */
@@ -698,11 +701,13 @@ window.__ModuleLoader__.load({
698
701
  "maxCallsPerTurn",
699
702
  "maxCallsPerSession",
700
703
  "maxCallsPerHour",
701
- "maxCostPerDayUsd",
704
+ "currency",
705
+ "usdToCny",
706
+ "maxCostPerDay",
702
707
  "priceInputPerMTok",
703
708
  "priceOutputPerMTok",
704
709
  "workspaceMaxCallsPerDay",
705
- "workspaceMaxCostPerDayUsd",
710
+ "workspaceMaxCostPerDay",
706
711
  "privacyScope",
707
712
  "redact",
708
713
  "dedupe",
@@ -814,9 +819,16 @@ window.__ModuleLoader__.load({
814
819
  postAnswer: input.postAnswer === "card" ? "card" : "off",
815
820
  advisorTools: input.advisorTools === true,
816
821
  tracePrompt: input.tracePrompt === "off" ? "off" : "preview",
822
+ currency: input.currency === "CNY" ? "CNY" : "USD",
823
+ usdToCny: 7.2,
817
824
  allowedModels: normalizeStringList(input.allowedModels),
818
825
  confirmedHosts: normalizeStringList(input.confirmedHosts),
819
826
  };
827
+ let rawRate = Number(input.usdToCny);
828
+ out.usdToCny =
829
+ Number.isFinite(rawRate) && rawRate > 0
830
+ ? clampMoney(rawRate, SETTINGS_DEFAULTS.usdToCny, 0.1, 100, 4)
831
+ : SETTINGS_DEFAULTS.usdToCny;
820
832
  for (let index = 0; index < SETTINGS_INT_FIELDS.length; index += 1) {
821
833
  let key = SETTINGS_INT_FIELDS[index];
822
834
  out[key] = clampInt(
@@ -827,6 +839,7 @@ window.__ModuleLoader__.load({
827
839
  );
828
840
  }
829
841
  for (let key of Object.keys(SETTINGS_MONEY_FIELDS)) {
842
+ if (key === "usdToCny") continue;
830
843
  out[key] = clampMoney(
831
844
  input[key],
832
845
  SETTINGS_DEFAULTS[key],
@@ -864,6 +877,80 @@ window.__ModuleLoader__.load({
864
877
  return n;
865
878
  }
866
879
 
880
+ /**
881
+ * 币种规整:未知值按 USD。
882
+ * @param {any} value
883
+ * @returns {"USD"|"CNY"}
884
+ */
885
+ function currencyOf(value) {
886
+ return value === "CNY" ? "CNY" : "USD";
887
+ }
888
+
889
+ /**
890
+ * USD → 设置币种金额;汇率非法时回落 7.2。
891
+ * @param {any} amountUsd
892
+ * @param {any} currency
893
+ * @param {any} rate
894
+ * @returns {number}
895
+ */
896
+ function fromUsd(amountUsd, currency, rate) {
897
+ let n = Number(amountUsd);
898
+ if (!Number.isFinite(n)) return 0;
899
+ if (currencyOf(currency) === "USD") return n;
900
+ let r = Number(rate);
901
+ if (!Number.isFinite(r) || r <= 0) r = 7.2;
902
+ return n * r;
903
+ }
904
+
905
+ /**
906
+ * 金额显示:USD 用 $,CNY 用 ¥。
907
+ * @param {any} amount
908
+ * @param {any} currency
909
+ * @param {number} [digits]
910
+ * @returns {string}
911
+ */
912
+ function formatMoney(amount, currency, digits) {
913
+ let n = Number(amount);
914
+ let value = Number.isFinite(n) ? n : 0;
915
+ let places =
916
+ typeof digits === "number" && Number.isFinite(digits)
917
+ ? Math.max(0, Math.min(8, Math.round(digits)))
918
+ : 4;
919
+ return `${currencyOf(currency) === "CNY" ? "¥" : "$"}${value.toFixed(places)}`;
920
+ }
921
+
922
+ /**
923
+ * 把草稿里的金额字段从当前币种换到目标币种,保持真实价值不变。
924
+ * 汇率是 1 USD = ? CNY;切换时用当前草稿里的汇率。
925
+ * @param {any} source
926
+ * @param {any} nextCurrency
927
+ * @returns {any}
928
+ */
929
+ function convertCurrency(source, nextCurrency) {
930
+ let from = currencyOf(source.currency);
931
+ let to = currencyOf(nextCurrency);
932
+ let next = Object.assign({}, source, { currency: to });
933
+ if (from === to) return next;
934
+ let rate = Number(source.usdToCny);
935
+ if (!Number.isFinite(rate) || rate <= 0) rate = 7.2;
936
+ let factor = to === "CNY" ? rate : 1 / rate;
937
+ /** @type {Record<string, number>} */
938
+ let fields = {
939
+ maxCostPerDay: 2,
940
+ workspaceMaxCostPerDay: 2,
941
+ priceInputPerMTok: 4,
942
+ priceOutputPerMTok: 4,
943
+ };
944
+ for (let key of Object.keys(fields)) {
945
+ let n = Number(source[key]);
946
+ if (!Number.isFinite(n)) n = 0;
947
+ let digits = fields[key];
948
+ let scale = 10 ** digits;
949
+ next[key] = Math.round(n * factor * scale) / scale;
950
+ }
951
+ return next;
952
+ }
953
+
867
954
  /**
868
955
  * 校验 `advisor/options`:settings 必须可用,其余字段缺失时降级为空。
869
956
  * 畸形一律 null(调用方显示内联错误 + 重试)。
@@ -2320,6 +2407,49 @@ window.__ModuleLoader__.load({
2320
2407
  );
2321
2408
  }
2322
2409
 
2410
+ /** 切换币种:按当前汇率折算金额,保持真实价值不变。 @param {string} value */
2411
+ function chooseCurrency(value) {
2412
+ if (!draft) return;
2413
+ let nextCurrency = currencyOf(value);
2414
+ if (nextCurrency === draft.currency) return;
2415
+ let next = convertCurrency(draft, nextCurrency);
2416
+ setDraft(next);
2417
+ setTexts(textsOf(next));
2418
+ setError(null);
2419
+ setNotice(
2420
+ t("settings.currency.converted")
2421
+ .replace("{currency}", nextCurrency)
2422
+ .replace("{rate}", String(next.usdToCny)),
2423
+ );
2424
+ }
2425
+
2426
+ /** 金额字段的币种单位。 @returns {string} */
2427
+ function currencyLabel() {
2428
+ return draft !== null && draft.currency === "CNY"
2429
+ ? t("settings.unit.cny")
2430
+ : t("settings.unit.usd");
2431
+ }
2432
+
2433
+ /** 单价的币种单位。 @returns {string} */
2434
+ function priceUnit() {
2435
+ return draft !== null && draft.currency === "CNY"
2436
+ ? t("settings.unit.cnyPerMTok")
2437
+ : t("settings.unit.usdPerMTok");
2438
+ }
2439
+
2440
+ /** 币种一行。 @returns {any} */
2441
+ function currencyField() {
2442
+ return selectField(
2443
+ "currency",
2444
+ "settings.currency",
2445
+ ["USD", "CNY"],
2446
+ "settings.currency.",
2447
+ draft.currency,
2448
+ chooseCurrency,
2449
+ { hint: t("settings.currencyHint") },
2450
+ );
2451
+ }
2452
+
2323
2453
  /**
2324
2454
  * @param {string} key
2325
2455
  * @param {boolean} on
@@ -3039,7 +3169,7 @@ window.__ModuleLoader__.load({
3039
3169
 
3040
3170
  let sep = t("settings.status.sep");
3041
3171
  let totals = snap.totals;
3042
- let priced = snap.settings.priceInputPerMTok > 0 || snap.settings.priceOutputPerMTok > 0;
3172
+ let priced = snap.price.source !== "none";
3043
3173
  let lastText =
3044
3174
  snap.last === null
3045
3175
  ? t("settings.status.none")
@@ -3051,7 +3181,13 @@ window.__ModuleLoader__.load({
3051
3181
  .replace("{output}", formatCount(totals.outputTokens)),
3052
3182
  t("settings.status.cost") +
3053
3183
  sep +
3054
- (priced ? `≈ $${Number(totals.costUsd).toFixed(4)}` : t("settings.status.costUnset")),
3184
+ (priced
3185
+ ? `≈${formatMoney(
3186
+ fromUsd(totals.costUsd, snap.settings.currency, snap.settings.usdToCny),
3187
+ snap.settings.currency,
3188
+ 4,
3189
+ )}`
3190
+ : t("settings.status.costUnset")),
3055
3191
  t("settings.status.last") + sep + lastText,
3056
3192
  t("settings.status.skip") +
3057
3193
  sep +
@@ -3089,7 +3225,14 @@ window.__ModuleLoader__.load({
3089
3225
  let priceSourceText = t(`settings.budget.priceSource.${snap.price.source}`);
3090
3226
  let poolLine = t("settings.budget.poolLine")
3091
3227
  .replace("{calls}", formatCount(snap.pool.calls))
3092
- .replace("{cost}", `$${Number(snap.pool.costUsd).toFixed(4)}`);
3228
+ .replace(
3229
+ "{cost}",
3230
+ formatMoney(
3231
+ fromUsd(snap.pool.costUsd, snap.settings.currency, snap.settings.usdToCny),
3232
+ snap.settings.currency,
3233
+ 4,
3234
+ ),
3235
+ );
3093
3236
 
3094
3237
  // 基础设置:只放开启前必须做的决定,以及每日预算与发送范围。
3095
3238
  let basicBody = [
@@ -3097,9 +3240,10 @@ window.__ModuleLoader__.load({
3097
3240
  subgroup(
3098
3241
  "settings.group.spend",
3099
3242
  [
3100
- numberField("maxCostPerDayUsd", "settings.budget.maxCostPerDayUsd", {
3243
+ currencyField(),
3244
+ numberField("maxCostPerDay", "settings.budget.maxCostPerDay", {
3101
3245
  hint: t("settings.basic.budgetHint"),
3102
- unit: t("settings.unit.usd"),
3246
+ unit: currencyLabel(),
3103
3247
  }),
3104
3248
  ],
3105
3249
  "spend",
@@ -3151,9 +3295,9 @@ window.__ModuleLoader__.load({
3151
3295
  help: t("settings.budget.workspaceHint"),
3152
3296
  unit: t("settings.unit.calls"),
3153
3297
  }),
3154
- numberField("workspaceMaxCostPerDayUsd", "settings.budget.workspaceMaxCostPerDayUsd", {
3298
+ numberField("workspaceMaxCostPerDay", "settings.budget.workspaceMaxCostPerDay", {
3155
3299
  help: t("settings.budget.workspaceHint"),
3156
- unit: t("settings.unit.usd"),
3300
+ unit: currencyLabel(),
3157
3301
  }),
3158
3302
  h(
3159
3303
  "div",
@@ -3166,13 +3310,17 @@ window.__ModuleLoader__.load({
3166
3310
  subgroup(
3167
3311
  "settings.group.money",
3168
3312
  [
3313
+ numberField("usdToCny", "settings.usdToCny", {
3314
+ help: t("settings.usdToCnyHint"),
3315
+ unit: t("settings.unit.cnyPerUsd"),
3316
+ }),
3169
3317
  numberField("priceInputPerMTok", "settings.budget.priceInputPerMTok", {
3170
3318
  help: t("settings.budget.priceHint"),
3171
- unit: t("settings.unit.usdPerMTok"),
3319
+ unit: priceUnit(),
3172
3320
  }),
3173
3321
  numberField("priceOutputPerMTok", "settings.budget.priceOutputPerMTok", {
3174
3322
  help: t("settings.budget.priceHint"),
3175
- unit: t("settings.unit.usdPerMTok"),
3323
+ unit: priceUnit(),
3176
3324
  }),
3177
3325
  h("div", { className: "dsh-advisor-readout", key: "priceSource" }, priceSourceText),
3178
3326
  ],
@@ -3498,7 +3646,6 @@ window.__ModuleLoader__.load({
3498
3646
  "settings.advisorToolsHint":
3499
3647
  "允许顾问读取工作目录里的文件来核实结论(最多 5 个、只读);会多一次模型调用。",
3500
3648
  "settings.budget.workspaceMaxCallsPerDay": "工作区每日调用上限",
3501
- "settings.budget.workspaceMaxCostPerDayUsd": "工作区每日预算",
3502
3649
  "settings.budget.workspaceHint": "工作区级,跨会话累计、按本地日重置",
3503
3650
  "settings.budget.poolLine": "工作区今日:{calls} 次 · ≈{cost}",
3504
3651
  "settings.budget.priceSource.builtin": "单价来源:内置参考价",
@@ -3526,6 +3673,20 @@ window.__ModuleLoader__.load({
3526
3673
  "settings.tracePrompt.hint":
3527
3674
  "在会话记录里保留本次实际发送文本的首尾各 2,000 字符(脱敏后);关掉后只记元数据。发送前脱敏关闭时,预览也会包含原文。",
3528
3675
  "settings.help.defaultPreview": "默认:首尾预览",
3676
+ "settings.currency": "币种",
3677
+ "settings.currency.USD": "美元(USD)",
3678
+ "settings.currency.CNY": "人民币(CNY)",
3679
+ "settings.currencyHint":
3680
+ "金额和单价按此币种填写;切换时会按汇率折算金额,保持真实价值不变。",
3681
+ "settings.currency.converted": "已按 1 USD = {rate} CNY 折算金额(尚未保存)。",
3682
+ "settings.usdToCny": "人民币汇率",
3683
+ "settings.usdToCnyHint":
3684
+ "1 USD = ? CNY;只在币种为人民币时用于换算。插件不联网取汇率,请手动维护。",
3685
+ "settings.unit.cny": "元",
3686
+ "settings.unit.cnyPerMTok": "元 / 百万 token",
3687
+ "settings.unit.cnyPerUsd": "元 / USD",
3688
+ "settings.budget.maxCostPerDay": "每日预算",
3689
+ "settings.budget.workspaceMaxCostPerDay": "工作区每日预算",
3529
3690
  "tail.trace.preview": "查看发送内容",
3530
3691
  "tail.trace.previewHide": "收起发送内容",
3531
3692
  "tail.trace.previewTruncated": "实际发送(脱敏后,首尾各 2,000 字符;共 {chars} 字符)",
@@ -3546,7 +3707,6 @@ window.__ModuleLoader__.load({
3546
3707
  "settings.budget.maxCallsPerTurn": "每回合调用上限",
3547
3708
  "settings.budget.maxCallsPerSession": "每会话调用上限",
3548
3709
  "settings.budget.maxCallsPerHour": "每小时调用上限",
3549
- "settings.budget.maxCostPerDayUsd": "每日预算",
3550
3710
  "settings.budget.priceInputPerMTok": "输入单价",
3551
3711
  "settings.budget.priceOutputPerMTok": "输出单价",
3552
3712
  "settings.scope.off": "不发送",
@@ -3592,7 +3752,8 @@ window.__ModuleLoader__.load({
3592
3752
  "settings.group.delivery": "投递与行为",
3593
3753
  "settings.group.more": "更多",
3594
3754
  "settings.group.status": "状态与诊断",
3595
- "settings.basic.budgetHint": "0 = 不限;默认 0,范围 0–10000。更细的限额在高级设置里。",
3755
+ "settings.basic.budgetHint":
3756
+ "0 = 不限;默认 0,范围 0–10000(按当前币种)。切换币种会按汇率折算;更细的限额在高级设置里。",
3596
3757
  "settings.budget.maxCostHint": "每天最多花多少钱;0 = 不限。只有填了单价才会计算金额。",
3597
3758
  "settings.advanced.maxTokensHint": "单次回答最多生成多少 token;越大越贵。",
3598
3759
  "settings.advanced.maxInputCharsHint":
@@ -3625,7 +3786,6 @@ window.__ModuleLoader__.load({
3625
3786
  "settings.advisorToolsHint":
3626
3787
  "Lets the advisor read files in the working directory to verify conclusions (up to 5 files, read-only); costs one extra model call.",
3627
3788
  "settings.budget.workspaceMaxCallsPerDay": "Workspace calls per day",
3628
- "settings.budget.workspaceMaxCostPerDayUsd": "Workspace daily budget",
3629
3789
  "settings.budget.workspaceHint":
3630
3790
  "Workspace-wide: shared across sessions, resets on the local day",
3631
3791
  "settings.budget.poolLine": "Workspace today: {calls} calls · ≈{cost}",
@@ -3656,6 +3816,20 @@ window.__ModuleLoader__.load({
3656
3816
  "settings.tracePrompt.hint":
3657
3817
  "Stores the first and last 2,000 characters of the text actually sent (after redaction) in the session record; off stores metadata only. If redaction is off, the preview contains raw text.",
3658
3818
  "settings.help.defaultPreview": "Default: head/tail preview",
3819
+ "settings.currency": "Currency",
3820
+ "settings.currency.USD": "US dollars (USD)",
3821
+ "settings.currency.CNY": "Chinese yuan (CNY)",
3822
+ "settings.currencyHint":
3823
+ "Amounts and prices are entered in this currency; switching converts them at the configured rate so the real value stays the same.",
3824
+ "settings.currency.converted": "Converted amounts at 1 USD = {rate} CNY (not saved yet).",
3825
+ "settings.usdToCny": "CNY per USD",
3826
+ "settings.usdToCnyHint":
3827
+ "1 USD = ? CNY; only used when the currency is CNY. The plugin never fetches rates; maintain it manually.",
3828
+ "settings.unit.cny": "CNY",
3829
+ "settings.unit.cnyPerMTok": "CNY / 1M tokens",
3830
+ "settings.unit.cnyPerUsd": "CNY / USD",
3831
+ "settings.budget.maxCostPerDay": "Daily budget",
3832
+ "settings.budget.workspaceMaxCostPerDay": "Workspace daily budget",
3659
3833
  "tail.trace.preview": "View sent content",
3660
3834
  "tail.trace.previewHide": "Hide sent content",
3661
3835
  "tail.trace.previewTruncated": "Sent (redacted; first/last 2,000 of {chars} chars)",
@@ -3679,7 +3853,6 @@ window.__ModuleLoader__.load({
3679
3853
  "settings.budget.maxCallsPerTurn": "Calls per turn",
3680
3854
  "settings.budget.maxCallsPerSession": "Calls per session",
3681
3855
  "settings.budget.maxCallsPerHour": "Calls per hour",
3682
- "settings.budget.maxCostPerDayUsd": "Daily budget",
3683
3856
  "settings.budget.priceInputPerMTok": "Input price",
3684
3857
  "settings.budget.priceOutputPerMTok": "Output price",
3685
3858
  "settings.scope.off": "None",
@@ -4306,6 +4479,7 @@ window.__ModuleLoader__.load({
4306
4479
  clampFloat: clampFloat,
4307
4480
  clampMoney: clampMoney,
4308
4481
  formatMoneyInput: formatMoneyInput,
4482
+ convertCurrency: convertCurrency,
4309
4483
  normalizeSettingsView: normalizeSettingsView,
4310
4484
  normalizeOptions: normalizeOptions,
4311
4485
  normalizeModels: normalizeModels,
package/lib/guard.js CHANGED
@@ -2,6 +2,8 @@
2
2
  // 纯函数守卫:预算、去重、免疫窗口、配对。不 import 宿主包,单测可直接跑。
3
3
  // 设计原则:所有判断都可以用「整数 + 时间戳」表达,不依赖会话对象的形状。
4
4
 
5
+ import { toUsd } from "./money.js";
6
+
5
7
  /** 去重指纹的默认窗口:24 小时。 */
6
8
  export const DEDUPE_WINDOW_MS = 24 * 60 * 60 * 1000;
7
9
  /** 去重表上限(有界 FIFO)。 */
@@ -111,14 +113,13 @@ export function checkBudget(input) {
111
113
  return { ok: false, code: "hour_limit", limit: settings.maxCallsPerHour, used };
112
114
  }
113
115
  }
114
- if (
115
- settings.maxCostPerDayUsd > 0 &&
116
- counters.dayCostUsd + estimatedCostUsd > settings.maxCostPerDayUsd
117
- ) {
116
+ // 设置里的限额按 settings.currency 填写;比较前先换算成 USD。
117
+ const maxCostUsd = toUsd(settings.maxCostPerDay, settings.currency, settings.usdToCny);
118
+ if (maxCostUsd > 0 && counters.dayCostUsd + estimatedCostUsd > maxCostUsd) {
118
119
  return {
119
120
  ok: false,
120
121
  code: "day_budget",
121
- limit: settings.maxCostPerDayUsd,
122
+ limit: maxCostUsd,
122
123
  used: counters.dayCostUsd,
123
124
  };
124
125
  }
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: `今日预算已用完($${budget.used.toFixed(4)}/$${budget.limit})`,
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
- : `工作区今日预算已用完($${poolCheck.used.toFixed(4)}/$${poolCheck.limit})`;
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 {
@@ -528,7 +545,15 @@ export class AdvisorService extends TypertRemoteService {
528
545
  : 0;
529
546
 
530
547
  const usageLine = call.ok
531
- ? `${formatTokens(call.usage?.inputTokens ?? 0)} in / ${formatTokens(call.usage?.outputTokens ?? 0)} out / ${formatMs(call.ms)}${costUsd > 0 ? ` / ≈$${costUsd.toFixed(4)}` : ""}`
548
+ ? `${formatTokens(call.usage?.inputTokens ?? 0)} in / ${formatTokens(call.usage?.outputTokens ?? 0)} out / ${formatMs(call.ms)}${
549
+ costUsd > 0
550
+ ? ` / ≈${formatMoney(
551
+ fromUsd(costUsd, settings.currency, settings.usdToCny),
552
+ settings.currency,
553
+ 4,
554
+ )}`
555
+ : ""
556
+ }`
532
557
  : `${formatMs(Date.now() - started)}`;
533
558
 
534
559
  const baseResult = {
@@ -1113,7 +1138,20 @@ export class AdvisorService extends TypertRemoteService {
1113
1138
  `脱敏命中:${transcript.stats.redactions.length === 0 ? "无" : transcript.stats.redactions.join(" / ")}`,
1114
1139
  `白名单:${allow.reason}`,
1115
1140
  `跨 provider:${crossProvider ? `是(需确认${confirmed ? ",已确认" : ",尚未确认 → /advisor confirm"})` : "否"}`,
1116
- `单价:${price.source === "none" ? "未配置(只记 token)" : `输入 $${price.input}/M · 输出 $${price.output}/M(${price.source === "builtin" ? "内置参考价" : "用户设置"})`}`,
1141
+ `币种:${settings.currency}${settings.currency === "CNY" ? `(1 USD = ${settings.usdToCny} CNY)` : ""}`,
1142
+ `单价:${
1143
+ price.source === "none"
1144
+ ? "未配置(只记 token)"
1145
+ : `输入 ${formatMoney(
1146
+ fromUsd(price.input, settings.currency, settings.usdToCny),
1147
+ settings.currency,
1148
+ 2,
1149
+ )}/M · 输出 ${formatMoney(
1150
+ fromUsd(price.output, settings.currency, settings.usdToCny),
1151
+ settings.currency,
1152
+ 2,
1153
+ )}/M(${price.source === "builtin" ? "内置参考价(USD 折算)" : "用户设置"})`
1154
+ }`,
1117
1155
  `工作区今日:${pool.calls} 次(上限 ${settings.workspaceMaxCallsPerDay || "∞"})`,
1118
1156
  ``,
1119
1157
  `—— 正文前 400 字符 ——`,
@@ -1362,7 +1400,9 @@ export class AdvisorService extends TypertRemoteService {
1362
1400
  maxCallsPerTurn: settings.maxCallsPerTurn,
1363
1401
  maxCallsPerSession: settings.maxCallsPerSession,
1364
1402
  maxCallsPerHour: settings.maxCallsPerHour,
1365
- maxCostPerDayUsd: settings.maxCostPerDayUsd,
1403
+ maxCostPerDay: settings.maxCostPerDay,
1404
+ currency: settings.currency,
1405
+ usdToCny: settings.usdToCny,
1366
1406
  },
1367
1407
  totals,
1368
1408
  last: this.lastResult,
@@ -1695,7 +1735,19 @@ export class AdvisorService extends TypertRemoteService {
1695
1735
  : {
1696
1736
  id: "budget",
1697
1737
  status: "warn",
1698
- message: `预算受限:${budget.code}(${budget.used}/${budget.limit})`,
1738
+ message: `预算受限:${budget.code}(${
1739
+ budget.code === "day_budget"
1740
+ ? `${formatMoney(
1741
+ fromUsd(budget.used, settings.currency, settings.usdToCny),
1742
+ settings.currency,
1743
+ 4,
1744
+ )}/${formatMoney(
1745
+ fromUsd(budget.limit, settings.currency, settings.usdToCny),
1746
+ settings.currency,
1747
+ 2,
1748
+ )}`
1749
+ : `${budget.used}/${budget.limit}`
1750
+ })`,
1699
1751
  },
1700
1752
  );
1701
1753
  }
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,7 +31,9 @@ export const DEFAULT_SETTINGS = Object.freeze({
29
31
  maxCallsPerTurn: 1,
30
32
  maxCallsPerSession: 32,
31
33
  maxCallsPerHour: 12,
32
- maxCostPerDayUsd: 0,
34
+ currency: "USD",
35
+ usdToCny: 7.2,
36
+ maxCostPerDay: 0,
33
37
  priceInputPerMTok: 0,
34
38
  priceOutputPerMTok: 0,
35
39
  privacyScope: "summary",
@@ -42,7 +46,7 @@ export const DEFAULT_SETTINGS = Object.freeze({
42
46
  confirmedHosts: Object.freeze([]),
43
47
  pairingEnforcement: "warn",
44
48
  workspaceMaxCallsPerDay: 200,
45
- workspaceMaxCostPerDayUsd: 0,
49
+ workspaceMaxCostPerDay: 0,
46
50
  postAnswer: "off",
47
51
  advisorTools: false,
48
52
  tracePrompt: "preview",
@@ -68,12 +72,15 @@ const INT_LIMITS = Object.freeze({
68
72
  * 金额不能走整数夹紧——0.5 会被取整成 1,0.15 会变成 0。
69
73
  */
70
74
  const MONEY_LIMITS = Object.freeze({
71
- maxCostPerDayUsd: { min: 0, max: 10000, digits: 2 },
72
- workspaceMaxCostPerDayUsd: { min: 0, max: 10000, digits: 2 },
75
+ maxCostPerDay: { min: 0, max: 10000, digits: 2 },
76
+ workspaceMaxCostPerDay: { min: 0, max: 10000, digits: 2 },
73
77
  priceInputPerMTok: { min: 0, max: 1000, digits: 4 },
74
78
  priceOutputPerMTok: { min: 0, max: 1000, digits: 4 },
75
79
  });
76
80
 
81
+ /** 汇率区间:1 USD = 0.1–100 CNY,保留 4 位小数。 */
82
+ const RATE_LIMIT = Object.freeze({ min: 0.1, max: 100, digits: 4 });
83
+
77
84
  /** 字符串字段的最大长度,防止有人在设置里塞进一整段提示词。 */
78
85
  const MAX_STRING = 300;
79
86
 
@@ -180,6 +187,19 @@ export function normalizeSettings(raw) {
180
187
  /** @type {any} */
181
188
  const out = { ...DEFAULT_SETTINGS };
182
189
 
190
+ out.currency = normalizeCurrency(input.currency);
191
+ const rawRate = Number(input.usdToCny);
192
+ out.usdToCny =
193
+ Number.isFinite(rawRate) && rawRate > 0
194
+ ? clampMoney(
195
+ rawRate,
196
+ DEFAULT_SETTINGS.usdToCny,
197
+ RATE_LIMIT.min,
198
+ RATE_LIMIT.max,
199
+ RATE_LIMIT.digits,
200
+ )
201
+ : DEFAULT_SETTINGS.usdToCny;
202
+
183
203
  if (typeof input.mode === "string" && MODES.includes(input.mode)) out.mode = input.mode;
184
204
 
185
205
  for (const key of ["provider", "model", "reasoningEffort"]) {
@@ -207,9 +227,26 @@ export function normalizeSettings(raw) {
207
227
  out[key] = clampInt(input[key], DEFAULT_SETTINGS[key], min, max);
208
228
  }
209
229
  for (const key of /** @type {(keyof typeof MONEY_LIMITS)[]} */ (Object.keys(MONEY_LIMITS))) {
230
+ if (key === "maxCostPerDay" || key === "workspaceMaxCostPerDay") continue;
210
231
  const spec = MONEY_LIMITS[key];
211
232
  out[key] = clampMoney(input[key], DEFAULT_SETTINGS[key], spec.min, spec.max, spec.digits);
212
233
  }
234
+ // 旧版 *Usd 键按 USD 迁移到当前币种;新键存在时优先。
235
+ /** @type {Array<[keyof typeof MONEY_LIMITS, string]>} */
236
+ const MIGRATE_MONEY = [
237
+ ["maxCostPerDay", "maxCostPerDayUsd"],
238
+ ["workspaceMaxCostPerDay", "workspaceMaxCostPerDayUsd"],
239
+ ];
240
+ for (const [key, oldKey] of MIGRATE_MONEY) {
241
+ const spec = MONEY_LIMITS[key];
242
+ const raw =
243
+ input[key] !== undefined
244
+ ? input[key]
245
+ : input[oldKey] === undefined
246
+ ? undefined
247
+ : fromUsd(Number(input[oldKey]) || 0, out.currency, out.usdToCny);
248
+ out[key] = clampMoney(raw, DEFAULT_SETTINGS[key], spec.min, spec.max, spec.digits);
249
+ }
213
250
  out.temperature = nullableNumber(input.temperature, 0, 2);
214
251
  out.tiers = normalizeTiers(input.tiers);
215
252
  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. Finer limits are under Advanced.",
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,18 @@
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"
219
229
  }
220
230
  }
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,18 @@
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"
219
229
  }
220
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangyishuai/dsh-advisor",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Pair the main model with a stronger advisor model it consults at key moments: autonomous second opinion, cost ledger, and model picker",
5
5
  "keywords": [
6
6
  "dsh",