dsh-plugin-greeting-bubble 1.3.0-beta.0 → 1.4.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
@@ -28,10 +28,10 @@
28
28
 
29
29
  ## 效果
30
30
 
31
- - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 你好,腾盛 ×
31
+ - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 早上好/中午好/下午好/晚上好,腾盛 ×(按当前时间变化)
32
32
  - **第二行显示账号余额**:`余额 ¥12.34`,来自当前登录的 DeepSeek 账号;每 60 秒刷新一次。
33
33
  - **余额低于 3 元**时,这一行变橙并显示「余额不足」提醒。
34
- - **点余额这一行展开详情**:账户名/联系方式、充值余额、赠送余额、最近更新时间、插件版本,以及「用量」「充值」快捷入口;再点一次收起。
34
+ - **点余额这一行展开详情**:账户名/联系方式、**当前会话标题与模型**、**连接状态(断开时可一键重连)**、**今日消耗估算(标注“估算”)**、充值余额、赠送余额、最近更新时间、插件版本,以及「用量」「充值」快捷入口;再点一次收起。
35
35
  - 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
36
36
  - 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
37
37
  - 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
@@ -92,7 +92,8 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
92
92
  | --- | --- |
93
93
  | 页面加载 | 气泡出现(每个页面视图一次),并读取一次余额 |
94
94
  | **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
95
- | **点余额那一行** | 展开/收起详情(账户、钱包明细、更新时间、版本、快捷入口) |
95
+ | **点余额那一行** | 展开/收起详情(账户、会话、连接、今日估算、钱包明细、更新时间、版本、快捷入口) |
96
+ | 详情里的「重连」 | 连接断开时出现,点击立即重连 Host |
96
97
  | 详情里的「刷新」 | 立即刷新余额(不用等 60 秒) |
97
98
  | 详情里的「隐藏金额 / 显示金额」 | 切换隐私模式并记住 |
98
99
  | 余额低于 ¥3 | 余额行变橙并显示「余额不足」 |
package/client.js CHANGED
@@ -46,6 +46,9 @@ window.__ModuleLoader__.load({
46
46
  /** Below this CNY amount the bubble warns. */
47
47
  const LOW_BALANCE_CNY = 3;
48
48
 
49
+ /** Local-day consumption baseline; reset when the date changes. */
50
+ const CONSUMPTION_KEY = 'dsh-greeting-bubble:consumption:v1';
51
+
49
52
  /** Platform pages linked from the details panel. */
50
53
  const USAGE_URL = 'https://platform.deepseek.com/usage';
51
54
  const TOP_UP_URL = 'https://platform.deepseek.com/top_up';
@@ -148,6 +151,93 @@ window.__ModuleLoader__.load({
148
151
  return new Date(timestamp).toLocaleTimeString();
149
152
  }
150
153
 
154
+ /** Today key in local time, used to reset the consumption baseline. */
155
+ function localDateKey() {
156
+ const now = new Date();
157
+ return now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0');
158
+ }
159
+
160
+ /** Estimated CNY spent today, measured from the first balance this plugin saw today. */
161
+ function trackConsumption(normal) {
162
+ const cny = (normal ?? []).find((wallet) => wallet.currency === 'CNY' && typeof wallet.balance === 'string');
163
+ if (!cny) return null;
164
+ const amount = Number(cny.balance);
165
+ if (!Number.isFinite(amount)) return null;
166
+ const today = localDateKey();
167
+ let stored = null;
168
+ try {
169
+ stored = JSON.parse(window.localStorage.getItem(CONSUMPTION_KEY) || 'null');
170
+ } catch {
171
+ stored = null;
172
+ }
173
+ let baseline = stored && stored.date === today && typeof stored.baseline === 'number' ? stored.baseline : amount;
174
+ if (amount > baseline) baseline = amount;
175
+ const spent = Math.max(0, baseline - amount);
176
+ try {
177
+ window.localStorage.setItem(CONSUMPTION_KEY, JSON.stringify({ date: today, baseline }));
178
+ } catch {
179
+ // Storage unavailable: the estimate simply does not survive the reload.
180
+ }
181
+ return spent;
182
+ }
183
+
184
+ /** Greeting key by local hour. */
185
+ function greetingKeyForHour(hour) {
186
+ if (hour >= 5 && hour < 11) return 'greetingMorning';
187
+ if (hour >= 11 && hour < 13) return 'greetingNoon';
188
+ if (hour >= 13 && hour < 18) return 'greetingAfternoon';
189
+ return 'greetingEvening';
190
+ }
191
+
192
+ /** Latest session title/model reported by the probe mounted in a session slot. */
193
+ const sessionInfoStore = (() => {
194
+ let value = null;
195
+ const listeners = new Set();
196
+ return {
197
+ get: () => value,
198
+ set(next) {
199
+ const same = next === null
200
+ ? value === null
201
+ : value !== null && next.sessionId === value.sessionId && next.title === value.title && next.model === value.model;
202
+ if (same) return;
203
+ value = next;
204
+ for (const listener of listeners) listener();
205
+ },
206
+ subscribe(listener) {
207
+ listeners.add(listener);
208
+ return () => { listeners.delete(listener); };
209
+ },
210
+ };
211
+ })();
212
+
213
+ /** Subscribe to a host observable (or read it once when unavailable). */
214
+ function useObservable(source) {
215
+ const subscribe = source && typeof source.subscribe === 'function' ? source.subscribe.bind(source) : null;
216
+ const get = source && typeof source.getSnapshot === 'function' ? source.getSnapshot.bind(source) : () => undefined;
217
+ if (typeof React.useSyncExternalStore === 'function' && subscribe !== null) {
218
+ return React.useSyncExternalStore(subscribe, get, get);
219
+ }
220
+ return get();
221
+ }
222
+
223
+ /**
224
+ * Session-scoped probe: reports the current session title and selected
225
+ * model to the overlay. Rendered inside `conversation.input.dock`, so it
226
+ * mounts only while a session is open and costs no visible space.
227
+ */
228
+ function SessionProbe({ sessionId, useProjection, useSessions }) {
229
+ const modelSelection = typeof useProjection === 'function' ? useProjection('modelSelection') : null;
230
+ const list = typeof useSessions === 'function' ? useSessions((state) => state) : null;
231
+ const summary = list && list.byId && sessionId ? list.byId[sessionId] : null;
232
+ const title = summary && summary.displayTitle ? summary.displayTitle : null;
233
+ const model = modelSelection && typeof modelSelection.model === 'string' ? modelSelection.model : null;
234
+ React.useEffect(() => {
235
+ sessionInfoStore.set(sessionId ? { sessionId, title, model } : null);
236
+ return () => { sessionInfoStore.set(null); };
237
+ }, [sessionId, title, model]);
238
+ return null;
239
+ }
240
+
151
241
  /**
152
242
  * Component-local stylesheet; unmounting the entry removes it with the
153
243
  * node.
@@ -338,13 +428,14 @@ window.__ModuleLoader__.load({
338
428
  * @param props - the framework `t` seat plus injected balance/profile loaders.
339
429
  * @returns the bubble, or null once the reader dismissed it.
340
430
  */
341
- function GreetingBubble({ t, loadBalance, loadProfile }) {
431
+ function GreetingBubble({ t, loadBalance, loadProfile, connection }) {
342
432
  const [dismissed, setDismissed] = React.useState(false);
343
433
  const [position, setPosition] = React.useState(readPosition);
344
434
  const [dragging, setDragging] = React.useState(false);
345
435
  const [balance, setBalance] = React.useState(null);
346
436
  const [profile, setProfile] = React.useState(null);
347
437
  const [updatedAt, setUpdatedAt] = React.useState(null);
438
+ const [spent, setSpent] = React.useState(null);
348
439
  const [expanded, setExpanded] = React.useState(false);
349
440
  const [privacy, setPrivacy] = React.useState(readPrivacy);
350
441
  const bubbleRef = React.useRef(null);
@@ -356,6 +447,9 @@ window.__ModuleLoader__.load({
356
447
  const cancelledRef = React.useRef(false);
357
448
 
358
449
  const label = (key, fallback) => (typeof t === 'function' ? t(key) : fallback);
450
+ const sessionInfo = useObservable(sessionInfoStore);
451
+ const connectionState = useObservable(connection && connection.state);
452
+ const canReconnect = Boolean(connection && typeof connection.reconnect === 'function');
359
453
 
360
454
  /** Fetch once, deduplicating concurrent calls. */
361
455
  function readBalance() {
@@ -366,7 +460,7 @@ window.__ModuleLoader__.load({
366
460
  .then((result) => {
367
461
  if (!result || result.ok !== true) return null;
368
462
  const wallets = normalizeBalance(result.value);
369
- return wallets === null ? null : { wallets, at: Date.now() };
463
+ return wallets === null ? null : { wallets, at: Date.now(), spent: trackConsumption(wallets.normal) };
370
464
  })
371
465
  .catch(() => null)
372
466
  .finally(() => { inFlightRef.current = null; });
@@ -405,6 +499,7 @@ window.__ModuleLoader__.load({
405
499
  if (result !== null) {
406
500
  setBalance(result.wallets);
407
501
  setUpdatedAt(result.at);
502
+ setSpent(result.spent);
408
503
  }
409
504
  backoffRef.current = result === null
410
505
  ? Math.min(backoffRef.current * 2, BALANCE_MAX_BACKOFF_MS)
@@ -450,7 +545,7 @@ window.__ModuleLoader__.load({
450
545
  }, []);
451
546
 
452
547
  if (dismissed) return null;
453
- const greeting = label('greeting', '你好,腾盛');
548
+ const greeting = label(greetingKeyForHour(new Date().getHours()), '你好,腾盛');
454
549
  const dismissLabel = label('dismiss', '关闭问候气泡');
455
550
  const normalText = balance === null ? null : formatWallets(balance.normal);
456
551
  const bonusText = balance === null ? null : formatWallets(balance.bonus);
@@ -461,6 +556,19 @@ window.__ModuleLoader__.load({
461
556
  const accountText = profile && (profile.name || profile.contact)
462
557
  ? [profile.name, profile.contact].filter(Boolean).join(' · ')
463
558
  : label('unavailable', '--');
559
+ const sessionText = sessionInfo && (sessionInfo.title || sessionInfo.model)
560
+ ? [sessionInfo.title, sessionInfo.model].filter(Boolean).join(' · ')
561
+ : label('unavailable', '--');
562
+ const connectionText = connectionState === 'connected'
563
+ ? label('connected', '已连接')
564
+ : connectionState === 'connecting'
565
+ ? label('connecting', '重连中')
566
+ : connectionState === 'disconnected'
567
+ ? label('disconnected', '已断开')
568
+ : label('unavailable', '--');
569
+ const spentText = spent === null
570
+ ? label('unavailable', '--')
571
+ : '≈ ' + currencySymbol('CNY') + formatAmount(spent);
464
572
 
465
573
  /** Refresh now and reset the backoff. */
466
574
  function handleRefresh() {
@@ -469,6 +577,7 @@ window.__ModuleLoader__.load({
469
577
  if (cancelledRef.current || result === null) return;
470
578
  setBalance(result.wallets);
471
579
  setUpdatedAt(result.at);
580
+ setSpent(result.spent);
472
581
  });
473
582
  }
474
583
 
@@ -620,6 +729,12 @@ window.__ModuleLoader__.load({
620
729
  h('span', { className: 'dsh-greeting-row-label' }, label('account', '账户')),
621
730
  h('span', { className: 'dsh-greeting-row-value' }, accountText),
622
731
  ),
732
+ h(
733
+ 'div',
734
+ { className: 'dsh-greeting-row' },
735
+ h('span', { className: 'dsh-greeting-row-label' }, label('session', '会话')),
736
+ h('span', { className: 'dsh-greeting-row-value' }, sessionText),
737
+ ),
623
738
  h(
624
739
  'div',
625
740
  { className: 'dsh-greeting-row' },
@@ -638,9 +753,28 @@ window.__ModuleLoader__.load({
638
753
  h('span', { className: 'dsh-greeting-row-label' }, label('updated', '更新')),
639
754
  h('span', { className: 'dsh-greeting-row-value' }, formatTime(updatedAt) + ' · v' + PLUGIN_VERSION),
640
755
  ),
756
+ h(
757
+ 'div',
758
+ { className: 'dsh-greeting-row' },
759
+ h('span', { className: 'dsh-greeting-row-label' }, label('connection', '连接')),
760
+ h('span', { className: 'dsh-greeting-row-value' }, connectionText),
761
+ ),
762
+ h(
763
+ 'div',
764
+ { className: 'dsh-greeting-row' },
765
+ h('span', { className: 'dsh-greeting-row-label' }, label('today', '今日')),
766
+ h('span', { className: 'dsh-greeting-row-value' }, spentText + ' ' + label('estimate', '(估算)')),
767
+ ),
641
768
  h(
642
769
  'div',
643
770
  { className: 'dsh-greeting-actions' },
771
+ canReconnect && connectionState !== 'connected'
772
+ ? h(
773
+ 'button',
774
+ { className: 'dsh-greeting-action', type: 'button', onClick: () => { connection.reconnect(); } },
775
+ label('reconnect', '重连'),
776
+ )
777
+ : null,
644
778
  h(
645
779
  'button',
646
780
  { className: 'dsh-greeting-action', type: 'button', onClick: handleRefresh },
@@ -661,7 +795,7 @@ window.__ModuleLoader__.load({
661
795
  }
662
796
 
663
797
  return {
664
- inject: ['slots', 'locale', 'remote', 'remote.account'],
798
+ inject: ['slots', 'locale', 'remote', 'remote.account', 'connection'],
665
799
  /**
666
800
  * Register the plugin's dictionary and its single overlay entry.
667
801
  * @param ctx - client plugin context.
@@ -673,13 +807,25 @@ window.__ModuleLoader__.load({
673
807
  // identical in every locale; only control labels are localized.
674
808
  zh: {
675
809
  greeting: '你好,腾盛',
810
+ greetingMorning: '早上好,腾盛',
811
+ greetingNoon: '中午好,腾盛',
812
+ greetingAfternoon: '下午好,腾盛',
813
+ greetingEvening: '晚上好,腾盛',
676
814
  dismiss: '关闭问候气泡',
677
815
  balance: '余额',
678
816
  bonus: '赠送',
679
817
  topUpBalance: '充值',
680
818
  bonusBalance: '赠送',
681
819
  account: '账户',
820
+ session: '会话',
821
+ connection: '连接',
822
+ connected: '已连接',
823
+ connecting: '重连中',
824
+ disconnected: '已断开',
825
+ reconnect: '重连',
682
826
  updated: '更新',
827
+ today: '今日',
828
+ estimate: '(估算)',
683
829
  hidden: '••••',
684
830
  unavailable: '--',
685
831
  lowBalance: '余额不足',
@@ -692,13 +838,25 @@ window.__ModuleLoader__.load({
692
838
  },
693
839
  en: {
694
840
  greeting: '你好,腾盛',
841
+ greetingMorning: '你好,腾盛',
842
+ greetingNoon: '你好,腾盛',
843
+ greetingAfternoon: '你好,腾盛',
844
+ greetingEvening: '你好,腾盛',
695
845
  dismiss: 'Dismiss greeting',
696
846
  balance: 'Balance',
697
847
  bonus: 'Bonus',
698
848
  topUpBalance: 'Top-up',
699
849
  bonusBalance: 'Bonus',
700
850
  account: 'Account',
851
+ session: 'Session',
852
+ connection: 'Connection',
853
+ connected: 'Connected',
854
+ connecting: 'Reconnecting',
855
+ disconnected: 'Disconnected',
856
+ reconnect: 'Reconnect',
701
857
  updated: 'Updated',
858
+ today: 'Today',
859
+ estimate: '(estimate)',
702
860
  hidden: '••••',
703
861
  unavailable: '--',
704
862
  lowBalance: 'Low balance',
@@ -741,12 +899,17 @@ window.__ModuleLoader__.load({
741
899
  if (typeof account.getProfile !== 'function') throw new Error('profile unavailable');
742
900
  return account.getProfile(metadata());
743
901
  };
902
+ ctx.slots.inject('conversation.input.dock', () => ctx.slots.register({
903
+ name: 'conversation.input.dock',
904
+ id: 'greeting-bubble.session',
905
+ order: 100,
906
+ }, SessionProbe));
744
907
  ctx.slots.inject('shell.overlay', () => ctx.slots.register({
745
908
  name: 'shell.overlay',
746
909
  id: 'greeting-bubble',
747
910
  order: 50,
748
911
  locale: NS,
749
- inject: () => ({ loadBalance, loadProfile }),
912
+ inject: () => ({ loadBalance, loadProfile, connection: ctx.connection }),
750
913
  }, GreetingBubble));
751
914
  },
752
915
  };
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
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. A balance below 3 CNY is flagged. Click the balance line to expand details: account, wallet breakdown, last update, plugin version, 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. 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 “--”. 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": "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, current session title and model, connection state with a one-click reconnect, today's spending estimate (explicitly marked as an estimate), wallet breakdown, last update, plugin version, 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": "页面加载后,在窗口右下角、输入框上方弹出按时间变化的问候气泡(早上好/中午好/下午好/晚上好,腾盛),并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次。余额低于 3 元会显示提醒;点击余额行展开详情:账户信息、当前会话标题与模型、连接状态(断开时可一键重连)、今日消耗估算(明确标注估算)、充值/赠送明细、更新时间、插件版本,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 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.3.0-beta.0",
3
+ "version": "1.4.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": {