dsh-capability-trimmer 1.0.3 → 1.0.4

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 (2) hide show
  1. package/client.js +59 -1
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -15,6 +15,9 @@ window.__ModuleLoader__.load({
15
15
  .cm-mode[data-state="off"]{border-color:var(--dsw-alias-state-warn-primary);color:var(--dsw-alias-state-warn-primary)}
16
16
  .cm-sub{margin:5px 0 0;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-secondary);max-width:70ch}
17
17
  .cm-actions{display:flex;gap:8px;align-items:center}
18
+ .cm-progress{position:relative;height:4px;margin:1px 0 2px;border-radius:999px;background:var(--dsw-alias-bg-layer-2);overflow:hidden}
19
+ .cm-progressfill{height:100%;border-radius:999px;background:var(--dsw-alias-brand-primary);transition:width .12s linear}
20
+ .cm-lastcheck{margin:0 0 2px;font-size:11px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}
18
21
  .cm-btn{padding:6px 13px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:inherit;font:inherit;font-size:12px;cursor:pointer}
19
22
  .cm-btn:hover{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}
20
23
  .cm-btn:disabled{opacity:.55;cursor:progress}
@@ -111,6 +114,7 @@ window.__ModuleLoader__.load({
111
114
  subProviderOff: '当前模式下技能提供者未启用,模型看不到任何技能。',
112
115
  presetDefault: '默认模式',
113
116
  recheck: '重新检查', checking: '检查中…',
117
+ lastCheck: '最近检查 ',
114
118
  skipTag: '已忽略关闭确认', skipTagTitle: '刷新页面后恢复',
115
119
  readFail: '读取失败:',
116
120
  firstOpen: '首次打开,正在扫描…',
@@ -188,6 +192,7 @@ window.__ModuleLoader__.load({
188
192
  subProviderOff: 'The skill provider is off in this preset — the model sees no skills.',
189
193
  presetDefault: 'Default preset',
190
194
  recheck: 'Re-scan', checking: 'Scanning…',
195
+ lastCheck: 'Last checked ',
191
196
  skipTag: 'Confirmations skipped', skipTagTitle: 'Restored after page refresh',
192
197
  readFail: 'Failed to load: ',
193
198
  firstOpen: 'First open, scanning…',
@@ -456,6 +461,13 @@ window.__ModuleLoader__.load({
456
461
 
457
462
  /** Process-wide cache: leaving the view and coming back must not refetch. */
458
463
  const cache = { preset: null, data: null }
464
+ const LAST_CHECK_KEY = 'capability-trimmer:last-check'
465
+ const formatLastCheck = (iso) => {
466
+ const at = new Date(iso)
467
+ if (Number.isNaN(at.getTime())) return ''
468
+ const sameDay = at.toDateString() === new Date().toDateString()
469
+ return sameDay ? at.toLocaleTimeString() : at.toLocaleString()
470
+ }
459
471
 
460
472
  function presetOf(snapshot) {
461
473
  if (!snapshot) return null
@@ -499,6 +511,14 @@ window.__ModuleLoader__.load({
499
511
  const [confirmGraph, setConfirmGraph] = useState(null)
500
512
  const [busy, setBusy] = useState(false)
501
513
  const [pending, setPending] = useState(() => new Set())
514
+ const [progress, setProgress] = useState(null)
515
+ const [lastCheck, setLastCheck] = useState(() => {
516
+ try {
517
+ return localStorage.getItem(LAST_CHECK_KEY)
518
+ } catch {
519
+ return null
520
+ }
521
+ })
502
522
 
503
523
  const load = useCallback(async (force) => {
504
524
  if (!force && cache.data && cache.preset === presetId) {
@@ -515,6 +535,15 @@ window.__ModuleLoader__.load({
515
535
  cache.data = payload
516
536
  setState(payload)
517
537
  setError(null)
538
+ if (force) {
539
+ const stamp = new Date().toISOString()
540
+ setLastCheck(stamp)
541
+ try {
542
+ localStorage.setItem(LAST_CHECK_KEY, stamp)
543
+ } catch {
544
+ // Storage may be unavailable; the timestamp still shows for this session.
545
+ }
546
+ }
518
547
  } catch (cause) {
519
548
  setError(cause instanceof Error ? cause.message : String(cause))
520
549
  } finally {
@@ -525,6 +554,25 @@ window.__ModuleLoader__.load({
525
554
  // First mount only; every later visit reuses the cache.
526
555
  useEffect(() => { load(false) }, [load])
527
556
 
557
+ // 手动重扫:进度条走完停 1 秒再消失,随后显示最近检查时间。
558
+ const recheck = useCallback(async () => {
559
+ if (busy || progress !== null) return
560
+ const startedAt = Date.now()
561
+ setProgress(4)
562
+ const ramp = setInterval(() => {
563
+ setProgress((value) => (value === null ? value : Math.min(88, value + 6)))
564
+ }, 90)
565
+ try {
566
+ await load(true)
567
+ } finally {
568
+ clearInterval(ramp)
569
+ const elapsed = Date.now() - startedAt
570
+ if (elapsed < 500) await new Promise((resolve) => setTimeout(resolve, 500 - elapsed))
571
+ setProgress(100)
572
+ setTimeout(() => setProgress(null), 1000)
573
+ }
574
+ }, [busy, load, progress])
575
+
528
576
  const doToggle = useCallback(async (kind, name, enabled, use = '') => {
529
577
  const key = `${kind}:${name}`
530
578
  setPending((current) => new Set(current).add(key))
@@ -767,12 +815,22 @@ window.__ModuleLoader__.load({
767
815
  providerOff ? baseTr('subProviderOff') : baseTr('sub')),
768
816
  ),
769
817
  h('div', { className: 'cm-actions' },
770
- h('button', { className: 'cm-btn', type: 'button', disabled: busy, onClick: () => load(true) },
818
+ h('button', { className: 'cm-btn', type: 'button', disabled: busy || progress !== null, onClick: recheck },
771
819
  busy ? baseTr('checking') : baseTr('recheck')),
772
820
  skipConfirm ? h('span', { className: 'cm-skiptag', title: baseTr('skipTagTitle') }, baseTr('skipTag')) : null,
773
821
  ),
774
822
  ),
775
823
 
824
+ progress !== null
825
+ ? h('div', {
826
+ className: 'cm-progress',
827
+ role: 'progressbar',
828
+ 'aria-valuemin': 0,
829
+ 'aria-valuemax': 100,
830
+ 'aria-valuenow': Math.round(progress),
831
+ }, h('div', { className: 'cm-progressfill', style: { width: `${progress}%` } }))
832
+ : (lastCheck ? h('p', { className: 'cm-lastcheck' }, baseTr('lastCheck') + formatLastCheck(lastCheck)) : null),
833
+
776
834
  error ? h('div', { className: 'cm-error' }, baseTr('readFail') + `${error}`) : null,
777
835
  !state && !error ? h('div', { className: 'cm-empty' }, baseTr('firstOpen')) : null,
778
836
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-capability-trimmer",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "cuoduidui",