@v587d/capital-generation 2.24.0 → 2.26.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +9 -4
  3. package/THIRD_PARTY_NOTICES.md +20 -0
  4. package/automation/brief.js +21 -24
  5. package/automation/builtins.js +55 -54
  6. package/automation/client.js +11 -3
  7. package/automation/client.src.cjs +70 -8
  8. package/automation/package.json +1 -1
  9. package/chart-ui/package.json +1 -1
  10. package/config/client.js +21 -5
  11. package/config/client.src.cjs +264 -0
  12. package/config/package.json +1 -1
  13. package/cordis.patch.yml +9 -2
  14. package/lib/agents/role-tool-policy.d.ts +1 -1
  15. package/lib/agents/root-tool-policy.d.ts +3 -3
  16. package/lib/agents/root-tool-policy.js +2 -2
  17. package/lib/data-collector/catalog-taxonomy.js +4 -0
  18. package/lib/python-runtime/child-env.d.ts +11 -0
  19. package/lib/python-runtime/child-env.js +39 -0
  20. package/lib/python-runtime/errors.d.ts +8 -0
  21. package/lib/python-runtime/errors.js +34 -0
  22. package/lib/python-runtime/lock.d.ts +11 -0
  23. package/lib/python-runtime/lock.js +68 -0
  24. package/lib/python-runtime/manager.d.ts +61 -0
  25. package/lib/python-runtime/manager.js +517 -0
  26. package/lib/python-runtime/manifest.d.ts +5 -0
  27. package/lib/python-runtime/manifest.js +160 -0
  28. package/lib/python-runtime/paths.d.ts +20 -0
  29. package/lib/python-runtime/paths.js +156 -0
  30. package/lib/python-runtime/platform.d.ts +32 -0
  31. package/lib/python-runtime/platform.js +145 -0
  32. package/lib/python-runtime/pnpm.d.ts +24 -0
  33. package/lib/python-runtime/pnpm.js +115 -0
  34. package/lib/python-runtime/probe.d.ts +13 -0
  35. package/lib/python-runtime/probe.js +101 -0
  36. package/lib/python-runtime/routes.d.ts +6 -0
  37. package/lib/python-runtime/routes.js +152 -0
  38. package/lib/python-runtime/types.d.ts +105 -0
  39. package/lib/python-runtime/types.js +3 -0
  40. package/lib/python-runtime-entry.d.ts +10 -0
  41. package/lib/python-runtime-entry.js +60 -0
  42. package/lib/sources/eastmoney-http.js +346 -1
  43. package/lib/sources/tencent-http.js +248 -2
  44. package/lib/sources/tencent-public-core.js +1 -1
  45. package/lib/sources-entry.d.ts +1 -1
  46. package/lib/time/tools.js +2 -0
  47. package/lib/web-retriever/local-fetch.d.ts +1 -1
  48. package/lib/web-retriever/local-fetch.js +1 -1
  49. package/lib/web-retriever/sources.d.ts +16 -1
  50. package/lib/web-retriever/sources.js +133 -1
  51. package/lib/web-retriever/tools.js +41 -1
  52. package/lib/web-retriever/wind-client.d.ts +1 -1
  53. package/lib/web-retriever/wind-client.js +1 -1
  54. package/package.json +13 -1
  55. package/plugin-page/README.en.md +1 -7
  56. package/plugin-page/README.zh.md +1 -8
  57. package/preset/capital-generation/agent.patch.yml +12 -13
  58. package/preset/capital-generation/skills/capital-web-protocol/SKILL.md +10 -4
  59. package/python/worker.py +154 -0
  60. package/runtime/manifest.json +75 -0
  61. package/scripts/python-runtime.mjs +139 -0
  62. package/watchlist/client.js +83 -3
  63. package/watchlist/client.src.cjs +565 -1
  64. package/watchlist/package.json +1 -1
@@ -5,7 +5,7 @@
5
5
  * fetches while closed. No turn-tail slot and no custom session events (closed
6
6
  * vocabulary, AGENTS.md §7). Only the search debounce is a timer.
7
7
  */
8
- const { createElement: h, useEffect, useState } = require('react')
8
+ const { createElement: h, useEffect, useRef, useState } = require('react')
9
9
  const { createSnapshotStore } = require('@deepseek-ai/dsh-client-store')
10
10
  // Official icons only; the set has no wallet/pie/coin glyph, so stepper keys use text −/+.
11
11
  // `MenuItemButton` gives the remove row official geometry and its separator line.
@@ -111,6 +111,48 @@ const zh = {
111
111
  'partial.a-share': 'A 股检索不可用:',
112
112
  'partial.hk': '港股检索不可用:',
113
113
  'partial.us': '美股检索不可用:',
114
+ /* 行情工作台(左侧栏入口 + 主面板);只读现有报价,不新增数据源。 */
115
+ 'desk.panel': '自选股',
116
+ 'desk.title': '自选股行情工作台',
117
+ 'desk.refresh': '刷新行情',
118
+ 'desk.refreshing': '刷新中…',
119
+ 'desk.loading': '正在读取自选股…',
120
+ 'desk.lastUpdate': '最近更新',
121
+ 'desk.notRefreshed': '未刷新',
122
+ 'desk.filter': '筛选标的',
123
+ 'desk.filterPlaceholder': '名称或代码',
124
+ 'desk.group': '分组',
125
+ 'desk.allGroups': '全部',
126
+ 'desk.newGroup': '分组名称',
127
+ 'desk.createGroup': '新建',
128
+ 'desk.deleteGroup': '删除分组',
129
+ 'desk.noGroup': '未分组',
130
+ 'desk.more': '更多操作',
131
+ 'desk.noGroupYet': '还没有分组',
132
+ 'desk.pin': '置顶',
133
+ 'desk.remove': '移除',
134
+ 'desk.removeHint': '再点一次删除按钮确认移除',
135
+ 'desk.cancel': '取消',
136
+ 'desk.empty': '还没有自选股',
137
+ 'desk.emptyHint': '用输入框的「自选股」面板添加标的,这里会同步显示。',
138
+ 'desk.noMatch': '没有匹配的标的',
139
+ 'desk.noMatchHint': '换个关键词,或切回「全部」分组。',
140
+ 'desk.selectHint': '选择一只标的查看详情',
141
+ 'desk.selectHintBody': '左侧列表按分组筛选;选中后这里显示报价、分时与成交量。',
142
+ 'desk.intraday': '当日分时',
143
+ 'desk.intradayEmpty': '当前行情接口只返回最新快照',
144
+ 'desk.intradayEmptyHint': '接入分时序列后,这里直接绘制当日走势。',
145
+ 'desk.volume': '成交量',
146
+ 'desk.volumeEmpty': '暂无成交量数据',
147
+ 'desk.capturedAt': '快照时间',
148
+ 'desk.sourceTime': '交易所时间',
149
+ 'desk.groupsOf': '所属分组',
150
+ 'desk.kind': '标的类型',
151
+ 'desk.colName': '名称',
152
+ 'desk.colPrice': '最新',
153
+ 'desk.colChange': '涨跌',
154
+ 'desk.colAction': '操作',
155
+ 'desk.loadFailed': '自选股服务暂不可用',
114
156
  }
115
157
 
116
158
  const en = {
@@ -190,6 +232,48 @@ const en = {
190
232
  'partial.a-share': 'A-share search unavailable: ',
191
233
  'partial.hk': 'HK search unavailable: ',
192
234
  'partial.us': 'US search unavailable: ',
235
+ /* Market desk (sidebar entry + main panel); reads the existing quotes, no new data source. */
236
+ 'desk.panel': 'Watchlist',
237
+ 'desk.title': 'Watchlist market desk',
238
+ 'desk.refresh': 'Refresh quotes',
239
+ 'desk.refreshing': 'Refreshing…',
240
+ 'desk.loading': 'Loading watchlist…',
241
+ 'desk.lastUpdate': 'Last update',
242
+ 'desk.notRefreshed': 'Not refreshed',
243
+ 'desk.filter': 'Filter symbols',
244
+ 'desk.filterPlaceholder': 'Name or code',
245
+ 'desk.group': 'Group',
246
+ 'desk.allGroups': 'All',
247
+ 'desk.newGroup': 'Group name',
248
+ 'desk.createGroup': 'Create',
249
+ 'desk.deleteGroup': 'Delete group',
250
+ 'desk.noGroup': 'Ungrouped',
251
+ 'desk.more': 'More actions',
252
+ 'desk.noGroupYet': 'No groups yet',
253
+ 'desk.pin': 'Pin',
254
+ 'desk.remove': 'Remove',
255
+ 'desk.removeHint': 'Press remove again to confirm',
256
+ 'desk.cancel': 'Cancel',
257
+ 'desk.empty': 'No symbols yet',
258
+ 'desk.emptyHint': 'Add symbols from the watchlist panel in the composer; they appear here.',
259
+ 'desk.noMatch': 'No symbols match',
260
+ 'desk.noMatchHint': 'Try another term, or switch back to All.',
261
+ 'desk.selectHint': 'Select a symbol',
262
+ 'desk.selectHintBody': 'The left list filters by group; the quote, intraday and volume panels follow the selection.',
263
+ 'desk.intraday': 'Intraday',
264
+ 'desk.intradayEmpty': 'The quote endpoint returns a snapshot only',
265
+ 'desk.intradayEmptyHint': 'Once an intraday series is available, the same-session trend draws here.',
266
+ 'desk.volume': 'Volume',
267
+ 'desk.volumeEmpty': 'No volume data',
268
+ 'desk.capturedAt': 'Captured',
269
+ 'desk.sourceTime': 'Exchange time',
270
+ 'desk.groupsOf': 'Groups',
271
+ 'desk.kind': 'Instrument',
272
+ 'desk.colName': 'Symbol',
273
+ 'desk.colPrice': 'Last',
274
+ 'desk.colChange': 'Change',
275
+ 'desk.colAction': 'Actions',
276
+ 'desk.loadFailed': 'Watchlist service unavailable',
193
277
  }
194
278
 
195
279
  /**
@@ -386,6 +470,86 @@ const CSS = `
386
470
  .capital-watchlist-rows { width: 256px; }
387
471
  /* Theme has no global border-box reset; the official item padding would overflow the list. */
388
472
  .capital-watchlist-rows button { box-sizing: border-box; }
473
+ /* --- 行情工作台:左侧栏入口 + main 面板。卡片走发丝线,浮层交给官方 Menu。 --- */
474
+ .cwd-page { height: 100%; min-height: 0; overflow-y: auto; --cwd-body-h: clamp(520px, 78vh, 860px); background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); --cwd-card: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1)); --capital-watchlist-up: #d1493f; --capital-watchlist-down: #17a063; }
475
+ .cwd-inner { max-width: 1180px; margin: 0 auto; padding: 28px 32px 44px; }
476
+ .cwd-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
477
+ .cwd-title { margin: 0; font-size: 26px; line-height: 32px; font-weight: 650; letter-spacing: -.2px; }
478
+ .cwd-headactions { display: flex; align-items: center; gap: 14px; flex: none; }
479
+ .cwd-updated { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); font-variant-numeric: tabular-nums; white-space: nowrap; }
480
+ .cwd-refresh { display: inline-flex; align-items: center; gap: 6px; flex: none; height: 34px; padding: 0 14px; border: .5px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 25%, transparent); border-radius: 10px; background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 12%, transparent); color: var(--dsw-alias-state-business-primary); font-family: inherit; font-size: 13px; line-height: 20px; font-weight: 500; cursor: pointer; }
481
+ .cwd-refresh:hover:not(:disabled) { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 20%, transparent); }
482
+ .cwd-refresh:disabled { opacity: .45; cursor: not-allowed; }
483
+ .cwd-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(430px, 1.35fr); gap: 22px; align-items: stretch; height: var(--cwd-body-h); }
484
+ .cwd-card { display: flex; flex-direction: column; height: 100%; min-width: 0; min-height: 0; border: .5px solid var(--dsw-alias-border-l1); border-radius: 14px; background: var(--cwd-card); overflow: hidden; }
485
+ .cwd-toolbar { display: flex; flex: none; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); }
486
+ .cwd-field { display: flex; align-items: center; gap: 6px; flex: 1 1 170px; min-width: 0; height: 34px; padding: 0 10px; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-tertiary); }
487
+ .cwd-field input { flex: 1 1 auto; min-width: 0; height: 100%; padding: 0; border: none; outline: none; background: transparent; color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; }
488
+ .cwd-field input::placeholder { color: var(--dsw-alias-label-tertiary); }
489
+ .cwd-pill { display: inline-flex; align-items: center; gap: 6px; flex: none; max-width: 160px; height: 34px; padding: 0 12px; border: none; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: 12.5px; line-height: 20px; cursor: pointer; }
490
+ .cwd-pill:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-accent); color: var(--dsw-alias-label-primary); }
491
+ .cwd-pill:disabled { opacity: .45; cursor: not-allowed; }
492
+ .cwd-pill span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
493
+ .cwd-groupcreate { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
494
+ .cwd-groupcreate input { width: 104px; height: 34px; padding: 0 10px; border: .5px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 12.5px; }
495
+ .cwd-thead, .cwd-row { display: grid; grid-template-columns: minmax(0, 1.6fr) 92px 84px 40px; gap: 10px; align-items: center; }
496
+ .cwd-thead { flex: none; padding: 8px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); font-size: 11px; line-height: 16px; letter-spacing: .2px; color: var(--dsw-alias-label-tertiary); white-space: nowrap; }
497
+ .cwd-right { text-align: right; }
498
+ .cwd-tablebody { flex: 1; min-height: 0; overflow-y: auto; border-bottom: .5px solid var(--dsw-alias-border-l2); }
499
+ .cwd-row { padding: 9px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); transition: background .15s var(--ds-ease-in-out); }
500
+ .cwd-row:last-of-type { border-bottom: none; }
501
+ .cwd-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
502
+ .cwd-row[aria-current="true"] { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 10%, transparent); }
503
+ .cwd-nameline { display: flex; align-items: center; gap: 6px; min-width: 0; }
504
+ .cwd-cellname { display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 0; border: none; background: transparent; color: inherit; font-family: inherit; text-align: left; cursor: pointer; }
505
+ .cwd-nametext { flex: 0 1 auto; min-width: 0; font-size: 14px; line-height: 19px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
506
+ .cwd-codeline { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 11px; line-height: 15px; color: var(--dsw-alias-label-tertiary); }
507
+ .cwd-code { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
508
+ .cwd-price { text-align: right; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
509
+ .cwd-pct { text-align: right; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
510
+ .cwd-up { color: var(--capital-watchlist-up); }
511
+ .cwd-down { color: var(--capital-watchlist-down); }
512
+ .cwd-flat { color: var(--dsw-alias-label-secondary); }
513
+ .cwd-stale { color: var(--dsw-alias-label-secondary); }
514
+ .cwd-rowactions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; }
515
+ .cwd-iconbtn { flex: none; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: var(--dsw-radius-sm); background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer; }
516
+ .cwd-iconbtn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-accent); color: var(--dsw-alias-label-primary); }
517
+ .cwd-iconbtn:disabled { opacity: .45; cursor: not-allowed; }
518
+ .cwd-detail { display: flex; flex: 1; flex-direction: column; gap: 14px; min-height: 0; padding: 16px; overflow-y: auto; }
519
+ .cwd-detailhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-width: 0; }
520
+ .cwd-detailname { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 16px; line-height: 22px; font-weight: 600; }
521
+ .cwd-detailtext { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
522
+ .cwd-detailcode { margin-top: 3px; font-size: 12px; line-height: 17px; color: var(--dsw-alias-label-tertiary); }
523
+ .cwd-bigquote { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
524
+ .cwd-bigprice { font-size: 34px; line-height: 40px; font-weight: 650; font-variant-numeric: tabular-nums; }
525
+ .cwd-bigpct { font-size: 14px; line-height: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
526
+ .cwd-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
527
+ .cwd-metaitem { min-width: 0; }
528
+ .cwd-metalabel { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
529
+ .cwd-metavalue { font-size: 12.5px; line-height: 18px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
530
+ .cwd-block { flex: none; padding-top: 12px; border-top: .5px solid var(--dsw-alias-border-l2); }
531
+ .cwd-block-chart { flex: 1; display: flex; flex-direction: column; min-height: 0; }
532
+ .cwd-blockhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
533
+ .cwd-blocktitle { font-size: 12.5px; line-height: 18px; font-weight: 600; }
534
+ .cwd-blocknote { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
535
+ .cwd-chart { flex: 1; min-height: 150px; display: grid; place-items: center; padding: 12px; border: 1px dashed var(--dsw-alias-border-l2); border-radius: 10px; background: repeating-linear-gradient(180deg, color-mix(in srgb, var(--dsw-alias-border-l2) 60%, transparent) 0 1px, transparent 1px 36px), var(--dsw-alias-bg-module-platform); text-align: center; }
536
+ .cwd-charttext { font-size: 12.5px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }
537
+ .cwd-charthint { margin-top: 4px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
538
+ .cwd-volume { height: 92px; display: grid; place-items: center; border: 1px dashed var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-module-platform); border-radius: 10px; font-size: 12px; color: var(--dsw-alias-label-tertiary); }
539
+ .cwd-empty { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 34px 18px; text-align: center; }
540
+ .cwd-emptytitle { font-size: 14px; line-height: 20px; font-weight: 600; }
541
+ .cwd-emptyhint { margin: 6px 0 0; font-size: 12.5px; line-height: 19px; color: var(--dsw-alias-label-tertiary); }
542
+ .cwd-notice { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
543
+ .cwd-notice-danger { color: var(--dsw-alias-state-error-primary); }
544
+ .cwd-error { flex: none; padding: 8px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-error-primary); }
545
+ .cwd-menuhint { padding: 6px 10px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
546
+ .cwd-menulist { width: 208px; }
547
+ .cwd-menulist button { box-sizing: border-box; }
548
+ .cwd-field:focus-within { outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 1px; }
549
+ .cwd-page button:focus-visible, .cwd-groupcreate input:focus-visible { outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 1px; }
550
+ .cwd-skeleton { display: block; height: 12px; border-radius: 6px; background: var(--dsw-alias-bg-skeleton); }
551
+ @media (max-width: 1040px) { .cwd-body { grid-template-columns: minmax(0, 1fr); gap: 16px; height: auto; } .cwd-card { height: auto; } .cwd-tablebody { flex: none; max-height: 60vh; } .cwd-chart { flex: none; height: 200px; } }
552
+ @media (max-width: 720px) { .cwd-inner { padding: 20px 16px 32px; } .cwd-thead, .cwd-row { grid-template-columns: minmax(0, 1.5fr) 78px 72px 36px; gap: 8px; } .cwd-thead { padding: 8px 10px; } .cwd-row { padding: 9px 10px; } }
389
553
  `
390
554
 
391
555
  function installStyles() {
@@ -1231,6 +1395,389 @@ function WatchlistDialog({ useDialog, surface, t, inputActions }) {
1231
1395
  )
1232
1396
  }
1233
1397
 
1398
+ /* ---------------------------------------------------------------------------
1399
+ * 行情工作台:左侧栏「自选股」入口 + main 面板。
1400
+ * 报价仍只走 /capital-watchlist(同一 host 路由、同一套失败码);分组只落本机。
1401
+ * 分时与成交量目前没有数据源,画占位并写明原因,不补造走势。
1402
+ * ------------------------------------------------------------------------ */
1403
+ const DESK_PANEL_ID = `${ENTRY_NAME}:desk`
1404
+ const DESK_GROUPS_KEY = 'capital.watchlist.desk.groups.v1'
1405
+ const DESK_ALL = '__all__'
1406
+
1407
+ function readDeskGroups() {
1408
+ const empty = { names: [], assignments: {} }
1409
+ try {
1410
+ const parsed = JSON.parse(localStorage.getItem(DESK_GROUPS_KEY) ?? '{}')
1411
+ if (parsed === null || typeof parsed !== 'object') return empty
1412
+ if (!Array.isArray(parsed.names)) return empty
1413
+ if (parsed.assignments === null || typeof parsed.assignments !== 'object') return empty
1414
+ return {
1415
+ names: parsed.names.filter((name) => typeof name === 'string' && name.length > 0).slice(0, 20),
1416
+ assignments: parsed.assignments,
1417
+ }
1418
+ } catch {
1419
+ return empty
1420
+ }
1421
+ }
1422
+
1423
+ function writeDeskGroups(value) {
1424
+ try {
1425
+ localStorage.setItem(DESK_GROUPS_KEY, JSON.stringify(value))
1426
+ } catch {
1427
+ // Private mode: groups stay in memory for this page.
1428
+ }
1429
+ }
1430
+
1431
+ const deskGroupsOf = (groups, thscode) => {
1432
+ const names = groups.assignments[thscode]
1433
+ return Array.isArray(names) ? names : []
1434
+ }
1435
+
1436
+ /** Missing change is missing (holiday / halted), never 0.00%. */
1437
+ const deskPctOf = (quote) => (quote !== null && quote !== undefined && typeof quote.change_pct === 'number' && Number.isFinite(quote.change_pct) ? quote.change_pct : null)
1438
+ const deskToneOf = (value) => (value === null ? 'cwd-flat' : value > 0 ? 'cwd-up' : value < 0 ? 'cwd-down' : 'cwd-flat')
1439
+ const deskPctText = (value) => (value === null ? '—' : `${value > 0 ? '+' : ''}${value.toFixed(2)}%`)
1440
+ /** Comma grouping is the market convention here, so it does not follow the UI locale. */
1441
+ const deskPriceFormat = new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
1442
+ const deskPriceText = (quote) => (quote !== null && quote !== undefined && typeof quote.price === 'number' && Number.isFinite(quote.price) ? deskPriceFormat.format(quote.price) : '—')
1443
+
1444
+ /** Sidebar glyph: an axis plus a rising line reads as quotes without inventing a wallet/pie shape. */
1445
+ function WatchlistDeskIcon({ size = 18 }) {
1446
+ return h('svg', {
1447
+ width: size,
1448
+ height: size,
1449
+ viewBox: '0 0 24 24',
1450
+ fill: 'none',
1451
+ stroke: 'currentColor',
1452
+ strokeWidth: 1.8,
1453
+ strokeLinecap: 'round',
1454
+ strokeLinejoin: 'round',
1455
+ 'aria-hidden': 'true',
1456
+ },
1457
+ h('path', { d: 'M4 19V5' }),
1458
+ h('path', { d: 'M4 19h16' }),
1459
+ h('path', { d: 'm7 15 3-4 3 2 5-7' }),
1460
+ h('circle', { cx: 18, cy: 6, r: 1.4, fill: 'currentColor', stroke: 'none' }))
1461
+ }
1462
+
1463
+ function WatchlistDeskPage({ t }) {
1464
+ const [items, setItems] = useState([])
1465
+ const [loading, setLoading] = useState(true)
1466
+ const [refreshing, setRefreshing] = useState(false)
1467
+ const [refreshedAt, setRefreshedAt] = useState(null)
1468
+ const [failures, setFailures] = useState({})
1469
+ const [error, setError] = useState(null)
1470
+ const [groups, setGroups] = useState(readDeskGroups)
1471
+ const [activeGroup, setActiveGroup] = useState(DESK_ALL)
1472
+ const [groupOpen, setGroupOpen] = useState(false)
1473
+ const [newGroup, setNewGroup] = useState('')
1474
+ const [query, setQuery] = useState('')
1475
+ const [selected, setSelected] = useState(null)
1476
+ const [pendingRemove, setPendingRemove] = useState(null)
1477
+ const [rowMenu, setRowMenu] = useState(null)
1478
+ const alive = useRef(true)
1479
+
1480
+ useEffect(() => {
1481
+ alive.current = true
1482
+ return () => { alive.current = false }
1483
+ }, [])
1484
+ useEffect(() => { writeDeskGroups(groups) }, [groups])
1485
+
1486
+ /** One refresh reply feeds the list, per-row failure marks and the footer time. */
1487
+ const applyRefresh = (payload) => {
1488
+ const landed = cleanRows(payload.items)
1489
+ if (Array.isArray(landed)) setItems(landed)
1490
+ const next = {}
1491
+ for (const item of payload.failures ?? []) {
1492
+ if (item !== null && typeof item === 'object' && typeof item.thscode === 'string') next[item.thscode] = item.code
1493
+ }
1494
+ setFailures(next)
1495
+ if (typeof payload.refreshed_at === 'number') setRefreshedAt(payload.refreshed_at)
1496
+ setError(payload.error !== undefined && payload.error !== null && typeof payload.error.code === 'string' ? payload.error.code : null)
1497
+ }
1498
+
1499
+ // Opening the panel is the user request: read the list, then quote it once. No polling.
1500
+ useEffect(() => {
1501
+ let cancelled = false
1502
+ const boot = async () => {
1503
+ try {
1504
+ const listed = await call('/list')
1505
+ if (cancelled) return
1506
+ const landed = cleanRows(listed.items) ?? []
1507
+ setItems(landed)
1508
+ // The detail panel is the main area: start on the first symbol instead of an empty aside.
1509
+ setSelected((value) => (value !== null ? value : (typeof landed[0]?.thscode === 'string' ? landed[0].thscode : null)))
1510
+ } catch (failure) {
1511
+ if (!cancelled) setError(failure.code ?? 'load_failed')
1512
+ return
1513
+ } finally {
1514
+ if (!cancelled) setLoading(false)
1515
+ }
1516
+ try {
1517
+ const payload = await call('/refresh', { body: {} })
1518
+ if (!cancelled) applyRefresh(payload)
1519
+ } catch (failure) {
1520
+ if (!cancelled) setError(failure.code ?? 'fuyao_unavailable')
1521
+ }
1522
+ }
1523
+ void boot()
1524
+ return () => { cancelled = true }
1525
+ }, [])
1526
+
1527
+ const refresh = async () => {
1528
+ if (refreshing) return
1529
+ setRefreshing(true)
1530
+ try {
1531
+ const payload = await call('/refresh', { body: {} })
1532
+ if (alive.current) applyRefresh(payload)
1533
+ } catch (failure) {
1534
+ if (alive.current) setError(failure.code ?? 'fuyao_unavailable')
1535
+ } finally {
1536
+ if (alive.current) setRefreshing(false)
1537
+ }
1538
+ }
1539
+
1540
+ const removeRow = async (thscode) => {
1541
+ const before = items
1542
+ setPendingRemove(null)
1543
+ setItems(before.filter((row) => row.thscode !== thscode))
1544
+ if (selected === thscode) setSelected(null)
1545
+ try {
1546
+ await call('/remove', { body: { thscode } })
1547
+ } catch {
1548
+ // Put the row back exactly where it was; the host never confirmed the removal.
1549
+ if (alive.current) setItems(before)
1550
+ }
1551
+ }
1552
+
1553
+ const pinRow = async (thscode) => {
1554
+ const before = items
1555
+ const target = before.find((row) => row.thscode === thscode)
1556
+ if (target === undefined) return
1557
+ setItems([target, ...before.filter((row) => row.thscode !== thscode)])
1558
+ try {
1559
+ const payload = await call('/pin', { body: { thscode } })
1560
+ if (Array.isArray(payload.items) && alive.current) setItems(cleanRows(payload.items))
1561
+ } catch {
1562
+ if (alive.current) setItems(before)
1563
+ }
1564
+ }
1565
+
1566
+ const createGroup = () => {
1567
+ const name = newGroup.trim()
1568
+ if (name.length === 0 || name === DESK_ALL || groups.names.includes(name)) return
1569
+ setGroups({ names: [...groups.names, name], assignments: groups.assignments })
1570
+ setNewGroup('')
1571
+ setActiveGroup(name)
1572
+ }
1573
+
1574
+ const deleteGroup = (name) => {
1575
+ if (name === DESK_ALL) return
1576
+ const assignments = {}
1577
+ for (const [thscode, names] of Object.entries(groups.assignments)) {
1578
+ const kept = (Array.isArray(names) ? names : []).filter((entry) => entry !== name)
1579
+ if (kept.length > 0) assignments[thscode] = kept
1580
+ }
1581
+ setGroups({ names: groups.names.filter((entry) => entry !== name), assignments })
1582
+ setActiveGroup(DESK_ALL)
1583
+ setGroupOpen(false)
1584
+ }
1585
+
1586
+ const toggleGroup = (thscode, name) => {
1587
+ const current = deskGroupsOf(groups, thscode)
1588
+ const next = current.includes(name) ? current.filter((entry) => entry !== name) : [...current, name]
1589
+ const assignments = { ...groups.assignments }
1590
+ if (next.length === 0) delete assignments[thscode]
1591
+ else assignments[thscode] = next
1592
+ setGroups({ names: groups.names, assignments })
1593
+ }
1594
+
1595
+ const term = query.trim().toLowerCase()
1596
+ const visible = items.filter((item) => {
1597
+ if (activeGroup !== DESK_ALL && !deskGroupsOf(groups, item.thscode).includes(activeGroup)) return false
1598
+ if (term.length === 0) return true
1599
+ return [item.name, item.thscode, item.ticker].some((value) => typeof value === 'string' && value.toLowerCase().includes(term))
1600
+ })
1601
+ const current = selected === null ? null : (items.find((item) => item.thscode === selected) ?? null)
1602
+
1603
+ const groupMenuItems = [{ id: DESK_ALL, label: t('desk.allGroups'), icon: activeGroup === DESK_ALL ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined }]
1604
+ .concat(groups.names.map((name) => ({ id: name, label: name, icon: activeGroup === name ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined })))
1605
+
1606
+ const rows = visible.map((item, index) => {
1607
+ const pct = deskPctOf(item.quote)
1608
+ const failure = failures[item.thscode]
1609
+ const names = deskGroupsOf(groups, item.thscode)
1610
+ const isSelected = selected === item.thscode
1611
+ const quoteTitle = failure === undefined ? undefined : t(`error.${failure}`)
1612
+ const menuOpen = rowMenu === item.thscode
1613
+ return h('div', {
1614
+ key: item.thscode,
1615
+ className: 'cwd-row',
1616
+ role: 'listitem',
1617
+ 'aria-current': isSelected ? 'true' : undefined,
1618
+ onClick: (event) => { if (event.target.closest('.cwd-rowactions') === null) setSelected(item.thscode) },
1619
+ },
1620
+ h('button', {
1621
+ type: 'button',
1622
+ className: 'cwd-cellname',
1623
+ 'aria-pressed': isSelected,
1624
+ onClick: () => setSelected(item.thscode),
1625
+ },
1626
+ h('span', { className: 'cwd-nameline' },
1627
+ h('span', { className: 'cwd-nametext', title: item.name }, scrubInvisible(item.name)),
1628
+ h(TypeTag, { assetType: item.asset_type, t })),
1629
+ h('span', { className: 'cwd-codeline' }, h('span', { className: 'cwd-code' }, item.thscode))),
1630
+ h('div', { className: failure === undefined ? 'cwd-price' : 'cwd-price cwd-stale', title: quoteTitle }, deskPriceText(item.quote)),
1631
+ h('div', { className: `cwd-pct ${deskToneOf(pct)}`, title: quoteTitle }, deskPctText(pct)),
1632
+ // One trigger per row: pin, group checkboxes and remove live in the official Menu.
1633
+ h('div', { className: 'cwd-rowactions' },
1634
+ h(Menu, {
1635
+ open: menuOpen,
1636
+ anchor: h('button', {
1637
+ type: 'button',
1638
+ className: 'cwd-iconbtn',
1639
+ title: t('desk.more'),
1640
+ 'aria-label': `${t('desk.more')} ${item.name}`,
1641
+ 'aria-haspopup': 'menu',
1642
+ 'aria-expanded': menuOpen,
1643
+ onClick: () => { setPendingRemove(null); setRowMenu(menuOpen ? null : item.thscode) },
1644
+ }, h(IconEllipsisOutlineRegular, { size: 16 })),
1645
+ items: [{ id: 'pin', label: t('desk.pin'), icon: h(IconPinOutlineRegular, { size: 14 }), disabled: index === 0 }],
1646
+ children: [
1647
+ ...(groups.names.length === 0
1648
+ ? [h('div', { key: 'no-group', className: 'cwd-menuhint' }, t('desk.noGroupYet'))]
1649
+ : groups.names.map((name) => h(MenuItemButton, {
1650
+ key: `group:${name}`,
1651
+ icon: names.includes(name) ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined,
1652
+ onSelect: () => toggleGroup(item.thscode, name),
1653
+ }, name))),
1654
+ h(MenuItemButton, {
1655
+ key: 'remove',
1656
+ danger: true,
1657
+ separatorBefore: true,
1658
+ icon: h(IconTrashOutlineRegular, { size: 14 }),
1659
+ onSelect: () => { setRowMenu(null); setPendingRemove(item) },
1660
+ }, t('desk.remove')),
1661
+ ],
1662
+ onSelect: (id) => {
1663
+ if (id !== 'pin') return
1664
+ setRowMenu(null)
1665
+ void pinRow(item.thscode)
1666
+ },
1667
+ onClose: () => setRowMenu(null),
1668
+ align: 'end',
1669
+ portal: true,
1670
+ listClassName: 'cwd-menulist',
1671
+ }))
1672
+ )
1673
+ })
1674
+
1675
+ const listBody = loading
1676
+ ? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.loading')))
1677
+ : items.length === 0
1678
+ ? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.empty')), h('p', { className: 'cwd-emptyhint' }, t('desk.emptyHint')))
1679
+ : visible.length === 0
1680
+ ? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.noMatch')), h('p', { className: 'cwd-emptyhint' }, t('desk.noMatchHint')))
1681
+ : h('div', { className: 'cwd-tablebody', role: 'list', 'aria-label': t('desk.title') }, rows)
1682
+
1683
+ const detailNames = current === null ? [] : deskGroupsOf(groups, current.thscode)
1684
+ const detailPct = current === null ? null : deskPctOf(current.quote)
1685
+ const detail = current === null
1686
+ ? h('div', { className: 'cwd-card' }, h('div', { className: 'cwd-empty' },
1687
+ h('div', { className: 'cwd-emptytitle' }, t('desk.selectHint')),
1688
+ h('p', { className: 'cwd-emptyhint' }, t('desk.selectHintBody'))))
1689
+ : h('div', { className: 'cwd-card' }, h('div', { className: 'cwd-detail' },
1690
+ h('div', { className: 'cwd-detailhead' },
1691
+ h('div', { style: { minWidth: 0 } },
1692
+ h('div', { className: 'cwd-detailname' },
1693
+ h('span', { className: 'cwd-detailtext', title: current.name }, scrubInvisible(current.name)),
1694
+ h(TypeTag, { assetType: current.asset_type, t })),
1695
+ h('div', { className: 'cwd-detailcode' }, current.thscode))),
1696
+ h('div', { className: 'cwd-bigquote' },
1697
+ h('span', { className: 'cwd-bigprice' }, deskPriceText(current.quote)),
1698
+ h('span', { className: `cwd-bigpct ${deskToneOf(detailPct)}` }, deskPctText(detailPct))),
1699
+ h('div', { className: 'cwd-meta' },
1700
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.capturedAt')), h('div', { className: 'cwd-metavalue' }, current.quote === null || current.quote === undefined ? t('desk.notRefreshed') : (formatTime(current.quote.captured_at) || t('desk.notRefreshed')))),
1701
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.sourceTime')), h('div', { className: 'cwd-metavalue' }, typeof current.quote?.source_time === 'string' && current.quote.source_time.length > 0 ? current.quote.source_time : '—')),
1702
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.groupsOf')), h('div', { className: 'cwd-metavalue' }, detailNames.length === 0 ? t('desk.noGroup') : detailNames.join(' / '))),
1703
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.kind')), h('div', { className: 'cwd-metavalue' }, typeLabel(current.asset_type, t)))),
1704
+ h('div', { className: 'cwd-block cwd-block-chart' },
1705
+ h('div', { className: 'cwd-blockhead' },
1706
+ h('span', { className: 'cwd-blocktitle' }, t('desk.intraday')),
1707
+ h('span', { className: 'cwd-blocknote' }, refreshedAt === null ? t('desk.notRefreshed') : formatTime(refreshedAt))),
1708
+ h('div', { className: 'cwd-chart' },
1709
+ h('div', null,
1710
+ h('div', { className: 'cwd-charttext' }, t('desk.intradayEmpty')),
1711
+ h('div', { className: 'cwd-charthint' }, t('desk.intradayEmptyHint'))))),
1712
+ h('div', { className: 'cwd-block' },
1713
+ h('div', { className: 'cwd-blockhead' }, h('span', { className: 'cwd-blocktitle' }, t('desk.volume'))),
1714
+ h('div', { className: 'cwd-volume' }, t('desk.volumeEmpty')))))
1715
+
1716
+ return h('div', { className: 'cwd-page' },
1717
+ h('div', { className: 'cwd-inner' },
1718
+ h('header', { className: 'cwd-head' },
1719
+ h('h1', { className: 'cwd-title' }, t('desk.title')),
1720
+ h('div', { className: 'cwd-headactions' },
1721
+ h('span', { className: 'cwd-updated' },
1722
+ `${t('desk.lastUpdate')} ${refreshedAt === null ? t('desk.notRefreshed') : formatTime(refreshedAt)}`),
1723
+ h('button', { type: 'button', className: 'cwd-refresh', disabled: refreshing, onClick: () => { void refresh() } },
1724
+ h(IconRefreshOutlineRegular, { size: 14 }),
1725
+ refreshing ? t('desk.refreshing') : t('desk.refresh')))),
1726
+ h('div', { className: 'cwd-body' },
1727
+ h('section', { className: 'cwd-card' },
1728
+ h('div', { className: 'cwd-toolbar' },
1729
+ h('label', { className: 'cwd-field' },
1730
+ h(IconSearchOutlineRegular, { size: 14 }),
1731
+ h('input', { type: 'text', value: query, placeholder: t('desk.filterPlaceholder'), 'aria-label': t('desk.filter'), onChange: (event) => setQuery(event.target.value) })),
1732
+ h(Menu, {
1733
+ open: groupOpen,
1734
+ anchor: h('button', {
1735
+ type: 'button',
1736
+ className: 'cwd-pill',
1737
+ 'aria-haspopup': 'menu',
1738
+ 'aria-expanded': groupOpen,
1739
+ 'aria-label': t('desk.group'),
1740
+ onClick: () => setGroupOpen(!groupOpen),
1741
+ }, h(IconGoalOutlineRegular, { size: 14 }), h('span', null, activeGroup === DESK_ALL ? t('desk.allGroups') : activeGroup)),
1742
+ items: groupMenuItems,
1743
+ children: activeGroup === DESK_ALL ? [] : [h(MenuItemButton, {
1744
+ key: 'delete-group',
1745
+ danger: true,
1746
+ separatorBefore: true,
1747
+ icon: h(IconTrashOutlineRegular, { size: 14 }),
1748
+ onSelect: () => deleteGroup(activeGroup),
1749
+ }, t('desk.deleteGroup'))],
1750
+ onSelect: (id) => { setGroupOpen(false); setActiveGroup(id) },
1751
+ onClose: () => setGroupOpen(false),
1752
+ align: 'start',
1753
+ portal: true,
1754
+ listClassName: 'cwd-menulist',
1755
+ }),
1756
+ h('div', { className: 'cwd-groupcreate' },
1757
+ h('input', {
1758
+ type: 'text',
1759
+ value: newGroup,
1760
+ maxLength: 20,
1761
+ placeholder: t('desk.newGroup'),
1762
+ 'aria-label': t('desk.newGroup'),
1763
+ onChange: (event) => setNewGroup(event.target.value),
1764
+ onKeyDown: (event) => { if (event.key === 'Enter') createGroup() },
1765
+ }),
1766
+ h('button', { type: 'button', className: 'cwd-pill', disabled: newGroup.trim().length === 0, onClick: createGroup }, t('desk.createGroup')))),
1767
+ error === null ? null : h('div', { className: 'cwd-error', role: 'alert' }, error === 'load_failed' ? t('desk.loadFailed') : t(`error.${error}`)),
1768
+ pendingRemove === null ? null : h('div', { className: 'cwd-notice cwd-notice-danger' },
1769
+ h('span', null, `${t('desk.removeHint')} · ${scrubInvisible(pendingRemove.name)}`),
1770
+ h('button', { type: 'button', className: 'cwd-pill', onClick: () => setPendingRemove(null) }, t('desk.cancel'))),
1771
+ h('div', { className: 'cwd-thead', role: 'row' },
1772
+ h('span', null, t('desk.colName')),
1773
+ h('span', { className: 'cwd-right' }, t('desk.colPrice')),
1774
+ h('span', { className: 'cwd-right' }, t('desk.colChange')),
1775
+ h('span', { className: 'cwd-right' }, t('desk.colAction'))),
1776
+ listBody),
1777
+ h('aside', null, detail)),
1778
+ ))
1779
+ }
1780
+
1234
1781
  function apply(ctx) {
1235
1782
  ctx.effect(installStyles, `${ENTRY_NAME}: styles`)
1236
1783
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), `${ENTRY_NAME}: dictionaries`)
@@ -1280,6 +1827,23 @@ function apply(ctx) {
1280
1827
  },
1281
1828
  }, WatchlistDialog))
1282
1829
 
1830
+ // Desk shell: one sidebar entry + its main panel. Quotes still come from the host
1831
+ // route the dialog uses; the page never fetches anything the dialog would not.
1832
+ // Registered after the overlay so the dialog stays the first seat this plugin adds.
1833
+ const deskT = ctx.locale.bind(NS)
1834
+ ctx.slots.inject('main', () => ctx.slots.register({
1835
+ name: 'main',
1836
+ key: DESK_PANEL_ID,
1837
+ locale: NS,
1838
+ }, WatchlistDeskPage))
1839
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
1840
+ name: 'sidebar.panellist',
1841
+ id: DESK_PANEL_ID,
1842
+ order: 12,
1843
+ locale: NS,
1844
+ label: () => deskT('desk.panel'),
1845
+ }, WatchlistDeskIcon))
1846
+
1283
1847
  ctx.inject(['commandUi'], (scope) => {
1284
1848
  const t = ctx.locale.bind(NS)
1285
1849
  scope.effect(() => scope.commandUi.register({
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/watchlist",
3
- "version": "2.24.0",
3
+ "version": "2.26.0",
4
4
  "description": "自动模式的用户自选股(宿主级清单 + Fuyao 报价快照 + /capital-watchlist 路由 + 输入框菜单弹窗):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",