dsh-plugin-greeting-bubble 1.1.0 → 1.2.1

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
@@ -29,6 +29,8 @@
29
29
  ## 效果
30
30
 
31
31
  - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 你好,腾盛 ×
32
+ - **第二行显示账号余额**:`余额 ¥12.34(赠送 ¥3.00)`,来自当前登录的 DeepSeek 账号(充值 + 赠送钱包);每 60 秒刷新一次,**点余额这一行可立即刷新**。
33
+ - 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
32
34
  - 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
33
35
  - **按住气泡可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
34
36
  - 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。气泡本体需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
@@ -85,8 +87,9 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
85
87
 
86
88
  | 操作 | 结果 |
87
89
  | --- | --- |
88
- | 页面加载 | 气泡出现(每个页面视图一次) |
90
+ | 页面加载 | 气泡出现(每个页面视图一次),并读取一次余额 |
89
91
  | **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
92
+ | **点余额那一行** | 立即刷新余额(不用等 60 秒) |
90
93
  | 点 ×(或聚焦后按 Enter / Space) | 本次页面隐藏气泡 |
91
94
  | 刷新页面 | 气泡再次出现,位置保持上次拖到的位置 |
92
95
  | 插件页关闭该包的开关 | 气泡立即消失(HMR 生效时无需刷新) |
@@ -132,7 +135,21 @@ localStorage.removeItem('dsh-greeting-bubble:position:v1')
132
135
  - 底/字色:`--dsw-alias-bg-layer-3`、`--dsw-alias-label-primary`,自动跟随亮/暗主题;
133
136
  - 尺寸与字号:`.dsh-greeting-bubble` 的 `font-size`、`gap`、`padding`。
134
137
 
135
- ### 4. 改成“只问候一次”(可选)
138
+ ### 4. 改余额刷新频率
139
+
140
+ `client.js` 顶部:
141
+
142
+ ```js
143
+ const BALANCE_REFRESH_MS = 60_000; // 正常刷新间隔
144
+ const BALANCE_MAX_BACKOFF_MS = 300_000; // 连续失败后的最大退避
145
+ ```
146
+
147
+ - 只在页面可见时刷新,切到后台暂停;
148
+ - 失败会退避(60s → 120s → 240s → 300s),成功后恢复 60s;
149
+ - 点击余额那一行会立即刷新并重置退避;
150
+ - 不建议改到 30 秒以下:余额接口是账号接口,不适合高频轮询。
151
+
152
+ ### 5. 改成“只问候一次”(可选)
136
153
 
137
154
  默认每次页面加载都会出现。如果希望用户关闭后永久不再出现,在组件里加一个 `localStorage` 开关,例如:
138
155
 
@@ -153,7 +170,7 @@ function GreetingBubble({ t }) {
153
170
 
154
171
  清除 `localStorage` 里这个键即可让问候重新出现。
155
172
 
156
- ### 5. 改图标、名称、描述
173
+ ### 6. 改图标、名称、描述
157
174
 
158
175
  - 图标:`icon.svg`(36×36,纯几何、无文字);
159
176
  - 插件页显示的名称与说明:`locale/zh.json`、`locale/en.json` 的 `meta.title` / `meta.description`;
@@ -193,6 +210,7 @@ package.json
193
210
  7. **样式走主题变量**:气泡用 `--dsw-alias-bg-layer-3`、`--dsw-alias-border-l3`、`--dsw-alias-label-primary`、`--dsw-alias-interactive-bg-hover` 等 token,亮/暗主题自动切换;组件内的 `<style>` 随组件卸载一起移除。
194
211
  8. **文案走 locale**:`locale: NS` 让框架把 `t` 注入组件,切换界面语言时文案实时更新,无需重载。
195
212
  9. **Host 端为空**:`index.js` 只导出 `export function apply() {}`。插件不注册工具、不发请求、不写会话日志,因此对模型和会话完全透明。
213
+ 10. **余额走账号 Remote**:`ctx.remote.account.getBalance(...)` 由 Host 用本地登录凭据请求 Platform,浏览器只拿到脱敏后的钱包金额;账号令牌永远不进浏览器。未登录(返回 null)或请求失败时显示 `--`。
196
214
 
197
215
  ## 文件结构
198
216
 
@@ -209,6 +227,7 @@ dsh-plugin-greeting-bubble/
209
227
  ├─ docs/
210
228
  │ ├─ DETAIL.md # 英文详情页文档(只含一张特性图)
211
229
  │ ├─ DETAIL.zh.md # 中文详情页文档(同一张图,中文替代文本)
230
+ │ ├─ DEV.md # 维护者开发/发布/排错指南
212
231
  │ └─ preview.svg # 特性图(640×300,无文字)
213
232
  ├─ test/
214
233
  │ └─ smoke.mjs # 离线冒烟测试(不随包发布)
@@ -220,6 +239,8 @@ dsh-plugin-greeting-bubble/
220
239
 
221
240
  ## 本地开发与测试
222
241
 
242
+ 维护者请先看 **[docs/DEV.md](docs/DEV.md)**:里面记录了完整的开发、测试、Git 与 npm 发布流程,以及我们实际踩过的坑(模块缓存、安装残留、2FA、观察期、GitHub DNS 等)。
243
+
223
244
  ```powershell
224
245
  # 1. 语法检查(需要 Node.js 18+)
225
246
  node --check index.js
@@ -249,17 +270,20 @@ node test/smoke.mjs
249
270
  - 依赖 `shell.overlay` 槽;更老的 DSH 版本没有该槽时,插件会安静地不显示,不会报错。
250
271
  - 每次页面加载都会出现一次,不记忆关闭状态(如需记忆见[自定义](#自定义))。
251
272
  - 浮层位于整帧之上:气泡默认在右下角、输入框上方(距右 20px、距底 84px),可以拖到任意位置;拖动后位置记在 localStorage 里(`dsh-greeting-bubble:position:v1`)。气泡本体需要接收拖动事件,所以它所在的那一小块会接住点击,其余区域不受影响。
252
- - 问候语固定为中文,在任何界面语言下都不翻译;只有关闭按钮的提示文字跟随语言。
253
- - 插件只在本地运行,不访问网络。
273
+ - 余额需要当前**已登录 DeepSeek 账号**;未登录、账号插件未启用或请求失败时显示 `余额 --`,不会报错。余额是 Platform 的实时钱包数据(充值 + 赠送),不是本地估算。
274
+ - 余额只显示在气泡里,不发送给任何第三方;但截图/录屏会带出金额,注意场合。
275
+ - 问候语固定为中文,在任何界面语言下都不翻译;只有按钮提示文字跟随语言。
276
+ - 插件自身不直接联网;余额读取经 Host 的账号服务完成。
254
277
 
255
278
  ## English
256
279
 
257
- A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble near the bottom-right corner after the page loads. Click × to dismiss it; it returns on the next page load. The bubble can be dragged anywhere, and its position is remembered in localStorage.
280
+ A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble near the bottom-right corner after the page loads, with the signed-in account balance on a second line. Click × to dismiss it; it returns on the next page load. The bubble can be dragged anywhere, and its position is remembered in localStorage.
258
281
 
259
282
  - Install: **Plugins → Add plugin** → `dsh-plugin-greeting-bubble` (npm), or `https://github.com/liwei169/dsh-plugin-greeting-bubble` (GitHub).
260
- - It registers one entry into the frame-wide `shell.overlay` slot, uses `--dsw-alias-*` theme tokens, localizes its close label, and keeps every registration inside `ctx.effect` / `ctx.slots.inject` so disabling the bundle removes the bubble again.
283
+ - It registers one entry into the frame-wide `shell.overlay` slot, uses `--dsw-alias-*` theme tokens, localizes its labels, and keeps every registration inside `ctx.effect` / `ctx.slots.inject` so disabling the bundle removes the bubble again.
261
284
  - Dragging uses pointer capture, clamps to the viewport, and saves the dropped position under `dsh-greeting-bubble:position:v1`.
262
- - No network access, no data collection, no model-facing behavior.
285
+ - Balance comes from `ctx.remote.account.getBalance(...)` (Host-side Platform call with the stored credential; the browser never sees the account token), refreshed every 60 seconds while the page is visible and on click, with backoff on failure.
286
+ - No direct network access, no data collection, no model-facing behavior.
263
287
 
264
288
  Tested with DeepSeek Harness 0.2.2-rc.5.
265
289
 
package/client.js CHANGED
@@ -12,9 +12,10 @@
12
12
  * control. Registering a fresh `id` adds an entry beside the shipped ones
13
13
  * instead of replacing them.
14
14
  *
15
- * The bubble is draggable: pointer capture keeps the drag smooth, the card is
16
- * clamped to the viewport, and the chosen spot is remembered in localStorage
17
- * under `POSITION_KEY`.
15
+ * The bubble is draggable (pointer capture, viewport clamp, remembered in
16
+ * localStorage) and shows the signed-in account's wallet balance, which it
17
+ * reads through the Host's `account` Remote — the browser never sees the
18
+ * account token and never calls Platform directly.
18
19
  */
19
20
  window.__ModuleLoader__.load({
20
21
  id: 'dsh-plugin-greeting-bubble',
@@ -28,6 +29,10 @@ window.__ModuleLoader__.load({
28
29
  /** Where the reader last dropped the bubble, as viewport px. */
29
30
  const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
30
31
 
32
+ /** Normal refresh cadence while the page is visible, and the failure cap. */
33
+ const BALANCE_REFRESH_MS = 60_000;
34
+ const BALANCE_MAX_BACKOFF_MS = 300_000;
35
+
31
36
  /** Read the remembered spot; a corrupt or absent value means "default". */
32
37
  function readPosition() {
33
38
  try {
@@ -57,19 +62,51 @@ window.__ModuleLoader__.load({
57
62
  return Math.max(min, Math.min(value, Math.max(min, max)));
58
63
  }
59
64
 
65
+ /** Platform wallet currency symbol. */
66
+ function currencySymbol(currency) {
67
+ if (currency === 'CNY') return '¥';
68
+ if (currency === 'USD') return '$';
69
+ return currency + ' ';
70
+ }
71
+
72
+ /** Display a Platform decimal string with two fraction digits. */
73
+ const AMOUNT_FORMAT = new Intl.NumberFormat(undefined, {
74
+ minimumFractionDigits: 2,
75
+ maximumFractionDigits: 2,
76
+ });
77
+
78
+ function formatAmount(value) {
79
+ const amount = Number(value);
80
+ return Number.isFinite(amount) ? AMOUNT_FORMAT.format(amount) : value;
81
+ }
82
+
83
+ /** True when a wallet amount is exactly zero (Platform sends decimal strings). */
84
+ function isZeroAmount(value) {
85
+ return Number(value) === 0;
86
+ }
87
+
88
+ /**
89
+ * Turn one `getBalance` result into the amount text for the second bubble
90
+ * line, or null when nothing sensible can be shown (signed out, failed, or
91
+ * empty wallets). The caller adds the localized "balance" label.
92
+ * @param balance - `AccountDetails['balance']` or null.
93
+ * @param bonusLabel - localized "bonus" word.
94
+ */
95
+ function formatBalance(balance, bonusLabel) {
96
+ if (!balance || balance.status !== 'ready' || !Array.isArray(balance.value)) return null;
97
+ const normal = balance.value
98
+ .filter((wallet) => wallet && typeof wallet.balance === 'string')
99
+ .map((wallet) => currencySymbol(wallet.currency) + formatAmount(wallet.balance));
100
+ if (normal.length === 0) return null;
101
+ const bonus = (balance.bonusWallets ?? [])
102
+ .filter((wallet) => wallet && typeof wallet.balance === 'string' && !isZeroAmount(wallet.balance))
103
+ .map((wallet) => currencySymbol(wallet.currency) + formatAmount(wallet.balance));
104
+ return bonus.length === 0 ? normal.join(' / ') : normal.join(' / ') + '(' + bonusLabel + ' ' + bonus.join(' / ') + ')';
105
+ }
106
+
60
107
  /**
61
108
  * Component-local stylesheet; unmounting the entry removes it with the
62
109
  * node.
63
- *
64
- * Placement notes:
65
- * - The default spot is 84px above the bottom edge, which clears the
66
- * composer's 34px send button and its card padding.
67
- * - Once dragged, the card switches to explicit `left`/`top` coordinates
68
- * and the reader's choice is remembered.
69
- * - The card now receives pointer events itself (it must, to be dragged);
70
- * only the layer around it stays click-through.
71
- * - Radii and elevation reuse the host tokens, so the bubble reads as one
72
- * of the app's own floating surfaces in both themes.
73
110
  */
74
111
  const STYLES = `
75
112
  .dsh-greeting-layer {
@@ -83,10 +120,11 @@ window.__ModuleLoader__.load({
83
120
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
84
121
  z-index: 1;
85
122
  display: flex;
86
- align-items: center;
87
- gap: 8px;
123
+ flex-direction: column;
124
+ align-items: stretch;
125
+ gap: 2px;
88
126
  box-sizing: border-box;
89
- max-width: min(320px, calc(100vw - 40px));
127
+ max-width: min(340px, calc(100vw - 40px));
90
128
  padding: 8px 6px 8px 12px;
91
129
  border: 0;
92
130
  --dsw-elevation-stroke-color: var(--dsw-alias-border-l3);
@@ -105,6 +143,12 @@ window.__ModuleLoader__.load({
105
143
  .dsh-greeting-bubble[data-dragging] {
106
144
  cursor: grabbing;
107
145
  }
146
+ .dsh-greeting-main {
147
+ display: flex;
148
+ align-items: center;
149
+ gap: 8px;
150
+ min-width: 0;
151
+ }
108
152
  .dsh-greeting-wave {
109
153
  flex: none;
110
154
  font-size: 16px;
@@ -114,6 +158,31 @@ window.__ModuleLoader__.load({
114
158
  min-width: 0;
115
159
  overflow-wrap: anywhere;
116
160
  }
161
+ .dsh-greeting-balance {
162
+ margin: 0;
163
+ padding: 0 0 0 24px;
164
+ border: 0;
165
+ border-radius: var(--dsw-radius-xs, 4px);
166
+ background: transparent;
167
+ color: var(--dsw-alias-label-tertiary);
168
+ font: inherit;
169
+ font-size: 12px;
170
+ line-height: 16px;
171
+ text-align: left;
172
+ width: fit-content;
173
+ max-width: 100%;
174
+ overflow-wrap: anywhere;
175
+ cursor: pointer;
176
+ pointer-events: auto;
177
+ }
178
+ .dsh-greeting-balance:hover {
179
+ color: var(--dsw-alias-label-secondary);
180
+ }
181
+ .dsh-greeting-balance:focus-visible {
182
+ outline: var(--dsw-focus-ring-width, 2px) solid
183
+ var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
184
+ outline-offset: 1px;
185
+ }
117
186
  .dsh-greeting-close {
118
187
  flex: none;
119
188
  display: inline-flex;
@@ -121,6 +190,7 @@ window.__ModuleLoader__.load({
121
190
  justify-content: center;
122
191
  width: 26px;
123
192
  height: 26px;
193
+ margin-left: auto;
124
194
  padding: 0;
125
195
  border: 0;
126
196
  border-radius: var(--dsw-radius-sm, 8px);
@@ -158,15 +228,77 @@ window.__ModuleLoader__.load({
158
228
  /**
159
229
  * The greeting bubble itself.
160
230
  *
161
- * @param props - the framework `t` seat bound to {@link NS}.
231
+ * @param props - the framework `t` seat plus the injected balance loader.
162
232
  * @returns the bubble, or null once the reader dismissed it.
163
233
  */
164
- function GreetingBubble({ t }) {
234
+ function GreetingBubble({ t, loadBalance }) {
165
235
  const [dismissed, setDismissed] = React.useState(false);
166
236
  const [position, setPosition] = React.useState(readPosition);
167
237
  const [dragging, setDragging] = React.useState(false);
238
+ const [walletText, setWalletText] = React.useState(null);
168
239
  const bubbleRef = React.useRef(null);
169
240
  const dragRef = React.useRef(null);
241
+ const inFlightRef = React.useRef(null);
242
+ const timerRef = React.useRef(null);
243
+ const backoffRef = React.useRef(BALANCE_REFRESH_MS);
244
+ const cancelledRef = React.useRef(false);
245
+
246
+ const label = (key, fallback) => (typeof t === 'function' ? t(key) : fallback);
247
+
248
+ /** Fetch once, deduplicating concurrent calls; resolves to wallet text or null. */
249
+ function readBalance() {
250
+ if (typeof loadBalance !== 'function') return Promise.resolve(null);
251
+ if (inFlightRef.current !== null) return inFlightRef.current;
252
+ const run = Promise.resolve()
253
+ .then(() => loadBalance())
254
+ .then((result) => {
255
+ if (!result || result.ok !== true) return null;
256
+ return formatBalance(result.value, label('bonus', '赠送'));
257
+ })
258
+ .catch(() => null)
259
+ .finally(() => { inFlightRef.current = null; });
260
+ inFlightRef.current = run;
261
+ return run;
262
+ }
263
+
264
+ /** One polling cycle: refresh, then schedule the next attempt with backoff. */
265
+ function tick() {
266
+ if (cancelledRef.current) return;
267
+ const visible = typeof document === 'undefined' || document.visibilityState !== 'hidden';
268
+ if (!visible) {
269
+ timerRef.current = window.setTimeout(tick, BALANCE_REFRESH_MS);
270
+ return;
271
+ }
272
+ void readBalance().then((text) => {
273
+ if (cancelledRef.current) return;
274
+ setWalletText(text);
275
+ backoffRef.current = text === null
276
+ ? Math.min(backoffRef.current * 2, BALANCE_MAX_BACKOFF_MS)
277
+ : BALANCE_REFRESH_MS;
278
+ timerRef.current = window.setTimeout(tick, backoffRef.current);
279
+ });
280
+ }
281
+
282
+ // Balance polling: visible-only, deduplicated, backed off on failure.
283
+ React.useEffect(() => {
284
+ cancelledRef.current = false;
285
+ tick();
286
+ function handleVisibility() {
287
+ if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
288
+ backoffRef.current = BALANCE_REFRESH_MS;
289
+ if (timerRef.current !== null) window.clearTimeout(timerRef.current);
290
+ tick();
291
+ }
292
+ }
293
+ document.addEventListener('visibilitychange', handleVisibility);
294
+ return () => {
295
+ cancelledRef.current = true;
296
+ if (timerRef.current !== null) window.clearTimeout(timerRef.current);
297
+ document.removeEventListener('visibilitychange', handleVisibility);
298
+ };
299
+ // The loader is stable for the registration's lifetime.
300
+ // eslint-disable-next-line react-hooks/exhaustive-deps
301
+ }, []);
170
302
 
171
303
  // Keep a remembered spot on screen when the window shrinks.
172
304
  React.useEffect(() => {
@@ -184,8 +316,18 @@ window.__ModuleLoader__.load({
184
316
  }, []);
185
317
 
186
318
  if (dismissed) return null;
187
- const text = typeof t === 'function' ? t('greeting') : '你好,腾盛';
188
- const dismissLabel = typeof t === 'function' ? t('dismiss') : '关闭问候气泡';
319
+ const text = label('greeting', '你好,腾盛');
320
+ const dismissLabel = label('dismiss', '关闭问候气泡');
321
+ const balanceLine = label('balance', '余额') + ' ' + (walletText ?? label('unavailable', '--'));
322
+
323
+ /** Manual refresh: reset the backoff and read once. */
324
+ function handleBalanceClick(event) {
325
+ event.stopPropagation();
326
+ backoffRef.current = BALANCE_REFRESH_MS;
327
+ void readBalance().then((value) => {
328
+ if (!cancelledRef.current) setWalletText(value);
329
+ });
330
+ }
189
331
 
190
332
  /** Start a drag: switch to absolute coordinates and capture the pointer. */
191
333
  function handlePointerDown(event) {
@@ -259,38 +401,53 @@ window.__ModuleLoader__.load({
259
401
  onPointerUp: handlePointerUp,
260
402
  onPointerCancel: handlePointerUp,
261
403
  },
262
- h('span', { className: 'dsh-greeting-wave', 'aria-hidden': 'true' }, '👋'),
263
- // `lang` pins the reading voice for this fixed Chinese phrase; the
264
- // status role lives on the text so the dismiss button stays outside
265
- // the live region.
266
- h('span', { className: 'dsh-greeting-text', role: 'status', lang: 'zh-CN' }, text),
404
+ h(
405
+ 'div',
406
+ { className: 'dsh-greeting-main', key: 'main' },
407
+ h('span', { className: 'dsh-greeting-wave', 'aria-hidden': 'true' }, '👋'),
408
+ // `lang` pins the reading voice for this fixed Chinese phrase; the
409
+ // status role lives on the text so the controls stay outside the
410
+ // live region.
411
+ h('span', { className: 'dsh-greeting-text', role: 'status', lang: 'zh-CN' }, text),
412
+ h(
413
+ 'button',
414
+ {
415
+ className: 'dsh-greeting-close',
416
+ type: 'button',
417
+ title: dismissLabel,
418
+ 'aria-label': dismissLabel,
419
+ onClick: () => { setDismissed(true); },
420
+ },
421
+ h(
422
+ 'svg',
423
+ { width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
424
+ h('path', {
425
+ d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
426
+ fill: 'none',
427
+ stroke: 'currentColor',
428
+ strokeWidth: 1.4,
429
+ strokeLinecap: 'round',
430
+ }),
431
+ ),
432
+ ),
433
+ ),
267
434
  h(
268
435
  'button',
269
436
  {
270
- className: 'dsh-greeting-close',
437
+ key: 'balance',
438
+ className: 'dsh-greeting-balance',
271
439
  type: 'button',
272
- title: dismissLabel,
273
- 'aria-label': dismissLabel,
274
- onClick: () => { setDismissed(true); },
440
+ title: label('refreshBalance', '刷新余额'),
441
+ onClick: handleBalanceClick,
275
442
  },
276
- h(
277
- 'svg',
278
- { width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
279
- h('path', {
280
- d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
281
- fill: 'none',
282
- stroke: 'currentColor',
283
- strokeWidth: 1.4,
284
- strokeLinecap: 'round',
285
- }),
286
- ),
443
+ balanceLine,
287
444
  ),
288
445
  ),
289
446
  );
290
447
  }
291
448
 
292
449
  return {
293
- inject: ['slots', 'locale'],
450
+ inject: ['slots', 'locale', 'remote', 'remote.account'],
294
451
  /**
295
452
  * Register the plugin's dictionary and its single overlay entry.
296
453
  * @param ctx - client plugin context.
@@ -299,17 +456,53 @@ window.__ModuleLoader__.load({
299
456
  ctx.effect(
300
457
  () => ctx.locale.register(NS, {
301
458
  // The greeting is the plugin's fixed signature phrase, so it stays
302
- // identical in every locale; only the control labels are localized.
303
- zh: { greeting: '你好,腾盛', dismiss: '关闭问候气泡' },
304
- en: { greeting: '你好,腾盛', dismiss: 'Dismiss greeting' },
459
+ // identical in every locale; only control labels are localized.
460
+ zh: {
461
+ greeting: '你好,腾盛',
462
+ dismiss: '关闭问候气泡',
463
+ balance: '余额',
464
+ bonus: '赠送',
465
+ unavailable: '--',
466
+ refreshBalance: '刷新余额',
467
+ },
468
+ en: {
469
+ greeting: '你好,腾盛',
470
+ dismiss: 'Dismiss greeting',
471
+ balance: 'Balance',
472
+ bonus: 'Bonus',
473
+ unavailable: '--',
474
+ refreshBalance: 'Refresh balance',
475
+ },
305
476
  }),
306
477
  'greeting-bubble: dictionaries',
307
478
  );
479
+ /** Current request identity for the Host's Platform calls. */
480
+ const metadata = () => {
481
+ let version = '';
482
+ try {
483
+ version = (typeof process !== 'undefined' && process.env && process.env.DSH_CLIENT_VERSION) || '';
484
+ } catch {
485
+ // `process` is absent in some browser builds; an empty version is fine.
486
+ }
487
+ return {
488
+ version,
489
+ locale: ctx.locale.getSnapshot().active,
490
+ timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
491
+ };
492
+ };
493
+ const loadBalance = () => {
494
+ const account = ctx.remote && ctx.remote.account;
495
+ if (!account || typeof account.getBalance !== 'function') {
496
+ throw new Error('account service unavailable');
497
+ }
498
+ return account.getBalance(metadata());
499
+ };
308
500
  ctx.slots.inject('shell.overlay', () => ctx.slots.register({
309
501
  name: 'shell.overlay',
310
502
  id: 'greeting-bubble',
311
503
  order: 50,
312
504
  locale: NS,
505
+ inject: () => ({ loadBalance }),
313
506
  }, GreetingBubble));
314
507
  },
315
508
  };
package/docs/DEV.md ADDED
@@ -0,0 +1,264 @@
1
+ # 开发与发布指南(维护者)
2
+
3
+ 这份文档面向仓库维护者,记录本插件的本地开发、测试、Git 提交和 npm 发布流程,以及我们实际踩过的坑。普通用户请看 [README](../README.md)。
4
+
5
+ 所有命令都在 **PowerShell** 中执行,工作目录为仓库根目录(本文以 `D:\插件实现` 为例)。
6
+
7
+ ---
8
+
9
+ ## 0. 环境说明
10
+
11
+ 本机没有全局 `node`/`npm`,但 DSH 自带了一套 Node 和 pnpm,后面的命令统一用它们:
12
+
13
+ ```powershell
14
+ $node = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\node\bin\node.exe'
15
+ $pnpm = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\pnpm\bin\pnpm.mjs'
16
+ ```
17
+
18
+ > 路径里的用户名按实际情况替换;如果以后装了全局 Node,也可以直接用 `node` / `npm`。
19
+
20
+ ---
21
+
22
+ ## 1. 项目结构
23
+
24
+ ```text
25
+ .
26
+ ├─ package.json # 包清单:dsh.bundle.patch + dsh.client + exports/files
27
+ ├─ cordis.patch.yml # 往 Loader 插入插件行(id: greeting-bubble)
28
+ ├─ index.js # Host 半(空 apply)
29
+ ├─ client.js # 浏览器半:气泡、拖动、余额、slot 注册
30
+ ├─ icon.svg # 插件图标
31
+ ├─ locale/{zh,en}.json # 插件页标题/描述
32
+ ├─ docs/ # 详情页文档 + 本文档
33
+ ├─ test/smoke.mjs # 离线冒烟测试
34
+ └─ README.md / LICENSE / UPLOAD.md
35
+ ```
36
+
37
+ ---
38
+
39
+ ## 2. 本地开发
40
+
41
+ ### 2.1 安装到 DSH(link 方式)
42
+
43
+ 插件页 → **添加插件** → 填入仓库的**绝对路径**(例如 `D:\插件实现`)→ 安装。
44
+
45
+ 也可以用 agent:
46
+
47
+ ```text
48
+ 安装 D:\插件实现 这个插件
49
+ ```
50
+
51
+ ### 2.2 修改代码后,按需要选择刷新级别
52
+
53
+ | 改动 | 生效方式 |
54
+ |---|---|
55
+ | 只改 `client.js` / 样式 / 文案 | 插件页**关闭再打开**开关 → 刷新页面 |
56
+ | 改 `package.json`、`cordis.patch.yml`、宿主逻辑 | 卸载后重装 → 刷新页面 |
57
+ | 换过安装路径、升级/降级版本、出现 `ENOENT` | **完全退出 DSH 再打开**(重启 Host 进程) |
58
+
59
+ > 页面刷新(Ctrl+R)只重载浏览器页面,**不会清 Host 进程的模块缓存**。
60
+
61
+ ### 2.3 为什么必须重启:模块缓存与路径
62
+
63
+ DSH 的 Host 进程用 Node 的 ESM 加载插件。模块一旦被解析,结果会按“说明符 → 实际文件路径”缓存在进程里。
64
+
65
+ 如果插件是 `link` 到某个目录、之后又**删除或移动了那个目录**,Host 缓存仍指向旧路径,于是报:
66
+
67
+ ```
68
+ failed to import: ENOENT: no such file or directory, open '...\old-path\index.js'
69
+ ```
70
+
71
+ **规则:**
72
+
73
+ - 开发目录放在固定位置,**不要删、不要临时复制到别处再安装**;
74
+ - 要移动/删除目录,先到插件页**卸载**插件;
75
+ - 不得已换了路径:重启 DSH。
76
+
77
+ 另外,pnpm 替换 `node_modules` 里的链接目录时,Windows 上偶尔会报 `EPERM`(目录被占用)。这时先卸载,再清理残留(见 2.4),然后重装。
78
+
79
+ ### 2.4 清理安装残留
80
+
81
+ ```powershell
82
+ $nm = 'C:\Users\<用户名>\.dsh\profiles\desktop\node_modules'
83
+ Get-ChildItem $nm -Force | Where-Object { $_.Name -like '*greeting-bubble*' } | ForEach-Object {
84
+ if ($_.LinkType -eq 'Junction') { cmd /c rmdir "$($_.FullName)" } # 只删链接,不删目标
85
+ else { Remove-Item -LiteralPath $_.FullName -Recurse -Force }
86
+ }
87
+ ```
88
+
89
+ > 只对名称包含 `greeting-bubble` 的项操作;不要动其他插件。
90
+
91
+ ---
92
+
93
+ ## 3. 测试
94
+
95
+ 提交前至少跑:
96
+
97
+ ```powershell
98
+ $node = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\node\bin\node.exe'
99
+
100
+ node --check index.js
101
+ node --check client.js
102
+ node test/smoke.mjs # 必须输出:ok: ...
103
+ ```
104
+
105
+ 冒烟测试用假的 `window / React / Cordis / Remote` 上下文执行 `client.js`,校验模块 id、slot 注册参数、字典、账号 Remote 注入和组件渲染。
106
+
107
+ 检查 npm 会打包哪些文件:
108
+
109
+ ```powershell
110
+ $pnpm = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\pnpm\bin\pnpm.mjs'
111
+ & $node $pnpm pack --dry-run
112
+ ```
113
+
114
+ ---
115
+
116
+ ## 4. 版本与发布(npm)
117
+
118
+ ### 4.1 版本号
119
+
120
+ 遵循语义化版本:
121
+
122
+ - 修 bug:`1.2.1`
123
+ - 加功能:`1.3.0`
124
+ - 不兼容改动:`2.0.0`
125
+
126
+ npm **不允许重复发布同一个版本号**,每次发布前必须先改 `package.json` 的 `version`。
127
+
128
+ ### 4.2 登录与令牌
129
+
130
+ 发布需要 npm 账号并开启 2FA(安全密钥/生物识别)。发布令牌放在本机:
131
+
132
+ ```
133
+ C:\Users\<用户名>\AppData\Local\pnpm\config\auth.ini
134
+ ```
135
+
136
+ 内容形如:
137
+
138
+ ```
139
+ //registry.npmjs.org/:_authToken=npm_xxxxx
140
+ ```
141
+
142
+ **令牌绝不提交到仓库**。令牌过期(或误删)后重新生成一个即可:
143
+
144
+ - npm → **Access Tokens** → **Generate New Token** → **Granular Access Token**
145
+ - 权限 **Read and write (publish and stage)**、范围 **All packages**、**Bypass 2FA** 打开
146
+
147
+ > 注意:2027 年 1 月起 npm 收紧“免 2FA 令牌”的直接发布,届时需改用带验证码/可信发布(CI)的方式。
148
+
149
+ ### 4.3 发布
150
+
151
+ ```powershell
152
+ cd D:\插件实现
153
+ $node = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\node\bin\node.exe'
154
+ $pnpm = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\pnpm\bin\pnpm.mjs'
155
+
156
+ # 先干跑
157
+ & $node $pnpm publish --dry-run --no-git-checks --access public
158
+
159
+ # 正式发布
160
+ & $node $pnpm publish --no-git-checks --access public
161
+
162
+ # 验证(registry 有 1~2 分钟处理延迟)
163
+ & $node $pnpm view dsh-plugin-greeting-bubble version
164
+ ```
165
+
166
+ ### 4.4 两个常见“不是失败”的现象
167
+
168
+ 1. **`0.0.0-stage` 占位版本**:全新包第一次发布时,npm 先放一个占位版本,真版本 1~2 分钟后生效;不是错误,也不用审批。
169
+ 2. **`minimumReleaseAge` 观察期**:pnpm 默认不自动安装刚发布不久的版本。按包名安装会拿到旧版本;想立即用新版:
170
+
171
+ ```
172
+ dsh-plugin-greeting-bubble@1.2.0
173
+ ```
174
+
175
+ 安装时带上版本号,profile 会自动加入 `minimumReleaseAgeExclude` 白名单。
176
+
177
+ ### 4.5 测试版(可选)
178
+
179
+ 频繁试错时,用预发布版本代替 link 安装,避免路径缓存问题:
180
+
181
+ ```powershell
182
+ # package.json 版本改成 1.2.1-beta.0 后
183
+ & $node $pnpm publish --no-git-checks --access public --tag beta
184
+ ```
185
+
186
+ 安装时填 `dsh-plugin-greeting-bubble@1.2.1-beta.0`;测试通过后再发正式版。
187
+
188
+ ---
189
+
190
+ ## 5. Git
191
+
192
+ ### 5.1 提交与推送
193
+
194
+ ```powershell
195
+ cd D:\插件实现
196
+ git add -A
197
+ git commit -m "feat: xxx (v1.3.0)"
198
+ git tag v1.3.0
199
+ git push
200
+ git push origin v1.3.0
201
+ ```
202
+
203
+ 远端:`https://github.com/liwei169/dsh-plugin-greeting-bubble.git`
204
+
205
+ 推送会使用 Git Credential Manager 已保存的 GitHub 登录;也可以用 PAT(classic,`repo` 权限)作为密码。
206
+
207
+ ### 5.2 GitHub 网络问题
208
+
209
+ 本机到 `github.com` 的 DNS 偶尔会被解析到不可用 IP,表现为推送/安装超时。临时办法(机器级、可撤销):
210
+
211
+ - 管理员编辑 `C:\Windows\System32\drivers\etc\hosts`,加一行
212
+
213
+ ```
214
+ 20.205.243.166 github.com
215
+ ```
216
+
217
+ - 执行 `ipconfig /flushdns`;
218
+ - 用完后删除该行即可。
219
+
220
+ 长期方案:使用稳定的 DNS 或代理。
221
+
222
+ ### 5.3 `.git` 管理文件丢失的应急恢复
223
+
224
+ 如果 `git status` 报 `not a git repository`,但 `.git/objects`、`.git/refs` 还在:
225
+
226
+ ```powershell
227
+ # 1) 重建 .git/HEAD,内容为:ref: refs/heads/main
228
+ # 2) 重建 .git/config,至少包含 core、remote.origin、branch.main
229
+ # 3) 从 refs 重建索引
230
+ git reset --mixed HEAD
231
+ git status -sb
232
+ ```
233
+
234
+ 历史不会丢;`git fsck` 可校验。
235
+
236
+ ---
237
+
238
+ ## 6. 发版 Checklist
239
+
240
+ - [ ] 改代码,`package.json` 版本号 +1
241
+ - [ ] `node --check index.js` / `node --check client.js` 通过
242
+ - [ ] `node test/smoke.mjs` 输出 `ok: ...`
243
+ - [ ] `pnpm pack --dry-run` 文件清单正确(12 个文件左右)
244
+ - [ ] `git add/commit/tag/push`(含 tag)
245
+ - [ ] `pnpm publish --no-git-checks --access public`
246
+ - [ ] `pnpm view dsh-plugin-greeting-bubble version` 确认新版本
247
+ - [ ] 插件页卸载旧版 → 安装 `dsh-plugin-greeting-bubble@新版本` → 重启 DSH
248
+ - [ ] 刷新页面,确认气泡、拖动、余额正常
249
+
250
+ ---
251
+
252
+ ## 7. 常见问题
253
+
254
+ | 现象 | 原因 / 解决 |
255
+ |---|---|
256
+ | 安装报 `EPERM ... rename` | `node_modules` 里有旧目录/链接残留:卸载后按 2.4 清理再装 |
257
+ | 加载报 `ENOENT ... old-path\index.js` | Host 缓存了已删除的安装路径:完全重启 DSH |
258
+ | 插件页显示“未运行”但文件都在 | 同上,多为路径缓存或导入失败,重启后仍失败就看安装日志 |
259
+ | 新版本装不上、装到旧版 | `minimumReleaseAge` 观察期:填 `包名@版本号` 安装 |
260
+ | 气泡没出现 | 插件页确认已启用;刷新;检查控制台 `slot entry crashed`;确认 DSH 版本含 `shell.overlay` |
261
+ | 余额显示 `--` | 未登录 DeepSeek 账号或账号服务不可用;确认设置里账号正常 |
262
+ | `pnpm publish` 报 403 需要 2FA | 令牌没有 Bypass 2FA:重新生成 Granular Token 并打开 Bypass 2FA |
263
+ | `pnpm publish` 报 401 | 令牌过期/被删:重新生成并写入 `auth.ini` |
264
+ | 推送/安装 GitHub 超时 | DNS 问题,见 5.2 |
package/locale/en.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "Greeting bubble",
4
- "description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer, after the page loads. Drag the bubble anywhere; its position is remembered for the next visit. Click × to dismiss it; it appears again on the next page load. The greeting stays Chinese in every interface language; only the close-button label is localized. The plugin makes no network requests, collects no data, and changes nothing else in the app. Disable or remove the bundle under Plugins to remove it.",
3
+ "description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer, plus the signed-in DeepSeek account balance (top-up and bonus wallets) refreshed every 60 seconds; click the balance line to refresh it immediately. Drag the bubble anywhere; its position is remembered for the next visit. Click × to dismiss it; it appears again on the next page load. The greeting stays Chinese in every interface language; only control labels are localized. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “Balance --”. The plugin makes no network requests of its own and collects no data. Disable or remove the bundle under Plugins to remove it.",
5
4
  "detail": "docs/DETAIL.md"
6
5
  }
7
6
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "右下角问候气泡",
4
- "description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡。按住气泡可以拖到任意位置,位置会记住,下次打开仍在原处。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有关闭按钮的提示文字跟随界面语言。插件不联网、不收集数据,除气泡外不改变任何界面。在「插件」页停用或移除本插件即可彻底去掉。",
3
+ "description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡,并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次,点击余额行可立即刷新。按住气泡可以拖到任意位置,位置会记住,下次打开仍在原处。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有按钮提示跟随界面语言。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「余额 --」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
5
4
  "detail": "docs/DETAIL.zh.md"
6
5
  }
7
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-greeting-bubble",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Shows a “你好,腾盛” speech bubble in the bottom-right corner of the DeepSeek Harness Web GUI.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {