dsh-plugin-greeting-bubble 1.4.1 → 1.5.0-beta.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
@@ -1,4 +1,4 @@
1
- # dsh-plugin-greeting-bubble · 你好,腾盛
1
+ # dsh-plugin-greeting-bubble · 你好,腾盛
2
2
 
3
3
  一个用于 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)Web 界面的小型 UI 插件:页面加载后,在**窗口右下角**弹出「你好,腾盛」问候气泡,点 × 即可关闭。
4
4
 
@@ -28,17 +28,21 @@
28
28
 
29
29
  ## 效果
30
30
 
31
- - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 早上好/中午好/下午好/晚上好,腾盛 ×(按当前时间变化)
32
- - **第二行显示账号余额**:`余额 ¥12.34`,来自当前登录的 DeepSeek 账号;每 60 秒刷新一次。
33
- - **余额低于 3 元**时,这一行变橙并显示「余额不足」提醒。
34
- - **点余额这一行展开详情**:账户名/联系方式、**连接状态(断开时可一键重连)**、**今日消费金额估算**、充值余额、最近更新时间,以及「用量」「充值」快捷入口;再点一次收起。
35
- - 今日消费金额 = 基准余额 − 当前余额;优先用**昨天最后一次读到的余额**(≈ 0 点余额),没有昨天数据则用**今天第一次读到的余额**;充值会使基准同步抬高,不计入消费;详情里会显示基准时间。
31
+ - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入**小机器人 + 气泡卡片**:`🤖 早上好,腾盛 · ¥12.34`(问候语按时间变化)。
32
+ - **折叠态**只显示机器人 + 「问候语 · 金额」胶囊;**点击机器人或胶囊**展开详情,再点一次收起。
33
+ - 机器人的状态会在视觉上体现:
34
+ - 正常:主题蓝,偶尔眨眼;
35
+ - 刷新中:天线闪烁;
36
+ - 余额 <¥3:变成橙色;
37
+ - 连接断开:变成灰色并“闭眼”。
38
+ - 展开后显示:账户名/联系方式、**连接状态(断开时可一键重连)**、**今日消费金额估算**、充值余额、最近更新时间,以及「用量」「充值」快捷入口。
39
+ - 今日消费金额只显示金额(`≈ ¥x.xx`);口径是基准余额 − 当前余额,优先用**昨天最后一次读到的余额**(≈ 0 点余额),没有昨天数据则用**今天第一次读到的余额**;充值会使基准同步抬高,不计入消费。
36
40
  - **安装插件之前、或 DSH 未运行期间**的消费无法统计,所以这是“自基准时间起”的估算,不是平台账单。
37
41
  - 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
38
- - 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
39
- - 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
40
- - **按住气泡可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
41
- - 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。气泡本体需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
42
+ - 未登录、账号服务不可用或请求失败时显示 `--`,不影响其他功能。
43
+ - 展开后用右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
44
+ - **按住机器人或卡片可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
45
+ - 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。控件需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
42
46
  - 在「插件」「设置」等页面同样显示(浮层属于整个应用框架)。
43
47
  - 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会被拖出屏幕(拖动时自动限制在可视区内)。
44
48
 
@@ -92,16 +96,17 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
92
96
 
93
97
  | 操作 | 结果 |
94
98
  | --- | --- |
95
- | 页面加载 | 气泡出现(每个页面视图一次),并读取一次余额 |
96
- | **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
97
- | **点余额那一行** | 展开/收起详情(账户、会话、连接、今日估算、钱包明细、更新时间、版本、快捷入口) |
99
+ | 页面加载 | 机器人 + 折叠胶囊出现(每个页面视图一次),并读取一次余额 |
100
+ | **按住机器人或卡片拖动** | 整体跟着指针移动,松手后记住位置 |
101
+ | **点机器人或胶囊** | 展开/收起详情卡 |
102
+ | 展开后的 × | 本次页面隐藏整个挂件 |
98
103
  | 详情里的「重连」 | 连接断开时出现,点击立即重连 Host |
99
104
  | 详情里的「刷新」 | 立即刷新余额(不用等 60 秒) |
100
105
  | 详情里的「隐藏金额 / 显示金额」 | 切换隐私模式并记住 |
101
- | 余额低于 ¥3 | 余额行变橙并显示「余额不足」 |
102
- | 点 ×(或聚焦后按 Enter / Space) | 本次页面隐藏气泡 |
103
- | 刷新页面 | 气泡再次出现,位置保持上次拖到的位置 |
104
- | 插件页关闭该包的开关 | 气泡立即消失(HMR 生效时无需刷新) |
106
+ | 余额低于 ¥3 | 机器人变橙,胶囊显示橙色圆点 |
107
+ | 连接断开 | 机器人变灰、闭眼 |
108
+ | 刷新页面 | 挂件再次出现,位置保持上次拖到的位置 |
109
+ | 插件页关闭该包的开关 | 挂件立即消失(HMR 生效时无需刷新) |
105
110
  | 插件页卸载该包 | 彻底移除,不再出现 |
106
111
 
107
112
  ## 自定义
package/client.js CHANGED
@@ -4,22 +4,19 @@
4
4
  * Loaded lazily by the DSH client module table: this file only registers a
5
5
  * factory. The factory returns a Cordis plugin whose `apply` owns every live
6
6
  * resource through `ctx.effect` / `ctx.slots.inject`, so disabling or removing
7
- * the bundle removes the bubble again without a reload.
7
+ * the bundle removes the widget again without a reload.
8
8
  *
9
9
  * Rendering surface: the `shell.overlay` list slot declared by
10
10
  * `@deepseek-ai/dsh-client-ui-layout`. It is a frame-wide layer above every
11
- * column, so the bubble floats over the whole app without moving any host
12
- * control. Registering a fresh `id` adds an entry beside the shipped ones
13
- * instead of replacing them.
11
+ * column, so the widget floats over the whole app without moving any host
12
+ * control.
14
13
  *
15
- * Features:
16
- * - draggable, viewport-clamped, position remembered in localStorage;
17
- * - account balance from the Host `account` Remote (never the token itself),
18
- * refreshed every 60s while visible, with backoff and a manual refresh;
19
- * - privacy mode hides amounts (remembered);
20
- * - a low-balance warning below 3 CNY;
21
- * - an expandable details panel with wallets, account, update time, version,
22
- * and links to the Platform usage/top-up pages.
14
+ * v1.5 visual language:
15
+ * - a small robot avatar beside one speech card, dragged as a single unit;
16
+ * - collapsed: robot + `greeting · amount` pill; expanded: greeting, details,
17
+ * and actions;
18
+ * - the robot reflects state: accent while connected, warning colour on a low
19
+ * balance, muted and "eyes closed" while disconnected, and a blinking idle.
23
20
  */
24
21
  window.__ModuleLoader__.load({
25
22
  id: 'dsh-plugin-greeting-bubble',
@@ -30,7 +27,7 @@ window.__ModuleLoader__.load({
30
27
  /** Locale namespace owned by this plugin (registered in `apply`). */
31
28
  const NS = 'greetingBubble';
32
29
 
33
- /** Where the reader last dropped the bubble, as viewport px. */
30
+ /** Where the reader last dropped the widget, as viewport px. */
34
31
  const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
35
32
 
36
33
  /** Whether amounts are hidden. */
@@ -40,7 +37,7 @@ window.__ModuleLoader__.load({
40
37
  const BALANCE_REFRESH_MS = 60_000;
41
38
  const BALANCE_MAX_BACKOFF_MS = 300_000;
42
39
 
43
- /** Below this CNY amount the bubble warns. */
40
+ /** Below this CNY amount the widget warns. */
44
41
  const LOW_BALANCE_CNY = 3;
45
42
 
46
43
  /** Local-day consumption baseline; reset when the date changes. */
@@ -50,6 +47,9 @@ window.__ModuleLoader__.load({
50
47
  const USAGE_URL = 'https://platform.deepseek.com/usage';
51
48
  const TOP_UP_URL = 'https://platform.deepseek.com/top_up';
52
49
 
50
+ /** Movement in px beyond which a pointer gesture counts as a drag, not a click. */
51
+ const DRAG_THRESHOLD = 4;
52
+
53
53
  /** Read the remembered spot; a corrupt or absent value means "default". */
54
54
  function readPosition() {
55
55
  try {
@@ -65,7 +65,7 @@ window.__ModuleLoader__.load({
65
65
  return null;
66
66
  }
67
67
 
68
- /** Persist the dropped spot; failures must never break the bubble. */
68
+ /** Persist the dropped spot; failures must never break the widget. */
69
69
  function writePosition(position) {
70
70
  try {
71
71
  window.localStorage.setItem(POSITION_KEY, JSON.stringify(position));
@@ -159,8 +159,6 @@ window.__ModuleLoader__.load({
159
159
  * balance: yesterday's last reading across midnight when available,
160
160
  * otherwise today's first reading. A top-up raises the baseline so it does
161
161
  * not count as negative spending.
162
- * @param normal - current normal wallets.
163
- * @returns `{ spent, startAt }`, or null when no CNY wallet is present.
164
162
  */
165
163
  function trackConsumption(normal) {
166
164
  const cny = (normal ?? []).find((wallet) => wallet.currency === 'CNY' && typeof wallet.balance === 'string');
@@ -181,17 +179,13 @@ window.__ModuleLoader__.load({
181
179
  baseline = state.baseline;
182
180
  startAt = typeof state.startAt === 'number' ? state.startAt : now;
183
181
  if (typeof state.lastAmount === 'number' && amount > state.lastAmount) {
184
- // A top-up mid-day: keep the spend counter continuous.
185
182
  baseline += amount - state.lastAmount;
186
183
  }
187
184
  } else if (state && typeof state.lastAmount === 'number' && typeof state.lastAt === 'number'
188
185
  && localDateKey(new Date(state.lastAt)) !== today) {
189
- // The plugin was running before midnight: its last reading is the
190
- // closest available day-start balance.
191
186
  baseline = state.lastAmount;
192
187
  startAt = state.lastAt;
193
188
  } else {
194
- // No reading from before today: today's first reading is the baseline.
195
189
  baseline = amount;
196
190
  startAt = now;
197
191
  }
@@ -229,7 +223,8 @@ window.__ModuleLoader__.load({
229
223
 
230
224
  /**
231
225
  * Component-local stylesheet; unmounting the entry removes it with the
232
- * node.
226
+ * node. Every colour comes from a `--dsw-alias-*` token so themes keep
227
+ * working; the robot itself is a plain SVG drawn with `currentColor`.
233
228
  */
234
229
  const STYLES = `
235
230
  .dsh-greeting-layer {
@@ -237,18 +232,75 @@ window.__ModuleLoader__.load({
237
232
  inset: 0;
238
233
  pointer-events: none;
239
234
  }
240
- .dsh-greeting-bubble {
235
+ .dsh-greeting-widget {
241
236
  position: absolute;
242
237
  right: calc(20px + env(safe-area-inset-right, 0px));
243
238
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
244
239
  z-index: 1;
245
240
  display: flex;
241
+ align-items: flex-end;
242
+ gap: 6px;
243
+ max-width: calc(100vw - 40px);
244
+ cursor: grab;
245
+ touch-action: none;
246
+ user-select: none;
247
+ pointer-events: auto;
248
+ animation: dsh-greeting-in 320ms cubic-bezier(0.22, 0.8, 0.24, 1) 350ms both;
249
+ }
250
+ .dsh-greeting-widget[data-dragging] {
251
+ cursor: grabbing;
252
+ }
253
+ .dsh-greeting-avatar {
254
+ flex: none;
255
+ width: 34px;
256
+ height: 34px;
257
+ padding: 0;
258
+ border: 0;
259
+ border-radius: 50%;
260
+ background: transparent;
261
+ color: var(--dsw-alias-state-business-primary, #3b6fe0);
262
+ cursor: pointer;
263
+ pointer-events: auto;
264
+ transition: color 120ms ease;
265
+ }
266
+ .dsh-greeting-widget[data-low] .dsh-greeting-avatar {
267
+ color: var(--dsw-alias-state-warn-primary, #b26a00);
268
+ }
269
+ .dsh-greeting-widget[data-disconnected] .dsh-greeting-avatar {
270
+ color: var(--dsw-alias-label-tertiary);
271
+ }
272
+ .dsh-greeting-avatar svg {
273
+ display: block;
274
+ width: 100%;
275
+ height: 100%;
276
+ overflow: visible;
277
+ }
278
+ .dsh-greeting-eye {
279
+ transform-box: fill-box;
280
+ transform-origin: center;
281
+ }
282
+ .dsh-greeting-widget[data-disconnected] .dsh-greeting-eyes {
283
+ transform: scaleY(0.12);
284
+ transform-box: fill-box;
285
+ transform-origin: center;
286
+ }
287
+ .dsh-greeting-widget:not([data-disconnected]) .dsh-greeting-eyes {
288
+ animation: dsh-greeting-blink 7s ease-in-out infinite;
289
+ }
290
+ .dsh-greeting-antenna-dot {
291
+ transform-box: fill-box;
292
+ transform-origin: center;
293
+ }
294
+ .dsh-greeting-widget[data-refreshing] .dsh-greeting-antenna-dot {
295
+ animation: dsh-greeting-pulse 900ms ease-in-out infinite;
296
+ }
297
+ .dsh-greeting-card {
298
+ box-sizing: border-box;
299
+ display: flex;
246
300
  flex-direction: column;
247
- align-items: stretch;
248
301
  gap: 2px;
249
- box-sizing: border-box;
250
- max-width: min(380px, calc(100vw - 40px));
251
- padding: 8px 6px 8px 12px;
302
+ max-width: min(360px, calc(100vw - 70px));
303
+ padding: 8px 8px 8px 10px;
252
304
  border: 0;
253
305
  --dsw-elevation-stroke-color: var(--dsw-alias-border-l3);
254
306
  border-radius: var(--dsw-radius-lg, 16px);
@@ -257,37 +309,64 @@ window.__ModuleLoader__.load({
257
309
  box-shadow: var(--dsw-elevation-prominent, 0 4px 16px rgba(0, 0, 0, 0.12));
258
310
  font-size: 13px;
259
311
  line-height: 20px;
260
- cursor: grab;
261
- touch-action: none;
262
- user-select: none;
263
312
  pointer-events: auto;
264
- animation: dsh-greeting-in 320ms cubic-bezier(0.22, 0.8, 0.24, 1) 350ms both;
265
313
  }
266
- .dsh-greeting-bubble[data-dragging] {
267
- cursor: grabbing;
268
- }
269
- .dsh-greeting-main {
270
- display: flex;
314
+ .dsh-greeting-card-compact {
315
+ flex-direction: row;
271
316
  align-items: center;
272
317
  gap: 8px;
318
+ padding: 6px 10px;
319
+ cursor: pointer;
320
+ }
321
+ .dsh-greeting-card-compact:hover {
322
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-3) 92%, var(--dsw-alias-label-primary));
323
+ }
324
+ .dsh-greeting-greeting {
273
325
  min-width: 0;
326
+ overflow: hidden;
327
+ text-overflow: ellipsis;
328
+ white-space: nowrap;
329
+ color: var(--dsw-alias-label-secondary);
330
+ font-size: 12px;
331
+ }
332
+ .dsh-greeting-amount {
333
+ flex: none;
334
+ font-size: 13px;
335
+ font-weight: 600;
336
+ color: var(--dsw-alias-label-primary);
337
+ white-space: nowrap;
338
+ }
339
+ .dsh-greeting-widget[data-low] .dsh-greeting-amount {
340
+ color: var(--dsw-alias-state-warn-primary, #b26a00);
274
341
  }
275
- .dsh-greeting-wave {
342
+ .dsh-greeting-dot {
276
343
  flex: none;
277
- font-size: 16px;
278
- line-height: 1;
344
+ width: 6px;
345
+ height: 6px;
346
+ border-radius: 50%;
347
+ background: var(--dsw-alias-state-warn-primary, #b26a00);
279
348
  }
280
- .dsh-greeting-text {
349
+ .dsh-greeting-head {
350
+ display: flex;
351
+ align-items: center;
352
+ gap: 8px;
281
353
  min-width: 0;
282
- overflow-wrap: anywhere;
354
+ padding-left: 2px;
355
+ }
356
+ .dsh-greeting-head-text {
357
+ min-width: 0;
358
+ overflow: hidden;
359
+ text-overflow: ellipsis;
360
+ white-space: nowrap;
361
+ font-size: 13px;
283
362
  }
284
363
  .dsh-greeting-close {
285
364
  flex: none;
286
365
  display: inline-flex;
287
366
  align-items: center;
288
367
  justify-content: center;
289
- width: 26px;
290
- height: 26px;
368
+ width: 24px;
369
+ height: 24px;
291
370
  margin-left: auto;
292
371
  padding: 0;
293
372
  border: 0;
@@ -301,57 +380,16 @@ window.__ModuleLoader__.load({
301
380
  background: var(--dsw-alias-interactive-bg-hover);
302
381
  color: var(--dsw-alias-label-secondary);
303
382
  }
304
- .dsh-greeting-toggle {
305
- display: flex;
306
- align-items: center;
307
- gap: 6px;
308
- margin: 0;
309
- padding: 0 0 0 24px;
310
- border: 0;
311
- border-radius: var(--dsw-radius-xs, 4px);
312
- background: transparent;
313
- color: var(--dsw-alias-label-tertiary);
314
- font: inherit;
315
- font-size: 12px;
316
- line-height: 16px;
317
- text-align: left;
318
- width: fit-content;
319
- max-width: 100%;
320
- cursor: pointer;
321
- pointer-events: auto;
322
- }
323
- .dsh-greeting-toggle:hover {
324
- color: var(--dsw-alias-label-secondary);
325
- }
326
- .dsh-greeting-toggle[data-low] {
327
- color: var(--dsw-alias-state-warn-primary, #b26a00);
328
- }
329
- .dsh-greeting-chevron {
330
- display: inline-block;
331
- transition: transform 120ms ease;
332
- }
333
- .dsh-greeting-toggle[aria-expanded='true'] .dsh-greeting-chevron {
334
- transform: rotate(90deg);
335
- }
336
- .dsh-greeting-warn {
337
- flex: none;
338
- padding: 0 5px;
339
- border-radius: 999px;
340
- background: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #b26a00) 14%, transparent);
341
- font-size: 11px;
342
- line-height: 16px;
343
- }
344
383
  .dsh-greeting-details {
345
384
  display: flex;
346
385
  flex-direction: column;
347
386
  gap: 3px;
348
387
  margin-top: 4px;
349
- padding: 6px 6px 2px 24px;
388
+ padding: 6px 6px 0 2px;
350
389
  border-top: 0.5px solid var(--dsw-alias-border-l3);
351
390
  color: var(--dsw-alias-label-secondary);
352
391
  font-size: 12px;
353
392
  line-height: 17px;
354
- cursor: default;
355
393
  }
356
394
  .dsh-greeting-row {
357
395
  display: flex;
@@ -367,6 +405,11 @@ window.__ModuleLoader__.load({
367
405
  overflow-wrap: anywhere;
368
406
  color: var(--dsw-alias-label-secondary);
369
407
  }
408
+ .dsh-greeting-row-value[data-nowrap] {
409
+ white-space: nowrap;
410
+ overflow: hidden;
411
+ text-overflow: ellipsis;
412
+ }
370
413
  .dsh-greeting-actions {
371
414
  display: flex;
372
415
  flex-wrap: wrap;
@@ -388,7 +431,8 @@ window.__ModuleLoader__.load({
388
431
  text-decoration: underline;
389
432
  }
390
433
  .dsh-greeting-action:focus-visible,
391
- .dsh-greeting-toggle:focus-visible,
434
+ .dsh-greeting-card-compact:focus-visible,
435
+ .dsh-greeting-avatar:focus-visible,
392
436
  .dsh-greeting-close:focus-visible {
393
437
  outline: var(--dsw-focus-ring-width, 2px) solid
394
438
  var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
@@ -404,31 +448,69 @@ window.__ModuleLoader__.load({
404
448
  transform: translateY(0) scale(1);
405
449
  }
406
450
  }
451
+ @keyframes dsh-greeting-blink {
452
+ 0%, 92%, 100% { transform: scaleY(1); }
453
+ 95% { transform: scaleY(0.1); }
454
+ }
455
+ @keyframes dsh-greeting-pulse {
456
+ 0%, 100% { opacity: 0.35; transform: scale(0.8); }
457
+ 50% { opacity: 1; transform: scale(1.15); }
458
+ }
407
459
  @media (prefers-reduced-motion: reduce) {
408
- .dsh-greeting-bubble {
460
+ .dsh-greeting-widget,
461
+ .dsh-greeting-widget:not([data-disconnected]) .dsh-greeting-eyes,
462
+ .dsh-greeting-widget[data-refreshing] .dsh-greeting-antenna-dot {
409
463
  animation: none;
410
464
  }
411
465
  }
412
466
  `;
413
467
 
468
+ /** The little robot beside the card. */
469
+ function RobotAvatar() {
470
+ return h(
471
+ 'svg',
472
+ { viewBox: '0 0 32 32', 'aria-hidden': 'true', focusable: 'false' },
473
+ h('g', { className: 'dsh-greeting-antenna' },
474
+ h('path', { d: 'M16 7V4', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }),
475
+ h('circle', { className: 'dsh-greeting-antenna-dot', cx: 16, cy: 2.6, r: 2, fill: 'currentColor' }),
476
+ ),
477
+ h('rect', { x: 3, y: 12, width: 2.6, height: 7, rx: 1.3, fill: 'currentColor' }),
478
+ h('rect', { x: 26.4, y: 12, width: 2.6, height: 7, rx: 1.3, fill: 'currentColor' }),
479
+ h('rect', { x: 5.5, y: 7.5, width: 21, height: 17, rx: 6.5, fill: 'currentColor' }),
480
+ h('g', { className: 'dsh-greeting-eyes', fill: 'var(--dsw-alias-label-on-color, #ffffff)' },
481
+ h('circle', { className: 'dsh-greeting-eye', cx: 12, cy: 15, r: 2.1 }),
482
+ h('circle', { className: 'dsh-greeting-eye', cx: 20, cy: 15, r: 2.1 }),
483
+ ),
484
+ h('path', {
485
+ d: 'M12 20c1.6 2.2 6.4 2.2 8 0',
486
+ fill: 'none',
487
+ stroke: 'var(--dsw-alias-label-on-color, #ffffff)',
488
+ strokeWidth: 1.6,
489
+ strokeLinecap: 'round',
490
+ }),
491
+ );
492
+ }
493
+
414
494
  /**
415
- * The greeting bubble itself.
495
+ * The greeting widget: robot + speech card, draggable as one unit.
416
496
  *
417
497
  * @param props - the framework `t` seat plus injected balance/profile loaders.
418
- * @returns the bubble, or null once the reader dismissed it.
498
+ * @returns the widget, or null once the reader dismissed it.
419
499
  */
420
500
  function GreetingBubble({ t, loadBalance, loadProfile, connection }) {
421
501
  const [dismissed, setDismissed] = React.useState(false);
422
502
  const [position, setPosition] = React.useState(readPosition);
423
503
  const [dragging, setDragging] = React.useState(false);
504
+ const [expanded, setExpanded] = React.useState(false);
424
505
  const [balance, setBalance] = React.useState(null);
425
506
  const [profile, setProfile] = React.useState(null);
426
507
  const [updatedAt, setUpdatedAt] = React.useState(null);
427
508
  const [spent, setSpent] = React.useState(null);
428
- const [expanded, setExpanded] = React.useState(false);
429
509
  const [privacy, setPrivacy] = React.useState(readPrivacy);
430
- const bubbleRef = React.useRef(null);
510
+ const [refreshing, setRefreshing] = React.useState(false);
511
+ const widgetRef = React.useRef(null);
431
512
  const dragRef = React.useRef(null);
513
+ const suppressClickRef = React.useRef(false);
432
514
  const inFlightRef = React.useRef(null);
433
515
  const profileRef = React.useRef(null);
434
516
  const timerRef = React.useRef(null);
@@ -443,6 +525,7 @@ window.__ModuleLoader__.load({
443
525
  function readBalance() {
444
526
  if (typeof loadBalance !== 'function') return Promise.resolve(null);
445
527
  if (inFlightRef.current !== null) return inFlightRef.current;
528
+ setRefreshing(true);
446
529
  const run = Promise.resolve()
447
530
  .then(() => loadBalance())
448
531
  .then((result) => {
@@ -451,7 +534,10 @@ window.__ModuleLoader__.load({
451
534
  return wallets === null ? null : { wallets, at: Date.now(), spent: trackConsumption(wallets.normal) };
452
535
  })
453
536
  .catch(() => null)
454
- .finally(() => { inFlightRef.current = null; });
537
+ .finally(() => {
538
+ inFlightRef.current = null;
539
+ if (!cancelledRef.current) setRefreshing(false);
540
+ });
455
541
  inFlightRef.current = run;
456
542
  return run;
457
543
  }
@@ -521,7 +607,7 @@ window.__ModuleLoader__.load({
521
607
  React.useEffect(() => {
522
608
  function handleResize() {
523
609
  setPosition((current) => {
524
- const element = bubbleRef.current;
610
+ const element = widgetRef.current;
525
611
  if (current === null || element === null) return current;
526
612
  const x = clamp(current.x, 0, window.innerWidth - element.offsetWidth);
527
613
  const y = clamp(current.y, 0, window.innerHeight - element.offsetHeight);
@@ -550,11 +636,8 @@ window.__ModuleLoader__.load({
550
636
  : connectionState === 'disconnected'
551
637
  ? label('disconnected', '已断开')
552
638
  : label('unavailable', '--');
553
- const spentText = spent === null
554
- ? label('unavailable', '--')
555
- : '≈ ' + currencySymbol('CNY') + formatAmount(spent.spent) + ' '
556
- + label('estimate', '(估算)')
557
- + (typeof spent.startAt === 'number' ? ' · ' + label('baseline', '基准') + ' ' + formatTime(spent.startAt) : '');
639
+ const spentText = spent === null ? label('unavailable', '--') : '≈ ' + currencySymbol('CNY') + formatAmount(spent.spent);
640
+ const collapsedLabel = greeting + ' · ' + amountText;
558
641
 
559
642
  /** Refresh now and reset the backoff. */
560
643
  function handleRefresh() {
@@ -568,7 +651,7 @@ window.__ModuleLoader__.load({
568
651
  }
569
652
 
570
653
  /** Expand/collapse; the first expansion loads the account profile. */
571
- function handleToggle() {
654
+ function toggleExpanded() {
572
655
  setExpanded((current) => {
573
656
  const next = !current;
574
657
  if (next && profile === null) {
@@ -589,11 +672,11 @@ window.__ModuleLoader__.load({
589
672
  });
590
673
  }
591
674
 
592
- /** Start a drag: switch to absolute coordinates and capture the pointer. */
593
- function handlePointerDown(event) {
675
+ /** Suppress the click that follows a drag gesture. */
676
+ function beginDrag(event) {
594
677
  if (event.button !== undefined && event.button !== 0) return;
595
678
  if (event.target && event.target.closest && event.target.closest('button, a')) return;
596
- const element = bubbleRef.current;
679
+ const element = widgetRef.current;
597
680
  if (!element) return;
598
681
  const rect = element.getBoundingClientRect();
599
682
  dragRef.current = {
@@ -604,6 +687,7 @@ window.__ModuleLoader__.load({
604
687
  top: rect.top,
605
688
  width: rect.width,
606
689
  height: rect.height,
690
+ moved: false,
607
691
  };
608
692
  setPosition({ x: rect.left, y: rect.top });
609
693
  setDragging(true);
@@ -614,24 +698,25 @@ window.__ModuleLoader__.load({
614
698
  }
615
699
 
616
700
  /** Move within the viewport while the pointer is captured. */
617
- function handlePointerMove(event) {
701
+ function moveDrag(event) {
618
702
  const drag = dragRef.current;
619
703
  if (drag === null || event.pointerId !== drag.pointerId) return;
620
- const x = drag.left + event.clientX - drag.startX;
621
- const y = drag.top + event.clientY - drag.startY;
704
+ const dx = event.clientX - drag.startX;
705
+ const dy = event.clientY - drag.startY;
706
+ if (!drag.moved && Math.abs(dx) + Math.abs(dy) > DRAG_THRESHOLD) drag.moved = true;
622
707
  setPosition({
623
- x: clamp(x, 0, window.innerWidth - drag.width),
624
- y: clamp(y, 0, window.innerHeight - drag.height),
708
+ x: clamp(drag.left + dx, 0, window.innerWidth - drag.width),
709
+ y: clamp(drag.top + dy, 0, window.innerHeight - drag.height),
625
710
  });
626
711
  }
627
712
 
628
713
  /** Finish a drag, clamp once more, and persist the dropped spot. */
629
- function handlePointerUp(event) {
714
+ function endDrag(event) {
630
715
  const drag = dragRef.current;
631
716
  if (drag === null || event.pointerId !== drag.pointerId) return;
632
717
  dragRef.current = null;
633
718
  setDragging(false);
634
- const element = bubbleRef.current;
719
+ const element = widgetRef.current;
635
720
  if (!element) return;
636
721
  const rect = element.getBoundingClientRect();
637
722
  const dropped = {
@@ -640,75 +725,89 @@ window.__ModuleLoader__.load({
640
725
  };
641
726
  setPosition(dropped);
642
727
  writePosition(dropped);
728
+ if (drag.moved) {
729
+ suppressClickRef.current = true;
730
+ window.setTimeout(() => { suppressClickRef.current = false; }, 0);
731
+ }
732
+ }
733
+
734
+ /** Toggle the card, ignoring the click that ends a drag and inner controls. */
735
+ function handleCardClick(event) {
736
+ if (suppressClickRef.current) return;
737
+ if (event.target && event.target.closest && event.target.closest('button, a')) return;
738
+ toggleExpanded();
739
+ }
740
+
741
+ /** Keyboard activation for the compact card. */
742
+ function handleCardKeyDown(event) {
743
+ if (event.key !== 'Enter' && event.key !== ' ') return;
744
+ event.preventDefault();
745
+ toggleExpanded();
643
746
  }
644
747
 
645
748
  return h(
646
749
  'div',
647
- { className: 'dsh-greeting-layer', style: { position: 'absolute', inset: 0, pointerEvents: 'none' } },
648
- h('style', { key: 'styles' }, STYLES),
750
+ {
751
+ className: 'dsh-greeting-widget',
752
+ ref: widgetRef,
753
+ 'data-dragging': dragging ? '' : undefined,
754
+ 'data-expanded': expanded ? '' : undefined,
755
+ 'data-low': low ? '' : undefined,
756
+ 'data-refreshing': refreshing ? '' : undefined,
757
+ 'data-disconnected': connectionState === 'disconnected' ? '' : undefined,
758
+ style: position === null
759
+ ? undefined
760
+ : { left: position.x, top: position.y, right: 'auto', bottom: 'auto' },
761
+ onPointerDown: beginDrag,
762
+ onPointerMove: moveDrag,
763
+ onPointerUp: endDrag,
764
+ onPointerCancel: endDrag,
765
+ },
649
766
  h(
650
- 'div',
767
+ 'button',
651
768
  {
652
- key: 'bubble',
653
- ref: bubbleRef,
654
- className: 'dsh-greeting-bubble',
655
- 'data-dragging': dragging ? '' : undefined,
656
- style: position === null
657
- ? undefined
658
- : { left: position.x, top: position.y, right: 'auto', bottom: 'auto' },
659
- onPointerDown: handlePointerDown,
660
- onPointerMove: handlePointerMove,
661
- onPointerUp: handlePointerUp,
662
- onPointerCancel: handlePointerUp,
769
+ className: 'dsh-greeting-avatar',
770
+ type: 'button',
771
+ title: greeting,
772
+ 'aria-label': greeting,
773
+ 'aria-expanded': expanded ? 'true' : 'false',
774
+ onClick: toggleExpanded,
663
775
  },
664
- h(
776
+ h(RobotAvatar),
777
+ ),
778
+ expanded
779
+ ? h(
665
780
  'div',
666
- { className: 'dsh-greeting-main', key: 'main' },
667
- h('span', { className: 'dsh-greeting-wave', 'aria-hidden': 'true' }, '👋'),
668
- h('span', { className: 'dsh-greeting-text', role: 'status', lang: 'zh-CN' }, greeting),
781
+ { className: 'dsh-greeting-card', key: 'card' },
669
782
  h(
670
- 'button',
671
- {
672
- className: 'dsh-greeting-close',
673
- type: 'button',
674
- title: dismissLabel,
675
- 'aria-label': dismissLabel,
676
- onClick: () => { setDismissed(true); },
677
- },
783
+ 'div',
784
+ { className: 'dsh-greeting-head' },
785
+ h('span', { className: 'dsh-greeting-head-text', role: 'status', lang: 'zh-CN' }, greeting),
678
786
  h(
679
- 'svg',
680
- { width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
681
- h('path', {
682
- d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
683
- fill: 'none',
684
- stroke: 'currentColor',
685
- strokeWidth: 1.4,
686
- strokeLinecap: 'round',
687
- }),
787
+ 'button',
788
+ {
789
+ className: 'dsh-greeting-close',
790
+ type: 'button',
791
+ title: dismissLabel,
792
+ 'aria-label': dismissLabel,
793
+ onClick: () => { setDismissed(true); },
794
+ },
795
+ h(
796
+ 'svg',
797
+ { width: 12, height: 12, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
798
+ h('path', {
799
+ d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
800
+ fill: 'none',
801
+ stroke: 'currentColor',
802
+ strokeWidth: 1.4,
803
+ strokeLinecap: 'round',
804
+ }),
805
+ ),
688
806
  ),
689
807
  ),
690
- ),
691
- h(
692
- 'button',
693
- {
694
- key: 'toggle',
695
- className: 'dsh-greeting-toggle',
696
- type: 'button',
697
- 'data-low': low ? '' : undefined,
698
- 'aria-expanded': expanded ? 'true' : 'false',
699
- title: label('details', '展开详情'),
700
- onClick: handleToggle,
701
- },
702
- h('span', { className: 'dsh-greeting-chevron', 'aria-hidden': 'true' }, '▸'),
703
- h('span', null, label('balance', '余额') + ' ' + amountText),
704
- low
705
- ? h('span', { className: 'dsh-greeting-warn' }, label('lowBalance', '余额不足'))
706
- : null,
707
- ),
708
- expanded
709
- ? h(
808
+ h(
710
809
  'div',
711
- { className: 'dsh-greeting-details', key: 'details' },
810
+ { className: 'dsh-greeting-details' },
712
811
  h(
713
812
  'div',
714
813
  { className: 'dsh-greeting-row' },
@@ -718,7 +817,7 @@ window.__ModuleLoader__.load({
718
817
  h(
719
818
  'div',
720
819
  { className: 'dsh-greeting-row' },
721
- h('span', { className: 'dsh-greeting-row-label' }, label('topUpBalance', '充值')),
820
+ h('span', { className: 'dsh-greeting-row-label' }, label('topUpBalance', '充值余额')),
722
821
  h('span', { className: 'dsh-greeting-row-value' }, privacy ? label('hidden', '••••') : (normalText ?? label('unavailable', '--'))),
723
822
  ),
724
823
  h(
@@ -737,7 +836,7 @@ window.__ModuleLoader__.load({
737
836
  'div',
738
837
  { className: 'dsh-greeting-row' },
739
838
  h('span', { className: 'dsh-greeting-row-label' }, label('today', '今日消费金额')),
740
- h('span', { className: 'dsh-greeting-row-value' }, spentText),
839
+ h('span', { className: 'dsh-greeting-row-value', 'data-nowrap': '' }, spentText),
741
840
  ),
742
841
  h(
743
842
  'div',
@@ -762,9 +861,24 @@ window.__ModuleLoader__.load({
762
861
  h('a', { className: 'dsh-greeting-action', href: USAGE_URL, target: '_blank', rel: 'noreferrer' }, label('usage', '用量')),
763
862
  h('a', { className: 'dsh-greeting-action', href: TOP_UP_URL, target: '_blank', rel: 'noreferrer' }, label('topUp', '充值')),
764
863
  ),
765
- )
766
- : null,
767
- ),
864
+ ),
865
+ )
866
+ : h(
867
+ 'div',
868
+ {
869
+ className: 'dsh-greeting-card dsh-greeting-card-compact',
870
+ key: 'compact',
871
+ role: 'button',
872
+ tabIndex: 0,
873
+ 'aria-label': collapsedLabel,
874
+ 'aria-expanded': 'false',
875
+ onClick: handleCardClick,
876
+ onKeyDown: handleCardKeyDown,
877
+ },
878
+ h('span', { className: 'dsh-greeting-greeting', role: 'status', lang: 'zh-CN' }, greeting),
879
+ h('span', { className: 'dsh-greeting-amount' }, amountText),
880
+ low ? h('span', { className: 'dsh-greeting-dot', 'aria-hidden': 'true' }) : null,
881
+ ),
768
882
  );
769
883
  }
770
884
 
@@ -787,7 +901,6 @@ window.__ModuleLoader__.load({
787
901
  greetingEvening: '晚上好,腾盛',
788
902
  dismiss: '关闭问候气泡',
789
903
  balance: '余额',
790
- bonus: '赠送',
791
904
  topUpBalance: '充值余额',
792
905
  account: '账户',
793
906
  connection: '连接',
@@ -797,12 +910,9 @@ window.__ModuleLoader__.load({
797
910
  reconnect: '重连',
798
911
  updated: '更新',
799
912
  today: '今日消费金额',
800
- estimate: '(估算)',
801
- baseline: '基准',
802
913
  hidden: '••••',
803
914
  unavailable: '--',
804
915
  lowBalance: '余额不足',
805
- details: '展开详情',
806
916
  refresh: '刷新',
807
917
  hideAmount: '隐藏金额',
808
918
  showAmount: '显示金额',
@@ -817,7 +927,6 @@ window.__ModuleLoader__.load({
817
927
  greetingEvening: '你好,腾盛',
818
928
  dismiss: 'Dismiss greeting',
819
929
  balance: 'Balance',
820
- bonus: 'Bonus',
821
930
  topUpBalance: 'Top-up balance',
822
931
  account: 'Account',
823
932
  connection: 'Connection',
@@ -827,12 +936,9 @@ window.__ModuleLoader__.load({
827
936
  reconnect: 'Reconnect',
828
937
  updated: 'Updated',
829
938
  today: "Today's spend",
830
- estimate: '(estimate)',
831
- baseline: 'baseline',
832
939
  hidden: '••••',
833
940
  unavailable: '--',
834
941
  lowBalance: 'Low balance',
835
- details: 'Show details',
836
942
  refresh: 'Refresh',
837
943
  hideAmount: 'Hide amounts',
838
944
  showAmount: 'Show amounts',
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
- {
1
+ {
2
2
  "meta": {
3
- "description": "Shows a time-aware “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer (morning/noon/afternoon/evening variants), plus the signed-in DeepSeek account balance refreshed every 60 seconds. A balance below 3 CNY is flagged. Click the balance line to expand details: account, connection state with a one-click reconnect, today's spend estimate (balance delta, ignoring top-ups; spending before the plugin was installed cannot be counted, and the baseline time is shown), top-up balance, last update, and shortcuts to the Platform usage/top-up pages; a privacy toggle hides amounts, and drag remembers the bubble position. Click × to dismiss it; it appears again on the next page load. Control labels are localized; the greeting stays Chinese. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “--”. The plugin makes no network requests of its own and collects no data. Disable or remove the bundle under Plugins to remove it.",
3
+ "description": "A small robot with a collapsing pill (greeting · balance) appears near the bottom-right corner of the window, just above the message composer; click the robot or pill to expand details: account, connection state with a one-click reconnect, today's spend estimate (balance delta, ignoring top-ups; spending before the plugin was installed cannot be counted), top-up balance, last update, and shortcuts to the Platform usage/top-up pages; a privacy toggle hides amounts, and drag remembers the bubble position. Click × to dismiss it; it appears again on the next page load. Control labels are localized; the greeting stays Chinese. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “--”. The plugin makes no network requests of its own and collects no data. Disable or remove the bundle under Plugins to remove it.",
4
4
  "detail": "docs/DETAIL.md"
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
- {
1
+ {
2
2
  "meta": {
3
- "description": "页面加载后,在窗口右下角、输入框上方弹出按时间变化的问候气泡(早上好/中午好/下午好/晚上好,腾盛),并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次。余额低于 3 元会显示提醒;点击余额行展开详情:账户信息、连接状态(断开时可一键重连)、今日消费金额估算(基于余额差,忽略充值;安装插件之前的消费无法统计,详情里会显示基准时间)、充值余额、更新时间,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
3
+ "description": "页面加载后,在窗口右下角、输入框上方出现小机器人 + 折叠胶囊(问候语 · 余额),点击机器人或胶囊展开详情:账户信息、连接状态(断开时可一键重连)、今日消费金额估算(基于余额差,忽略充值;安装插件之前的消费无法统计)、充值余额、更新时间,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
4
4
  "detail": "docs/DETAIL.zh.md"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-greeting-bubble",
3
- "version": "1.4.1",
3
+ "version": "1.5.0-beta.0",
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": {