@v587d/capital-generation 2.22.0 → 2.23.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.
@@ -56,6 +56,9 @@ const PADDLE_OCR_DEFAULT_REF = 'PADDLE_OCR_TOKEN'
56
56
  const TABS_ID = 'capital-config-tabs'
57
57
  /** Must match `SKILL_DOC_ROUTE` in `config/index.js`; drift = details never load. */
58
58
  const SKILL_DOC_ROUTE = '/capital-skills'
59
+ /** Automation host routes; same auth plane as the workspace dropdown. */
60
+ const STORAGE_ROUTE = '/capital-automation/storage'
61
+ const STORAGE_CLEAR_ROUTE = '/capital-automation/storage/clear'
59
62
  const DOC_URLS = {
60
63
  fuyao: 'https://fuyao.aicubes.cn/docs/',
61
64
  ftshare: 'https://market.ft.tech/gateway/doc/p/pb8eizu3',
@@ -85,6 +88,14 @@ const AUTOMATION_RANGES = {
85
88
  maxSteps: { min: 100, max: 2_000, unit: 'automationUnitSteps' },
86
89
  maxToolCalls: { min: 100, max: 5_000, unit: 'automationUnitCalls' },
87
90
  }
91
+ const STORAGE_CATEGORY_LABELS = {
92
+ datasets: 'automationStorageDatasets',
93
+ profiles: 'automationStorageProfiles',
94
+ ocr: 'automationStorageOcr',
95
+ charts: 'automationStorageCharts',
96
+ runs: 'automationStorageRuns',
97
+ other: 'automationStorageOther',
98
+ }
88
99
  const SELECTED_SKILL_FIELDS = SELECTED_SKILL_CATALOG.map(({ key }) => key)
89
100
  // Stable orders: facet counts change with the other dimension, but chips must not jump under the cursor.
90
101
  const SELECTED_SKILL_TRAITS = selectedSkillTraitOrder()
@@ -136,6 +147,37 @@ const zh = {
136
147
  automationWorkspaceLoading: '工作区列表读取中…',
137
148
  automationWorkspaceUnavailable: '工作区列表暂时读不到;任务仍会使用默认工作区,切回本格会重试。',
138
149
  automationWorkspaceFallback: '专属默认工作区',
150
+ automationStorageGroup: '存储',
151
+ automationStorageWorkspace: '工作区数据',
152
+ automationStorageCache: '可清理缓存',
153
+ automationStorageAnalysis: '分析结果',
154
+ automationStorageRetained: '保留',
155
+ automationStorageSessions: '运行会话',
156
+ automationStorageSessionsHint: '由 DSH 管理,不随「清除数据缓存」删除',
157
+ automationStorageUnavailable: '占用读取失败;切回本格会重试。',
158
+ automationStorageRetry: '重试',
159
+ automationStorageStale: '刷新失败,显示上次结果。',
160
+ automationStorageEmpty: '暂无可清理缓存',
161
+ automationStorageClear: '清除数据缓存',
162
+ automationStorageClearing: '清除中…',
163
+ automationStorageConfirmTitle: '清除数据缓存',
164
+ automationStorageConfirmBody: '将删除 {path} 中 {size} 的 capital-data 缓存(含数据集、数据档案与 OCR)。capital-analysis 中的分析结果、任务、运行记录、简报、通知和运行会话都会保留。',
165
+ automationStorageConfirm: '清除 {size}',
166
+ automationStorageCancel: '取消',
167
+ automationStorageCleared: '已释放 {size}。',
168
+ automationStorageClearedPartial: '已释放 {size},另有 {failed} 个文件未能删除。',
169
+ automationStorageClearFailed: '清理失败,请稍后再试。',
170
+ automationStorageRunInProgress: '有运行正在进行,请结束后再清理。',
171
+ automationStorageActiveHint: '有运行正在进行,结束后可清理。',
172
+ automationStorageUnsafe: '缓存目录不是普通目录,已停止清理。',
173
+ automationStorageDatasets: '数据集',
174
+ automationStorageProfiles: '数据档案',
175
+ automationStorageOcr: 'OCR',
176
+ automationStorageCharts: '图表',
177
+ automationStorageRuns: '分析产物',
178
+ automationStorageOther: '其他',
179
+ automationStorageSessionCount: '{count} 个',
180
+ automationStorageUnreadable: '部分文件读不到,显示的是可读部分。',
139
181
  windLabel: 'Wind Alice API Key',
140
182
  windHint: 'Wind 金融信披类文档检索接口。保存后新自动模式会话生效。',
141
183
  paddleocrLabel: 'PaddleOCR 文档解析 Token',
@@ -207,6 +249,37 @@ const en = {
207
249
  automationWorkspaceLoading: 'Loading workspaces…',
208
250
  automationWorkspaceUnavailable: 'The workspace list is unavailable; runs still use the default workspace. Re-entering this tab retries.',
209
251
  automationWorkspaceFallback: 'Dedicated default workspace',
252
+ automationStorageGroup: 'Storage',
253
+ automationStorageWorkspace: 'Workspace data',
254
+ automationStorageCache: 'Clearable cache',
255
+ automationStorageAnalysis: 'Analysis results',
256
+ automationStorageRetained: 'Retained',
257
+ automationStorageSessions: 'Run sessions',
258
+ automationStorageSessionsHint: 'Managed by DSH; not removed by “Clear data cache”',
259
+ automationStorageUnavailable: 'Could not read usage; re-enter this tab to retry.',
260
+ automationStorageRetry: 'Retry',
261
+ automationStorageStale: 'Refresh failed; showing the previous result.',
262
+ automationStorageEmpty: 'No cache to clear',
263
+ automationStorageClear: 'Clear data cache',
264
+ automationStorageClearing: 'Clearing…',
265
+ automationStorageConfirmTitle: 'Clear data cache',
266
+ automationStorageConfirmBody: 'Delete {size} of capital-data cache from {path} (datasets, profiles, and OCR). Analysis results in capital-analysis, tasks, run records, briefs, notifications, and run sessions are kept.',
267
+ automationStorageConfirm: 'Clear {size}',
268
+ automationStorageCancel: 'Cancel',
269
+ automationStorageCleared: 'Freed {size}.',
270
+ automationStorageClearedPartial: 'Freed {size}; {failed} file(s) could not be removed.',
271
+ automationStorageClearFailed: 'Cleanup failed. Please try again.',
272
+ automationStorageRunInProgress: 'A run is in progress. Try again after it ends.',
273
+ automationStorageActiveHint: 'A run is in progress; cleanup is available after it ends.',
274
+ automationStorageUnsafe: 'The cache directory is not a regular directory; cleanup was stopped.',
275
+ automationStorageDatasets: 'Datasets',
276
+ automationStorageProfiles: 'Data profiles',
277
+ automationStorageOcr: 'OCR',
278
+ automationStorageCharts: 'Charts',
279
+ automationStorageRuns: 'Runs',
280
+ automationStorageOther: 'Other',
281
+ automationStorageSessionCount: '{count} sessions',
282
+ automationStorageUnreadable: 'Some files could not be read; showing readable data.',
210
283
  windLabel: 'Wind Alice API Key',
211
284
  windHint: 'Wind financial disclosure document retrieval interface. Takes effect in new Auto mode sessions.',
212
285
  paddleocrLabel: 'PaddleOCR document token',
@@ -279,6 +352,37 @@ function installStyles() {
279
352
  .capital-config-automation-group > .capital-config-group-label { color: var(--dsw-alias-label-secondary); font-size: 12px; font-weight: 500; line-height: 18px; }
280
353
  .capital-config-number { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
281
354
  .capital-config-workspace { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
355
+ .capital-config-storage { display: flex; flex-direction: column; min-width: 0; border: .5px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-2); }
356
+ .capital-config-storage-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 10px 14px; }
357
+ .capital-config-storage-head > .capital-config-storage-label { font-size: 12px; }
358
+ .capital-config-storage-head > .capital-config-storage-amount { font-size: 15px; font-weight: 600; line-height: 22px; }
359
+ .capital-config-storage-item { display: flex; flex-direction: column; gap: 6px; padding: 10px 14px; border-top: .5px solid var(--dsw-alias-border-l2); }
360
+ .capital-config-storage-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; min-width: 0; }
361
+ .capital-config-storage-value { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
362
+ .capital-config-storage-label { color: var(--dsw-alias-label-secondary); font-size: 12.5px; line-height: 20px; }
363
+ .capital-config-storage-amount { display: inline-flex; align-items: baseline; gap: 6px; color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 500; line-height: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
364
+ .capital-config-storage-count { color: var(--dsw-alias-label-tertiary); font-size: 11.5px; font-weight: 400; }
365
+ .capital-config-storage-chips { display: flex; flex-wrap: wrap; gap: 4px; }
366
+ .capital-config-storage-chip { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 16px; white-space: nowrap; }
367
+ .capital-config-storage-badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--dsw-alias-state-success-tertiary); color: var(--dsw-alias-state-success-primary); font-size: 11px; font-weight: 500; line-height: 16px; white-space: nowrap; }
368
+ .capital-config-storage-meta { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 11.5px; line-height: 17px; overflow-wrap: anywhere; }
369
+ .capital-config-storage-meta[data-tone="warn"] { color: var(--dsw-alias-state-warn-primary); }
370
+ .capital-config-storage-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; border-top: .5px solid var(--dsw-alias-border-l2); }
371
+ .capital-config-storage-status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-left: auto; min-width: 0; }
372
+ .capital-config-storage-retry { padding: 0; border: 0; background: transparent; color: var(--dsw-alias-brand-primary); font: inherit; font-size: 12px; line-height: 18px; cursor: pointer; }
373
+ .capital-config-storage-retry:hover { text-decoration: underline; }
374
+ .capital-config-storage-retry:focus-visible { outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-brand-primary)); outline-offset: 2px; }
375
+ .capital-config-storage-result { margin: 0; color: var(--dsw-alias-state-success-primary); font-size: 12px; line-height: 18px; }
376
+ .capital-config-cache-button { box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; height: 32px; padding: 0 14px; border: .5px solid var(--dsw-alias-border-l1); border-radius: 999px; background: transparent; color: var(--dsw-alias-label-primary); font: inherit; font-size: 12.5px; line-height: 20px; cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; }
377
+ .capital-config-cache-button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
378
+ .capital-config-cache-button[data-variant="danger"] { border-color: var(--dsw-alias-state-error-primary); color: var(--dsw-alias-state-error-primary); }
379
+ .capital-config-cache-button[data-variant="danger"]:hover:not(:disabled) { background: var(--dsw-alias-state-error-primary); color: var(--dsw-alias-bg-base); }
380
+ .capital-config-cache-button:focus-visible { outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-brand-primary)); outline-offset: 0; }
381
+ .capital-config-cache-button:disabled { opacity: .5; cursor: not-allowed; }
382
+ div.capital-config-cache-modal { width: min(480px, 100%); }
383
+ .capital-config-cache-modal-content { min-height: 0; overflow: auto; }
384
+ .capital-config-cache-modal-body { margin: 0; color: var(--dsw-alias-label-secondary); font-size: 12.5px; line-height: 20px; }
385
+ .capital-config-cache-actions { display: flex; justify-content: flex-end; gap: 8px; }
282
386
  .capital-config-number-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; }
283
387
  .capital-config-number-head .capital-config-write-failed { font-size: 11px; line-height: 16px; }
284
388
  .capital-config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
@@ -449,6 +553,15 @@ class CapitalCardController {
449
553
  this.workspaceDetails = null
450
554
  this.workspacesInFlight = false
451
555
  this.workspacesFailed = false
556
+ this.storage = null
557
+ this.storageInFlight = false
558
+ this.storageQueued = false
559
+ this.storageFailed = false
560
+ this.storageClearing = false
561
+ this.storageClearError = null
562
+ this.storageClearedBytes = null
563
+ this.storageClearedFailed = 0
564
+ this.storageRequestId = 0
452
565
  // Row count is external: null = unknown, never 0; fetch only after the card is shown.
453
566
  this.bundleRows = null
454
567
  this.rowsRequested = false
@@ -511,6 +624,17 @@ class CapitalCardController {
511
624
  writing: this.workspaceWriting,
512
625
  failed: this.workspaceFailed,
513
626
  }),
627
+ storage: {
628
+ data: this.storage,
629
+ loading: this.storageInFlight || (this.storage === null && this.storageFailed !== true),
630
+ failed: this.storageFailed,
631
+ unavailable: this.storageFailed && this.storage === null,
632
+ stale: this.storageFailed && this.storage !== null,
633
+ clearing: this.storageClearing,
634
+ error: this.storageClearError,
635
+ clearedBytes: this.storageClearedBytes,
636
+ clearedFailed: this.storageClearedFailed,
637
+ },
514
638
  // `count === null` means unknown, not zero: the card decides whether to draw it.
515
639
  components: { count: this.bundleRows },
516
640
  }
@@ -725,6 +849,81 @@ class CapitalCardController {
725
849
  this.store.set(this.projection())
726
850
  }
727
851
 
852
+ /**
853
+ * Workspace usage is read from the automation route. Dirty cache is harmless: the
854
+ * server caps the scan and the card still allows a retry. A forced read merges with
855
+ * an in-flight one so a workspace switch cannot race an older response.
856
+ */
857
+ async ensureStorage(force = false) {
858
+ if (this.storageInFlight) {
859
+ if (force) this.storageQueued = true
860
+ return
861
+ }
862
+ if (!force && this.storage !== null && !this.storageFailed) return
863
+ const requestId = (this.storageRequestId += 1)
864
+ this.storageInFlight = true
865
+ this.storageFailed = false
866
+ this.store.set(this.projection())
867
+ try {
868
+ if (typeof fetch !== 'function') throw new Error('fetch_unavailable')
869
+ const response = await fetch(STORAGE_ROUTE, { method: 'GET', cache: 'no-store', credentials: 'same-origin' })
870
+ if (!response?.ok) throw new Error(`http_${response?.status ?? 0}`)
871
+ const payload = await response.json()
872
+ const storage = payload?.storage
873
+ if (storage === null || typeof storage !== 'object' || Array.isArray(storage)) throw new Error('invalid_payload')
874
+ if (requestId === this.storageRequestId) {
875
+ this.storage = storage
876
+ this.storageFailed = false
877
+ }
878
+ } catch {
879
+ if (requestId === this.storageRequestId) this.storageFailed = true
880
+ } finally {
881
+ if (requestId === this.storageRequestId) this.storageInFlight = false
882
+ this.store.set(this.projection())
883
+ if (this.storageQueued) {
884
+ this.storageQueued = false
885
+ void this.ensureStorage(true)
886
+ }
887
+ }
888
+ }
889
+
890
+ async clearStorage() {
891
+ if (this.storageClearing) return 'ignored'
892
+ this.storageClearing = true
893
+ this.storageClearError = null
894
+ this.storageClearedBytes = null
895
+ this.storageClearedFailed = 0
896
+ this.store.set(this.projection())
897
+ try {
898
+ if (typeof fetch !== 'function') throw new Error('fetch_unavailable')
899
+ const response = await fetch(STORAGE_CLEAR_ROUTE, {
900
+ method: 'POST',
901
+ headers: { 'content-type': 'application/json' },
902
+ body: JSON.stringify({ confirm: true }),
903
+ credentials: 'same-origin',
904
+ })
905
+ const payload = await response.json().catch(() => null)
906
+ if (!response?.ok || payload?.ok !== true) {
907
+ const code = payload?.code
908
+ this.storageClearError = code === 'run_in_progress'
909
+ ? 'run_in_progress'
910
+ : code === 'cache_root_unsafe' ? 'unsafe' : 'failed'
911
+ return 'failed'
912
+ }
913
+ const cleared = payload?.cleared
914
+ if (Number.isSafeInteger(cleared?.bytes) && cleared.bytes >= 0) this.storageClearedBytes = cleared.bytes
915
+ if (Array.isArray(cleared?.failed)) this.storageClearedFailed = cleared.failed.length
916
+ await this.ensureStorage(true)
917
+ return 'cleared'
918
+ } catch {
919
+ this.storageClearError = 'failed'
920
+ return 'failed'
921
+ } finally {
922
+ this.storageClearing = false
923
+ this.store.set(this.projection())
924
+ }
925
+ }
926
+
728
927
  async writeAutomationWorkspace(value) {
729
928
  if (this.workspaceWriting) return 'ignored'
730
929
  const snapshot = this.scope.getSnapshot()
@@ -742,6 +941,15 @@ class CapitalCardController {
742
941
  const landed = (this.scope.getSnapshot().value?.automation?.[AUTOMATION_WORKSPACE_FIELD] ?? '') === next
743
942
  if (!landed) this.workspaceFailed = true
744
943
  this.store.set(this.projection())
944
+ if (landed) {
945
+ // A different workspace has a different cache; drop the old numbers before refetching.
946
+ this.storage = null
947
+ this.storageFailed = false
948
+ this.storageClearError = null
949
+ this.storageClearedBytes = null
950
+ this.storageClearedFailed = 0
951
+ void this.ensureStorage(true)
952
+ }
745
953
  return landed ? 'saved' : 'failed'
746
954
  }
747
955
 
@@ -758,6 +966,8 @@ class CapitalCardController {
758
966
  toggleSelectedSkillsMode: (auto) => this.toggleSelectedSkillsMode(auto),
759
967
  ensureBundleRows: () => this.ensureBundleRows(),
760
968
  ensureWorkspaces: () => this.ensureWorkspaces(),
969
+ ensureStorage: (force) => this.ensureStorage(force),
970
+ clearStorage: () => this.clearStorage(),
761
971
  writeAutomationWorkspace: (value) => this.writeAutomationWorkspace(value),
762
972
  }
763
973
  }
@@ -956,6 +1166,53 @@ function SelectedSkillRow({ entry, state, disabled, onChange, t }) {
956
1166
  * `data-capital-config-tab`, so when unavailable we draw neither tabs nor that
957
1167
  * attribute and the host list stays visible.
958
1168
  */
1169
+ function formatBytes(value) {
1170
+ const bytes = typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0
1171
+ if (bytes < 1024) return `${Math.round(bytes)} B`
1172
+ const units = ['KB', 'MB', 'GB', 'TB']
1173
+ let size = bytes
1174
+ let unit = -1
1175
+ while (size >= 1024 && unit < units.length - 1) {
1176
+ size /= 1024
1177
+ unit += 1
1178
+ }
1179
+ return `${size.toFixed(1)} ${units[unit]}`
1180
+ }
1181
+
1182
+ function ClearCacheModal({ open, bytes, displayPath, clearing, error, onCancel, onConfirm, t }) {
1183
+ const size = formatBytes(bytes)
1184
+ const errorText = error === 'run_in_progress'
1185
+ ? t('automationStorageRunInProgress')
1186
+ : error === 'unsafe' ? t('automationStorageUnsafe') : error === 'failed' ? t('automationStorageClearFailed') : null
1187
+ return h(Modal, {
1188
+ open,
1189
+ onClose: () => { if (!clearing) onCancel() },
1190
+ title: t('automationStorageConfirmTitle'),
1191
+ closeLabel: t('automationStorageCancel'),
1192
+ className: 'capital-config-cache-modal',
1193
+ contentClassName: 'capital-config-cache-modal-content',
1194
+ footer: h('div', { className: 'capital-config-cache-actions' },
1195
+ h('button', {
1196
+ type: 'button',
1197
+ className: 'capital-config-cache-button',
1198
+ disabled: clearing,
1199
+ onClick: onCancel,
1200
+ }, t('automationStorageCancel')),
1201
+ h('button', {
1202
+ type: 'button',
1203
+ className: 'capital-config-cache-button',
1204
+ 'data-variant': 'danger',
1205
+ 'aria-busy': clearing ? 'true' : undefined,
1206
+ disabled: clearing,
1207
+ onClick: onConfirm,
1208
+ }, clearing ? t('automationStorageClearing') : t('automationStorageConfirm', { size })),
1209
+ ),
1210
+ },
1211
+ h('p', { className: 'capital-config-cache-modal-body' },
1212
+ t('automationStorageConfirmBody', { size, path: displayPath || t('automationStorageWorkspace') })),
1213
+ errorText ? h('p', { role: 'alert', className: 'capital-config-write-failed' }, errorText) : null)
1214
+ }
1215
+
959
1216
  function CapitalCard(props) {
960
1217
  const t = props.t
961
1218
  const state = props.useCapitalCard((snapshot) => snapshot)
@@ -963,13 +1220,16 @@ function CapitalCard(props) {
963
1220
  const autoMode = state.selectedSkillsMode?.auto === true
964
1221
  const locale = skillLocale()
965
1222
  const [tab, setTab] = useState('sources')
1223
+ const [clearCacheOpen, setClearCacheOpen] = useState(false)
966
1224
  const [traitFilter, setTraitFilter] = useState(SELECTED_SKILL_FILTER_ALL)
967
1225
  const [presetFilter, setPresetFilter] = useState(SELECTED_SKILL_FILTER_ALL)
968
1226
  // Fetch on mount: tab labels carry numbers; hooks must precede the unavailable return.
969
1227
  useEffect(() => { props.ensureBundleRows() }, [])
970
- // The workspace list lives behind the automation route; fetch when its tab first opens.
1228
+ // The workspace list and storage usage live behind the automation route; fetch when its tab opens.
971
1229
  useEffect(() => {
972
- if (tab === 'automation') props.ensureWorkspaces()
1230
+ if (tab !== 'automation') return
1231
+ props.ensureWorkspaces()
1232
+ props.ensureStorage()
973
1233
  }, [tab])
974
1234
  // Pinned order is snapshotted on tab entry so rows never move under the cursor.
975
1235
  const enabledKeys = () => new Set(SELECTED_SKILL_CATALOG
@@ -1108,6 +1368,118 @@ function CapitalCard(props) {
1108
1368
  ? h('p', { id: workspacePathId, className: 'capital-config-hint' }, t('automationWorkspacePath', { path: workspaceState.current.path }))
1109
1369
  : null,
1110
1370
  )
1371
+ const storageState = state.storage ?? {
1372
+ data: null,
1373
+ loading: false,
1374
+ failed: false,
1375
+ unavailable: false,
1376
+ stale: false,
1377
+ clearing: false,
1378
+ error: null,
1379
+ clearedBytes: null,
1380
+ clearedFailed: 0,
1381
+ }
1382
+ const storageData = storageState.data
1383
+ const cacheBytes = Number.isSafeInteger(storageData?.cache?.bytes) ? storageData.cache.bytes : 0
1384
+ const analysisBytes = Number.isSafeInteger(storageData?.analysis?.bytes) ? storageData.analysis.bytes : 0
1385
+ const workspaceBytes = cacheBytes + analysisBytes
1386
+ const sessions = storageData?.sessions
1387
+ const sessionBytes = Number.isSafeInteger(sessions?.bytes) ? sessions.bytes : 0
1388
+ const sessionCount = Number.isSafeInteger(sessions?.count) ? sessions.count : 0
1389
+ const storageAmount = (value, truncated) => `${truncated === true ? '≥ ' : ''}${formatBytes(value)}`
1390
+ const chipsOf = (categories, ids) => ids
1391
+ .map((id) => ({ id, value: Number.isSafeInteger(categories?.[id]?.bytes) ? categories[id].bytes : 0 }))
1392
+ .filter((item) => item.value > 0)
1393
+ .map((item) => h('span', { key: item.id, className: 'capital-config-storage-chip' }, `${t(STORAGE_CATEGORY_LABELS[item.id])} ${formatBytes(item.value)}`))
1394
+ const cacheChips = storageData === null ? [] : chipsOf(storageData.cache?.categories, ['datasets', 'profiles', 'ocr', 'other'])
1395
+ const analysisChips = storageData === null ? [] : chipsOf(storageData.analysis?.categories, ['charts', 'runs', 'other'])
1396
+ const cacheBlocked = storageData?.canClear === false
1397
+ const canClearCache = cacheBytes > 0 && !cacheBlocked && storageState.loading !== true && storageState.clearing !== true
1398
+ const clearError = storageState.error === 'run_in_progress'
1399
+ ? t('automationStorageRunInProgress')
1400
+ : storageState.error === 'unsafe' ? t('automationStorageUnsafe')
1401
+ : storageState.error === 'failed' ? t('automationStorageClearFailed') : null
1402
+ const cacheMetaTone = storageData?.cache?.unsafe === true || (storageData?.activeRuns ?? 0) > 0 ? 'warn' : undefined
1403
+ const cacheMeta = storageState.loading || storageState.unavailable || storageState.stale
1404
+ ? null
1405
+ : storageData?.cache?.unsafe === true ? t('automationStorageUnsafe')
1406
+ : (storageData?.activeRuns ?? 0) > 0 ? t('automationStorageActiveHint')
1407
+ : cacheBytes === 0 ? t('automationStorageEmpty')
1408
+ : storageData?.cache?.unreadable > 0 ? t('automationStorageUnreadable') : null
1409
+ const footNote = storageState.unavailable ? t('automationStorageUnavailable') : storageState.stale ? t('automationStorageStale') : null
1410
+ const clearedHint = storageState.clearedBytes === null
1411
+ ? null
1412
+ : storageState.clearedFailed > 0
1413
+ ? t('automationStorageClearedPartial', { size: formatBytes(storageState.clearedBytes), failed: storageState.clearedFailed })
1414
+ : t('automationStorageCleared', { size: formatBytes(storageState.clearedBytes) })
1415
+ const storageSection = automationGroup('automationStorageGroup', [
1416
+ h('div', { className: 'capital-config-storage' },
1417
+ h('div', { className: 'capital-config-storage-head' },
1418
+ h('span', { className: 'capital-config-storage-label' }, t('automationStorageWorkspace')),
1419
+ h('span', { className: 'capital-config-storage-amount' }, storageData === null
1420
+ ? '—'
1421
+ : storageAmount(workspaceBytes, storageData?.cache?.truncated === true || storageData?.analysis?.truncated === true)),
1422
+ ),
1423
+ h('div', { className: 'capital-config-storage-item' },
1424
+ h('div', { className: 'capital-config-storage-row' },
1425
+ h('span', { className: 'capital-config-storage-label' }, t('automationStorageCache')),
1426
+ h('span', { className: 'capital-config-storage-amount' }, storageData === null
1427
+ ? '—'
1428
+ : storageAmount(cacheBytes, storageData?.cache?.truncated === true)),
1429
+ ),
1430
+ cacheChips.length > 0 ? h('div', { className: 'capital-config-storage-chips' }, ...cacheChips) : null,
1431
+ cacheMeta ? h('p', { className: 'capital-config-storage-meta', 'data-tone': cacheMetaTone }, cacheMeta) : null,
1432
+ ),
1433
+ h('div', { className: 'capital-config-storage-item' },
1434
+ h('div', { className: 'capital-config-storage-row' },
1435
+ h('span', { className: 'capital-config-storage-label' }, t('automationStorageAnalysis')),
1436
+ h('span', { className: 'capital-config-storage-value' },
1437
+ h('span', { className: 'capital-config-storage-amount' }, storageData === null
1438
+ ? '—'
1439
+ : storageAmount(analysisBytes, storageData?.analysis?.truncated === true)),
1440
+ storageData === null ? null : h('span', { className: 'capital-config-storage-badge' }, t('automationStorageRetained')),
1441
+ ),
1442
+ ),
1443
+ analysisChips.length > 0 ? h('div', { className: 'capital-config-storage-chips' }, ...analysisChips) : null,
1444
+ ),
1445
+ h('div', { className: 'capital-config-storage-item' },
1446
+ h('div', { className: 'capital-config-storage-row' },
1447
+ h('span', { className: 'capital-config-storage-label' }, t('automationStorageSessions')),
1448
+ h('span', { className: 'capital-config-storage-value' },
1449
+ h('span', { className: 'capital-config-storage-amount' },
1450
+ storageData === null || sessions?.available === false ? '—' : formatBytes(sessionBytes),
1451
+ ),
1452
+ storageData === null || sessions?.available === false
1453
+ ? null
1454
+ : h('span', { className: 'capital-config-storage-count' }, t('automationStorageSessionCount', { count: sessionCount })),
1455
+ ),
1456
+ ),
1457
+ h('p', { className: 'capital-config-storage-meta' }, t('automationStorageSessionsHint')),
1458
+ ),
1459
+ h('div', { className: 'capital-config-storage-foot' },
1460
+ h('button', {
1461
+ type: 'button',
1462
+ className: 'capital-config-cache-button',
1463
+ 'data-variant': 'danger',
1464
+ 'aria-busy': storageState.clearing ? 'true' : undefined,
1465
+ disabled: !canClearCache,
1466
+ onClick: () => setClearCacheOpen(true),
1467
+ }, storageState.clearing ? t('automationStorageClearing') : t('automationStorageClear')),
1468
+ h('div', { className: 'capital-config-storage-status' },
1469
+ clearedHint ? h('p', { role: 'status', className: 'capital-config-storage-result' }, clearedHint) : null,
1470
+ clearError && storageState.clearing !== true ? h('p', { role: 'alert', className: 'capital-config-write-failed' }, clearError) : null,
1471
+ footNote ? h('p', { className: 'capital-config-storage-meta' }, footNote) : null,
1472
+ storageState.unavailable || storageState.stale
1473
+ ? h('button', {
1474
+ type: 'button',
1475
+ className: 'capital-config-storage-retry',
1476
+ onClick: () => props.ensureStorage(true),
1477
+ }, t('automationStorageRetry'))
1478
+ : null,
1479
+ ),
1480
+ ),
1481
+ ),
1482
+ ])
1111
1483
  const automationSection = h('div', { className: 'capital-config-automation' },
1112
1484
  workspaceSection,
1113
1485
  automationGroup('automationScheduleGroup', [
@@ -1138,6 +1510,7 @@ function CapitalCard(props) {
1138
1510
  ),
1139
1511
  state.automation?.inAppNotifications?.failed ? h('p', { role: 'status', className: 'capital-config-write-failed' }, t('saveFailed')) : null,
1140
1512
  ]),
1513
+ storageSection,
1141
1514
  )
1142
1515
  const modeSection = h('div', { className: 'capital-config-selected-mode' },
1143
1516
  h('div', { className: 'capital-config-switch-row' },
@@ -1245,6 +1618,20 @@ function CapitalCard(props) {
1245
1618
  )]),
1246
1619
  // The panel is the host's rows list; keep the aria-controls target non-empty via sr-only.
1247
1620
  panel('components', [h('span', { className: 'capital-config-sr-only' }, t('componentsHint'))]),
1621
+ clearCacheOpen ? h(ClearCacheModal, {
1622
+ open: true,
1623
+ bytes: cacheBytes,
1624
+ displayPath: storageData?.workspace?.displayPath ?? workspaceState.current?.path ?? '',
1625
+ clearing: storageState.clearing,
1626
+ error: storageState.error,
1627
+ onCancel: () => { if (!storageState.clearing) setClearCacheOpen(false) },
1628
+ onConfirm: () => {
1629
+ Promise.resolve(props.clearStorage()).then((result) => {
1630
+ if (result === 'cleared') setClearCacheOpen(false)
1631
+ })
1632
+ },
1633
+ t,
1634
+ }) : null,
1248
1635
  )
1249
1636
  }
1250
1637
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/config",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "自动模式的取数凭据与偏好配置行:卡片坐在 @v587d/capital-generation 插件主页的「配置」段,点这一行本身没有表单。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -3,7 +3,7 @@
3
3
  * Known limit: DNS resolves per request but the IP is not pinned to the connection,
4
4
  * so a rebinding window remains (same trade-off as dsh-search-first).
5
5
  */
6
- export declare const LOCAL_FETCH_CLIENT_VERSION = "2.22.0";
6
+ export declare const LOCAL_FETCH_CLIENT_VERSION = "2.23.0";
7
7
  export declare const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
8
8
  export type LocalFetchErrorCode = 'ABORTED' | 'TIMEOUT' | 'INVALID_URL' | 'BLOCKED_URL' | 'DNS' | 'REDIRECT' | 'HTTP' | 'TOO_LARGE' | 'UNSUPPORTED_CONTENT_TYPE';
9
9
  export declare class LocalFetchError extends Error {
@@ -4,7 +4,7 @@
4
4
  * so a rebinding window remains (same trade-off as dsh-search-first).
5
5
  */
6
6
  import { htmlToMarkdown, stripInvisibleText } from './html-markdown.js';
7
- export const LOCAL_FETCH_CLIENT_VERSION = '2.22.0';
7
+ export const LOCAL_FETCH_CLIENT_VERSION = '2.23.0';
8
8
  export const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
9
9
  export class LocalFetchError extends Error {
10
10
  code;
@@ -35,7 +35,7 @@ export interface WindCallResult {
35
35
  code?: WindErrorCode;
36
36
  }
37
37
  /** Must match `package.json` version; a test pins the two together. */
38
- export declare const WIND_CLIENT_VERSION = "2.22.0";
38
+ export declare const WIND_CLIENT_VERSION = "2.23.0";
39
39
  export interface WindClient {
40
40
  callTool(toolName: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<WindCallResult>;
41
41
  }
@@ -19,7 +19,7 @@ export const WIND_SERVER_ENDPOINTS = {
19
19
  analytics_data: 'https://mcp.wind.com.cn/vserver_analytics_data/mcp/',
20
20
  };
21
21
  /** Must match `package.json` version; a test pins the two together. */
22
- export const WIND_CLIENT_VERSION = '2.22.0';
22
+ export const WIND_CLIENT_VERSION = '2.23.0';
23
23
  function errorText(error) {
24
24
  return error instanceof Error ? error.message : String(error);
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-generation",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "Capital Generation:面向中国散户的 AI 投资助手插件(自动模式 Agent Preset)",
5
5
  "icon": "assets/cg-icon.png",
6
6
  "author": "v587d",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/watchlist",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "自动模式的用户自选股(宿主级清单 + Fuyao 报价快照 + /capital-watchlist 路由 + 输入框菜单弹窗):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",