@qthinker/opencode-deepseek-search 0.2.1 → 0.3.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/src/usage.ts CHANGED
@@ -6,6 +6,9 @@
6
6
  //
7
7
  // Everything here is pure; persistence is the caller's job (ctx.storage).
8
8
 
9
+ import { t } from "./i18n/index.ts"
10
+ import type { Language } from "./rpc.ts"
11
+
9
12
  export const USAGE_KEY = "usage/v1"
10
13
  export const KEEP_DAYS = 60
11
14
  export const MICRO = 1_000_000
@@ -102,31 +105,51 @@ export function formatYuan(costMicro: number): string {
102
105
  return `¥${(costMicro / MICRO).toFixed(4)}`
103
106
  }
104
107
 
105
- export function formatUsage(ledger: UsageLedger, pricePerThousand: number, mode: string, today = dayKey()): string {
108
+ export function formatUsage(
109
+ ledger: UsageLedger,
110
+ pricePerThousand: number,
111
+ mode: string,
112
+ language: Language,
113
+ today = dayKey(),
114
+ ): string {
106
115
  const month = today.slice(0, 7)
107
116
  const line = (label: string, d: UsageDay) =>
108
- `${label}: 搜索 ${d.search} · 抓取 ${d.fetch} · 未计费 ${d.empty + d.failed}(空结果 ${d.empty} / 失败 ${d.failed})· 估算 ${formatYuan(d.costMicro)}`
117
+ t(language, "usage.report.line", {
118
+ label,
119
+ search: d.search,
120
+ fetch: d.fetch,
121
+ skipped: d.empty + d.failed,
122
+ empty: d.empty,
123
+ failed: d.failed,
124
+ cost: formatYuan(d.costMicro),
125
+ })
109
126
  return [
110
- `DeepSeek 用量(本地统计,按成功请求估算;当前模式 ${mode};单价 ¥${pricePerThousand}/1000 次)`,
111
- line(`今日 ${today}`, sumDays(ledger, (k) => k === today)),
112
- line(`本月 ${month}`, sumDays(ledger, (k) => k.startsWith(month))),
113
- line("累计", sumDays(ledger, () => true)),
114
- "说明:空结果与失败请求不计费;DeepSeek 以账号侧账单为准,本统计不含其他机器或其他工具的调用。",
127
+ t(language, "usage.report.title", { mode, price: pricePerThousand }),
128
+ line(`${t(language, "usage.label.today")} ${today}`, sumDays(ledger, (k) => k === today)),
129
+ line(`${t(language, "usage.label.month")} ${month}`, sumDays(ledger, (k) => k.startsWith(month))),
130
+ line(t(language, "usage.label.total"), sumDays(ledger, () => true)),
131
+ t(language, "usage.report.note"),
115
132
  ].join("\n")
116
133
  }
117
134
 
118
135
  /**
119
136
  * Compact one-line summaries for a status display, keyed by period. Callers add
120
- * the 今日/本月/累计 labels themselves. Costs are read from the ledger, which
137
+ * the localized period label themselves. Costs are read from the ledger, which
121
138
  * already accumulated them at tally time.
122
139
  */
123
140
  export function usageSummaryLines(
124
141
  ledger: UsageLedger,
142
+ language: Language,
125
143
  today = dayKey(),
126
144
  ): { today: string; month: string; total: string } {
127
145
  const month = today.slice(0, 7)
128
146
  const line = (d: UsageDay) =>
129
- `搜索 ${d.search} · 抓取 ${d.fetch} · 空/失 ${d.empty + d.failed} · ${formatYuan(d.costMicro)}`
147
+ t(language, "usage.summary.line", {
148
+ search: d.search,
149
+ fetch: d.fetch,
150
+ skipped: d.empty + d.failed,
151
+ cost: formatYuan(d.costMicro),
152
+ })
130
153
  return {
131
154
  today: line(sumDays(ledger, (k) => k === today)),
132
155
  month: line(sumDays(ledger, (k) => k.startsWith(month))),