dsh-credit-meter 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-credit-meter contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,124 @@
1
- # Temporary Holding Version
1
+ # Credit meter
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [Chinese](README.zh.md)
4
+
5
+ ![Credit meter icon](icon.svg)
6
+
7
+ A DeepSeek Harness plugin that shows the remaining DeepSeek account credit as
8
+ one more reading in the composer dock — the row under the message input that
9
+ already carries activity, token usage, and the context meter.
10
+
11
+ ![Recording of the credit reading in the composer dock](docs/preview.gif)
12
+
13
+ ## What it shows
14
+
15
+ `Available ¥1.91` next to a small wallet glyph. Hovering the reading, or
16
+ reading it with a screen reader, lists the wallets behind that number:
17
+
18
+ ```
19
+ Account credit
20
+ Available ¥1.91
21
+ Recharge ¥1.91
22
+ ```
23
+
24
+ The labels are localized, so the reading follows the language of the UI.
25
+
26
+ ## Where it appears
27
+
28
+ One entry in the session's composer dock, after the token-usage reading and
29
+ before the context meter. The value is account-wide, so switching sessions does
30
+ not change it.
31
+
32
+ DSH does not render the dock on a blank home screen, so the reading starts with
33
+ the first message of a session.
34
+
35
+ ## When it refreshes
36
+
37
+ - When the session's billed tokens change — about two seconds after a step settles.
38
+ - Once a minute while the page is visible.
39
+ - Immediately when the window regains focus, and once on page load.
40
+
41
+ DeepSeek Platform can take a while to book a request into the balance it
42
+ reports, so a just-finished turn may still show the previous amount for up to
43
+ about a minute.
44
+
45
+ ## What the number means
46
+
47
+ Platform reports one wallet per currency and keeps recharge and bonus separate.
48
+ The reading is the spendable total of the best-funded currency:
49
+
50
+ - recharge plus bonus of that currency;
51
+ - a zero wallet in another currency never wins over a funded one;
52
+ - every other funded currency is appended, for example `Available ¥1.91 +$5.00`;
53
+ - formatting follows the Platform Web client: two decimals rounded down, and
54
+ `<¥0.01` below one cent.
55
+
56
+ The tooltip lists funded wallets only, so a bonus-only account reads
57
+ `Bonus ¥2.00` there.
58
+
59
+ ## Requirements
60
+
61
+ - DeepSeek Harness `0.2.2-rc.2` or a compatible release (`engines.dsh`).
62
+ - Signed in to a DeepSeek account in DSH.
63
+ - The Web GUI or the Desktop app.
64
+
65
+ ## Install
66
+
67
+ From a local directory (the current state of this package):
68
+
69
+ 1. Keep this directory where it is; DSH links it instead of copying it.
70
+ 2. In DSH, open **Plugins → Add plugin** and choose this directory. The agent
71
+ equivalent is `plugin_manager` with `install_bundle` and the absolute path.
72
+ 3. Refresh the page once if it was already open, then send a message.
73
+
74
+ From npm (only after this package is published; see [PUBLISHING.md](PUBLISHING.md)):
75
+
76
+ 1. **Plugins → Add plugin**, then enter `dsh-credit-meter@1.0.0`.
77
+
78
+ ## Privacy
79
+
80
+ The reading comes from the same account query Settings → Account uses
81
+ (`ctx.remote.account.getBalance`). The plugin:
82
+
83
+ - never reads, copies, or stores the account token;
84
+ - sends no data anywhere else and adds no telemetry;
85
+ - keeps the last value in memory only, and drops it when the plugin is disabled.
86
+
87
+ Disabling the plugin in **Plugins** removes the reading and stops the queries.
88
+
89
+ ## Limitations
90
+
91
+ - Display only: the reading has no click target and no top-up link.
92
+ - Refreshes on the cadence above, not continuously.
93
+ - Account-wide by design; it is not a per-session cost meter.
94
+ - A failed read keeps the last value and marks it stale in the tooltip.
95
+ - Nothing is shown before the first read completes, or while signed out.
96
+
97
+ ## Development
98
+
99
+ There is no build step. `client.js` is the browser bundle DSH loads as-is: it
100
+ registers a lazy factory through `window.__ModuleLoader__.load` and resolves
101
+ React from the shell's module table.
102
+
103
+ ```
104
+ .
105
+ ├── package.json package identity, bundle patch, client declaration
106
+ ├── cordis.patch.yml inserts the plugin row into the runtime
107
+ ├── index.js Host half (intentionally empty)
108
+ ├── client.js browser half: querying, formatting, dock entry
109
+ ├── docs/ feature preview and detail document
110
+ ├── locale/ plugin-page title and description
111
+ ├── icon.svg plugin-page icon
112
+ ├── README.md this file
113
+ ├── README.zh.md Chinese README
114
+ ├── PUBLISHING.md release checklist
115
+ └── LICENSE MIT
116
+ ```
117
+
118
+ Edit `client.js`, check it with `node --check client.js`, and refresh the page.
119
+ DSH does not hot-replace the code of a package that is already running, so a
120
+ reload is required for a change to take effect.
121
+
122
+ ## License
123
+
124
+ [MIT](LICENSE)
package/README.zh.md ADDED
@@ -0,0 +1,110 @@
1
+ # Credit meter(账户额度读数)
2
+
3
+ [English](README.md) | 中文
4
+
5
+ ![Credit meter 图标](icon.svg)
6
+
7
+ 一个 DeepSeek Harness 插件:把 DeepSeek 账户剩余额度显示在输入框下方那行读数里。
8
+ 那一行原本就有活动统计、token 用量和上下文占用。
9
+
10
+ ![额度读数录屏](docs/preview.gif)
11
+
12
+ ## 显示什么
13
+
14
+ 钱包图标旁边是 `可用余额 ¥1.91`。鼠标悬停(或读屏软件读取)会列出这个数字背后的钱包:
15
+
16
+ ```
17
+ 账户额度
18
+ 可用余额 ¥1.91
19
+ 充值 ¥1.91
20
+ ```
21
+
22
+ 英文界面显示为 `Available ¥1.91`。
23
+
24
+ ## 出现在哪里
25
+
26
+ 会话输入框下方读数行里的一项,排在 token 用量之后、上下文占用之前。这个数值属于整个账户,
27
+ 所以切换会话不会改变它。
28
+
29
+ DSH 的空白首页不渲染这行读数,因此它从会话的第一条消息开始出现。
30
+
31
+ ## 什么时候刷新
32
+
33
+ - 本会话的计费 token 变化时——一步结束后大约 2 秒。
34
+ - 页面可见时,每分钟一次。
35
+ - 窗口重新获得焦点时立刻一次,页面加载时一次。
36
+
37
+ DeepSeek 平台把一次请求记进余额需要时间,所以刚结束的一轮可能还会显示旧金额,最长约一分钟。
38
+
39
+ ## 数字的含义
40
+
41
+ 平台按币种分别返回钱包,充值和赠送分开记。读数取"最有钱的那个币种"的可花总额:
42
+
43
+ - 该币种的充值 + 赠送;
44
+ - 另一个币种金额为 0 时,不会盖过有余额的币种;
45
+ - 其他有余额的币种会追加在后面,例如 `可用余额 ¥1.91 +$5.00`;
46
+ - 格式与 Platform 网页端一致:两位小数向下取整,不足一分显示 `<¥0.01`。
47
+
48
+ 悬停提示只列有余额的钱包,所以只有赠送额度时那里显示 `赠送 ¥2.00`。
49
+
50
+ ## 运行要求
51
+
52
+ - DeepSeek Harness `0.2.2-rc.2` 或兼容版本(见 `engines.dsh`)。
53
+ - 在 DSH 中已登录 DeepSeek 账户。
54
+ - Web 界面或桌面端。
55
+
56
+ ## 安装
57
+
58
+ 从本地目录安装(当前这个包的状态):
59
+
60
+ 1. 把这个目录留在原处;DSH 是链接它,而不是复制。
61
+ 2. 在 DSH 里打开 **Plugins(插件)→ Add plugin(添加插件)**,选择这个目录。
62
+ 用 Agent 的等价做法是 `plugin_manager` 的 `install_bundle`,参数为绝对路径。
63
+ 3. 如果页面本来开着,先刷新一次,然后发一条消息。
64
+
65
+ 从 npm 安装(需要这个包已经发布,见 [PUBLISHING.md](PUBLISHING.md)):
66
+
67
+ 1. **Plugins → Add plugin**,输入 `dsh-credit-meter@1.0.0`。
68
+
69
+ ## 隐私
70
+
71
+ 读数和设置页的账户余额来自同一个查询(`ctx.remote.account.getBalance`)。本插件:
72
+
73
+ - 从不读取、复制或保存账户凭据(token);
74
+ - 不向其他地方发送数据,也不加任何遥测;
75
+ - 只在内存里保留最近一次数值,插件被禁用时即丢弃。
76
+
77
+ 在 **Plugins** 里关掉插件,读数和余额请求都会停止。
78
+
79
+ ## 已知限制
80
+
81
+ - 只做展示:读数不能点击,也没有充值链接。
82
+ - 按上面的节奏刷新,不是连续实时。
83
+ - 按设计属于整个账户,不是"本会话花了多少"的计量器。
84
+ - 读取失败时保留上一个数值,并在悬停提示里标注可能过期。
85
+ - 首次读取完成前、未登录时不显示。
86
+
87
+ ## 开发
88
+
89
+ 没有构建步骤。`client.js` 就是 DSH 直接加载的浏览器包:它通过
90
+ `window.__ModuleLoader__.load` 登记一个惰性工厂,并从外壳的模块表里取 React。
91
+
92
+ ```
93
+ .
94
+ ├── package.json 包身份、bundle patch、client 声明
95
+ ├── cordis.patch.yml 把插件行插入运行时
96
+ ├── index.js Host 半(有意为空)
97
+ ├── client.js 浏览器半:取数、格式化、dock 条目
98
+ ├── docs/ 效果图与插件详情文档
99
+ ├── locale/ 插件页的标题与描述
100
+ ├── icon.svg 插件页图标
101
+ ├── README.md 英文 README
102
+ └── README.zh.md 本文件
103
+ ```
104
+
105
+ 改完 `client.js` 用 `node --check client.js` 检查,然后刷新页面。
106
+ DSH 不会热替换已经在运行的包代码,所以必须重载页面才会生效。
107
+
108
+ ## 许可证
109
+
110
+ [MIT](LICENSE)
package/client.js ADDED
@@ -0,0 +1,360 @@
1
+ /**
2
+ * DeepSeek account credit in the composer dock.
3
+ *
4
+ * The reading is the account Remote's balance query. It re-reads when the
5
+ * session's billed tokens change (so a finished turn shows the new amount
6
+ * without waiting for the timer), every minute while the page is visible, on
7
+ * window focus, and once on load. It is account-wide, not session-wide: every
8
+ * dock entry subscribes to one module-level store, so switching sessions
9
+ * neither re-reads nor remounts the reading.
10
+ */
11
+ window.__ModuleLoader__.load({
12
+ id: 'dsh-credit-meter',
13
+ factory(require) {
14
+ const React = require('react')
15
+ const h = React.createElement
16
+
17
+ /** Dictionary namespace owned by this plugin. */
18
+ const NS = 'creditMeter'
19
+ /** Balance refresh period; a settled turn also re-reads immediately. */
20
+ const POLL_INTERVAL_MS = 60_000
21
+ /** Bursts of usage changes (one per step) coalesce into one delayed read. */
22
+ const SETTLE_DELAY_MS = 2_000
23
+
24
+ const en = {
25
+ title: 'Account credit',
26
+ balance: 'Available',
27
+ recharge: 'Recharge',
28
+ bonus: 'Bonus',
29
+ stale: 'The last read failed, so this value may be out of date',
30
+ }
31
+ const zh = {
32
+ title: '账户额度',
33
+ balance: '可用余额',
34
+ recharge: '充值',
35
+ bonus: '赠送',
36
+ stale: '上次读取失败,该数值可能已过期',
37
+ }
38
+
39
+ const CURRENCY_SYMBOLS = { CNY: '¥', USD: '$' }
40
+
41
+ /**
42
+ * Format one amount the way Platform's own Web client does: two decimals
43
+ * rounded down, sub-cent amounts as `<symbol>0.01`, grouped digits.
44
+ * @param value - finite amount.
45
+ * @param currency - wallet currency code.
46
+ * @returns display text, or null when the amount is not finite.
47
+ */
48
+ function formatBalance(value, currency) {
49
+ const symbol = CURRENCY_SYMBOLS[currency] ?? `${currency} `
50
+ if (!Number.isFinite(value)) return null
51
+ const magnitude = Math.abs(value)
52
+ if (magnitude === 0) return `${symbol}0.00`
53
+ if (magnitude < 0.01) return `${value < 0 ? '-' : '<'}${symbol}0.01`
54
+ const [integer, fraction] = (Math.floor(magnitude * 100) / 100).toFixed(2).split('.')
55
+ return `${value < 0 ? '-' : ''}${symbol}${Number(integer).toLocaleString()}.${fraction}`
56
+ }
57
+
58
+ /**
59
+ * Format one wallet entry, tolerating a malformed amount.
60
+ * @param wallet - one wallet entry from the balance response.
61
+ * @returns display text, or null.
62
+ */
63
+ function formatWallet(wallet) {
64
+ return formatBalance(Number(wallet.balance), wallet.currency)
65
+ }
66
+
67
+ /** An amount worth naming: at least one cent in either direction. */
68
+ const isMeaningful = (value) => Math.abs(value) >= 0.01
69
+
70
+ /**
71
+ * Reduce one balance response to the resting reading and its detail lines.
72
+ * Platform reports one wallet per currency and keeps recharge and bonus
73
+ * separate, so the reading is the spendable total of the best-funded
74
+ * currency — a zero wallet of another currency must not win.
75
+ * @param state - store state.
76
+ * @param t - this plugin's translate function.
77
+ * @returns the reading, or null when no wallet carries a number.
78
+ */
79
+ function summarize(state, t) {
80
+ const wallets = [...state.wallets, ...state.bonusWallets]
81
+ const totals = new Map()
82
+ for (const wallet of wallets) {
83
+ const amount = Number(wallet.balance)
84
+ if (!Number.isFinite(amount)) continue
85
+ totals.set(wallet.currency, (totals.get(wallet.currency) ?? 0) + amount)
86
+ }
87
+ const ranked = [...totals.entries()].sort((left, right) => Math.abs(right[1]) - Math.abs(left[1]))
88
+ if (ranked.length === 0) return null
89
+ const [primaryCurrency, primaryTotal] = ranked[0]
90
+ const main = formatBalance(primaryTotal, primaryCurrency)
91
+ if (main === null) return null
92
+ // A second funded currency stays visible instead of hiding behind the first.
93
+ const extras = ranked.slice(1)
94
+ .filter(([, total]) => isMeaningful(total))
95
+ .map(([currency, total]) => formatBalance(total, currency))
96
+ .filter(text => text !== null)
97
+ .map(text => `+${text}`)
98
+ const reading = [main, ...extras].join(' ')
99
+ const lines = [t('title'), `${t('balance')} ${reading}`]
100
+ // Zero wallets stay out of the breakdown while another wallet carries money.
101
+ const funded = wallets.some(wallet => isMeaningful(Number(wallet.balance)))
102
+ for (const [group, key] of [[state.wallets, 'recharge'], [state.bonusWallets, 'bonus']]) {
103
+ for (const wallet of group) {
104
+ if (funded && !isMeaningful(Number(wallet.balance))) continue
105
+ const text = formatWallet(wallet)
106
+ if (text !== null) lines.push(`${t(key)} ${text}`)
107
+ }
108
+ }
109
+ if (state.stale) lines.push(t('stale'))
110
+ return { label: `${t('balance')} ${reading}`, lines }
111
+ }
112
+
113
+ /**
114
+ * One account-wide balance store shared by every dock entry. Subscribers wake
115
+ * only when the displayed amounts, the staleness, or the phase change; a
116
+ * failed read keeps the last good reading and marks it stale.
117
+ * @returns the store.
118
+ */
119
+ function createStore() {
120
+ let state = { phase: 'idle', key: '', wallets: [], bonusWallets: [], stale: false }
121
+ const listeners = new Set()
122
+ const keyOf = (value) => [
123
+ value.phase,
124
+ value.stale ? 'stale' : 'fresh',
125
+ value.wallets.map(wallet => `${wallet.currency}=${wallet.balance}`).join(','),
126
+ value.bonusWallets.map(wallet => `${wallet.currency}=${wallet.balance}`).join(','),
127
+ ].join('|')
128
+ const publish = (next) => {
129
+ const resolved = next.phase === 'ready'
130
+ ? next
131
+ : { phase: next.phase, wallets: [], bonusWallets: [], stale: false }
132
+ const key = keyOf(resolved)
133
+ if (key === state.key) return
134
+ state = { ...resolved, key }
135
+ for (const listener of Array.from(listeners)) listener()
136
+ }
137
+ return {
138
+ getSnapshot: () => state,
139
+ subscribe: (listener) => {
140
+ listeners.add(listener)
141
+ return () => { listeners.delete(listener) }
142
+ },
143
+ ready(wallets, bonusWallets) {
144
+ publish({ phase: 'ready', wallets, bonusWallets, stale: false })
145
+ },
146
+ // A cleared grant is definitive; a failed read is not.
147
+ signedOut() {
148
+ publish({ phase: 'signed-out', wallets: [], bonusWallets: [] })
149
+ },
150
+ failed() {
151
+ if (state.phase === 'ready') {
152
+ publish({ phase: 'ready', wallets: state.wallets, bonusWallets: state.bonusWallets, stale: true })
153
+ return
154
+ }
155
+ publish({ phase: 'failed', wallets: [], bonusWallets: [] })
156
+ },
157
+ /** Replaced by the poller; a settled turn calls it to re-read early. */
158
+ requestRefresh() {},
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Build the Platform request identity for one account call.
164
+ * @param ctx - client context.
165
+ * @returns the metadata the account Remote expects.
166
+ */
167
+ function readClientMetadata(ctx) {
168
+ const locale = ctx.locale.getSnapshot().active
169
+ const accountUi = ctx.get('accountUi')
170
+ if (accountUi !== undefined && typeof accountUi.clientMetadata === 'function') {
171
+ try { return accountUi.clientMetadata(locale) } catch (_error) { /* use the local identity */ }
172
+ }
173
+ const env = typeof process === 'undefined' ? {} : (process.env ?? {})
174
+ return {
175
+ version: env.DSH_CLIENT_VERSION ?? 'unknown',
176
+ locale,
177
+ // Date.getTimezoneOffset reports minutes west of UTC; Platform wants seconds east.
178
+ timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Read the account balance now and keep reading it while the page is visible.
184
+ * @param ctx - client context.
185
+ * @param store - the account-wide balance store.
186
+ * @returns the polling disposer.
187
+ */
188
+ function startPolling(ctx, store) {
189
+ const account = ctx.remote.account
190
+ let stopped = false
191
+ let inFlight = false
192
+ let retries = 0
193
+ let scheduled
194
+ const retryTimers = new Set()
195
+ const refresh = async () => {
196
+ if (stopped || inFlight) return
197
+ inFlight = true
198
+ try {
199
+ const result = await account.getBalance(readClientMetadata(ctx))
200
+ if (stopped) return
201
+ if (result === null || result === undefined || result.ok !== true) {
202
+ store.failed()
203
+ retrySoon()
204
+ return
205
+ }
206
+ const details = result.value
207
+ // A null outcome means no stored grant, so there is nothing to show.
208
+ if (details === null || details === undefined) { store.signedOut(); return }
209
+ if (details.status !== 'ready') { store.failed(); retrySoon(); return }
210
+ retries = 0
211
+ store.ready(details.value ?? [], details.bonusWallets ?? [])
212
+ } catch (_error) {
213
+ if (stopped) return
214
+ store.failed()
215
+ retrySoon()
216
+ } finally {
217
+ inFlight = false
218
+ }
219
+ }
220
+ // The first read can race the account plugin's registration; a few short
221
+ // retries settle it without waiting for the next poll period.
222
+ function retrySoon() {
223
+ if (stopped || retries >= 3 || store.getSnapshot().phase === 'ready') return
224
+ retries += 1
225
+ const handle = setTimeout(() => {
226
+ retryTimers.delete(handle)
227
+ void refresh()
228
+ }, 4_000 * retries)
229
+ retryTimers.add(handle)
230
+ }
231
+ const timer = setInterval(() => {
232
+ if (document.visibilityState !== 'hidden') void refresh()
233
+ }, POLL_INTERVAL_MS)
234
+ const onFocus = () => { void refresh() }
235
+ const onVisibility = () => {
236
+ if (document.visibilityState === 'visible') void refresh()
237
+ }
238
+ window.addEventListener('focus', onFocus)
239
+ document.addEventListener('visibilitychange', onVisibility)
240
+ store.requestRefresh = () => {
241
+ if (stopped || scheduled !== undefined) return
242
+ scheduled = setTimeout(() => {
243
+ scheduled = undefined
244
+ void refresh()
245
+ }, SETTLE_DELAY_MS)
246
+ }
247
+ void refresh()
248
+ return () => {
249
+ stopped = true
250
+ clearInterval(timer)
251
+ if (scheduled !== undefined) clearTimeout(scheduled)
252
+ for (const handle of retryTimers) clearTimeout(handle)
253
+ retryTimers.clear()
254
+ window.removeEventListener('focus', onFocus)
255
+ document.removeEventListener('visibilitychange', onVisibility)
256
+ }
257
+ }
258
+
259
+ /** `useSyncExternalStore` with a subscription fallback for older React builds. */
260
+ const useStore = React.useSyncExternalStore ?? function useStoreFallback(subscribe, getSnapshot) {
261
+ const [value, setValue] = React.useState(getSnapshot)
262
+ React.useEffect(() => subscribe(() => { setValue(getSnapshot()) }), [subscribe, getSnapshot])
263
+ return value
264
+ }
265
+
266
+ /** Projection read used when the dock does not hand one over. */
267
+ const noProjection = () => undefined
268
+
269
+ /** Wallet glyph drawn in the current text color so it follows the theme. */
270
+ const WALLET_GLYPH = h(
271
+ 'svg',
272
+ {
273
+ width: 14, height: 14, viewBox: '0 0 16 16', fill: 'none',
274
+ 'aria-hidden': true, focusable: 'false', style: { flex: 'none' },
275
+ },
276
+ h('path', {
277
+ d: 'M2.4 4.2c0-.61.49-1.1 1.1-1.1h7.2',
278
+ stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round',
279
+ }),
280
+ h('rect', {
281
+ x: 2.4, y: 4.6, width: 11.2, height: 7.2, rx: 1.6,
282
+ stroke: 'currentColor', strokeWidth: 1.4,
283
+ }),
284
+ h('circle', { cx: 10.4, cy: 8.2, r: 0.9, fill: 'currentColor' }),
285
+ )
286
+
287
+ /** Resting reading style: the composer dock's own reading metrics. */
288
+ const READING_STYLE = {
289
+ display: 'inline-flex',
290
+ alignItems: 'center',
291
+ gap: '6px',
292
+ boxSizing: 'border-box',
293
+ minWidth: 0,
294
+ maxWidth: '100%',
295
+ padding: '1px 8px',
296
+ borderRadius: 'var(--dsw-radius-sm)',
297
+ color: 'var(--dsw-alias-label-tertiary)',
298
+ fontSize: 'calc(var(--dsh-content-font-size-secondary, 13px) - 1px)',
299
+ lineHeight: 'calc(20px + var(--dsh-content-font-delta-secondary, 0px))',
300
+ fontVariantNumeric: 'tabular-nums',
301
+ whiteSpace: 'nowrap',
302
+ }
303
+
304
+ /**
305
+ * The dock reading: a wallet glyph, the balance word, and the spendable
306
+ * amount. The billed-token projection re-reads the balance when a turn
307
+ * settles; the full wallet breakdown is in the tooltip and the accessible name.
308
+ * @param props - the dock entry's runtime props, locale seat, and this
309
+ * plugin's own translator.
310
+ * @returns the reading, or nothing while signed out or before the first read.
311
+ */
312
+ function CreditPill(props) {
313
+ const state = useStore(store.subscribe, store.getSnapshot)
314
+ const useProjection = props.useProjection ?? noProjection
315
+ const usage = useProjection('tokenUsage')
316
+ const billed = usage === undefined || usage === null
317
+ ? undefined
318
+ : usage.uncachedInputTokens + usage.cacheReadTokens + usage.cacheWriteTokens + usage.outputTokens
319
+ React.useEffect(() => {
320
+ if (billed === undefined) return
321
+ store.requestRefresh()
322
+ }, [billed])
323
+ const t = typeof props.t === 'function' ? props.t : props.translate
324
+ if (state.phase !== 'ready') return null
325
+ const reading = summarize(state, t)
326
+ if (reading === null) return null
327
+ return h(
328
+ 'span',
329
+ {
330
+ className: 'credit-meter',
331
+ title: reading.lines.join('\n'),
332
+ 'aria-label': reading.lines.join(' · '),
333
+ 'data-credit-meter': reading.label,
334
+ style: READING_STYLE,
335
+ },
336
+ WALLET_GLYPH,
337
+ h('span', { style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' } }, reading.label),
338
+ )
339
+ }
340
+
341
+ /** One store for the whole page: the balance is account-wide, not session-wide. */
342
+ const store = createStore()
343
+
344
+ return {
345
+ inject: ['slots', 'locale', 'remote', 'remote.account'],
346
+ apply(ctx) {
347
+ ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'credit-meter: dictionaries')
348
+ const translate = ctx.locale.bind(NS)
349
+ ctx.effect(() => startPolling(ctx, store), 'credit-meter: balance polling')
350
+ const Pill = (props) => h(CreditPill, { ...props, translate })
351
+ ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({
352
+ name: 'conversation.composer.dock',
353
+ id: 'credit-meter',
354
+ order: 2,
355
+ locale: NS,
356
+ }, Pill))
357
+ },
358
+ }
359
+ },
360
+ })
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: credit-meter
3
+ name: 'dsh-credit-meter'
package/docs/DETAIL.md ADDED
@@ -0,0 +1 @@
1
+ ![Recording: the credit reading in the row under the message composer, and the hover tooltip listing the recharge balance](preview.gif)
@@ -0,0 +1 @@
1
+ ![录屏:输入框下方的额度读数,以及悬停时列出的充值余额](preview.gif)
Binary file
package/icon.svg ADDED
@@ -0,0 +1,11 @@
1
+ <svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <defs>
3
+ <linearGradient id="credit-meter-body" x1="9.5" y1="8" x2="27" y2="25" gradientUnits="userSpaceOnUse">
4
+ <stop stop-color="#7CB7FF" />
5
+ <stop offset="1" stop-color="#4A65E8" />
6
+ </linearGradient>
7
+ </defs>
8
+ <path d="M10.5 10.5C10.5 9.12 11.62 8 13 8H23.5" stroke="url(#credit-meter-body)" stroke-width="2.5" stroke-linecap="round" />
9
+ <rect x="9" y="10.5" width="19.5" height="15" rx="3.2" fill="url(#credit-meter-body)" fill-opacity="0.18" stroke="url(#credit-meter-body)" stroke-width="2.5" />
10
+ <circle cx="23.2" cy="18" r="1.7" fill="#4A65E8" />
11
+ </svg>
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Host half of the credit meter bundle. The reading comes from the account
3
+ * Remote namespace, so this half registers nothing; it exists because the
4
+ * bundle's patch inserts a plugin row for the package.
5
+ */
6
+ export function apply() {}
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Credit meter",
4
+ "description": "Shows the remaining DeepSeek account credit in the reading row under the composer: a wallet glyph, the word Available, and the spendable amount (recharge plus bonus of the best-funded currency; a second funded currency is appended as +$5.00). Hover it for the per-currency recharge and bonus wallets. It re-reads when a turn settles, once a minute while the window is visible, and when the window regains focus, so the amount follows what the session spends. Nothing is shown while signed out or before the first read; a failed read keeps the last value and marks it stale. The reading is account-wide, so switching sessions does not change it; a blank home screen has no reading row and shows nothing. Turning the plugin off removes the reading and its balance queries.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "额度余额",
4
+ "description": "在输入框下方的读数行显示 DeepSeek 账户剩余额度:钱包图标、\"可用余额\"与可花金额(充值 + 赠送,按币种分开,取金额最高的币种;另一种币种有钱时以 +$5.00 形式补在后面),悬停可查看各币种的充值余额与赠送余额分项。会话一轮结束时、窗口可见期间每分钟、以及窗口重新获得焦点时都会重读,因此数值会跟随本会话的花费变化。未登录或首次读取完成前不显示;读取失败时保留上一次数值并标记为可能过期。该读数属于整个账户,切换会话不会改变;空白首页没有读数行,因此不显示。关闭插件会移除该读数及其余额请求。",
5
+ "detail": "docs/DETAIL.zh.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "dsh-credit-meter",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Remaining DeepSeek account credit as a composer-dock reading",
5
+ "license": "MIT",
6
+ "author": "dsh-credit-meter contributors",
7
+ "keywords": [
8
+ "dsh",
9
+ "dsh-plugin",
10
+ "deepseek",
11
+ "deepseek-harness",
12
+ "credit",
13
+ "balance"
14
+ ],
15
+ "type": "module",
16
+ "engines": {
17
+ "dsh": "^0.2.2-rc.2"
18
+ },
19
+ "exports": {
20
+ ".": "./index.js",
21
+ "./client": "./client.js",
22
+ "./locale/*.json": "./locale/*.json",
23
+ "./icon": "./icon.svg"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "client.js",
28
+ "cordis.patch.yml",
29
+ "locale/*.json",
30
+ "icon.svg",
31
+ "docs",
32
+ "README.md",
33
+ "README.zh.md",
34
+ "LICENSE"
35
+ ],
36
+ "dsh": {
37
+ "manifestVersion": 1,
38
+ "bundle": {
39
+ "patch": "./cordis.patch.yml"
40
+ },
41
+ "client": {
42
+ "platform": "web",
43
+ "immediately": true,
44
+ "inject": [
45
+ "@deepseek-ai/dsh-client-ui-conversation"
46
+ ]
47
+ }
48
+ }
49
+ }