@waterplus-ai/waterbuddy 0.1.36 → 0.1.38

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.
@@ -507,8 +507,11 @@ window.__ModuleLoader__.load({
507
507
  const logout = async () => { await fetch('/api/waterbuddy/logout', { method: 'POST' }); setUser(null); setOpen(false); setSession({ qrCode: '', status: '', error: '', loading: false }) }
508
508
  const name = userName(user)
509
509
  const buttonStyle = { borderRadius: 10, padding: '9px 18px', fontSize: 13, fontWeight: 600, cursor: 'pointer' }
510
- // 余额单位是 sub2api 的美元,不是人民币(见 SUB2API-TOKEN-QUOTA-PLAN §2)。
511
- const balanceText = `$${Number(llm?.balance || 0).toFixed(2)}`
510
+ // 额度以美元记账、按人民币向用户展示;折算与格式化都在 Host 侧完成
511
+ // (见 formatBalanceText),客户端只渲染文本,不自己拿汇率算。
512
+ const balanceText = typeof llm?.balanceText === 'string' && llm.balanceText
513
+ ? llm.balanceText
514
+ : `$${Number(llm?.balance || 0).toFixed(2)}`
512
515
  // 用户把默认模型换成别人的提供方时,消耗的不是我们的额度,一律不展示额度。
513
516
  const managesQuota = llm?.managesQuota === true
514
517
  const exhausted = managesQuota && llm?.exhausted === true
package/lib/host/index.js CHANGED
@@ -3,7 +3,7 @@ import fs from 'node:fs'
3
3
  import os from 'node:os'
4
4
  import path from 'node:path'
5
5
  import { WATERPLUS_PERSONA } from '../shared/persona.js'
6
- import { bindLlmCredential, describeLlmCredential, ensureLlmCredential, isGatewayActive, readActiveProvider, refreshLlmQuota, restoreDeviceLlmCredential, switchDefaultProviderWithRetry } from './llm-gateway.js'
6
+ import { bindLlmCredential, describeLlmCredential, ensureLlmCredential, formatBalanceText, isGatewayActive, readActiveProvider, refreshLlmQuota, restoreDeviceLlmCredential, switchDefaultProviderWithRetry } from './llm-gateway.js'
7
7
 
8
8
  const WATERPLUS_ICON = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=', 'base64')
9
9
  const CLIENT_ID = '2CC7F925-07AE-4AB9-9F17-75B7378D5890'
@@ -411,10 +411,12 @@ export function apply(ctx, config) {
411
411
  }
412
412
  // 用别人的模型时额度不归我们管,客户端据此隐藏额度展示。
413
413
  const activeProvider = readActiveProvider(ctx)
414
+ const managesQuota = isGatewayActive(ctx)
415
+ // balanceText 是折算后的人民币展示文本;balance 仍是美元,客户端不要自行换算。
414
416
  json(res, 200, {
415
417
  llm: llmStatus
416
- ? { ...llmStatus, activeProvider, managesQuota: isGatewayActive(ctx) }
417
- : { activeProvider, managesQuota: isGatewayActive(ctx) },
418
+ ? { ...llmStatus, activeProvider, managesQuota, balanceText: formatBalanceText(llmStatus.balance, config) }
419
+ : { activeProvider, managesQuota, balanceText: formatBalanceText(0, config) },
418
420
  })
419
421
  } },
420
422
  { kind: 'exact', path: '/api/waterbuddy/llm/refresh', handler: async (req, res) => { if (req.method !== 'POST') return json(res, 405, { error: 'method-not-allowed' }); try { json(res, 200, { llm: await bootstrapLlmCredential(ctx, config) }) } catch (error) { json(res, 502, { error: error.message }) } } },
@@ -24,6 +24,29 @@ export const DEFAULT_LLM_GATEWAY_MODEL = 'deepseek-flash'
24
24
  /** 未登录设备的额度用尽后由客户端引导登录(见 P3)。 */
25
25
  export const LOW_BALANCE_HINT = 0
26
26
 
27
+ /**
28
+ * 额度以美元记账(sub2api 的 `user.balance` 单位,见 SUB2API-TOKEN-QUOTA-PLAN §19.1),
29
+ * 但产品按人民币向用户交代额度,所以**只折算展示文本**:`balance` 字段保持美元,
30
+ * `lowBalance` / `exhausted` 的阈值比较依赖美元口径,不能被折算污染。
31
+ *
32
+ * 默认汇率取 DeepSeek 官方两套价目表的隐含汇率(Flash $0.15↔¥1 = 6.67;
33
+ * V4-Pro $0.66↔¥4.5 = 6.82)。改价或改用别的汇率只动插件 config,不改代码。
34
+ */
35
+ export const DEFAULT_USD_TO_CNY_RATE = 6.8
36
+
37
+ /** 展示汇率:插件 config 优先,缺失或非法时回落默认值。 */
38
+ export function resolveUsdToCnyRate(config) {
39
+ const rate = Number(config?.balanceUsdToCnyRate)
40
+ return Number.isFinite(rate) && rate > 0 ? rate : DEFAULT_USD_TO_CNY_RATE
41
+ }
42
+
43
+ /** 把美元余额折算成人民币展示文本。只用于展示,不参与任何计费或阈值判断。 */
44
+ export function formatBalanceText(balanceUsd, config) {
45
+ const amount = Number(balanceUsd)
46
+ const usd = Number.isFinite(amount) ? amount : 0
47
+ return `¥${(usd * resolveUsdToCnyRate(config)).toFixed(2)}`
48
+ }
49
+
27
50
  const DEVICE_ID_PATTERN = /^[A-Za-z0-9._:-]{8,128}$/
28
51
 
29
52
  let llmGatewayTransport
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@waterplus-ai/waterbuddy",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "description": "WaterBuddy branding and Web profile bundle for DeepSeek Harness",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
7
+ "packageManager": "pnpm@11.7.0",
7
8
  "main": "lib/host/index.js",
8
9
  "exports": {
9
10
  ".": "./lib/host/index.js",
@@ -37,4 +38,4 @@
37
38
  "pack:release": "pnpm pack --pack-destination releases",
38
39
  "release:cdn": "node scripts/build-cdn-release.mjs"
39
40
  }
40
- }
41
+ }
@@ -74,6 +74,10 @@
74
74
  # 设备领 key 的平台地址;换部署只改这里,无需改代码。
75
75
  config:
76
76
  llmGatewayBaseUrl: https://ai.shuiwujia.com
77
+ # 额度以美元记账(sub2api 的 balance 单位),展示时按此汇率折算人民币。
78
+ # 默认 6.8,取自 DeepSeek 官方美元价与人民币价的隐含汇率(6.67~6.82)。
79
+ # 留空则回落同一个默认值。
80
+ balanceUsdToCnyRate: 6.8
77
81
  - id: mcp-xiaojia
78
82
  name: '@deepseek-ai/dsh-mcp-client'
79
83
  config: